Browse Source

Polish "Stop limiting layer customization to external modules"

See gh-21207
pull/21259/head
Andy Wilkinson 6 years ago
parent
commit
2d769e7679
  1. 16
      spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LayerResolver.java
  2. 16
      spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests.java
  3. 4
      spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-multiModuleCustomLayers.gradle

16
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/tasks/bundling/LayerResolver.java

@ -28,9 +28,6 @@ import org.gradle.api.artifacts.Configuration; @@ -28,9 +28,6 @@ import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ModuleVersionIdentifier;
import org.gradle.api.artifacts.ResolvedArtifact;
import org.gradle.api.artifacts.ResolvedConfiguration;
import org.gradle.api.artifacts.component.ComponentIdentifier;
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
import org.gradle.api.artifacts.component.ProjectComponentIdentifier;
import org.gradle.api.file.FileCopyDetails;
import org.gradle.api.specs.Spec;
@ -137,16 +134,9 @@ class LayerResolver { @@ -137,16 +134,9 @@ class LayerResolver {
private final Map<File, LibraryCoordinates> artifactCoordinates = new LinkedHashMap<>();
ResolvedConfigurationDependencies(ResolvedConfiguration resolvedConfiguration) {
if (resolvedConfiguration != null) {
for (ResolvedArtifact resolvedArtifact : resolvedConfiguration.getResolvedArtifacts()) {
ComponentIdentifier identifier = resolvedArtifact.getId().getComponentIdentifier();
if (identifier instanceof ModuleComponentIdentifier
|| identifier instanceof ProjectComponentIdentifier) {
this.artifactCoordinates.put(resolvedArtifact.getFile(),
new ModuleVersionIdentifierLibraryCoordinates(
resolvedArtifact.getModuleVersion().getId()));
}
}
for (ResolvedArtifact resolvedArtifact : resolvedConfiguration.getResolvedArtifacts()) {
this.artifactCoordinates.put(resolvedArtifact.getFile(),
new ModuleVersionIdentifierLibraryCoordinates(resolvedArtifact.getModuleVersion().getId()));
}
}

16
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/java/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests.java

@ -178,7 +178,7 @@ class BootJarIntegrationTests extends AbstractBootArchiveIntegrationTests { @@ -178,7 +178,7 @@ class BootJarIntegrationTests extends AbstractBootArchiveIntegrationTests {
}
@TestTemplate
void projectDependenciesCanBeIncludedInCustomLayer() throws IOException {
void multiModuleCustomLayers() throws IOException {
writeSettingsGradle();
writeMainClass();
writeResource();
@ -188,8 +188,8 @@ class BootJarIntegrationTests extends AbstractBootArchiveIntegrationTests { @@ -188,8 +188,8 @@ class BootJarIntegrationTests extends AbstractBootArchiveIntegrationTests {
String layerToolsJar = "BOOT-INF/lib/" + JarModeLibrary.LAYER_TOOLS.getName();
try (JarFile jarFile = new JarFile(new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0])) {
assertThat(jarFile.getEntry(layerToolsJar)).isNotNull();
assertThat(jarFile.getEntry("BOOT-INF/lib/foo-1.2.3.jar")).isNotNull();
assertThat(jarFile.getEntry("BOOT-INF/lib/bar-1.2.3.jar")).isNotNull();
assertThat(jarFile.getEntry("BOOT-INF/lib/alpha-1.2.3.jar")).isNotNull();
assertThat(jarFile.getEntry("BOOT-INF/lib/bravo-1.2.3.jar")).isNotNull();
assertThat(jarFile.getEntry("BOOT-INF/lib/commons-lang3-3.9.jar")).isNotNull();
assertThat(jarFile.getEntry("BOOT-INF/lib/spring-core-5.2.5.RELEASE.jar")).isNotNull();
assertThat(jarFile.getEntry("BOOT-INF/lib/spring-jcl-5.2.5.RELEASE.jar")).isNotNull();
@ -203,8 +203,8 @@ class BootJarIntegrationTests extends AbstractBootArchiveIntegrationTests { @@ -203,8 +203,8 @@ class BootJarIntegrationTests extends AbstractBootArchiveIntegrationTests {
"subproject-dependencies", "static", "app");
assertThat(indexedLayers.keySet()).containsExactlyElementsOf(layerNames);
Set<String> expectedSubprojectDependencies = new TreeSet<>();
expectedSubprojectDependencies.add("BOOT-INF/lib/foo-1.2.3.jar");
expectedSubprojectDependencies.add("BOOT-INF/lib/bar-1.2.3.jar");
expectedSubprojectDependencies.add("BOOT-INF/lib/alpha-1.2.3.jar");
expectedSubprojectDependencies.add("BOOT-INF/lib/bravo-1.2.3.jar");
Set<String> expectedDependencies = new TreeSet<>();
expectedDependencies.add("BOOT-INF/lib/spring-core-5.2.5.RELEASE.jar");
expectedDependencies.add("BOOT-INF/lib/spring-jcl-5.2.5.RELEASE.jar");
@ -261,9 +261,9 @@ class BootJarIntegrationTests extends AbstractBootArchiveIntegrationTests { @@ -261,9 +261,9 @@ class BootJarIntegrationTests extends AbstractBootArchiveIntegrationTests {
}
private void writeSettingsGradle() {
File settings = new File(this.gradleBuild.getProjectDir(), "settings.gradle");
try (PrintWriter writer = new PrintWriter(new FileWriter(settings))) {
writer.println("include 'foo', 'bar'");
try (PrintWriter writer = new PrintWriter(
new FileWriter(new File(this.gradleBuild.getProjectDir(), "settings.gradle")))) {
writer.println("include 'alpha', 'bravo'");
}
catch (IOException ex) {
throw new RuntimeException(ex);

4
spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-projectDependenciesCanBeIncludedInCustomLayer.gradle → spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/test/resources/org/springframework/boot/gradle/tasks/bundling/BootJarIntegrationTests-multiModuleCustomLayers.gradle

@ -40,8 +40,8 @@ repositories { @@ -40,8 +40,8 @@ repositories {
}
dependencies {
implementation(project(':foo'))
implementation(project(':bar'))
implementation(project(':alpha'))
implementation(project(':bravo'))
implementation("commons-io:commons-io:2.7-SNAPSHOT")
implementation("org.apache.commons:commons-lang3:3.9")
implementation("org.springframework:spring-core:5.2.5.RELEASE")
Loading…
Cancel
Save