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

Ci friendly #77

Merged
merged 9 commits into from
Dec 14, 2018
Merged

Ci friendly #77

merged 9 commits into from
Dec 14, 2018

Conversation

lasselindqvist
Copy link
Collaborator

Here is one possible implementation of CI friendly variable resolver.

This has some things I don't personally like. For example CiInterpolatorImpl just basically replicates StringSearchInterpolator because first I tried to extend it and overwrite just some of the methods but that lead to weird classloading issues that I didn't have the energy to solve.

Also resolving variables inside profile dependencies doesn't work as it should but that is because of the multiple other problems in profile resolving in the flatten plugin.

Now I have found out that there might be some better solutions to flattening CI variables in poms. Like https://github.com/fmarot/cifriendly-maven-plugin which seems to be a much simpler approach to solving just this one problem. I haven't tried that plugin though.

Anyway, I just wanted to leave this so that other people can access this particular solution if it is what they need in their projects.

import java.util.Collection;
import java.util.List;
import java.util.Properties;

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please undo the reformatting...cause that covers the real changes...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be better now.

@fmarot
Copy link

fmarot commented Sep 23, 2018

Lol ! I am the author of https://github.com/fmarot/cifriendly-maven-plugin and was eagerly awaiting your solution to flatten only the version number as being part of flatten-maven-plugin would have made it the de-facto standard for Maven.
In the past I had experimented with flatten-maven-plugin and have had some "surprises" (It was a long time ago but I think it interfered with some OS dependant properties depending on the build OS) so making sure it would only interfere with one specific property was exactly what I was looking for.
Regarding my plugin the flatten/unflatten goals do the job but I do not like having to modify files before building (and the maven release plugin dislikes it even more). My plugin also include since recently a rip-off of this plugin https://github.com/jgitver/jgitver where it acts as a maven extension to substitute original poms with new ones where the version is calculated at runtime. Beware: I would not call my plugin production-ready but can improve it if need be.

While we're at it and @khmarbaise may be looking :) if I may, I think that Maven really need a standard and simple solution to "just replace the version number when it is a variable" without relying on a plugin, especially the flatten plugin that does much more than that. And goof support in the IDE (when having multiple projects) is also needed so it would help (I thnik) if this feature was in the core Maven.

Sorry to have a bit hijacked the thread...

@lasselindqvist lasselindqvist force-pushed the ci-friendly branch 3 times, most recently from 02f238f to 803a1fe Compare September 24, 2018 06:37
@lasselindqvist
Copy link
Collaborator Author

Yes. It would be nice to have this as part of the "official" Flatten plugin as it is more likely for people to use it. So I this functionality makes it into the plugin in one way or the other.

Btw, my local build runs the new integration test fine, but the Travis CI apparently does not. I cannot see it or test it, but maybe it has the classloading issue that I got rid of locally by not extending the existing classes.

I don't currently have much time for contributing but might take a look at the profile handling in the future.

@bertramn bertramn mentioned this pull request Sep 26, 2018
@bertramn
Copy link

Not sure how valid below is but if I put something like this into a module in a multi-module pom:

<properties>
  <jackson.version>2.9.6</jackson.version>
</properties>

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.fasterxml.jackson</groupId>
      <artifactId>jackson-bom</artifactId>
      <version>${jackson.version}</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

I get these type of errors:

[ERROR] Failed to execute goal org.codehaus.mojo:flatten-maven-plugin:1.1.0-SNAPSHOT:flatten (flatten) on project multi-module-parent: 1 problem was encountered while building the effective model for com.example:multi-module-parent:2.0.10-SNAPSHOT
[ERROR] [FATAL] Non-readable POM /Users/fred/.m2/repository/com/fasterxml/jackson/jackson-bom/${jackson.version}/jackson-bom-${jackson.version}.pom: /Users/fred/.m2/repository/com/fasterxml/jackson/jackson-bom/${jackson.version}/jackson-bom-${jackson.version}.pom (No such file or directory) @ /Users/fred/.m2/repository/com/fasterxml/jackson/jackson-bom/${jackson.version}/jackson-bom-${jackson.version}.pom

@lasselindqvist
Copy link
Collaborator Author

This is caused by the block
if (flattenMode == FlattenMode.resolveCiFriendliesOnly) {
defaultModelBuilder.setModelInterpolator(new CiModelInterpolator());
}
on lines 764-766 in FlattenMojo.java. It doesn't belong there and was left accidentally after testing the solution. I made a test for the parent dependency case and will publish the changes soon. Also I will make a test case for multi-module poms.

@lasselindqvist
Copy link
Collaborator Author

The unnecessary block was removed.
One integration test complete-multimodule-parent-pom-cifriendly was added for multi-module projects.
One integration test inherit-parent-dependencyManagement-cifriendly was added for cases where dependency versions are inherit from parents with version defined in properties.
FlattenMode had to be changed so that version is resolved instead of interpolating, otherwise the default revision property is used instead of the one given by the invoker. Also the parent block has to be resolved instead of interpolating, otherwise the revision variable in the parent version does not get resolved.

