mirror of
https://github.com/ethauvin/bld.git
synced 2025-04-25 16:27:11 -07:00
Added support for generating bld output as JSON so that it can be consumed by other tools.
Added wrapper support for local Maven repository bld snapshots. Updated version to 2.0.0-SNAPSHOT.
This commit is contained in:
parent
177a2e39af
commit
793efb27ce
13 changed files with 295 additions and 90 deletions
|
@ -9,11 +9,12 @@ import rife.bld.help.HelpHelp;
|
||||||
import rife.bld.operations.HelpOperation;
|
import rife.bld.operations.HelpOperation;
|
||||||
import rife.bld.operations.exceptions.ExitStatusException;
|
import rife.bld.operations.exceptions.ExitStatusException;
|
||||||
import rife.ioc.HierarchicalProperties;
|
import rife.ioc.HierarchicalProperties;
|
||||||
|
import rife.template.Template;
|
||||||
|
import rife.template.TemplateFactory;
|
||||||
import rife.tools.ExceptionUtils;
|
import rife.tools.ExceptionUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileReader;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
@ -38,6 +39,7 @@ public class BuildExecutor {
|
||||||
private static final String ARG_HELP3 = "-?";
|
private static final String ARG_HELP3 = "-?";
|
||||||
private static final String ARG_STACKTRACE1 = "--stacktrace";
|
private static final String ARG_STACKTRACE1 = "--stacktrace";
|
||||||
private static final String ARG_STACKTRACE2 = "-s";
|
private static final String ARG_STACKTRACE2 = "-s";
|
||||||
|
private static final String ARG_JSON = "--json";
|
||||||
|
|
||||||
private final HierarchicalProperties properties_;
|
private final HierarchicalProperties properties_;
|
||||||
private List<String> arguments_ = Collections.emptyList();
|
private List<String> arguments_ = Collections.emptyList();
|
||||||
|
@ -46,6 +48,7 @@ public class BuildExecutor {
|
||||||
private final AtomicReference<String> currentCommandName_ = new AtomicReference<>();
|
private final AtomicReference<String> currentCommandName_ = new AtomicReference<>();
|
||||||
private final AtomicReference<CommandDefinition> currentCommandDefinition_ = new AtomicReference<>();
|
private final AtomicReference<CommandDefinition> currentCommandDefinition_ = new AtomicReference<>();
|
||||||
private int exitStatus_ = 0;
|
private int exitStatus_ = 0;
|
||||||
|
private boolean outputJson_ = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the full Java stacktrace when exceptions occur, as opposed
|
* Show the full Java stacktrace when exceptions occur, as opposed
|
||||||
|
@ -124,6 +127,17 @@ public class BuildExecutor {
|
||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether output should be in the JSON format.
|
||||||
|
*
|
||||||
|
* @return {@code true} if JSON output is enabled;
|
||||||
|
* or {@code false} otherwise
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
public boolean outputJson() {
|
||||||
|
return outputJson_;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the properties uses by this conversation.
|
* Returns the properties uses by this conversation.
|
||||||
*
|
*
|
||||||
|
@ -213,9 +227,13 @@ public class BuildExecutor {
|
||||||
public int execute(String[] arguments) {
|
public int execute(String[] arguments) {
|
||||||
arguments_ = new ArrayList<>(Arrays.asList(arguments));
|
arguments_ = new ArrayList<>(Arrays.asList(arguments));
|
||||||
|
|
||||||
|
if (!arguments_.isEmpty() && arguments_.get(0).equals(ARG_JSON)) {
|
||||||
|
outputJson_ = true;
|
||||||
|
arguments_.remove(0);
|
||||||
|
}
|
||||||
var show_help = false;
|
var show_help = false;
|
||||||
show_help |= arguments_.removeAll(List.of(ARG_HELP1, ARG_HELP2, ARG_HELP3));
|
show_help |= arguments_.removeAll(List.of(ARG_HELP1, ARG_HELP2, ARG_HELP3));
|
||||||
showStacktrace |= arguments_.removeAll(List.of(ARG_STACKTRACE1, ARG_STACKTRACE2));
|
showStacktrace = arguments_.removeAll(List.of(ARG_STACKTRACE1, ARG_STACKTRACE2));
|
||||||
show_help |= arguments_.isEmpty();
|
show_help |= arguments_.isEmpty();
|
||||||
|
|
||||||
if (show_help) {
|
if (show_help) {
|
||||||
|
@ -223,41 +241,105 @@ public class BuildExecutor {
|
||||||
return exitStatus_;
|
return exitStatus_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var first_command = true;
|
||||||
|
var json_template = TemplateFactory.JSON.get("bld.executor_execute");
|
||||||
|
var exception_caught = false;
|
||||||
while (!arguments_.isEmpty()) {
|
while (!arguments_.isEmpty()) {
|
||||||
var command = arguments_.remove(0);
|
var command = arguments_.remove(0);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!executeCommand(command)) {
|
var orig_out = System.out;
|
||||||
break;
|
var orig_err = System.err;
|
||||||
|
var out = new ByteArrayOutputStream();
|
||||||
|
var err = new ByteArrayOutputStream();
|
||||||
|
if (outputJson()) {
|
||||||
|
System.setOut(new PrintStream(out, true, StandardCharsets.UTF_8));
|
||||||
|
System.setErr(new PrintStream(err, true, StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
|
||||||
exitStatus(1);
|
|
||||||
|
|
||||||
System.err.println();
|
try {
|
||||||
|
if (!executeCommand(command)) {
|
||||||
if (showStacktrace) {
|
break;
|
||||||
System.err.println(ExceptionUtils.getExceptionStackTrace(e));
|
}
|
||||||
} else {
|
}
|
||||||
boolean first = true;
|
finally {
|
||||||
var e2 = e;
|
if (outputJson()) {
|
||||||
while (e2 != null) {
|
if (first_command) {
|
||||||
if (e2.getMessage() != null) {
|
json_template.blankValue("separator");
|
||||||
if (!first) {
|
|
||||||
System.err.print("> ");
|
|
||||||
}
|
|
||||||
System.err.println(e2.getMessage());
|
|
||||||
first = false;
|
|
||||||
}
|
}
|
||||||
e2 = e2.getCause();
|
else {
|
||||||
|
json_template.setValue("separator", ", ");
|
||||||
|
}
|
||||||
|
json_template.setValueEncoded("command", command);
|
||||||
|
json_template.setValueEncoded("out", out.toString(StandardCharsets.UTF_8));
|
||||||
|
json_template.setValueEncoded("err", err.toString(StandardCharsets.UTF_8));
|
||||||
|
json_template.appendBlock("commands", "command");
|
||||||
|
|
||||||
|
System.setOut(orig_out);
|
||||||
|
System.setErr(orig_err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (first) {
|
first_command = false;
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
exception_caught = true;
|
||||||
|
|
||||||
|
exitStatus(1);
|
||||||
|
|
||||||
|
if (outputJson()) {
|
||||||
|
var t = TemplateFactory.JSON.get("bld.executor_error");
|
||||||
|
if (showStacktrace) {
|
||||||
|
t.setValueEncoded("error-message", ExceptionUtils.getExceptionStackTrace(e));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
boolean first_exception = true;
|
||||||
|
var e2 = e;
|
||||||
|
while (e2 != null) {
|
||||||
|
if (e2.getMessage() != null) {
|
||||||
|
t.setValueEncoded("error-message", e2.getMessage());
|
||||||
|
first_exception = false;
|
||||||
|
}
|
||||||
|
e2 = e2.getCause();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (first_exception) {
|
||||||
|
t.setValueEncoded("error-message", ExceptionUtils.getExceptionStackTrace(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println(t.getContent());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.err.println();
|
||||||
|
|
||||||
|
if (showStacktrace) {
|
||||||
System.err.println(ExceptionUtils.getExceptionStackTrace(e));
|
System.err.println(ExceptionUtils.getExceptionStackTrace(e));
|
||||||
|
} else {
|
||||||
|
boolean first_exception = true;
|
||||||
|
var e2 = e;
|
||||||
|
while (e2 != null) {
|
||||||
|
if (e2.getMessage() != null) {
|
||||||
|
if (!first_exception) {
|
||||||
|
System.err.print("> ");
|
||||||
|
}
|
||||||
|
System.err.println(e2.getMessage());
|
||||||
|
first_exception = false;
|
||||||
|
}
|
||||||
|
e2 = e2.getCause();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (first_exception) {
|
||||||
|
System.err.println(ExceptionUtils.getExceptionStackTrace(e));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!exception_caught) {
|
||||||
|
if (outputJson()) {
|
||||||
|
System.out.println(json_template.getContent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return exitStatus_;
|
return exitStatus_;
|
||||||
}
|
}
|
||||||
|
@ -441,7 +523,9 @@ public class BuildExecutor {
|
||||||
// only proceed if exactly one match was found
|
// only proceed if exactly one match was found
|
||||||
if (matches.size() == 1) {
|
if (matches.size() == 1) {
|
||||||
matched_command = matches.get(0);
|
matched_command = matches.get(0);
|
||||||
System.out.println("Executing matched command: " + matched_command);
|
if (!outputJson()) {
|
||||||
|
System.out.println("Executing matched command: " + matched_command);
|
||||||
|
}
|
||||||
definition = buildCommands().get(matched_command);
|
definition = buildCommands().get(matched_command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -460,9 +544,17 @@ public class BuildExecutor {
|
||||||
currentCommandName_.set(null);
|
currentCommandName_.set(null);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
new HelpOperation(this, arguments()).executePrintOverviewHelp();
|
var message = "Unknown command '" + command + "'";
|
||||||
System.err.println();
|
if (outputJson()) {
|
||||||
System.err.println("ERROR: unknown command '" + command + "'");
|
var t = TemplateFactory.JSON.get("bld.executor_error");
|
||||||
|
t.setValueEncoded("error-message", message);
|
||||||
|
System.out.println(t.getContent());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
new HelpOperation(this, arguments()).executePrintOverviewHelp();
|
||||||
|
System.err.println();
|
||||||
|
System.err.println("ERROR: " + message);
|
||||||
|
}
|
||||||
exitStatus(1);
|
exitStatus(1);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,6 +127,7 @@ public class DownloadOperation extends AbstractOperation<DownloadOperation> {
|
||||||
* Configures a compile operation from a {@link BaseProject}.
|
* Configures a compile operation from a {@link BaseProject}.
|
||||||
*
|
*
|
||||||
* @param project the project to configure the compile operation from
|
* @param project the project to configure the compile operation from
|
||||||
|
* @return this operation instance
|
||||||
* @since 1.5
|
* @since 1.5
|
||||||
*/
|
*/
|
||||||
public DownloadOperation fromProject(BaseProject project) {
|
public DownloadOperation fromProject(BaseProject project) {
|
||||||
|
|
|
@ -6,6 +6,8 @@ package rife.bld.operations;
|
||||||
|
|
||||||
import rife.bld.BldVersion;
|
import rife.bld.BldVersion;
|
||||||
import rife.bld.BuildExecutor;
|
import rife.bld.BuildExecutor;
|
||||||
|
import rife.template.TemplateFactory;
|
||||||
|
import rife.tools.ExceptionUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -44,26 +46,37 @@ public class HelpOperation {
|
||||||
topic = arguments_.remove(0);
|
topic = arguments_.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.err.println("Welcome to bld " + BldVersion.getVersion() + ".");
|
if (!executor_.outputJson()) {
|
||||||
System.err.println();
|
System.err.println("Welcome to bld " + BldVersion.getVersion() + ".");
|
||||||
|
System.err.println();
|
||||||
|
}
|
||||||
|
|
||||||
boolean print_full_help = true;
|
boolean print_full_help = true;
|
||||||
|
Exception exception = null;
|
||||||
try {
|
try {
|
||||||
var commands = executor_.buildCommands();
|
var commands = executor_.buildCommands();
|
||||||
if (commands.containsKey(topic)) {
|
if (commands.containsKey(topic)) {
|
||||||
var command = commands.get(topic);
|
var command = commands.get(topic);
|
||||||
var help = command.getHelp().getDescription(topic);
|
var help = command.getHelp().getDescription(topic);
|
||||||
if (!help.isEmpty()) {
|
if (!help.isEmpty()) {
|
||||||
System.err.println(help);
|
if (executor_.outputJson()) {
|
||||||
|
var t = TemplateFactory.JSON.get("bld.help_description");
|
||||||
|
t.setValueEncoded("command", topic);
|
||||||
|
t.setValueEncoded("description", help);
|
||||||
|
System.out.print(t.getContent());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.err.println(help);
|
||||||
|
}
|
||||||
print_full_help = false;
|
print_full_help = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
exception = e;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (print_full_help) {
|
if (print_full_help) {
|
||||||
executePrintOverviewHelp();
|
executePrintOverviewHelp(exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,32 +87,67 @@ public class HelpOperation {
|
||||||
* @since 1.5
|
* @since 1.5
|
||||||
*/
|
*/
|
||||||
public void executePrintOverviewHelp() {
|
public void executePrintOverviewHelp() {
|
||||||
|
executePrintOverviewHelp(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void executePrintOverviewHelp(Exception exception) {
|
||||||
var commands = executor_.buildCommands();
|
var commands = executor_.buildCommands();
|
||||||
|
|
||||||
System.err.println("""
|
if (executor_.outputJson()) {
|
||||||
The bld CLI provides its features through a series of commands that
|
var t = TemplateFactory.JSON.get("bld.help_commands");
|
||||||
perform specific tasks. The help command provides more information about
|
|
||||||
the other commands.
|
|
||||||
|
|
||||||
Usage: help [command]
|
if (exception != null) {
|
||||||
|
t.setValueEncoded("error-message", ExceptionUtils.getExceptionStackTrace(exception));
|
||||||
|
}
|
||||||
|
|
||||||
The following commands are supported.
|
boolean first = true;
|
||||||
""");
|
for (var command : commands.entrySet()) {
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
t.blankValue("separator");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
t.setValue("separator", ", ");
|
||||||
|
}
|
||||||
|
t.setValueEncoded("command", command.getKey());
|
||||||
|
var build_help = command.getValue().getHelp();
|
||||||
|
t.setValueEncoded("summary", build_help.getSummary());
|
||||||
|
t.appendBlock("commands", "command");
|
||||||
|
}
|
||||||
|
System.out.print(t.getContent());
|
||||||
|
|
||||||
var command_length = commands.keySet().stream().max(comparingInt(String::length)).get().length() + 2;
|
|
||||||
for (var command : commands.entrySet()) {
|
|
||||||
System.err.print(" ");
|
|
||||||
System.err.printf("%-" + command_length + "s", command.getKey());
|
|
||||||
var build_help = command.getValue().getHelp();
|
|
||||||
System.err.print(build_help.getSummary());
|
|
||||||
System.err.println();
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
if (exception != null) {
|
||||||
|
exception.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
System.err.println("""
|
System.err.println("""
|
||||||
|
The bld CLI provides its features through a series of commands that
|
||||||
|
perform specific tasks. The help command provides more information about
|
||||||
|
the other commands.
|
||||||
|
|
||||||
-?, -h, --help Shows this help message
|
Usage: help [command]
|
||||||
-D<name>=<value> Set a JVM system property
|
|
||||||
-s, --stacktrace Print out the stacktrace for exceptions
|
The following commands are supported.
|
||||||
""");
|
""");
|
||||||
|
|
||||||
|
var command_length = commands.keySet().stream().max(comparingInt(String::length)).get().length() + 2;
|
||||||
|
for (var command : commands.entrySet()) {
|
||||||
|
System.err.print(" ");
|
||||||
|
System.err.printf("%-" + command_length + "s", command.getKey());
|
||||||
|
var build_help = command.getValue().getHelp();
|
||||||
|
System.err.print(build_help.getSummary());
|
||||||
|
System.err.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.err.println("""
|
||||||
|
|
||||||
|
-?, -h, --help Shows this help message
|
||||||
|
-D<name>=<value> Set a JVM system property
|
||||||
|
-s, --stacktrace Print out the stacktrace for exceptions
|
||||||
|
--json Output in JSON format (only as first argument)
|
||||||
|
""");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -604,7 +604,7 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
|
||||||
*
|
*
|
||||||
* @param properties the publication properties
|
* @param properties the publication properties
|
||||||
* @return this operation instance
|
* @return this operation instance
|
||||||
* @since 1.9.2
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public PublishOperation properties(PublishProperties properties) {
|
public PublishOperation properties(PublishProperties properties) {
|
||||||
properties_ = properties;
|
properties_ = properties;
|
||||||
|
@ -691,7 +691,7 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
|
||||||
* This is a modifiable structure that can be retrieved and changed.
|
* This is a modifiable structure that can be retrieved and changed.
|
||||||
*
|
*
|
||||||
* @return the publication properties
|
* @return the publication properties
|
||||||
* @since 1.9.2
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public PublishProperties properties() {
|
public PublishProperties properties() {
|
||||||
return properties_;
|
return properties_;
|
||||||
|
|
|
@ -20,14 +20,6 @@ public class VersionOperation extends AbstractOperation<VersionOperation> {
|
||||||
*/
|
*/
|
||||||
public void execute() {
|
public void execute() {
|
||||||
if (!silent()) {
|
if (!silent()) {
|
||||||
System.out.println("""
|
|
||||||
_ _ _
|
|
||||||
| | | | | |
|
|
||||||
| |__ | | __| |
|
|
||||||
| '_ \\| |/ _` |
|
|
||||||
| |_) | | (_| |
|
|
||||||
|_.__/|_|\\__,_|
|
|
||||||
""");
|
|
||||||
System.out.println("bld " + BldVersion.getVersion());
|
System.out.println("bld " + BldVersion.getVersion());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ public class PomBuilder {
|
||||||
*
|
*
|
||||||
* @param properties the properties to use
|
* @param properties the properties to use
|
||||||
* @return this {@code PomBuilder} instance
|
* @return this {@code PomBuilder} instance
|
||||||
* @since 1.9.2
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public PomBuilder properties(PublishProperties properties) {
|
public PomBuilder properties(PublishProperties properties) {
|
||||||
properties_ = properties;
|
properties_ = properties;
|
||||||
|
@ -63,7 +63,7 @@ public class PomBuilder {
|
||||||
* Retrieves the properties to build the POM with.
|
* Retrieves the properties to build the POM with.
|
||||||
*
|
*
|
||||||
* @return the properties to use
|
* @return the properties to use
|
||||||
* @since 1.9.2
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public PublishProperties properties() {
|
public PublishProperties properties() {
|
||||||
return properties_;
|
return properties_;
|
||||||
|
|
|
@ -10,7 +10,7 @@ import java.util.*;
|
||||||
* Provides the properties information for publication.
|
* Provides the properties information for publication.
|
||||||
*
|
*
|
||||||
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
|
* @author Geert Bevin (gbevin[remove] at uwyn dot com)
|
||||||
* @since 1.9.2
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public class PublishProperties extends LinkedHashMap<String, String> {
|
public class PublishProperties extends LinkedHashMap<String, String> {
|
||||||
private static final String MAVEN_COMPILER_SOURCE = "maven.compiler.source";
|
private static final String MAVEN_COMPILER_SOURCE = "maven.compiler.source";
|
||||||
|
@ -21,7 +21,7 @@ public class PublishProperties extends LinkedHashMap<String, String> {
|
||||||
*
|
*
|
||||||
* @param value the value to be set for the 'maven.compiler.source' property
|
* @param value the value to be set for the 'maven.compiler.source' property
|
||||||
* @return this {@code PomProperties} instance
|
* @return this {@code PomProperties} instance
|
||||||
* @since 1.9.2
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public PublishProperties mavenCompilerSource(Integer value) {
|
public PublishProperties mavenCompilerSource(Integer value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
@ -37,7 +37,7 @@ public class PublishProperties extends LinkedHashMap<String, String> {
|
||||||
* Retrieves the value of the 'maven.compiler.source' property.
|
* Retrieves the value of the 'maven.compiler.source' property.
|
||||||
*
|
*
|
||||||
* @return the value of the 'maven.compiler.source' property
|
* @return the value of the 'maven.compiler.source' property
|
||||||
* @since 1.9.2
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public Integer mavenCompilerSource() {
|
public Integer mavenCompilerSource() {
|
||||||
var value = get(MAVEN_COMPILER_SOURCE);
|
var value = get(MAVEN_COMPILER_SOURCE);
|
||||||
|
@ -52,7 +52,7 @@ public class PublishProperties extends LinkedHashMap<String, String> {
|
||||||
*
|
*
|
||||||
* @param value the value to be set for the 'maven.compiler.target' property
|
* @param value the value to be set for the 'maven.compiler.target' property
|
||||||
* @return this {@code PomProperties} instance
|
* @return this {@code PomProperties} instance
|
||||||
* @since 1.9.2
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public PublishProperties mavenCompilerTarget(Integer value) {
|
public PublishProperties mavenCompilerTarget(Integer value) {
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
|
@ -68,7 +68,7 @@ public class PublishProperties extends LinkedHashMap<String, String> {
|
||||||
* Retrieves the value of the 'maven.compiler.target' property.
|
* Retrieves the value of the 'maven.compiler.target' property.
|
||||||
*
|
*
|
||||||
* @return the value of the 'maven.compiler.target' property
|
* @return the value of the 'maven.compiler.target' property
|
||||||
* @since 1.9.2
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public Integer mavenCompilerTarget() {
|
public Integer mavenCompilerTarget() {
|
||||||
var value = get(MAVEN_COMPILER_TARGET);
|
var value = get(MAVEN_COMPILER_TARGET);
|
||||||
|
|
|
@ -33,7 +33,14 @@ import static rife.tools.FileUtils.JAVA_FILE_PATTERN;
|
||||||
* @since 1.5
|
* @since 1.5
|
||||||
*/
|
*/
|
||||||
public class Wrapper {
|
public class Wrapper {
|
||||||
|
private enum LaunchMode {
|
||||||
|
Cli,
|
||||||
|
Build,
|
||||||
|
Json
|
||||||
|
}
|
||||||
|
|
||||||
public static final String BUILD_ARGUMENT = "--build";
|
public static final String BUILD_ARGUMENT = "--build";
|
||||||
|
public static final String JSON_ARGUMENT = "--json";
|
||||||
|
|
||||||
static final String MAVEN_CENTRAL = "https://repo1.maven.org/maven2/";
|
static final String MAVEN_CENTRAL = "https://repo1.maven.org/maven2/";
|
||||||
static final String SONATYPE_SNAPSHOTS = "https://s01.oss.sonatype.org/content/repositories/snapshots/";
|
static final String SONATYPE_SNAPSHOTS = "https://s01.oss.sonatype.org/content/repositories/snapshots/";
|
||||||
|
@ -59,10 +66,12 @@ public class Wrapper {
|
||||||
static final String PROPERTY_JAVA_OPTIONS = "bld.javaOptions";
|
static final String PROPERTY_JAVA_OPTIONS = "bld.javaOptions";
|
||||||
static final File BLD_USER_DIR = new File(System.getProperty("user.home"), ".bld");
|
static final File BLD_USER_DIR = new File(System.getProperty("user.home"), ".bld");
|
||||||
static final File DISTRIBUTIONS_DIR = new File(BLD_USER_DIR, "dist");
|
static final File DISTRIBUTIONS_DIR = new File(BLD_USER_DIR, "dist");
|
||||||
|
static final Pattern META_DATA_LOCAL_COPY = Pattern.compile("<localCopy>\\s*true\\s*</localCopy>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
|
||||||
static final Pattern META_DATA_SNAPSHOT_VERSION = Pattern.compile("<snapshotVersion>.*?<value>([^<]+)</value>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
|
static final Pattern META_DATA_SNAPSHOT_VERSION = Pattern.compile("<snapshotVersion>.*?<value>([^<]+)</value>", Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
|
||||||
static final Pattern OPTIONS_PATTERN = Pattern.compile("\"[^\"]+\"|\\S+");
|
static final Pattern OPTIONS_PATTERN = Pattern.compile("\"[^\"]+\"|\\S+");
|
||||||
|
|
||||||
private File currentDir_ = new File(System.getProperty("user.dir"));
|
private File currentDir_ = new File(System.getProperty("user.dir"));
|
||||||
|
private LaunchMode launchMode_ = LaunchMode.Cli;
|
||||||
|
|
||||||
private final Properties wrapperProperties_ = new Properties();
|
private final Properties wrapperProperties_ = new Properties();
|
||||||
private File wrapperPropertiesFile_ = null;
|
private File wrapperPropertiesFile_ = null;
|
||||||
|
@ -198,6 +207,7 @@ public class Wrapper {
|
||||||
|
|
||||||
try (var jar = new JarOutputStream(new FileOutputStream(new File(destinationDirectory, WRAPPER_JAR)), manifest)) {
|
try (var jar = new JarOutputStream(new FileOutputStream(new File(destinationDirectory, WRAPPER_JAR)), manifest)) {
|
||||||
addClassToJar(jar, Wrapper.class);
|
addClassToJar(jar, Wrapper.class);
|
||||||
|
addClassToJar(jar, Wrapper.LaunchMode.class);
|
||||||
addClassToJar(jar, WrapperClassLoader.class);
|
addClassToJar(jar, WrapperClassLoader.class);
|
||||||
addClassToJar(jar, FileUtils.class);
|
addClassToJar(jar, FileUtils.class);
|
||||||
addClassToJar(jar, FileUtilsErrorException.class);
|
addClassToJar(jar, FileUtilsErrorException.class);
|
||||||
|
@ -264,7 +274,17 @@ public class Wrapper {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
currentDir_ = new File(current_file.getParent());
|
currentDir_ = new File(current_file.getParent());
|
||||||
|
|
||||||
|
if (BUILD_ARGUMENT.equals(arguments.get(0))) {
|
||||||
|
launchMode_ = LaunchMode.Build;
|
||||||
|
arguments.remove(0);
|
||||||
|
|
||||||
|
if (arguments.size() >= 2 && JSON_ARGUMENT.equals(arguments.get(1))) {
|
||||||
|
launchMode_ = LaunchMode.Json;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
initWrapperProperties(getVersion());
|
initWrapperProperties(getVersion());
|
||||||
File distribution;
|
File distribution;
|
||||||
|
@ -409,11 +429,27 @@ public class Wrapper {
|
||||||
|
|
||||||
var download_version = version;
|
var download_version = version;
|
||||||
var is_snapshot = isSnapshot(version);
|
var is_snapshot = isSnapshot(version);
|
||||||
|
var is_local = false;
|
||||||
if (is_snapshot) {
|
if (is_snapshot) {
|
||||||
var meta_data = readString(version, new URL(downloadUrl(version, "maven-metadata.xml")));
|
var meta_data = "";
|
||||||
var matcher = META_DATA_SNAPSHOT_VERSION.matcher(meta_data);
|
try {
|
||||||
if (matcher.find()) {
|
meta_data = readString(version, new URL(downloadUrl(version, "maven-metadata.xml")));
|
||||||
download_version = matcher.group(1);
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
try {
|
||||||
|
meta_data = readString(version, new URL(downloadUrl(version, "maven-metadata-local.xml")));
|
||||||
|
}
|
||||||
|
catch (IOException e2) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var local_matcher = META_DATA_LOCAL_COPY.matcher(meta_data);
|
||||||
|
is_local = local_matcher.find();
|
||||||
|
if (!is_local) {
|
||||||
|
var version_matcher = META_DATA_SNAPSHOT_VERSION.matcher(meta_data);
|
||||||
|
if (version_matcher.find()) {
|
||||||
|
download_version = version_matcher.group(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,16 +459,26 @@ public class Wrapper {
|
||||||
// if this is a snapshot and the distribution file exists,
|
// if this is a snapshot and the distribution file exists,
|
||||||
// ensure that it's the latest by comparing hashes
|
// ensure that it's the latest by comparing hashes
|
||||||
if (is_snapshot && distribution_file.exists()) {
|
if (is_snapshot && distribution_file.exists()) {
|
||||||
var download_md5 = readString(version, new URL(downloadUrl(version, bldFileName(download_version)) + ".md5"));
|
boolean delete_distribution_files = is_local;
|
||||||
try {
|
if (!delete_distribution_files) {
|
||||||
var digest = MessageDigest.getInstance("MD5");
|
var download_md5 = readString(version, new URL(downloadUrl(version, bldFileName(download_version)) + ".md5"));
|
||||||
digest.update(FileUtils.readBytes(distribution_file));
|
try {
|
||||||
if (!download_md5.equals(encodeHexLower(digest.digest()))) {
|
var digest = MessageDigest.getInstance("MD5");
|
||||||
distribution_file.delete();
|
digest.update(FileUtils.readBytes(distribution_file));
|
||||||
|
if (!download_md5.equals(encodeHexLower(digest.digest()))) {
|
||||||
|
delete_distribution_files = true;
|
||||||
|
}
|
||||||
|
} catch (NoSuchAlgorithmException ignore) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delete_distribution_files) {
|
||||||
|
distribution_file.delete();
|
||||||
|
if (distribution_sources_file.exists()) {
|
||||||
distribution_sources_file.delete();
|
distribution_sources_file.delete();
|
||||||
}
|
}
|
||||||
} catch (NoSuchAlgorithmException ignore) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// download distribution jars if necessary
|
// download distribution jars if necessary
|
||||||
|
@ -457,15 +503,19 @@ public class Wrapper {
|
||||||
private void downloadDistribution(File file, String downloadUrl)
|
private void downloadDistribution(File file, String downloadUrl)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
try {
|
try {
|
||||||
System.out.print("Downloading: " + downloadUrl + " ... ");
|
if (launchMode_ != LaunchMode.Json) {
|
||||||
System.out.flush();
|
System.out.print("Downloading: " + downloadUrl + " ... ");
|
||||||
|
System.out.flush();
|
||||||
|
}
|
||||||
var url = new URL(downloadUrl);
|
var url = new URL(downloadUrl);
|
||||||
var readableByteChannel = Channels.newChannel(url.openStream());
|
var readableByteChannel = Channels.newChannel(url.openStream());
|
||||||
try (var fileOutputStream = new FileOutputStream(file)) {
|
try (var fileOutputStream = new FileOutputStream(file)) {
|
||||||
var fileChannel = fileOutputStream.getChannel();
|
var fileChannel = fileOutputStream.getChannel();
|
||||||
fileChannel.transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
|
fileChannel.transferFrom(readableByteChannel, 0, Long.MAX_VALUE);
|
||||||
|
|
||||||
System.out.print("done");
|
if (launchMode_ != LaunchMode.Json) {
|
||||||
|
System.out.print("done");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
System.err.println("not found");
|
System.err.println("not found");
|
||||||
|
@ -477,7 +527,9 @@ public class Wrapper {
|
||||||
Files.deleteIfExists(file.toPath());
|
Files.deleteIfExists(file.toPath());
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
System.out.println();
|
if (launchMode_ != LaunchMode.Json) {
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,7 +556,7 @@ public class Wrapper {
|
||||||
|
|
||||||
private int launchMain(File jarFile, List<String> arguments)
|
private int launchMain(File jarFile, List<String> arguments)
|
||||||
throws IOException, InterruptedException, FileUtilsErrorException {
|
throws IOException, InterruptedException, FileUtilsErrorException {
|
||||||
if (arguments.isEmpty() || !BUILD_ARGUMENT.equals(arguments.get(0))) {
|
if (launchMode_ == LaunchMode.Cli) {
|
||||||
return launchMainCli(jarFile, arguments);
|
return launchMainCli(jarFile, arguments);
|
||||||
}
|
}
|
||||||
return launchMainBuild(jarFile, arguments);
|
return launchMainBuild(jarFile, arguments);
|
||||||
|
@ -535,8 +587,6 @@ public class Wrapper {
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
resolveExtensions();
|
resolveExtensions();
|
||||||
|
|
||||||
arguments.remove(0);
|
|
||||||
|
|
||||||
var build_bld_dir = buildBldDirectory();
|
var build_bld_dir = buildBldDirectory();
|
||||||
if (build_bld_dir.exists()) {
|
if (build_bld_dir.exists()) {
|
||||||
FileUtils.deleteDirectory(buildBldDirectory());
|
FileUtils.deleteDirectory(buildBldDirectory());
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
1.9.2-SNAPSHOT
|
2.0.0-SNAPSHOT
|
3
src/main/resources/templates/bld/executor_error.json
Normal file
3
src/main/resources/templates/bld/executor_error.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"error": "{{v error-message/}}"
|
||||||
|
}
|
8
src/main/resources/templates/bld/executor_execute.json
Normal file
8
src/main/resources/templates/bld/executor_execute.json
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"commands": {{{v commands}}{{/v}}{{b command}}{{v separator/}}
|
||||||
|
"{{v command/}}": {
|
||||||
|
"out": "{{v out/}}",
|
||||||
|
"err": "{{v err/}}"
|
||||||
|
}{{/b}}
|
||||||
|
}
|
||||||
|
}
|
6
src/main/resources/templates/bld/help_commands.json
Normal file
6
src/main/resources/templates/bld/help_commands.json
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
{{v error}}{{/v}}{{b error}}"error": "{{v error-message/}}",
|
||||||
|
{{/b}}"commands": {{{v commands}}{{/v}}{{b command}}{{v separator/}}
|
||||||
|
"{{v command/}}": "{{v summary/}}"{{/b}}
|
||||||
|
}
|
||||||
|
}
|
5
src/main/resources/templates/bld/help_description.json
Normal file
5
src/main/resources/templates/bld/help_description.json
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"description": {
|
||||||
|
"{{v command/}}": "{{v description/}}"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue