diff --git a/jps/.idea/inspectionProfiles/profiles_settings.xml b/jps/.idea/inspectionProfiles/profiles_settings.xml index 9ae8684e375e..24c0574ce220 100644 --- a/jps/.idea/inspectionProfiles/profiles_settings.xml +++ b/jps/.idea/inspectionProfiles/profiles_settings.xml @@ -1,11 +1,12 @@ - + - - - - + + + + + \ No newline at end of file diff --git a/jps/.idea/libraries/Javac2.xml b/jps/.idea/libraries/Javac2.xml index bdf5e5bfa822..d478577bdeea 100644 --- a/jps/.idea/libraries/Javac2.xml +++ b/jps/.idea/libraries/Javac2.xml @@ -1,15 +1,11 @@ - - - - - + - + \ No newline at end of file diff --git a/jps/.idea/misc.xml b/jps/.idea/misc.xml index 1c91dd1a2eb5..513d1dec1c76 100644 --- a/jps/.idea/misc.xml +++ b/jps/.idea/misc.xml @@ -1,8 +1,5 @@ - - diff --git a/jps/.idea/scopes/scope_settings.xml b/jps/.idea/scopes/scope_settings.xml new file mode 100644 index 000000000000..922003b8433b --- /dev/null +++ b/jps/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/jps/lib/javac2-all.jar b/jps/lib/javac2-all.jar index 7b4c10aa3eaa..5f7f2ae671cb 100644 Binary files a/jps/lib/javac2-all.jar and b/jps/lib/javac2-all.jar differ diff --git a/jps/src/org/jetbrains/ether/Pair.java b/jps/src/org/jetbrains/ether/Pair.java new file mode 100644 index 000000000000..2feb50239939 --- /dev/null +++ b/jps/src/org/jetbrains/ether/Pair.java @@ -0,0 +1,18 @@ +package org.jetbrains.ether; + +/** + * Created by IntelliJ IDEA. + * User: db + * Date: 19.06.11 + * Time: 16:48 + * To change this template use File | Settings | File Templates. + */ +public class Pair { + public final X fst; + public final Y snd; + + public Pair(final X fst, final Y snd) { + this.fst = fst; + this.snd = snd; + } +} diff --git a/jps/src/org/jetbrains/ether/dependencyView/ClassRepr.java b/jps/src/org/jetbrains/ether/dependencyView/ClassRepr.java index a45d97fcfbdc..56a60bd872d8 100644 --- a/jps/src/org/jetbrains/ether/dependencyView/ClassRepr.java +++ b/jps/src/org/jetbrains/ether/dependencyView/ClassRepr.java @@ -1,12 +1,12 @@ package org.jetbrains.ether.dependencyView; -import com.sun.tools.javac.util.Pair; import org.jetbrains.ether.RW; -import org.objectweb.asm.Opcodes; import java.io.BufferedReader; import java.io.BufferedWriter; -import java.util.*; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; /** * Created by IntelliJ IDEA. @@ -27,12 +27,15 @@ public class ClassRepr extends Proto { public abstract class Diff extends Difference { public abstract Difference.Specifier interfaces(); + public abstract Difference.Specifier nestedClasses(); + public abstract Difference.Specifier fields(); + public abstract Difference.Specifier methods(); } - public Diff difference (final Proto past) { + public Diff difference(final Proto past) { final ClassRepr pastClass = (ClassRepr) past; int diff = super.difference(past).base(); @@ -53,11 +56,11 @@ public class ClassRepr extends Proto { } public Difference.Specifier fields() { - return Difference.make (pastClass.fields, fields); + return Difference.make(pastClass.fields, fields); } public Difference.Specifier methods() { - return Difference.make (pastClass.methods, methods); + return Difference.make(pastClass.methods, methods); } public int base() { @@ -89,7 +92,7 @@ public class ClassRepr extends Proto { } } - public ClassRepr (final int a, final StringCache.S sn, final StringCache.S fn, final StringCache.S n, final StringCache.S sig, final String sup, final String[] i, final Collection ns, final Set f, final Set m) { + public ClassRepr(final int a, final StringCache.S sn, final StringCache.S fn, final StringCache.S n, final StringCache.S sig, final String sup, final String[] i, final Collection ns, final Set f, final Set m) { super(a, sig, n); fileName = fn; sourceFileName = sn; @@ -98,7 +101,7 @@ public class ClassRepr extends Proto { nestedClasses = (Set) TypeRepr.createClassType(ns, new HashSet()); fields = f; methods = m; - } + } public ClassRepr(final BufferedReader r) { super(r); @@ -147,7 +150,7 @@ public class ClassRepr extends Proto { return result; } - public UsageRepr.Usage createUsage () { + public UsageRepr.Usage createUsage() { return UsageRepr.createClassUsage(name); } diff --git a/jps/src/org/jetbrains/ether/dependencyView/ClassfileAnalyzer.java b/jps/src/org/jetbrains/ether/dependencyView/ClassfileAnalyzer.java index e8132efdc86b..68becb19dd3f 100644 --- a/jps/src/org/jetbrains/ether/dependencyView/ClassfileAnalyzer.java +++ b/jps/src/org/jetbrains/ether/dependencyView/ClassfileAnalyzer.java @@ -1,6 +1,6 @@ package org.jetbrains.ether.dependencyView; -import com.sun.tools.javac.util.Pair; +import org.jetbrains.ether.Pair; import org.objectweb.asm.*; import org.objectweb.asm.commons.EmptyVisitor; import org.objectweb.asm.signature.SignatureReader; @@ -23,12 +23,12 @@ public class ClassfileAnalyzer { private static class ClassCrawler extends EmptyVisitor { - private void processSignature (final String sig) { + private void processSignature(final String sig) { if (sig != null) new SignatureReader(sig).accept(signatureCrawler); } - private final SignatureVisitor signatureCrawler = new SignatureVisitor () { + private final SignatureVisitor signatureCrawler = new SignatureVisitor() { public void visitFormalTypeParameter(String name) { } @@ -127,7 +127,7 @@ public class ClassfileAnalyzer { takeIntoAccount = notPrivate(a); access = a; - name = StringCache.get (n); + name = StringCache.get(n); signature = sig; superClass = s; interfaces = i; @@ -137,7 +137,7 @@ public class ClassfileAnalyzer { @Override public void visitSource(String source, String debug) { - sourceFile = StringCache.get (source); + sourceFile = StringCache.get(source); } @Override @@ -208,7 +208,7 @@ public class ClassfileAnalyzer { } } - public static Pair> analyze(final StringCache.S fileName, final ClassReader cr) { + public static Pair> analyze(final StringCache.S fileName, final ClassReader cr) { final ClassCrawler visitor = new ClassCrawler(fileName); cr.accept(visitor, 0); diff --git a/jps/src/org/jetbrains/ether/dependencyView/Difference.java b/jps/src/org/jetbrains/ether/dependencyView/Difference.java index 3810c16ea680..a79b00cfe7ba 100644 --- a/jps/src/org/jetbrains/ether/dependencyView/Difference.java +++ b/jps/src/org/jetbrains/ether/dependencyView/Difference.java @@ -1,6 +1,6 @@ package org.jetbrains.ether.dependencyView; -import com.sun.tools.javac.util.Pair; +import org.jetbrains.ether.Pair; import java.util.*; diff --git a/jps/src/org/jetbrains/ether/dependencyView/Mappings.java b/jps/src/org/jetbrains/ether/dependencyView/Mappings.java index aa1d939c5a71..bc5291c011b9 100644 --- a/jps/src/org/jetbrains/ether/dependencyView/Mappings.java +++ b/jps/src/org/jetbrains/ether/dependencyView/Mappings.java @@ -1,6 +1,6 @@ package org.jetbrains.ether.dependencyView; -import com.sun.tools.javac.util.Pair; +import org.jetbrains.ether.Pair; import org.jetbrains.ether.ProjectWrapper; import org.objectweb.asm.ClassReader; import org.objectweb.asm.Opcodes; diff --git a/jps/src/org/jetbrains/jps/builders/StandardBuilders.groovy b/jps/src/org/jetbrains/jps/builders/StandardBuilders.groovy index 0e2d8e309ef6..4c1ff8432d29 100644 --- a/jps/src/org/jetbrains/jps/builders/StandardBuilders.groovy +++ b/jps/src/org/jetbrains/jps/builders/StandardBuilders.groovy @@ -16,370 +16,388 @@ import org.jetbrains.jps.* */ class JavacBuilder implements ModuleBuilder, ModuleCycleBuilder { - def preprocessModuleCycle(ModuleBuildState state, ModuleChunk moduleChunk, Project project) { - doBuildModule(moduleChunk, state) - } - - def processModule(ModuleBuildState state, ModuleChunk moduleChunk, Project project) { - doBuildModule(moduleChunk, state) - } - - def doBuildModule(ModuleChunk module, ModuleBuildState state) { - if (state.sourceRoots.isEmpty()) return; - - String sourceLevel = module["sourceLevel"] - String targetLevel = module["targetLevel"] - String customArgs = module["javac_args"]; // it seems javac_args property is not set, can we drop it? - if (module.project.builder.useInProcessJavac) { - String version = System.getProperty("java.version") - if (true) { - if (Java16ApiCompilerRunner.compile(module, state, sourceLevel, targetLevel, customArgs)) { - return - } - } - else { - module.project.info("In-process Javac won't be used for '${module.name}', because Java version ($version) doesn't match to source level ($sourceLevel)") - } + def preprocessModuleCycle(ModuleBuildState state, ModuleChunk moduleChunk, Project project) { + doBuildModule(moduleChunk, state) } - def params = [:] - params.destdir = state.targetFolder - if (sourceLevel != null) params.source = sourceLevel - if (targetLevel != null) params.target = targetLevel - - def javacOpts = module.project.props["compiler.javac.options"]; - def memHeapSize = javacOpts["MAXIMUM_HEAP_SIZE"] == null ? "512m" : javacOpts["MAXIMUM_HEAP_SIZE"] + "m"; - def boolean debugInfo = !"false".equals(javacOpts["DEBUGGING_INFO"]); - def boolean nowarn = "true".equals(javacOpts["GENERATE_NO_WARNINGS"]); - def boolean deprecation = !"false".equals(javacOpts["DEPRECATION"]); - customArgs = javacOpts["ADDITIONAL_OPTIONS_STRING"]; - - params.fork = "true" - params.memoryMaximumSize = memHeapSize; - params.debug = String.valueOf(debugInfo); - params.nowarn = String.valueOf(nowarn); - params.deprecation = String.valueOf(deprecation); - params.verbose = "true" - - def javacExecutable = getJavacExecutable(module) - if (javacExecutable != null) { - params.executable = javacExecutable + def processModule(ModuleBuildState state, ModuleChunk moduleChunk, Project project) { + doBuildModule(moduleChunk, state) } - def ant = module.project.binding.ant + def doBuildModule(ModuleChunk module, ModuleBuildState state) { + if (state.sourceRoots.isEmpty()) return; - final BuildListener listener = new AntListener(state.targetFolder, state.sourceRoots, state.callback); - - ant.project.addBuildListener(listener); - - ant.javac(params) { - if (customArgs) { - compilerarg(line: customArgs) - } - - if (state.sourceFiles != null) { - List patterns = [] - - state.sourceFiles.each { - for (String root: state.sourceRoots) { - if (it.startsWith(root) && it.endsWith(".java")) { - patterns << it.substring(root.length() + 1) - break; + String sourceLevel = module["sourceLevel"] + String targetLevel = module["targetLevel"] + String customArgs = module["javac_args"]; // it seems javac_args property is not set, can we drop it? + if (module.project.builder.useInProcessJavac) { + String version = System.getProperty("java.version") + if (true) { + if (Java16ApiCompilerRunner.compile(module, state, sourceLevel, targetLevel, customArgs)) { + return + } + } + else { + module.project.info("In-process Javac won't be used for '${module.name}', because Java version ($version) doesn't match to source level ($sourceLevel)") } - } - - patterns.each { - include(name: it) - } } - } - state.sourceRoots.each { - src(path: it) - } + def params = [:] + params.destdir = state.targetFolder + if (sourceLevel != null) params.source = sourceLevel + if (targetLevel != null) params.target = targetLevel - state.excludes.each { String root -> - state.sourceRoots.each {String src -> - if (root.startsWith("${src}/")) { - exclude(name: "${root.substring(src.length() + 1)}/**") - } + def javacOpts = module.project.props["compiler.javac.options"]; + def memHeapSize = javacOpts["MAXIMUM_HEAP_SIZE"] == null ? "512m" : javacOpts["MAXIMUM_HEAP_SIZE"] + "m"; + def boolean debugInfo = !"false".equals(javacOpts["DEBUGGING_INFO"]); + def boolean nowarn = "true".equals(javacOpts["GENERATE_NO_WARNINGS"]); + def boolean deprecation = !"false".equals(javacOpts["DEPRECATION"]); + customArgs = javacOpts["ADDITIONAL_OPTIONS_STRING"]; + + params.fork = "true" + params.memoryMaximumSize = memHeapSize; + params.debug = String.valueOf(debugInfo); + params.nowarn = String.valueOf(nowarn); + params.deprecation = String.valueOf(deprecation); + params.verbose = "true" + + def javacExecutable = getJavacExecutable(module) + if (javacExecutable != null) { + params.executable = javacExecutable } - } - classpath { - state.classpath.each { - pathelement(location: it) + def ant = module.project.binding.ant + + final BuildListener listener = new AntListener(state.targetFolder, state.sourceRoots, state.callback); + + ant.project.addBuildListener(listener); + + ant.javac(params) { + if (customArgs) { + compilerarg(line: customArgs) + } + + if (state.sourceFiles != null) { + List patterns = [] + + state.sourceFiles.each { + for (String root: state.sourceRoots) { + if (it.startsWith(root) && it.endsWith(".java")) { + patterns << it.substring(root.length() + 1) + break; + } + } + + patterns.each { + include(name: it) + } + } + } + + state.sourceRoots.each { + src(path: it) + } + + state.excludes.each { String root -> + state.sourceRoots.each {String src -> + if (root.startsWith("${src}/")) { + exclude(name: "${root.substring(src.length() + 1)}/**") + } + } + } + + classpath { + state.classpath.each { + pathelement(location: it) + } + } + } + + ant.project.removeBuildListener(listener); + + if (state.sourceFiles != null) { + module.project.builder.listeners*.onJavaFilesCompiled(module, state.sourceFiles.size()) } - } } - ant.project.removeBuildListener(listener); - - if (state.sourceFiles != null) { - module.project.builder.listeners*.onJavaFilesCompiled(module, state.sourceFiles.size()) + private String getJavacExecutable(ModuleChunk module) { + def customJavac = module["javac"] + def jdk = module.getSdk() + if (customJavac != null) { + return customJavac + } + else if (jdk instanceof JavaSdk) { + return jdk.getJavacExecutable() + } + return null } - } - - private String getJavacExecutable(ModuleChunk module) { - def customJavac = module["javac"] - def jdk = module.getSdk() - if (customJavac != null) { - return customJavac - } - else if (jdk instanceof JavaSdk) { - return jdk.getJavacExecutable() - } - return null - } } class ResourceCopier implements ModuleBuilder { - def processModule(ModuleBuildState state, ModuleChunk moduleChunk, Project project) { - if (state.iterated) return; + def processModule(ModuleBuildState state, ModuleChunk moduleChunk, Project project) { + if (state.iterated) return; - state.iterated = true + state.iterated = true - if (state.sourceRoots.isEmpty()) return; + if (state.sourceRoots.isEmpty()) return; - def ant = project.binding.ant + def ant = project.binding.ant - state.sourceRoots.each {String root -> - if (new File(root).exists()) { - def target = state.targetFolder - def prefix = moduleChunk.modules.collect { it.sourceRootPrefixes[root] }.find {it != null} - if (prefix != null) { - if (!(target.endsWith("/") || target.endsWith("\\"))) { - target += "/" - } - target += prefix + state.sourceRoots.each {String root -> + if (new File(root).exists()) { + def target = state.targetFolder + def prefix = moduleChunk.modules.collect { it.sourceRootPrefixes[root] }.find {it != null} + if (prefix != null) { + if (!(target.endsWith("/") || target.endsWith("\\"))) { + target += "/" + } + target += prefix + } + + ant.copy(todir: target) { + fileset(dir: root) { + patternset(refid: moduleChunk["compiler.resources.id"]) + type(type: "file") + } + } + } + else { + project.warning("$root doesn't exist") + } } - - ant.copy(todir: target) { - fileset(dir: root) { - patternset(refid: moduleChunk["compiler.resources.id"]) - type(type: "file") - } - } - } - else { - project.warning("$root doesn't exist") - } } - } } class GroovycBuilder implements ModuleBuilder { - def GroovycBuilder(Project project) { - project.taskdef(name: "groovyc", classname: "org.codehaus.groovy.ant.Groovyc") - } - - def processModule(ModuleBuildState state, ModuleChunk moduleChunk, Project project) { - if (!GroovyFileSearcher.containGroovyFiles(state.sourceRoots)) return - - def ant = project.binding.ant - - final String destDir = state.targetFolder - - ant.touch(millis: 239) { - fileset(dir: destDir) { - include(name: "**/*.class") - } + def GroovycBuilder(Project project) { + project.taskdef(name: "groovyc", classname: "org.codehaus.groovy.ant.Groovyc") } - // unfortunately we have to disable fork here because of a bug in Groovyc task: it creates too long command line if classpath is large - ant.groovyc(destdir: destDir /*, fork: "true"*/) { - state.sourceRoots.each { - src(path: it) - } + def processModule(ModuleBuildState state, ModuleChunk moduleChunk, Project project) { + if (!GroovyFileSearcher.containGroovyFiles(state.sourceRoots)) return - include(name: "**/*.groovy") + def ant = project.binding.ant - classpath { - state.classpath.each { - pathelement(location: it) + final String destDir = state.targetFolder + + ant.touch(millis: 239) { + fileset(dir: destDir) { + include(name: "**/*.class") + } } - pathelement(location: destDir) // Includes classes generated there by javac compiler - } - } + // unfortunately we have to disable fork here because of a bug in Groovyc task: it creates too long command line if classpath is large + ant.groovyc(destdir: destDir /*, fork: "true"*/) { + state.sourceRoots.each { + src(path: it) + } - ant.touch() { - fileset(dir: destDir) { - include(name: "**/*.class") - } + include(name: "**/*.groovy") + + classpath { + state.classpath.each { + pathelement(location: it) + } + + pathelement(location: destDir) // Includes classes generated there by javac compiler + } + } + + ant.touch() { + fileset(dir: destDir) { + include(name: "**/*.class") + } + } } - } } class GroovyStubGenerator implements ModuleBuilder { - def GroovyStubGenerator(Project project) { - project.taskdef(name: "generatestubs", classname: "org.codehaus.groovy.ant.GenerateStubsTask") - } - - def processModule(ModuleBuildState state, ModuleChunk moduleChunk, Project project) { - if (!GroovyFileSearcher.containGroovyFiles(state.sourceRoots)) return - - def ant = project.binding.ant - - String targetFolder = project.targetFolder - File dir = new File(targetFolder != null ? targetFolder : ".", "___temp___") - BuildUtil.deleteDir(project, dir.absolutePath) - ant.mkdir(dir: dir) - - def stubsRoot = dir.getAbsolutePath() - ant.generatestubs(destdir: stubsRoot) { - state.sourceRoots.each { - src(path: it) - } - - include(name: "**/*.groovy") - include(name: "**/*.java") - - classpath { - state.classpath.each { - pathelement(location: it) - } - } + def GroovyStubGenerator(Project project) { + project.taskdef(name: "generatestubs", classname: "org.codehaus.groovy.ant.GenerateStubsTask") } - state.sourceRoots << stubsRoot - state.tempRootsToDelete << stubsRoot - } + def processModule(ModuleBuildState state, ModuleChunk moduleChunk, Project project) { + if (!GroovyFileSearcher.containGroovyFiles(state.sourceRoots)) return + + def ant = project.binding.ant + + String targetFolder = project.targetFolder + File dir = new File(targetFolder != null ? targetFolder : ".", "___temp___") + BuildUtil.deleteDir(project, dir.absolutePath) + ant.mkdir(dir: dir) + + def stubsRoot = dir.getAbsolutePath() + ant.generatestubs(destdir: stubsRoot) { + state.sourceRoots.each { + src(path: it) + } + + include(name: "**/*.groovy") + include(name: "**/*.java") + + classpath { + state.classpath.each { + pathelement(location: it) + } + } + } + + state.sourceRoots << stubsRoot + state.tempRootsToDelete << stubsRoot + } } class JetBrainsInstrumentations implements ModuleBuilder { - class CustomFormInstrumenter extends FormInstrumenter { - final List formFiles; - final ModuleBuildState state; + class CustomFormInstrumenter extends + FormInstrumenter { + final List formFiles; + final ModuleBuildState state; - @Override - void associate(final String formFile, final String classFile) { - if (state.callback != null) { - final String formRelPath = state.projectWrapper.getRelativePath(formFile); - final String classRelPath = state.projectWrapper.getRelativePath(classFile); + @Override + void associate(final String formFile, final String classFile) { + if (state.callback != null) { + final String formRelPath = state.projectWrapper.getRelativePath(formFile); + final String classRelPath = state.projectWrapper.getRelativePath(classFile); - state.callback.associateForm(StringCache.get(formRelPath), StringCache.get(classRelPath)); - } - } - - @Override - void log(String msg, int option) { - System.out.println(msg); - } - - @Override - void fireError(String msg) { - System.err.println(msg); - } - - CustomFormInstrumenter(final File destDir, final List nestedFormPathList, final List ff, final ModuleBuildState s) { - super(destDir, nestedFormPathList); - formFiles = ff; - state = s; - } - } - - def JetBrainsInstrumentations(Project project) { - project.taskdef(name: "jb_instrumentations", classname: "com.intellij.ant.InstrumentIdeaExtensions") - } - - def processModule(ModuleBuildState state, ModuleChunk moduleChunk, Project project) { - if (state.loader == null) { - final StringBuffer cp = new StringBuffer() - - cp.append(state.targetFolder) - cp.append(File.pathSeparator) - - state.classpath.each { - cp.append(it) - cp.append(File.pathSeparator) - } - - state.loader = InstrumentationUtil.createPseudoClassLoader(cp.toString()) - - final List formFiles = new ArrayList(); - final ProjectWrapper pw = state.projectWrapper; - - for (Module m: moduleChunk.elements) { - final Set names = state.tests ? pw.getModule(m.getName()).getTests() : pw.getModule(m.getName()).getSources(); - for (S name: names) { - if (name.value.endsWith(".form")) { - formFiles.add(new File(pw.getAbsolutePath(name.value))); - } - } - } - - final List nestedFormDirs = new ArrayList(); - - state.moduleDependenciesSourceRoots.each { - nestedFormDirs << new PrefixedPath(project.binding.ant.project, it) - } - - state.formInstrumenter = new CustomFormInstrumenter(new File(state.targetFolder), nestedFormDirs, formFiles, state); - - if (!state.incremental) { - for (File formFile: formFiles) { - state.formInstrumenter.instrumentForm(formFile, state.loader); - } - } - } - - if (state.incremental) { - for (String f: state.sourceFiles) { - if (f.endsWith(".form")) { - state.formInstrumenter.instrumentForm(new File(f), state.loader); - } - } - } - - if (project.getBuilder().useInProcessJavac) - return; - - if (!state.incremental) { - new Object() { - public void traverse(final File root) { - final File[] files = root.listFiles(); - - for (File f: files) { - final String name = f.getName(); - - if (name.endsWith(".class")) { - InstrumentationUtil.instrumentNotNull(f, state.loader) + state.callback.associateForm(StringCache.get(formRelPath), StringCache.get(classRelPath)); } - else if (f.isDirectory()) { - traverse(f) - } - } } - }.traverse(new File(state.targetFolder)) - } - else { - final Collection classes = state.callback.getClassFiles() - classes.each { - InstrumentationUtil.instrumentNotNull(new File(state.targetFolder + File.separator + it.value + ".class"), state.loader) - } + @Override + void log(String msg, int option) { + System.out.println(msg); + } + + @Override + void fireError(String msg) { + throw new RuntimeException(msg); + } + + CustomFormInstrumenter(final File destDir, final List nestedFormPathList, final List ff, final ModuleBuildState s) { + super(destDir, nestedFormPathList); + formFiles = ff; + state = s; + } + } + + def JetBrainsInstrumentations(Project project) { + project.taskdef(name: "jb_instrumentations", classname: "com.intellij.ant.InstrumentIdeaExtensions") + } + + def getPrefixedPath(Project project, String root, ModuleChunk moduleChunk) { + final path = new PrefixedPath(project.binding.ant.project, root) + + moduleChunk.elements.each {module -> + final String prefix = module.sourceRootPrefixes[root] + if (prefix != null) { + path.setPrefix(prefix) + } + } + + return path + } + + def processModule(ModuleBuildState state, ModuleChunk moduleChunk, Project project) { + if (state.loader == null) { + final StringBuffer cp = new StringBuffer() + + cp.append(state.targetFolder) + cp.append(File.pathSeparator) + + state.classpath.each { + cp.append(it) + cp.append(File.pathSeparator) + } + + state.loader = InstrumentationUtil.createPseudoClassLoader(cp.toString()) + + final List formFiles = new ArrayList(); + final ProjectWrapper pw = state.projectWrapper; + + for (Module m: moduleChunk.elements) { + final Set names = state.tests ? pw.getModule(m.getName()).getTests() : pw.getModule(m.getName()).getSources(); + for (S name: names) { + if (name.value.endsWith(".form")) { + formFiles.add(new File(pw.getAbsolutePath(name.value))); + } + } + } + + final List nestedFormDirs = new ArrayList(); + + state.sourceRoots.each { + nestedFormDirs << getPrefixedPath(project, it, moduleChunk) + } + + state.moduleDependenciesSourceRoots.each { + nestedFormDirs << getPrefixedPath(project, it, moduleChunk) + } + + state.formInstrumenter = new CustomFormInstrumenter(new File(state.targetFolder), nestedFormDirs, formFiles, state); + + if (!state.incremental) { + for (File formFile: formFiles) { + state.formInstrumenter.instrumentForm(formFile, state.loader); + } + } + } + + if (state.incremental) { + for (String f: state.sourceFiles) { + if (f.endsWith(".form")) { + state.formInstrumenter.instrumentForm(new File(f), state.loader); + } + } + } + + if (project.getBuilder().useInProcessJavac) + return; + + if (!state.incremental) { + new Object() { + public void traverse(final File root) { + final File[] files = root.listFiles(); + + for (File f: files) { + final String name = f.getName(); + + if (name.endsWith(".class")) { + InstrumentationUtil.instrumentNotNull(f, state.loader) + } + else if (f.isDirectory()) { + traverse(f) + } + } + } + }.traverse(new File(state.targetFolder)) + } + else { + final Collection classes = state.callback.getClassFiles() + + classes.each { + InstrumentationUtil.instrumentNotNull(new File(state.targetFolder + File.separator + it.value + ".class"), state.loader) + } + } } - } } class CustomTasksBuilder implements ModuleBuilder { - List tasks = [] + List tasks = [] - def processModule(ModuleBuildState state, ModuleChunk moduleChunk, Project project) { - moduleChunk.modules.each {Module module -> - tasks*.perform(module, state.targetFolder) + def processModule(ModuleBuildState state, ModuleChunk moduleChunk, Project project) { + moduleChunk.modules.each {Module module -> + tasks*.perform(module, state.targetFolder) + } } - } - def registerTask(String moduleName, Closure task) { - tasks << ({Module module, String outputFolder -> - if (module.name == moduleName) { - task(module, outputFolder) - } - } as ModuleBuildTask) - } + def registerTask(String moduleName, Closure task) { + tasks << ({Module module, String outputFolder -> + if (module.name == moduleName) { + task(module, outputFolder) + } + } as ModuleBuildTask) + } } \ No newline at end of file diff --git a/jps/src/org/jetbrains/jps/builders/javacApi/Java16ApiCompiler.groovy b/jps/src/org/jetbrains/jps/builders/javacApi/Java16ApiCompiler.groovy index e705c4ef0261..400d3aa6f8a1 100644 --- a/jps/src/org/jetbrains/jps/builders/javacApi/Java16ApiCompiler.groovy +++ b/jps/src/org/jetbrains/jps/builders/javacApi/Java16ApiCompiler.groovy @@ -16,101 +16,98 @@ import org.jetbrains.jps.builders.JavaFileCollector * @author nik */ class Java16ApiCompiler { - private static instance - private OptimizedFileManager fileManager - private JavaCompiler compiler + private static instance + private OptimizedFileManager fileManager + private JavaCompiler compiler - static Java16ApiCompiler getInstance() { - if (instance == null) { - instance = new Java16ApiCompiler() - } - return instance - } - - def Java16ApiCompiler() { - compiler = ToolProvider.getSystemJavaCompiler() - fileManager = new OptimizedFileManager(); - } - - def compile(ModuleChunk chunk, ModuleBuildState state, String sourceLevel, String targetLevel, String customArgs) { - List options = [] - - if (customArgs != null) { - options << customArgs - } - - if (sourceLevel != null) { - options << "-source" - options << sourceLevel - } - if (targetLevel != null) { - options << "-target" - options << targetLevel - } - options << "-g" - options << "-nowarn" - - List filesToCompile = [] - - if (state.sourceFiles.size() > 0) { - for (String src: state.sourceFiles) { - if (src.endsWith(".java")) { - filesToCompile << new File(src) + static Java16ApiCompiler getInstance() { + if (instance == null) { + instance = new Java16ApiCompiler() } - } - } - else { - Set excluded = state.excludes.collect { new File(it.toString()) } - state.sourceRoots.each { - JavaFileCollector.collectRecursively(new File(it.toString()), filesToCompile, excluded) - } + return instance } - if (filesToCompile.size() > 0) { - fileManager.setLocation(StandardLocation.CLASS_OUTPUT, [new File(state.targetFolder)]) - List classpath = [] - List bootclasspath = [] - StringBuffer cp = new StringBuffer() - - Sdk sdk = chunk.getSdk() - - if (sdk != null) { - sdk.classpath.each { bootclasspath << new File(String.valueOf(it)) } - - fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, bootclasspath) - } - - state.classpath.each { - classpath << new File(String.valueOf(it)) - cp.append(String.valueOf(it)) - cp.append(File.pathSeparator) - } - - cp.append(state.targetFolder) - - fileManager.setLocation(StandardLocation.CLASS_PATH, classpath) - - System.out.println("Chunk: " + chunk.toString() + " Classpath: " + cp.toString()); - - fileManager.setProperties(state.callback, InstrumentationUtil.createPseudoClassLoader(cp.toString())) - - Iterable toCompile = fileManager.getJavaFileObjectsFromFiles(filesToCompile) - Project project = chunk.project - StringWriter out = new StringWriter() - CompilationTask task = compiler.getTask(new PrintWriter(out), fileManager, null, options, null, toCompile) - - if (!task.call()) { - project.builder.buildInfoPrinter.printCompilationErrors(project, "javac", out.toString()) - project.error("Compilation failed") - } - else { - System.out.println(out.toString()); - } - project.builder.listeners*.onJavaFilesCompiled(chunk, filesToCompile.size()) + def Java16ApiCompiler() { + compiler = ToolProvider.getSystemJavaCompiler() + fileManager = new OptimizedFileManager(); } - else { - chunk.project.info("No java source files found in '${chunk.name}', skipping compilation") + + def compile(ModuleChunk chunk, ModuleBuildState state, String sourceLevel, String targetLevel, String customArgs) { + List options = [] + + if (customArgs != null) { + options << customArgs + } + + if (sourceLevel != null) { + options << "-source" + options << sourceLevel + } + if (targetLevel != null) { + options << "-target" + options << targetLevel + } + options << "-g" + options << "-nowarn" + + List filesToCompile = [] + + if (state.sourceFiles.size() > 0) { + for (String src: state.sourceFiles) { + if (src.endsWith(".java")) { + filesToCompile << new File(src) + } + } + } + else { + Set excluded = state.excludes.collect { new File(it.toString()) } + state.sourceRoots.each { + JavaFileCollector.collectRecursively(new File(it.toString()), filesToCompile, excluded) + } + } + + if (filesToCompile.size() > 0) { + fileManager.setLocation(StandardLocation.CLASS_OUTPUT, [new File(state.targetFolder)]) + List classpath = [] + List bootclasspath = [] + StringBuffer cp = new StringBuffer() + + Sdk sdk = chunk.getSdk() + + if (sdk != null) { + sdk.classpath.each { bootclasspath << new File(String.valueOf(it)) } + + fileManager.setLocation(StandardLocation.PLATFORM_CLASS_PATH, bootclasspath) + } + + state.classpath.each { + classpath << new File(String.valueOf(it)) + cp.append(String.valueOf(it)) + cp.append(File.pathSeparator) + } + + cp.append(state.targetFolder) + + fileManager.setLocation(StandardLocation.CLASS_PATH, classpath) + fileManager.setProperties(state.callback, InstrumentationUtil.createPseudoClassLoader(cp.toString())) + + Iterable toCompile = fileManager.getJavaFileObjectsFromFiles(filesToCompile) + Project project = chunk.project + StringWriter out = new StringWriter() + CompilationTask task = compiler.getTask(new PrintWriter(out), fileManager, null, options, null, toCompile) + + if (!task.call()) { + project.builder.buildInfoPrinter.printCompilationErrors(project, "javac", out.toString()) + project.error("Compilation failed") + } + else { + System.out.println(out.toString()); + } + project.builder.listeners*.onJavaFilesCompiled(chunk, filesToCompile.size()) + } + else { + chunk.project.info("No java source files found in '${chunk.name}', skipping compilation") + } } - } } diff --git a/jps/src/org/jetbrains/jps/builders/javacApi/OptimizedFileManager.java b/jps/src/org/jetbrains/jps/builders/javacApi/OptimizedFileManager.java index 75cbcc5cd875..61c4ab7bdcb8 100644 --- a/jps/src/org/jetbrains/jps/builders/javacApi/OptimizedFileManager.java +++ b/jps/src/org/jetbrains/jps/builders/javacApi/OptimizedFileManager.java @@ -210,8 +210,8 @@ public class OptimizedFileManager extends DefaultFileManager { myWriters.add(new DelayedClassFileWriter() { public void commit() throws IOException { final OutputStream result = superOpenOutputStream(); - final ClassReader reader = new ClassReader(buffer); - final byte[] instrumented = InstrumentationUtil.instrumentNotNull(reader, loader); + + final byte[] instrumented = InstrumentationUtil.instrumentNotNull(buffer, loader); if (instrumented != null) { result.write(instrumented);