Skip to content

Commit

Permalink
Don't try to avoid other std output when help is generating JSON, the…
Browse files Browse the repository at this point in the history
… plugin will now parse the JSON out regardless
  • Loading branch information
gbevin committed Jul 20, 2024
1 parent 3ec2cc6 commit 0e4e171
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 30 deletions.
Binary file modified lib/bld/bld-wrapper.jar
Binary file not shown.
37 changes: 7 additions & 30 deletions src/main/java/rife/bld/wrapper/Wrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,11 @@
public class Wrapper {
private enum LaunchMode {
Cli,
Build,
Json
Build
}

public static final String BUILD_ARGUMENT = "--build";
public static final String JSON_ARGUMENT = "--json";
public static final String OFFLINE_ARGUMENT = "--offline";
public static final String HELP_COMMAND = "help";

public static final String WRAPPER_PREFIX = "bld-wrapper";
public static final String WRAPPER_PROPERTIES = WRAPPER_PREFIX + ".properties";
Expand Down Expand Up @@ -399,18 +396,6 @@ private int installAndLaunch(List<String> arguments) {
OFFLINE_ARGUMENT.equals(arguments.get(1))) {
offline_ = true;
}

var help_index = arguments.indexOf(HELP_COMMAND);
if (help_index != -1) {
try {
if (arguments.get(help_index + 1).equals(JSON_ARGUMENT) ||
arguments.get(help_index + 2).equals(JSON_ARGUMENT)) {
launchMode_ = LaunchMode.Json;
}
} catch (IndexOutOfBoundsException e) {
// no-op, there are no additional arguments, so definitely no json option
}
}
}

try {
Expand Down Expand Up @@ -520,10 +505,8 @@ private File installDistribution()
var is_snapshot = isSnapshot(version);
var is_local = false;
if (offline_) {
if (launchMode_ != LaunchMode.Json) {
System.out.println("Offline mode: no artifacts will be checked nor downloaded");
System.out.flush();
}
System.out.println("Offline mode: no artifacts will be checked nor downloaded");
System.out.flush();
}
else {
if (is_snapshot) {
Expand Down Expand Up @@ -600,19 +583,15 @@ private File installDistribution()
private void downloadDistribution(File file, String downloadUrl)
throws IOException {
try {
if (launchMode_ != LaunchMode.Json) {
System.out.print("Downloading: " + downloadUrl + " ... ");
System.out.flush();
}
System.out.print("Downloading: " + downloadUrl + " ... ");
System.out.flush();
var url = new URL(downloadUrl);
var readableByteChannel = Channels.newChannel(url.openStream());
try (var fileOutputStream = new FileOutputStream(file)) {
var fileChannel = fileOutputStream.getChannel();
fileChannel.transferFrom(readableByteChannel, 0, Long.MAX_VALUE);

if (launchMode_ != LaunchMode.Json) {
System.out.print("done");
}
System.out.print("done");
}
} catch (FileNotFoundException e) {
System.err.println("not found");
Expand All @@ -624,9 +603,7 @@ private void downloadDistribution(File file, String downloadUrl)
Files.deleteIfExists(file.toPath());
throw e;
} finally {
if (launchMode_ != LaunchMode.Json) {
System.out.println();
}
System.out.println();
}
}

Expand Down

0 comments on commit 0e4e171

Please sign in to comment.