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

Include the classifier when creating an ArtifactKey from a org.apachemaven.artifact.Artifact #1358

Merged
merged 1 commit into from
Jun 16, 2023

Conversation

TheHound
Copy link
Contributor

Include the classifier when creating an ArtifactKey from a org.apachemaven.artifact.Artifact to avoid issues with same dependency but different classifier & scope combinations.

@laeubi
Copy link
Member

laeubi commented Apr 25, 2023

@TheHound can you explain the specific problem this solves? Could it probably even be demonstrated as a junit test (e.g. in org.eclipse.m2e.core.tests?

@github-actions
Copy link

github-actions bot commented Apr 25, 2023

Test Results

   210 files  +2     210 suites  +2   31m 24s ⏱️ + 4m 54s
   656 tests +1     647 ✔️ +1    9 💤 ±0  0 ±0 
1 312 runs  +2  1 294 ✔️ +2  18 💤 ±0  0 ±0 

Results for commit c7643f1. ± Comparison against base commit 172f6be.

♻️ This comment has been updated with latest results.

@TheHound
Copy link
Contributor Author

TheHound commented Apr 25, 2023

Sure I'll have a go tomorrow at adding a unit test but in the meantime a basic explanation of the issue is imagine the following dependencies :

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>2.0.7</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>2.0.7</version>
    <classifier>tests<classifier>
    <scope>test</scope>
</dependency>

The dependency doesn't matter just the concept of having the same dependency but using different classifier with different scope.
Now in MavenProjectFacade the artifact refs are created as

void setMavenProjectArtifacts(MavenProject mavenProject) {
  Set<ArtifactRef> collect = mavenProject.getArtifacts().stream()
      .map(a -> new ArtifactRef(new ArtifactKey(a), a.getScope()))
      .collect(Collectors.toCollection(LinkedHashSet::new));
  this.artifacts = Collections.unmodifiableSet(collect);
}

https://github.com/eclipse-m2e/m2e-core/blob/master/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/registry/MavenProjectFacade.java#L343
Because the ArtifactKey doesn't contain the classifier we end up with a set with two items with identical keys org.slf4:slf4j-api:2.0.7:: and different scopes.

This can cause issues in other plugins using m2e (for example I am pretty sure the eclipse Jetty plugin doesn't handle maven projects using classifiers because of this)

@TheHound TheHound force-pushed the artifact-key-classifier branch from 18996ba to 7c88a5e Compare April 28, 2023 11:00
@TheHound
Copy link
Contributor Author

Have updated the commit with a test case demonstrating the expected change in artifact portable strings

Copy link
Member

@laeubi laeubi left a comment

Choose a reason for hiding this comment

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

Looks good to me but as its is a quite central change will request a review from some other commiters.

@laeubi laeubi requested review from HannesWell and mickaelistria May 2, 2023 11:45
@HannesWell HannesWell force-pushed the artifact-key-classifier branch from 7c88a5e to da6a24b Compare May 4, 2023 20:50
Copy link
Contributor

@HannesWell HannesWell left a comment

Choose a reason for hiding this comment

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

This looks like a reasonable change for me.

@mickaelistria what do you think?

@HannesWell HannesWell force-pushed the artifact-key-classifier branch from da6a24b to 0d59233 Compare May 20, 2023 11:38
@HannesWell
Copy link
Contributor

@mickaelistria, @akurtakov what do you think about this?
We plan do perform a release next week and I think it would be good to have this included.

@HannesWell HannesWell added this to the 2.3.0 milestone May 20, 2023
Copy link
Contributor

@mickaelistria mickaelistria left a comment

Choose a reason for hiding this comment

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

I don't see a reason against this change; unless test do show some related error.

@laeubi
Copy link
Member

laeubi commented May 22, 2023

It seems a versionbump is required, beside this I think it should be included in this release. FYI @fbricon

@laeubi laeubi force-pushed the artifact-key-classifier branch from 0d59233 to eef8eff Compare May 22, 2023 15:43
@fbricon
Copy link
Contributor

fbricon commented May 22, 2023

I think the classifier was not considered initially due to workspace project resolution. You need to ensure a workspace project A depending on workspace B and B:tests won't break for instance.
https://github.com/tesla/m2e-core-tests/blob/0652381e7da3c6dfa5bb5e864e215da786bb2efd/org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/BuildPathManagerTest.java#L740-L764 might be relevant

@HannesWell
Copy link
Contributor

I think the classifier was not considered initially due to workspace project resolution. You need to ensure a workspace project A depending on workspace B and B:tests won't break for instance. https://github.com/tesla/m2e-core-tests/blob/0652381e7da3c6dfa5bb5e864e215da786bb2efd/org.eclipse.m2e.tests/src/org/eclipse/m2e/tests/BuildPathManagerTest.java#L740-L764 might be relevant

The test passes in the CI. So should we still consider this or better have another solution?

@fbricon
Copy link
Contributor

fbricon commented May 23, 2023

I haven't tested that change. If you're confident it's safe, then go ahead with it.

@HannesWell
Copy link
Contributor

I haven't tested that change. If you're confident it's safe, then go ahead with it.

Me neither and since I and nobody else considered the case you mentioned I'm not that confident.
Nevertheless in order to make progress here. but in a safer way I suggest to merge this after the upcoming release is out (and we are sure we don't contribute a follow up to Sim-Rel). Then we have some time to test the change via snapshots and get more confidence for the next release.

@HannesWell HannesWell modified the milestones: 2.3.0, 2.4.0 May 23, 2023
@HannesWell HannesWell force-pushed the artifact-key-classifier branch 2 times, most recently from e3d9be1 to 425a520 Compare June 15, 2023 21:22
….maven.artifact.Artifact to avoid issues with same dependency but different classifier & scope combinations
@HannesWell HannesWell force-pushed the artifact-key-classifier branch from 425a520 to c7643f1 Compare June 15, 2023 23:19
@HannesWell HannesWell merged commit 9c6d8d5 into eclipse-m2e:master Jun 16, 2023
@HannesWell
Copy link
Contributor

Let's see how this works IRL.
Thanks @TheHound!

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.

5 participants