-
Notifications
You must be signed in to change notification settings - Fork 77
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
Introduced a new resolver for the mvn:///
scheme.
#1962
Conversation
…mvn scheme. to be tested
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1962 +/- ##
=======================================
Coverage 49% 49%
- Complexity 6244 6261 +17
=======================================
Files 664 665 +1
Lines 59572 59620 +48
Branches 8635 8645 +10
=======================================
+ Hits 29319 29385 +66
+ Misses 28054 28035 -19
- Partials 2199 2200 +1 ☔ View full report in Codecov by Sentry. |
…MavenRepositoryResolver
Needs a few tests but they are hard to write given that the most used feature is really simple, while the funny exceptions mess with the configuration that the current build depends on. |
mvn:///
scheme.
…dhere to the syntax rules of not having dots in the artifactId. So now the separator is ! exlamation mark which works perfectly
@DavyLandman This is now tested on my big .m2 folder, which includes tycho/eclipse projects and many other weirdly named projects. Too bad we could not use A next PR will introduce |
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.
Looks good, it's a bit of a pity we end up calling mvn as a fallback.
The only question I have is about the encoding inside of the authority. why not make it path based?
* So the authority encodes the identity of the maven project and the path encodes | ||
* what's inside the respective jar file. | ||
* | ||
* Here version is [0-9]+ major . [0-9]+ minor .[0-9]+ path -[A-Za-z\-]* optionalTag |
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.
typo: path
-> patch
* version reference in the authority pattern, by design. Any automated resolution here would | ||
* make the dependency management downstream less transparant and possibly error-prone. | ||
* | ||
* This resolver also does not implement any download or installation procedure, by design. |
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 is the one thing I'm missing from this PR, or is that intended in a later PR?
I guess it's because we're refering to a local maven repo with the mvn
scheme, not the global public one (which would import a "where is the repo located" problem?)
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.
Yes it's important to separate concerns here:
- The mvn:/// names are intended as the unambiguous result of dependency resolution.
- If dependency resolution requires download or installation; those two have to be implemented as human interactive processes or bundling has to be done explicitly by a responsible developer. There are legal implications here that should not belong with an automated scheme resolver.
- Transparency is of the utmost importance, in particular these new names must make it clear when/if a project is resolved with more than one different version.
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.
Finally I really want this resolver to be quiet on the printing to stderr front. Now that the resolver is transparent, a quick view of the current path config is fully informative while before the lib:/// resolver had to print a log for transparancy purposes. A download feature would also require ugly visual logs every time it happened.
public class MavenRepositoryURIResolver extends AliasedFileResolver { | ||
private final Pattern authorityRegEx | ||
= Pattern.compile("^([a-zA-Z0-9-_.]+?)[!]([a-zA-Z0-9-_.]+)([!][a-zA-Z0-9\\-_.]+)$"); | ||
// groupId ! artifactId ! optionAlComplexVersionString |
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.
would regular /
not work as separators? I'm asking since in other places we used !
to go into a jar/zip.
So we would have:
mvn://groupId/artifactId/version!fileInsideTheJar.txt
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.
/ is not allowed in authorities
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.
We use ! here too to go into the jar. See below.
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 is why the ! is a good character to use. We've used it before to avoid overlap with filenames; and that seemed ok. Every other character that is not a / or a ! or a . is a bad separator because people are allowed to use then in filenames.
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.
. ended up not to work because people don't follow the maven naming rules.
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.
I meant, groupid as authority, and the rest for regular paths?
Alternative: we could even use authority to distinguish between local and remote maven repo
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.
- Remote maven repo's are something to think about very carefully, in a legal sense. I don't want to blur that distinction anywhere. So for this scheme that is out of the question.
- I want the authority to identify a jar, a project scope, just like the other schemes we use for this, project, plugin, bundle, etc. That way the path is always consistently rooted at the base of a file name space. I don't want our Rascal code to have to split loc paths based on some arbitrary knowledge about the specific scheme.
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 last point makes code that runs directly from target folders or project schemes and from an mvn jar, or from an eclipse plugin, or OSGI bundle, etc. etc. much easier to make correct, because loc.path
will produce the same postfix in every situation.
I started with that, but the puzzle pieces wouldn't fit.
Still it would be possible in theory to make it all work as path strings as well. With judicious uses of the |
I don't like that either. The alternative is to parse the XML itself. I decided that when we have built-in maven support in the core runtime, we can revisit this code and just query the configuration API directly. However, as this code is run via static initialization (via reg.getInstance()) ; there will still be considerable hoops to jump through before we can call from this resolver into the maven implementation. I'm not so sure that will work. At least let's delay the XML parsing here until we know what's the deal. |
Also this is where I fell to one knee; because even if the .m2 folder exists the config.xml would still take precedence. I choose to break this in favor of efficiency. If you really want to config another .m2 folder you should remove the one from your home directory for this scheme to work. Of course this makes the current code much much faster in case of the default setup. |
@DavyLandman thanks for the Sunday review 🤓👍🤩 |
If this
mvn://<groupId>!<artifactId>!<versionWithoptionalReleaseTag>
scheme works properly, it can transparantly replace all thelib://<artifactId/
usages.file:///
URIs. This important for efficiency as themvn://
paths end up in classloader situations where they are short-circuited into highly optimized URLclassloaders.<path>/<to>/<groupId>/<artifactId>/<version>/<artifactId>-<version>.jar
and nothing more and nothing less.mvn:///
the authority-less root resolves to the root of the local maven repository for exploration purposes.-Dmaven.repo.local=<whatever>
is set, the root iswhatever
~/.m2
exists, the root is~/.m2/repository
<localRepository>something</localRepository>
is set insettings.xml
in the maven installation folder, then the root issomething
~/.m2/repository
!
separators are essential; we first tried with.
because of style, but while testing on real local repositories (big ones) we found many projects to have.
in their artifact names. That led to ambigous parsing of the authority which is not stable.For Eclipse projects we were already using
plugin://
andbundle://
for dependencies transparantly. Thelib:///
scheme did not add anything much there anyway.A new PR will make the necessary adjustments to the PathConfig and RascalManifest configuration algorithms for the interpreter and the compiler. This one focuses only on adding the resolution capability for the
mvn
scheme. It is quite possible that after these changes theRequired-Libraries
configuration option is no longer use{d,ful} and we can get rid of it.