-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/474 load GitHub references #548
Feature/474 load GitHub references #548
Conversation
471d665
to
8238d21
Compare
...aspect-model-resolver/src/main/java/org/eclipse/esmf/aspectmodel/resolver/GroupStrategy.java
Outdated
Show resolved
Hide resolved
tools/samm-cli/src/main/java/org/eclipse/esmf/aspect/AspectMigrateCommand.java
Outdated
Show resolved
Hide resolved
547c8fd
to
b0668e0
Compare
33cee0a
to
634505a
Compare
634505a
to
3f924a9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR is missing two things:
- It seems the GitHub Resolver is not activated in the Maven Plugin (I only see one invocation of its
install()
method, which is in samm-cli). It should be usable there and its functionality also tested, at least on a basic level. I expect that a new property needs to be added to configure the GitHub models root. - It is completely missing user documentation. I expect changes:
- in java-aspect-tooling.adoc which explains the plugin loading mechanism in the AspectModelResolver
- in samm-cli.adoc which explains which URIs can be used as INPUT (e.g. only
file:
URIs and URLs which point to GitHub, but not other Git hosts and not SAMM URNs) - in maven-plugin.adoc which explains that/how the GitHub resolver is used from the Maven Plugin.
return addToModel( model, resolver.apply( version ).stream().map( TurtleLoader::openUrl ) ); | ||
final Model result = ModelFactory.createDefaultModel(); | ||
|
||
var error = resolver.apply( version ).stream() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable can be final
var error = resolver.apply( version ).stream() | ||
.map( url -> Try.withResources( url::openStream ) | ||
.of( TurtleLoader::loadTurtle ) | ||
.mapTry(Try::get) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please apply the project code style; see the conventions on options for automatic checks.
final Stream<String> subjectUri = statement.getSubject().isURIResource() | ||
? Stream.of( statement.getSubject().getURI() ) | ||
: Stream.empty(); | ||
final Stream<String> subjectUri = statement.getSubject().isURIResource() ? | ||
Stream.of( statement.getSubject().getURI() ) : Stream.empty(); | ||
final Stream<String> propertyUri = Stream.of( statement.getPredicate().getURI() ); | ||
final Stream<String> objectUri = statement.getObject().isURIResource() | ||
? Stream.of( statement.getObject().asResource().getURI() ) | ||
: Stream.empty(); | ||
final Stream<String> objectUri = statement.getObject().isURIResource() ? | ||
Stream.of( statement.getObject().asResource().getURI() ) : Stream.empty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert this formatting, the ?:
operators should be at the beginning of the line
* @return the resolved model on success | ||
*/ | ||
public Try<VersionedModel> resolveAspectModel( final ResolutionStrategy resolutionStrategy, final AspectModelUrn input ) { | ||
return resolveAspectModel( resolutionStrategy, List.of( input ) ); | ||
} | ||
|
||
public Try<VersionedModel> resolveAspectModel( final ResolutionStrategy resolutionStrategy, final URI input ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion we should not add this method to the resolver API. Aspect Models may contain only resources that use valid Aspect Model URNs as their URIs. While they can also refer to other URIs (e.g., the XSD types), these do not need to be resolved, i.e., they never point to anything that needs resolving. Having a resolution that takes an arbitrary URI as input however suggests otherwise.
*/ | ||
public class AspectModelResolver { | ||
private static final Logger LOG = LoggerFactory.getLogger( AspectModelResolver.class ); | ||
private static final List<Pair<Predicate<URI>, Function<URI, Try<ResolutionStrategy>>>> STRATEGY_BUILDERS = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having "default" resolvers here is a good idea. I'd prefer to have the types more specific though, since we do not resolve arbitrary URI
s but only AspectModelUrn
s (also see my other comment below). The ResolutionStrategy
is already function that takes the respective Aspect Model URN as input for resolution, I would not wrap this in another function that decides whether the resolver can resolve a given URI; it's the duty of the resolver to decide this. So I'd propose this:
- Instead of the
List<Pair>
, makeResolutionStrategy
also implementPredicate<AspectModelUrn>
so that it can decide and report if it can resolve a URN - Change this List accordingly to a
List<ResolutionStrategy>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After having read more of the PR, I think the URI here is not supposed to identify the model element to resolve (i.e. its AspectModelUrn) but is already the source for the model (URL or file:
URI)? In this case, I don't understand the setup at all; since this information is supposed to be known only to the ResolutionStrategy; the AspectModelResolver's task is only to execute the ResolutionStrategies and collect and merge their results. Where a model "comes from" should be encapsulated by the ResolutionStrategy.
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use wildcard imports
void setUp() throws IOException { | ||
testUrl = mock( URL.class ); | ||
when( testUrl.getHost() ).thenReturn( "github.com" ); | ||
// when( testUrl.toURI() ).thenReturn( URI.create( GITHUB_URL + GITHUB_FILE ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be removed?
@@ -13,20 +13,23 @@ | |||
|
|||
package org.eclipse.esmf; | |||
|
|||
import static org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver.fileToUrn; | |||
import static org.apache.commons.lang3.StringUtils.isBlank; | |||
import static org.eclipse.esmf.aspectmodel.resolver.AspectModelResolver.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use wildcard imports
? new File( uri ) | ||
: isBlank( uri.getScheme() ) | ||
? new File( uri.getPath() ) | ||
: null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Methods should never return null
(with very few exceptions, e.g., if you your method returns Try<Void>
, you can return Try.of(null)
). If the value could be missing, return Optional<File>
instead. Mapping URI
to File
is a partial function, i.e., not for every input value a corresponding output value can exists.
@@ -913,7 +913,7 @@ private String resolverCommand() { | |||
? ".bat" : ".sh" ) ).getCanonicalPath(); | |||
final String modelsRoot = new File( System.getProperty( "user.dir" ) + "/target/classes/valid" ).getCanonicalPath(); | |||
final String metaModelVersion = KnownVersion.getLatest().toString().toLowerCase(); | |||
return resolverScript + " " + modelsRoot + " " + metaModelVersion; | |||
return resolverScript + " " + modelsRoot + " " + metaModelVersion + " "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there a separate space at the end of the resolver command?
Was implemented here: #608 |
Fixes #474