You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2024/06/08 20:30:08 UTC
(maven-dependency-plugin) branch MDEP-838 created (now f090b5ef)
This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a change to branch MDEP-838
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
at f090b5ef [MDEP-838] "Artifact has not been packaged yet" error message is not very helpful
This branch includes the following new commits:
new f090b5ef [MDEP-838] "Artifact has not been packaged yet" error message is not very helpful
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(maven-dependency-plugin) 01/01: [MDEP-838] "Artifact has not been packaged yet" error message is not very helpful
Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch MDEP-838
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
commit f090b5efdeff0b2f2ebcc88a40f4b02dc4a6f408
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sat Jun 8 21:59:10 2024 +0200
[MDEP-838] "Artifact has not been packaged yet" error message is not very helpful
This closes #412
---
.../plugins/dependency/fromConfiguration/CopyMojo.java | 9 ++++++---
.../fromDependencies/CopyDependenciesMojo.java | 13 ++++++++-----
.../apache/maven/plugins/dependency/utils/CopyUtil.java | 16 ++++++++++------
.../dependency/AbstractDependencyMojoTestCase.java | 7 ++++---
.../fromDependencies/TestCopyDependenciesMojo.java | 10 ++++++++--
5 files changed, 36 insertions(+), 19 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/CopyMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/CopyMojo.java
index d7a3ba61..a9de46fe 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/CopyMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/CopyMojo.java
@@ -22,6 +22,7 @@ import java.io.File;
import java.io.IOException;
import java.util.List;
+import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
@@ -108,16 +109,18 @@ public class CopyMojo extends AbstractFromConfigurationMojo {
*
* @param artifactItem containing the information about the Artifact to copy.
* @throws MojoExecutionException with a message if an error occurs.
- * @see CopyUtil#copyFile(File, File)
+ * @see CopyUtil#copyArtifactFile(Artifact, File)
*/
protected void copyArtifact(ArtifactItem artifactItem) throws MojoExecutionException {
File destFile = new File(artifactItem.getOutputDirectory(), artifactItem.getDestFileName());
try {
- copyUtil.copyFile(artifactItem.getArtifact().getFile(), destFile);
+ copyUtil.copyArtifactFile(artifactItem.getArtifact(), destFile);
} catch (IOException e) {
throw new MojoExecutionException(
- "Failed copy " + artifactItem.getArtifact().getFile() + " to " + destFile, e);
+ "Failed to copy artifact '" + artifactItem.getArtifact() + "' ("
+ + artifactItem.getArtifact().getFile() + ") to " + destFile,
+ e);
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java
index 97956ec7..48759af2 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java
@@ -201,7 +201,7 @@ public class CopyDependenciesMojo extends AbstractFromDependenciesMojo {
* @param theUseBaseVersion specifies if the baseVersion of the artifact should be used instead of the version.
* @param removeClassifier specifies if the classifier should be removed from the file name when copying.
* @throws MojoExecutionException with a message if an error occurs.
- * @see CopyUtil#copyFile(File, File)
+ * @see CopyUtil#copyArtifactFile(Artifact, File)
* @see DependencyUtil#getFormattedOutputDirectory(boolean, boolean, boolean, boolean, boolean, boolean, File, Artifact)
*/
protected void copyArtifact(
@@ -227,9 +227,10 @@ public class CopyDependenciesMojo extends AbstractFromDependenciesMojo {
File destFile = new File(destDir, destFileName);
try {
- copyUtil.copyFile(artifact.getFile(), destFile);
+ copyUtil.copyArtifactFile(artifact, destFile);
} catch (IOException e) {
- throw new MojoExecutionException("Failed copy " + artifact.getFile() + " to " + destFile, e);
+ throw new MojoExecutionException(
+ "Failed to copy artifact '" + artifact + "' (" + artifact.getFile() + ") to " + destFile, e);
}
}
@@ -271,10 +272,12 @@ public class CopyDependenciesMojo extends AbstractFromDependenciesMojo {
pomArtifact, removeVersion, prependGroupId, useBaseVersion, removeClassifier));
if (!pomDestFile.exists()) {
try {
- copyUtil.copyFile(pomArtifact.getFile(), pomDestFile);
+ copyUtil.copyArtifactFile(pomArtifact, pomDestFile);
} catch (IOException e) {
throw new MojoExecutionException(
- "Failed copy " + pomArtifact.getFile() + " to " + pomDestFile, e);
+ "Failed to copy artifact '" + pomArtifact + "' (" + pomArtifact.getFile() + ") to "
+ + pomDestFile,
+ e);
}
}
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/utils/CopyUtil.java b/src/main/java/org/apache/maven/plugins/dependency/utils/CopyUtil.java
index 8078081e..21d067ae 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/utils/CopyUtil.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/utils/CopyUtil.java
@@ -25,6 +25,7 @@ import javax.inject.Singleton;
import java.io.File;
import java.io.IOException;
+import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.util.FileUtils;
import org.slf4j.Logger;
@@ -50,20 +51,23 @@ public class CopyUtil {
}
/**
- * Does the actual copy of the file and logging.
+ * Does the actual copy of the artifact (file) and logging.
*
- * @param source represents the file to copy.
+ * @param sourceArtifact represents the artifact (file) to copy.
* @param destination file name of destination file.
- * @throws IOException with a message if an error occurs.
+ * @throws IOException if copy has failed
+ * @throws MojoExecutionException if artifact file is a directory (which has not been packaged yet)
*
* @since 3.7.0
*/
- public void copyFile(File source, File destination) throws IOException, MojoExecutionException {
- logger.info("Copying {} to {}", source, destination);
+ public void copyArtifactFile(Artifact sourceArtifact, File destination) throws IOException, MojoExecutionException {
+ logger.info("Copying artifact '{}' ({}) to {}", sourceArtifact, sourceArtifact.getFile(), destination);
+ File source = sourceArtifact.getFile();
if (source.isDirectory()) {
// usual case is a future jar packaging, but there are special cases: classifier and other packaging
- throw new MojoExecutionException("Artifact has not been packaged yet. When used on reactor artifact, "
+ throw new MojoExecutionException("Artifact '" + sourceArtifact
+ + "' has not been packaged yet (is a directory). When used on reactor artifact, "
+ "copy should be executed after packaging: see MDEP-187.");
}
diff --git a/src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTestCase.java b/src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTestCase.java
index 5fb0180e..cde5ea88 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTestCase.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTestCase.java
@@ -22,6 +22,7 @@ import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
+import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
@@ -63,14 +64,14 @@ public abstract class AbstractDependencyMojoTestCase extends AbstractMojoTestCas
FileUtils.deleteDirectory(testDir);
} catch (IOException e) {
e.printStackTrace();
- fail("Trying to remove directory:" + testDir + System.lineSeparator() + e);
+ fail("Trying to remove directory: " + testDir + System.lineSeparator() + e);
}
assertFalse(testDir.exists());
}
}
- protected void copyFile(File artifact, File destFile) throws MojoExecutionException, IOException {
- new CopyUtil(new DefaultBuildContext()).copyFile(artifact, destFile);
+ protected void copyArtifactFile(Artifact sourceArtifact, File destFile) throws MojoExecutionException, IOException {
+ new CopyUtil(new DefaultBuildContext()).copyArtifactFile(sourceArtifact, destFile);
}
protected void installLocalRepository(LegacySupport legacySupport) throws ComponentLookupException {
diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java
index c2f7c694..e2a14f16 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java
@@ -30,6 +30,7 @@ import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.LegacySupport;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.testing.stubs.ArtifactStub;
import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
import org.apache.maven.plugins.dependency.utils.DependencyUtil;
@@ -80,14 +81,19 @@ public class TestCopyDependenciesMojo extends AbstractDependencyMojoTestCase {
assertFalse(handle.isMarkerSet());
}
- public void testCopyFile() throws Exception {
+ public void testCopyArtifactFile() throws Exception {
+ final Artifact srcArtifact = new ArtifactStub();
+ srcArtifact.setGroupId("org.apache.maven.plugins");
+ srcArtifact.setArtifactId("maven-dependency-plugin-dummy");
+ srcArtifact.setVersion("1.0");
File src = File.createTempFile("copy", null);
+ srcArtifact.setFile(src);
File dest = new File(mojo.outputDirectory, "toMe.jar");
assertFalse(dest.exists());
- copyFile(src, dest);
+ copyArtifactFile(srcArtifact, dest);
assertTrue(dest.exists());
}