From cb6362df82ea71d5454295250cba0279803ebb24 Mon Sep 17 00:00:00 2001 From: Robert Thornton Date: Wed, 20 Feb 2019 05:28:58 +0000 Subject: [PATCH 1/2] Use kotlin_module not kotlin-module to identify Kotlin module metadata See gh-16004 --- .../boot/loader/tools/Repackager.java | 2 +- .../boot/loader/tools/RepackagerTests.java | 8 +- .../src/it/jar-with-kotlin-module/pom.xml | 106 ++++++++++++++++++ .../main/kotlin/org/test/SampleApplication.kt | 22 ++++ .../it/jar-with-kotlin-module/verify.groovy | 30 +++++ 5 files changed, 163 insertions(+), 5 deletions(-) create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/pom.xml create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/src/main/kotlin/org/test/SampleApplication.kt create mode 100644 spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/verify.groovy diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java index 7ecdf2bead..bf3cff5bb6 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/main/java/org/springframework/boot/loader/tools/Repackager.java @@ -381,7 +381,7 @@ public class Repackager { } if ((entry.getName().startsWith("META-INF/") && !entry.getName().equals("META-INF/aop.xml") - && !entry.getName().endsWith(".kotlin-module")) + && !entry.getName().endsWith(".kotlin_module")) || entry.getName().startsWith("BOOT-INF/") || entry.getName().equals("module-info.class")) { return entry; diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/RepackagerTests.java b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/RepackagerTests.java index 778bf33ee9..a28925c16c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/RepackagerTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader-tools/src/test/java/org/springframework/boot/loader/tools/RepackagerTests.java @@ -679,15 +679,15 @@ public class RepackagerTests { public void kotlinModuleMetadataMovesBeneathBootInfClassesWhenRepackaged() throws Exception { this.testJarFile.addClass("A.class", ClassWithMainMethod.class); - this.testJarFile.addFile("META-INF/test.kotlin-module", - this.temporaryFolder.newFile("test.kotlin-module")); + this.testJarFile.addFile("META-INF/test.kotlin_module", + this.temporaryFolder.newFile("test.kotlin_module")); File source = this.testJarFile.getFile(); File dest = this.temporaryFolder.newFile("dest.jar"); Repackager repackager = new Repackager(source); repackager.repackage(dest, NO_LIBRARIES); try (JarFile jarFile = new JarFile(dest)) { - assertThat(jarFile.getEntry("META-INF/test.kotlin-module")).isNull(); - assertThat(jarFile.getEntry("BOOT-INF/classes/META-INF/test.kotlin-module")) + assertThat(jarFile.getEntry("META-INF/test.kotlin_module")).isNull(); + assertThat(jarFile.getEntry("BOOT-INF/classes/META-INF/test.kotlin_module")) .isNotNull(); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/pom.xml new file mode 100644 index 0000000000..1ce66c36bf --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/pom.xml @@ -0,0 +1,106 @@ + + + 4.0.0 + org.springframework.boot.maven.it + jar-with-kotlin-module + 0.0.1.BUILD-SNAPSHOT + + UTF-8 + @java.version@ + @java.version@ + + + ${project.basedir}/src/main/kotlin + ${project.basedir}/src/test/kotlin + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + repackage + + + + + org.jetbrains.kotlin + kotlin-compiler + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + @maven-jar-plugin.version@ + + + + Foo + + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + @kotlin.version@ + + + compile + process-resources + + compile + + + + test-compile + process-test-resources + + compile + + + + + + + + + org.springframework + spring-context + @spring.version@ + + + javax.servlet + javax.servlet-api + @servlet-api.version@ + provided + + + org.apache.logging.log4j + log4j-api + @log4j2.version@ + + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + @kotlin.version@ + + + org.jetbrains.kotlin + kotlin-reflect + @kotlin.version@ + + + org.jetbrains.kotlin + kotlin-compiler + @kotlin.version@ + + + diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/src/main/kotlin/org/test/SampleApplication.kt b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/src/main/kotlin/org/test/SampleApplication.kt new file mode 100644 index 0000000000..c4d4345aae --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/src/main/kotlin/org/test/SampleApplication.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2012-2017 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@file:JvmName("SampleApplication") +package org.test; + +fun main(args: Array) { + +} \ No newline at end of file diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/verify.groovy b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/verify.groovy new file mode 100644 index 0000000000..8ae0716cf7 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/verify.groovy @@ -0,0 +1,30 @@ +/* + * Copyright 2012-2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.*; +import org.springframework.boot.maven.*; + +File f = new File( basedir, "target/jar-with-kotlin-module-0.0.1.BUILD-SNAPSHOT.jar"); +new Verify.JarArchiveVerification(f, Verify.SAMPLE_APP) { + @Override + protected void verifyZipEntries(Verify.ArchiveVerifier verifier) throws Exception { + super.verifyZipEntries(verifier) + verifier.assertHasEntryNameStartingWith("BOOT-INF/classes/META-INF/jar-with-kotlin-module.kotlin_module") + verifier.assertHasUnpackEntry("BOOT-INF/lib/kotlin-compiler-") + verifier.assertHasNonUnpackEntry("BOOT-INF/lib/kotlin-stdlib-") + verifier.assertHasNonUnpackEntry("BOOT-INF/lib/kotlin-reflect-") + } +}.verify(); From 55fe26b075972a1641f11c7bb5f0492b9ff134c6 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 20 Feb 2019 17:18:21 +0000 Subject: [PATCH 2/2] Polish "Use kotlin_module not kotlin-module to identify Kotlin module metadata" See gh-16004 --- .../src/main/kotlin/org/test/SampleApplication.kt | 2 +- .../src/it/jar-with-kotlin-module/verify.groovy | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/src/main/kotlin/org/test/SampleApplication.kt b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/src/main/kotlin/org/test/SampleApplication.kt index c4d4345aae..696095f42a 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/src/main/kotlin/org/test/SampleApplication.kt +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/src/main/kotlin/org/test/SampleApplication.kt @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/verify.groovy b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/verify.groovy index 8ae0716cf7..764a89bf56 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/verify.groovy +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/it/jar-with-kotlin-module/verify.groovy @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.