public boolean doCompile(Collection<CompilationUnitBuilder> builders) { List<ICompilationUnit> icus = new ArrayList<ICompilationUnit>(); for (CompilationUnitBuilder builder : builders) { addPackages(Shared.getPackageName(builder.getTypeName()).replace('.', '/')); icus.add(new Adapter(builder)); } if (icus.isEmpty()) { return false; } compilerImpl = new CompilerImpl(); compilerImpl.compile(icus.toArray(new ICompilationUnit[icus.size()])); compilerImpl = null; return true; }
private static Set<String> readPackages() { HashSet<String> pkgs = new HashSet<String>(); String klass = "java/lang/Object.class"; URL url = ClassLoader.getSystemClassLoader().getResource(klass); try { JarURLConnection connection = (JarURLConnection) url.openConnection(); JarFile f = connection.getJarFile(); Enumeration<JarEntry> entries = f.entries(); while (entries.hasMoreElements()) { JarEntry e = entries.nextElement(); String name = e.getName(); if (name.endsWith(".class")) { String pkg = Shared.getSlashedPackageFrom(name); addPackageRecursively(pkgs, pkg); } } return pkgs; } catch (IOException e) { throw new InternalCompilerException("Unable to find JRE", e); } }
public void addCompiledUnit(CompilationUnit unit) { addPackages(Shared.getPackageName(unit.getTypeName()).replace('.', '/')); addBinaryTypes(unit.getCompiledClasses()); }
@Override public char[][] getPackageName() { String packageName = Shared.getPackageName(builder.getTypeName()); return CharOperation.splitOn('.', packageName.toCharArray()); }
@Override public char[] getMainTypeName() { return Shared.getShortName(builder.getTypeName()).toCharArray(); }