[MNG-7095] Support for parallel builds when resuming

Resolves #98
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5760ResumeFeatureTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5760ResumeFeatureTest.java
index d4cbab9..97249aa 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5760ResumeFeatureTest.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng5760ResumeFeatureTest.java
@@ -43,6 +43,7 @@
     private final File parentDependentTestDir;
     private final File parentIndependentTestDir;
     private final File noProjectTestDir;
+    private final File fourModulesTestDir;
 
     public MavenITmng5760ResumeFeatureTest() throws IOException {
         super( "[4.0.0-alpha-1,)" );
@@ -52,6 +53,8 @@
                 "/mng-5760-resume-feature/parent-independent" );
         this.noProjectTestDir = ResourceExtractor.simpleExtractResources( getClass(),
                 "/mng-5760-resume-feature/no-project" );
+        this.fourModulesTestDir = ResourceExtractor.simpleExtractResources( getClass(),
+                "/mng-5760-resume-feature/four-modules" );
     }
 
     /**
@@ -175,6 +178,109 @@
         }
     }
 
+    public void testFailureWithParallelBuild() throws Exception
+    {
+        // four modules: a, b, c, d
+        // c depends on b, d depends on a
+
+        // Let's do a first pass with a and c failing.  The build is parallel,
+        // so we have a first thread with a and d, and the second one with b and c
+        // The result should be:
+        //   a : failure (slow, so b and c will be built in the mean time)
+        //   b : success
+        //   c : failure
+        //   d : skipped
+        Verifier verifier = newVerifier( fourModulesTestDir.getAbsolutePath() );
+        verifier.addCliOption( "-T2" );
+        verifier.addCliOption( "-Dmodule-a.delay=1000" );
+        verifier.addCliOption( "-Dmodule-a.fail=true" );
+        verifier.addCliOption( "-Dmodule-c.fail=true" );
+        try
+        {
+            verifier.executeGoal( "verify" );
+            fail( "Expected this invocation to fail" );
+        }
+        catch ( final VerificationException ve )
+        {
+            // Expected to fail.
+        }
+        finally
+        {
+            verifier.resetStreams();
+        }
+
+        // Let module-b fail, if it would have been built...
+        verifier = newVerifier( fourModulesTestDir.getAbsolutePath() );
+        verifier.addCliOption( "-T2" );
+        verifier.addCliOption( "-Dmodule-b.fail=true" );
+        // ... but adding -r should exclude it from the build because the previous Maven invocation
+        // marked it as successfully built.
+        verifier.addCliOption( "-r" );
+        // The result should be:
+        //   a : success
+        //   c : success
+        //   d : success
+        try
+        {
+            verifier.executeGoal( "verify" );
+        }
+        finally
+        {
+            verifier.resetStreams();
+        }
+    }
+
+    public void testFailureAfterSkipWithParallelBuild() throws Exception
+    {
+        // four modules: a, b, c, d
+        // c depends on b, d depends on a
+
+        // Let's do a first pass with a and c failing.  The build is parallel,
+        // so we have a first thread with a and d, and the second one with b and c
+        // The result should be:
+        //   a : success
+        //   b : success, slow
+        //   c : skipped
+        //   d : failure
+        Verifier verifier = newVerifier( fourModulesTestDir.getAbsolutePath() );
+        verifier.addCliOption( "-T2" );
+        verifier.addCliOption( "-Dmodule-b.delay=2000" );
+        verifier.addCliOption( "-Dmodule-d.fail=true" );
+        try
+        {
+            verifier.executeGoal( "verify" );
+            fail( "Expected this invocation to fail" );
+        }
+        catch ( final VerificationException ve )
+        {
+            // Expected to fail.
+        }
+        finally
+        {
+            verifier.resetStreams();
+        }
+
+        // Let module-a and module-b fail, if they would have been built...
+        verifier = newVerifier( fourModulesTestDir.getAbsolutePath() );
+        verifier.addCliOption( "-T2" );
+        verifier.addCliOption( "-Dmodule-a.fail=true" );
+        verifier.addCliOption( "-Dmodule-b.fail=true" );
+        // ... but adding -r should exclude those two from the build because the previous Maven invocation
+        // marked them as successfully built.
+        verifier.addCliOption( "-r" );
+        try
+        {
+            // The result should be:
+            //   c : success
+            //   d : success
+            verifier.executeGoal( "verify" );
+        }
+        finally
+        {
+            verifier.resetStreams();
+        }
+    }
+
     /**
      * Throws an exception if the text <strong>is</strong> present in the log.
      *
diff --git a/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-a/pom.xml b/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-a/pom.xml
new file mode 100644
index 0000000..1f89611
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-a/pom.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>module-a</artifactId>
+
+    <parent>
+        <groupId>org.apache.maven.its.mng5760</groupId>
+        <artifactId>parent</artifactId>
+        <version>1.0</version>
+    </parent>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.22.0</version>
+	  </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-a/src/test/java/org/apache/maven/it/TestCase.java b/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-a/src/test/java/org/apache/maven/it/TestCase.java
new file mode 100644
index 0000000..fcc1662
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-a/src/test/java/org/apache/maven/it/TestCase.java
@@ -0,0 +1,37 @@
+package org.apache.maven.it;
+
+/*
+ * 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 org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+public class TestCase
+{
+    @Test
+    public void testCase() throws Exception
+    {
+        Thread.sleep( Integer.getInteger( "module-a.delay", 0 ) );
+        if ( Boolean.getBoolean("module-a.fail") )
+        {
+            fail("Deliberately fail test case in module A");
+        }
+    }
+}
\ No newline at end of file
diff --git a/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-b/pom.xml b/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-b/pom.xml
new file mode 100644
index 0000000..5ba7ab2
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-b/pom.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>module-b</artifactId>
+
+    <parent>
+        <groupId>org.apache.maven.its.mng5760</groupId>
+        <artifactId>parent</artifactId>
+        <version>1.0</version>
+    </parent>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.22.0</version>
+	  </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-b/src/test/java/org/apache/maven/it/TestCase.java b/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-b/src/test/java/org/apache/maven/it/TestCase.java
new file mode 100644
index 0000000..454578a
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-b/src/test/java/org/apache/maven/it/TestCase.java
@@ -0,0 +1,37 @@
+package org.apache.maven.it;
+
+/*
+ * 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 org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+public class TestCase
+{
+    @Test
+    public void testCase() throws Exception
+    {
+        Thread.sleep( Integer.getInteger( "module-b.delay", 0 ) );
+        if ( Boolean.getBoolean("module-b.fail") )
+        {
+            fail("Deliberately fail test case in module B");
+        }
+    }
+}
\ No newline at end of file
diff --git a/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-c/pom.xml b/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-c/pom.xml
new file mode 100644
index 0000000..b0b7f41
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-c/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>module-c</artifactId>
+
+    <parent>
+        <groupId>org.apache.maven.its.mng5760</groupId>
+        <artifactId>parent</artifactId>
+        <version>1.0</version>
+    </parent>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.maven.its.mng5760</groupId>
+            <artifactId>module-b</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.22.0</version>
+	  </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-c/src/test/java/org/apache/maven/it/TestCase.java b/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-c/src/test/java/org/apache/maven/it/TestCase.java
new file mode 100644
index 0000000..6931a02
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-c/src/test/java/org/apache/maven/it/TestCase.java
@@ -0,0 +1,37 @@
+package org.apache.maven.it;
+
+/*
+ * 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 org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+public class TestCase
+{
+    @Test
+    public void testCase() throws Exception
+    {
+        Thread.sleep( Integer.getInteger( "module-c.delay", 0 ) );
+        if ( Boolean.getBoolean("module-c.fail") )
+        {
+            fail("Deliberately fail test case in module C");
+        }
+    }
+}
\ No newline at end of file
diff --git a/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-d/pom.xml b/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-d/pom.xml
new file mode 100644
index 0000000..9ce20e6
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-d/pom.xml
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>module-d</artifactId>
+
+    <parent>
+        <groupId>org.apache.maven.its.mng5760</groupId>
+        <artifactId>parent</artifactId>
+        <version>1.0</version>
+    </parent>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.maven.its.mng5760</groupId>
+            <artifactId>module-a</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+    </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.22.0</version>
+	  </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-d/src/test/java/org/apache/maven/it/TestCase.java b/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-d/src/test/java/org/apache/maven/it/TestCase.java
new file mode 100644
index 0000000..34f7752
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/module-d/src/test/java/org/apache/maven/it/TestCase.java
@@ -0,0 +1,37 @@
+package org.apache.maven.it;
+
+/*
+ * 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 org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+public class TestCase
+{
+    @Test
+    public void testCase() throws Exception
+    {
+        Thread.sleep( Integer.getInteger( "module-d.delay", 0 ) );
+        if ( Boolean.getBoolean("module-d.fail") )
+        {
+            fail("Deliberately fail test case in module D");
+        }
+    }
+}
\ No newline at end of file
diff --git a/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/pom.xml b/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/pom.xml
new file mode 100644
index 0000000..831ad90
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-5760-resume-feature/four-modules/pom.xml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.apache.maven.its.mng5760</groupId>
+    <artifactId>parent</artifactId>
+    <version>1.0</version>
+
+    <packaging>pom</packaging>
+
+    <name>Maven Integration Test :: MNG-5760</name>
+    <description>
+        Tests for the --resume flag.
+    </description>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <maven.compiler.source>1.8</maven.compiler.source>
+        <maven.compiler.target>1.8</maven.compiler.target>
+    </properties>
+
+    <modules>
+        <module>module-a</module>
+        <module>module-b</module>
+        <module>module-c</module>
+        <module>module-d</module>
+    </modules>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.12</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+</project>