Skip to content

Commit

Permalink
Merge branch '2.6.x' into 2.7.x
Browse files Browse the repository at this point in the history
Closes gh-30791
  • Loading branch information
wilkinsona committed Apr 25, 2022
2 parents b406971 + 409ec48 commit 56690a7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
Expand Up @@ -110,7 +110,8 @@ private Iterable<File> classpathEntries(Spec<File> filter) {
private void moveMetaInfToRoot(CopySpec spec) {
spec.eachFile((file) -> {
String path = file.getRelativeSourcePath().getPathString();
if (path.startsWith("META-INF/") && !path.equals("META-INF/aop.xml") && !path.endsWith(".kotlin_module")) {
if (path.startsWith("META-INF/") && !path.equals("META-INF/aop.xml") && !path.endsWith(".kotlin_module")
&& !path.startsWith("META-INF/services/")) {
this.support.moveToRoot(file);
}
});
Expand Down
Expand Up @@ -163,6 +163,27 @@ void kotlinModuleIsPackagedBeneathClassesDirectory() throws IOException {
}
}

@Test
void metaInfServicesEntryIsPackagedBeneathClassesDirectory() throws IOException {
getTask().getMainClass().set("com.example.Main");
File classpathDirectory = new File(this.temp, "classes");
File service = new File(classpathDirectory, "META-INF/services/com.example.Service");
service.getParentFile().mkdirs();
service.createNewFile();
File applicationClass = new File(classpathDirectory, "com/example/Application.class");
applicationClass.getParentFile().mkdirs();
applicationClass.createNewFile();
getTask().classpath(classpathDirectory);
executeTask();
try (JarFile jarFile = new JarFile(getTask().getArchiveFile().get().getAsFile())) {
assertThat(jarFile.getEntry("BOOT-INF/classes/com/example/Application.class")).isNotNull();
assertThat(jarFile.getEntry("com/example/Application.class")).isNull();
assertThat(jarFile.getEntry("BOOT-INF/classes/META-INF/services/com.example.Service")).isNotNull();
assertThat(jarFile.getEntry("META-INF/services/com.example.Service")).isNull();
}

}

@Override
void applyLayered(Action<LayeredSpec> action) {
getTask().layered(action);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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 @@ -452,7 +452,8 @@ private String transformName(String name) {
private boolean isTransformable(JarArchiveEntry entry) {
String name = entry.getName();
if (name.startsWith("META-INF/")) {
return name.equals("META-INF/aop.xml") || name.endsWith(".kotlin_module");
return name.equals("META-INF/aop.xml") || name.endsWith(".kotlin_module")
|| name.startsWith("META-INF/services/");
}
return !name.startsWith("BOOT-INF/") && !name.equals("module-info.class");
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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 @@ -484,6 +484,18 @@ void metaInfAopXmlIsMovedBeneathBootInfClassesWhenRepackaged() throws Exception
assertThat(getPackagedEntry("BOOT-INF/classes/META-INF/aop.xml")).isNotNull();
}

@Test
void metaInfServicesFilesAreMovedBeneathBootInfClassesWhenRepackaged() throws Exception {
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
File service = new File(this.tempDir, "com.example.Service");
service.createNewFile();
this.testJarFile.addFile("META-INF/services/com.example.Service", service);
P packager = createPackager();
execute(packager, NO_LIBRARIES);
assertThat(getPackagedEntry("META-INF/services/com.example.Service")).isNull();
assertThat(getPackagedEntry("BOOT-INF/classes/META-INF/services/com.example.Service")).isNotNull();
}

@Test
void allEntriesUseUnixPlatformAndUtf8NameEncoding() throws IOException {
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
Expand Down

0 comments on commit 56690a7

Please sign in to comment.