@lasselindqvist
Copy link
Collaborator Author

Based on the Travis CI build log I would guess that the build problem is caused by the fact that the Travis CI build does not use the invoker.properties file unlike my local build.

@patrickjamesbarry
Copy link

Eagerly waiting on this new feature! Thanks for putting some work behind it!

@lasselindqvist
Copy link
Collaborator Author

The JDK8 build seems to work now (https://travis-ci.org/mojohaus/flatten-maven-plugin/builds/437944243) when the revision is given in the maven-invoker-plugin configuration instead of invoker.properties. Maybe it is a security feature in Travis CI or a bug/feature in maven-invoker-plugin.

@patrickjamesbarry
Copy link

Does the ci job just need to be re-kicked? Looks like the build issue with older jdks were addressed in #75.

@lasselindqvist
Copy link
Collaborator Author

I will rebase this pull request once #75 has been merged to master branch and then we will get a new build.

@hohwille
Copy link
Member

Thanks for your work on this and all the added tests.
Could you shed some light into resolveCiFriendliesOnly.
Does Ci here stand for continuous integration? If yes, why?
I actually do not really get the point of the name resolveCiFriendliesOnly and do not think it is intuitive.
I assume you are aware that you can do create any custom config without modifying the plugin itself?

@lasselindqvist
Copy link
Collaborator Author

The CI friendly is a reference to https://maven.apache.org/maven-ci-friendly.html. CI does stand for continuous integration. The name could be something else, but I don't really have any better suggestions for it.
You can achieve close to the same functionality by just resolving the parent, version and dependencies, but this implementation resolves only the three ci-friendly variables and is a bit more correct if you need to have other unresolved variables in your pom.

@patrickjamesbarry
Copy link

Is this PR ready to merge?

@lasselindqvist
Copy link
Collaborator Author

@hohwille are there any intentions to merge or decline this?

@deathrowe
Copy link

All I want for Christmas... is for this to merge!!! 😄

Copy link
Member

@hohwille hohwille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I got things right, you want to replace only the three variables that you predefined and hardcoded into this new flatten mode. It would also be insightful to understand more about the undesired side-effects of flatten-maven-plugin that you want to avoid with this new mode (if I got you right you were talking about system properties like maybe java.home or something that otherwise get accidentally replaced if used in POM - is that the case? Should instead then that be considered as a bug and be fixed?).

My biggest concern is that the name of the new mode and especially the 3 hardcoded variables with their names and meanings do not seem to be following a convincing design.
This might just be my personal point of view. I have no idea how many people were involved in this and came up with the "Maven CI Friendly Versions" documentation published on the maven site maybe after long discussions and smart thoughts I might not get.
I see that you want to have this feature deadly and I might seem as a stupid guy not reacting for ages and now complaining with picky reviews.
@khmarbaise / @mojohaus/owners do you agree with my point of view or am I just picky. I do not want to be a spoilspot here...

@@ -219,7 +219,7 @@
</properties>
<goals>
<goal>clean</goal>
<goal>${project.groupId}:${project.artifactId}:${project.version}:flatten</goal>
<goal>${project.groupId}:${project.artifactId}:${project.version}:flatten -Drevision=1.2.3.4</goal>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having a fixed revision for all tests seems kind of unflexible but that can be resolved later...

Copy link
Collaborator Author

@lasselindqvist lasselindqvist Dec 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary if we want to run the integration tests in Travis. For some reason it doesn't use the ones given in invoker.properties even though in local builds they are used.
I am not sure if the problem is with Travis or the Invoker plugin.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, got it. You explained that earlier. Sorry, that I did not got it directly... Considered done. If someone finds a nicer solution can still be improved after merge...

@@ -0,0 +1,13 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indendation is 2 in other existing files.

@@ -0,0 +1 @@
invoker.mavenOpts = -Drevision=1.2.3.4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, this is the nice solution. Can we strip the revision system property from the plugins toplevel pom then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Referring to the other answer, this is what I tried first and forgot to remove it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is working outside travis (event with out having it in pom) please leave it here. Otherwise please cleanup.

fatjar,

/** Only resolves variables revision, sha and changelist. Keeps everything else. */
resolveCiFriendliesOnly;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed in the issue the name is not very good. Already resolveCiVaraiblesOnly would be a little better. Still thinking of something better. After all who defined this (https://maven.apache.org/maven-ci-friendly.html). To tell it straigth away:

  • the linked documentation states about sha1 you write sha here.
  • sha/sha1 is a particular hash algorithm. It is also already getting obsolete and is attacked. If you are naming a variable you should not use the name of the algorithm esp. if you set it as system property. How about checksum or hash?
  • Who came up with the name changelist? If that is for -SNAPSHOT or an empty string this is also entirely odd. A Changelist is something like this: https://en.wikipedia.org/wiki/Version_control#Common_vocabulary also it can easily be mistaken for a changelog (there is maven changes plugin and maven changelog plugin).

This is my actual concern...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no knowledge about the origins of the "Maven CI Friendly Versions" documentation, so I cannot answer about it. The purpose is to just resolve the variables that are stated there, but I think mostly the use case would be for "revision".
"sha" should be "sha1".
I am fine with any naming for the variable.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure there is no misunderstanding (I am awaiting this PR): the guys at the head of Maven (@khmarbaise & al) themselves came up with 3 harcoded variable names that are possible to be accepted as variable part of the version. This is what is usually called "CI Friendly Maven". This may not be the best choice, there may have been different alternative implementations, but to this day this is the current status of Core Maven. Knowing the forward compatible history of Maven, I doubt they will change. So there is really no need to try to find alternatives here. Even non core plugin should just reuse what Maven user are (or will be) familiar with, the way of naming things (CIFriendly, sha1, changelist & revision) should be the same.
My 2 cents

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fmarot could you shed in some light here? Do you agree to some of my points or do you have some arguments for your PoV?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lasselindqvist as you are so superb fast and active in updating the PR:
would it be possible that you link to the original documentation from the javadoc then like this:

See Maven CI Friendly for further details.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, each subject one after another:

  • resolveCiFriendliesOnly vs resolveCiVariablesOnly : I prefer the former to keep it linked with the Maven Core vocabulary of "CI Friendly". But it is not very important
  • sha1 VS sha in the comment : @lasselindqvist already corrected it
  • rename sha1 to a more generic word: this is a no go as Maven Core uses explicitly "sha1" as one of the 3 allowed keywords.
  • changelist : same as above. the Flatten plugin has no choice but to comply with the wording of Maven Core. Otherwise users would not understand.
    (just trying to help here ;) thanks for your work both of you)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fmarot thanks for the quick feedback. I was not aware if this is just something a single guy came up with - but if maven core already adopted this I do not want to fight anything here. I just want to care about design and quality and avoide foolish decisions ;)
