Skip to content

Commit 06ae7fb

Browse files
committed
Add jar validation and fix multi-release jar
See gh-35768 Signed-off-by: Clayton Walker <[email protected]>
1 parent 21d3b2d commit 06ae7fb

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

buildSrc/src/main/java/org/springframework/build/multirelease/MultiReleaseJarPlugin.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import org.gradle.api.plugins.JavaPlugin;
2828
import org.gradle.api.plugins.JavaPluginExtension;
2929
import org.gradle.api.tasks.TaskContainer;
30+
import org.gradle.api.tasks.TaskProvider;
31+
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
32+
import org.gradle.jvm.tasks.Jar;
3033
import org.gradle.jvm.toolchain.JavaToolchainService;
3134

3235
/**
@@ -57,5 +60,9 @@ public void apply(Project project) {
5760
tasks,
5861
dependencies,
5962
objects);
63+
TaskProvider<MultiReleaseJarValidateTask> validateJarTask = tasks.register("validateJar", MultiReleaseJarValidateTask.class, (task) -> {
64+
task.getJar().set(tasks.named("jar", Jar.class).flatMap(AbstractArchiveTask::getArchiveFile));
65+
});
66+
tasks.named("check", task -> task.dependsOn(validateJarTask));
6067
}
6168
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2002-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.build.multirelease;
18+
19+
import org.gradle.api.file.RegularFileProperty;
20+
import org.gradle.api.tasks.CacheableTask;
21+
import org.gradle.api.tasks.InputFile;
22+
import org.gradle.api.tasks.JavaExec;
23+
import org.gradle.api.tasks.PathSensitive;
24+
import org.gradle.api.tasks.PathSensitivity;
25+
26+
import java.util.List;
27+
28+
@CacheableTask
29+
public abstract class MultiReleaseJarValidateTask extends JavaExec {
30+
@InputFile
31+
@PathSensitive(PathSensitivity.RELATIVE)
32+
public abstract RegularFileProperty getJar();
33+
public MultiReleaseJarValidateTask() {
34+
getMainModule().set("jdk.jartool");
35+
getArgumentProviders().add(() -> List.of("--validate", "--file", getJar().get().getAsFile().getAbsolutePath()));
36+
}
37+
}

spring-core/src/main/java24/org/springframework/core/type/classreading/ClassFileMetadataReaderFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* @author Brian Clozel
3131
* @since 7.0
3232
*/
33-
public class ClassFileMetadataReaderFactory extends AbstractMetadataReaderFactory {
33+
class ClassFileMetadataReaderFactory extends AbstractMetadataReaderFactory {
3434

3535
/**
3636
* Create a new ClassFileMetadataReaderFactory for the default class loader.

0 commit comments

Comments
 (0)