[ 
https://issues.apache.org/jira/browse/SUREFIRE-1383?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16145163#comment-16145163
 ] 

ASF GitHub Bot commented on SUREFIRE-1383:
------------------------------------------

Github user Tibor17 commented on a diff in the pull request:

    https://github.com/apache/maven-surefire/pull/157#discussion_r135766258
  
    --- Diff: 
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
 ---
    @@ -847,12 +847,31 @@ private DefaultScanResult scanDependencies()
             {
                 try
                 {
    +                DefaultScanResult scanResult = new DefaultScanResult( 
Collections.EMPTY_LIST );
    +                
    +                List<String> dependenciesToScan = new ArrayList();
    +                Collections.addAll( dependenciesToScan, 
getDependenciesToScan() );
    +                TestListResolver includedAndExcludedTests = 
getIncludedAndExcludedTests();
    +
    +                for ( MavenProject mavenProject : 
session.getSortedProjects() )
    +                {
    +                    String groupArtifactId = mavenProject.getGroupId() + 
":" + mavenProject.getArtifactId();
    +                    if ( dependenciesToScan.removeAll( 
Collections.singleton( groupArtifactId ) ) )
    +                    {
    +                        File outputDirectoryFile = new File( 
mavenProject.getBuild().getOutputDirectory() );
    +                        DirectoryScanner scanner =
    +                                new DirectoryScanner( outputDirectoryFile, 
includedAndExcludedTests );
    +                        scanResult = scanResult.append( scanner.scan() );
    +                    }
    +                }
    +
                     // @TODO noinspection unchecked, check MavenProject 3.x 
for Generics in surefire:3.0
                     @SuppressWarnings( "unchecked" )
    -                List<File> dependenciesToScan =
    -                    DependencyScanner.filter( project.getTestArtifacts(), 
Arrays.asList( getDependenciesToScan() ) );
    -                DependencyScanner scanner = new DependencyScanner( 
dependenciesToScan, getIncludedAndExcludedTests() );
    -                return scanner.scan();
    +                List<File> dependenciesToScanFile =
    +                        DependencyScanner.filter( 
project.getTestArtifacts(), dependenciesToScan );
    --- End diff --
    
    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.


> dependenciesToScan Does Not Leverage Classpath Elements 
> --------------------------------------------------------
>
>                 Key: SUREFIRE-1383
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1383
>             Project: Maven Surefire
>          Issue Type: Bug
>          Components: Maven Surefire Plugin
>    Affects Versions: 2.20
>            Reporter: Owen Farrell
>            Assignee: Tibor Digana
>             Fix For: 2.20.1
>
>         Attachments: scanned-dependencies-sample.zip
>
>
> The <dependenciesToScan> configuration attribute relies solely on installed 
> artifacts. This is an issue when the targeted dependencies were built as part 
> of the current session. The net result is that stale artifacts are used (i.e. 
> if the dependency has changed since it was last installed) or the tests are 
> not executed at all (if the dependency has not been previously installed.
> Attached is a sample project that illustrates this issue:
> Given I have a multi-module project
>    And the first module built includes test classes as part of the project 
> artifact
>    And subsequent modules scan the first for unit tests to execute
> When I execute the _*test*_ goal (prior to any install)
> Then the build should succeed
>    And tests should be executed with each module



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to