Eliminated Pair.

This commit is contained in:
Dmitry Boulytchev
2011-06-22 12:09:53 +04:00
parent 24588d2a64
commit 900ba306bc
13 changed files with 466 additions and 431 deletions

View File

@@ -1,11 +1,12 @@
<component name="InspectionProjectProfileManager">
<settings>
<list size="5">
<list size="6">
<item index="0" class="java.lang.String" itemvalue="TYPO" />
<item index="1" class="java.lang.String" itemvalue="INFO" />
<item index="2" class="java.lang.String" itemvalue="WARNING" />
<item index="3" class="java.lang.String" itemvalue="ERROR" />
<item index="4" class="java.lang.String" itemvalue="SERVER PROBLEM" />
<item index="1" class="java.lang.String" itemvalue="WEAK WARNING" />
<item index="2" class="java.lang.String" itemvalue="INFO" />
<item index="3" class="java.lang.String" itemvalue="WARNING" />
<item index="4" class="java.lang.String" itemvalue="ERROR" />
<item index="5" class="java.lang.String" itemvalue="SERVER PROBLEM" />
</list>
</settings>
</component>

View File

@@ -1,15 +1,11 @@
<component name="libraryTable">
<library name="Javac2">
<CLASSES>
<root url="jar://$PROJECT_DIR$/../test/idea/out/dist.all.ce/lib/jgoodies-forms.jar!/" />
<root url="jar://$PROJECT_DIR$/../test/idea/out/dist.all.ce/lib/jdom.jar!/" />
<root url="jar://$PROJECT_DIR$/../test/idea/out/dist.all.ce/lib/asm-commons.jar!/" />
<root url="jar://$PROJECT_DIR$/../test/idea/out/dist.all.ce/lib/asm.jar!/" />
<root url="jar://$PROJECT_DIR$/../test/idea/out/dist.all.ce/lib/javac2.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/javac2-all.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$PROJECT_DIR$/../test/idea/java/compiler/javac2/src" />
<root url="file://$PROJECT_DIR$/../test/idea.ultimate/community/java/compiler/javac2/src" />
</SOURCES>
</library>
</component>

3
jps/.idea/misc.xml generated
View File

@@ -1,8 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DependencyValidationManager">
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
</component>
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>

5
jps/.idea/scopes/scope_settings.xml generated Normal file
View File

@@ -0,0 +1,5 @@
<component name="DependencyValidationManager">
<state>
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
</state>
</component>

Binary file not shown.

View File

@@ -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<X, Y> {
public final X fst;
public final Y snd;
public Pair(final X fst, final Y snd) {
this.fst = fst;
this.snd = snd;
}
}

View File

@@ -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<TypeRepr.AbstractType> interfaces();
public abstract Difference.Specifier<TypeRepr.AbstractType> nestedClasses();
public abstract Difference.Specifier<FieldRepr> fields();
public abstract Difference.Specifier<MethodRepr> 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<FieldRepr> fields() {
return Difference.make (pastClass.fields, fields);
return Difference.make(pastClass.fields, fields);
}
public Difference.Specifier<MethodRepr> 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<String> ns, final Set<FieldRepr> f, final Set<MethodRepr> 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<String> ns, final Set<FieldRepr> f, final Set<MethodRepr> m) {
super(a, sig, n);
fileName = fn;
sourceFileName = sn;
@@ -98,7 +101,7 @@ public class ClassRepr extends Proto {
nestedClasses = (Set<TypeRepr.AbstractType>) TypeRepr.createClassType(ns, new HashSet<TypeRepr.AbstractType>());
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);
}

View File

@@ -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<ClassRepr,Set<UsageRepr.Usage>> analyze(final StringCache.S fileName, final ClassReader cr) {
public static Pair<ClassRepr, Set<UsageRepr.Usage>> analyze(final StringCache.S fileName, final ClassReader cr) {
final ClassCrawler visitor = new ClassCrawler(fileName);
cr.accept(visitor, 0);

View File

@@ -1,6 +1,6 @@
package org.jetbrains.ether.dependencyView;
import com.sun.tools.javac.util.Pair;
import org.jetbrains.ether.Pair;
import java.util.*;

View File

@@ -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;

View File

@@ -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<String> formFiles;
final ModuleBuildState state;
class CustomFormInstrumenter extends
FormInstrumenter {
final List<String> 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<String> nestedFormPathList, final List<String> 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<File> formFiles = new ArrayList<File>();
final ProjectWrapper pw = state.projectWrapper;
for (Module m: moduleChunk.elements) {
final Set<S> 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<PrefixedPath> nestedFormDirs = new ArrayList<PrefixedPath>();
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<StringCache.S> 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<String> nestedFormPathList, final List<String> 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<File> formFiles = new ArrayList<File>();
final ProjectWrapper pw = state.projectWrapper;
for (Module m: moduleChunk.elements) {
final Set<S> 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<PrefixedPath> nestedFormDirs = new ArrayList<PrefixedPath>();
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<StringCache.S> classes = state.callback.getClassFiles()
classes.each {
InstrumentationUtil.instrumentNotNull(new File(state.targetFolder + File.separator + it.value + ".class"), state.loader)
}
}
}
}
}
class CustomTasksBuilder implements ModuleBuilder {
List<ModuleBuildTask> tasks = []
List<ModuleBuildTask> 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)
}
}

View File

@@ -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<String> 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<File> 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<File> 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<File> classpath = []
List<File> 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<? extends JavaFileObject> 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<String> 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<File> filesToCompile = []
if (state.sourceFiles.size() > 0) {
for (String src: state.sourceFiles) {
if (src.endsWith(".java")) {
filesToCompile << new File(src)
}
}
}
else {
Set<File> 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<File> classpath = []
List<File> 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<? extends JavaFileObject> 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")
}
}
}
}

View File

@@ -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);