summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--jack/src/com/android/jack/CommandLine.java69
-rw-r--r--jack/src/com/android/jack/Main.java4
-rw-r--r--jack/src/com/android/jack/Options.java44
-rw-r--r--jack/src/com/android/jack/server/ServerTaskInsideVm.java75
4 files changed, 155 insertions, 37 deletions
diff --git a/jack/src/com/android/jack/CommandLine.java b/jack/src/com/android/jack/CommandLine.java
index d3f77a4..b02bac8 100644
--- a/jack/src/com/android/jack/CommandLine.java
+++ b/jack/src/com/android/jack/CommandLine.java
@@ -57,12 +57,13 @@ public abstract class CommandLine {
@Nonnull
private static Logger logger = LoggerFactory.getLogger();
- protected static void runJackAndExitOnError(@Nonnull Options options) {
+ protected static int runJack(@Nonnull PrintStream err, @Nonnull Options options) {
ProcessException pe = null;
try {
try {
Jack.checkAndRun(options);
+ return (ExitStatus.SUCCESS);
} catch (ProcessException e) {
// Handle the cause, but keep the ProcessException in case of
// Internal Compiler Error only
@@ -70,56 +71,56 @@ public abstract class CommandLine {
throw e.getCause();
}
} catch (ConfigurationException exceptions) {
- System.err.println(exceptions.getNextExceptionCount() + " error"
+ err.println(exceptions.getNextExceptionCount() + " error"
+ (exceptions.getNextExceptionCount() > 1 ? "s" : "")
+ " during configuration. Try --help-properties for help.");
for (ChainedException exception : exceptions) {
- System.err.println(" " + exception.getMessage());
+ err.println(" " + exception.getMessage());
}
- System.exit(ExitStatus.FAILURE_USAGE);
+ return (ExitStatus.FAILURE_USAGE);
} catch (IllegalOptionsException e) {
- System.err.println(e.getMessage());
- System.err.println("Try --help for help.");
+ err.println(e.getMessage());
+ err.println("Try --help for help.");
- System.exit(ExitStatus.FAILURE_USAGE);
+ return (ExitStatus.FAILURE_USAGE);
} catch (FrontendCompilationException e) {
// Cause exception has already been logged
- System.exit(ExitStatus.FAILURE_COMPILATION);
+ return (ExitStatus.FAILURE_COMPILATION);
} catch (JackUserException e) {
- System.err.println(e.getMessage());
+ err.println(e.getMessage());
logger.log(Level.FINE, "Jack user exception:", e);
- System.exit(ExitStatus.FAILURE_COMPILATION);
+ return (ExitStatus.FAILURE_COMPILATION);
} catch (JackLoadingException e) {
- System.err.println(e.getMessage());
+ err.println(e.getMessage());
logger.log(Level.FINE, "Jack loading exception:", e);
- System.exit(ExitStatus.FAILURE_COMPILATION);
+ return (ExitStatus.FAILURE_COMPILATION);
} catch (OutOfMemoryError e) {
- printExceptionMessage(e, "Out of memory error.");
- System.err.println("Try increasing heap size with java option '-Xmx<size>'");
- System.err.println(INTERRUPTED_COMPILATION_WARNING);
+ printExceptionMessage(err, e, "Out of memory error.");
+ err.println("Try increasing heap size with java option '-Xmx<size>'");
+ err.println(INTERRUPTED_COMPILATION_WARNING);
logger.log(Level.FINE, "Out of memory error:", e);
- System.exit(ExitStatus.FAILURE_VM);
+ return (ExitStatus.FAILURE_VM);
} catch (StackOverflowError e) {
- printExceptionMessage(e, "Stack overflow error.");
- System.err.println("Try increasing stack size with java option '-Xss<size>'");
- System.err.println(INTERRUPTED_COMPILATION_WARNING);
+ printExceptionMessage(err, e, "Stack overflow error.");
+ err.println("Try increasing stack size with java option '-Xss<size>'");
+ err.println(INTERRUPTED_COMPILATION_WARNING);
logger.log(Level.FINE, "Stack overflow error:", e);
- System.exit(ExitStatus.FAILURE_VM);
+ return (ExitStatus.FAILURE_VM);
} catch (VirtualMachineError e) {
- printExceptionMessage(e, "Virtual machine error: " + e.getClass() + ".");
- System.err.println(INTERRUPTED_COMPILATION_WARNING);
+ printExceptionMessage(err, e, "Virtual machine error: " + e.getClass() + ".");
+ err.println(INTERRUPTED_COMPILATION_WARNING);
logger.log(Level.FINE, "Virtual machine error:", e);
- System.exit(ExitStatus.FAILURE_VM);
+ return (ExitStatus.FAILURE_VM);
} catch (UnrecoverableException e) {
- System.err.println("Unrecoverable error: " + e.getMessage());
- System.err.println(INTERRUPTED_COMPILATION_WARNING);
+ err.println("Unrecoverable error: " + e.getMessage());
+ err.println(INTERRUPTED_COMPILATION_WARNING);
logger.log(Level.FINE, "Unrecoverable exception:", e);
- System.exit(ExitStatus.FAILURE_UNRECOVERABLE);
+ return (ExitStatus.FAILURE_UNRECOVERABLE);
} catch (JackAbortException e) {
// Exception should already have been reported, do not print message.
logger.log(Level.FINE, "Jack fatal exception:", e);
- System.exit(ExitStatus.FAILURE_COMPILATION);
+ return (ExitStatus.FAILURE_COMPILATION);
} catch (Throwable e) {
// Internal Compiler Error here
// If the exception come from a ProcessException, we want
@@ -131,13 +132,13 @@ public abstract class CommandLine {
String info = "Internal compiler error (version " + Jack.getVersionString() + ")";
logger.log(Level.SEVERE, info + ':', e);
e.printStackTrace();
- System.err.println();
- System.err.println(info + '.');
+ err.println();
+ err.println(info + '.');
if (e.getMessage() != null) {
- System.err.println(e.getMessage() + '.');
+ err.println(e.getMessage() + '.');
}
- System.err.println(INTERRUPTED_COMPILATION_WARNING);
- System.exit(ExitStatus.FAILURE_INTERNAL);
+ err.println(INTERRUPTED_COMPILATION_WARNING);
+ return (ExitStatus.FAILURE_INTERNAL);
}
}
@@ -226,12 +227,12 @@ public abstract class CommandLine {
}
}
- protected static void printExceptionMessage(@Nonnull Throwable t,
+ protected static void printExceptionMessage(@Nonnull PrintStream err, @Nonnull Throwable t,
@Nonnull String defaultMessage) {
String exceptionMessage = t.getMessage();
if (exceptionMessage == null) {
exceptionMessage = defaultMessage;
}
- System.err.println(exceptionMessage);
+ err.println(exceptionMessage);
}
}
diff --git a/jack/src/com/android/jack/Main.java b/jack/src/com/android/jack/Main.java
index ca3e4ff..78eb4f2 100644
--- a/jack/src/com/android/jack/Main.java
+++ b/jack/src/com/android/jack/Main.java
@@ -69,7 +69,7 @@ public abstract class Main extends CommandLine {
}
// Compile
- runJackAndExitOnError(options);
+ System.exit(runJack(System.err, options));
} catch (CmdLineException e) {
System.err.println(e.getMessage());
CmdLineParser parser = e.getParser();
@@ -85,8 +85,6 @@ public abstract class Main extends CommandLine {
System.exit(ExitStatus.FAILURE_USAGE);
}
-
- System.exit(ExitStatus.SUCCESS);
}
@Nonnull
diff --git a/jack/src/com/android/jack/Options.java b/jack/src/com/android/jack/Options.java
index af8597e..e7dca2e 100644
--- a/jack/src/com/android/jack/Options.java
+++ b/jack/src/com/android/jack/Options.java
@@ -75,7 +75,10 @@ import com.android.sched.util.file.FileOrDirectory.ChangePermission;
import com.android.sched.util.file.FileOrDirectory.Existence;
import com.android.sched.util.file.FileOrDirectory.Permission;
import com.android.sched.util.file.FileUtils;
+import com.android.sched.util.file.NoSuchFileException;
+import com.android.sched.util.file.NotDirectoryException;
import com.android.sched.util.file.OutputStreamFile;
+import com.android.sched.util.file.WrongPermissionException;
import com.android.sched.util.location.FileLocation;
import com.android.sched.util.location.NoLocation;
import com.android.sched.util.location.StringLocation;
@@ -486,6 +489,15 @@ public class Options {
@CheckForNull
private OutputStream reporterStream = null;
+ @CheckForNull
+ private File workingDirectory = null;
+
+ @CheckForNull
+ private PrintStream standardError = null;
+
+ @CheckForNull
+ private PrintStream standardOutput = null;
+
public void setVerbosityLevel(@Nonnull VerbosityLevel verbose) {
this.verbose = verbose;
}
@@ -612,6 +624,26 @@ public class Options {
}
}
+ if (workingDirectory != null) {
+ try {
+ configBuilder.setWorkingDirectory(workingDirectory);
+ } catch (NotDirectoryException e) {
+ throw new IllegalOptionsException(e.getMessage(), e);
+ } catch (WrongPermissionException e) {
+ throw new IllegalOptionsException(e.getMessage(), e);
+ } catch (NoSuchFileException e) {
+ throw new IllegalOptionsException(e.getMessage(), e);
+ }
+ }
+
+ if (standardError != null) {
+ configBuilder.setStandardError(standardError);
+ }
+
+ if (standardOutput != null) {
+ configBuilder.setStandardOutput(standardOutput);
+ }
+
configBuilder.pushDefaultLocation(new StringLocation("Options"));
configBuilder.set(VERBOSITY_LEVEL, verbose);
@@ -1007,6 +1039,18 @@ public class Options {
this.reporterStream = reporterStream;
}
+ public void setWorkingDirectory(@Nonnull File workingDirectory) {
+ this.workingDirectory = workingDirectory;
+ }
+
+ public void setStandardError(@Nonnull PrintStream standardError) {
+ this.standardError = standardError;
+ }
+
+ public void setStandardOutput(@Nonnull PrintStream standardOutput) {
+ this.standardOutput = standardOutput;
+ }
+
@Nonnull
private static Directory createTempDir(
@Nonnull RunnableHooks hooks) {
diff --git a/jack/src/com/android/jack/server/ServerTaskInsideVm.java b/jack/src/com/android/jack/server/ServerTaskInsideVm.java
new file mode 100644
index 0000000..2f4d67d
--- /dev/null
+++ b/jack/src/com/android/jack/server/ServerTaskInsideVm.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.jack.server;
+
+import com.android.jack.CommandLine;
+import com.android.jack.Main;
+import com.android.jack.Options;
+import com.android.sched.util.config.cli.TokenIterator;
+import com.android.sched.util.file.CannotReadException;
+import com.android.sched.util.file.NoSuchFileException;
+import com.android.sched.util.file.NotFileOrDirectoryException;
+import com.android.sched.util.file.WrongPermissionException;
+
+import org.kohsuke.args4j.CmdLineException;
+
+import java.io.File;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.NoSuchElementException;
+
+import javax.annotation.Nonnull;
+
+/**
+ * {@link ServerTask} implementation.
+ */
+public class ServerTaskInsideVm extends CommandLine implements ServerTask {
+
+ @Override
+ public int run(@Nonnull PrintStream out, @Nonnull PrintStream err, @Nonnull File pwd,
+ @Nonnull TokenIterator args) {
+ List<String> list = new ArrayList<String>();
+ Options options;
+ try {
+ while (args.hasNext()) {
+ list.add(args.next());
+ }
+ options = Main.parseCommandLine(list);
+ options.setWorkingDirectory(pwd);
+ options.setStandardError(err);
+ options.setStandardOutput(out);
+ } catch (CmdLineException e) {
+ if (e.getMessage() != null) {
+ err.println(e.getMessage());
+ }
+ return ServerExitStatus.FAILURE_USAGE;
+ } catch (NoSuchElementException e) {
+ return ServerExitStatus.FAILURE_USAGE;
+ } catch (WrongPermissionException e) {
+ return ServerExitStatus.FAILURE_USAGE;
+ } catch (NoSuchFileException e) {
+ return ServerExitStatus.FAILURE_USAGE;
+ } catch (NotFileOrDirectoryException e) {
+ return ServerExitStatus.FAILURE_USAGE;
+ } catch (CannotReadException e) {
+ return ServerExitStatus.FAILURE_USAGE;
+ }
+
+ return runJack(err, options);
+ }
+}