Skip to content

Commit a5cd92d

Browse files
melixdnestoro
authored andcommitted
Address review feedback
1 parent 62ef250 commit a5cd92d

File tree

4 files changed

+74
-15
lines changed

4 files changed

+74
-15
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2021, 2021 Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package org.graalvm.buildtools.model.resources;
42+
43+
public abstract class NativeImageFlags {
44+
public static final String BUILD_OUTPUT_COLORFUL = "-H:+BuildOutputColorful";
45+
public static final String COLOR = "--color";
46+
public static final String CONFIGURATION_FILE_DIRECTORIES = "-H:ConfigurationFileDirectories";
47+
public static final String LAYER_CREATE = "-H:LayerCreate";
48+
public static final String LAYER_USE = "-H:LayerUse";
49+
public static final String NO_FALLBACK = "--no-fallback";
50+
public static final String PGO_INSTRUMENT = "--pgo-instrument";
51+
public static final String QUICK_BUILD = "-Ob";
52+
public static final String SHARED = "--shared";
53+
public static final String UNLOCK_EXPERIMENTAL_VMOPTIONS = "-H:+UnlockExperimentalVMOptions";
54+
public static final String VERBOSE = "--verbose";
55+
56+
private NativeImageFlags() {
57+
58+
}
59+
}

