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

[3.8.x][MNG-7407] Introduce a ModelVersionProcessor component to make CI Friends Versions pluggable #674

Closed
wants to merge 1 commit into from

Conversation

laeubi
Copy link

@laeubi laeubi commented Feb 2, 2022

Currently the handling for https://maven.apache.org/maven-ci-friendly.html is hard wired into maven.

For Tycho we like to replace/extend the default handling for this to supply the user with some automatic derived values for some of the variables.

This PR extracts the parts of that handling in a new ModelVersionProcessor that has the current behavior as a default implemented. This not only makes it more clear how this is handled (no cross references between DefaultModelValidator and AbstractStringBasedModelInterpolator required) but also allows to override the handling by a core extension.

FYI @mickaelistria @akurtakov

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without
    pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [MNG-XXX] SUMMARY, where you replace MNG-XXX
    and SUMMARY with the appropriate JIRA issue. Best practice is to use the JIRA issue
    title in the pull request title and in the first line of the commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean verify to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the Core IT successfully.

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

}
if ( request.getSystemProperties().containsKey( SHA1_PROPERTY ) )
{
modelProperties.put( SHA1_PROPERTY, request.getSystemProperties().get( SHA1_PROPERTY ) );
Copy link
Member

Choose a reason for hiding this comment

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

@rfscholte I believe that this is a bug in our code since those are are supposed to be user properties and not system properties or we need to support both. @laeubi Not a regression from you, but an observation.

Copy link
Author

Choose a reason for hiding this comment

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

As far as I understand the idea ias that system properties given on the command line take precedence over everything else.

Copy link
Member

Choose a reason for hiding this comment

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

True, but those are not system properties, those are user properties. A common misconception and badly coined in the Maven core codebase. See:

private static void setCliProperty( String name, String value, Properties properties )
{
properties.setProperty( name, value );
// ----------------------------------------------------------------------
// I'm leaving the setting of system properties here as not to break
// the SystemPropertyProfileActivator. This won't harm embedding. jvz.
// ----------------------------------------------------------------------
System.setProperty( name, value );
}

Copy link
Author

Choose a reason for hiding this comment

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

Okay I have changed the PR accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

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

@rfscholte I believe that this is a bug in our code since those are are supposed to be user properties and not system properties or we need to support both.

It should be at least user properties. That's probably enough, as I expect that's the way CI servers can provide a value.

Copy link
Member

@michael-o michael-o left a comment

Choose a reason for hiding this comment

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

Looks sane to me, needs testing though. Open questions:

  • Why for Maven 3.8.x only? No master?
  • The title is misleading. What you actually did is to move a default implementation to a replace component. @cstamas Did this also in resolver. May be can better rewording this to something like: Introduce a ModelVersionProcessor component to make CI Friends Versions pluggable
  • Can this be covered by a test somehow?

@laeubi
Copy link
Author

laeubi commented Feb 6, 2022

* Why for Maven 3.8.x only? No master?

I can open a PR for master also.

* The title is misleading. What you actually did is to move a default implementation to a replace component. @cstamas Did this also in resolver. May be can better rewording this to something like: Introduce a ModelVersionProcessor component to make CI Friends Versions pluggable

Sure do you simply want to rename the PR or should I do so?

* Can this be covered by a test somehow?

There are already some tests for this functionality that also run fine with this changes.

@michael-o
Copy link
Member

michael-o commented Feb 6, 2022

* Why for Maven 3.8.x only? No master?

I can open a PR for master also.

Yes, please.

* The title is misleading. What you actually did is to move a default implementation to a replace component. @cstamas Did this also in resolver. May be can better rewording this to something like: Introduce a ModelVersionProcessor component to make CI Friends Versions pluggable

Sure do you simply want to rename the PR or should I do so?

Yes, please. PR and JIRA issue.

* Can this be covered by a test somehow?

There are already some tests for this functionality that also run fine with this changes.

Please point me to them.

@laeubi
Copy link
Author

laeubi commented Feb 6, 2022

Please point me to them.

I think this is where it is tested

public void testCiFriendlySha1()
throws Exception
{
SimpleProblemCollector result = validateRaw( "raw-model/ok-ci-friendly-sha1.xml" );
assertViolations( result, 0, 0, 0 );
}
@Test
public void testCiFriendlyRevision()
throws Exception
{
SimpleProblemCollector result = validateRaw( "raw-model/ok-ci-friendly-revision.xml" );
assertViolations( result, 0, 0, 0 );
}
@Test
public void testCiFriendlyChangeList()
throws Exception
{
SimpleProblemCollector result = validateRaw( "raw-model/ok-ci-friendly-changelist.xml" );
assertViolations( result, 0, 0, 0 );
}
@Test
public void testCiFriendlyAllExpressions()
throws Exception
{
SimpleProblemCollector result = validateRaw( "raw-model/ok-ci-friendly-all-expressions.xml" );
assertViolations( result, 0, 0, 0 );
}
@Test
public void testCiFriendlyBad()
throws Exception
{
SimpleProblemCollector result = validateRaw( "raw-model/bad-ci-friendly.xml" );
assertViolations( result, 0, 0, 1 );
assertEquals( "'version' contains an expression but should be a constant.", result.getWarnings().get( 0 ) );
}
@Test
public void testCiFriendlyBadSha1Plus()
throws Exception
{
SimpleProblemCollector result = validateRaw( "raw-model/bad-ci-friendly-sha1plus.xml" );
assertViolations( result, 0, 0, 1 );
assertEquals( "'version' contains an expression but should be a constant.", result.getWarnings().get( 0 ) );
}
@Test
public void testCiFriendlyBadSha1Plus2()
throws Exception
{
SimpleProblemCollector result = validateRaw( "raw-model/bad-ci-friendly-sha1plus2.xml" );
assertViolations( result, 0, 0, 1 );
assertEquals( "'version' contains an expression but should be a constant.", result.getWarnings().get( 0 ) );
}

@laeubi laeubi changed the title MNG-7407 Allow core-extension to override default CI-Firendly-Versions handling [3.8.x][MNG-7407] Introduce a ModelVersionProcessor component to make CI Friends Versions pluggable Feb 6, 2022
@laeubi
Copy link
Author

laeubi commented Feb 6, 2022

Title updated as you suggested.

@michael-o
Copy link
Member

Please point me to them.

I think this is where it is tested

public void testCiFriendlySha1()
throws Exception
{
SimpleProblemCollector result = validateRaw( "raw-model/ok-ci-friendly-sha1.xml" );
assertViolations( result, 0, 0, 0 );
}
@Test
public void testCiFriendlyRevision()
throws Exception
{
SimpleProblemCollector result = validateRaw( "raw-model/ok-ci-friendly-revision.xml" );
assertViolations( result, 0, 0, 0 );
}
@Test
public void testCiFriendlyChangeList()
throws Exception
{
SimpleProblemCollector result = validateRaw( "raw-model/ok-ci-friendly-changelist.xml" );
assertViolations( result, 0, 0, 0 );
}
@Test
public void testCiFriendlyAllExpressions()
throws Exception
{
SimpleProblemCollector result = validateRaw( "raw-model/ok-ci-friendly-all-expressions.xml" );
assertViolations( result, 0, 0, 0 );
}
@Test
public void testCiFriendlyBad()
throws Exception
{
SimpleProblemCollector result = validateRaw( "raw-model/bad-ci-friendly.xml" );
assertViolations( result, 0, 0, 1 );
assertEquals( "'version' contains an expression but should be a constant.", result.getWarnings().get( 0 ) );
}
@Test
public void testCiFriendlyBadSha1Plus()
throws Exception
{
SimpleProblemCollector result = validateRaw( "raw-model/bad-ci-friendly-sha1plus.xml" );
assertViolations( result, 0, 0, 1 );
assertEquals( "'version' contains an expression but should be a constant.", result.getWarnings().get( 0 ) );
}
@Test
public void testCiFriendlyBadSha1Plus2()
throws Exception
{
SimpleProblemCollector result = validateRaw( "raw-model/bad-ci-friendly-sha1plus2.xml" );
assertViolations( result, 0, 0, 1 );
assertEquals( "'version' contains an expression but should be a constant.", result.getWarnings().get( 0 ) );
}

Indeed, this should be enough for the default implementation.

@laeubi
Copy link
Author

laeubi commented Feb 6, 2022

I can open a PR for master also.

Yes, please.

Done: #675

@michael-o
Copy link
Member

Please rebase

@laeubi
Copy link
Author

laeubi commented Feb 13, 2022

Please rebase

Done.

asfgit pushed a commit that referenced this pull request Feb 19, 2022
asfgit pushed a commit that referenced this pull request Feb 19, 2022
@michael-o
Copy link
Member

Merged.

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.

3 participants