Skip to content

Commit

Permalink
Merge branch '2.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Feb 1, 2019
2 parents b4e890c + 2650a07 commit 342bced
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -55,13 +55,15 @@ public BootJar() {
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -54,6 +54,9 @@ public BootWar() {
(copySpec) -> copySpec.from(
(Callable<Iterable<File>>) () -> (this.providedClasspath != null)
? this.providedClasspath : Collections.emptyList()));
getRootSpec().filesMatching("module-info.class", (details) -> {
details.setRelativePath(details.getRelativeSourcePath());
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -133,6 +133,30 @@ public void classpathFoldersArePackagedBeneathClassesPath() throws IOException {
}
}

@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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -381,7 +381,8 @@ public JarArchiveEntry transform(JarArchiveEntry entry) {
}
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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -661,6 +661,20 @@ public void jarThatUsesCustomCompressionConfigurationCanBeRepackaged()
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",
Expand Down

0 comments on commit 342bced

Please sign in to comment.