|
13 | 13 |
|
14 | 14 | package org.eclipse.esmf.aspectmodel;
|
15 | 15 |
|
16 |
| -import static java.util.stream.Collectors.toSet; |
17 |
| - |
18 | 16 | import java.io.FileOutputStream;
|
19 | 17 | import java.io.IOException;
|
20 | 18 | import java.nio.file.Files;
|
21 | 19 | import java.nio.file.Path;
|
| 20 | +import java.util.HashMap; |
22 | 21 | import java.util.HashSet;
|
23 | 22 | import java.util.List;
|
| 23 | +import java.util.Map; |
24 | 24 | import java.util.Set;
|
25 | 25 |
|
26 | 26 | import org.eclipse.esmf.aspectmodel.loader.AspectModelLoader;
|
@@ -59,35 +59,37 @@ protected void validateParameters() throws MojoExecutionException {
|
59 | 59 | }
|
60 | 60 |
|
61 | 61 | protected Set<Aspect> loadAspects() throws MojoExecutionException {
|
62 |
| - Set<AspectModel> models = loadModels(); |
63 |
| - return models.stream().map( AspectModel::aspect ).collect( toSet() ); |
| 62 | + return new HashSet<>( loadAspectModels().values() ); |
64 | 63 | }
|
65 | 64 |
|
66 | 65 | protected Set<AspectModel> loadModels() throws MojoExecutionException {
|
67 |
| - try { |
68 |
| - final Path modelsRoot = Path.of( modelsRootDirectory ); |
69 |
| - final ResolutionStrategy fileSystemStrategy = new FileSystemStrategy( modelsRoot ); |
70 |
| - final Set<AspectModel> result = new HashSet<>(); |
| 66 | + return new HashSet<>( loadAspectModels().keySet() ); |
| 67 | + } |
| 68 | + |
| 69 | + private Map<AspectModel, Aspect> loadAspectModels() throws MojoExecutionException { |
| 70 | + final Path modelsRoot = Path.of( modelsRootDirectory ); |
| 71 | + final ResolutionStrategy fileSystemStrategy = new FileSystemStrategy( modelsRoot ); |
| 72 | + final Map<AspectModel, Aspect> result = new HashMap<>(); |
71 | 73 |
|
72 |
| - for ( final String inputUrn : includes ) { |
73 |
| - final AspectModelUrn urn = AspectModelUrn.fromUrn( inputUrn ); |
74 |
| - final Either<List<Violation>, AspectModel> loadingResult = new AspectModelValidator().loadModel( () -> |
75 |
| - new AspectModelLoader( fileSystemStrategy ).load( urn ) ); |
76 |
| - if ( loadingResult.isLeft() ) { |
77 |
| - final List<Violation> violations = loadingResult.getLeft(); |
78 |
| - final String errorMessage = detailedValidationMessages |
79 |
| - ? new DetailedViolationFormatter().apply( violations ) |
80 |
| - : new ViolationFormatter().apply( violations ); |
81 |
| - throw new MojoExecutionException( errorMessage ); |
82 |
| - } |
83 |
| - result.add( loadingResult.get() ); |
| 74 | + for ( final String inputUrn : includes ) { |
| 75 | + final AspectModelUrn urn = AspectModelUrn.fromUrn( inputUrn ); |
| 76 | + final Either<List<Violation>, AspectModel> loadingResult = new AspectModelValidator().loadModel( () -> |
| 77 | + new AspectModelLoader( fileSystemStrategy ).load( urn ) ); |
| 78 | + if ( loadingResult.isLeft() ) { |
| 79 | + final List<Violation> violations = loadingResult.getLeft(); |
| 80 | + final String errorMessage = detailedValidationMessages |
| 81 | + ? new DetailedViolationFormatter().apply( violations ) |
| 82 | + : new ViolationFormatter().apply( violations ); |
| 83 | + throw new MojoExecutionException( errorMessage ); |
84 | 84 | }
|
85 |
| - return result; |
86 |
| - } catch ( final MojoExecutionException exception ) { |
87 |
| - throw exception; |
88 |
| - } catch ( final Throwable throwable ) { |
89 |
| - throw new MojoExecutionException( "Processing error while loading Aspects", throwable ); |
| 85 | + final AspectModel aspectModel = loadingResult.get(); |
| 86 | + final Aspect aspect = aspectModel.aspects().stream() |
| 87 | + .filter( theAspect -> theAspect.urn().equals( urn ) ) |
| 88 | + .findFirst() |
| 89 | + .orElseThrow( () -> new MojoExecutionException( "Loaded Aspect Model does not contain Aspect " + urn ) ); |
| 90 | + result.put( aspectModel, aspect ); |
90 | 91 | }
|
| 92 | + return result; |
91 | 93 | }
|
92 | 94 |
|
93 | 95 | protected FileOutputStream getOutputStreamForFile( final String artifactName, final String outputDirectory ) {
|
|
0 commit comments