2424import java .nio .charset .StandardCharsets ;
2525import java .nio .file .Files ;
2626import java .util .ArrayList ;
27+ import java .util .HashSet ;
2728import java .util .List ;
29+ import java .util .Properties ;
2830import java .util .Set ;
2931import java .util .regex .Pattern ;
3032import java .util .stream .Collectors ;
3133import org .apache .maven .plugins .annotations .Parameter ;
3234import org .apache .maven .project .MavenProject ;
35+ import org .codehaus .plexus .interpolation .PropertiesBasedValueSource ;
36+ import org .codehaus .plexus .interpolation .RegexBasedInterpolator ;
3337import org .eclipse .aether .artifact .Artifact ;
3438import org .eclipse .aether .artifact .DefaultArtifact ;
3539
3943 */
4044public abstract class AbstractAssembleMojo extends AbstractBaseMojo {
4145
46+ private static final String REPO_COMPONENT = "weaverbird-repo" ;
47+
48+ private static final String SERVER_COMPONENT = "weaverbird-server" ;
49+
50+ private static final String CLI_COMPONENT = "weaverbird-cli" ;
51+
52+ private static final String GUI_COMPONENT = "weaverbird-gui" ;
53+
4254 static List <String > readFile (String fileName ) throws IOException {
4355 try (InputStream is = AbstractAssembleMojo .class .getResourceAsStream (fileName );
4456 BufferedReader reader = new BufferedReader (new InputStreamReader (is , StandardCharsets .UTF_8 ))) {
@@ -77,7 +89,12 @@ static List<Artifact> readArtifacts(String fileName) throws IOException {
7789 private final List <Artifact > modulePathModules = new ArrayList <>();
7890
7991 @ Parameter (required = true )
80- private Set <String > components ;
92+ private List <String > components ;
93+
94+ /**
95+ * Use only via {@link #getComponentSet()}.
96+ */
97+ private Set <String > componentSet ;
8198
8299 List <Artifact > getModulePathModules () {
83100 return modulePathModules ;
@@ -87,37 +104,51 @@ void createData() throws Exception {
87104 var dataPath = getPath ().resolve ("data" );
88105 Files .createDirectories (dataPath );
89106 var registry = readFileToStr ("registry.xml" );
107+ StringBuilder builder = new StringBuilder ();
108+ for (var c : components ) {
109+ addComponent (builder , c );
110+ }
111+ var addedComponents = builder .toString ();
112+ builder .setLength (0 );
113+ var resolvedComponents = "" ;
114+ if (getComponentSet ().contains (REPO_COMPONENT )) {
115+ addComponent (builder , REPO_COMPONENT );
116+ resolvedComponents = builder .toString ();
117+ }
118+ var properties = new Properties ();
119+ properties .put ("addedComponents" , addedComponents );
120+ properties .put ("resolvedComponents" , resolvedComponents );
121+ registry = interpolate (registry , properties );
90122 FileUtils .writeFile (dataPath .resolve ("weaverbird-registry.xml" ), registry , StandardCharsets .UTF_8 );
91123 }
92124
93125 void createConfig () throws Exception {
94126 var configPath = getPath ().resolve ("config" );
95-
96- if (components .contains ("weaverbird-repo" )) {
97- var repoDirPath = configPath .resolve ("weaverbird-repo" ).resolve (project .getVersion ());
127+ if (getComponentSet ().contains (REPO_COMPONENT )) {
128+ var repoDirPath = configPath .resolve (REPO_COMPONENT ).resolve (project .getVersion ());
98129 Files .createDirectories (repoDirPath );
99130 var repoConfig = readFileToStr ("repo-config.xml" );
100131 FileUtils .writeFile (repoDirPath .resolve ("configuration.xml" ), repoConfig , StandardCharsets .UTF_8 );
101132 }
102133
103- if (components .contains ("weaverbird-server" )) {
104- var serverDirPath = configPath .resolve ("weaverbird-server" ).resolve (project .getVersion ());
134+ if (getComponentSet () .contains (SERVER_COMPONENT )) {
135+ var serverDirPath = configPath .resolve (SERVER_COMPONENT ).resolve (project .getVersion ());
105136 Files .createDirectories (serverDirPath );
106137 var serverConfig = readFileToStr ("server-config.xml" );
107138 FileUtils .writeFile (serverDirPath .resolve ("configuration.xml" ), serverConfig , StandardCharsets .UTF_8 );
108139 var serverSettings = readFileToStr ("server-settings.xml" );
109140 FileUtils .writeFile (serverDirPath .resolve ("settings.xml" ), serverSettings , StandardCharsets .UTF_8 );
110141 }
111142
112- if (components .contains ("weaverbird-cli" )) {
113- var cliDirPath = configPath .resolve ("weaverbird-cli" ).resolve (project .getVersion ());
143+ if (getComponentSet () .contains (CLI_COMPONENT )) {
144+ var cliDirPath = configPath .resolve (CLI_COMPONENT ).resolve (project .getVersion ());
114145 Files .createDirectories (cliDirPath );
115146 var cliConfig = readFileToStr ("cli-config.xml" );
116147 FileUtils .writeFile (cliDirPath .resolve ("configuration.xml" ), cliConfig , StandardCharsets .UTF_8 );
117148 }
118149
119- if (components .contains ("weaverbird-gui" )) {
120- var guiDirPath = configPath .resolve ("weaverbird-gui" ).resolve (project .getVersion ());
150+ if (getComponentSet () .contains (GUI_COMPONENT )) {
151+ var guiDirPath = configPath .resolve (GUI_COMPONENT ).resolve (project .getVersion ());
121152 Files .createDirectories (guiDirPath );
122153 var guiConfig = readFileToStr ("gui-config.xml" );
123154 FileUtils .writeFile (guiDirPath .resolve ("configuration.xml" ), guiConfig , StandardCharsets .UTF_8 );
@@ -141,14 +172,41 @@ void createRepo(boolean modulePathSupported) throws Exception {
141172 resolveProvidedModules (session , null );
142173 }
143174
144- var repoComponentArtifacts = readArtifacts ("repo-modules.txt" );
145- for (var a : repoComponentArtifacts ) {
146- resolveModule (a , session );
175+ if (getComponentSet ().contains (REPO_COMPONENT )) {
176+ var repoComponentArtifacts = readArtifacts ("repo-modules.txt" );
177+ for (var a : repoComponentArtifacts ) {
178+ resolveModule (a , session );
179+ }
147180 }
148181 }
149182
150183 void createTemp () throws Exception {
151184 var tempPath = getPath ().resolve ("temp" );
152185 Files .createDirectories (tempPath );
153186 }
187+
188+ String interpolate (String content , Properties properties ) throws Exception {
189+ RegexBasedInterpolator interpolator = new RegexBasedInterpolator ();
190+ interpolator .addValueSource (new PropertiesBasedValueSource (properties ));
191+ interpolator .addValueSource (new PropertiesBasedValueSource (System .getProperties ()));
192+ return interpolator .interpolate (content );
193+ }
194+
195+ private Set <String > getComponentSet () {
196+ if (this .componentSet == null ) {
197+ this .componentSet = new HashSet <>(components );
198+ }
199+ return componentSet ;
200+ }
201+
202+ private void addComponent (StringBuilder builder , String name ) {
203+ if (builder .length () > 0 ) {
204+ builder .append ("\n " );
205+ }
206+ builder .append (" <Component name=\" " );
207+ builder .append (name );
208+ builder .append ("\" version=\" " );
209+ builder .append (project .getVersion ());
210+ builder .append ("\" />" );
211+ }
154212}
0 commit comments