Skip to content

Commit f090b5e

Browse files
committed
[MDEP-838] "Artifact has not been packaged yet" error message is not very helpful
This closes #412
1 parent 9902456 commit f090b5e

File tree

5 files changed

+36
-19
lines changed

5 files changed

+36
-19
lines changed

src/main/java/org/apache/maven/plugins/dependency/fromConfiguration/CopyMojo.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.IOException;
2323
import java.util.List;
2424

25+
import org.apache.maven.artifact.Artifact;
2526
import org.apache.maven.plugin.MojoExecutionException;
2627
import org.apache.maven.plugin.MojoFailureException;
2728
import org.apache.maven.plugins.annotations.Component;
@@ -108,16 +109,18 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException {
108109
*
109110
* @param artifactItem containing the information about the Artifact to copy.
110111
* @throws MojoExecutionException with a message if an error occurs.
111-
* @see CopyUtil#copyFile(File, File)
112+
* @see CopyUtil#copyArtifactFile(Artifact, File)
112113
*/
113114
protected void copyArtifact(ArtifactItem artifactItem) throws MojoExecutionException {
114115
File destFile = new File(artifactItem.getOutputDirectory(), artifactItem.getDestFileName());
115116

116117
try {
117-
copyUtil.copyFile(artifactItem.getArtifact().getFile(), destFile);
118+
copyUtil.copyArtifactFile(artifactItem.getArtifact(), destFile);
118119
} catch (IOException e) {
119120
throw new MojoExecutionException(
120-
"Failed copy " + artifactItem.getArtifact().getFile() + " to " + destFile, e);
121+
"Failed to copy artifact '" + artifactItem.getArtifact() + "' ("
122+
+ artifactItem.getArtifact().getFile() + ") to " + destFile,
123+
e);
121124
}
122125
}
123126

src/main/java/org/apache/maven/plugins/dependency/fromDependencies/CopyDependenciesMojo.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ protected void copyArtifact(
201201
* @param theUseBaseVersion specifies if the baseVersion of the artifact should be used instead of the version.
202202
* @param removeClassifier specifies if the classifier should be removed from the file name when copying.
203203
* @throws MojoExecutionException with a message if an error occurs.
204-
* @see CopyUtil#copyFile(File, File)
204+
* @see CopyUtil#copyArtifactFile(Artifact, File)
205205
* @see DependencyUtil#getFormattedOutputDirectory(boolean, boolean, boolean, boolean, boolean, boolean, File, Artifact)
206206
*/
207207
protected void copyArtifact(
@@ -227,9 +227,10 @@ protected void copyArtifact(
227227
File destFile = new File(destDir, destFileName);
228228

229229
try {
230-
copyUtil.copyFile(artifact.getFile(), destFile);
230+
copyUtil.copyArtifactFile(artifact, destFile);
231231
} catch (IOException e) {
232-
throw new MojoExecutionException("Failed copy " + artifact.getFile() + " to " + destFile, e);
232+
throw new MojoExecutionException(
233+
"Failed to copy artifact '" + artifact + "' (" + artifact.getFile() + ") to " + destFile, e);
233234
}
234235
}
235236

@@ -271,10 +272,12 @@ public void copyPoms(File destDir, Set<Artifact> artifacts, boolean removeVersio
271272
pomArtifact, removeVersion, prependGroupId, useBaseVersion, removeClassifier));
272273
if (!pomDestFile.exists()) {
273274
try {
274-
copyUtil.copyFile(pomArtifact.getFile(), pomDestFile);
275+
copyUtil.copyArtifactFile(pomArtifact, pomDestFile);
275276
} catch (IOException e) {
276277
throw new MojoExecutionException(
277-
"Failed copy " + pomArtifact.getFile() + " to " + pomDestFile, e);
278+
"Failed to copy artifact '" + pomArtifact + "' (" + pomArtifact.getFile() + ") to "
279+
+ pomDestFile,
280+
e);
278281
}
279282
}
280283
}

src/main/java/org/apache/maven/plugins/dependency/utils/CopyUtil.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.io.File;
2626
import java.io.IOException;
2727

28+
import org.apache.maven.artifact.Artifact;
2829
import org.apache.maven.plugin.MojoExecutionException;
2930
import org.codehaus.plexus.util.FileUtils;
3031
import org.slf4j.Logger;
@@ -50,20 +51,23 @@ public CopyUtil(BuildContext buildContext) {
5051
}
5152