@khmarbaise can you confirm this.
IMHO we could then merge this and maybe I might even be able to push out a new release before xmas.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.



/**
* {@inheritDoc}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check your IDE settings (Eclipse templates). {@inheritDoc} JavaDoc tag is obsolete since java 1.6 and replaced by @Override annotation.

{
result.append( input, endIdx + 1, input.length() );
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woho. Can't this ~120 lines of code be reduced to a view lines using regex, findFirst and replace? In the end you are only looking for 3 fixded given expressions. Also you could directly indexOf or replace for that 3 variables if they are hardcoded anyhow... Just looks overcomplicated to me. I might also be missing something. Just a suggestion, nothing that could not be accepted as is. A regular JUnit for this would be helpful and more explanatory as well...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CiInterpolatorImpl just basically replicates StringSearchInterpolator from plexus-interpolation with small changes so that it only replaces those three variables. It is ugly, but works with the same behavior as the resolving of other variables in the plugin. Using regex might detect and resolve circular and nested variables differently.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfectly fine then. Get the point. Maybe a link to the "copied" implementation (StringSearchInterpolator) in the javadoc ({@link package.name.StringSearchInterpolator}) with such hint would be lovely.

Change 'sha' to 'sha1' in resolveCiFriendliesOnly comment
invoker.mavenOpts = -Drevision=1.2.3.4 since Travis CI builds does not use them anyway so it is misleading
Replace tabs with 2 spaces as all the other XML files use 2 tabs as the indentation.
Add a reference to https://maven.apache.org/maven-ci-friendly.html in resolveCiFriendliesOnly documentation.
Link to StringSearchInterpolator and explain the difference to the original in the class Javadoc.
Copy link
Member

@hohwille hohwille left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lasselindqvist thanks for the quick reactions and improvements to my review feedback.

As the CI friendly variables are already defined by maven and out in the wild for 2 years this seems fine to me now. Thanks to all contributing and clarifying.

@hohwille hohwille merged commit 00e7cec into mojohaus:master Dec 14, 2018
@hohwille hohwille added this to the 1.1.0 milestone Dec 14, 2018
@hohwille
Copy link
Member

All I want for Christmas...

Here is your package. Please vote:
https://groups.google.com/forum/#!topic/mojohaus-dev/u28wlFOuSrU

Also please note that you broke the javadoc and I had to rebuild manually with doclint disabled.
Further you forgot to document the new mode in the JavaDoc of the flattenMode parameter:
http://www.mojohaus.org/flatten-maven-plugin/flatten-mojo.html#flattenMode

I was not so picky for the review to not block this any further. However, it would be lovely if you could provide a PR with these additional cleanups. In case you would do that, do not rush - its Christmas time so first enjoy being with your family. Can be done next year as well...

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.

7 participants