Skip to content

Commit 93f6822

Browse files
committed
Maven Plugin allow referencing aspect models from multiple repositories
1 parent a0c3ce9 commit 93f6822

File tree

4 files changed

+67
-53
lines changed

4 files changed

+67
-53
lines changed

tools/esmf-aspect-model-maven-plugin/src/main/java/org/eclipse/esmf/aspectmodel/AspectModelMojo.java

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ public abstract class AspectModelMojo extends AbstractMojo {
8787
protected boolean detailedValidationMessages;
8888

8989
@Parameter
90-
protected String githubServerId;
90+
protected List<String> githubServerIds;
9191

9292
@Parameter( defaultValue = "${session}", readonly = true )
9393
protected MavenSession mavenSession;
9494

9595
@Parameter
9696
protected Map<String, String> resolutionConfiguration = new HashMap<>();
9797

98-
protected GithubModelSourceConfig gitHubConfig;
98+
protected List<GithubModelSourceConfig> gitHubConfigs = new ArrayList<>();
9999

100100
private Map<AspectModel, Aspect> aspects;
101101

@@ -141,8 +141,10 @@ private AspectModelLoader createAspectModelLoader() throws MojoExecutionExceptio
141141
final Path modelsRoot = Path.of( modelsRootDirectory );
142142
strategies.add( new FileSystemStrategy( modelsRoot ) );
143143
}
144-
if ( gitHubConfig != null ) {
145-
strategies.add( new GitHubStrategy( gitHubConfig ) );
144+
if ( !gitHubConfigs.isEmpty() ) {
145+
for ( GithubModelSourceConfig gitHubConfig : gitHubConfigs ) {
146+
strategies.add( new GitHubStrategy( gitHubConfig ) );
147+
}
146148
}
147149
if ( strategies.isEmpty() ) {
148150
throw new MojoExecutionException(
@@ -206,50 +208,54 @@ public void execute() throws MojoExecutionException, MojoFailureException {
206208
return;
207209
}
208210

209-
if ( githubServerId != null ) {
211+
if ( githubServerIds != null && !githubServerIds.isEmpty() ) {
210212
if ( mavenSession == null ) {
211213
getLog().warn( "Could not read Maven session, ignoring GitHub server configuration." );
212214
} else {
213-
final Server server = mavenSession.getSettings().getServer( githubServerId );
214-
if ( server != null ) {
215-
final Xpp3Dom dom = (Xpp3Dom) server.getConfiguration();
216-
final String[] repositoryParts = Optional.ofNullable( dom.getChild( "repository" ) )
217-
.map( Xpp3Dom::getValue )
218-
.map( repository -> repository.split( "/" ) )
219-
.orElseThrow( () -> new MojoExecutionException( "Expected <repository> in settings.xml is missing" ) );
220-
final String directory = Optional.ofNullable( dom.getChild( "directory" ) )
221-
.map( Xpp3Dom::getValue )
222-
.orElse( "" );
223-
final String token = Optional.ofNullable( dom.getChild( "token" ) )
224-
.map( Xpp3Dom::getValue )
225-
.orElse( null );
226-
227-
final GithubRepository.Ref ref = Optional.ofNullable( dom.getChild( "branch" ) )
228-
.map( Xpp3Dom::getValue )
229-
.<GithubRepository.Ref> map( GithubRepository.Branch::new )
230-
.or( () -> Optional.ofNullable( dom.getChild( "tag" ) )
231-
.map( Xpp3Dom::getValue )
232-
.map( GithubRepository.Tag::new ) )
233-
.orElse( new GithubRepository.Branch( "main" ) );
234-
235-
final List<Proxy> proxies = mavenSession.getSettings().getProxies();
236-
final ProxyConfig proxyConfig = Optional.ofNullable( proxies ).stream().flatMap( Collection::stream )
237-
.filter( proxy -> proxy.getProtocol().equals( "https" ) )
238-
.findFirst()
239-
.or( () -> Optional.ofNullable( proxies ).stream().flatMap( Collection::stream )
240-
.filter( proxy -> proxy.getProtocol().equals( "http" ) )
241-
.findFirst() )
242-
.filter( Proxy::isActive )
243-
.map( proxy -> ProxyConfig.from( proxy.getHost(), proxy.getPort() ) )
244-
.orElse( ProxyConfig.detectProxySettings() );
245-
246-
final GithubRepository repository = new GithubRepository( repositoryParts[0], repositoryParts[1], ref );
247-
gitHubConfig = GithubModelSourceConfigBuilder.builder()
248-
.proxyConfig( proxyConfig )
249-
.repository( repository )
250-
.directory( directory )
251-
.token( token )
252-
.build();
215+
for ( String serverId : githubServerIds ) {
216+
final Server server = mavenSession.getSettings().getServer( serverId );
217+
if ( server != null ) {
218+
final Xpp3Dom dom = (Xpp3Dom) server.getConfiguration();
219+
final String[] repositoryParts = Optional.ofNullable( dom.getChild( "repository" ) )
220+
.map( Xpp3Dom::getValue )
221+
.map( repository -> repository.split( "/" ) )
222+
.orElseThrow( () -> new MojoExecutionException( "Expected <repository> in settings.xml is missing" ) );
223+
final String directory = Optional.ofNullable( dom.getChild( "directory" ) )
224+
.map( Xpp3Dom::getValue )
225+
.orElse( "" );
226+
final String token = Optional.ofNullable( dom.getChild( "token" ) )
227+
.map( Xpp3Dom::getValue )
228+
.orElse( null );
229+
230+
final GithubRepository.Ref ref = Optional.ofNullable( dom.getChild( "branch" ) )
231+
.map( Xpp3Dom::getValue )
232+
.<GithubRepository.Ref> map( GithubRepository.Branch::new )
233+
.or( () -> Optional.ofNullable( dom.getChild( "tag" ) )
234+
.map( Xpp3Dom::getValue )
235+
.map( GithubRepository.Tag::new ) )
236+
.orElse( new GithubRepository.Branch( "main" ) );
237+
238+
final List<Proxy> proxies = mavenSession.getSettings().getProxies();
239+
final ProxyConfig proxyConfig = Optional.ofNullable( proxies ).stream().flatMap( Collection::stream )
240+
.filter( proxy -> proxy.getProtocol().equals( "https" ) )
241+
.findFirst()
242+
.or( () -> Optional.ofNullable( proxies ).stream().flatMap( Collection::stream )
243+
.filter( proxy -> proxy.getProtocol().equals( "http" ) )
244+
.findFirst() )
245+
.filter( Proxy::isActive )
246+
.map( proxy -> ProxyConfig.from( proxy.getHost(), proxy.getPort() ) )
247+
.orElse( ProxyConfig.detectProxySettings() );
248+
249+
final GithubRepository repository = new GithubRepository( repositoryParts[0], repositoryParts[1], ref );
250+
GithubModelSourceConfig gitHubConfig = GithubModelSourceConfigBuilder.builder()
251+
.proxyConfig( proxyConfig )
252+
.repository( repository )
253+
.directory( directory )
254+
.token( token )
255+
.build();
256+
257+
gitHubConfigs.add( gitHubConfig );
258+
}
253259
}
254260
}
255261
}

tools/esmf-aspect-model-maven-plugin/src/test/java/org/eclipse/esmf/aspectmodel/MojoConfigTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import static org.assertj.core.api.Assertions.assertThat;
1717
import static org.assertj.core.api.Assertions.assertThatCode;
1818

19+
import java.util.List;
20+
1921
import org.eclipse.esmf.aspectmodel.resolver.github.GithubModelSourceConfig;
2022

2123
import org.apache.maven.plugin.Mojo;
@@ -59,11 +61,13 @@ public void testGitHubServerConfig() throws Exception {
5961
""";
6062
final AspectModelMojo validate = (AspectModelMojo) getMojo( "test-pom-github-server-config", "validate", serverConfig );
6163
validate.execute();
62-
final GithubModelSourceConfig config = validate.gitHubConfig;
63-
assertThat( config.repository().owner() ).isEqualTo( "test-org" );
64-
assertThat( config.repository().repository() ).isEqualTo( "test-repository" );
65-
assertThat( config.directory() ).isEqualTo( "src/main/resources/aspects" );
66-
assertThat( config.repository().branchOrTag().name() ).isEqualTo( "main" );
67-
assertThat( config.token() ).isEqualTo( "THE_TOKEN" );
64+
final List<GithubModelSourceConfig> configs = validate.gitHubConfigs;
65+
for ( GithubModelSourceConfig config : configs ) {
66+
assertThat( config.repository().owner() ).isEqualTo( "test-org" );
67+
assertThat( config.repository().repository() ).isEqualTo( "test-repository" );
68+
assertThat( config.directory() ).isEqualTo( "src/main/resources/aspects" );
69+
assertThat( config.repository().branchOrTag().name() ).isEqualTo( "main" );
70+
assertThat( config.token() ).isEqualTo( "THE_TOKEN" );
71+
}
6872
}
6973
}

tools/esmf-aspect-model-maven-plugin/src/test/resources/test-pom-github-server-config/pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
</configuration>
4545
</server>
4646
-->
47-
<githubServerId>test-github-config</githubServerId>
47+
<githubServerIds>
48+
<githubServerId>test-github-config</githubServerId>
49+
</githubServerIds>
4850
</configuration>
4951
</plugin>
5052
</plugins>

tools/esmf-aspect-model-maven-plugin/src/test/resources/validate-pom-resolve-from-github/pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
</configuration>
4242
</server>
4343
-->
44-
<githubServerId>test-github-config</githubServerId>
44+
<githubServerIds>
45+
<githubServerId>test-github-config</githubServerId>
46+
</githubServerIds>
4547
</configuration>
4648
</plugin>
4749
</plugins>

0 commit comments

Comments
 (0)