5253
/**
53-
* Does the actual copy of the file and logging.
54+
* Does the actual copy of the artifact (file) and logging.
5455
*
55-
* @param source represents the file to copy.
56+
* @param sourceArtifact represents the artifact (file) to copy.
5657
* @param destination file name of destination file.
57-
* @throws IOException with a message if an error occurs.
58+
* @throws IOException if copy has failed
59+
* @throws MojoExecutionException if artifact file is a directory (which has not been packaged yet)
5860
*
5961
* @since 3.7.0
6062
*/
61-
public void copyFile(File source, File destination) throws IOException, MojoExecutionException {
62-
logger.info("Copying {} to {}", source, destination);
63+
public void copyArtifactFile(Artifact sourceArtifact, File destination) throws IOException, MojoExecutionException {
64+
logger.info("Copying artifact '{}' ({}) to {}", sourceArtifact, sourceArtifact.getFile(), destination);
6365

66+
File source = sourceArtifact.getFile();
6467
if (source.isDirectory()) {
6568
// usual case is a future jar packaging, but there are special cases: classifier and other packaging
66-
throw new MojoExecutionException("Artifact has not been packaged yet. When used on reactor artifact, "
69+
throw new MojoExecutionException("Artifact '" + sourceArtifact
70+
+ "' has not been packaged yet (is a directory). When used on reactor artifact, "
6771
+ "copy should be executed after packaging: see MDEP-187.");
6872
}
6973

src/test/java/org/apache/maven/plugins/dependency/AbstractDependencyMojoTestCase.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.IOException;
2323

2424
import org.apache.commons.io.FileUtils;
25+
import org.apache.maven.artifact.Artifact;
2526
import org.apache.maven.plugin.LegacySupport;
2627
import org.apache.maven.plugin.MojoExecutionException;
2728
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
@@ -63,14 +64,14 @@ protected void tearDown() {
6364
FileUtils.deleteDirectory(testDir);
6465
} catch (IOException e) {
6566
e.printStackTrace();
66-
fail("Trying to remove directory:" + testDir + System.lineSeparator() + e);
67+
fail("Trying to remove directory: " + testDir + System.lineSeparator() + e);
6768
}
6869
assertFalse(testDir.exists());
6970
}
7071
}
7172

72-
protected void copyFile(File artifact, File destFile) throws MojoExecutionException, IOException {
73-
new CopyUtil(new DefaultBuildContext()).copyFile(artifact, destFile);
73+
protected void copyArtifactFile(Artifact sourceArtifact, File destFile) throws MojoExecutionException, IOException {
74+
new CopyUtil(new DefaultBuildContext()).copyArtifactFile(sourceArtifact, destFile);
7475
}
7576

7677
protected void installLocalRepository(LegacySupport legacySupport) throws ComponentLookupException {

src/test/java/org/apache/maven/plugins/dependency/fromDependencies/TestCopyDependenciesMojo.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.maven.plugin.LegacySupport;
3131
import org.apache.maven.plugin.MojoExecutionException;
3232
import org.apache.maven.plugin.MojoFailureException;
33+
import org.apache.maven.plugin.testing.stubs.ArtifactStub;
3334
import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
3435
import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
3536
import org.apache.maven.plugins.dependency.utils.DependencyUtil;
@@ -80,14 +81,19 @@ public void assertNoMarkerFile(Artifact artifact) throws MojoExecutionException
8081
assertFalse(handle.isMarkerSet());
8182
}
8283

83-
public void testCopyFile() throws Exception {
84+
public void testCopyArtifactFile() throws Exception {
85+
final Artifact srcArtifact = new ArtifactStub();
86+
srcArtifact.setGroupId("org.apache.maven.plugins");
87+
srcArtifact.setArtifactId("maven-dependency-plugin-dummy");
88+
srcArtifact.setVersion("1.0");
8489
File src = File.createTempFile("copy", null);
90+
srcArtifact.setFile(src);
8591

8692
File dest = new File(mojo.outputDirectory, "toMe.jar");
8793

8894
assertFalse(dest.exists());
8995

90-
copyFile(src, dest);
96+
copyArtifactFile(srcArtifact, dest);
9197
assertTrue(dest.exists());
9298
}
9399

0 commit comments

Comments
 (0)