List of usage examples for org.eclipse.jdt.internal.compiler CompilationResult getProblems
public CategorizedProblem[] getProblems()
From source file:br.com.objectos.code.JdtCompilerTest.java
License:Apache License
private void acceptResult(CompilationResult result) { CategorizedProblem[] problems = result.getProblems(); ObjectAssertion.assertThat(problems).isNull(); }
From source file:io.takari.maven.plugins.compile.jdt.CompilerJdt.java
License:Open Source License
@Override public void acceptResult(CompilationResult result) { if (result == null) { return; // ah? }/*from w ww . ja v a 2 s . c om*/ final String sourceName = new String(result.getFileName()); final File sourceFile = new File(sourceName); Resource<File> input = context.getProcessedSource(sourceFile); // track type references if (result.rootReferences != null && result.qualifiedReferences != null && result.simpleNameReferences != null) { context.setAttribute(input.getResource(), ATTR_REFERENCES, new ReferenceCollection( result.rootReferences, result.qualifiedReferences, result.simpleNameReferences)); } if (result.hasProblems() && (!isLenientProcOnly() || isShowWarnings())) { for (CategorizedProblem problem : result.getProblems()) { MessageSeverity severity = isLenientProcOnly() ? MessageSeverity.WARNING : problem.isError() ? MessageSeverity.ERROR : MessageSeverity.WARNING; input.addMessage(problem.getSourceLineNumber(), ((DefaultProblem) problem).column, problem.getMessage(), severity, null /* cause */); } } try { if (!result.hasErrors() && !isProcOnly()) { for (ClassFile classFile : result.getClassFiles()) { 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); writeClassFile(input, relativeStringName, classFile); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // XXX double check affected sources are recompiled when this source has errors }
From source file:ma.glasnost.orika.impl.generator.eclipsejdt.CompilerRequestor.java
License:Apache License
public void acceptResult(CompilationResult result) { boolean hasErrors = false; if (result.hasProblems()) { problems = result.getProblems(); }/*from w w w . j a va 2 s .c o m*/ if (!hasErrors) { ClassFile[] classFiles = result.getClassFiles(); for (int i = 0; i < classFiles.length; i++) { ClassFile classFile = classFiles[i]; char[][] compoundName = classFile.getCompoundName(); StringBuilder className = new StringBuilder(); String sep = ""; for (int j = 0; j < compoundName.length; j++) { className.append(sep); className.append(new String(compoundName[j])); sep = "."; } byte[] bytes = classFile.getBytes(); compiledClassFiles.put(className.toString(), bytes); } } }
From source file:net.sf.j2s.core.builder.AbstractImageBuilder.java
License:Open Source License
protected void updateProblemsFor(SourceFile sourceFile, CompilationResult result) throws CoreException { CategorizedProblem[] problems = result.getProblems(); if (problems == null || problems.length == 0) return;// ww w .j av a 2 s . c o m this.notifier.updateProblemCounts(problems); storeProblemsFor(sourceFile, problems); }
From source file:net.sf.j2s.core.builder.IncrementalImageBuilder.java
License:Open Source License
protected void updateProblemsFor(SourceFile sourceFile, CompilationResult result) throws CoreException { if (CharOperation.equals(sourceFile.getMainTypeName(), TypeConstants.PACKAGE_INFO_NAME)) { IResource pkgResource = sourceFile.resource.getParent(); pkgResource.deleteMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_ZERO); }/*from w w w . ja v a 2 s . c o m*/ IMarker[] markers = JavaBuilder.getProblemsFor(sourceFile.resource); CategorizedProblem[] problems = result.getProblems(); if (problems == null && markers.length == 0) return; this.notifier.updateProblemCounts(markers, problems); JavaBuilder.removeProblemsFor(sourceFile.resource); storeProblemsFor(sourceFile, problems); }
From source file:org.apache.commons.jci.compilers.EclipseJavaCompiler.java
License:Apache License
public org.apache.commons.jci.compilers.CompilationResult compile(final String[] pSourceFiles, final ResourceReader pReader, final ResourceStore pStore, final ClassLoader pClassLoader, final JavaCompilerSettings pSettings) { final Map<String, String> settingsMap = new EclipseJavaCompilerSettings(pSettings).toNativeSettings(); final Collection<CompilationProblem> problems = new ArrayList<CompilationProblem>(); final ICompilationUnit[] compilationUnits = new ICompilationUnit[pSourceFiles.length]; for (int i = 0; i < compilationUnits.length; i++) { final String sourceFile = pSourceFiles[i]; if (pReader.isAvailable(sourceFile)) { compilationUnits[i] = new CompilationUnit(pReader, sourceFile); log.debug("compiling " + sourceFile); } else {/*from ww w. java2 s. co m*/ // log.error("source not found " + sourceFile); final CompilationProblem problem = new CompilationProblem() { public int getEndColumn() { return 0; } public int getEndLine() { return 0; } public String getFileName() { return sourceFile; } public String getMessage() { return "Source " + sourceFile + " could not be found"; } public int getStartColumn() { return 0; } public int getStartLine() { return 0; } public boolean isError() { return true; } @Override public String toString() { return getMessage(); } }; if (problemHandler != null) { problemHandler.handle(problem); } problems.add(problem); } } if (problems.size() > 0) { final CompilationProblem[] result = new CompilationProblem[problems.size()]; problems.toArray(result); return new org.apache.commons.jci.compilers.CompilationResult(result); } final IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems(); final IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault()); final INameEnvironment nameEnvironment = new INameEnvironment() { public NameEnvironmentAnswer findType(final char[][] pCompoundTypeName) { final StringBuilder result = new StringBuilder(); for (int i = 0; i < pCompoundTypeName.length; i++) { if (i != 0) { result.append('.'); } result.append(pCompoundTypeName[i]); } //log.debug("finding compoundTypeName=" + result.toString()); return findType(result.toString()); } public NameEnvironmentAnswer findType(final char[] pTypeName, final char[][] pPackageName) { final StringBuilder result = new StringBuilder(); for (int i = 0; i < pPackageName.length; i++) { result.append(pPackageName[i]); result.append('.'); } // log.debug("finding typeName=" + new String(typeName) + " packageName=" + result.toString()); result.append(pTypeName); return findType(result.toString()); } private NameEnvironmentAnswer findType(final String pClazzName) { if (isPackage(pClazzName)) { return null; } log.debug("finding " + pClazzName); final String resourceName = ConversionUtils.convertClassToResourcePath(pClazzName); final byte[] clazzBytes = pStore.read(resourceName); if (clazzBytes != null) { log.debug("loading from store " + pClazzName); final char[] fileName = pClazzName.toCharArray(); try { final ClassFileReader classFileReader = new ClassFileReader(clazzBytes, fileName, true); return new NameEnvironmentAnswer(classFileReader, null); } catch (final ClassFormatException e) { log.error("wrong class format", e); return null; } } log.debug("not in store " + pClazzName); final InputStream is = pClassLoader.getResourceAsStream(resourceName); if (is == null) { log.debug("class " + pClazzName + " not found"); return null; } final byte[] buffer = new byte[8192]; final ByteArrayOutputStream baos = new ByteArrayOutputStream(buffer.length); int count; try { while ((count = is.read(buffer, 0, buffer.length)) > 0) { baos.write(buffer, 0, count); } baos.flush(); final char[] fileName = pClazzName.toCharArray(); final ClassFileReader classFileReader = new ClassFileReader(baos.toByteArray(), fileName, true); return new NameEnvironmentAnswer(classFileReader, null); } catch (final IOException e) { log.error("could not read class", e); return null; } catch (final ClassFormatException e) { log.error("wrong class format", e); return null; } finally { try { baos.close(); } catch (final IOException oe) { log.error("could not close output stream", oe); } try { is.close(); } catch (final IOException ie) { log.error("could not close input stream", ie); } } } private boolean isPackage(final String pClazzName) { // reject this early as it is cheap if (pClazzName.contains("-")) { // "-" is not valid in package names return false; } final InputStream is = pClassLoader .getResourceAsStream(ConversionUtils.convertClassToResourcePath(pClazzName)); if (is != null) { log.debug("found the class for " + pClazzName + "- no package"); try { is.close(); } catch (final IOException ie) { log.error("could not close input stream", ie); } return false; } // FIXME: this should not be tied to the extension final String source = pClazzName.replace('.', '/') + ".java"; if (pReader.isAvailable(source)) { log.debug("found the source " + source + " for " + pClazzName + " - no package "); return false; } /* * See https://issues.apache.org/jira/browse/JCI-59 * At present, the code assumes that anything else is a package name * This is wrong, as for example jci.AdditionalTopLevel is not a package name. * It's not clear how to fix this in general. * It would seem to need access to the input classpath and/or the generated classes. */ return true; } public boolean isPackage(char[][] parentPackageName, char[] pPackageName) { final StringBuilder result = new StringBuilder(); if (parentPackageName != null) { for (int i = 0; i < parentPackageName.length; i++) { if (i != 0) { result.append('.'); } result.append(parentPackageName[i]); } } // log.debug("isPackage parentPackageName=" + result.toString() + " packageName=" + new String(packageName)); if (parentPackageName != null && parentPackageName.length > 0) { result.append('.'); } result.append(pPackageName); return isPackage(result.toString()); } public void cleanup() { log.debug("cleanup"); } }; final ICompilerRequestor compilerRequestor = new ICompilerRequestor() { public void acceptResult(final CompilationResult pResult) { if (pResult.hasProblems()) { for (IProblem iproblem : pResult.getProblems()) { final CompilationProblem problem = new EclipseCompilationProblem(iproblem); if (problemHandler != null) { problemHandler.handle(problem); } problems.add(problem); } } if (!pResult.hasErrors()) { final ClassFile[] clazzFiles = pResult.getClassFiles(); for (ClassFile clazzFile : clazzFiles) { final char[][] compoundName = clazzFile.getCompoundName(); final StringBuilder clazzName = new StringBuilder(); for (int j = 0; j < compoundName.length; j++) { if (j != 0) { clazzName.append('.'); } clazzName.append(compoundName[j]); } pStore.write(clazzName.toString().replace('.', '/') + ".class", clazzFile.getBytes()); } } } }; final Compiler compiler = new Compiler(nameEnvironment, policy, new CompilerOptions(settingsMap), compilerRequestor, problemFactory); compiler.compile(compilationUnits); final CompilationProblem[] result = new CompilationProblem[problems.size()]; problems.toArray(result); return new org.apache.commons.jci.compilers.CompilationResult(result); }
From source file:org.apache.jasper.compiler.JDTJavaCompiler.java
License:Open Source License
/** * Invoke CompilationResult#getProblems safely so that it works with * 3.1.1 and more recent versions of the eclipse java compiler. * See https://jsp.dev.java.net/issues/show_bug.cgi?id=13 * //from w w w. j a v a 2 s . c om * @param result The compilation result. * @return The same object than CompilationResult#getProblems */ private static final IProblem[] safeGetProblems(CompilationResult result) { if (!USE_INTROSPECTION_TO_INVOKE_GET_PROBLEM) { try { return result.getProblems(); } catch (NoSuchMethodError re) { USE_INTROSPECTION_TO_INVOKE_GET_PROBLEM = true; } } try { if (GET_PROBLEM_METH == null) { GET_PROBLEM_METH = result.getClass().getDeclaredMethod("getProblems", new Class[] {}); } //an array of a particular type can be casted into an array of a super type. return (IProblem[]) GET_PROBLEM_METH.invoke(result, null); } catch (Throwable e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new RuntimeException(e); } } }
From source file:org.apache.tuscany.maven.compiler.CompilerRequestor.java
License:Apache License
public void acceptResult(CompilationResult result) { boolean hasErrors = false; if (result.hasProblems()) { // Convert JDT IProblems into plexus CompilerErrors for (IProblem problem : result.getProblems()) { if (problem.isWarning()) { if (showWarnings) { compilerErrors.add(new CompilerError(new String(problem.getOriginatingFileName()), false, problem.getSourceLineNumber(), problem.getSourceStart(), problem.getSourceLineNumber(), problem.getSourceEnd(), problem.getMessage())); }//ww w .ja va2 s .com } else if (problem.isError()) { hasErrors = true; compilerErrors.add(new CompilerError(new String(problem.getOriginatingFileName()), true, problem.getSourceLineNumber(), problem.getSourceStart(), problem.getSourceLineNumber(), problem.getSourceEnd(), problem.getMessage())); } } } // Write the class files if (!hasErrors) { ClassFile[] classFiles = result.getClassFiles(); for (ClassFile classFile : classFiles) { // Create file and parent directories StringBuffer className = new StringBuffer(); for (char[] name : classFile.getCompoundName()) { if (className.length() != 0) { className.append('.'); } className.append(name); } File file = new File(outputDirectory, className.toString().replace('.', '/') + ".class"); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } // Write class file contents FileOutputStream fos = null; try { fos = new FileOutputStream(file); fos.write(classFile.getBytes()); } catch (FileNotFoundException e) { throw new IllegalArgumentException(e); } catch (IOException e) { throw new IllegalArgumentException(e); } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { } } } } } }
From source file:org.auroraide.server.jci.compilers.EclipseJavaCompiler.java
License:Apache License
public org.apache.commons.jci.compilers.CompilationResult compile(final String[] pSourceFiles, final ResourceReader pReader, final ResourceStore pStore, final ClassLoader pClassLoader, final JavaCompilerSettings pSettings) { final Map<?, ?> settingsMap = ((EclipseJavaCompilerSettings) defaultSettings).getMap(); final Collection<CompilationProblem> problems = new ArrayList<CompilationProblem>(); final ICompilationUnit[] compilationUnits = new ICompilationUnit[pSourceFiles.length]; for (int i = 0; i < compilationUnits.length; i++) { final String sourceFile = pSourceFiles[i]; if (pReader.isAvailable(sourceFile)) { compilationUnits[i] = new CompilationUnit(pReader, sourceFile); log.debug("compiling " + sourceFile); } else {/* w w w . j a va2s . c o m*/ // log.error("source not found " + sourceFile); final CompilationProblem problem = new CompilationProblem() { public int getEndColumn() { return 0; } public int getEndLine() { return 0; } public String getFileName() { return sourceFile; } public String getMessage() { return "Source " + sourceFile + " could not be found"; } public int getStartColumn() { return 0; } public int getStartLine() { return 0; } public boolean isError() { return true; } public String toString() { return getMessage(); } }; if (problemHandler != null) { problemHandler.handle(problem); } problems.add(problem); } } if (problems.size() > 0) { final CompilationProblem[] result = new CompilationProblem[problems.size()]; problems.toArray(result); return new org.apache.commons.jci.compilers.CompilationResult(result); } final IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems(); final IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault()); final INameEnvironment nameEnvironment = new INameEnvironment() { public NameEnvironmentAnswer findType(final char[][] pCompoundTypeName) { final StringBuffer result = new StringBuffer(); for (int i = 0; i < pCompoundTypeName.length; i++) { if (i != 0) { result.append('.'); } result.append(pCompoundTypeName[i]); } //log.debug("finding compoundTypeName=" + result.toString()); return findType(result.toString()); } public NameEnvironmentAnswer findType(final char[] pTypeName, final char[][] pPackageName) { final StringBuffer result = new StringBuffer(); for (int i = 0; i < pPackageName.length; i++) { result.append(pPackageName[i]); result.append('.'); } // log.debug("finding typeName=" + new String(typeName) + " packageName=" + result.toString()); result.append(pTypeName); return findType(result.toString()); } private NameEnvironmentAnswer findType(final String pClazzName) { if (isPackage(pClazzName)) { return null; } log.debug("finding " + pClazzName); final String resourceName = ConversionUtils.convertClassToResourcePath(pClazzName); final byte[] clazzBytes = pStore.read(pClazzName); if (clazzBytes != null) { log.debug("loading from store " + pClazzName); final char[] fileName = pClazzName.toCharArray(); try { final ClassFileReader classFileReader = new ClassFileReader(clazzBytes, fileName, true); return new NameEnvironmentAnswer(classFileReader, null); } catch (final ClassFormatException e) { log.error("wrong class format", e); return null; } } log.debug("not in store " + pClazzName); final InputStream is = pClassLoader.getResourceAsStream(resourceName); if (is == null) { log.debug("class " + pClazzName + " not found"); return null; } final byte[] buffer = new byte[8192]; final ByteArrayOutputStream baos = new ByteArrayOutputStream(buffer.length); int count; try { while ((count = is.read(buffer, 0, buffer.length)) > 0) { baos.write(buffer, 0, count); } baos.flush(); final char[] fileName = pClazzName.toCharArray(); final ClassFileReader classFileReader = new ClassFileReader(baos.toByteArray(), fileName, true); return new NameEnvironmentAnswer(classFileReader, null); } catch (final IOException e) { log.error("could not read class", e); return null; } catch (final ClassFormatException e) { log.error("wrong class format", e); return null; } finally { try { baos.close(); } catch (final IOException oe) { log.error("could not close output stream", oe); } try { is.close(); } catch (final IOException ie) { log.error("could not close input stream", ie); } } } private boolean isPackage(final String pClazzName) { final InputStream is = pClassLoader .getResourceAsStream(ConversionUtils.convertClassToResourcePath(pClazzName)); if (is != null) { log.debug("found the class for " + pClazzName + "- no package"); return false; } // FIXME: this should not be tied to the extension final String source = pClazzName.replace('.', '/') + ".java"; if (pReader.isAvailable(source)) { log.debug("found the source " + source + " for " + pClazzName + " - no package "); return false; } return true; } public boolean isPackage(char[][] parentPackageName, char[] pPackageName) { final StringBuffer result = new StringBuffer(); if (parentPackageName != null) { for (int i = 0; i < parentPackageName.length; i++) { if (i != 0) { result.append('.'); } result.append(parentPackageName[i]); } } // log.debug("isPackage parentPackageName=" + result.toString() + " packageName=" + new String(packageName)); if (parentPackageName != null && parentPackageName.length > 0) { result.append('.'); } result.append(pPackageName); return isPackage(result.toString()); } public void cleanup() { log.debug("cleanup"); } }; final ICompilerRequestor compilerRequestor = new ICompilerRequestor() { public void acceptResult(final CompilationResult pResult) { if (pResult.hasProblems()) { final IProblem[] iproblems = pResult.getProblems(); for (int i = 0; i < iproblems.length; i++) { final IProblem iproblem = iproblems[i]; final CompilationProblem problem = new EclipseCompilationProblem(iproblem); if (problemHandler != null) { problemHandler.handle(problem); } problems.add(problem); } } if (!pResult.hasErrors()) { final ClassFile[] clazzFiles = pResult.getClassFiles(); for (int i = 0; i < clazzFiles.length; i++) { final ClassFile clazzFile = clazzFiles[i]; final char[][] compoundName = clazzFile.getCompoundName(); final StringBuffer clazzName = new StringBuffer(); for (int j = 0; j < compoundName.length; j++) { if (j != 0) { clazzName.append('.'); } clazzName.append(compoundName[j]); } pStore.write(clazzName.toString().replace('.', '/') + ".class", clazzFile.getBytes()); } } } }; final Compiler compiler = new Compiler(nameEnvironment, policy, settingsMap, compilerRequestor, problemFactory, false); compiler.compile(compilationUnits); final CompilationProblem[] result = new CompilationProblem[problems.size()]; problems.toArray(result); return new org.apache.commons.jci.compilers.CompilationResult(result); }
From source file:org.drools.commons.jci.compilers.EclipseJavaCompiler.java
License:Apache License
public org.drools.commons.jci.compilers.CompilationResult compile(final String[] pSourceFiles, final ResourceReader pReader, final ResourceStore pStore, final ClassLoader pClassLoader, final JavaCompilerSettings pSettings) { final Map settingsMap = new EclipseJavaCompilerSettings(pSettings).toNativeSettings(); final Collection problems = new ArrayList(); final ICompilationUnit[] compilationUnits = new ICompilationUnit[pSourceFiles.length]; for (int i = 0; i < compilationUnits.length; i++) { final String sourceFile = pSourceFiles[i]; if (pReader.isAvailable(sourceFile)) { compilationUnits[i] = new CompilationUnit(pReader, sourceFile); } else {//from w ww.j a v a 2 s. c o m // log.error("source not found " + sourceFile); final CompilationProblem problem = new CompilationProblem() { public int getEndColumn() { return 0; } public int getEndLine() { return 0; } public String getFileName() { return sourceFile; } public String getMessage() { return "Source " + sourceFile + " could not be found"; } public int getStartColumn() { return 0; } public int getStartLine() { return 0; } public boolean isError() { return true; } public String toString() { return getMessage(); } }; if (problemHandler != null) { problemHandler.handle(problem); } problems.add(problem); } } if (problems.size() > 0) { final CompilationProblem[] result = new CompilationProblem[problems.size()]; problems.toArray(result); return new org.drools.commons.jci.compilers.CompilationResult(result); } final IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.proceedWithAllProblems(); final IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault()); final INameEnvironment nameEnvironment = new INameEnvironment() { public NameEnvironmentAnswer findType(final char[][] pCompoundTypeName) { final StringBuilder result = new StringBuilder(); for (int i = 0; i < pCompoundTypeName.length; i++) { if (i != 0) { result.append('.'); } result.append(pCompoundTypeName[i]); } //log.debug("finding compoundTypeName=" + result.toString()); return findType(result.toString()); } public NameEnvironmentAnswer findType(final char[] pTypeName, final char[][] pPackageName) { final StringBuilder result = new StringBuilder(); for (int i = 0; i < pPackageName.length; i++) { result.append(pPackageName[i]); result.append('.'); } // log.debug("finding typeName=" + new String(typeName) + " packageName=" + result.toString()); result.append(pTypeName); return findType(result.toString()); } private NameEnvironmentAnswer findType(final String pClazzName) { final String resourceName = ClassUtils.convertClassToResourcePath(pClazzName); final byte[] clazzBytes = pStore.read(resourceName); if (clazzBytes != null) { try { return createNameEnvironmentAnswer(pClazzName, clazzBytes); } catch (final ClassFormatException e) { throw new RuntimeException( "ClassFormatException in loading class '" + pClazzName + "' with JCI."); } } InputStream is = null; ByteArrayOutputStream baos = null; try { is = pClassLoader.getResourceAsStream(resourceName); if (is == null) { return null; } final byte[] buffer = new byte[8192]; baos = new ByteArrayOutputStream(buffer.length); int count; while ((count = is.read(buffer, 0, buffer.length)) > 0) { baos.write(buffer, 0, count); } baos.flush(); return createNameEnvironmentAnswer(pClazzName, baos.toByteArray()); } catch (final IOException e) { throw new RuntimeException("could not read class", e); } catch (final ClassFormatException e) { throw new RuntimeException("wrong class format", e); } finally { try { if (baos != null) { baos.close(); } } catch (final IOException oe) { throw new RuntimeException("could not close output stream", oe); } try { if (is != null) { is.close(); } } catch (final IOException ie) { throw new RuntimeException("could not close input stream", ie); } } } private NameEnvironmentAnswer createNameEnvironmentAnswer(final String pClazzName, final byte[] clazzBytes) throws ClassFormatException { final char[] fileName = pClazzName.toCharArray(); final ClassFileReader classFileReader = new ClassFileReader(clazzBytes, fileName, true); return new NameEnvironmentAnswer(classFileReader, null); } private boolean isSourceAvailable(final String pClazzName, final ResourceReader pReader) { // FIXME: this should not be tied to the extension final String source = pClazzName.replace('.', '/') + ".java"; return pReader.isAvailable(source); } private boolean isPackage(final String pClazzName) { InputStream is = null; try { is = pClassLoader.getResourceAsStream(ClassUtils.convertClassToResourcePath(pClazzName)); return is == null && !isSourceAvailable(pClazzName, pReader); } finally { if (is != null) { try { is.close(); } catch (IOException e) { throw new RuntimeException("Unable to close stream for resource: " + pClazzName); } } } } public boolean isPackage(char[][] parentPackageName, char[] pPackageName) { final StringBuilder result = new StringBuilder(); if (parentPackageName != null) { for (int i = 0; i < parentPackageName.length; i++) { if (i != 0) { result.append('.'); } result.append(parentPackageName[i]); } } // log.debug("isPackage parentPackageName=" + result.toString() + " packageName=" + new String(packageName)); if (parentPackageName != null && parentPackageName.length > 0) { result.append('.'); } result.append(pPackageName); return isPackage(result.toString()); } public void cleanup() { } }; final ICompilerRequestor compilerRequestor = new ICompilerRequestor() { public void acceptResult(final CompilationResult pResult) { if (pResult.hasProblems()) { final IProblem[] iproblems = pResult.getProblems(); for (int i = 0; i < iproblems.length; i++) { final IProblem iproblem = iproblems[i]; final CompilationProblem problem = new EclipseCompilationProblem(iproblem); if (problemHandler != null) { problemHandler.handle(problem); } problems.add(problem); } } if (!pResult.hasErrors()) { final ClassFile[] clazzFiles = pResult.getClassFiles(); for (int i = 0; i < clazzFiles.length; i++) { final ClassFile clazzFile = clazzFiles[i]; final char[][] compoundName = clazzFile.getCompoundName(); final StringBuilder clazzName = new StringBuilder(); for (int j = 0; j < compoundName.length; j++) { if (j != 0) { clazzName.append('.'); } clazzName.append(compoundName[j]); } pStore.write(clazzName.toString().replace('.', '/') + ".class", clazzFile.getBytes()); } } } }; final Compiler compiler = new Compiler(nameEnvironment, policy, settingsMap, compilerRequestor, problemFactory, false); compiler.compile(compilationUnits); final CompilationProblem[] result = new CompilationProblem[problems.size()]; problems.toArray(result); return new org.drools.commons.jci.compilers.CompilationResult(result); }