Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/it/projects/mdep-654-copy-checksums/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ under the License.
<artifactId>mdep-654</artifactId>
<version>1.0</version>
<description>
MDEP-654: copy-dependencies with useRepositoryLayout and copyChecksums also copies the checksum files
MDEP-654: copy-dependencies with useRepositoryLayout also copies the checksum files
that sit next to each artifact and POM in the local repository.
</description>
<dependencies>
Expand All @@ -40,7 +40,6 @@ under the License.
<artifactId>maven-dependency-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<useRepositoryLayout>true</useRepositoryLayout>
<copyPom>true</copyPom>
</configuration>
<executions>
Expand All @@ -51,6 +50,7 @@ under the License.
</goals>
<configuration>
<outputDirectory>${project.build.directory}/without-checksums</outputDirectory>
<useRepositoryLayout>false</useRepositoryLayout>
</configuration>
</execution>
<execution>
Expand All @@ -60,7 +60,7 @@ under the License.
</goals>
<configuration>
<outputDirectory>${project.build.directory}/with-checksums</outputDirectory>
<copyChecksums>true</copyChecksums>
<useRepositoryLayout>true</useRepositoryLayout>
</configuration>
</execution>
</executions>
Expand Down
4 changes: 2 additions & 2 deletions src/it/projects/mdep-654-copy-checksums/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* under the License.
*/

// MDEP-654: checksum files from the local repository are copied only when copyChecksums is set.
// MDEP-654: with useRepositoryLayout, the checksum files from the local repository are copied too.
def relative = 'org/apache/maven/its/dependency/mdep654-dep/1.0'
def localRepo = new File(localRepositoryPath, relative)
assert new File(localRepo, 'mdep654-dep-1.0.jar.sha1').isFile() : "No jar checksum in the local repository ${localRepo}"

