You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2020/04/07 13:13:56 UTC

[maven-integration-testing] 13/21: Test case for checking whether a packaged artifact is up to date with the compiled artifact

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a commit to branch MNG-4660
in repository https://gitbox.apache.org/repos/asf/maven-integration-testing.git

commit 9b8751c8dd90ad8dc5c47ed13e27a113e7ea6dad
Author: Maarten Mulders <ma...@infosupport.com>
AuthorDate: Thu Mar 26 14:02:42 2020 +0100

    Test case for checking whether a packaged artifact is up to date with the compiled artifact
---
 .../org/apache/maven/it/IntegrationTestSuite.java  |  1 +
 .../it/MavenITmng4660OutdatedPackagedArtifact.java | 91 ++++++++++++++++++++++
 .../module-a/pom.xml                               | 36 +++++++++
 .../src/main/java/org/apache/maven/it/Example.java | 24 ++++++
 .../module-b/pom.xml                               | 44 +++++++++++
 .../java/org/apache/maven/it/AnotherExample.java   | 28 +++++++
 .../test/java/org/apache/maven/it/TestCase.java    | 31 ++++++++
 .../mng-4660-outdated-packaged-artifact/pom.xml    | 62 +++++++++++++++
 .../java/org/apache/maven/it/AnotherExample.java   | 28 +++++++
 9 files changed, 345 insertions(+)

diff --git a/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java b/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
index 09aeb18..3f0cbc8 100644
--- a/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
+++ b/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
@@ -108,6 +108,7 @@ public class IntegrationTestSuite
         // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
 
         suite.addTestSuite( MavenITmng4660ResumeFromTest.class );
