Exemplo n.º 1
0
 public void acceptResult(CompilationResult compilationResult) {
   this.hasErrors |= compilationResult.hasErrors();
   this.problemLog +=
       Util.getProblemLog(compilationResult, this.showCategory, this.showWarningToken);
   outputClassFiles(compilationResult);
   if (this.clientRequestor != null) {
     this.clientRequestor.acceptResult(compilationResult);
   }
 }
Exemplo n.º 2
0
 protected void addProblem(CompilationResult result) {
   if (problems == null) {
     problems = new ArrayList<CompilationResult>();
   }
   problems.add(result);
   if (result.hasErrors()) {
     hasErrors = true;
   }
 }
Exemplo n.º 3
0
 @Override
 public void onCompilationResult(CompilationResult result) {
   if (result.hasErrors()) {
     myHasErrors = true;
     for (CategorizedProblem error : result.getErrors()) {
       myBuffer.append(error.getMessage());
       myBuffer.append("\n");
     }
   }
 }
Exemplo n.º 4
0
 protected void outputClassFiles(CompilationResult unitResult) {
   if ((unitResult != null) && (!unitResult.hasErrors() || this.forceOutputGeneration)) {
     ClassFile[] classFiles = unitResult.getClassFiles();
     if (this.outputPath != null) {
       for (int i = 0, fileCount = classFiles.length; i < fileCount; i++) {
         // retrieve the key and the corresponding classfile
         ClassFile classFile = classFiles[i];
         String relativeName =
             new String(classFile.fileName()).replace('/', File.separatorChar) + ".class";
         try {
           org.eclipse.jdt.internal.compiler.util.Util.writeToDisk(
               true, this.outputPath, relativeName, classFile);
         } catch (IOException e) {
           e.printStackTrace();
         }
       }
     }
   }
 }
Exemplo n.º 5
0
  // Dump classfiles onto disk for all compilation units that where successful
  // and do not carry a -d none spec, either directly or inherited from Main.
  @Override
  public void outputClassFiles(CompilationResult unitResult) {
    if (!((unitResult == null) || (unitResult.hasErrors() && !this.proceedOnError))) {
      ClassFile[] classFiles = unitResult.getClassFiles();
      boolean generateClasspathStructure =
          this.fileManager.hasLocation(StandardLocation.CLASS_OUTPUT);
      String currentDestinationPath = this.destinationPath;
      File outputLocation = null;
      if (currentDestinationPath != null) {
        outputLocation = new File(currentDestinationPath);
        outputLocation.mkdirs();
      }
      for (int i = 0, fileCount = classFiles.length; i < fileCount; i++) {
        // retrieve the key and the corresponding classfile
        ClassFile classFile = classFiles[i];
        char[] filename = classFile.fileName();
        int length = filename.length;
        char[] relativeName = new char[length + 6];
        System.arraycopy(filename, 0, relativeName, 0, length);
        System.arraycopy(SuffixConstants.SUFFIX_class, 0, relativeName, length, 6);
        CharOperation.replace(relativeName, '/', File.separatorChar);
        String relativeStringName = new String(relativeName);
        if (this.compilerOptions.verbose) {
          EclipseCompilerImpl.this.out.println(
              Messages.bind(
                  Messages.compilation_write,
                  new String[] {
                    String.valueOf(this.exportedClassFilesCounter + 1), relativeStringName
                  }));
        }
        try {
          JavaFileObject javaFileForOutput =
              this.fileManager.getJavaFileForOutput(
                  StandardLocation.CLASS_OUTPUT,
                  new String(filename),
                  JavaFileObject.Kind.CLASS,
                  this.javaFileObjectMap.get(unitResult.compilationUnit));

          if (generateClasspathStructure) {
            if (currentDestinationPath != null) {
              int index = CharOperation.lastIndexOf(File.separatorChar, relativeName);
              if (index != -1) {
                File currentFolder =
                    new File(currentDestinationPath, relativeStringName.substring(0, index));
                currentFolder.mkdirs();
              }
            } else {
              // create the subfolfers is necessary
              // need a way to retrieve the folders to create
              String path = javaFileForOutput.toUri().getPath();
              int index = path.lastIndexOf('/');
              if (index != -1) {
                File file = new File(path.substring(0, index));
                file.mkdirs();
              }
            }
          }

          OutputStream openOutputStream = javaFileForOutput.openOutputStream();
          BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(openOutputStream);
          bufferedOutputStream.write(classFile.header, 0, classFile.headerOffset);
          bufferedOutputStream.write(classFile.contents, 0, classFile.contentsOffset);
          bufferedOutputStream.flush();
          bufferedOutputStream.close();
        } catch (IOException e) {
          this.logger.logNoClassFileCreated(currentDestinationPath, relativeStringName, e);
        }
        this.logger.logClassFile(
            generateClasspathStructure, currentDestinationPath, relativeStringName);
        this.exportedClassFilesCounter++;
      }
      this.batchCompiler.lookupEnvironment.releaseClassFiles(classFiles);
    }
  }