def withDir = new File(basedir, "target/with-checksums/${relative}")
def withoutDir = new File(basedir, "target/without-checksums/${relative}")
def withoutDir = new File(basedir, "target/without-checksums")
['mdep654-dep-1.0.jar', 'mdep654-dep-1.0.pom'].each { name ->
assert new File(withDir, name).isFile()
assert new File(withoutDir, name).isFile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,6 @@ public class CopyDependenciesMojo extends AbstractFromDependenciesMojo {
@Parameter(property = "mdep.copySignatures", defaultValue = "false")
protected boolean copySignatures;

/**
* Also copy the checksum files ({@code .sha1}, {@code .md5}, {@code .sha256} and {@code .sha512}) that sit next
* to each artifact and its POM in the local repository. Only used together with {@link #useRepositoryLayout};
* checksum files that do not exist in the local repository are skipped.
*
* @since 3.12.0
*/
@Parameter(property = "mdep.copyChecksums", defaultValue = "false")
protected boolean copyChecksums;

@Inject
public CopyDependenciesMojo(
MavenSession session,
Expand Down Expand Up @@ -152,10 +142,6 @@ protected boolean isResolvingAfterFiltering() {
*/
@Override
protected void doExecute() throws MojoExecutionException {
if (copyChecksums && !useRepositoryLayout) {
getLog().warn(
"copyChecksums only applies together with useRepositoryLayout, no checksum files are copied.");
}
DependencyStatusSets dss =
getDependencySets(this.failOnMissingClassifierArtifact, addParentPoms, addImportedBoms);
Set<Artifact> artifacts = dss.getResolvedDependencies();
Expand Down Expand Up @@ -252,6 +238,7 @@ private void installMissingPom(Artifact artifact, RepositorySystemSession reposi
try {
getResolverUtil().installArtifact(pomArtifact, repositorySystemSession);
installBaseSnapshot(pomArtifact, repositorySystemSession);
copyChecksumFiles(pomArtifact, repositorySystemSession);
} catch (InstallationException e) {
getLog().warn("unable to install " + pomArtifact, e);
}
Expand All @@ -263,7 +250,7 @@ private void installMissingPom(Artifact artifact, RepositorySystemSession reposi
* the installed artifact is.
*/
private void copyChecksumFiles(Artifact artifact, RepositorySystemSession repositorySystemSession) {
if (!copyChecksums || artifact.getFile() == null) {
if (artifact.getFile() == null) {
return;
}
LocalRepositoryManager localRepositoryManager = repositorySystemSession.getLocalRepositoryManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,36 @@ void testCopyPomForSkippedArtifactWithRepositoryLayoutOnlyWhenMissing(CopyDepend
assertEquals("existing pom", readFile(pomDestination));
}

@Test
@InjectMojo(goal = "copy-dependencies")
void testCopyPomChecksumsForSkippedArtifactWithRepositoryLayout(CopyDependenciesMojo mojo) throws Exception {
Artifact artifact = stubFactory.createArtifact("org.example", "artifact", "2.0", Artifact.SCOPE_COMPILE);
Artifact pomArtifact =
stubFactory.createArtifact("org.example", "artifact", "2.0", Artifact.SCOPE_COMPILE, "pom", null);
writeFile(artifact.getFile(), "new jar");
writeFile(pomArtifact.getFile(), "new pom");
writeFile(new File(pomArtifact.getFile().getPath() + ".sha1"), "pom sha1");

Set<Artifact> artifacts = new HashSet<>();
artifacts.add(artifact);
mojo.getProject().setArtifacts(artifacts);

CopyDependenciesMojo mojoSpy = spy(mojo);
doReturn(pomArtifact).when(mojoSpy).getResolvedPomArtifact(any(Artifact.class));
mojoSpy.setCopyPom(true);
mojoSpy.useRepositoryLayout = true;
mojoSpy.overWriteReleases = false;
mojoSpy.overWriteIfNewer = false;

File artifactDirectory = new File(mojoSpy.outputDirectory, "org/example/artifact/2.0");
writeFile(new File(artifactDirectory, "artifact-2.0.jar"), "old jar");

mojoSpy.execute();

assertEquals("new pom", readFile(new File(artifactDirectory, "artifact-2.0.pom")));
assertEquals("pom sha1", readFile(new File(artifactDirectory, "artifact-2.0.pom.sha1")));
}

private static void writeFile(File file, String contents) throws IOException {
Files.createDirectories(file.getParentFile().toPath());
Files.write(file.toPath(), contents.getBytes(StandardCharsets.UTF_8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ void testAddImportedBomsIsOffByDefault(CopyDependenciesMojo mojo) {

@Test
@InjectMojo(goal = "copy-dependencies")
@MojoParameter(name = "copyChecksums", value = "true")
void testRepositoryLayoutCopiesChecksums(CopyDependenciesMojo mojo) throws Exception {
Artifact artifact = stubFactory.createArtifact(
"testGroupId",
Expand Down Expand Up @@ -394,7 +393,7 @@ void testInterpolateImportedBomCoordinatesFromParentAndEnvironment(CopyDependenc

@Test
@InjectMojo(goal = "copy-dependencies")
void testRepositoryLayoutSkipsChecksumsByDefault(CopyDependenciesMojo mojo) throws Exception {
void testFlatLayoutDoesNotCopyChecksums(CopyDependenciesMojo mojo) throws Exception {
Artifact artifact = stubFactory.createArtifact(
"testGroupId",
"artifact-without-checksums",
Expand All @@ -408,12 +407,12 @@ void testRepositoryLayoutSkipsChecksumsByDefault(CopyDependenciesMojo mojo) thro
"sha1-value".getBytes(StandardCharsets.UTF_8));
mojo.getProject().setArtifacts(Collections.singleton(artifact));

mojo.useRepositoryLayout = true;
mojo.useRepositoryLayout = false;
mojo.execute();

Path artifactDirectory = mojo.outputDirectory.toPath().resolve("testGroupId/artifact-without-checksums/1.0");
assertTrue(Files.isRegularFile(artifactDirectory.resolve("artifact-without-checksums-1.0.jar")));
assertFalse(Files.exists(artifactDirectory.resolve("artifact-without-checksums-1.0.jar.sha1")));
Path outputDirectory = mojo.outputDirectory.toPath();
assertTrue(Files.isRegularFile(outputDirectory.resolve("artifact-without-checksums-1.0.jar")));
assertFalse(Files.exists(outputDirectory.resolve("artifact-without-checksums-1.0.jar.sha1")));
}

private Artifact createExpandedVersionArtifact(
Expand Down
Loading