List of usage examples for com.google.gwt.dev.util Util readFileAsString
public static String readFileAsString(File file)
From source file:gwt.ns.webworker.linker.WorkerCompiler.java
License:Apache License
/** * Compiles requests in new process./*from w w w . j a va 2 s . co m*/ * * @param logger * @param requests * @return Compiled worker scripts. * @throws UnableToCompleteException */ private static SortedMap<WorkerRequestArtifact, String> runCompiler(TreeLogger logger, SortedSet<WorkerRequestArtifact> requests) throws UnableToCompleteException { List<String> commands = new ArrayList<String>(); commands.add("java"); // flag child process as recursive. value unimportant commands.add("-D" + RECURSION_FLAG_PROP + "=" + "true"); //inherit classpath from this process commands.add("-cp"); commands.add(System.getProperty("java.class.path")); commands.add("com.google.gwt.dev.Compiler"); // TODO: best practices for fixed directory that will be erased? // destination war directory commands.add("-war"); commands.add(TEMP_WAR_DIR_NAME); // TODO: user specified compiler options...workers, output style, etc // are these even visible? for (WorkerRequestArtifact req : requests) { commands.add(req.getCanonicalName()); } ProcessBuilder compileBuilder = new ProcessBuilder(commands); compileBuilder.redirectErrorStream(true); TreeLogger compLogger = logger.branch(TreeLogger.INFO, "Recursively compiling Worker modules..."); // default print command so build system mismatches are obvious StringBuilder buf = new StringBuilder(); for (String com : commands) { buf.append(com + " "); } logger.log(TreeLogger.INFO, "Executing cmd: \"" + buf.toString() + "\""); Process compile; try { compile = compileBuilder.start(); } catch (IOException e) { compLogger.log(TreeLogger.ERROR, "Unable to compile.", e); throw new UnableToCompleteException(); } // new thread for piping compiler output to logger PipeOutput pipe = new PipeOutput(compLogger, compile.getInputStream()); new Thread(pipe).start(); int exitValue; try { // block until compiler finished exitValue = compile.waitFor(); } catch (InterruptedException e) { compLogger.log(TreeLogger.ERROR, "Thread interrupted while waiting for compilation.", e); throw new UnableToCompleteException(); } if (exitValue != 0) { compLogger.log(TreeLogger.ERROR, "Error in compilation. See previous error."); throw new UnableToCompleteException(); } SortedMap<WorkerRequestArtifact, String> workerScripts = new TreeMap<WorkerRequestArtifact, String>(); for (WorkerRequestArtifact req : requests) { assert (!workerScripts.containsKey(req)) : "Module " + req.getName() + " was likely compiled twice."; // TODO: requires knowledge of linker used to package worker // query that linker to find file? needs to be more robust if // allowing more perms, etc, anyway String name = req.getName(); File scriptFile = new File(TEMP_WAR_DIR, name + File.separator + name + WorkerRequestArtifact.WORKER_EXTENSION); if (!scriptFile.isFile()) { compLogger.log(TreeLogger.ERROR, "Script file " + scriptFile.getPath() + " not found as expected. This is likely because the build system is not flexible enough to fit your needs. File an issue!"); throw new UnableToCompleteException(); } String script = Util.readFileAsString(scriptFile); workerScripts.put(req, script); } // delete temp directory // TODO: if this was a temp directory, this would feel a lot safer Util.recursiveDelete(TEMP_WAR_DIR, false); if (workerScripts.isEmpty()) { workerScripts = null; } return workerScripts; }
From source file:org.bonitasoft.tools.gwt.jetty.JettyLauncher.java
License:Open Source License
@Override public boolean processArguments(TreeLogger logger, String arguments) { if (arguments != null && arguments.length() > 0) { // TODO(jat): better parsing of the args for (String arg : arguments.split(",")) { int equals = arg.indexOf('='); String tag;/*from ww w . j a v a 2s. c o m*/ String value = null; if (equals < 0) { tag = arg; } else { tag = arg.substring(0, equals); value = arg.substring(equals + 1); } if ("ssl".equals(tag)) { useSsl = true; URL keyStoreUrl = getClass().getResource("localhost.keystore"); if (keyStoreUrl == null) { logger.log(TreeLogger.ERROR, "Default GWT keystore not found"); return false; } keyStore = keyStoreUrl.toExternalForm(); keyStorePassword = "localhost"; } else if ("keystore".equals(tag)) { useSsl = true; keyStore = value; } else if ("password".equals(tag)) { useSsl = true; keyStorePassword = value; } else if ("pwfile".equals(tag)) { useSsl = true; keyStorePassword = Util.readFileAsString(new File(value)).trim(); if (keyStorePassword == null) { logger.log(TreeLogger.ERROR, "Unable to read keystore password from '" + value + "'"); return false; } } else if ("clientAuth".equals(tag)) { useSsl = true; try { clientAuth = ClientAuth.valueOf(value); } catch (IllegalArgumentException e) { logger.log(TreeLogger.WARN, "Ignoring invalid clientAuth of '" + value + "'"); } } else { logger.log(TreeLogger.ERROR, "Unexpected argument to " + JettyLauncher.class.getSimpleName() + ": " + arg); return false; } } if (useSsl) { if (keyStore == null) { logger.log(TreeLogger.ERROR, "A keystore is required to use SSL"); return false; } if (keyStorePassword == null) { logger.log(TreeLogger.ERROR, "A keystore password is required to use SSL"); return false; } } } return true; }