common/utils/src/main/java/org/graalvm/buildtools/utils/JarScanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class JarScanner {
4141
public static void scanJar(Path inputJar, Path outputFile) throws IOException {
4242
try (Writer fileWriter = Files.newBufferedWriter(outputFile); PrintWriter writer = new PrintWriter(fileWriter)) {
4343
Set<String> packageList = new TreeSet<>();
44-
try (FileSystem jarFileSystem = FileSystems.newFileSystem(inputJar, null)) {
44+
try (FileSystem jarFileSystem = FileSystems.newFileSystem(inputJar, (ClassLoader) null)) {
4545
Path root = jarFileSystem.getPath("/");
4646
try (Stream<Path> files = Files.walk(root)) {
4747
files.forEach(path -> {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,15 @@ private void configureAutomaticTaskCreation(Project project,
348348
var useLayers = options.getLayers()
349349
.stream()
350350
.filter(layer -> layer instanceof UseLayerOptions)
351-
.collect(Collectors.toList());
351+
.toList();
352352
if (!useLayers.isEmpty()) {
353353
var libsDirs = project.getObjects().fileCollection();
354354
libsDirs.from(useLayers
355355
.stream()
356356
.map(l -> l.getLayerName().flatMap(layerName -> tasks.named(compileTaskNameForBinary(layerName), BuildNativeImageTask.class))
357357
.map(t -> t.getOutputDirectory().getAsFile())
358358
)
359-
.collect(Collectors.toList()));
359+
.toList());
360360
if (IS_WINDOWS) {
361361
var pathVariable = providers.environmentVariable("PATH");
362362
task.getEnvironment().put("PATH", pathVariable.map(path -> path + ";" + libsDirs.getAsPath()).orElse(providers.provider(libsDirs::getAsPath)));

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.graalvm.buildtools.gradle.tasks.CreateLayerOptions;
4646
import org.graalvm.buildtools.gradle.tasks.LayerOptions;
4747
import org.graalvm.buildtools.gradle.tasks.UseLayerOptions;
48+
import org.graalvm.buildtools.model.resources.NativeImageFlags;
4849
import org.graalvm.buildtools.utils.NativeImageUtils;
4950
import org.gradle.api.Transformer;
5051
import org.gradle.api.file.ConfigurableFileCollection;
@@ -129,7 +130,7 @@ public List<String> asArguments() {
129130
ConfigurableFileCollection jarsClasspath = null;
130131
if (hasLayers) {
131132
LOGGER.warn("Experimental support for layered images enabled. DSL may change at any time.");
132-
cliArgs.add("-H:+UnlockExperimentalVMOptions");
133+
cliArgs.add(NativeImageFlags.UNLOCK_EXPERIMENTAL_VMOPTIONS);
133134
var layers = options.getLayers();
134135
var arg = new StringBuilder();
135136
for (LayerOptions layer : layers) {
@@ -139,14 +140,13 @@ public List<String> asArguments() {
139140
if (layer instanceof CreateLayerOptions) {
140141
var create = (CreateLayerOptions) layer;
141142
layerCreateName = layer.getLayerName().get();
142-
arg.append("-H:LayerCreate=");
143+
arg.append(NativeImageFlags.LAYER_CREATE + "=");
143144
arg.append(layerCreateName).append(".nil");
144145
var modules = create.getModules().get();
145146
jarsClasspath = create.getJars();
146147
boolean hasModules = !modules.isEmpty();
147148
boolean hasPackage = create.getPackages().isPresent() && !create.getPackages().get().isEmpty();
148-
var createLayerJars = jarsClasspath.getFiles();
149-
boolean hasJars = !createLayerJars.isEmpty();
149+
boolean hasJars = !jarsClasspath.getFiles().isEmpty();
150150
if (hasModules || hasPackage || hasJars) {
151151
var packages = create.getPackages().get();
152152
arg.append(",");
@@ -168,7 +168,7 @@ public List<String> asArguments() {
168168
}
169169
} else {
170170
var layerUse = (UseLayerOptions) layer;
171-
arg.append("-H:LayerUse=");
171+
arg.append(NativeImageFlags.LAYER_USE + "=");
172172
arg.append(layerUse.getLayerFile().getAsFile().get().getAbsolutePath());
173173
}
174174
}
@@ -187,14 +187,14 @@ public List<String> asArguments() {
187187
cliArgs.add(jarsClasspath.getAsPath());
188188
}
189189
appendBooleanOption(cliArgs, options.getDebug(), "-g");
190-
appendBooleanOption(cliArgs, options.getFallback().map(NEGATE), "--no-fallback");
191-
appendBooleanOption(cliArgs, options.getVerbose(), "--verbose");
192-
appendBooleanOption(cliArgs, options.getSharedLibrary(), "--shared");
193-
appendBooleanOption(cliArgs, options.getQuickBuild(), "-Ob");
190+
appendBooleanOption(cliArgs, options.getFallback().map(NEGATE), NativeImageFlags.NO_FALLBACK);
191+
appendBooleanOption(cliArgs, options.getVerbose(), NativeImageFlags.VERBOSE);
192+
appendBooleanOption(cliArgs, options.getSharedLibrary(), NativeImageFlags.SHARED);
193+
appendBooleanOption(cliArgs, options.getQuickBuild(), NativeImageFlags.QUICK_BUILD);
194194
if (useColors.get()) {
195-
appendBooleanOption(cliArgs, options.getRichOutput(), majorJDKVersion.getOrElse(-1) >= 21 ? "--color" : "-H:+BuildOutputColorful");
195+
appendBooleanOption(cliArgs, options.getRichOutput(), majorJDKVersion.getOrElse(-1) >= 21 ? NativeImageFlags.COLOR : NativeImageFlags.BUILD_OUTPUT_COLORFUL);
196196
}
197-
appendBooleanOption(cliArgs, options.getPgoInstrument(), "--pgo-instrument");
197+
appendBooleanOption(cliArgs, options.getPgoInstrument(), NativeImageFlags.PGO_INSTRUMENT);
198198

199199
String targetOutputPath = getExecutableName().get();
200200
if (layerCreateName != null) {
@@ -221,7 +221,7 @@ public List<String> asArguments() {
221221
.map(File::getAbsolutePath)
222222
.collect(Collectors.joining(","));
223223
if (!configFiles.isEmpty()) {
224-
cliArgs.add("-H:ConfigurationFileDirectories=" + configFiles);
224+
cliArgs.add(NativeImageFlags.CONFIGURATION_FILE_DIRECTORIES + "=" + configFiles);
225225
}
226226
if (Boolean.FALSE.equals(options.getPgoInstrument().get()) && options.getPgoProfilesDirectory().isPresent()) {
227227
FileTree files = options.getPgoProfilesDirectory().get().getAsFileTree();

0 commit comments

Comments
 (0)