From f23f2b611c8670bb9da8e6ddd32d3755289166c2 Mon Sep 17 00:00:00 2001
From: ulrich <not disclosed>
Date: Sun, 19 Mar 2017 16:33:35 +0000
Subject: [PATCH] compileAll (Entwurf) aufgeraeumt

---
 src/java/de/uhilger/filecms/api/CompileService.java |  109 ++++++++++--------------------------------------------
 1 files changed, 21 insertions(+), 88 deletions(-)

diff --git a/src/java/de/uhilger/filecms/api/CompileService.java b/src/java/de/uhilger/filecms/api/CompileService.java
index 49bc175..ceb507e 100644
--- a/src/java/de/uhilger/filecms/api/CompileService.java
+++ b/src/java/de/uhilger/filecms/api/CompileService.java
@@ -55,26 +55,29 @@
       Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(files);
       compiler.getTask(null, null, diagnostics, null, null, compilationUnits).call();
       fileManager.close();
-
-      List compileResults = diagnostics.getDiagnostics();
-      Iterator i = compileResults.iterator();
-      while(i.hasNext()) {
-        Object o = i.next();
-        Diagnostic<? extends JavaFileObject> err;
-        if(o instanceof Diagnostic) {
-          err = (Diagnostic) o;
-          CompilerIssue issue = new CompilerIssue();
-          issue.setKind(err.getKind().name());
-          issue.setLineNumber(err.getLineNumber());
-          issue.setMessage(err.getMessage(Locale.GERMANY));
-          issue.setSoureName(err.getSource().getName());
-          compilerIssues.add(issue);
-        }
-      }
+      collectResults(diagnostics, compilerIssues);
     } catch(Exception ex) {
       logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
     }
     return compilerIssues;
+  }
+  
+  private void collectResults(DiagnosticCollector<JavaFileObject> diagnostics, List<CompilerIssue> compilerIssues) {
+    List compileResults = diagnostics.getDiagnostics();
+    Iterator i = compileResults.iterator();
+    while (i.hasNext()) {
+      Object o = i.next();
+      Diagnostic<? extends JavaFileObject> err;
+      if (o instanceof Diagnostic) {
+        err = (Diagnostic) o;
+        CompilerIssue issue = new CompilerIssue();
+        issue.setKind(err.getKind().name());
+        issue.setLineNumber(err.getLineNumber());
+        issue.setMessage(err.getMessage(Locale.GERMANY));
+        issue.setSoureName(err.getSource().getName());
+        compilerIssues.add(issue);
+      }
+    }
   }
   
   private void collectFiles(ArrayList<File> files, File dir, FileFilter filter) {
@@ -112,13 +115,8 @@
    * @throws IOException 
    */
   public List<CompilerIssue> compile(String relPath, List fileNames, String mode) throws IOException {
-    //Files[] files1 = ... ; // input for first compilation task
-    //Files[] files2 = ... ; // input for second compilation task
-    
     File targetDir = getTargetDir(relPath);
-    //System.out.println(targetDir.getAbsolutePath());
     ArrayList<File> files = new ArrayList();
-    
     for(int i=0; i < fileNames.size(); i++) {
       Object o = fileNames.get(i);
       if(o instanceof ArrayList) {
@@ -129,15 +127,10 @@
         files.add(targetFile);
       }
     }
-
     JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
     DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector();
     StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
-
-    Iterable<? extends JavaFileObject> compilationUnits1 = fileManager.getJavaFileObjectsFromFiles(files);
-    
-    
-    
+    Iterable<? extends JavaFileObject> compilationUnits1 = fileManager.getJavaFileObjectsFromFiles(files);    
     if( mode.equals("1")) {
       final Iterable<String> options = Arrays.asList(new String[]{"-Xlint",
               /*"-cp", project.getClassPath(),*/
@@ -147,72 +140,12 @@
     } else {
       compiler.getTask(null, null, diagnostics, null, null, compilationUnits1).call();
     }     
-    
-    //compiler.getTask(null, fileManager, diagnostics, null, null, compilationUnits1).call();
-
-    /*
-    Iterable<? extends JavaFileObject> compilationUnits2
-            = fileManager.getJavaFileObjects(files2); // use alternative method
-    // reuse the same file manager to allow caching of jar files
-    compiler.getTask(null, fileManager, null, null, null, compilationUnits2).call();
-    */
     fileManager.close();
-
-    List compileResults = diagnostics.getDiagnostics();
     List<CompilerIssue> compilerIssues = new ArrayList();
-    Iterator i = compileResults.iterator();
-    while(i.hasNext()) {
-      Object o = i.next();
-      Diagnostic<? extends JavaFileObject> err;
-      if(o instanceof Diagnostic) {
-        err = (Diagnostic) o;
-        CompilerIssue issue = new CompilerIssue();
-        issue.setKind(err.getKind().name());
-        issue.setLineNumber(err.getLineNumber());
-        issue.setMessage(err.getMessage(Locale.GERMANY));
-        issue.setSoureName(err.getSource().getName());
-        compilerIssues.add(issue);
-      }
-    }
+    collectResults(diagnostics, compilerIssues);
     return compilerIssues;
   }
   
-  /*
-  private File getTargetDir(String relPath) {
-    logger.fine(relPath);
-    String targetPath = null;
-    if(relPath.startsWith(PUB_DIR_NAME)) {
-      targetPath = PUB_DIR_PATH + getUserName() + relPath.substring(PUB_DIR_NAME.length());
-    } else if(relPath.startsWith(HOME_DIR_NAME)) {
-      targetPath = HOME_DIR_PATH + getUserName() + relPath.substring(HOME_DIR_NAME.length());
-    } else {
-      // kann eigentlich nicht sein..
-    }
-    logger.fine(targetPath);
-    File targetDir = new File(getBase().getAbsolutePath(), targetPath);
-    return targetDir;
-  }
-  
-  private FileRef getBase() {
-    FileRef base = null;
-    Object o = getServletContext().getAttribute(Initialiser.FILE_BASE);
-    if(o instanceof String) {
-      String baseStr = (String) o;
-      logger.fine(baseStr);
-      File file = new File(baseStr);
-      base = new FileRef(file.getAbsolutePath(), file.isDirectory());
-    }
-    return base;
-  }
-  private String getUserName() {
-    String userName = null;
-    Object p = getRequest().getUserPrincipal();
-    if(p instanceof Principal) {
-      userName = ((Principal) p).getName();
-    }
-    return userName;
-  }    
-*/
 }
 
 

--
Gitblit v1.9.3