Skip to content

Commit

Permalink
Allow bld to run in embedded mode
Browse files Browse the repository at this point in the history
  • Loading branch information
gbevin committed Jun 24, 2024
1 parent 4f20fb2 commit 9338768
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
14 changes: 13 additions & 1 deletion src/main/java/rife/bld/BuildExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import rife.bld.help.HelpHelp;
import rife.bld.operations.HelpOperation;
import rife.bld.operations.exceptions.ExitStatusException;
import rife.bld.wrapper.Wrapper;
import rife.ioc.HierarchicalProperties;
import rife.tools.ExceptionUtils;

Expand Down Expand Up @@ -271,7 +272,18 @@ public int execute(String[] arguments) {
* @since 1.5.1
*/
public void start(String[] arguments) {
System.exit(execute(arguments));
boolean embedded = false;
if (arguments != null) {
var arg_list = new ArrayList<>(Arrays.asList(arguments));
embedded = arg_list.remove(Wrapper.EMBEDDED_ARGUMENT);
if (embedded) {
arguments = arg_list.toArray(arguments);
}
}
var status = execute(arguments);
if (!embedded) {
System.exit(status);
}
}

/**
Expand Down
38 changes: 35 additions & 3 deletions src/main/java/rife/bld/wrapper/Wrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
* @since 1.5
*/
public class Wrapper {
public static final String BUILD_ARGUMENT = "--build";
public static final String EMBEDDED_ARGUMENT = "--embedded";

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 DOWNLOAD_LOCATION = MAVEN_CENTRAL + "com/uwyn/rife2/bld/${version}/";
Expand Down Expand Up @@ -60,7 +63,6 @@ public class Wrapper {
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+");


private File currentDir_ = new File(System.getProperty("user.dir"));

private final Properties wrapperProperties_ = new Properties();
Expand All @@ -73,14 +75,41 @@ public class Wrapper {
private final byte[] buffer_ = new byte[1024];
private WrapperClassLoader classloader_;

private final boolean embedded_;

/**
* Creates a new embedded wrapper.
*
* @since 1.0
*/
public Wrapper() {
embedded_ = true;
}

/**
* Creates a new wrapper.
*
* @param embedded {@code true} if the wrapper should run in embedded mode;
* or {@code false} if it should run standalone and automatically exit
* @since 1.9.2
*/
public Wrapper(boolean embedded) {
embedded_ = embedded;
}

/**
* Launches the wrapper.
*
* @param arguments the command line arguments to pass on to the build logic
* @since 1.5
*/
public static void main(String[] arguments) {
System.exit(new Wrapper().installAndLaunch(new ArrayList<>(Arrays.asList(arguments))));
var arg_list = new ArrayList<>(Arrays.asList(arguments));
var embedded = arg_list.remove(EMBEDDED_ARGUMENT);
var status = new Wrapper(embedded).installAndLaunch(arg_list);
if (!embedded) {
System.exit(status);
}
}

/**
Expand Down Expand Up @@ -503,7 +532,7 @@ private void resolveExtensions() {

private int launchMain(File jarFile, List<String> arguments)
throws IOException, InterruptedException, FileUtilsErrorException {
if (arguments.isEmpty() || !"--build".equals(arguments.get(0))) {
if (arguments.isEmpty() || !BUILD_ARGUMENT.equals(arguments.get(0))) {
return launchMainCli(jarFile, arguments);
}
return launchMainBuild(jarFile, arguments);
Expand Down Expand Up @@ -574,6 +603,9 @@ private int launchMainBuild(File jarFile, List<String> arguments)
java_args.add(classpath);

java_args.addAll(bldJavaOptions());
if (embedded_) {
java_args.add(EMBEDDED_ARGUMENT);
}
java_args.addAll(arguments);

var process_builder = new ProcessBuilder(java_args);
Expand Down

0 comments on commit 9338768

Please sign in to comment.