mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
Leave module-info.class in root of archive when repackaging
Closes gh-15810
This commit is contained in:
parent
c84a0f530b
commit
2650a07dc9
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 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.
|
||||
@ -55,13 +55,15 @@ public class BootJar extends Jar implements BootArchive {
|
||||
getMainSpec().with(this.bootInf);
|
||||
this.bootInf.into("classes", classpathFiles(File::isDirectory));
|
||||
this.bootInf.into("lib", classpathFiles(File::isFile));
|
||||
this.bootInf.filesMatching("module-info.class", (details) -> {
|
||||
details.setRelativePath(details.getRelativeSourcePath());
|
||||
});
|
||||
}
|
||||
|
||||
private Action<CopySpec> classpathFiles(Spec<File> filter) {
|
||||
return (copySpec) -> copySpec
|
||||
.from((Callable<Iterable<File>>) () -> (this.classpath != null)
|
||||
? this.classpath.filter(filter) : Collections.emptyList());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 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.
|
||||
@ -54,6 +54,9 @@ public class BootWar extends War implements BootArchive {
|
||||
(copySpec) -> copySpec.from(
|
||||
(Callable<Iterable<File>>) () -> (this.providedClasspath != null)
|
||||
? this.providedClasspath : Collections.emptyList()));
|
||||
getRootSpec().filesMatching("module-info.class", (details) -> {
|
||||
details.setRelativePath(details.getRelativeSourcePath());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 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.
|
||||
@ -133,6 +133,30 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void moduleInfoClassIsPackagedInTheRootOfTheArchive() throws IOException {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
File classpathFolder = this.temp.newFolder();
|
||||
File moduleInfoClass = new File(classpathFolder, "module-info.class");
|
||||
moduleInfoClass.getParentFile().mkdirs();
|
||||
moduleInfoClass.createNewFile();
|
||||
File applicationClass = new File(classpathFolder,
|
||||
"com/example/Application.class");
|
||||
applicationClass.getParentFile().mkdirs();
|
||||
applicationClass.createNewFile();
|
||||
this.task.classpath(classpathFolder);
|
||||
this.task.execute();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
assertThat(
|
||||
jarFile.getEntry(this.classesPath + "/com/example/Application.class"))
|
||||
.isNotNull();
|
||||
assertThat(jarFile.getEntry("com/example/Application.class")).isNull();
|
||||
assertThat(jarFile.getEntry("module-info.class")).isNotNull();
|
||||
assertThat(jarFile.getEntry(this.classesPath + "/module-info.class"))
|
||||
.isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void classpathCanBeSetUsingAFileCollection() throws IOException {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 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.
|
||||
@ -381,7 +381,8 @@ public class Repackager {
|
||||
}
|
||||
if ((entry.getName().startsWith("META-INF/")
|
||||
&& !entry.getName().equals("META-INF/aop.xml"))
|
||||
|| entry.getName().startsWith("BOOT-INF/")) {
|
||||
|| entry.getName().startsWith("BOOT-INF/")
|
||||
|| entry.getName().equals("module-info.class")) {
|
||||
return entry;
|
||||
}
|
||||
JarArchiveEntry renamedEntry = new JarArchiveEntry(
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 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.
|
||||
@ -661,6 +661,20 @@ public class RepackagerTests {
|
||||
repackager.repackage(dest, NO_LIBRARIES);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void moduleInfoClassRemainsInRootOfJarWhenRepackaged() throws Exception {
|
||||
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
|
||||
this.testJarFile.addClass("module-info.class", ClassWithoutMainMethod.class);
|
||||
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("module-info.class")).isNotNull();
|
||||
assertThat(jarFile.getEntry("BOOT-INF/classes/module-info.class")).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
private File createLibrary() throws IOException {
|
||||
TestJarFile library = new TestJarFile(this.temporaryFolder);
|
||||
library.addClass("com/example/library/Library.class",
|
||||
|
Loading…
Reference in New Issue
Block a user