+        suite.addTestSuite( MavenITmng4660OutdatedPackagedArtifact.class );
         suite.addTestSuite( MavenITmng6759TransitiveDependencyRepositoriesTest.class );
         suite.addTestSuite( MavenITmng6720FailFastTest.class );
         suite.addTestSuite( MavenITmng6558ToolchainsBuildingEventTest.class );
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java
new file mode 100644
index 0000000..289a357
--- /dev/null
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4660OutdatedPackagedArtifact.java
@@ -0,0 +1,91 @@
+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.apache.maven.it.util.ResourceExtractor;
+import org.apache.maven.shared.utils.io.FileUtils;
+
+import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+/**
+ * This is a test case for a new check introduced with <a href="https://issues.apache.org/jira/browse/MNG-4660">MNG-4660</a>.
+ * That check verifies if a packaged artifact within the Reactor is up-to-date with the outputDirectory of the same project.
+ *
+ * @author Maarten Mulders
+ * @author Martin Kanters
+ */
+public class MavenITmng4660OutdatedPackagedArtifact extends AbstractMavenIntegrationTestCase {
+    public MavenITmng4660OutdatedPackagedArtifact()
+    {
+        super( "[3.7.0,)" );
+    }
+
+    /**
+     * Test that Maven logs a warning when a packaged artifact is found that is older than the outputDirectory of the
+     * same artifact.
+     */
+    public void testShouldWarnWhenPackagedArtifactIsOutdated() throws Exception
+    {
+        final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4660-outdated-packaged-artifact" );
+
+        // 1. Package the whole project
+        final Verifier verifier1 = newVerifier( testDir.getAbsolutePath() );
+        verifier1.deleteDirectory( "target" );
+        verifier1.deleteArtifacts( "org.apache.maven.its.mng4660" );
+
+        verifier1.executeGoal( "package" );
+
+        verifier1.verifyErrorFreeLog();
+        verifier1.resetStreams();
+
+
+        // 2. Create a properties file with some content and compile only that module (module A).
+        final Verifier verifier2 = newVerifier( testDir.getAbsolutePath() );
+
+        final Path resourcesDirectory = Files.createDirectories( Paths.get( testDir.toString(), "module-a", "src", "main", "resources" ) );
+        System.err.println( "Created directory " + resourcesDirectory.toAbsolutePath().toString() );
+        final Path fileToWrite = resourcesDirectory.resolve( "example.properties" );
+        FileUtils.fileWrite( fileToWrite.toString(), "x=42" );
+        System.err.println( "Wrote file " + fileToWrite.toAbsolutePath().toString() );
+
+        verifier2.setAutoclean( false );
+        verifier2.addCliOption( "--projects" );
+        verifier2.addCliOption( ":module-a" );
+        verifier2.executeGoal( "compile" );
+
+        verifier2.verifyErrorFreeLog();
+        verifier2.resetStreams();
+
+        // 3. Resume project build from module B, that depends on module A we just touched. Its packaged artifact
+        // is no longer in sync with its compiled artifacts.
+        final Verifier verifier3 = newVerifier( testDir.getAbsolutePath() );
+        verifier3.setAutoclean( false );
+        verifier3.addCliOption( "--resume-from" );
+        verifier3.addCliOption( ":module-b" );
+        verifier3.executeGoal( "compile" );
+
+        verifier3.verifyErrorFreeLog();
+        verifier3.verifyTextInLog( "Packaged artifact is not up-to-date" );
+        verifier3.resetStreams();
+    }
+}
diff --git a/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-a/pom.xml b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-a/pom.xml
new file mode 100644
index 0000000..f6e2caa
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-a/pom.xml
@@ -0,0 +1,36 @@
+<?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.mng4660</groupId>
+        <artifactId>parent</artifactId>
+        <version>1.0</version>
+    </parent>
+
+</project>
diff --git a/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-a/src/main/java/org/apache/maven/it/Example.java b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-a/src/main/java/org/apache/maven/it/Example.java
new file mode 100644
index 0000000..1608aba
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-a/src/main/java/org/apache/maven/it/Example.java
@@ -0,0 +1,24 @@
+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.
+ */
+
+public class Example
+{
+}
\ No newline at end of file
diff --git a/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/pom.xml b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/pom.xml
new file mode 100644
index 0000000..e00e63b
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/pom.xml
@@ -0,0 +1,44 @@
+<?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.mng4660</groupId>
+        <artifactId>parent</artifactId>
+        <version>1.0</version>
+    </parent>
+
+    <dependencies>
+      <dependency>
+          <groupId>org.apache.maven.its.mng4660</groupId>
+          <artifactId>module-a</artifactId>
+          <version>1.0</version>
+      </dependency>
+    </dependencies>
+
+</project>
diff --git a/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/src/main/java/org/apache/maven/it/AnotherExample.java b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/src/main/java/org/apache/maven/it/AnotherExample.java
new file mode 100644
index 0000000..20ab187
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/src/main/java/org/apache/maven/it/AnotherExample.java
@@ -0,0 +1,28 @@
+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.
+ */
+
+public class AnotherExample
+{
+    public AnotherExample()
+    {
+        new Example();
+    }
+}
\ No newline at end of file
diff --git a/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/src/test/java/org/apache/maven/it/TestCase.java b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/src/test/java/org/apache/maven/it/TestCase.java
new file mode 100644
index 0000000..74a4579
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/module-b/src/test/java/org/apache/maven/it/TestCase.java
@@ -0,0 +1,31 @@
+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;
+
+public class TestCase
+{
+    @Test
+    public void testCase()
+    {
+        final Example example = new Example();
+    }
+}
\ No newline at end of file
diff --git a/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/pom.xml b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/pom.xml
new file mode 100644
index 0000000..a2d0bcd
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-4660-outdated-packaged-artifact/pom.xml
@@ -0,0 +1,62 @@
+<?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.mng4660</groupId>
+    <artifactId>parent</artifactId>
+    <version>1.0</version>
+
+    <packaging>pom</packaging>
+
+    <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-b</module>
+        <module>module-a</module>
+    </modules>
+
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.4</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.8.1</version>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/core-it-suite/src/test/resources/mng-4660-resume-from/module-b/src/main/java/org/apache/maven/it/AnotherExample.java b/core-it-suite/src/test/resources/mng-4660-resume-from/module-b/src/main/java/org/apache/maven/it/AnotherExample.java
new file mode 100644
index 0000000..20ab187
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-4660-resume-from/module-b/src/main/java/org/apache/maven/it/AnotherExample.java
@@ -0,0 +1,28 @@
+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.
+ */
+
+public class AnotherExample
+{
+    public AnotherExample()
+    {
+        new Example();
+    }
+}
\ No newline at end of file