You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2020/08/04 12:14:53 UTC

[maven-integration-testing] 01/01: [MNG-6972] Allow access to org.apache.maven.graph

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

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

commit 18666afcdbcc2ec20f9cf1b8688d6d6b1c7717b2
Author: mickroll <mi...@users.noreply.github.com>
AuthorDate: Mon Aug 3 16:39:06 2020 +0200

    [MNG-6972] Allow access to org.apache.maven.graph
    
    This closes #69
---
 .../org/apache/maven/it/IntegrationTestSuite.java  |  1 +
 ...avenITmng6972AllowAccessToGraphPackageTest.java | 70 ++++++++++++++++++++++
 .../build-plugin/pom.xml                           | 67 +++++++++++++++++++++
 .../example/BuildExtensionUsingGraphPackage.java   | 44 ++++++++++++++
 .../using-module/pom.xml                           | 38 ++++++++++++
 5 files changed, 220 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 33dc60b..1198133 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
@@ -107,6 +107,7 @@ public class IntegrationTestSuite
         // -------------------------------------------------------------------------------------------------------------
         // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
 
+        suite.addTestSuite( MavenITmng6972AllowAccessToGraphPackageTest.class );
         suite.addTestSuite( MavenITmng5760ResumeFeatureTest.class );
         suite.addTestSuite( MavenITmng6656BuildConsumer.class );
         suite.addTestSuite( MavenITmng6562WarnDefaultBindings.class );
diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6972AllowAccessToGraphPackageTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6972AllowAccessToGraphPackageTest.java
new file mode 100644
index 0000000..cd9fb02
--- /dev/null
+++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6972AllowAccessToGraphPackageTest.java
@@ -0,0 +1,70 @@
+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 java.io.File;
+
+import org.apache.maven.it.util.ResourceExtractor;
+
+/**
+ * This is a test for <a href="https://issues.apache.org/jira/browse/MNG-6972">MNG-6972</a>.
+ */
+public class MavenITmng6972AllowAccessToGraphPackageTest
+    extends AbstractMavenIntegrationTestCase
+{
+
+    public MavenITmng6972AllowAccessToGraphPackageTest()
+    {
+        super( "[3.7.0,)" );
+    }
+
+    public void testitMNG6972()
+        throws Exception
+    {
+
+        // The testdir is computed from the location of this file.
+        final File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-6972-allow-access-to-graph-package" );
+
+        Verifier verifier;
+
+        /*
+         * We must first make sure that any artifact created
+         * by this test has been removed from the local
+         * repository. Failing to do this could cause
+         * unstable test results. Fortunately, the verifier
+         * makes it easy to do this.
+         */
+        verifier = new Verifier( testDir.getAbsolutePath() );
+        verifier.deleteArtifact( "mng-6972-allow-access-to-graph-package", "build-plugin", "1.0", "jar" );
+        verifier.deleteArtifact( "mng-6972-allow-access-to-graph-package", "using-module", "1.0", "jar" );
+
+        verifier = new Verifier( new File( testDir.getAbsolutePath(), "build-plugin" ).getAbsolutePath() );
+        verifier.getSystemProperties().put( "maven.multiModuleProjectDirectory", testDir.getAbsolutePath() );
+        verifier.executeGoal( "install" );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        verifier = new Verifier( new File( testDir.getAbsolutePath(), "using-module" ).getAbsolutePath() );
+        verifier.getSystemProperties().put( "maven.multiModuleProjectDirectory", testDir.getAbsolutePath() );
+        verifier.executeGoal( "install" );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+    }
+}
diff --git a/core-it-suite/src/test/resources/mng-6972-allow-access-to-graph-package/build-plugin/pom.xml b/core-it-suite/src/test/resources/mng-6972-allow-access-to-graph-package/build-plugin/pom.xml
new file mode 100644
index 0000000..7a25a06
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-6972-allow-access-to-graph-package/build-plugin/pom.xml
@@ -0,0 +1,67 @@
+<?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>mng-6972-allow-access-to-graph-package</groupId>
+  <artifactId>build-plugin</artifactId>
+  <version>1.0</version>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <maven.compiler.source>1.8</maven.compiler.source>
+    <maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
+
+    <plexus-component.version>1.5.5</plexus-component.version>
+    <maven-version>3.3.1</maven-version>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-core</artifactId>
+      <version>${maven-version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-component-annotations</artifactId>
+      <version>${plexus-component.version}</version>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.plexus</groupId>
+        <artifactId>plexus-component-metadata</artifactId>
+        <version>${plexus-component.version}</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>generate-metadata</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/core-it-suite/src/test/resources/mng-6972-allow-access-to-graph-package/build-plugin/src/main/java/com/example/BuildExtensionUsingGraphPackage.java b/core-it-suite/src/test/resources/mng-6972-allow-access-to-graph-package/build-plugin/src/main/java/com/example/BuildExtensionUsingGraphPackage.java
new file mode 100644
index 0000000..d3889d4
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-6972-allow-access-to-graph-package/build-plugin/src/main/java/com/example/BuildExtensionUsingGraphPackage.java
@@ -0,0 +1,44 @@
+package com.example;
+
+import java.lang.IllegalStateException;
+import java.util.Objects;
+
+import org.apache.maven.AbstractMavenLifecycleParticipant;
+import org.apache.maven.MavenExecutionException;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.execution.ProjectDependencyGraph;
+import org.apache.maven.graph.GraphBuilder;
+import org.apache.maven.model.building.ModelProblem;
+import org.apache.maven.model.building.Result;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.component.annotations.Component;
+import org.codehaus.plexus.component.annotations.Requirement;
+
+@Component( role = AbstractMavenLifecycleParticipant.class )
+public class BuildExtensionUsingGraphPackage extends AbstractMavenLifecycleParticipant
+{
+
+    @Requirement( hint = GraphBuilder.HINT )
+    private GraphBuilder graphBuilder;
+
+    @Override
+    public void afterProjectsRead( final MavenSession session ) throws MavenExecutionException
+    {
+        Objects.requireNonNull( graphBuilder, "graphBuilder should be available in build extension" );
+
+        Result<? extends ProjectDependencyGraph> graphResult = graphBuilder.build( session );
+        Objects.requireNonNull( graphResult, "graphResult should have been built" );
+
+        for ( ModelProblem problem : graphResult.getProblems() )
+        {
+            if ( problem.getSeverity() == ModelProblem.Severity.WARNING )
+            {
+                throw new IllegalStateException( "unexpected WARNING found: " + problem );
+            }
+            else
+            {
+                throw new IllegalStateException( "unexpected Problem found: " + problem );
+            }
+        }
+    }
+}
diff --git a/core-it-suite/src/test/resources/mng-6972-allow-access-to-graph-package/using-module/pom.xml b/core-it-suite/src/test/resources/mng-6972-allow-access-to-graph-package/using-module/pom.xml
new file mode 100644
index 0000000..a91056b
--- /dev/null
+++ b/core-it-suite/src/test/resources/mng-6972-allow-access-to-graph-package/using-module/pom.xml
@@ -0,0 +1,38 @@
+<?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>mng-6972-allow-access-to-graph-package</groupId>
+  <artifactId>using-module</artifactId>
+  <version>1</version>
+
+  <build>
+    <extensions>
+      <extension>
+        <groupId>mng-6972-allow-access-to-graph-package</groupId>
+        <artifactId>build-plugin</artifactId>
+        <version>1.0</version>
+      </extension>
+    </extensions>
+  </build>
+</project>