Skip to content

Commit

Permalink
Follow naming conventions of static final fields
Browse files Browse the repository at this point in the history
  • Loading branch information
olpaw committed Jan 30, 2023
1 parent 353c12e commit 4fbec8c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ final class BundleSupport {
boolean loadBundle;
boolean writeBundle;

private static final int bundleFileFormatVersionMajor = 0;
private static final int bundleFileFormatVersionMinor = 9;
private static final int BUNDLE_FILE_FORMAT_VERSION_MAJOR = 0;
private static final int BUNDLE_FILE_FORMAT_VERSION_MINOR = 9;

private static final String bundleInfoMessagePrefix = "GraalVM Native Image Bundle Support: ";
private static final String bundleTempDirPrefix = "bundleRoot-";
private static final String originalDirExtension = ".orig";
private static final String BUNDLE_INFO_MESSAGE_PREFIX = "GraalVM Native Image Bundle Support: ";
private static final String BUNDLE_TEMP_DIR_PREFIX = "bundleRoot-";
private static final String ORIGINAL_DIR_EXTENSION = ".orig";

private Path bundlePath;
private String bundleName;
Expand Down Expand Up @@ -154,7 +154,7 @@ static BundleSupport create(NativeImage nativeImage, String bundleArg, NativeIma
for (int i = buildArgs.size() - 1; i >= 0; i--) {
args.push(buildArgs.get(i));
}
nativeImage.showVerboseMessage(nativeImage.isVerbose(), bundleInfoMessagePrefix + "Inject args: '" + String.join(" ", buildArgs) + "'");
nativeImage.showVerboseMessage(nativeImage.isVerbose(), BUNDLE_INFO_MESSAGE_PREFIX + "Inject args: '" + String.join(" ", buildArgs) + "'");
/* Snapshot args after in-place expansion (includes also args after this one) */
bundleSupport.updatedBuildArgs = args.snapshot();
break;
Expand Down Expand Up @@ -193,7 +193,7 @@ private BundleSupport(NativeImage nativeImage) {
loadBundle = false;
writeBundle = true;
try {
rootDir = Files.createTempDirectory(bundleTempDirPrefix);
rootDir = Files.createTempDirectory(BUNDLE_TEMP_DIR_PREFIX);
bundleProperties = new BundleProperties();

Path inputDir = rootDir.resolve("input");
Expand Down Expand Up @@ -222,11 +222,11 @@ private BundleSupport(NativeImage nativeImage, String bundleFilenameArg) {
updateBundleLocation(Path.of(bundleFilenameArg), false);

try {
rootDir = Files.createTempDirectory(bundleTempDirPrefix);
rootDir = Files.createTempDirectory(BUNDLE_TEMP_DIR_PREFIX);
bundleProperties = new BundleProperties();

outputDir = rootDir.resolve("output");
String originalOutputDirName = outputDir.getFileName().toString() + originalDirExtension;
String originalOutputDirName = outputDir.getFileName().toString() + ORIGINAL_DIR_EXTENSION;

Path bundleFilePath = bundlePath.resolve(bundleName + BUNDLE_FILE_EXTENSION);
try (JarFile archive = new JarFile(bundleFilePath.toFile())) {
Expand Down Expand Up @@ -497,14 +497,14 @@ void complete() {
Path externalOutputDir = bundlePath.resolve(bundleName + "." + outputDir.getFileName());
copyFiles(outputDir, externalOutputDir, true);
outputNewline.run();
nativeImage.showMessage(bundleInfoMessagePrefix + "Bundle build output written to " + externalOutputDir);
nativeImage.showMessage(BUNDLE_INFO_MESSAGE_PREFIX + "Bundle build output written to " + externalOutputDir);
}

try {
if (writeBundle) {
Path bundleFilePath = writeBundle();
outputNewline.run();
nativeImage.showMessage(bundleInfoMessagePrefix + "Bundle written to " + bundleFilePath);
nativeImage.showMessage(BUNDLE_INFO_MESSAGE_PREFIX + "Bundle written to " + bundleFilePath);
}
} finally {
nativeImage.showNewline();
Expand Down Expand Up @@ -550,7 +550,7 @@ void updateBundleLocation(Path bundleFile, boolean redefine) {
}

private Path writeBundle() {
String originalOutputDirName = outputDir.getFileName().toString() + originalDirExtension;
String originalOutputDirName = outputDir.getFileName().toString() + ORIGINAL_DIR_EXTENSION;
Path originalOutputDir = rootDir.resolve(originalOutputDirName);
if (Files.exists(originalOutputDir)) {
nativeImage.deleteAllFiles(originalOutputDir);
Expand Down Expand Up @@ -589,10 +589,10 @@ private Path writeBundle() {
if (buildArg.startsWith(nativeImage.oHPath)) {
continue;
}
if (buildArg.equals(CmdLineOptionHandler.verboseOption)) {
if (buildArg.equals(CmdLineOptionHandler.VERBOSE_OPTION)) {
continue;
}
if (buildArg.equals(CmdLineOptionHandler.dryRunOption)) {
if (buildArg.equals(CmdLineOptionHandler.DRY_RUN_OPTION)) {
continue;
}
if (buildArg.startsWith("-Dllvm.bin.dir=")) {
Expand Down Expand Up @@ -737,11 +737,11 @@ private void loadAndVerify() {
fileVersionKey = PROPERTY_KEY_BUNDLE_FILE_VERSION_MINOR;
int minor = Integer.parseInt(properties.getOrDefault(fileVersionKey, "-1"));
String message = String.format("The given bundle file %s was created with newer bundle-file-format version %d.%d" +
" (current %d.%d). Update to the latest version of native-image.", bundleFileName, major, minor, bundleFileFormatVersionMajor, bundleFileFormatVersionMinor);
if (major > bundleFileFormatVersionMajor) {
" (current %d.%d). Update to the latest version of native-image.", bundleFileName, major, minor, BUNDLE_FILE_FORMAT_VERSION_MAJOR, BUNDLE_FILE_FORMAT_VERSION_MINOR);
if (major > BUNDLE_FILE_FORMAT_VERSION_MAJOR) {
throw NativeImage.showError(message);
} else if (major == bundleFileFormatVersionMajor) {
if (minor > bundleFileFormatVersionMinor) {
} else if (major == BUNDLE_FILE_FORMAT_VERSION_MAJOR) {
if (minor > BUNDLE_FILE_FORMAT_VERSION_MINOR) {
NativeImage.showWarning(message);
}
}
Expand All @@ -761,14 +761,14 @@ private void loadAndVerify() {
localDateStr = "unknown time";
}
nativeImage.showNewline();
nativeImage.showMessage(String.format("%sLoaded Bundle from %s", bundleInfoMessagePrefix, bundleFileName));
nativeImage.showMessage(String.format("%sBundle created at '%s'", bundleInfoMessagePrefix, localDateStr));
nativeImage.showMessage(String.format("%sUsing version: '%s'%s on platform: '%s'%s", bundleInfoMessagePrefix, bundleVersion, currentVersion, bundlePlatform, currentPlatform));
nativeImage.showMessage(String.format("%sLoaded Bundle from %s", BUNDLE_INFO_MESSAGE_PREFIX, bundleFileName));
nativeImage.showMessage(String.format("%sBundle created at '%s'", BUNDLE_INFO_MESSAGE_PREFIX, localDateStr));
nativeImage.showMessage(String.format("%sUsing version: '%s'%s on platform: '%s'%s", BUNDLE_INFO_MESSAGE_PREFIX, bundleVersion, currentVersion, bundlePlatform, currentPlatform));
}

private void write() {
properties.put(PROPERTY_KEY_BUNDLE_FILE_VERSION_MAJOR, String.valueOf(bundleFileFormatVersionMajor));
properties.put(PROPERTY_KEY_BUNDLE_FILE_VERSION_MINOR, String.valueOf(bundleFileFormatVersionMinor));
properties.put(PROPERTY_KEY_BUNDLE_FILE_VERSION_MAJOR, String.valueOf(BUNDLE_FILE_FORMAT_VERSION_MAJOR));
properties.put(PROPERTY_KEY_BUNDLE_FILE_VERSION_MINOR, String.valueOf(BUNDLE_FILE_FORMAT_VERSION_MINOR));
properties.put(PROPERTY_KEY_BUNDLE_FILE_CREATION_TIMESTAMP, ZonedDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME));
boolean imageBuilt = !nativeImage.isDryRun();
properties.put(PROPERTY_KEY_IMAGE_BUILT, String.valueOf(imageBuilt));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@

class CmdLineOptionHandler extends NativeImage.OptionHandler<NativeImage> {

private static final String helpText = NativeImage.getResource("/Help.txt");
private static final String helpExtraText = NativeImage.getResource("/HelpExtra.txt");
private static final String HELP_TEXT = NativeImage.getResource("/Help.txt");
private static final String HELP_EXTRA_TEXT = NativeImage.getResource("/HelpExtra.txt");

static final String verboseOption = "--verbose";
static final String dryRunOption = "--dry-run";
static final String debugAttachOption = "--debug-attach";
static final String VERBOSE_OPTION = "--verbose";
static final String DRY_RUN_OPTION = "--dry-run";
static final String DEBUG_ATTACH_OPTION = "--debug-attach";
/* Defunct legacy options that we have to accept to maintain backward compatibility */
private static final String verboseServerOption = "--verbose-server";
private static final String serverOptionPrefix = "--server-";
private static final String VERBOSE_SERVER_OPTION = "--verbose-server";
private static final String SERVER_OPTION_PREFIX = "--server-";

private static final String javaRuntimeVersion = System.getProperty("java.runtime.version");
private static final String JAVA_RUNTIME_VERSION = System.getProperty("java.runtime.version");

boolean useDebugAttach = false;

Expand All @@ -73,7 +73,7 @@ private boolean consume(ArgumentQueue args, String headArg) {
case "--help":
args.poll();
singleArgumentCheck(args, headArg);
nativeImage.showMessage(helpText);
nativeImage.showMessage(HELP_TEXT);
nativeImage.showNewline();
nativeImage.apiOptionHandler.printOptions(nativeImage::showMessage, false);
nativeImage.showNewline();
Expand All @@ -85,14 +85,14 @@ private boolean consume(ArgumentQueue args, String headArg) {
args.poll();
singleArgumentCheck(args, headArg);
String message = NativeImage.getNativeImageVersion();
message += " (Java Version " + javaRuntimeVersion + ")";
message += " (Java Version " + JAVA_RUNTIME_VERSION + ")";
nativeImage.showMessage(message);
System.exit(ExitStatus.OK.getValue());
return true;
case "--help-extra":
args.poll();
singleArgumentCheck(args, headArg);
nativeImage.showMessage(helpExtraText);
nativeImage.showMessage(HELP_EXTRA_TEXT);
nativeImage.apiOptionHandler.printOptions(nativeImage::showMessage, true);
nativeImage.showNewline();
nativeImage.optionRegistry.showOptions(OptionUtils.MacroOptionKind.Macro, true, nativeImage::showMessage);
Expand Down Expand Up @@ -121,11 +121,11 @@ private boolean consume(ArgumentQueue args, String headArg) {
}
nativeImage.addExcludeConfig(Pattern.compile(excludeJar), Pattern.compile(excludeConfig));
return true;
case verboseOption:
case VERBOSE_OPTION:
args.poll();
nativeImage.addVerbose();
return true;
case dryRunOption:
case DRY_RUN_OPTION:
args.poll();
nativeImage.setDryRun(true);
return true;
Expand All @@ -146,7 +146,7 @@ private boolean consume(ArgumentQueue args, String headArg) {
args.poll();
BundleSupport.allowBundleSupport = true;
return true;
case verboseServerOption:
case VERBOSE_SERVER_OPTION:
args.poll();
NativeImage.showWarning("Ignoring server-mode native-image argument " + headArg + ".");
return true;
Expand All @@ -157,13 +157,13 @@ private boolean consume(ArgumentQueue args, String headArg) {
return true;
}

if (headArg.startsWith(debugAttachOption)) {
if (headArg.startsWith(DEBUG_ATTACH_OPTION)) {
if (useDebugAttach) {
throw NativeImage.showError("The " + debugAttachOption + " option can only be used once.");
throw NativeImage.showError("The " + DEBUG_ATTACH_OPTION + " option can only be used once.");
}
useDebugAttach = true;
String debugAttachArg = args.poll();
String addressSuffix = debugAttachArg.substring(debugAttachOption.length());
String addressSuffix = debugAttachArg.substring(DEBUG_ATTACH_OPTION.length());
String address = addressSuffix.isEmpty() ? "8000" : addressSuffix.substring(1);
/* Using agentlib to allow interoperability with other agents */
nativeImage.addImageBuilderJavaArgs("-agentlib:jdwp=transport=dt_socket,server=y,address=" + address + ",suspend=y");
Expand All @@ -172,10 +172,10 @@ private boolean consume(ArgumentQueue args, String headArg) {
return true;
}

if (headArg.startsWith(serverOptionPrefix)) {
if (headArg.startsWith(SERVER_OPTION_PREFIX)) {
args.poll();
NativeImage.showWarning("Ignoring server-mode native-image argument " + headArg + ".");
String serverOptionCommand = headArg.substring(serverOptionPrefix.length());
String serverOptionCommand = headArg.substring(SERVER_OPTION_PREFIX.length());
if (!serverOptionCommand.startsWith("session=")) {
/*
* All but the --server-session=... option used to exit(0). We want to simulate that
Expand All @@ -198,7 +198,7 @@ private static void singleArgumentCheck(ArgumentQueue args, String arg) {
@Override
void addFallbackBuildArgs(List<String> buildArgs) {
if (nativeImage.isVerbose()) {
buildArgs.add(verboseOption);
buildArgs.add(VERBOSE_OPTION);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ private List<String> getAgentArguments() {

if (!agentOptions.isEmpty()) {
if (useDebugAttach()) {
throw NativeImage.showError(CmdLineOptionHandler.debugAttachOption + " cannot be used with class initialization/object instantiation tracing (" + oHTraceClassInitialization +
throw NativeImage.showError(CmdLineOptionHandler.DEBUG_ATTACH_OPTION + " cannot be used with class initialization/object instantiation tracing (" + oHTraceClassInitialization +
"/ + " + oHTraceObjectInstantiation + ").");
}
args.add("-agentlib:native-image-diagnostics-agent=" + agentOptions);
Expand Down

0 comments on commit 4fbec8c

Please sign in to comment.