Skip to content

Commit 94c68e2

Browse files
committed
Enable resolution from private GitHub repositories in Maven Plugin
1 parent 679ac81 commit 94c68e2

File tree

66 files changed

+421
-146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+421
-146
lines changed

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/ProxyConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public record ProxyConfig(
3232

3333
public static final ProxyConfig NO_PROXY = new ProxyConfig( null, null );
3434

35+
public static ProxyConfig from( final String host, final int port ) {
36+
return new ProxyConfig( ProxySelector.of( new InetSocketAddress( host, port ) ), null );
37+
}
38+
3539
public static ProxyConfig detectProxySettings() {
3640
final String envProxy = System.getenv( "http_proxy" );
3741
if ( envProxy != null && System.getProperty( "http.proxyHost" ) == null ) {

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/fs/StructuredModelsRoot.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import org.eclipse.esmf.aspectmodel.resolver.exceptions.ModelResolutionException;
2828
import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn;
2929

30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
32+
3033
/**
3134
* Represents the root directory of the directory hierarchy in which Aspect Models are organized.
3235
* The directory is assumed to contain a file system hierarchy as follows: {@code N/V/X.ttl} where N is the namespace,
@@ -43,6 +46,8 @@
4346
* </pre>
4447
*/
4548
public class StructuredModelsRoot extends ModelsRoot {
49+
private static final Logger LOG = LoggerFactory.getLogger( StructuredModelsRoot.class );
50+
4651
public StructuredModelsRoot( final Path path ) {
4752
super( path );
4853
}
@@ -83,8 +88,11 @@ public Stream<URI> namespaceContents( final AspectModelUrn namespace ) {
8388
.resolve( namespace.getNamespaceMainPart() )
8489
.resolve( namespace.getVersion() )
8590
.toFile();
86-
return Arrays.stream( Objects.requireNonNull( namespaceDirectory.listFiles( file ->
87-
file.getName().endsWith( ".ttl" ) ) ) )
88-
.map( File::toURI );
91+
final File[] files = namespaceDirectory.listFiles( file -> file.getName().endsWith( ".ttl" ) );
92+
if ( files == null ) {
93+
LOG.debug( "Supposed models root {} does not contain any .ttl files", namespaceDirectory );
94+
return Stream.empty();
95+
}
96+
return Arrays.stream( Objects.requireNonNull( files ) ).map( File::toURI );
8997
}
9098
}

core/esmf-aspect-model-serializer/src/main/java/org/eclipse/esmf/aspectmodel/serializer/AspectSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public String aspectToString( final Aspect aspect ) {
140140
}
141141

142142
// The Aspect has no source file, it was probably created programmatically.
143-
// Construct a virtual AspectModelFile with an RDF representation that be serialized.
143+
// Construct a virtual AspectModelFile with an RDF representation that can be serialized.
144144

145145
final RdfNamespace namespace = new SimpleRdfNamespace( "", aspect.urn().getUrnPrefix() );
146146
final Model rdfModel = new RdfModelCreatorVisitor( namespace ).visitAspect( aspect, null ).model();

documentation/developer-guide/modules/tooling-guide/pages/maven-plugin.adoc

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,44 @@ To include the plugin, use the following dependency:
1818
</dependency>
1919
----
2020

21-
NOTE: The current implementation of the `esmf-aspect-model-maven-plugin` uses the
22-
`FileSystemStrategy` to resolve Aspect Models. See
21+
[NOTE]
22+
====
23+
The current implementation of the `esmf-aspect-model-maven-plugin` uses the
24+
`FileSystemStrategy` or the `GitHubStrategy`, or combination of both, to resolve Aspect Models. See
2325
xref:java-aspect-tooling.adoc#understanding-model-resolution[Understanding Model Resolution] for
24-
more information.
26+
more information. Generally, the configuration for every Maven goal described here must be
27+
configured using either the `modelsRootDirectory` or the `githubServerId` attribute, or both.
28+
29+
The `modelsRootDirectory` points to a (relative or absolute) local file system directory path.
30+
31+
The `githubServerId` points to the `<id>` of a `<server>` configuration in the Maven settings. For
32+
example, if the configuration for the esmf-aspect-model-maven-plugin contains
33+
`<githubServerId>my-gh-repo</githubServerId>`, your https://maven.apache.org/settings.html[Maven
34+
Settings] should contain a corresonding `<server>` entry:
35+
36+
[source,xml,subs=attributes+]
37+
----
38+
<settings>
39+
<!-- ... -->
40+
<servers>
41+
<!-- ... -->
42+
<server>
43+
<id>my-gh-repo</id>
44+
<configuration>
45+
<!-- Which repository on GitHub does this server refer to -->
46+
<repository>ownername/repositoryname</repository>
47+
<!-- Which directory inside the repository is the models root -->
48+
<directory>src/main/resources/aspects</directory>
49+
<!-- branch (or tag) -->
50+
<branch>main</branch>
51+
<!-- Only required for private repositories: GitHub access token -->
52+
<token>...</token>
53+
</configuration>
54+
</server>
55+
</servers>
56+
</settings>
57+
----
58+
====
2559

2660
== Validating an Aspect Model
2761

@@ -45,6 +79,7 @@ Usage:
4579
</executions>
4680
<configuration>
4781
<modelsRootDirectory>$\{path-to-models-root}</modelsRootDirectory>
82+
<githubServerId>my-github-repo</githubServerId>
4883
<includes>
4984
<include>$\{urn-of-aspect-model-to-be-included}</include>
5085
</includes>
@@ -61,6 +96,7 @@ Configuration Properties:
6196
| Property | Description | Type | Default Value | Required
6297
| `detailedValidationMessages` | Print detailed validation messages | `Boolean` | `false` | {nok}
6398
| `modelsRootDirectory` | The path to the root directory containing the Aspect Model file(s). | `String` | `$\{basedir}/src/main/resources/aspects` | {nok}
99+
| `githubServerId` | The id of the `<server>` entry describing the GitHub repository to resolve models from. | `String` | none | {nok}
64100
| `includes` | A list of Aspect Model URNs identifying the Aspect Models to be included in the plugin execution. | `String` | none | {ok}
65101
|===
66102

@@ -106,6 +142,7 @@ Configuration Properties:
106142
| Property | Description | Type | Default Value | Required
107143
| `detailedValidationMessages` | Detailed validation messages if the model can not be loaded | `Boolean` | `false` | {nok}
108144
| `modelsRootDirectory` | The path to the root directory containing the Aspect Model file(s). | `String` | `$\{basedir}/src/main/resources/aspects` | {nok}
145+
| `githubServerId` | The id of the `<server>` entry describing the GitHub repository to resolve models from. | `String` | none | {nok}
109146
| `includes` | A list of Aspect Model URNs identifying the Aspect Models to be included in the plugin execution. | `String` | none | {ok}
110147
| `outputDirectory` | The path to the directory where the generated Java files will be written to. | `String` | none | {ok}
111148
| `packageName` | The package name for the generated Java files. This may also
@@ -164,6 +201,7 @@ Configuration Properties:
164201
| Property | Description | Type | Default Value | Required
165202
| `detailedValidationMessages` | Detailed validation messages if the model can not be loaded | `Boolean` | `false` | {nok}
166203
| `modelsRootDirectory` | The path to the root directory containing the Aspect Model file(s). | `String` | `$\{basedir}/src/main/resources/aspects` | {nok}
204+
| `githubServerId` | The id of the `<server>` entry describing the GitHub repository to resolve models from. | `String` | none | {nok}
167205
| `includes` | A list of Aspect Model URNs identifying the Aspect Models to be included in the plugin execution. | `String` | none | {ok}
168206
| `outputDirectory` | The path to the directory where the generated Java files will be written to. | `String` | none | {ok}
169207
| `packageName` | The package name for the generated Java files. This may also
@@ -217,6 +255,7 @@ Configuration Properties:
217255
| Property | Description | Type | Default Value | Required
218256
| `detailedValidationMessages` | Detailed validation messages if the model can not be loaded | `Boolean` | `false` | {nok}
219257
| `modelsRootDirectory` | The path to the root directory containing the Aspect Model file(s). | `String` | `$\{basedir}/src/main/resources/aspects` | {nok}
258+
| `githubServerId` | The id of the `<server>` entry describing the GitHub repository to resolve models from. | `String` | none | {nok}
220259
| `includes` | A list of Aspect Model URNs identifying the Aspect Models to be included in the plugin execution. | `String` | none | {ok}
221260
| `outputDirectory` | The path to the directory where the generated JSON Schema will be written to. | `String` | none | {ok}
222261
| `language` | The language from the model for which a JSON Schema should be generated. | `String` | en | {nok}
@@ -264,6 +303,7 @@ Configuration Properties:
264303
| Property | Description | Type | Default Value | Required
265304
| `detailedValidationMessages` | Detailed validation messages if the model can not be loaded | `Boolean` | `false` | {nok}
266305
| `modelsRootDirectory` | The path to the root directory containing the Aspect Model file(s). | `String` | `$\{basedir}/src/main/resources/aspects` | {nok}
306+
| `githubServerId` | The id of the `<server>` entry describing the GitHub repository to resolve models from. | `String` | none | {nok}
267307
| `includes` | A list of Aspect Model URNs identifying the Aspect Models to be included in the plugin execution. | `String` | none | {ok}
268308
| `outputDirectory` | The path to the directory where the generated OpenAPI Specification will be written to. | `String` | none | {ok}
269309
| `aspectApiBaseUrl` | The base URL for the Aspect API OpenAPI specification. | `String` | none | {ok}
@@ -325,6 +365,7 @@ Configuration Properties:
325365
|===
326366
| Property | Description | Type | Default Value | Required
327367
| `modelsRootDirectory` | The path to the root directory containing the Aspect Model file(s). | `String` | `$\{basedir}/src/main/resources/aspects` | {nok}
368+
| `githubServerId` | The id of the `<server>` entry describing the GitHub repository to resolve models from. | `String` | none | {nok}
328369
| `outputDirectory` | The path to the directory where the generated AsyncAPI Specification will be written to. | `String` | none | {ok}
329370
| `applicationId` | Sets the application id, e.g. an identifying URL | `String` | none | {nok}
330371
| `channelAddress` | Sets the channel address (i.e., for MQTT, the topic's name) | `String` | none | {nok}
@@ -373,6 +414,7 @@ Configuration Properties:
373414
|===
374415
| Property | Description | Type | Default Value | Required
375416
| `modelsRootDirectory` | The path to the root directory containing the Aspect Model file(s). | `String` | `$\{basedir}/src/main/resources/aspects` | {nok}
417+
| `githubServerId` | The id of the `<server>` entry describing the GitHub repository to resolve models from. | `String` | none | {nok}
376418
| `outputDirectory` | The path to the directory where the generated SQL script will be written to. | `String` | none | {ok}
377419
| `dialect` | The SQL dialect to generate for. | `String` | `databricks` | {nok}
378420
| `strategy` | The mapping strategy to use. | `String` | `denormalized` | {nok}
@@ -427,6 +469,7 @@ Configuration Properties:
427469
| Property | Description | Type | Default Value | Required
428470
| `detailedValidationMessages` | Detailed validation messages if the model can not be loaded | `Boolean` | `false` | {nok}
429471
| `modelsRootDirectory` | The path to the root directory containing the Aspect Model file(s). | `String` | `$\{basedir}/src/main/resources/aspects` | {nok}
472+
| `githubServerId` | The id of the `<server>` entry describing the GitHub repository to resolve models from. | `String` | none | {nok}
430473
| `includes` | A list of Aspect Model URNs identifying the Aspect Models to be included in the plugin execution. | `String` | none | {ok}
431474
| `outputDirectory` | The path to the directory where the generated HTML document will be written to. | `String` | none | {ok}
432475
| `htmlCustomCSSFilePath` | Path to a CSS file with custom styles to be included in the generated HTML documentation. | `String` | none | {nok}
@@ -476,6 +519,7 @@ Configuration Properties:
476519
| Property | Description | Type | Default Value | Required
477520
| `detailedValidationMessages` | Detailed validation messages if the model can not be loaded | `Boolean` | `false` | {nok}
478521
| `modelsRootDirectory` | The path to the root directory containing the Aspect Model file(s). | `String` | `$\{basedir}/src/main/resources/aspects` | {nok}
522+
| `githubServerId` | The id of the `<server>` entry describing the GitHub repository to resolve models from. | `String` | none | {nok}
479523
| `includes` | A list of Aspect Model URNs identifying the Aspect Models to be included in the plugin execution. | `String` | none | {ok}
480524
| `outputDirectory` | The path to the directory where the generated diagrams will be written to. | `String` | none | {ok}
481525
| `targetFormats` | A list formats in which the diagram(s) will be created. A diagram will be generated for each specified format. | `String` | none | {ok}
@@ -522,6 +566,7 @@ Configuration Properties:
522566
| Property | Description | Type | Default Value | Required
523567
| `detailedValidationMessages` | Detailed validation messages if the model can not be loaded | `Boolean` | `false` | {nok}
524568
| `modelsRootDirectory` | The path to the root directory containing the Aspect Model file(s). | `String` | `$\{basedir}/src/main/resources/aspects` | {nok}
569+
| `githubServerId` | The id of the `<server>` entry describing the GitHub repository to resolve models from. | `String` | none | {nok}
525570
| `includes` | A list of Aspect Model URNs identifying the Aspect Models to be included in the plugin execution. | `String` | none | {ok}
526571
| `outputDirectory` | The path to the directory where the generated JSON payload will be written to. | `String` | none | {ok}
527572
| `addTypeAttribute` | Adds a `@type` attribute for inherited Entities | `Boolean` | `false` | {ok}
@@ -566,6 +611,7 @@ Configuration Properties:
566611
| Property | Description | Type | Default Value | Required
567612
| `detailedValidationMessages` | Detailed validation messages if the model can not be loaded | `Boolean` | `false` | {nok}
568613
| `modelsRootDirectory` | The path to the root directory containing the Aspect Model file(s). | `String` | `$\{basedir}/src/main/resources/aspects` | {nok}
614+
| `githubServerId` | The id of the `<server>` entry describing the GitHub repository to resolve models from. | `String` | none | {nok}
569615
| `includes` | A list of Aspect Model URNs identifying the Aspect Models to be included in the plugin execution. | `String` | none | {ok}
570616
| `outputDirectory` | The path to the directory where the generated JSON-LD will be written to. | `String` | none | {ok}
571617
|===
@@ -614,6 +660,7 @@ Configuration Properties:
614660
| Property | Description | Type | Default Value | Required
615661
| `detailedValidationMessages` | Detailed validation messages if the model can not be loaded | `Boolean` | `false` | {nok}
616662
| `modelsRootDirectory` | The path to the root directory containing the Aspect Model file(s). | `String` | `$\{basedir}/src/main/resources/aspects` | {nok}
663+
| `githubServerId` | The id of the `<server>` entry describing the GitHub repository to resolve models from. | `String` | none | {nok}
617664
| `includes` | A list of Aspect Model URNs identifying the Aspect Models to be included in the plugin execution. | `String` | none | {ok}
618665
| `outputDirectory` | The path to the directory containing the pretty printed Aspect Model. | `String` | none | {ok}
619666
|===
@@ -663,6 +710,7 @@ Configuration Properties:
663710
| Property | Description | Type | Default Value | Required
664711
| `detailedValidationMessages` | Detailed validation messages if the model can not be loaded | `Boolean` | `false` | {nok}
665712
| `modelsRootDirectory` | The path to the root directory containing the Aspect Model file(s). | `String` | `$\{basedir}/src/main/resources/aspects` | {nok}
713+
| `githubServerId` | The id of the `<server>` entry describing the GitHub repository to resolve models from. | `String` | none | {nok}
666714
| `includes` | A list of Aspect Model URNs identifying the Aspect Models to be included in the plugin execution. | `String` | none | {ok}
667715
| `outputDirectory` | The path to the directory where the generated AAS file will be written to. | `String` | none | {ok}
668716
| `targetFormat` | The format to write, one of `aasx`, `xml` or `json`. | `String` | none | {ok}

tools/esmf-aspect-model-maven-plugin/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
<groupId>org.eclipse.esmf</groupId>
5757
<artifactId>esmf-aspect-model-starter</artifactId>
5858
</dependency>
59+
<dependency>
60+
<groupId>org.eclipse.esmf</groupId>
61+
<artifactId>esmf-aspect-model-github-resolver</artifactId>
62+
</dependency>
5963

6064
<dependency>
6165
<groupId>org.apache.maven.plugin-testing</groupId>

0 commit comments

Comments
 (0)