1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 package org.jomc.mojo;
32
33 import javax.xml.bind.JAXBElement;
34 import org.apache.maven.plugin.MojoExecutionException;
35 import org.apache.maven.plugins.annotations.Mojo;
36 import org.apache.maven.plugins.annotations.Parameter;
37 import org.apache.maven.plugins.annotations.ResolutionScope;
38 import org.jomc.model.Instance;
39 import org.jomc.model.Modules;
40 import org.jomc.model.modlet.ModelHelper;
41 import org.jomc.modlet.Model;
42 import org.jomc.modlet.ModelContext;
43
44
45
46
47
48
49
50
51 @Mojo( name = "show-main-instance",
52 requiresDependencyResolution = ResolutionScope.TEST,
53 threadSafe = true )
54 public final class MainInstanceShowMojo extends AbstractModelShowMojo
55 {
56
57
58
59
60 @Parameter( name = "identifier",
61 property = "jomc.identifier",
62 required = true )
63 private String identifier;
64
65
66
67
68 @Parameter( name = "showMainInstanceExecutionStrategy",
69 property = "jomc.showMainInstanceExecutionStrategy",
70 defaultValue = "once-per-session" )
71 private String showMainInstanceExecutionStrategy;
72
73
74
75
76 public MainInstanceShowMojo()
77 {
78 super();
79 }
80
81 @Override
82 protected JAXBElement<?> getDisplayModel( final ModelContext modelContext ) throws MojoExecutionException
83 {
84 final Model model = this.getModel( modelContext );
85 final Modules modules = ModelHelper.getModules( model );
86 final Instance instance = modules != null ? modules.getInstance( this.identifier ) : null;
87 JAXBElement<?> displayModel = null;
88
89 if ( instance != null )
90 {
91 displayModel = new org.jomc.model.ObjectFactory().createInstance( instance );
92 }
93
94 return displayModel;
95 }
96
97 @Override
98 protected ClassLoader getDisplayClassLoader() throws MojoExecutionException
99 {
100 return this.getMainClassLoader();
101 }
102
103 @Override
104 protected String getGoal() throws MojoExecutionException
105 {
106 return "show-main-instance";
107 }
108
109 @Override
110 protected String getExecutionStrategy() throws MojoExecutionException
111 {
112 return this.showMainInstanceExecutionStrategy;
113 }
114
115 }