Skip to content

Commit 5e68bec

Browse files
Fix review feedback
1 parent 0afe2d8 commit 5e68bec

File tree

4 files changed

+33
-28
lines changed

4 files changed

+33
-28
lines changed

.github/workflows/test-native-gradle-plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
strategy:
5454
fail-fast: false
5555
matrix:
56-
gradle-version: ["current", "7.3.3", "6.7.1"]
56+
gradle-version: ["current", "7.3.3", "7.2", "7.1", "6.8.3", "6.7.1"]
5757
graalvm-version: [ dev ]
5858
java-version: [ 11 ]
5959
os: [ ubuntu-20.04 ]

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/internal/BaseNativeImageOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ public String getName() {
205205

206206
/**
207207
* Returns the MapProperty that contains information about configuration that should be excluded
208-
* during image building. It consists of a dependency coordinates and a list of
209-
* regular expressions that match resources that should be excluded as a value.
208+
* during image building. It consists of dependency coordinates and a list of
209+
* regular expressions that match resources that should be excluded.
210210
*
211211
* @return a map of filters for configuration exclusion
212212
*/

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/internal/NativeImageCommandLineProvider.java

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343

4444
import org.graalvm.buildtools.gradle.dsl.NativeImageOptions;
4545
import org.graalvm.buildtools.utils.NativeImageUtils;
46-
import org.gradle.api.Project;
4746
import org.gradle.api.Transformer;
47+
import org.gradle.api.artifacts.Configuration;
4848
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
4949
import org.gradle.api.file.FileSystemLocation;
5050
import org.gradle.api.file.RegularFile;
@@ -58,6 +58,7 @@
5858
import java.util.ArrayList;
5959
import java.util.Collections;
6060
import java.util.List;
61+
import java.util.Set;
6162
import java.util.stream.Collectors;
6263

6364
public class NativeImageCommandLineProvider implements CommandLineArgumentProvider {
@@ -68,20 +69,17 @@ public class NativeImageCommandLineProvider implements CommandLineArgumentProvid
6869
private final Provider<String> outputDirectory;
6970
private final Provider<RegularFile> classpathJar;
7071
private final Provider<Boolean> useArgFile;
71-
private final Project project;
7272

7373
public NativeImageCommandLineProvider(Provider<NativeImageOptions> options,
7474
Provider<String> executableName,
7575
Provider<String> outputDirectory,
7676
Provider<RegularFile> classpathJar,
77-
Provider<Boolean> useArgFile,
78-
Project project) {
77+
Provider<Boolean> useArgFile) {
7978
this.options = options;
8079
this.executableName = executableName;
8180
this.outputDirectory = outputDirectory;
8281
this.classpathJar = classpathJar;
8382
this.useArgFile = useArgFile;
84-
this.project = project;
8583
}
8684

8785
@Nested
@@ -108,24 +106,32 @@ private List<String> buildExcludeConfigArgs(NativeImageOptions options) {
108106
List<String> args = new ArrayList<>();
109107
options.getExcludeConfig().get().forEach((dependency, listOfResourcePatterns) -> {
110108
// Resolve jar for this dependency.
111-
project.getConfigurations().getByName("runtimeClasspath").getIncoming().artifactView(view -> {
112-
view.setLenient(true);
113-
view.componentFilter(id -> {
114-
if (id instanceof ModuleComponentIdentifier) {
115-
ModuleComponentIdentifier mid = (ModuleComponentIdentifier) id;
116-
String gav = String.format("%s:%s",
117-
mid.getGroup(),
118-
mid.getModule()
119-
);
120-
return dependency.startsWith(gav);
121-
}
122-
return false;
123-
});
124-
}).getFiles().forEach(jarPath -> listOfResourcePatterns.forEach(resourcePattern -> {
125-
args.add("--exclude-config");
126-
args.add(jarPath.toPath().toAbsolutePath().toString());
127-
args.add(String.format("\"%s\"", resourcePattern));
128-
}));
109+
options.getClasspath()
110+
.getFrom().stream()
111+
.filter(Configuration.class::isInstance)
112+
.map(Configuration.class::cast)
113+
.map(configuration -> configuration.getIncoming().artifactView(view -> {
114+
view.setLenient(true);
115+
view.componentFilter(id -> {
116+
if (id instanceof ModuleComponentIdentifier) {
117+
ModuleComponentIdentifier mid = (ModuleComponentIdentifier) id;
118+
String gav = String.format("%s:%s",
119+
mid.getGroup(),
120+
mid.getModule()
121+
);
122+
return dependency.startsWith(gav);
123+
}
124+
return false;
125+
});
126+
}).getFiles().getFiles())
127+
.flatMap(Set::stream) // merge resulting sets of files
128+
.collect(Collectors.toSet())
129+
.forEach(jarPath -> listOfResourcePatterns.forEach(resourcePattern -> {
130+
args.add("--exclude-config");
131+
args.add(jarPath.toPath().toAbsolutePath().toString());
132+
args.add(String.format("\"%s\"", resourcePattern));
133+
}));
134+
129135
});
130136
return args;
131137
}

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/tasks/BuildNativeImageTask.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ private List<String> buildActualCommandLineArgs() {
155155
// a mapped value before the task was called, when we are actually calling it...
156156
getProviders().provider(() -> getOutputDirectory().getAsFile().get().getAbsolutePath()),
157157
getClasspathJar(),
158-
getUseArgFile(),
159-
getProject()
158+
getUseArgFile()
160159
).asArguments();
161160
}
162161

0 commit comments

Comments
 (0)