[prev in list] [next in list] [prev in thread] [next in thread]
List: maven-dev
Subject: svn commit: r939608 - in /maven/plugins/trunk/maven-invoker-plugin/src:
From: bentmann () apache ! org
Date: 2010-04-30 9:45:56
Message-ID: 20100430094556.65C6423888E4 () eris ! apache ! org
[Download RAW message or body]
Author: bentmann
Date: Fri Apr 30 09:45:55 2010
New Revision: 939608
URL: http://svn.apache.org/viewvc?rev=939608&view=rev
Log:
[MINVOKER-102] Provide a way to install Extra dependencies
Submitted by: Marvin Froeder
Added:
maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/
maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/pom.xml \
(with props) maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/src/
maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/src/it/
maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/src/it/project/
maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/src/it/project/pom.xml \
(with props) maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/src/it/settings.xml \
(with props) maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/verify.bsh \
(with props) Modified:
maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java
Added: maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/pom.xml?rev=939608&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/pom.xml \
(added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/pom.xml \
Fri Apr 30 09:45:55 2010 @@ -0,0 +1,56 @@
+<?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.plugins.invoker</groupId>
+ <artifactId>local-repo-isolated</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <description>
+ Test to check for usage of an isolated local repository.
+ </description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <version>@pom.version@</version>
+ <configuration>
+ <localRepositoryPath>${project.build.directory}/it-repo</localRepositoryPath>
+ <pomIncludes>
+ <pomInclude>*/pom.xml</pomInclude>
+ </pomIncludes>
+ <settingsFile>src/it/settings.xml</settingsFile>
+ <extraArtifacts>
+ <extraArtifact>asm:asm:3.0</extraArtifact>
+ <extraArtifact>org.apache.maven.plugins:maven-clean-plugin:2.4:maven-plugin</extraArtifact>
+ <extraArtifact>org.apache.maven.plugins:maven-clean-plugin:2.4:jar:javadoc</extraArtifact>
+ </extraArtifacts>
+ </configuration>
+ <executions>
+ <execution>
+ <id>integration-test</id>
+ <phase>initialize</phase>
+ <goals>
+ <goal>install</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/src/it/project/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/src/it/project/pom.xml?rev=939608&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/src/it/project/pom.xml \
(added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/src/it/project/pom.xml \
Fri Apr 30 09:45:55 2010 @@ -0,0 +1,32 @@
+<?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>test</groupId>
+ <artifactId>local-repo-isolated</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+</project>
Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/src/it/project/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/src/it/project/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/src/it/settings.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/src/it/settings.xml?rev=939608&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/src/it/settings.xml \
(added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/src/it/settings.xml \
Fri Apr 30 09:45:55 2010 @@ -0,0 +1,57 @@
+<?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.
+-->
+
+<settings>
+ <!-- This path must be ignored, the path from the plugin configuration is always \
dominant --> + <localRepository>@project.build.directory@/bad-repo</localRepository>
+ <profiles>
+ <profile>
+ <id>it-repo</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <repositories>
+ <repository>
+ <id>local.central</id>
+ <url>file://@localRepository@</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>local.central</id>
+ <url>file://@localRepository@</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
+ </profiles>
+</settings>
Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/src/it/settings.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/src/it/settings.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/verify.bsh?rev=939608&view=auto
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/verify.bsh \
(added)
+++ maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/verify.bsh \
Fri Apr 30 09:45:55 2010 @@ -0,0 +1,55 @@
+import java.io.*;
+import java.util.*;
+import java.util.regex.*;
+
+try
+{
+ File itRepoDir = new File( basedir, "target/it-repo" );
+ if ( !itRepoDir.isDirectory() )
+ {
+ System.out.println( "IT local repository missing: " + itRepoDir );
+ return false;
+ }
+
+ File installedFile = new File( itRepoDir, \
"org/apache/maven/plugins/maven-clean-plugin/2.4/maven-clean-plugin-2.4.pom" ); + \
if ( !installedFile.isFile() ) + {
+ System.out.println( "Installed file missing in local repo: " + installedFile \
); + return false;
+ }
+
+ installedFile = new File( itRepoDir, \
"org/apache/maven/plugins/maven-clean-plugin/2.4/maven-clean-plugin-2.4.jar" ); + \
if ( !installedFile.isFile() ) + {
+ System.out.println( "Installed file missing in local repo: " + installedFile \
); + return false;
+ }
+
+ installedFile = new File( itRepoDir, \
"org/apache/maven/plugins/maven-clean-plugin/2.4/maven-clean-plugin-2.4-javadoc.jar" \
); + if ( !installedFile.isFile() )
+ {
+ System.out.println( "Installed file missing in local repo: " + installedFile \
); + return false;
+ }
+
+ installedFile = new File( itRepoDir, "asm/asm/3.0/asm-3.0.jar" );
+ if ( !installedFile.isFile() )
+ {
+ System.out.println( "Installed file missing in local repo: " + installedFile \
); + return false;
+ }
+
+ installedFile = new File( itRepoDir, "asm/asm/3.0/asm-3.0.pom" );
+ if ( !installedFile.isFile() )
+ {
+ System.out.println( "Installed file missing in local repo: " + installedFile \
); + return false;
+ }
+}
+catch( Throwable t )
+{
+ t.printStackTrace();
+ return false;
+}
+
+return true;
Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/verify.bsh
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-invoker-plugin/src/it/install-extra-artifacts/verify.bsh
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/ja \
va/org/apache/maven/plugin/invoker/InstallMojo.java?rev=939608&r1=939607&r2=939608&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java \
(original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/InstallMojo.java \
Fri Apr 30 09:45:55 2010 @@ -22,17 +22,24 @@ package org.apache.maven.plugin.invoker;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.installer.ArtifactInstaller;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
+import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.resolver.ResolutionNode;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.plugin.AbstractMojo;
@@ -132,6 +139,48 @@ public class InstallMojo
private Collection copiedArtifacts;
/**
+ * Extra dependencies that needed to be installed on the local repository.<BR>
+ * Format:
+ *
+ * <pre>
+ * groupId:artifactId:version:type:classifier
+ * </pre>
+ *
+ * Examples:
+ *
+ * <pre>
+ * org.apache.maven.plugins:maven-clean-plugin:2.4:maven-plugin
+ * org.apache.maven.plugins:maven-clean-plugin:2.4:jar:javadoc
+ * </pre>
+ *
+ * If the type is 'maven-plugin' the plugin will try to resolve the artifact \
using plugin remote repositories, + * instead of using artifact remore \
repository. + *
+ * @parameter
+ */
+ private String[] extraArtifacts;
+
+ /**
+ * @component
+ */
+ private ArtifactResolver resolver;
+
+ /**
+ * @parameter default-value="${project.remoteArtifactRepositories}"
+ */
+ private List remoteRepositories;
+
+ /**
+ * @parameter default-value="${project.pluginArtifactRepositories}"
+ */
+ private List remotePluginRepositories;
+
+ /**
+ * @component
+ */
+ private ArtifactMetadataSource artifactMetadataSource;
+
+ /**
* Performs this mojo's tasks.
*
* @throws MojoExecutionException If the artifacts could not be installed.
@@ -153,6 +202,11 @@ public class InstallMojo
installProjectDependencies( project, reactorProjects, testRepository );
installProjectParents( project, testRepository );
installProjectArtifacts( project, testRepository );
+
+ if ( extraArtifacts != null )
+ {
+ installExtraArtifacts( testRepository, extraArtifacts );
+ }
}
/**
@@ -447,29 +501,7 @@ public class InstallMojo
{
Artifact artifact = (Artifact) it.next();
- Artifact depArtifact =
- artifactFactory.createArtifactWithClassifier( \
artifact.getGroupId(), artifact.getArtifactId(),
- \
artifact.getBaseVersion(), artifact.getType(),
- \
artifact.getClassifier() );
-
- File artifactFile = artifact.getFile();
-
- Artifact pomArtifact =
- artifactFactory.createProjectArtifact( depArtifact.getGroupId(), \
depArtifact.getArtifactId(),
- \
depArtifact.getBaseVersion() );
-
- File pomFile = new File( localRepository.getBasedir(), \
localRepository.pathOf( pomArtifact ) );
-
- if ( pomFile.isFile() )
- {
- if ( !pomArtifact.getId().equals( depArtifact.getId() ) )
- {
- copyArtifact( pomFile, pomArtifact, testRepository );
- }
- copyParentPoms( pomFile, testRepository );
- }
-
- copyArtifact( artifactFile, depArtifact, testRepository );
+ copyArtifact( artifact, testRepository );
}
// install dependencies that were resolved from the reactor
@@ -489,6 +521,34 @@ public class InstallMojo
}
}
+ private void copyArtifact( Artifact artifact, ArtifactRepository testRepository \
) + throws MojoExecutionException
+ {
+ Artifact depArtifact =
+ artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), \
artifact.getArtifactId(), + \
artifact.getBaseVersion(), artifact.getType(), + \
artifact.getClassifier() ); +
+ File artifactFile = artifact.getFile();
+
+ Artifact pomArtifact =
+ artifactFactory.createProjectArtifact( depArtifact.getGroupId(), \
depArtifact.getArtifactId(), + \
depArtifact.getBaseVersion() ); +
+ File pomFile = new File( localRepository.getBasedir(), \
localRepository.pathOf( pomArtifact ) ); +
+ if ( pomFile.isFile() )
+ {
+ if ( !pomArtifact.getId().equals( depArtifact.getId() ) )
+ {
+ copyArtifact( pomFile, pomArtifact, testRepository );
+ }
+ copyParentPoms( pomFile, testRepository );
+ }
+
+ copyArtifact( artifactFile, depArtifact, testRepository );
+ }
+
/**
* Installs all parent POMs of the specified POM file that are available in the \
local repository.
*
@@ -535,4 +595,66 @@ public class InstallMojo
}
}
+ private void installExtraArtifacts( ArtifactRepository testRepository, String[] \
extraArtifacts ) + throws MojoExecutionException
+ {
+ for ( int i = 0; i < extraArtifacts.length; i++ )
+ {
+ String[] gav = extraArtifacts[i].split( ":" );
+ if ( gav.length < 3 || gav.length > 5 )
+ {
+ throw new MojoExecutionException( "Invalid artifact " + \
extraArtifacts[i] ); + }
+
+ String type = null;
+ if ( gav.length > 3 )
+ {
+ type = gav[3];
+ }
+ else
+ {
+ type = "jar";
+ }
+
+ String classifier = null;
+ if ( gav.length == 5 )
+ {
+ classifier = gav[4];
+ }
+
+ List remoteRepositories;
+ if ( "maven-plugin".equals( type ) )
+ {
+ remoteRepositories = this.remotePluginRepositories;
+ }
+ else
+ {
+ remoteRepositories = this.remoteRepositories;
+ }
+
+ Artifact artifact = null;
+ try
+ {
+ artifact = artifactFactory.createArtifactWithClassifier( gav[0], \
gav[1], gav[2], type, classifier ); +
+ Artifact originatingArtifact = artifactFactory.createBuildArtifact( \
"dummy", "dummy", "1.0", "jar" ); +
+ ArtifactResolutionResult arr =
+ resolver.resolveTransitively( Collections.singleton( artifact ), \
originatingArtifact, + \
remoteRepositories, localRepository, artifactMetadataSource ); +
+ Set nodes = arr.getArtifactResolutionNodes();
+ for ( Iterator iterator = nodes.iterator(); iterator.hasNext(); )
+ {
+ ResolutionNode node = (ResolutionNode) iterator.next();
+ copyArtifact( node.getArtifact(), testRepository );
+ }
+ }
+ catch ( Exception e )
+ {
+ throw new MojoExecutionException( "Unable to resolve dependencies \
for: " + artifact, e ); + }
+ }
+ }
+
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic