diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java b/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java index 33dc60b7c7..11981335fe 100644 --- a/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java @@ -107,6 +107,7 @@ public static Test suite() // ------------------------------------------------------------------------------------------------------------- // 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/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6972AllowAccessToGraphPackageTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6972AllowAccessToGraphPackageTest.java new file mode 100644 index 0000000000..cd9fb02dfa --- /dev/null +++ b/its/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 MNG-6972. + */ +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/its/core-it-suite/src/test/resources/mng-6972-allow-access-to-graph-package/build-plugin/pom.xml b/its/core-it-suite/src/test/resources/mng-6972-allow-access-to-graph-package/build-plugin/pom.xml new file mode 100644 index 0000000000..7a25a060de --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-6972-allow-access-to-graph-package/build-plugin/pom.xml @@ -0,0 +1,67 @@ + + + + + + 4.0.0 + + mng-6972-allow-access-to-graph-package + build-plugin + 1.0 + + + UTF-8 + 1.8 + ${maven.compiler.source} + + 1.5.5 + 3.3.1 + + + + + org.apache.maven + maven-core + ${maven-version} + provided + + + org.codehaus.plexus + plexus-component-annotations + ${plexus-component.version} + + + + + + org.codehaus.plexus + plexus-component-metadata + ${plexus-component.version} + + + + generate-metadata + + + + + + + diff --git a/its/core-it-suite/src/test/resources/mng-6972-allow-access-to-graph-package/build-plugin/src/main/java/com/example/BuildExtensionUsingGraphPackage.java b/its/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 0000000000..d3889d4e3c --- /dev/null +++ b/its/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 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/its/core-it-suite/src/test/resources/mng-6972-allow-access-to-graph-package/using-module/pom.xml b/its/core-it-suite/src/test/resources/mng-6972-allow-access-to-graph-package/using-module/pom.xml new file mode 100644 index 0000000000..a91056bcb7 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-6972-allow-access-to-graph-package/using-module/pom.xml @@ -0,0 +1,38 @@ + + + + + + 4.0.0 + + mng-6972-allow-access-to-graph-package + using-module + 1 + + + + + mng-6972-allow-access-to-graph-package + build-plugin + 1.0 + + + +