1 package org.apache.maven.archetype.mojos;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.archetype.ArchetypeManager;
23 import org.apache.maven.archetype.catalog.Archetype;
24 import org.apache.maven.execution.MavenSession;
25 import org.apache.maven.plugin.AbstractMojo;
26 import org.apache.maven.plugin.MojoExecutionException;
27 import org.apache.maven.plugins.annotations.Component;
28 import org.apache.maven.plugins.annotations.LifecyclePhase;
29 import org.apache.maven.plugins.annotations.Mojo;
30 import org.apache.maven.plugins.annotations.Parameter;
31 import org.apache.maven.project.MavenProject;
32 import org.codehaus.plexus.util.StringUtils;
33
34
35
36
37
38
39 @Mojo( name = "update-local-catalog", defaultPhase = LifecyclePhase.INSTALL )
40 public class UpdateLocalCatalogMojo
41 extends AbstractMojo
42 {
43 @Parameter( defaultValue = "${session}", readonly = true, required = true )
44 private MavenSession session;
45
46 @Component
47 private ArchetypeManager manager;
48
49
50
51
52 @Parameter( defaultValue = "${project}", readonly = true, required = true )
53 private MavenProject project;
54
55 public void execute()
56 throws MojoExecutionException
57 {
58 Archetype archetype = new Archetype();
59 archetype.setGroupId( project.getGroupId() );
60 archetype.setArtifactId( project.getArtifactId() );
61 archetype.setVersion( project.getVersion() );
62
63 if ( StringUtils.isNotEmpty( project.getDescription() ) )
64 {
65 archetype.setDescription( project.getDescription() );
66 }
67 else
68 {
69 archetype.setDescription( project.getName() );
70 }
71
72 manager.updateLocalCatalog( session.getProjectBuildingRequest(), archetype );
73 }
74 }