Repository: maven
Updated Branches:
  refs/heads/master 85b4e3d8e -> faa9ef0cd


[MNG-6370] ConcurrencyDependencyGraph#getNumberOfBuilds() does not remove 
finished projects from unfinished ones

This closes #161


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/faa9ef0c
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/faa9ef0c
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/faa9ef0c

Branch: refs/heads/master
Commit: faa9ef0cd3de27d31064f88cd74140516b3569a3
Parents: 85b4e3d
Author: Sylwester Lachiewicz <slachiew...@gmail.com>
Authored: Wed Mar 7 23:39:56 2018 +0100
Committer: Michael Osipov <micha...@apache.org>
Committed: Wed Mar 7 23:58:20 2018 +0100

----------------------------------------------------------------------
 .../ConcurrencyDependencyGraph.java             |  6 +-
 .../ConcurrencyDependencyGraphTest.java         | 83 ++++++++++++++++++++
 2 files changed, 86 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/faa9ef0c/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/ConcurrencyDependencyGraph.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/ConcurrencyDependencyGraph.java
 
b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/ConcurrencyDependencyGraph.java
index d7d764e..190e0f7 100644
--- 
a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/ConcurrencyDependencyGraph.java
+++ 
b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/multithreaded/ConcurrencyDependencyGraph.java
@@ -45,7 +45,7 @@ public class ConcurrencyDependencyGraph
 
     private final ProjectDependencyGraph projectDependencyGraph;
 
-    private final HashSet<MavenProject> finishedProjects = new HashSet<>();
+    private final Set<MavenProject> finishedProjects = new HashSet<>();
 
     public ConcurrencyDependencyGraph( ProjectBuildList projectBuilds, 
ProjectDependencyGraph projectDependencyGraph )
     {
@@ -69,7 +69,7 @@ public class ConcurrencyDependencyGraph
         List<MavenProject> result = new ArrayList<>();
         for ( ProjectSegment projectBuild : projectBuilds )
         {
-            if ( projectDependencyGraph.getUpstreamProjects( 
projectBuild.getProject(), false ).size() == 0 )
+            if ( projectDependencyGraph.getUpstreamProjects( 
projectBuild.getProject(), false ).isEmpty() )
             {
                 result.add( projectBuild.getProject() );
             }
@@ -111,7 +111,7 @@ public class ConcurrencyDependencyGraph
     public Set<MavenProject> getUnfinishedProjects()
     {
         Set<MavenProject> unfinished = new HashSet<>( 
projectBuilds.getProjects() );
-        unfinished.remove( finishedProjects );
+        unfinished.removeAll( finishedProjects );
         return unfinished;
     }
 

http://git-wip-us.apache.org/repos/asf/maven/blob/faa9ef0c/maven-core/src/test/java/org/apache/maven/lifecycle/internal/builder/multithreaded/ConcurrencyDependencyGraphTest.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/test/java/org/apache/maven/lifecycle/internal/builder/multithreaded/ConcurrencyDependencyGraphTest.java
 
b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/builder/multithreaded/ConcurrencyDependencyGraphTest.java
new file mode 100644
index 0000000..b909fb0
--- /dev/null
+++ 
b/maven-core/src/test/java/org/apache/maven/lifecycle/internal/builder/multithreaded/ConcurrencyDependencyGraphTest.java
@@ -0,0 +1,83 @@
+package org.apache.maven.lifecycle.internal.builder.multithreaded;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional 
information regarding
+ * copyright ownership. The ASF licenses this file to you under the Apache 
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the 
License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
KIND, either express
+ * or implied. See the License for the specific language governing permissions 
and limitations under
+ * the License.
+ */
+
+import junit.framework.TestCase;
+import org.apache.maven.execution.ProjectDependencyGraph;
+import org.apache.maven.lifecycle.internal.ProjectBuildList;
+import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
+import org.apache.maven.project.MavenProject;
+
+import java.util.List;
+import java.util.Set;
+
+public class ConcurrencyDependencyGraphTest extends TestCase {
+
+    public void testGraph() throws Exception {
+
+        ProjectBuildList projectBuildList = 
ProjectDependencyGraphStub.getProjectBuildList(
+                ProjectDependencyGraphStub.getMavenSession() );
+
+        ProjectDependencyGraph projectDependencyGraph = new 
ProjectDependencyGraphStub();
+
+        ConcurrencyDependencyGraph graph = new ConcurrencyDependencyGraph( 
projectBuildList, projectDependencyGraph );
+
+        // start
+        assertEquals( 0, graph.getFinishedProjects().size() );
+        assertEquals( 6, graph.getNumberOfBuilds() );
+
+        List<MavenProject> rootSchedulableBuilds = 
graph.getRootSchedulableBuilds();
+        // only Project.A has no dependences
+        assertEquals( 1, rootSchedulableBuilds.size() );
+        assertEquals( ProjectDependencyGraphStub.A, 
rootSchedulableBuilds.iterator().next() );
+        // double check A deps
+        List<MavenProject> dependenciesA = graph.getDependencies( 
ProjectDependencyGraphStub.A );
+        assertEquals( 0, dependenciesA.size() );
+
+        assertEquals( 6, graph.getUnfinishedProjects().size() );
+
+        List<MavenProject> schedulableNewProcesses = graph.markAsFinished( 
ProjectDependencyGraphStub.A );
+        // expect Project B, C
+        assertEquals( 2, schedulableNewProcesses.size() );
+        assertEquals( 1, graph.getFinishedProjects().size() );
+
+        graph.markAsFinished( ProjectDependencyGraphStub.A );
+        // still only  A
+        assertEquals( 1, graph.getFinishedProjects().size() );
+
+        Set<MavenProject> unfinishedProjects = graph.getUnfinishedProjects();
+        assertEquals( 5, unfinishedProjects.size() );
+
+        graph.markAsFinished( schedulableNewProcesses.get( 0 ) );
+        assertEquals( 2, graph.getFinishedProjects().size() );
+        assertEquals( 4, graph.getUnfinishedProjects().size() );
+
+        List<MavenProject> dependenciesC = graph.getDependencies( 
ProjectDependencyGraphStub.C );
+        // C depends only on A
+        assertEquals( 1, dependenciesC.size() );
+
+        List<MavenProject> dependenciesX = graph.getDependencies( 
ProjectDependencyGraphStub.X );
+        // X depends only on B and C
+        assertEquals( 2, dependenciesX.size() );
+
+        List<MavenProject> activeDependenciesC = graph.getActiveDependencies( 
ProjectDependencyGraphStub.C );
+        // A already finished
+        assertEquals( 0, activeDependenciesC.size() );
+
+        List<MavenProject> activeDependenciesX = graph.getActiveDependencies( 
ProjectDependencyGraphStub.X );
+        // waiting for C
+        assertEquals( 1, activeDependenciesX.size() );
+    }
+}

Reply via email to