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
SUREFIRE-1383 dependenciesToScan Does Not Leverage Classpath Elements #157
Conversation
Pls squash both commits to one. |
|
||
for ( MavenProject mavenProject : session.getSortedProjects() ) | ||
{ | ||
String groupArtifactId = new StringBuilder( mavenProject.getGroupId() ).append( ":" ) |
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.
Pls concatenate as follows mavenProject.getGroupId() + ":" + mavenProject.getArtifactId()
.
This is simple and javac
would compile to StringBuilder anyway, but longer in sources.
@@ -847,12 +847,33 @@ private DefaultScanResult scanDependencies() | |||
{ | |||
try | |||
{ | |||
DefaultScanResult scanResult = new DefaultScanResult( Collections.EMPTY_LIST ); | |||
|
|||
List<String> dependenciesToScanList = new ArrayList( Arrays.asList( getDependenciesToScan() ) ); |
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.
dependenciesToScanList
already contains plural. Pls rename dependenciesToScanList
to dependenciesToScan
.
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.
No need to create two collections with
List<String> dependenciesToScanList = new ArrayList( Arrays.asList( getDependenciesToScan() ) );
One modifiable collection can be with this code:
List<String> dependenciesToScanList = new ArrayList();
Collections.addAll( dependenciesToScanList, getDependenciesToScan() );
DependencyScanner.filter( project.getTestArtifacts(), Arrays.asList( getDependenciesToScan() ) ); | ||
DependencyScanner scanner = new DependencyScanner( dependenciesToScan, getIncludedAndExcludedTests() ); | ||
return scanner.scan(); | ||
List<File> dependenciesToScanFileList = |
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.
dependenciesToScanFileList
already contains plural. Pls rename dependenciesToScanFileList
to dependenciesToScanFile
.
@Tibor17 - done. |
Would you add integration test? |
I've put together an integration test that can validate the execution of SUREFIRE-1383. And all is good on that front. While I was poking around the other ITs, I tripped on the IT for SUREFIRE-569. As written, the IT passes just fine. But the changes that I'm proposing make that test case moot - it uses the same packaging structure of 2 projects built within a single session. I updated that test case to better reflect the original ask of scanning JAR dependencies, but that means splitting the test case execution in to 2 separate lifecycles. When I split the single lifecycle in to 2, I'm running in to a dependency resolution issue. For whatever reason, the second execution is unable to locate artifacts installed in the IT repo as part of the first lifecycle. In looking around at the other ITs, it looks like this is the only test case that runs an install goal and is then dependent on the result of that install. Thoughts?
|
Looking at it a bit deeper, looks like the root cause is that the |
One workaround for this would be to install the missing
|
No, no. |
I don't follow. When I run an install from any level, the In order to execute an IT across multiple lifecycles, that POM needs to be installed it in to the local repository specified by failsafe. It looks to me like every IT that references |
Copying the Would it make sense to open a separate issue/enhancement for installing the |
I have been busy with other ticket. Where did we finish. Do you need a help? |
And I got busy with other work as well. I think I found a solution that doesn't completely violate the pattern used by integration tests. Long story short, the IT for SUREFIRE-569 has been updated to be completely independent modules. The first module leverages the flatten plugin to avoid any parent references, which then allows the second module to complete successfully. The IT for SUREFIRE-1383 executes within a single process and verifies the updates that I've proposed. Sorry for all the noise on the ticket - I hosed my fork while making the last round of updates. |
@Tibor17 - Have you had a chance to review this PR? |
@owenfarrell |
@Tibor17 - thoughts? |
I have the exact same issue. This fix is very much appreciated. |
@JoelNGeorge |
@owenfarrell |
@Tibor17 - IT569 does not fail when introducing my changes. But since the test was written as a single lifecycle, it inadvertently uses the code I've introduced in this PR (see comment above). The only changes to IT569 were to split the single lifecycle in to multiple lifecycles. While there, I tried to clean up the test resources to match current standards/conventions. But those changes to IT569 were to preserve its named intent: run tests from a dependency jar. Looks like two options to me:
|
@owenfarrell |
@@ -847,12 +847,31 @@ private DefaultScanResult scanDependencies() | |||
{ | |||
try | |||
{ | |||
DefaultScanResult scanResult = new DefaultScanResult( Collections.EMPTY_LIST ); |
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.
Do you use IntelliJ IDEA? It highlights the argument in yellow.
Use this:
DefaultScanResult scanResult = new DefaultScanResult( Collections.<String>emptyList() );
@@ -847,12 +847,31 @@ private DefaultScanResult scanDependencies() | |||
{ | |||
try | |||
{ | |||
DefaultScanResult scanResult = new DefaultScanResult( Collections.EMPTY_LIST ); | |||
|
|||
List<String> dependenciesToScan = new ArrayList(); |
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.
missing Generics on constructor. We have Java 1.6.
List<String> dependenciesToScan = new ArrayList<String>();
DependencyScanner.filter( project.getTestArtifacts(), Arrays.asList( getDependenciesToScan() ) ); | ||
DependencyScanner scanner = new DependencyScanner( dependenciesToScan, getIncludedAndExcludedTests() ); | ||
return scanner.scan(); | ||
List<File> dependenciesToScanFile = |
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.
Pls align to single line after using static import:
import static java.lang.Thread.currentThread; import static org.apache.maven.plugin.surefire.util.DependencyScanner.filter; import static java.util.Collections.singletonMap;
DependencyScanner scanner = new DependencyScanner( dependenciesToScan, getIncludedAndExcludedTests() ); | ||
return scanner.scan(); | ||
List<File> dependenciesToScanFile = | ||
DependencyScanner.filter( project.getTestArtifacts(), dependenciesToScan ); |
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.
Here some artifacts may have classifier tests
. This means your loop may appear below test artifacts and only those project artifacts (gid:aid:*) should be excluded which appear in getTestArtifacts()
and scans appended creating one aggregated scan result.
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.
Locally staged updates to reflect your generics comments. But I don't follow what you're asking for here.
Per the documentation, the dependenciesToScan property doesn't support classifiers - just group ID and artifact ID. So I didn't add any logic around classifier resolution. Is that what you were expecting?
@owenfarrell |
Tibor Digana on dev@maven.apache.org replies: project.getTestArtifacts() If you find the one Artifact in this collection then you can simply ignore session.getSortedProjects() If it basically opposite what you have done in your code with the removal. |
Tibor Digana on dev@maven.apache.org replies: List dependenciesToScan = for ( MavenProject mavenProject : session.getSortedProjects() ) IF groupId:artifactId IS NOT IN project.getTestArtifacts() THEN => } |
I don't think that logic would work for my scenario. For example:
According to your logic, Surefire would prefer the already-installed artifact, effectively ignoring those changes made in step 3. That would put us right back where we started. Using my logic, Surefire would prefer the working copy changes and execute accordingly. Since the existing
|
@owenfarrell |
@owenfarrell
|
@Tibor17 I see what you're going for, that makes sense. I've update my PR to just include IT contents now, with an improved IT that emulates a scenario where working copy changes are made (i.e. install a multi-module project, modify the contents to add more tests, test the modified contents). If your solution gets my IT PR to pass, I think the solution will cover my bona fide scenarios. |
@Tibor17 - any updates? |
@owenfarrell |
Any progress on this? |
@paulduffin |
@owenfarrell |
@owenfarrell |
@owenfarrell |
Added logic to prefer output directories of projects built as part of the current session.