[MINSTALL-128] Replace usage of the deprecated ArtifactFactory
In order to fix the use of deprecated code from ArtifactFactory, the install-file Mojo now creates a new MavenProject and attaches to this project all artifacts to install.
git-svn-id: https://svn.apache.org/repos/asf/maven/plugins/trunk@1763933 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/pom.xml b/pom.xml
index ae1e867..37145bb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -110,12 +110,6 @@
<artifactId>maven-plugin-testing-harness</artifactId>
<version>2.1</version>
<scope>test</scope>
- <exclusions>
- <exclusion>
- <artifactId>plexus-container-default</artifactId>
- <groupId>org.codehaus.plexus</groupId>
- </exclusion>
- </exclusions>
</dependency>
<dependency> <!-- used by maven-plugin-testing-harness, don't give it compile scope! -->
<groupId>org.apache.maven</groupId>
diff --git a/src/it/attach-jar-checksum/verify.bsh b/src/it/attach-jar-checksum/verify.bsh
index 5942fd9..0861243 100644
--- a/src/it/attach-jar-checksum/verify.bsh
+++ b/src/it/attach-jar-checksum/verify.bsh
@@ -20,7 +20,7 @@
import java.io.*;
import java.util.*;
-import org.apache.maven.plugin.install.*;
+import org.apache.maven.plugin.install.Utils;
String[] paths =
{
@@ -34,13 +34,16 @@
"org/apache/maven/its/install/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT-sources.jar.md5",
"org/apache/maven/its/install/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT-sources.jar.sha1",
"org/apache/maven/its/install/ajc/test/1.0-SNAPSHOT/maven-metadata-local.xml",
-// "org/apache/maven/its/install/ajc/test/1.0-SNAPSHOT/maven-metadata-local.xml.md5",
-// "org/apache/maven/its/install/ajc/test/1.0-SNAPSHOT/maven-metadata-local.xml.sha1",
"org/apache/maven/its/install/ajc/test/maven-metadata-local.xml",
-// "org/apache/maven/its/install/ajc/test/maven-metadata-local.xml.md5",
-// "org/apache/maven/its/install/ajc/test/maven-metadata-local.xml.sha1",
};
+Set cksumToCheckPaths = new HashSet( Arrays.asList( new String[]
+{
+ "org/apache/maven/its/install/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.pom",
+ "org/apache/maven/its/install/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.jar",
+ "org/apache/maven/its/install/ajc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT-sources.jar"
+} ) );
+
for ( String path : paths )
{
File file = new File( localRepositoryPath, path );
@@ -49,8 +52,8 @@
{
throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() );
}
- if ( file.getName().endsWith( ".md5" ) || file.getName().endsWith( ".sha1" ) )
- {
+ if ( cksumToCheckPaths.contains( path ) )
+ {
System.out.println( "Verifying " + file );
Utils.verifyChecksum( file );
}
diff --git a/src/it/generate-pom-auto-1/verify.bsh b/src/it/generate-pom-auto-1/verify.bsh
index d06e2a7..914139f 100644
--- a/src/it/generate-pom-auto-1/verify.bsh
+++ b/src/it/generate-pom-auto-1/verify.bsh
@@ -20,13 +20,11 @@
import java.io.*;
import java.util.*;
-import org.apache.maven.plugin.install.*;
+import org.apache.maven.plugin.install.Utils;
String[] paths =
{
"org/apache/maven/its/install/gpa1/test/maven-metadata-local.xml",
-// "org/apache/maven/its/install/gpa1/test/maven-metadata-local.xml.md5",
-// "org/apache/maven/its/install/gpa1/test/maven-metadata-local.xml.sha1",
"org/apache/maven/its/install/gpa1/test/0.1/test-0.1.jar",
"org/apache/maven/its/install/gpa1/test/0.1/test-0.1.jar.md5",
"org/apache/maven/its/install/gpa1/test/0.1/test-0.1.jar.sha1",
@@ -35,6 +33,12 @@
"org/apache/maven/its/install/gpa1/test/0.1/test-0.1.pom.sha1",
};
+Set cksumToCheckPaths = new HashSet( Arrays.asList( new String[]
+{
+ "org/apache/maven/its/install/gpa1/test/0.1/test-0.1.jar",
+ "org/apache/maven/its/install/gpa1/test/0.1/test-0.1.pom",
+} ) );
+
for ( String path : paths )
{
File file = new File( localRepositoryPath, path );
@@ -43,8 +47,8 @@
{
throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() );
}
- if ( file.getName().endsWith( ".md5" ) || file.getName().endsWith( ".sha1" ) )
- {
+ if ( cksumToCheckPaths.contains( path ) )
+ {
System.out.println( "Verifying " + file );
Utils.verifyChecksum( file );
}
diff --git a/src/it/jar-sources-javadoc/verify.bsh b/src/it/jar-sources-javadoc/verify.bsh
index 6a224be..c753a27 100644
--- a/src/it/jar-sources-javadoc/verify.bsh
+++ b/src/it/jar-sources-javadoc/verify.bsh
@@ -20,13 +20,11 @@
import java.io.*;
import java.util.*;
-import org.apache.maven.plugin.install.*;
+import org.apache.maven.plugin.install.Utils;
String[] paths =
{
"org/apache/maven/its/install/jsj/test/maven-metadata-local.xml",
-// "org/apache/maven/its/install/jsj/test/maven-metadata-local.xml.md5",
-// "org/apache/maven/its/install/jsj/test/maven-metadata-local.xml.sha1",
"org/apache/maven/its/install/jsj/test/0.1/test-0.1.jar",
"org/apache/maven/its/install/jsj/test/0.1/test-0.1.jar.md5",
"org/apache/maven/its/install/jsj/test/0.1/test-0.1.jar.sha1",
@@ -41,6 +39,14 @@
"org/apache/maven/its/install/jsj/test/0.1/test-0.1-javadoc.jar.sha1",
};
+Set cksumToCheckPaths = new HashSet( Arrays.asList( new String[]
+{
+ "org/apache/maven/its/install/jsj/test/0.1/test-0.1.jar",
+ "org/apache/maven/its/install/jsj/test/0.1/test-0.1.pom",
+ "org/apache/maven/its/install/jsj/test/0.1/test-0.1-sources.jar",
+ "org/apache/maven/its/install/jsj/test/0.1/test-0.1-javadoc.jar"
+} ) );
+
for ( String path : paths )
{
File file = new File( localRepositoryPath, path );
@@ -49,8 +55,8 @@
{
throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() );
}
- if ( file.getName().endsWith( ".md5" ) || file.getName().endsWith( ".sha1" ) )
- {
+ if ( cksumToCheckPaths.contains( path ) )
+ {
System.out.println( "Verifying " + file );
Utils.verifyChecksum( file );
}
diff --git a/src/it/local-repo-override-with-checksum/invoker.properties b/src/it/local-repo-override-with-checksum/invoker.properties
new file mode 100644
index 0000000..0413238
--- /dev/null
+++ b/src/it/local-repo-override-with-checksum/invoker.properties
@@ -0,0 +1,18 @@
+# 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.
+
+invoker.goals = org.apache.maven.plugins:maven-install-plugin:${project.version}:install-file
diff --git a/src/it/local-repo-override-with-checksum/pom.xml b/src/it/local-repo-override-with-checksum/pom.xml
new file mode 100644
index 0000000..0dfca77
--- /dev/null
+++ b/src/it/local-repo-override-with-checksum/pom.xml
@@ -0,0 +1,46 @@
+<?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/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.install.lro</groupId>
+ <artifactId>test</artifactId>
+ <version>1.0</version>
+ <packaging>jar</packaging>
+
+ <description>
+ Tests the manual installation into a different local repo than the one configured in the settings
+ (MINSTALL-35), also installing checksums.
+ </description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <version>@project.version@</version>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/src/it/local-repo-override-with-checksum/setup.bsh b/src/it/local-repo-override-with-checksum/setup.bsh
new file mode 100644
index 0000000..d37913a
--- /dev/null
+++ b/src/it/local-repo-override-with-checksum/setup.bsh
@@ -0,0 +1,29 @@
+/*
+ * 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.*;
+import java.util.*;
+
+import org.codehaus.plexus.util.*;
+
+File file = new File( basedir, "target" );
+System.out.println( "Deleting " + file );
+FileUtils.deleteDirectory( file );
+
+return true;
diff --git a/src/it/local-repo-override-with-checksum/test.jar b/src/it/local-repo-override-with-checksum/test.jar
new file mode 100644
index 0000000..226277c
--- /dev/null
+++ b/src/it/local-repo-override-with-checksum/test.jar
Binary files differ
diff --git a/src/it/local-repo-override-with-checksum/test.properties b/src/it/local-repo-override-with-checksum/test.properties
new file mode 100644
index 0000000..bff58f1
--- /dev/null
+++ b/src/it/local-repo-override-with-checksum/test.properties
@@ -0,0 +1,24 @@
+# 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.
+
+file = test.jar
+groupId = gid
+artifactId = test
+version = 0.1
+packaging = jar
+createChecksum = true
+localRepositoryPath = target/local-repo
diff --git a/src/it/local-repo-override-with-checksum/verify.bsh b/src/it/local-repo-override-with-checksum/verify.bsh
new file mode 100644
index 0000000..b7b2757
--- /dev/null
+++ b/src/it/local-repo-override-with-checksum/verify.bsh
@@ -0,0 +1,40 @@
+/*
+ * 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.*;
+import java.util.*;
+
+String[] paths =
+{
+ "gid/test/0.1/test-0.1.jar",
+ "gid/test/0.1/test-0.1.jar.md5",
+ "gid/test/0.1/test-0.1.jar.sha1",
+};
+
+for ( String path : paths )
+{
+ File file = new File( new File( basedir, "target/local-repo" ), path );
+ System.out.println( "Checking for existence of " + file );
+ if ( !file.isFile() )
+ {
+ throw new FileNotFoundException( "Existing: " + file.getAbsolutePath() );
+ }
+}
+
+return true;
diff --git a/src/it/pom-checksum/verify.bsh b/src/it/pom-checksum/verify.bsh
index 8419eb6..7d323ae 100644
--- a/src/it/pom-checksum/verify.bsh
+++ b/src/it/pom-checksum/verify.bsh
@@ -20,7 +20,7 @@
import java.io.*;
import java.util.*;
-import org.apache.maven.plugin.install.*;
+import org.apache.maven.plugin.install.Utils;
String[] paths =
{
@@ -28,13 +28,14 @@
"org/apache/maven/its/install/pc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.pom.md5",
"org/apache/maven/its/install/pc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.pom.sha1",
"org/apache/maven/its/install/pc/test/1.0-SNAPSHOT/maven-metadata-local.xml",
-// "org/apache/maven/its/install/pc/test/1.0-SNAPSHOT/maven-metadata-local.xml.md5",
-// "org/apache/maven/its/install/pc/test/1.0-SNAPSHOT/maven-metadata-local.xml.sha1",
"org/apache/maven/its/install/pc/test/maven-metadata-local.xml",
-// "org/apache/maven/its/install/pc/test/maven-metadata-local.xml.md5",
-// "org/apache/maven/its/install/pc/test/maven-metadata-local.xml.sha1",
};
+Set cksumToCheckPaths = new HashSet( Arrays.asList( new String[]
+{
+ "org/apache/maven/its/install/pc/test/1.0-SNAPSHOT/test-1.0-SNAPSHOT.pom"
+} ) );
+
for ( String path : paths )
{
File file = new File( localRepositoryPath, path );
@@ -43,8 +44,8 @@
{
throw new FileNotFoundException( "Missing: " + file.getAbsolutePath() );
}
- if ( file.getName().endsWith( ".md5" ) || file.getName().endsWith( ".sha1" ) )
- {
+ if ( cksumToCheckPaths.contains( path ) )
+ {
System.out.println( "Verifying " + file );
Utils.verifyChecksum( file );
}
diff --git a/src/main/java/org/apache/maven/plugin/install/AbstractInstallMojo.java b/src/main/java/org/apache/maven/plugin/install/AbstractInstallMojo.java
index cc70542..b87884c 100644
--- a/src/main/java/org/apache/maven/plugin/install/AbstractInstallMojo.java
+++ b/src/main/java/org/apache/maven/plugin/install/AbstractInstallMojo.java
@@ -20,21 +20,15 @@
*/
import java.io.File;
-import java.io.IOException;
-import java.util.Collection;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.shared.artifact.install.ArtifactInstaller;
+import org.apache.maven.project.artifact.ProjectArtifactMetadata;
import org.apache.maven.shared.repository.RepositoryManager;
-import org.apache.maven.shared.utils.io.FileUtils;
/**
* Common fields for installation mojos.
@@ -46,16 +40,6 @@
extends AbstractMojo
{
- /**
- */
- @Component
- protected ArtifactFactory artifactFactory;
-
- /**
- */
- @Component
- protected ArtifactInstaller installer;
-
@Component
protected RepositoryManager repositoryManager;
@@ -78,8 +62,6 @@
@Parameter( property = "updateReleaseInfo", defaultValue = "false" )
protected boolean updateReleaseInfo;
- protected final DualDigester digester = new DualDigester();
-
@Parameter( defaultValue = "${session}", required = true, readonly = true )
protected MavenSession session;
@@ -103,116 +85,10 @@
* @param metadata The artifact metadata whose local repo path should be determined, must not be <code>null</code>.
* @return The absolute path to the artifact metadata when installed, never <code>null</code>.
*/
- protected File getLocalRepoFile( ArtifactMetadata metadata )
+ protected File getLocalRepoFile( ProjectArtifactMetadata metadata )
{
String path = localRepository.pathOfLocalRepositoryMetadata( metadata, localRepository );
return new File( localRepository.getBasedir(), path );
}
- /**
- * Installs the checksums for the specified artifact if this has been enabled in the plugin configuration. This
- * method creates checksums for files that have already been installed to the local repo to account for on-the-fly
- * generated/updated files. For example, in Maven 2.0.4- the <code>ProjectArtifactMetadata</code> did not install
- * the original POM file (cf. MNG-2820). While the plugin currently requires Maven 2.0.6, we continue to hash the
- * installed POM for robustness with regard to future changes like re-introducing some kind of POM filtering.
- *
- * @param artifact The artifact for which to create checksums, must not be <code>null</code>.
- * @param createChecksum {@code true} if checksum should be created, otherwise {@code false}.
- * @throws MojoExecutionException If the checksums could not be installed.
- */
- protected void installChecksums( Artifact artifact, boolean createChecksum )
- throws MojoExecutionException
- {
- if ( !createChecksum )
- {
- return;
- }
-
- File artifactFile = getLocalRepoFile( artifact );
- installChecksums( artifactFile );
- }
-
- // CHECKSTYLE_OFF: LineLength
- protected void addMetaDataFilesForArtifact( Artifact artifact, Collection<File> targetMetadataFiles, boolean createChecksum )
- // CHECKSTYLE_ON: LineLength
- {
- if ( !createChecksum )
- {
- return;
- }
-
- Collection<ArtifactMetadata> metadatas = artifact.getMetadataList();
- if ( metadatas != null )
- {
- for ( ArtifactMetadata metadata : metadatas )
- {
- File metadataFile = getLocalRepoFile( metadata );
- targetMetadataFiles.add( metadataFile );
- }
- }
- }
-
- /**
- * Installs the checksums for the specified metadata files.
- *
- * @param metadataFiles The collection of metadata files to install checksums for, must not be <code>null</code>.
- * @throws MojoExecutionException If the checksums could not be installed.
- */
- protected void installChecksums( Collection<File> metadataFiles )
- throws MojoExecutionException
- {
- for ( File metadataFile : metadataFiles )
- {
- installChecksums( metadataFile );
- }
- }
-
- /**
- * Installs the checksums for the specified file (if it exists).
- *
- * @param installedFile The path to the already installed file in the local repo for which to generate checksums,
- * must not be <code>null</code>.
- * @throws MojoExecutionException If the checksums could not be installed.
- */
- private void installChecksums( File installedFile )
- throws MojoExecutionException
- {
- boolean signatureFile = installedFile.getName().endsWith( ".asc" );
- if ( installedFile.isFile() && !signatureFile )
- {
-
- getLog().debug( "Calculating checksums for " + installedFile );
- digester.calculate( installedFile );
- installChecksum( installedFile, ".md5", digester.getMd5() );
- installChecksum( installedFile, ".sha1", digester.getSha1() );
- }
- }
-
- /**
- * Installs a checksum for the specified file.
- *
- * @param installedFile The base path from which the path to the checksum files is derived by appending the given
- * file extension, must not be <code>null</code>.
- * @param ext The file extension (including the leading dot) to use for the checksum file, must not be
- * <code>null</code>.
- * @param checksum the checksum to write
- * @throws MojoExecutionException If the checksum could not be installed.
- */
- private void installChecksum( File installedFile, String ext, String checksum )
- throws MojoExecutionException
- {
- File checksumFile = new File( installedFile.getAbsolutePath() + ext );
- getLog().debug( "Installing checksum to " + checksumFile );
- try
- {
- //noinspection ResultOfMethodCallIgnored
- checksumFile.getParentFile().mkdirs();
- FileUtils.fileWrite( checksumFile.getAbsolutePath(), "UTF-8", checksum );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Failed to install checksum to " + checksumFile, e );
- }
- }
-
}
diff --git a/src/main/java/org/apache/maven/plugin/install/DualDigester.java b/src/main/java/org/apache/maven/plugin/install/DualDigester.java
deleted file mode 100644
index ba83ac4..0000000
--- a/src/main/java/org/apache/maven/plugin/install/DualDigester.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package org.apache.maven.plugin.install;
-
-/*
- * 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 java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-import org.apache.commons.codec.binary.Hex;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.codehaus.plexus.util.IOUtil;
-
-
-/**
- * Calculates md5 and sha1 digest.
- * <p/>
- * Todo: Consider using a thread to calculate one of the digests when the files are large; it's fairly slow !
- *
- * @author Kristian Rosenvold
- */
-public class DualDigester
-{
- private final MessageDigest md5 = getDigester( "MD5" );
-
- private final MessageDigest sh1 = getDigester( "SHA-1" );
-
- private static final int BUFSIZE = 65536 * 2;
-
- private final byte[] buffer = new byte[BUFSIZE];
-
- static MessageDigest getDigester( String algorithm )
- {
- try
- {
- return MessageDigest.getInstance( algorithm );
- }
- catch ( NoSuchAlgorithmException e )
- {
- throw new RuntimeException( "Unable to initialize digest " + algorithm + " : " + e.getMessage() );
- }
- }
-
- public void calculate( File file )
- throws MojoExecutionException
- {
- FileInputStream fis = null;
-
- try
- {
- fis = new FileInputStream( file );
- calculate( fis );
- fis.close();
- fis = null;
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Failed to calculate digest checksum for " + file, e );
- }
- finally
- {
- IOUtil.close( fis );
- }
- }
-
- void calculate( InputStream stream )
- throws IOException
- {
- md5.reset();
- sh1.reset();
- update( stream );
- }
-
- public String getMd5()
- {
- return Hex.encodeHexString( md5.digest() );
- }
-
- public String getSha1()
- {
- return Hex.encodeHexString( sh1.digest() );
- }
-
- private void update( InputStream is )
- throws IOException
- {
- int size = is.read( buffer, 0, BUFSIZE );
- while ( size >= 0 )
- {
- md5.update( buffer, 0, size );
- sh1.update( buffer, 0, size );
- size = is.read( buffer, 0, BUFSIZE );
- }
- }
-}
diff --git a/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java b/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
index 2bf4617..fcdfaf3 100644
--- a/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
+++ b/src/main/java/org/apache/maven/plugin/install/InstallFileMojo.java
@@ -28,17 +28,13 @@
import java.io.Reader;
import java.io.Writer;
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
import java.util.Enumeration;
-import java.util.LinkedHashSet;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.regex.Pattern;
import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.model.InputLocation;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
@@ -46,6 +42,8 @@
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.model.building.ModelProblemCollector;
+import org.apache.maven.model.building.ModelSource;
+import org.apache.maven.model.building.StringModelSource;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.model.validation.ModelValidator;
@@ -54,9 +52,15 @@
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.DefaultProjectBuildingRequest;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
+import org.apache.maven.project.ProjectBuilder;
+import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
-import org.apache.maven.shared.artifact.install.ArtifactInstallerException;
+import org.apache.maven.shared.project.install.ProjectInstaller;
+import org.apache.maven.shared.project.install.ProjectInstallerRequest;
import org.apache.maven.shared.utils.ReaderFactory;
import org.apache.maven.shared.utils.WriterFactory;
import org.apache.maven.shared.utils.io.IOUtil;
@@ -78,28 +82,28 @@
* {@code pom.xml} in jar if available.
*/
@Parameter( property = "groupId" )
- protected String groupId;
+ private String groupId;
/**
* ArtifactId of the artifact to be installed. Retrieved from POM file if one is specified or extracted from
* {@code pom.xml} in jar if available.
*/
@Parameter( property = "artifactId" )
- protected String artifactId;
+ private String artifactId;
/**
* Version of the artifact to be installed. Retrieved from POM file if one is specified or extracted from
* {@code pom.xml} in jar if available.
*/
@Parameter( property = "version" )
- protected String version;
+ private String version;
/**
* Packaging type of the artifact to be installed. Retrieved from POM file if one is specified or extracted from
* {@code pom.xml} in jar if available.
*/
@Parameter( property = "packaging" )
- protected String packaging;
+ private String packaging;
/**
* Classifier type of the artifact to be installed. For example, "sources" or "javadoc". Defaults to none which
@@ -108,7 +112,7 @@
* @since 2.2
*/
@Parameter( property = "classifier" )
- protected String classifier;
+ private String classifier;
/**
* The file to be installed in the local repository.
@@ -166,6 +170,24 @@
private ModelValidator modelValidator;
/**
+ * Used for attaching the artifacts to install to the project.
+ */
+ @Component
+ private MavenProjectHelper projectHelper;
+
+ /**
+ * Used for creating the project to which the artifacts to install will be attached.
+ */
+ @Component
+ private ProjectBuilder projectBuilder;
+
+ /**
+ * Used to install the project created.
+ */
+ @Component
+ private ProjectInstaller installer;
+
+ /**
* @see org.apache.maven.plugin.Mojo#execute()
*/
public void execute()
@@ -202,34 +224,57 @@
validateArtifactInformation();
- Artifact artifact =
- artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, packaging, classifier );
-
+ MavenProject project = createMavenProject();
+ Artifact artifact = project.getArtifact();
+
if ( file.equals( getLocalRepoFile( artifact ) ) )
{
throw new MojoFailureException( "Cannot install artifact. "
+ "Artifact is already in the local repository.\n\nFile in question is: " + file + "\n" );
}
- artifact.setFile( file );
-
- File generatedPomFile = null;
+
+ if ( classifier == null )
+ {
+ artifact.setFile( file );
+ if ( "pom".equals( packaging ) )
+ {
+ project.setFile( file );
+ }
+ }
+ else
+ {
+ projectHelper.attachArtifact( project, packaging, classifier, file );
+ }
if ( !"pom".equals( packaging ) )
{
if ( pomFile != null )
{
- ArtifactMetadata pomMetadata = new ProjectArtifactMetadata( artifact, pomFile );
- artifact.addMetadata( pomMetadata );
+ if ( classifier == null )
+ {
+ artifact.addMetadata( new ProjectArtifactMetadata( artifact, pomFile ) );
+ }
+ else
+ {
+ project.setFile( pomFile );
+ }
}
else
{
- generatedPomFile = generatePomFile();
- ArtifactMetadata pomMetadata = new ProjectArtifactMetadata( artifact, generatedPomFile );
+ File generatedPomFile = generatePomFile();
+ ProjectArtifactMetadata pomMetadata = new ProjectArtifactMetadata( artifact, generatedPomFile );
if ( Boolean.TRUE.equals( generatePom )
|| ( generatePom == null && !getLocalRepoFile( pomMetadata ).exists() ) )
{
getLog().debug( "Installing generated POM" );
- artifact.addMetadata( pomMetadata );
+ if ( classifier == null )
+ {
+ artifact.addMetadata( pomMetadata );
+ }
+ else
+ {
+ project.setFile( generatedPomFile );
+ }
}
else if ( generatePom == null )
{
@@ -238,74 +283,57 @@
}
}
- if ( updateReleaseInfo )
- {
- artifact.setRelease( true );
- }
-
- Collection<File> metadataFiles = new LinkedHashSet<File>();
-
- // TODO: maybe not strictly correct, while we should enforce that packaging has a type handler of the same id,
- // we don't
- try
- {
-// installer.install( file, artifact, localRepository );
- installer.install( buildingRequest, Collections.singletonList( artifact ) );
- installChecksums( artifact, createChecksum );
- addMetaDataFilesForArtifact( artifact, metadataFiles, createChecksum );
-
- }
- catch ( ArtifactInstallerException e )
- {
- throw new MojoExecutionException( "Error installing artifact '" + artifact.getDependencyConflictId()
- + "': " + e.getMessage(), e );
- }
- finally
- {
- if ( generatedPomFile != null )
- {
- // noinspection ResultOfMethodCallIgnored
- generatedPomFile.delete();
- }
- }
-
if ( sources != null )
{
- artifact = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, "jar", "sources" );
- artifact.setFile( sources );
- try
- {
-// installer.install( sources, artifact, localRepository );
- installer.install( buildingRequest, Collections.singletonList( artifact ) );
- installChecksums( artifact, createChecksum );
- addMetaDataFilesForArtifact( artifact, metadataFiles, createChecksum );
-
- }
- catch ( ArtifactInstallerException e )
- {
- throw new MojoExecutionException( "Error installing sources " + sources + ": " + e.getMessage(), e );
- }
+ projectHelper.attachArtifact( project, "jar", "sources", sources );
}
if ( javadoc != null )
{
- artifact = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, "jar", "javadoc" );
- artifact.setFile( javadoc );
- try
- {
-// installer.install( javadoc, artifact, localRepository );
- installer.install( buildingRequest, Collections.singletonList( artifact ) );
- installChecksums( artifact, createChecksum );
- addMetaDataFilesForArtifact( artifact, metadataFiles, createChecksum );
-
- }
- catch ( ArtifactInstallerException e )
- {
- throw new MojoExecutionException( "Error installing API docs " + javadoc + ": " + e.getMessage(), e );
- }
+ projectHelper.attachArtifact( project, "jar", "javadoc", javadoc );
}
+
+ try
+ {
+ // CHECKSTYLE_OFF: LineLength
+ ProjectInstallerRequest projectInstallerRequest =
+ new ProjectInstallerRequest().setProject( project ).setCreateChecksum( createChecksum ).setUpdateReleaseInfo( updateReleaseInfo );
+ // CHECKSTYLE_ON: LineLength
- installChecksums( metadataFiles );
+ installer.install( buildingRequest, projectInstallerRequest, localRepository );
+ }
+ catch ( Exception e )
+ {
+ throw new MojoExecutionException( e.getMessage(), e );
+ }
+ }
+
+ /**
+ * Creates a Maven project in-memory from the user-supplied groupId, artifactId and version. When a classifier is
+ * supplied, the packaging must be POM because the project with only have attachments. This project serves as basis
+ * to attach the artifacts to install to.
+ *
+ * @return The created Maven project, never <code>null</code>.
+ * @throws MojoFailureException When building the project failed.
+ */
+ private MavenProject createMavenProject()
+ throws MojoFailureException
+ {
+ ModelSource modelSource =
+ new StringModelSource( "<project>" + "<modelVersion>4.0.0</modelVersion>" + "<groupId>" + groupId
+ + "</groupId>" + "<artifactId>" + artifactId + "</artifactId>" + "<version>" + version + "</version>"
+ + "<packaging>" + ( classifier == null ? packaging : "pom" ) + "</packaging>" + "</project>" );
+ DefaultProjectBuildingRequest buildingRequest =
+ new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() );
+ buildingRequest.setProcessPlugins( false );
+ try
+ {
+ return projectBuilder.build( modelSource, buildingRequest ).getProject();
+ }
+ catch ( ProjectBuildingException e )
+ {
+ throw new MojoFailureException( e.getMessage(), e );
+ }
}
private void readingPomFromJarFile()
diff --git a/src/test/java/org/apache/maven/plugin/install/DualDigesterTest.java b/src/test/java/org/apache/maven/plugin/install/DualDigesterTest.java
deleted file mode 100644
index 0cb9b78..0000000
--- a/src/test/java/org/apache/maven/plugin/install/DualDigesterTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.apache.maven.plugin.install;
-
-/*
- * 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 junit.framework.Assert;
-import junit.framework.TestCase;
-
-import java.io.ByteArrayInputStream;
-
-public class DualDigesterTest
- extends TestCase
-{
- public void testGetMd5()
- throws Exception
- {
- DualDigester dualDigester = new DualDigester();
- dualDigester.calculate( new ByteArrayInputStream( "A Dog And A Cat".getBytes() ) );
- Assert.assertEquals( "39bc6b34be719cab3a3dc922445aae7c", dualDigester.getMd5() );
- Assert.assertEquals( "d07b1e7ecc7986b3f1126ddf1b67e3601ec362a9", dualDigester.getSha1() );
- dualDigester.calculate( new ByteArrayInputStream( "Yep, we do it again".getBytes() ) );
- Assert.assertEquals( "8cd83a9cbbd7076f668c2bcc0379ed49", dualDigester.getMd5() );
- Assert.assertEquals( "194ebcb8d168cffdc25c3b854d6187b568cf6273", dualDigester.getSha1() );
- }
-
-}
diff --git a/src/test/java/org/apache/maven/plugin/install/InstallFileMojoTest.java b/src/test/java/org/apache/maven/plugin/install/InstallFileMojoTest.java
index fcae808..a8b2c32 100644
--- a/src/test/java/org/apache/maven/plugin/install/InstallFileMojoTest.java
+++ b/src/test/java/org/apache/maven/plugin/install/InstallFileMojoTest.java
@@ -21,6 +21,7 @@
import java.io.File;
import java.io.Reader;
+import java.util.Map;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Model;
@@ -32,6 +33,7 @@
import org.apache.maven.shared.utils.io.FileUtils;
import org.apache.maven.shared.utils.io.IOUtil;
import org.sonatype.aether.impl.internal.EnhancedLocalRepositoryManager;
+import org.sonatype.aether.util.ChecksumUtils;
import org.sonatype.aether.util.DefaultRepositorySystemSession;
import static org.mockito.Mockito.mock;
@@ -45,8 +47,6 @@
{
private String groupId;
- private String legacyGroupId;
-
private String artifactId;
private String version;
@@ -272,27 +272,20 @@
mojo.execute();
- //get the actual checksum of the artifact
- mojo.digester.calculate( file );
- String actualMd5Sum = mojo.digester.getMd5();
- String actualSha1Sum = mojo.digester.getSha1();
-
String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifactId + "/" + version + "/" +
- artifactId + "-" + version;
-
+ artifactId + "-" + version;
+
File installedArtifact = new File( localPath + "." + "jar" );
-
- File md5 = new File( localPath + ".jar.md5" );
- File sha1 = new File( localPath + ".jar.sha1" );
-
- assertTrue( md5.exists() );
- assertTrue( sha1.exists() );
-
- String generatedMd5 = FileUtils.fileRead( md5, "UTF-8" );
- String generatedSha1 = FileUtils.fileRead( sha1, "UTF-8" );
-
- assertEquals( actualMd5Sum, generatedMd5 );
- assertEquals( actualSha1Sum, generatedSha1 );
+
+ //get the actual checksum of the artifact
+ Map<String, Object> csums = ChecksumUtils.calc( file, Utils.CHECKSUM_ALGORITHMS );
+ for (Map.Entry<String, Object> csum : csums.entrySet()) {
+ Object actualSum = csum.getValue();
+ File sum = new File( localPath + ".jar." + csum.getKey().toLowerCase().replace( "-", "" ) );
+ assertTrue( sum.exists() );
+ String generatedSum = FileUtils.fileRead( sum, "UTF-8" );
+ assertEquals( actualSum, generatedSum );
+ }
assertTrue( installedArtifact.exists() );
@@ -304,8 +297,6 @@
{
this.groupId = dotToSlashReplacer( (String) getVariableValueFromObject( obj, "groupId" ) );
- this.legacyGroupId = (String) getVariableValueFromObject( obj, "groupId" );
-
this.artifactId = (String) getVariableValueFromObject( obj, "artifactId" );
this.version = (String) getVariableValueFromObject( obj, "version" );
diff --git a/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java b/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java
index 9c717d5..5ed59ec 100644
--- a/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java
+++ b/src/test/java/org/apache/maven/plugin/install/InstallMojoTest.java
@@ -25,6 +25,7 @@
import java.io.File;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
@@ -39,6 +40,7 @@
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.shared.utils.io.FileUtils;
import org.sonatype.aether.impl.internal.EnhancedLocalRepositoryManager;
+import org.sonatype.aether.util.ChecksumUtils;
import org.sonatype.aether.util.DefaultRepositorySystemSession;
/**
@@ -293,46 +295,33 @@
assertTrue( pom.exists() );
+ String groupId = dotToSlashReplacer( artifact.getGroupId() );
+ String packaging = project.getPackaging();
+ String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" +
+ artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion();
+
//get the actual checksum of the pom
- mojo.digester.calculate( pom );
- String actualPomMd5Sum = mojo.digester.getMd5();
- String actualPomSha1Sum = mojo.digester.getSha1();
+ Map<String, Object> csums = ChecksumUtils.calc( pom, Utils.CHECKSUM_ALGORITHMS );
+ for (Map.Entry<String, Object> csum : csums.entrySet()) {
+ Object actualPomSum = csum.getValue();
+ File pomSum = new File( localPath + ".pom." + csum.getKey().toLowerCase().replace( "-", "" ) );
+ assertTrue( pomSum.exists() );
+ String generatedPomSum = FileUtils.fileRead( pomSum, "UTF-8" );
+ assertEquals( actualPomSum, generatedPomSum );
+ }
//get the actual checksum of the artifact
- mojo.digester.calculate( file );
- String actualMd5Sum = mojo.digester.getMd5();
- String actualSha1Sum = mojo.digester.getSha1();
-
- String groupId = dotToSlashReplacer( artifact.getGroupId() );
-
- String packaging = project.getPackaging();
-
- String localPath = getBasedir() + "/" + LOCAL_REPO + groupId + "/" + artifact.getArtifactId() + "/" +
- artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion();
+ csums = ChecksumUtils.calc( file, Utils.CHECKSUM_ALGORITHMS );
+ for (Map.Entry<String, Object> csum : csums.entrySet()) {
+ Object actualSum = csum.getValue();
+ File sum = new File( localPath + "." + packaging + "." + csum.getKey().toLowerCase().replace( "-", "" ) );
+ assertTrue( sum.exists() );
+ String generatedSum = FileUtils.fileRead( sum, "UTF-8" );
+ assertEquals( actualSum, generatedSum );
+ }
File installedArtifact = new File( localPath + "." + packaging );
- File pomMd5 = new File( localPath + ".pom.md5" );
- File pomSha1 = new File( localPath + ".pom.sha1" );
-
- File md5 = new File( localPath + "." + packaging + ".md5" );
- File sha1 = new File( localPath + "." + packaging + ".sha1" );
-
- assertTrue( pomMd5.exists() );
- assertTrue( pomSha1.exists() );
- assertTrue( md5.exists() );
- assertTrue( sha1.exists() );
-
- String generatedMd5 = FileUtils.fileRead( md5, "UTF-8" );
- String generatedSha1 = FileUtils.fileRead( sha1, "UTF-8" );
- String generatedPomMd5 = FileUtils.fileRead( pomMd5, "UTF-8" );
- String generatedPomSha1 = FileUtils.fileRead( pomSha1, "UTF-8" );
-
- assertEquals( actualMd5Sum, generatedMd5 );
- assertEquals( actualSha1Sum, generatedSha1 );
- assertEquals( actualPomMd5Sum, generatedPomMd5 );
- assertEquals( actualPomSha1Sum, generatedPomSha1 );
-
assertTrue( installedArtifact.exists() );
assertEquals( 9, FileUtils.getFiles( new File( LOCAL_REPO ), null, null ).size() );
diff --git a/src/test/java/org/apache/maven/plugin/install/SimpleDigester.java b/src/test/java/org/apache/maven/plugin/install/SimpleDigester.java
deleted file mode 100644
index 1f6ac1a..0000000
--- a/src/test/java/org/apache/maven/plugin/install/SimpleDigester.java
+++ /dev/null
@@ -1,143 +0,0 @@
-package org.apache.maven.plugin.install;
-
-/*
- * 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.commons.codec.binary.Hex;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.StringUtils;
-
-import java.io.*;
-import java.security.MessageDigest;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * @author Kristian Rosenvold
- */
-public class SimpleDigester
-{
-
- private final MessageDigest messageDigest;
-
- private static final int bufsize = 65536;
-
- public SimpleDigester( String algorithm )
- {
- messageDigest = DualDigester.getDigester( algorithm );
- }
-
- public static SimpleDigester md5()
- {
- return new SimpleDigester( "MD5" );
- }
-
- public static SimpleDigester sha1()
- {
- return new SimpleDigester( "SHA-1" );
- }
-
- public String calculate( File file )
- throws MojoExecutionException
- {
- InputStream in = null;
- try
- {
- in = new BufferedInputStream( new FileInputStream( file ), (int) Math.min( file.length(), bufsize ) );
- messageDigest.reset();
- update( in );
- final String hexString = Hex.encodeHexString( messageDigest.digest() );
- in.close();
- in = null;
- return hexString;
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException(
- "Failed to calculate " + messageDigest.getAlgorithm() + " checksum for " + file, e );
- }
- finally
- {
- IOUtil.close( in );
- }
- }
-
- private void update( InputStream is )
- throws IOException
- {
- byte[] buffer = new byte[bufsize];
- int size = is.read( buffer, 0, bufsize );
- while ( size >= 0 )
- {
- messageDigest.update( buffer, 0, size );
- size = is.read( buffer, 0, bufsize );
- }
- }
-
- public void verify( File file, String checksum )
- throws MojoExecutionException
- {
- String trimmed = cleanChecksum( checksum, messageDigest.getAlgorithm(), file.getName() );
- String sum = calculate( file );
- if ( !StringUtils.equalsIgnoreCase( trimmed, sum ) )
- {
- throw new RuntimeException( "Checksum failed (expected=" + trimmed + ", actual=" + sum + ")" );
- }
- }
-
- private static String cleanChecksum( String checksum, String algorithm, String path )
- {
- String trimmed = checksum.replace( '\n', ' ' ).trim();
-
- // Free-BSD / openssl
- String regex = algorithm.replaceAll( "-", "" ) + "\\s*\\((.*?)\\)\\s*=\\s*([a-fA-F0-9]+)";
- Matcher m = Pattern.compile( regex ).matcher( trimmed );
- if ( m.matches() )
- {
- String filename = m.group( 1 );
- if ( !isValidChecksumPattern( filename, path ) )
- {
- throw new RuntimeException( "Supplied checksum does not match checksum pattern" );
- }
- trimmed = m.group( 2 );
- }
- else
- {
- // GNU tools
- m = Pattern.compile( "([a-fA-F0-9]+)\\s+\\*?(.+)" ).matcher( trimmed );
- if ( m.matches() )
- {
- String filename = m.group( 2 );
- if ( !isValidChecksumPattern( filename, path ) )
- {
- throw new RuntimeException( "Supplied checksum does not match checksum pattern" );
- }
- trimmed = m.group( 1 );
- }
- }
- return trimmed;
- }
-
- private static boolean isValidChecksumPattern( String filename, String path )
- {
- return filename.endsWith( path ) || filename.equals( "-" );
- }
-
-}
diff --git a/src/test/java/org/apache/maven/plugin/install/Utils.java b/src/test/java/org/apache/maven/plugin/install/Utils.java
index f4c19e3..6b70117 100644
--- a/src/test/java/org/apache/maven/plugin/install/Utils.java
+++ b/src/test/java/org/apache/maven/plugin/install/Utils.java
@@ -21,9 +21,12 @@
import java.io.File;
import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
import org.apache.maven.plugin.MojoExecutionException;
-import org.codehaus.plexus.util.FileUtils;
+import org.sonatype.aether.util.ChecksumUtils;
/**
* A utility class to assist testing.
@@ -31,37 +34,31 @@
* @author Benjamin Bentmann
* @version $Id$
*/
-@SuppressWarnings( "UnusedDeclaration" )
public class Utils
{
+ public static final List<String> CHECKSUM_ALGORITHMS = Arrays.asList( "MD5", "SHA-1" );
+
/**
- * Verifies a checksum file in the local repo.
+ * Verifies the checksum files in the local repo for the given file.
*
- * @param checksumFile The checksum file to verify, must not be <code>null</code>.
+ * @param file The file to verify its checksum with, must not be <code>null</code>.
+ * @throws MojoExecutionException In case the checksums were incorrect.
+ * @throws IOException If the files couldn't be read.
*/
- public static void verifyChecksum( File checksumFile )
+ public static void verifyChecksum( File file )
throws MojoExecutionException, IOException
{
- File dataFile;
- SimpleDigester digester;
- if ( checksumFile.getName().endsWith( ".md5" ) )
+ Map<String, Object> checksums = ChecksumUtils.calc( file, CHECKSUM_ALGORITHMS );
+ for ( Map.Entry<String, Object> entry : checksums.entrySet() )
{
- digester = SimpleDigester.md5();
- dataFile = new File( checksumFile.getPath().substring( 0, checksumFile.getPath().length() - 4 ) );
+ File cksumFile = new File( file + "." + entry.getKey().toLowerCase().replace( "-", "" ) );
+ String actualChecksum = ChecksumUtils.read( cksumFile );
+ if ( !actualChecksum.equals( entry.getValue() ) )
+ {
+ throw new MojoExecutionException( "Incorrect " + entry.getKey() + " checksum for file: " + file );
+ }
}
- else if ( checksumFile.getName().endsWith( ".sha1" ) )
- {
- digester = SimpleDigester.sha1();
- dataFile = new File( checksumFile.getPath().substring( 0, checksumFile.getPath().length() - 5 ) );
- }
- else
- {
- throw new IllegalArgumentException( "Unsupported checksum file: " + checksumFile );
- }
-
- String expected = FileUtils.fileRead( checksumFile, "UTF-8" );
- digester.verify( dataFile, expected );
}
}
diff --git a/src/test/java/org/apache/maven/plugin/install/testingharness/MojoTestRepositorySystem.java b/src/test/java/org/apache/maven/plugin/install/testingharness/MojoTestRepositorySystem.java
deleted file mode 100644
index 573ca02..0000000
--- a/src/test/java/org/apache/maven/plugin/install/testingharness/MojoTestRepositorySystem.java
+++ /dev/null
@@ -1,185 +0,0 @@
-package org.apache.maven.plugin.install.testingharness;
-
-/*
- * 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 java.util.List;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.DefaultArtifact;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
-import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
-import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
-import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
-import org.apache.maven.model.Dependency;
-import org.apache.maven.model.Plugin;
-import org.apache.maven.model.Repository;
-import org.apache.maven.repository.ArtifactTransferListener;
-import org.apache.maven.repository.RepositorySystem;
-import org.apache.maven.settings.Mirror;
-import org.apache.maven.settings.Proxy;
-import org.apache.maven.settings.Server;
-import org.sonatype.aether.RepositorySystemSession;
-
-public class MojoTestRepositorySystem implements RepositorySystem
-{
-
- @Override
- public Artifact createProjectArtifact( String groupId, String artifactId, String version )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Artifact createArtifact( String groupId, String artifactId, String version, String packaging )
- {
- // called in org.apache.maven.plugin.testing.AbstractMojoTestCase.setUp()
- return new DefaultArtifact( groupId, artifactId, version, "compile", packaging, "", null );
- }
-
- @Override
- public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type )
- {
- throw new UnsupportedOperationException();
- }
-
-
- @Override
- public Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String type,
- String classifier )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Artifact createPluginArtifact( Plugin plugin )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Artifact createDependencyArtifact( Dependency dependency )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ArtifactRepository buildArtifactRepository( Repository repository )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ArtifactRepository createDefaultRemoteRepository()
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ArtifactRepository createDefaultLocalRepository()
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ArtifactRepository createLocalRepository( File localRepository )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ArtifactRepository createArtifactRepository( String id, String url,
- ArtifactRepositoryLayout repositoryLayout,
- ArtifactRepositoryPolicy snapshots,
- ArtifactRepositoryPolicy releases )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public List<ArtifactRepository> getEffectiveRepositories( List<ArtifactRepository> repositories )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public Mirror getMirror( ArtifactRepository repository, List<Mirror> mirrors )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void injectMirror( List<ArtifactRepository> repositories, List<Mirror> mirrors )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void injectProxy( List<ArtifactRepository> repositories, List<Proxy> proxies )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void injectAuthentication( List<ArtifactRepository> repositories, List<Server> servers )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void injectMirror( RepositorySystemSession session, List<ArtifactRepository> repositories )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void injectProxy( RepositorySystemSession session, List<ArtifactRepository> repositories )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void injectAuthentication( RepositorySystemSession session, List<ArtifactRepository> repositories )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void publish( ArtifactRepository repository, File source, String remotePath,
- ArtifactTransferListener transferListener )
- {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void retrieve( ArtifactRepository repository, File destination, String remotePath,
- ArtifactTransferListener transferListener )
- {
- throw new UnsupportedOperationException();
- }
-
-}
diff --git a/src/test/resources/META-INF/plexus/components.xml b/src/test/resources/META-INF/plexus/components.xml
deleted file mode 100644
index 9bf74fe..0000000
--- a/src/test/resources/META-INF/plexus/components.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?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.
--->
-
-<component-set>
- <components>
- <component>
- <role>org.apache.maven.repository.RepositorySystem</role>
- <role-hint>default</role-hint>
- <implementation>org.apache.maven.plugin.install.testingharness.MojoTestRepositorySystem</implementation>
- <isolated-realm>false</isolated-realm>
- </component>
- </components>
-</component-set>