@Override
  protected boolean doSlowStartup() {
    tempWorkDir = options.getWorkDir() == null;
    if (tempWorkDir) {
      try {
        options.setWorkDir(Utility.makeTemporaryDirectory(null, "gwtc"));
      } catch (IOException e) {
        System.err.println("Unable to create hosted mode work directory");
        e.printStackTrace();
        return false;
      }
    }

    TreeLogger branch = getTopLogger().branch(TreeLogger.TRACE, "Linking modules");
    Event slowStartupEvent = SpeedTracerLogger.start(DevModeEventType.SLOW_STARTUP);
    try {
      for (ModuleDef module : startupModules.values()) {
        TreeLogger loadLogger =
            branch.branch(
                TreeLogger.DEBUG,
                "Bootstrap link for command-line module '" + module.getCanonicalName() + "'");
        link(loadLogger, module);
      }
    } catch (UnableToCompleteException e) {
      // Already logged.
      return false;
    } finally {
      slowStartupEvent.end();
    }
    return true;
  }
 /**
  * Ensures that we have a work directory. If specified via a flag, the directory must already
  * exist. Otherwise, create a temp directory.
  */
 private static File ensureWorkDir(Options options) throws IOException {
   File workDir = options.getWorkDir();
   if (workDir == null) {
     workDir = Utility.makeTemporaryDirectory(null, "gwt-codeserver-");
   } else {
     if (!workDir.isDirectory()) {
       throw new IOException("workspace directory doesn't exist: " + workDir);
     }
   }
   return workDir;
 }
 @Override
 public NameEnvironmentAnswer findType(char[][] compoundTypeName) {
   char[] binaryNameChars = CharOperation.concatWith(compoundTypeName, '/');
   String binaryName = String.valueOf(binaryNameChars);
   CompiledClass compiledClass = binaryTypes.get(binaryName);
   try {
     if (compiledClass != null) {
       return compiledClass.getNameEnvironmentAnswer();
     }
   } catch (ClassFormatException ex) {
     // fall back to binary class
   }
   if (isPackage(binaryName)) {
     return null;
   }
   if (additionalTypeProviderDelegate != null) {
     GeneratedUnit unit = additionalTypeProviderDelegate.doFindAdditionalType(binaryName);
     if (unit != null) {
       CompilationUnitBuilder b = CompilationUnitBuilder.create(unit);
       Adapter a = new Adapter(b);
       return new NameEnvironmentAnswer(a, null);
     }
   }
   try {
     URL resource = getClassLoader().getResource(binaryName + ".class");
     if (resource != null) {
       InputStream openStream = resource.openStream();
       try {
         ClassFileReader cfr = ClassFileReader.read(openStream, resource.toExternalForm(), true);
         return new NameEnvironmentAnswer(cfr, null);
       } finally {
         Utility.close(openStream);
       }
     }
   } catch (ClassFormatException e) {
   } catch (IOException e) {
   }
   return null;
 }
示例#4
0
  public boolean run(TreeLogger logger, ModuleDef... modules) throws UnableToCompleteException {
    boolean tempWorkDir = false;
    try {
      if (options.getWorkDir() == null) {
        options.setWorkDir(Utility.makeTemporaryDirectory(null, "gwtc"));
        tempWorkDir = true;
      }
      if (options.isSoycEnabled() && options.getExtraDir() == null) {
        options.setExtraDir(new File("extras"));
      }

      File persistentUnitCacheDir = null;
      if (options.getWarDir() != null && !options.getWarDir().getName().endsWith(".jar")) {
        persistentUnitCacheDir = new File(options.getWarDir(), "../");
      }
      CompilationStateBuilder.init(logger, persistentUnitCacheDir);

      for (ModuleDef module : modules) {
        String moduleName = module.getCanonicalName();
        if (options.isValidateOnly()) {
          if (!Precompile.validate(logger, options, module, options.getGenDir())) {
            return false;
          }
        } else {
          long compileStart = System.currentTimeMillis();
          TreeLogger branch = logger.branch(TreeLogger.INFO, "Compiling module " + moduleName);

          // Optimize early since permutation compiles will run in process.
          options.setOptimizePrecompile(true);
          Precompilation precompilation =
              Precompile.precompile(branch, options, module, options.getGenDir());
          if (precompilation == null) {
            return false;
          }

          Event compilePermutationsEvent =
              SpeedTracerLogger.start(CompilerEventType.COMPILE_PERMUTATIONS);
          Permutation[] allPerms = precompilation.getPermutations();
          List<FileBackedObject<PermutationResult>> resultFiles =
              CompilePerms.makeResultFiles(options.getCompilerWorkDir(moduleName), allPerms);
          CompilePerms.compile(
              branch, precompilation, allPerms, options.getLocalWorkers(), resultFiles);
          compilePermutationsEvent.end();

          ArtifactSet generatedArtifacts = precompilation.getGeneratedArtifacts();
          JJSOptions precompileOptions = precompilation.getUnifiedAst().getOptions();

          precompilation = null; // No longer needed, so save the memory

          Event linkEvent = SpeedTracerLogger.start(CompilerEventType.LINK);
          File absPath = new File(options.getWarDir(), module.getName());
          absPath = absPath.getAbsoluteFile();

          String logMessage = "Linking into " + absPath;
          if (options.getExtraDir() != null) {
            File absExtrasPath = new File(options.getExtraDir(), module.getName());
            absExtrasPath = absExtrasPath.getAbsoluteFile();
            logMessage += "; Writing extras to " + absExtrasPath;
          }
          Link.link(
              logger.branch(TreeLogger.TRACE, logMessage),
              module,
              generatedArtifacts,
              allPerms,
              resultFiles,
              options.getWarDir(),
              options.getDeployDir(),
              options.getExtraDir(),
              precompileOptions);

          linkEvent.end();
          long compileDone = System.currentTimeMillis();
          long delta = compileDone - compileStart;
          if (branch.isLoggable(TreeLogger.INFO)) {
            branch.log(
                TreeLogger.INFO,
                "Compilation succeeded -- " + String.format("%.3f", delta / 1000d) + "s");
          }
        }
      }

    } catch (IOException e) {
      logger.log(TreeLogger.ERROR, "Unable to create compiler work directory", e);
      return false;
    } finally {
      if (tempWorkDir) {
        Util.recursiveDelete(options.getWorkDir(), false);
      }
    }
    return true;
  }