1
2
3
4 package org.apache.maven.plugin.archetype;
5
6 import org.apache.maven.plugin.AbstractMojo;
7 import org.apache.maven.plugin.MojoExecutionException;
8 import org.apache.maven.archetype.Archetype;
9 import org.apache.maven.archetype.ArchetypeNotFoundException;
10 import org.apache.maven.archetype.ArchetypeDescriptorException;
11 import org.apache.maven.archetype.ArchetypeTemplateProcessingException;
12 import org.apache.maven.archetype.ArchetypeCreator;
13 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
14 import org.apache.maven.artifact.repository.ArtifactRepository;
15 import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
16 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
17 import org.apache.maven.project.MavenProject;
18 import org.apache.maven.project.MavenProjectHelper;
19 import org.codehaus.plexus.util.StringUtils;
20
21 import java.util.List;
22 import java.util.Map;
23 import java.util.HashMap;
24 import java.util.ArrayList;
25 import java.util.Properties;
26 import java.io.File;
27 import java.io.FileInputStream;
28
29
30
31
32
33
34
35
36
37 public class CreateArchetypeFromProjectMojo
38 extends AbstractMojo
39 {
40
41
42
43
44
45
46 private MavenProject project;
47
48
49
50
51
52
53
54 private ArtifactRepository localRepository;
55
56
57
58
59
60
61
62 private File targetDirectory;
63
64
65
66
67
68
69 private ArchetypeCreator archetypeCreator;
70
71
72
73
74
75
76 private MavenProjectHelper projectHelper;
77
78
79
80
81
82
83
84
85 private File archetypeProperties;
86
87 public void execute()
88 throws MojoExecutionException
89 {
90 try
91 {
92 Properties p = new Properties();
93
94 p.load( new FileInputStream( archetypeProperties ) );
95
96 File archetypeJar = archetypeCreator.createArchetype( project, localRepository, targetDirectory, p );
97
98 projectHelper.attachArtifact( project, "jar", "archetype", archetypeJar );
99 }
100 catch ( Exception e )
101 {
102 throw new MojoExecutionException( "Cannot create archetype from this project.", e );
103 }
104 }
105 }