Skip to content
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

Closed

Conversation

ysrbo
Copy link
Contributor

@ysrbo ysrbo commented Mar 19, 2024

Fixes #474

@ysrbo ysrbo force-pushed the feature/474-load-github-references branch 5 times, most recently from 471d665 to 8238d21 Compare March 20, 2024 06:55
@Yauhenikapl Yauhenikapl marked this pull request as ready for review March 20, 2024 09:03
@ysrbo ysrbo force-pushed the feature/474-load-github-references branch 4 times, most recently from 547c8fd to b0668e0 Compare March 21, 2024 06:52
@ysrbo ysrbo force-pushed the feature/474-load-github-references branch 2 times, most recently from 33cee0a to 634505a Compare March 28, 2024 08:05
@ysrbo ysrbo force-pushed the feature/474-load-github-references branch from 634505a to 3f924a9 Compare March 28, 2024 08:05
Copy link
Contributor

@atextor atextor left a 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:

  1. 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.
  2. It is completely missing user documentation. I expect changes:
    1. in java-aspect-tooling.adoc which explains the plugin loading mechanism in the AspectModelResolver
    2. 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)
    3. 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()
Copy link
Contributor

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)
Copy link
Contributor

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.

Comment on lines -90 to +96
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();
Copy link
Contributor

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 ) {
Copy link
Contributor

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<>();
Copy link
Contributor

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 URIs but only AspectModelUrns (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>, make ResolutionStrategy also implement Predicate<AspectModelUrn> so that it can decide and report if it can resolve a URN
  • Change this List accordingly to a List<ResolutionStrategy>

Copy link
Contributor

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.

Comment on lines +4 to +5
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
Copy link
Contributor

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 )
Copy link
Contributor

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.*;
Copy link
Contributor

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;
Copy link
Contributor

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 + " ";
Copy link
Contributor

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?

@Yauhenikapl
Copy link
Contributor

Was implemented here: #608

@atextor atextor deleted the feature/474-load-github-references branch August 21, 2024 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task] Load model with references from github
3 participants