From a450f233393a9e3297fea633373635d060a3c709 Mon Sep 17 00:00:00 2001 From: ulrich <undisclosed> Date: Mon, 20 Mar 2017 13:46:41 +0000 Subject: [PATCH] Compile all mitsamt Resultaten --- src/java/de/uhilger/filecms/api/CompileService.java | 129 +++++++++++++----------------------------- 1 files changed, 40 insertions(+), 89 deletions(-) diff --git a/src/java/de/uhilger/filecms/api/CompileService.java b/src/java/de/uhilger/filecms/api/CompileService.java index 49bc175..b0ce388 100644 --- a/src/java/de/uhilger/filecms/api/CompileService.java +++ b/src/java/de/uhilger/filecms/api/CompileService.java @@ -34,6 +34,7 @@ import javax.tools.JavaFileObject; import javax.tools.StandardJavaFileManager; import javax.tools.ToolProvider; +import org.apache.commons.io.FileUtils; /** * @@ -53,28 +54,48 @@ DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector(); StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null); Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(files); - compiler.getTask(null, null, diagnostics, null, null, compilationUnits).call(); + + File buildDir = new File(targetDir.getParentFile(), "build"); + final Iterable<String> options = Arrays.asList(new String[]{"-Xlint", + /*"-cp", project.getClassPath(),*/ + /* + ausgehend von src eins hoeher, dann nach build + */ + "-d", buildDir.getAbsolutePath() + }); + FileUtils.deleteDirectory(buildDir); + buildDir.mkdir(); + compiler.getTask(null, null, diagnostics, options, 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, relPath); } catch(Exception ex) { logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex); } return compilerIssues; + } + + private void collectResults(DiagnosticCollector<JavaFileObject> diagnostics, List<CompilerIssue> compilerIssues, String relPath) { + 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)); + + String srcName = err.getSource().getName().replace("\\", "/"); + String cleanRelPath = relPath.replace(HOME_DIR_NAME + "/", "").replace(PUB_DIR_NAME + "/", ""); + int pos = srcName.indexOf(cleanRelPath); + String className = srcName.substring(pos + cleanRelPath.length()); + issue.setSourceName(className.replace("/", ".").substring(1)); + //issue.setSourceName(srcName + "\r\n" + relPath); + compilerIssues.add(issue); + } + } } private void collectFiles(ArrayList<File> files, File dir, FileFilter filter) { @@ -112,13 +133,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 +145,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 +158,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, relPath); 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