Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file size to dependency filenames to avoid filename collisions #1338

Merged
merged 5 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ private static JavaLayerConfigurations getForNonWarProject(
layerBuilder.addFile(
layerType,
dependencyFile.toPath(),
dependenciesExtractionPath.resolve(dependencyFile.getName()));
dependenciesExtractionPath.resolve(
dependencyFile
.getName()
.replace(".jar", "-" + Files.size(dependencyFile.toPath()) + ".jar")));
TadCordle marked this conversation as resolved.
Show resolved Hide resolved
TadCordle marked this conversation as resolved.
Show resolved Hide resolved
} else {
logger.info("\t'" + dependencyFile + "' (not found, skipped)");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ public void setUp() throws URISyntaxException, IOException {
allFiles.add(Paths.get(Resources.getResource("application/dependencies/libraryA.jar").toURI()));
allFiles.add(
Paths.get(Resources.getResource("application/dependencies/dependency-1.0.0.jar").toURI()));
allFiles.add(
Paths.get(
Resources.getResource("application/dependencies/more/dependency-1.0.0.jar").toURI()));
allFiles.add(
Paths.get(
Resources.getResource("application/dependencies/another/one/dependency-1.0.0.jar")
.toURI()));
allFiles.add(
Paths.get(
Resources.getResource("application/dependencies/dependencyX-1.0.0-SNAPSHOT.jar")
Expand Down Expand Up @@ -158,6 +165,8 @@ public void test_correctFiles() throws URISyntaxException, IOException {
ImmutableList<Path> expectedDependenciesFiles =
ImmutableList.of(
applicationDirectory.resolve("dependencies/dependency-1.0.0.jar"),
applicationDirectory.resolve("dependencies/more/dependency-1.0.0.jar"),
applicationDirectory.resolve("dependencies/another/one/dependency-1.0.0.jar"),
applicationDirectory.resolve("dependencies/libraryA.jar"),
applicationDirectory.resolve("dependencies/libraryB.jar"));
ImmutableList<Path> expectedSnapshotDependenciesFiles =
Expand Down Expand Up @@ -262,12 +271,14 @@ public void testGetForProject_nonDefaultAppRoot() throws IOException {

assertExtractionPathsUnordered(
Arrays.asList(
"/my/app/libs/dependency-1.0.0.jar",
"/my/app/libs/libraryA.jar",
"/my/app/libs/libraryB.jar"),
"/my/app/libs/dependency-1.0.0-770.jar",
"/my/app/libs/dependency-1.0.0-200.jar",
"/my/app/libs/dependency-1.0.0-480.jar",
"/my/app/libs/libraryA-0.jar",
"/my/app/libs/libraryB-0.jar"),
configuration.getDependencyLayerEntries());
assertExtractionPathsUnordered(
Arrays.asList("/my/app/libs/dependencyX-1.0.0-SNAPSHOT.jar"),
Collections.singletonList("/my/app/libs/dependencyX-1.0.0-SNAPSHOT-770.jar"),
configuration.getSnapshotDependencyLayerEntries());
assertExtractionPathsUnordered(
Arrays.asList(
Expand Down Expand Up @@ -295,10 +306,14 @@ public void testGetForProject_defaultAppRoot() throws IOException {

assertExtractionPathsUnordered(
Arrays.asList(
"/app/libs/dependency-1.0.0.jar", "/app/libs/libraryA.jar", "/app/libs/libraryB.jar"),
"/app/libs/dependency-1.0.0-770.jar",
"/app/libs/dependency-1.0.0-200.jar",
"/app/libs/dependency-1.0.0-480.jar",
"/app/libs/libraryA-0.jar",
"/app/libs/libraryB-0.jar"),
configuration.getDependencyLayerEntries());
assertExtractionPathsUnordered(
Arrays.asList("/app/libs/dependencyX-1.0.0-SNAPSHOT.jar"),
Collections.singletonList("/app/libs/dependencyX-1.0.0-SNAPSHOT-770.jar"),
configuration.getSnapshotDependencyLayerEntries());
assertExtractionPathsUnordered(
Arrays.asList(
Expand Down Expand Up @@ -366,10 +381,10 @@ public void testWebApp() throws URISyntaxException, IOException {
assertSourcePathsUnordered(expectedExtraFiles, configuration.getExtraFilesLayerEntries());

assertExtractionPathsUnordered(
Arrays.asList("/my/app/WEB-INF/lib/dependency-1.0.0.jar"),
Collections.singletonList("/my/app/WEB-INF/lib/dependency-1.0.0.jar"),
configuration.getDependencyLayerEntries());
assertExtractionPathsUnordered(
Arrays.asList("/my/app/WEB-INF/lib/dependencyX-1.0.0-SNAPSHOT.jar"),
Collections.singletonList("/my/app/WEB-INF/lib/dependencyX-1.0.0-SNAPSHOT.jar"),
configuration.getSnapshotDependencyLayerEntries());
assertExtractionPathsUnordered(
Arrays.asList(
Expand Down Expand Up @@ -409,10 +424,10 @@ public void testWebApp_defaultWebAppRoot() throws URISyntaxException, IOExceptio
AbsoluteUnixPath.get(JavaLayerConfigurations.DEFAULT_WEB_APP_ROOT));

assertExtractionPathsUnordered(
Arrays.asList("/jetty/webapps/ROOT/WEB-INF/lib/dependency-1.0.0.jar"),
Collections.singletonList("/jetty/webapps/ROOT/WEB-INF/lib/dependency-1.0.0.jar"),
configuration.getDependencyLayerEntries());
assertExtractionPathsUnordered(
Arrays.asList("/jetty/webapps/ROOT/WEB-INF/lib/dependencyX-1.0.0-SNAPSHOT.jar"),
Collections.singletonList("/jetty/webapps/ROOT/WEB-INF/lib/dependencyX-1.0.0-SNAPSHOT.jar"),
configuration.getSnapshotDependencyLayerEntries());
assertExtractionPathsUnordered(
Arrays.asList(
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
]e$Ềx���,�
.3��I݅����3�8��V�KA����M��)=5�~�'qю�$[��- :��&�%�� ����E�o����7N���s`�i�Z0MT.����9J[�}?\E ��}U�v���J�d��o(��i��"M��ԛ��_+/�c���I<��Zje��44%���d2?�l>.��-�O�=H�i�
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ private static JavaLayerConfigurations getForNonWarProject(
LayerType layerType =
artifact.isSnapshot() ? LayerType.SNAPSHOT_DEPENDENCIES : LayerType.DEPENDENCIES;
layerBuilder.addFile(
layerType, artifactPath, dependenciesExtractionPath.resolve(artifactPath.getFileName()));
layerType,
artifactPath,
dependenciesExtractionPath.resolve(
artifactPath
.getFileName()
.toString()
.replace(".jar", "-" + Files.size(artifactPath) + ".jar")));
}

Path classesOutputDirectory = Paths.get(project.getBuild().getOutputDirectory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ private static void assertExtractionPathsUnordered(
private static void assertNonDefaultAppRoot(JavaLayerConfigurations configuration) {
assertExtractionPathsUnordered(
Arrays.asList(
"/my/app/libs/dependency-1.0.0.jar",
"/my/app/libs/libraryA.jar",
"/my/app/libs/libraryB.jar"),
"/my/app/libs/dependency-1.0.0-770.jar",
"/my/app/libs/dependency-1.0.0-200.jar",
"/my/app/libs/dependency-1.0.0-480.jar",
"/my/app/libs/libraryA-0.jar",
"/my/app/libs/libraryB-0.jar"),
configuration.getDependencyLayerEntries());
assertExtractionPathsUnordered(
Arrays.asList("/my/app/libs/dependencyX-1.0.0-SNAPSHOT.jar"),
Collections.singletonList("/my/app/libs/dependencyX-1.0.0-SNAPSHOT-770.jar"),
configuration.getSnapshotDependencyLayerEntries());
assertExtractionPathsUnordered(
Arrays.asList(
Expand Down Expand Up @@ -111,14 +113,18 @@ private static void assertNonDefaultAppRoot(JavaLayerConfigurations configuratio
@Before
public void setUp() throws URISyntaxException, IOException {
Path outputPath = Paths.get(Resources.getResource("application/output").toURI());
Path dependenciesPath = Paths.get(Resources.getResource("application/dependencies").toURI());

Mockito.when(mockMavenProject.getBuild()).thenReturn(mockBuild);
Mockito.when(mockBuild.getOutputDirectory()).thenReturn(outputPath.toString());

Set<Artifact> artifacts =
ImmutableSet.of(
makeArtifact(Paths.get("application", "dependencies", "libraryB.jar")),
makeArtifact(Paths.get("application", "dependencies", "libraryA.jar")),
makeArtifact(dependenciesPath.resolve("libraryB.jar")),
makeArtifact(dependenciesPath.resolve("libraryA.jar")),
makeArtifact(dependenciesPath.resolve("more").resolve("dependency-1.0.0.jar")),
makeArtifact(
dependenciesPath.resolve("another").resolve("one").resolve("dependency-1.0.0.jar")),
// Maven reads and populates "Artifacts" with its own processing, so read some from a
// repository
testRepository.findArtifact("com.test", "dependency", "1.0.0"),
Expand All @@ -135,11 +141,14 @@ public void setUp() throws URISyntaxException, IOException {

@Test
public void test_correctFiles() throws URISyntaxException, IOException {
Path dependenciesPath = Paths.get(Resources.getResource("application/dependencies").toURI());
ImmutableList<Path> expectedDependenciesFiles =
ImmutableList.of(
testRepository.artifactPathOnDisk("com.test", "dependency", "1.0.0"),
Paths.get("application", "dependencies", "libraryA.jar"),
Paths.get("application", "dependencies", "libraryB.jar"));
dependenciesPath.resolve("more").resolve("dependency-1.0.0.jar"),
dependenciesPath.resolve("another").resolve("one").resolve("dependency-1.0.0.jar"),
dependenciesPath.resolve("libraryA.jar"),
dependenciesPath.resolve("libraryB.jar"));
ImmutableList<Path> expectedSnapshotDependenciesFiles =
ImmutableList.of(
testRepository.artifactPathOnDisk("com.test", "dependencyX", "1.0.0-SNAPSHOT"));
Expand Down Expand Up @@ -266,10 +275,10 @@ public void testGetForWarProject_nonDefaultAppRoot() throws URISyntaxException,
assertSourcePathsUnordered(expectedExtraFiles, configuration.getExtraFilesLayerEntries());

assertExtractionPathsUnordered(
Arrays.asList("/my/app/WEB-INF/lib/dependency-1.0.0.jar"),
Collections.singletonList("/my/app/WEB-INF/lib/dependency-1.0.0.jar"),
configuration.getDependencyLayerEntries());
assertExtractionPathsUnordered(
Arrays.asList("/my/app/WEB-INF/lib/dependencyX-1.0.0-SNAPSHOT.jar"),
Collections.singletonList("/my/app/WEB-INF/lib/dependencyX-1.0.0-SNAPSHOT.jar"),
configuration.getSnapshotDependencyLayerEntries());
assertExtractionPathsUnordered(
Arrays.asList(
Expand Down Expand Up @@ -349,28 +358,28 @@ public void testGetForWarProject_noErrorIfWebInfClassesDoesNotExist() throws IOE
}

@Test
public void testIsWarProject_WarPackagingIsWar() throws IOException {
public void testIsWarProject_WarPackagingIsWar() {
Mockito.when(mockMavenProject.getPackaging()).thenReturn("war");

Assert.assertTrue(MojoCommon.isWarProject(mockMavenProject));
}

@Test
public void testIsWarProject_GwtAppPackagingIsWar() throws IOException {
public void testIsWarProject_GwtAppPackagingIsWar() {
Mockito.when(mockMavenProject.getPackaging()).thenReturn("gwt-app");

Assert.assertTrue(MojoCommon.isWarProject(mockMavenProject));
}

@Test
public void testIsWarProject_JarPackagingIsNotWar() throws IOException {
public void testIsWarProject_JarPackagingIsNotWar() {
Mockito.when(mockMavenProject.getPackaging()).thenReturn("jar");

Assert.assertFalse(MojoCommon.isWarProject(mockMavenProject));
}

@Test
public void testIsWarProject_GwtLibPackagingIsNotWar() throws IOException {
public void testIsWarProject_GwtLibPackagingIsNotWar() {
Mockito.when(mockMavenProject.getPackaging()).thenReturn("gwt-lib");

Assert.assertFalse(MojoCommon.isWarProject(mockMavenProject));
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
]e$Ềx���,�
.3��I݅����3�8��V�KA����M��)=5�~�'qю�$[��- :��&�%�� ����E�o����7N���s`�i�Z0MT.����9J[�}?\E ��}U�v���J�d��o(��i��"M��ԛ��_+/�c���I<��Zje��44%���d2?�l>.��-�O�=H�i