From 76df08f75f1a234da30a4ad029a46ba05e27984b Mon Sep 17 00:00:00 2001 From: Dmitry Boulytchev Date: Sat, 25 Jun 2011 02:28:18 +0400 Subject: [PATCH] Fixed tests. --- jps/.idea/misc.xml | 111 ++- jps/antLayout/antlayout.iml | 26 +- jps/jps.iml | 42 +- jps/plugins/gwt/gwt.iml | 30 +- jps/plugins/javaee/javaee.iml | 28 +- jps/plugins/jpa/jpa.iml | 28 +- .../org/jetbrains/ether/ProjectWrapper.java | 38 +- .../jps/builders/StandardBuilders.groovy | 806 +++++++++--------- .../org/jetbrains/jps/JpsBuildTestCase.groovy | 112 +-- 9 files changed, 623 insertions(+), 598 deletions(-) diff --git a/jps/.idea/misc.xml b/jps/.idea/misc.xml index ecbc28393039..513d1dec1c76 100644 --- a/jps/.idea/misc.xml +++ b/jps/.idea/misc.xml @@ -1,57 +1,54 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - http://www.w3.org/1999/xhtml - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + http://www.w3.org/1999/xhtml + + + + + + + + diff --git a/jps/antLayout/antlayout.iml b/jps/antLayout/antlayout.iml index 1c77fe401738..11a70982363f 100644 --- a/jps/antLayout/antlayout.iml +++ b/jps/antLayout/antlayout.iml @@ -1,13 +1,13 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + diff --git a/jps/jps.iml b/jps/jps.iml index 9cbfb9d03b03..a06d07ed6f03 100644 --- a/jps/jps.iml +++ b/jps/jps.iml @@ -1,21 +1,21 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff --git a/jps/plugins/gwt/gwt.iml b/jps/plugins/gwt/gwt.iml index ce88e5079265..8a514adfdbda 100644 --- a/jps/plugins/gwt/gwt.iml +++ b/jps/plugins/gwt/gwt.iml @@ -1,15 +1,15 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + diff --git a/jps/plugins/javaee/javaee.iml b/jps/plugins/javaee/javaee.iml index 59f1b7087d02..b21e687f59bb 100644 --- a/jps/plugins/javaee/javaee.iml +++ b/jps/plugins/javaee/javaee.iml @@ -1,14 +1,14 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/jps/plugins/jpa/jpa.iml b/jps/plugins/jpa/jpa.iml index 59f1b7087d02..b21e687f59bb 100644 --- a/jps/plugins/jpa/jpa.iml +++ b/jps/plugins/jpa/jpa.iml @@ -1,14 +1,14 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/jps/src/org/jetbrains/ether/ProjectWrapper.java b/jps/src/org/jetbrains/ether/ProjectWrapper.java index 0573eeedb2ac..690666905651 100644 --- a/jps/src/org/jetbrains/ether/ProjectWrapper.java +++ b/jps/src/org/jetbrains/ether/ProjectWrapper.java @@ -739,17 +739,27 @@ public class ProjectWrapper { } } - private ProjectWrapper(final String prjDir, final String setupScript) { + private ProjectWrapper(final GantBinding binding, final String prjDir, final String setupScript, final Map pathVariables) { dependencyMapping = new Mappings(this); backendCallback = dependencyMapping.getCallback(); affectedFiles = new HashSet(); - myProject = new Project(new GantBinding()); - myRoot = getCanonicalPath(prjDir); + myProject = new Project(binding == null ? new GantBinding() : binding); + + final File prjFile = new File(prjDir); + final boolean dirBased = !(prjFile.isFile() && prjDir.endsWith(".ipr")); + + myRoot = dirBased ? getCanonicalPath(prjDir) : getCanonicalPath(prjFile.getPath()); + + final String loadPath = dirBased ? getAbsolutePath(myIDEADir) : prjDir; myProjectSnapshot = myHomeDir + File.separator + myJPSDir + File.separator + myRoot.replace(File.separatorChar, myFileSeparatorReplacement); - IdeaProjectLoader.loadFromPath(myProject, getAbsolutePath(myIDEADir), setupScript); + if (pathVariables == null) { + IdeaProjectLoader.loadFromPath(myProject, loadPath, setupScript); + } else { + IdeaProjectLoader.loadFromPath(myProject, loadPath, pathVariables, setupScript); + } for (Module m : myProject.getModules().values()) { myModules.put(m.getName(), new ModuleWrapper(m)); @@ -880,7 +890,11 @@ public class ProjectWrapper { } public static ProjectWrapper load(final String path, final String setupScript) { - return new ProjectWrapper(path, setupScript); + return new ProjectWrapper(null, path, setupScript, null); + } + + public static ProjectWrapper load(final GantBinding binding, final String path, final String setupScript, final Map pathVariables) { + return new ProjectWrapper(binding, path, setupScript, pathVariables); } public void report(final String module) { @@ -925,6 +939,18 @@ public class ProjectWrapper { makeModules(myProject.getModules().values(), defaultFlags); } + public void buildArtifacts() { + myProject.buildArtifacts(); + } + + public void deleteTempFiles() { + myProject.deleteTempFiles(); + } + + public Project getProject() { + return myProject; + } + class BusyBeaver { final ProjectBuilder builder; final Set compiledFiles = new HashSet(); @@ -1126,7 +1152,7 @@ public class ProjectWrapper { final List dep = new ArrayList(); for (ClasspathItem cpi : module.getClasspath(kind)) { - if (cpi instanceof Module) { + if (cpi instanceof Module && !marked.contains(((Module) cpi).getName())) { DotPrinter.edge(((Module) cpi).getName(), mName); dep.add((Module) cpi); } diff --git a/jps/src/org/jetbrains/jps/builders/StandardBuilders.groovy b/jps/src/org/jetbrains/jps/builders/StandardBuilders.groovy index 70f81c8c0d00..09beffa5d4ed 100644 --- a/jps/src/org/jetbrains/jps/builders/StandardBuilders.groovy +++ b/jps/src/org/jetbrains/jps/builders/StandardBuilders.groovy @@ -1,405 +1,403 @@ -package org.jetbrains.jps.builders - -import com.intellij.ant.InstrumentationUtil -import com.intellij.ant.InstrumentationUtil.FormInstrumenter -import com.intellij.ant.PrefixedPath -import org.apache.tools.ant.BuildListener -import org.jetbrains.ether.ProjectWrapper -import org.jetbrains.ether.dependencyView.AntListener -import org.jetbrains.ether.dependencyView.StringCache -import org.jetbrains.ether.dependencyView.StringCache.S -import org.jetbrains.jps.builders.javacApi.Java16ApiCompilerRunner -import org.jetbrains.jps.* - -/** - * @author max - */ -class JavacBuilder implements ModuleBuilder, ModuleCycleBuilder { - - def preprocessModuleCycle(ModuleBuildState state, ModuleChunk moduleChunk, org.jetbrains.jps.Project project) { - doBuildModule(moduleChunk, state) - } - - def processModule(ModuleBuildState state, ModuleChunk moduleChunk, org.jetbrains.jps.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 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 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()) - } - } - - 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, org.jetbrains.jps.Project project) { - if (state.iterated) return; - - state.iterated = true - - if (state.sourceRoots.isEmpty()) return; - - 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 - } - - 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(org.jetbrains.jps.Project project) { - project.taskdef(name: "groovyc", classname: "org.codehaus.groovy.ant.Groovyc") - } - - def processModule(ModuleBuildState state, ModuleChunk moduleChunk, org.jetbrains.jps.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") - } - } - - // 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) - } - - 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(org.jetbrains.jps.Project project) { - project.taskdef(name: "generatestubs", classname: "org.codehaus.groovy.ant.GenerateStubsTask") - } - - def processModule(ModuleBuildState state, ModuleChunk moduleChunk, org.jetbrains.jps.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; - - @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) { - 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(org.jetbrains.jps.Project project) { - project.taskdef(name: "jb_instrumentations", classname: "com.intellij.ant.InstrumentIdeaExtensions") - } - - def getPrefixedPath(org.jetbrains.jps.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, org.jetbrains.jps.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; - - if (pw != null) { - 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 = [] - - def processModule(ModuleBuildState state, ModuleChunk moduleChunk, org.jetbrains.jps.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) - } +package org.jetbrains.jps.builders + +import com.intellij.ant.InstrumentationUtil +import com.intellij.ant.InstrumentationUtil.FormInstrumenter +import com.intellij.ant.PrefixedPath +import org.apache.tools.ant.BuildListener +import org.jetbrains.ether.ProjectWrapper +import org.jetbrains.ether.dependencyView.AntListener +import org.jetbrains.ether.dependencyView.StringCache +import org.jetbrains.ether.dependencyView.StringCache.S +import org.jetbrains.jps.builders.javacApi.Java16ApiCompilerRunner +import org.jetbrains.jps.* + +/** + * @author max + */ +class JavacBuilder implements ModuleBuilder, ModuleCycleBuilder { + + def preprocessModuleCycle(ModuleBuildState state, ModuleChunk moduleChunk, org.jetbrains.jps.Project project) { + doBuildModule(moduleChunk, state) + } + + def processModule(ModuleBuildState state, ModuleChunk moduleChunk, org.jetbrains.jps.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 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 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()) + } + } + + 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, org.jetbrains.jps.Project project) { + if (state.iterated) return; + + state.iterated = true + + if (state.sourceRoots.isEmpty()) return; + + 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 + } + + 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(org.jetbrains.jps.Project project) { + project.taskdef(name: "groovyc", classname: "org.codehaus.groovy.ant.Groovyc") + } + + def processModule(ModuleBuildState state, ModuleChunk moduleChunk, org.jetbrains.jps.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") + } + } + + // 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) + } + + 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(org.jetbrains.jps.Project project) { + project.taskdef(name: "generatestubs", classname: "org.codehaus.groovy.ant.GenerateStubsTask") + } + + def processModule(ModuleBuildState state, ModuleChunk moduleChunk, org.jetbrains.jps.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; + + @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) { + 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(org.jetbrains.jps.Project project) { + project.taskdef(name: "jb_instrumentations", classname: "com.intellij.ant.InstrumentIdeaExtensions") + } + + def getPrefixedPath(org.jetbrains.jps.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, org.jetbrains.jps.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 = [] + + def processModule(ModuleBuildState state, ModuleChunk moduleChunk, org.jetbrains.jps.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) + } } \ No newline at end of file diff --git a/jps/testSrc/org/jetbrains/jps/JpsBuildTestCase.groovy b/jps/testSrc/org/jetbrains/jps/JpsBuildTestCase.groovy index 114c7194637d..0282d9a38442 100644 --- a/jps/testSrc/org/jetbrains/jps/JpsBuildTestCase.groovy +++ b/jps/testSrc/org/jetbrains/jps/JpsBuildTestCase.groovy @@ -2,69 +2,73 @@ package org.jetbrains.jps import junit.framework.TestCase import org.codehaus.gant.GantBinding +import org.jetbrains.ether.ProjectWrapper import org.jetbrains.jps.idea.IdeaProjectLoader import org.jetbrains.jps.util.FileSystemItem -import org.jetbrains.jps.util.FileUtil; +import org.jetbrains.jps.util.FileUtil /** * @author nik */ abstract class JpsBuildTestCase extends TestCase { - - def doTest(String projectPath, Closure initProject, Closure expectedOutput) { - doTest(projectPath, [:], initProject, expectedOutput) - } - def doTest(String projectPath, Map pathVariables, Closure initProject, Closure expectedOutput) { - Project project = buildAll(projectPath, pathVariables, initProject) - assertOutput(project, project.targetFolder, expectedOutput); - } - - def protected assertOutput(Project project, String targetFolder, Closure expectedOutput) { - def root = new FileSystemItem(name: "") - initFileSystemItem(root, expectedOutput) - root.assertDirectoryEqual(new File(targetFolder), "") - } - - def protected buildAll(String projectPath, Map pathVariables, Closure initProject) { - Project project = loadProject(projectPath, pathVariables) - def target = FileUtil.createTempDirectory("targetDir") - project.targetFolder = target.absolutePath - initProject(project) - project.clean() - project.makeAll() - project.buildArtifacts() - project.deleteTempFiles() - return project - } - - protected Project loadProject(String projectPath, Map pathVariables) { - def binding = new GantBinding() - binding.includeTool << Jps - def project = new Project(binding) - IdeaProjectLoader.loadFromPath(project, projectPath, pathVariables, null) - return project - } - - def initFileSystemItem(FileSystemItem item, Closure initializer) { - def meta = new InitializingExpando() - meta.dir = {String name, Closure content -> - def dir = new FileSystemItem(name: name, directory: true) - initFileSystemItem(dir, content) - item << dir - } - meta.archive = {String name, Closure content -> - def archive = new FileSystemItem(name: name, archive: true) - initFileSystemItem(archive, content) - item << archive - } - meta.file = {Object[] args -> - item << new FileSystemItem(name: args[0], content: args.length > 1 ? args[1] : null) + def doTest(String projectPath, Closure initProject, Closure expectedOutput) { + doTest(projectPath, [:], initProject, expectedOutput) } - initializer.delegate = meta - initializer.setResolveStrategy Closure.DELEGATE_FIRST - initializer() - } + def doTest(String projectPath, Map pathVariables, Closure initProject, Closure expectedOutput) { + Project project = buildAll(projectPath, pathVariables, initProject) + assertOutput(project, project.targetFolder, expectedOutput); + } + + def protected assertOutput(Project project, String targetFolder, Closure expectedOutput) { + def root = new FileSystemItem(name: "") + initFileSystemItem(root, expectedOutput) + root.assertDirectoryEqual(new File(targetFolder), "") + } + + def protected buildAll(String projectPath, Map pathVariables, Closure initProject) { + def binding = new GantBinding() + binding.includeTool << Jps + ProjectWrapper pw = ProjectWrapper.load(binding, projectPath, null, pathVariables) + Project project = pw.getProject() + def target = FileUtil.createTempDirectory("targetDir") + project.targetFolder = target.absolutePath + initProject(project) + pw.clean() + pw.rebuild() + pw.buildArtifacts() + pw.deleteTempFiles() + return project + } + + protected Project loadProject(String projectPath, Map pathVariables) { + def binding = new GantBinding() + binding.includeTool << Jps + def project = new Project(binding) + IdeaProjectLoader.loadFromPath(project, projectPath, pathVariables, null) + return project + } + + def initFileSystemItem(FileSystemItem item, Closure initializer) { + def meta = new InitializingExpando() + meta.dir = {String name, Closure content -> + def dir = new FileSystemItem(name: name, directory: true) + initFileSystemItem(dir, content) + item << dir + } + meta.archive = {String name, Closure content -> + def archive = new FileSystemItem(name: name, archive: true) + initFileSystemItem(archive, content) + item << archive + } + meta.file = {Object[] args -> + item << new FileSystemItem(name: args[0], content: args.length > 1 ? args[1] : null) + } + + initializer.delegate = meta + initializer.setResolveStrategy Closure.DELEGATE_FIRST + initializer() + } }