You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2009/11/17 23:02:43 UTC

svn commit: r881561 - in /maven/core-integration-testing/trunk: core-it-suite/src/test/java/org/apache/maven/it/ core-it-suite/src/test/resources/mng-4450/ core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/c...

Author: bentmann
Date: Tue Nov 17 22:02:42 2009
New Revision: 881561

URL: http://svn.apache.org/viewvc?rev=881561&view=rev
Log:
[MNG-4450] [regression] Stub project for missing dependency POMs is not properly created

o Added IT

Added:
    maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4450StubModelForMissingDependencyPomTest.java   (with props)
    maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4450/
    maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4450/pom.xml   (with props)
    maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/BuildPomMojo.java   (with props)
Modified:
    maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java

Modified: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java?rev=881561&r1=881560&r2=881561&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java (original)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java Tue Nov 17 22:02:42 2009
@@ -85,6 +85,7 @@
         // suite.addTestSuite( MavenIT0109ReleaseUpdateTest.class );
         // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
 
+        suite.addTestSuite( MavenITmng4450StubModelForMissingDependencyPomTest.class );
         suite.addTestSuite( MavenITmng4448FollowHttpRedirectTest.class );
         suite.addTestSuite( MavenITmng4436SingletonComponentLookupTest.class );
         suite.addTestSuite( MavenITmng4433ForceParentSnapshotUpdateTest.class );

Added: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4450StubModelForMissingDependencyPomTest.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4450StubModelForMissingDependencyPomTest.java?rev=881561&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4450StubModelForMissingDependencyPomTest.java (added)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4450StubModelForMissingDependencyPomTest.java Tue Nov 17 22:02:42 2009
@@ -0,0 +1,65 @@
+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.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+
+import java.io.File;
+import java.util.Properties;
+
+/**
+ * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4450">MNG-4450</a>.
+ * 
+ * @author Benjamin Bentmann
+ */
+public class MavenITmng4450StubModelForMissingDependencyPomTest
+    extends AbstractMavenIntegrationTestCase
+{
+
+    public MavenITmng4450StubModelForMissingDependencyPomTest()
+    {
+        super( "[2.0.3,3.0-alpha-1),[3.0-alpha-5,)" );
+    }
+
+    /**
+     * Verify that building missing POMs for dependencies fails gracefully with a stub model.
+     */
+    public void testit()
+        throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4450" );
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+        verifier.setAutoclean( false );
+        verifier.deleteDirectory( "target" );
+        verifier.executeGoal( "validate" );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        Properties props = verifier.loadProperties( "target/pom.properties" );
+
+        assertEquals( "org.apache.maven.its.mng4450:missing:pom:0.1", 
+            props.getProperty( "org.apache.maven.its.mng4450:missing:jar:0.1.project.id" ) );
+        assertEquals( "org.apache.maven.its.mng4450:missing:pom:0.1", 
+            props.getProperty( "org.apache.maven.its.mng4450:missing:jar:0.1.artifact.id" ) );
+    }
+
+}

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4450StubModelForMissingDependencyPomTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4450StubModelForMissingDependencyPomTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4450/pom.xml
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4450/pom.xml?rev=881561&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4450/pom.xml (added)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4450/pom.xml Tue Nov 17 22:02:42 2009
@@ -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>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.mng4450</groupId>
+  <artifactId>test</artifactId>
+  <version>0.1</version>
+  <packaging>jar</packaging>
+
+  <name>Maven Integration Test :: MNG-4450</name>
+  <description>
+    Verify that building missing POMs for dependencies fails gracefully with a stub model.
+  </description>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.its.plugins</groupId>
+        <artifactId>maven-it-plugin-artifact</artifactId>
+        <version>2.1-SNAPSHOT</version>
+        <executions>
+          <execution>
+            <id>test</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>build-pom</goal>
+            </goals>
+            <configuration>
+              <dependencies>
+                <dependency>
+                  <groupId>org.apache.maven.its.mng4450</groupId>
+                  <artifactId>missing</artifactId>
+                  <version>0.1</version>
+                </dependency>
+              </dependencies>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4450/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4450/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/BuildPomMojo.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/BuildPomMojo.java?rev=881561&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/BuildPomMojo.java (added)
+++ maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/BuildPomMojo.java Tue Nov 17 22:02:42 2009
@@ -0,0 +1,159 @@
+package org.apache.maven.plugin.coreit;
+
+/*
+ * 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.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectBuilder;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+
+/**
+ * Builds the remote POMs of user-specified artifacts. This mimics in part the Maven Remote Resources Plugin.
+ * 
+ * @goal build-pom
+ * 
+ * @author Benjamin Bentmann
+ * @version $Id$
+ */
+public class BuildPomMojo
+    extends AbstractMojo
+{
+
+    /**
+     * The properties file to dump the POM info to.
+     * 
+     * @parameter default-value="target/pom.properties"
+     */
+    private File propertiesFile;
+
+    /**
+     * The local repository.
+     * 
+     * @parameter default-value="${localRepository}"
+     * @readonly
+     * @required
+     */
+    private ArtifactRepository localRepository;
+
+    /**
+     * The remote repositories of the current Maven project.
+     * 
+     * @parameter default-value="${project.remoteArtifactRepositories}"
+     * @readonly
+     * @required
+     */
+    private List remoteRepositories;
+
+    /**
+     * The artifact resolver.
+     * 
+     * @component
+     */
+    private MavenProjectBuilder builder;
+
+    /**
+     * The artifact factory.
+     * 
+     * @component
+     */
+    private ArtifactFactory factory;
+
+    /**
+     * The dependencies to resolve.
+     * 
+     * @parameter
+     */
+    private Dependency[] dependencies;
+
+    /**
+     * Runs this mojo.
+     * 
+     * @throws MojoFailureException If the artifact file has not been set.
+     */
+    public void execute()
+        throws MojoExecutionException, MojoFailureException
+    {
+        Properties props = new Properties();
+
+        getLog().info( "[MAVEN-CORE-IT-LOG] Building remote POMs" );
+
+        if ( dependencies != null )
+        {
+            for ( int i = 0; i < dependencies.length; i++ )
+            {
+                Dependency dependency = dependencies[i];
+
+                Artifact artifact =
+                    factory.createArtifactWithClassifier( dependency.getGroupId(), dependency.getArtifactId(),
+                                                          dependency.getVersion(), dependency.getType(),
+                                                          dependency.getClassifier() );
+
+                getLog().info( "[MAVEN-CORE-IT-LOG] Building " + artifact.getId() );
+
+                try
+                {
+                    MavenProject project = builder.buildFromRepository( artifact, remoteRepositories, localRepository );
+
+                    String key = artifact.getId() + ".";
+                    props.setProperty( key + "project.id", project.getId() );
+                    if ( project.getArtifact() != null )
+                    {
+                        props.setProperty( key + "artifact.id", project.getArtifact().getId() );
+                    }
+                }
+                catch ( Exception e )
+                {
+                    getLog().warn( "Failed to build remote POM for " + artifact.getId(), e );
+                }
+            }
+        }
+
+        try
+        {
+            propertiesFile.getParentFile().mkdirs();
+
+            FileOutputStream os = new FileOutputStream( propertiesFile );
+            try
+            {
+                props.store( os, "[MAVEN-CORE-IT-LOG]" );
+            }
+            finally
+            {
+                os.close();
+            }
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Failed to dump POMs: " + e.getMessage(), e );
+        }
+    }
+
+}

Propchange: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/BuildPomMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-artifact/src/main/java/org/apache/maven/plugin/coreit/BuildPomMojo.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision