From 896b7a168ca8619f99f541187f644cbeb613a53f Mon Sep 17 00:00:00 2001 From: nik Date: Tue, 3 Apr 2012 16:40:28 +0400 Subject: [PATCH] jps: obsolete code removed --- .../org/jetbrains/ether/DirectoryScanner.java | 174 -- jps/src/org/jetbrains/ether/DotPrinter.java | 78 - jps/src/org/jetbrains/ether/Main.java | 271 --- jps/src/org/jetbrains/ether/MockFS.java | 127 -- jps/src/org/jetbrains/ether/Options.java | 272 --- .../org/jetbrains/ether/ProjectWrapper.java | 1485 ----------------- jps/src/org/jetbrains/ether/Reporter.java | 101 -- .../ether/dependencyView/AntListener.java | 307 ---- .../org/jetbrains/jps/ModuleBuildState.groovy | 5 - .../org/jetbrains/jps/ProjectBuilder.groovy | 86 +- .../jps/builders/StandardBuilders.groovy | 113 +- .../javacApi/Java16ApiCompiler.groovy | 15 +- 12 files changed, 32 insertions(+), 3002 deletions(-) delete mode 100644 jps/src/org/jetbrains/ether/DirectoryScanner.java delete mode 100644 jps/src/org/jetbrains/ether/DotPrinter.java delete mode 100644 jps/src/org/jetbrains/ether/Main.java delete mode 100644 jps/src/org/jetbrains/ether/MockFS.java delete mode 100644 jps/src/org/jetbrains/ether/Options.java delete mode 100644 jps/src/org/jetbrains/ether/ProjectWrapper.java delete mode 100644 jps/src/org/jetbrains/ether/Reporter.java delete mode 100644 jps/src/org/jetbrains/ether/dependencyView/AntListener.java diff --git a/jps/src/org/jetbrains/ether/DirectoryScanner.java b/jps/src/org/jetbrains/ether/DirectoryScanner.java deleted file mode 100644 index 8afed0ba5fe0..000000000000 --- a/jps/src/org/jetbrains/ether/DirectoryScanner.java +++ /dev/null @@ -1,174 +0,0 @@ -package org.jetbrains.ether; - -import java.io.File; -import java.io.FileFilter; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Created by IntelliJ IDEA. - * User: db - * Date: 19.11.10 - * Time: 2:01 - * To change this template use File | Settings | File Templates. - */ - -public class DirectoryScanner { - - public static class Result { - final Set myFiles; - long myLatest; - long myEarliest; - - public Result() { - myFiles = new HashSet(); - myLatest = 0; - myEarliest = Long.MAX_VALUE; - } - - public void update(final ProjectWrapper.FileWrapper w) { - final long t = w.getStamp(); - - if (t > myLatest) myLatest = t; - - if (t < myEarliest) myEarliest = t; - - myFiles.add(w); - } - - public long getEarliest() { - return myEarliest; - } - - public long getLatest() { - return myLatest; - } - - public Set getFiles() { - return myFiles; - } - } - - private static class Crawler { - final Result myResult; - final FileFilter myFilter; - final ProjectWrapper myProjectWrapper; - - public Crawler(final FileFilter ff, final ProjectWrapper pw) { - myResult = new Result(); - myFilter = ff; - myProjectWrapper = pw; - } - - public Result getResult() { - return myResult; - } - - public void run(File root) { - if (root.exists()) { - final File[] files = root.listFiles(myFilter); - - for (int i = 0; i < files.length; i++) { - myResult.update(myProjectWrapper.new FileWrapper(files[i])); - } - - final File[] subdirs = root.listFiles(myDirectoryFilter); - - for (int i = 0; i < subdirs.length; i++) { - run(subdirs[i]); - } - } - } - } - - private static FileFilter myDirectoryFilter = new FileFilter() { - public boolean accept(File f) { - final String name = f.getName(); - - return f.isDirectory() && !name.equals(".") && !name.equals(".."); - } - }; - - private static FileFilter myTrueFilter = new FileFilter() { - public boolean accept(File s) { - return s.isFile(); - } - }; - - private static FileFilter createFilter(final Collection excludes) { - if (excludes == null) { - return myTrueFilter; - } - - StringBuilder buf = new StringBuilder(); - - for (String exclude : excludes) { - StringBuilder alternative = new StringBuilder(); - - if (exclude != null) { - for (int i = 0; i < exclude.length(); i++) { - final char c = exclude.charAt(i); - - switch (c) { - case '.': - case '\\': - case '*': - case '^': - case '$': - case '[': - case '(': - case '|': - alternative.append("\\"); - alternative.append(c); - break; - - case '?': - alternative.append("."); - break; - - default: - alternative.append(c); - } - } - } - - if (alternative.length() > 0) { - alternative.append(".*"); - - if (buf.length() > 0) buf.append("|"); - - buf.append("("); - buf.append(alternative); - buf.append(')'); - } - } - - if (buf.length() > 0) { - final Pattern patt = Pattern.compile(buf.toString()); - - return new FileFilter() { - public boolean accept(File f) { - final Matcher m = patt.matcher(f.getAbsolutePath()); - final boolean ok = !m.matches(); - - return ok && f.isFile(); - } - }; - } - - return myTrueFilter; - } - - public static Result getFiles(final Set roots, final Set excludes, final ProjectWrapper pw) { - final Crawler cw = new Crawler(createFilter(excludes), pw); - - for (String root : roots) { - cw.run(new File(root)); - } - - return cw.getResult(); - } -} diff --git a/jps/src/org/jetbrains/ether/DotPrinter.java b/jps/src/org/jetbrains/ether/DotPrinter.java deleted file mode 100644 index cb45d0dc4fa6..000000000000 --- a/jps/src/org/jetbrains/ether/DotPrinter.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.jetbrains.ether; - -import java.io.PrintStream; - -/** - * Created by IntelliJ IDEA. - * User: db - * Date: 18.01.11 - * Time: 6:33 - * To change this template use File | Settings | File Templates. - */ -public class DotPrinter { - private final PrintStream stream; - - public DotPrinter(final PrintStream stream) { - this.stream = stream; - } - - private static String escape(final String s) { - final StringBuilder b = new StringBuilder(); - - for (int i = 0; i < s.length(); i++) { - final char c = s.charAt(i); - - if (c == '_' || Character.isDigit(c) || Character.isLetter(c)) { - b.append(c); - } - else if (c == '-') { - b.append('_'); - } - else { - b.append(Character.getNumericValue(c)); - } - } - - return b.toString(); - } - - public static void header(final PrintStream s) { - if (s != null) s.println("digraph X {"); - } - - public void header() { - header(stream); - } - - public static void footer(final PrintStream s) { - if (s != null) s.println("}"); - } - - public void footer() { - footer(stream); - } - - public static void node(final PrintStream s, String n) { - if (s != null) { - n = escape(n); - s.println(" " + n + "[label=\"" + n + "\"];"); - } - } - - public void node(final String n) { - node(stream, n); - } - - public static void edge(final PrintStream s, String b, String e) { - if (s != null) { - b = escape(b); - e = escape(e); - - s.println(" " + b + " -> " + e + ";"); - } - } - - public void edge(final String b, final String e) { - edge(stream, b, e); - } -} diff --git a/jps/src/org/jetbrains/ether/Main.java b/jps/src/org/jetbrains/ether/Main.java deleted file mode 100644 index 6e773535028f..000000000000 --- a/jps/src/org/jetbrains/ether/Main.java +++ /dev/null @@ -1,271 +0,0 @@ -package org.jetbrains.ether; - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.List; - -/** - * Created by IntelliJ IDEA. - * User: db - * Date: 18.11.10 - * Time: 19:42 - * To change this template use File | Settings | File Templates. - *

- * The main class to start with - */ -public class Main { - private static final Options myOptions; - - private enum Action { - REBUILD, - MAKE, - CLEAN, - NONE - } - - static { - final Options.Descriptor[] descrs = {new Options.Descriptor("script", "script", "s", Options.ArgumentSpecifier.MANDATORY, - "specify script for project library/sdk setup; use prefix '@' to specify script file"), - new Options.Descriptor("inspect", "inspect", "i", Options.ArgumentSpecifier.OPTIONAL, - "list relevant information for the whole project or specified module"), - new Options.Descriptor("save", "save", "x", Options.ArgumentSpecifier.NONE, "collect and save project information"), - new Options.Descriptor("clean", "clean", "c", Options.ArgumentSpecifier.NONE, "clean project"), - new Options.Descriptor("rebuild", "rebuild", "r", Options.ArgumentSpecifier.NONE, "rebuild project"), - new Options.Descriptor("make", "make", "m", Options.ArgumentSpecifier.OPTIONAL, "make the whole project or specified module"), - new Options.Descriptor("tests", "tests", "t", Options.ArgumentSpecifier.NONE, "make tests as well"), - new Options.Descriptor("force", "force", "f", Options.ArgumentSpecifier.NONE, "force actions"), - new Options.Descriptor("incremental", "incremental", "u", Options.ArgumentSpecifier.NONE, "perform incremental make"), - new Options.Descriptor("help", "help", "h", Options.ArgumentSpecifier.NONE, "show help on options"), - new Options.Descriptor("log", "log", "l", Options.ArgumentSpecifier.OPTIONAL, "log into file (for development purposes)")}; - - myOptions = new Options(descrs); - } - - private static PrintStream logStream = null; - private static boolean logStreamSet = false; - - private static PrintStream getLog() { - if (logStreamSet) { - return logStream; - } - - logStreamSet = true; - - final Options.Argument arg = myOptions.get("log"); - - if (arg == null) { - return null; - } - - if (arg instanceof Options.Value) { - try { - return logStream = new PrintStream(new FileOutputStream(((Options.Value)arg).get())); - } - catch (IOException e) { - e.printStackTrace(); - return null; - } - } - - if (arg instanceof Options.Switch) { - return logStream = System.out; - } - - return null; - } - - private static boolean doSave() { - return myOptions.get("save") instanceof Options.Switch; - } - - private static boolean doTests() { - return myOptions.get("tests") instanceof Options.Switch; - } - - private static boolean doRebuild() { - return myOptions.get("rebuild") instanceof Options.Switch; - } - - private static boolean doForce() { - return myOptions.get("force") instanceof Options.Switch; - } - - private static boolean doIncremental() { - return myOptions.get("incremental") instanceof Options.Switch; - } - - private static boolean doHelp() { - return myOptions.get("help") instanceof Options.Switch; - } - - private static Options.Argument doInspect() { - return myOptions.get("inspect"); - } - - private static Options.Argument doMake() { - return myOptions.get("make"); - } - - private static boolean doClean() { - return myOptions.get("clean") instanceof Options.Switch; - } - - private static String getScript() { - final Options.Argument arg = myOptions.get("script"); - - if (arg instanceof Options.Value) return ((Options.Value)arg).get(); - - return null; - } - - private static ProjectWrapper.Flags getFlags() { - return new ProjectWrapper.Flags() { - public boolean tests() { - return doTests(); - } - - public boolean force() { - return doForce(); - } - - public boolean incremental() { - return doIncremental(); - } - - public PrintStream logStream() { - return getLog(); - } - }; - } - - private static void checkConsistency() { - int test = 0; - - if (doClean()) test++; - if (doMake() != null) test++; - if (doRebuild()) test++; - - if (test > 1) { - System.err.print("WARNING: Conflicting options (should be --make OR --rebuild OR --clean); preferring "); - if (doMake() != null) { - System.err.println("make."); - } - else if (doRebuild()) System.err.println("rebuild."); - } - - if (doClean() || doRebuild()) { - if (doTests()) { - System.err.println("WARNING: extra --tests option ignored."); - } - if (doForce()) { - System.err.println("WARNING: extra --force option ignored."); - } - } - } - - private static Action getAction() { - if (doMake() != null) { - return Action.MAKE; - } - - if (doRebuild()) return Action.REBUILD; - - if (doClean()) return Action.CLEAN; - - return Action.NONE; - } - - public static void main(String[] args) { - System.out.println("JetBrains.com build server. (C) JetBrains.com, 2010-2011.\n"); - - final List notes = myOptions.parse(args); - - for (String note : notes) { - System.err.println("WARNING: " + note); - } - - checkConsistency(); - - if (doHelp()) { - System.out.println("Usage: ??? \n"); - System.out.println("Options are:"); - System.out.println(myOptions.memo()); - } - - final List projects = myOptions.getFree(); - - if (projects.isEmpty() && !doHelp()) { - System.out.println("Nothing to do; use --help or -h option to see the help.\n"); - } - - for (String prj : projects) { - boolean saved = false; - ProjectWrapper project = null; - - switch (getAction()) { - case CLEAN: - System.out.println("Cleaning project \"" + prj + "\""); - project = ProjectWrapper.load(prj, getScript(), false); - - project.clean(); - project.save(); - saved = true; - break; - - case REBUILD: - System.out.println("Rebuilding project \"" + prj + "\""); - project = ProjectWrapper.load(prj, getScript(), false); - project.rebuild(); - project.save(); - saved = true; - break; - - case MAKE: - final Options.Argument make = doMake(); - - if (make instanceof Options.Value) { - final String module = ((Options.Value)make).get(); - System.out.println("Making module \"" + module + "\" in project \"" + prj + "\""); - project = ProjectWrapper.load(prj, getScript(), true); - project.makeModule(module, getFlags()); - project.save(); - saved = true; - } - else if (make instanceof Options.Switch) { - System.out.println("Making all modules in project \"" + prj + "\""); - project = ProjectWrapper.load(prj, getScript(), true); - project.makeModule(null, getFlags()); - project.save(); - saved = true; - } - ; - break; - } - - final Options.Argument inspect = doInspect(); - - if (inspect instanceof Options.Switch) { - project = ProjectWrapper.load(prj, getScript(), true); - project.report(); - if (doSave()) { - project.save(); - saved = true; - } - } - else if (inspect instanceof Options.Value) { - project = ProjectWrapper.load(prj, getScript(), true); - project.report(((Options.Value)inspect).get()); - if (doSave()) { - project.save(); - saved = true; - } - } - - if (doSave() && !saved) { - project = ProjectWrapper.load(prj, getScript(), true); - project.save(); - } - } - } -} diff --git a/jps/src/org/jetbrains/ether/MockFS.java b/jps/src/org/jetbrains/ether/MockFS.java deleted file mode 100644 index c81aa8e775dc..000000000000 --- a/jps/src/org/jetbrains/ether/MockFS.java +++ /dev/null @@ -1,127 +0,0 @@ -package org.jetbrains.ether; - -import java.io.FileFilter; -import java.io.FilenameFilter; -import java.util.*; - -/** - * Created by IntelliJ IDEA. - * User: db - * Date: 27.06.11 - * Time: 21:03 - * To change this template use File | Settings | File Templates. - */ -public class MockFS { - final Map myFiles = new HashMap(); - final File myRoot; - - private File getFile(java.io.File f) { - if (f.getAbsolutePath().startsWith(myRoot.getAbsolutePath())) { - File g = myFiles.get(f); - - if (g != null) { - return g; - } - - g = new File(f, false); - - myFiles.put(f, g); - - return g; - } - - return null; - } - - public class File extends java.io.File { - final Set mySubFiles = new HashSet(); - final File myParent; - - private File(final java.io.File file, final boolean root) { - super(file.getPath()); - - if (root) { - myParent = null; - return; - } - - final java.io.File parent = file.getParentFile(); - - myParent = parent == null ? null : getFile(parent); - - if (myParent != null) { - myParent.mySubFiles.add(this); - } - } - - @Override - public String[] list() { - return list(new FilenameFilter() { - public boolean accept(java.io.File dir, String name) { - return true; - } - }); - } - - @Override - public String[] list(final FilenameFilter filter) { - final List result = new LinkedList(); - - for (final File f : mySubFiles) { - if (filter.accept(this, f.getName())) { - result.add(f.getName()); - } - } - - return result.toArray(new String[result.size()]); - } - - @Override - public java.io.File[] listFiles() { - return mySubFiles.toArray(new File[mySubFiles.size()]); - } - - @Override - public java.io.File[] listFiles(final FilenameFilter filter) { - final List result = new LinkedList(); - - for (File f : mySubFiles) { - if (filter.accept(this, f.getName())) { - result.add(f); - } - } - - return result.toArray(new File[result.size()]); - } - - @Override - public java.io.File[] listFiles(final FileFilter filter) { - final List result = new LinkedList(); - - for (File f : mySubFiles) { - if (filter.accept(f)) { - result.add(f); - } - } - - return result.toArray(new File[result.size()]); - } - } - - private MockFS(final String root) { - final java.io.File rootFile = new java.io.File(root); - - myRoot = new File(rootFile, true); - myFiles.put(rootFile, myRoot); - } - - public static File fromFiles(final String root, final Collection files) { - final MockFS fs = new MockFS(root); - - for (String f : files) { - fs.getFile(new java.io.File(f)); - } - - return fs.myRoot; - } -} diff --git a/jps/src/org/jetbrains/ether/Options.java b/jps/src/org/jetbrains/ether/Options.java deleted file mode 100644 index 266c2bed6a0a..000000000000 --- a/jps/src/org/jetbrains/ether/Options.java +++ /dev/null @@ -1,272 +0,0 @@ -package org.jetbrains.ether; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Created by IntelliJ IDEA. - * User: db - * Date: 21.11.10 - * Time: 14:33 - * To change this template use File | Settings | File Templates. - */ -public class Options { - - public enum ArgumentSpecifier { - MANDATORY, - OPTIONAL, - NONE; - } - - public abstract interface Argument { - } - - public static class Switch implements Argument { - - } - - private static Switch SWITCH = new Switch(); - - public static class Value implements Argument { - private final String myValue; - - Value(final String s) { - myValue = s; - } - - public String get() { - return myValue; - } - } - - private class Cursor { - int myPos; - final int myLength; - final String[] myArgs; - - Cursor(final String[] args) { - myArgs = args; - myPos = 0; - myLength = myArgs.length; - } - - public String look() { - if (myPos >= myLength) return null; - - return myArgs[myPos]; - } - - public void shift() { - myPos++; - } - - public String lookahead() { - final String arg = myArgs[myPos + 1]; - myPos += 2; - - return arg; - } - - public boolean nextIsArg() { - return (myPos < myLength - 1 && !myArgs[myPos + 1].startsWith("-")); - } - - public boolean endOf() { - return myPos >= myLength; - } - } - - private interface Callback { - void update(String key, Argument value); - - void addFree(String value); - - void report(String note); - } - - public static class Descriptor { - private final ArgumentSpecifier myArgumentSpecifier; - private final String myKey; - private final String myLong; - private final String myShort; - private final String myMemo; - - private final Pattern myLongPattern; - - Descriptor(final String key, final String longForm, final String shortForm, final ArgumentSpecifier as, final String memo) { - myArgumentSpecifier = as; - myKey = key; - myLong = longForm; - myShort = shortForm; - myMemo = memo; - - myLongPattern = myLong == null ? null : Pattern.compile("^--" + myLong + "(=(.*))?$"); - } - - public String memo() { - final StringBuilder buf = new StringBuilder(); - String longArg = "", shortArg = ""; - - switch (myArgumentSpecifier) { - case OPTIONAL: - longArg = "[=]"; - shortArg = " []"; - break; - - case NONE: - longArg = ""; - shortArg = ""; - break; - - case MANDATORY: - longArg = "="; - shortArg = " "; - break; - } - - buf.append(" --" + myLong + longArg + ", -" + myShort + shortArg + "\n"); - buf.append(" " + myMemo + "\n"); - - return buf.toString(); - } - - public boolean proceed(final Cursor cursor, final Callback callback) { - if (cursor.endOf()) return false; - - final String arg = cursor.look(); - - if (!arg.startsWith("-")) { - callback.addFree(arg); - cursor.shift(); - return true; - } - - if (myShort != null && arg.equals("-" + myShort)) { - switch (myArgumentSpecifier) { - case NONE: - callback.update(myKey, SWITCH); - break; - - default: - if (cursor.nextIsArg()) { - callback.update(myKey, new Value(cursor.lookahead())); - } - else { - switch (myArgumentSpecifier) { - case OPTIONAL: - callback.update(myKey, SWITCH); - break; - case MANDATORY: - callback.report("option \"" + arg + "\" requires an argument, discarding."); - } - } - } - ; - - cursor.shift(); - return true; - } - - final Matcher m = myLongPattern.matcher(arg); - - if (myLong != null && m.matches()) { - final String prm = m.group(2); - - switch (myArgumentSpecifier) { - case MANDATORY: - if (prm == null) { - callback.report("option \"" + arg + "\" requires an argument, discarding."); - } - else { - callback.update(myKey, new Value(prm)); - } - break; - - case NONE: - if (prm == null) { - callback.update(myKey, SWITCH); - } - else { - callback.report("option \"" + arg + "\" does not take an argument, omitting."); - } - break; - - case OPTIONAL: - callback.update(myKey, prm == null ? SWITCH : new Value(prm)); - break; - } - - cursor.shift(); - return true; - } - - return false; - } - } - - private Map myOptions = new HashMap(); - private List myFree; - - private final Descriptor[] myDescriptors; - - Options(final Descriptor[] descrs) { - myDescriptors = descrs; - } - - public List parse(final String[] args) { - myOptions.clear(); - myFree = new ArrayList(); - final List notes = new ArrayList(); - final Callback cb = new Callback() { - public void addFree(final String value) { - myFree.add(value); - } - - public void update(final String key, final Argument value) { - myOptions.put(key, value); - } - - public void report(final String note) { - notes.add(note); - } - }; - final Cursor cursor = new Cursor(args); - - while (!cursor.endOf()) { - boolean recognized = false; - - for (int i = 0; i < myDescriptors.length; i++) { - recognized |= myDescriptors[i].proceed(cursor, cb); - } - - if (!recognized) { - cb.report("unrecognized option \"" + cursor.look() + "\" omitted."); - cursor.shift(); - } - } - - return notes; - } - - public Argument get(final String name) { - return myOptions.get(name); - } - - public List getFree() { - return myFree; - } - - public String memo() { - final StringBuilder buf = new StringBuilder(); - - for (final Descriptor descriptor : myDescriptors) { - buf.append(descriptor.memo()).append("\n"); - } - - return buf.toString(); - } -} diff --git a/jps/src/org/jetbrains/ether/ProjectWrapper.java b/jps/src/org/jetbrains/ether/ProjectWrapper.java deleted file mode 100644 index 05c22f89ada4..000000000000 --- a/jps/src/org/jetbrains/ether/ProjectWrapper.java +++ /dev/null @@ -1,1485 +0,0 @@ -package org.jetbrains.ether; - -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.util.SystemProperties; -import org.codehaus.gant.GantBinding; -import org.codehaus.groovy.runtime.DefaultGroovyMethods; -import org.jetbrains.ether.dependencyView.Callbacks; -import org.jetbrains.ether.dependencyView.ClassRepr; -import org.jetbrains.ether.dependencyView.Mappings; -import org.jetbrains.jps.*; -import org.jetbrains.jps.idea.IdeaProjectLoader; -import org.jetbrains.jps.resolvers.PathEntry; - -import java.io.*; -import java.util.*; - -/** - * Created by IntelliJ IDEA. - * User: db - * Date: 19.11.10 - * Time: 2:58 - * To change this template use File | Settings | File Templates. - */ - -public class ProjectWrapper { - public interface Flags { - boolean tests(); - - boolean incremental(); - - boolean force(); - - PrintStream logStream(); - } - - private final static Flags defaultFlags = new Flags() { - public boolean tests() { - return true; - } - - public boolean incremental() { - return false; - } - - public boolean force() { - return true; - } - - public PrintStream logStream() { - return null; - } - }; - - private abstract class Logger { - private final PrintStream stream; - - public Logger(final Flags flags) { - this.stream = flags.logStream(); - } - - public void logFilePaths(PrintStream stream, Collection paths) { - List strings = new ArrayList(paths.size()); - for (String path : paths) { - strings.add(FileUtil.toSystemIndependentName(getRelativePath(path))); - } - logMany(stream, strings); - } - - public void logMany(final PrintStream stream, final Collection list) { - final String[] a = new String[list.size()]; - int i = 0; - - for (T e : list) { - a[i++] = e.toString(); - } - - Arrays.sort(a); - - for (String o : a) { - stream.println(o); - } - } - - public abstract void log(final PrintStream stream); - - public void log() { - if (stream != null) log(stream); - } - } - - // Home directory - private static final String myHomeDir = SystemProperties.getUserHome(); - - // JPS directory - private static final String myJPSDir = ".jps"; - - // IDEA project structure directory name - private static final String myIDEADir = ".idea"; - - // JPS directory initialization - private static void initJPSDirectory() { - final File f = new File(myHomeDir + File.separator + myJPSDir); - - if (!f.exists()) { - if (!f.mkdir()) { - throw new RuntimeException("unable to create JPS snapshot directory " + f.getPath()); - } - } - } - - // File separator replacement - private static final char myFileSeparatorReplacement = '.'; - - // Original JPS Project - private final GantBasedProject myProject; - private final ProjectBuilder myProjectBuilder; - - // Project directory - private final String myRoot; - - // Project snapshot file name - private final String myProjectSnapshot; - - public interface ClasspathItemWrapper extends RW.Writable { - public List getClassPath(ClasspathKind kind); - } - - private final RW.Reader myLibraryWrapperReader = new RW.Reader() { - public LibraryWrapper read(final BufferedReader r) { - return new LibraryWrapper(r); - } - }; - - public class LibraryWrapper implements ClasspathItemWrapper { - final String myName; - final List myClassPath; - - public void write(final BufferedWriter w) { - RW.writeln(w, "Library:" + myName); - RW.writeln(w, "Classpath:"); - RW.writeln(w, myClassPath, RW.fromString); - } - - public LibraryWrapper(final BufferedReader r) { - myName = RW.readStringAttribute(r, "Library:"); - - RW.readTag(r, "Classpath:"); - myClassPath = (List)RW.readMany(r, RW.myStringReader, new ArrayList()); - } - - public LibraryWrapper(final Library lib) { - lib.forceInit(); - myName = lib.getName(); - myClassPath = lib.getClasspath(); - } - - public String getName() { - return myName; - } - - public List getClassPath(final ClasspathKind kind) { - return myClassPath; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - LibraryWrapper that = (LibraryWrapper)o; - - if (myName != null ? !myName.equals(that.myName) : that.myName != null) return false; - - return true; - } - - @Override - public int hashCode() { - return myName != null ? myName.hashCode() : 0; - } - } - - private final RW.Reader myWeakClasspathItemWrapperReader = new RW.Reader() { - public ClasspathItemWrapper read(final BufferedReader r) { - final String s = RW.lookString(r); - if (s.startsWith("Library:")) { - return new WeakClasspathItemWrapper(RW.readStringAttribute(r, "Library:"), "Library"); - } - if (s.startsWith("Module:")) { - return new WeakClasspathItemWrapper(RW.readStringAttribute(r, "Module:"), "Module"); - } - else { - return new GenericClasspathItemWrapper(r); - } - } - }; - - public class WeakClasspathItemWrapper implements ClasspathItemWrapper { - final String myName; - final String myType; - - public WeakClasspathItemWrapper(final String name, final String type) { - myName = name; - myType = type; - } - - public WeakClasspathItemWrapper(final ModuleWrapper m) { - myType = "Module"; - myName = m.getName(); - } - - public WeakClasspathItemWrapper(final LibraryWrapper l) { - myType = "Library"; - myName = l.getName(); - } - - public boolean isModule() { - return myType.equals("Module"); - } - - public String getName() { - return myName; - } - - public List getClassPath(ClasspathKind kind) { - return null; - } - - public void write(final BufferedWriter w) { - RW.writeln(w, myType + ":" + getName()); - } - } - - public class GenericClasspathItemWrapper implements ClasspathItemWrapper { - final List myClassPath; - final String myType; - - public GenericClasspathItemWrapper(final ClasspathItem item) { - if (item instanceof PathEntry) { - myType = "PathEntry"; - } - else if (item instanceof JavaSdk) { - myType = "JavaSdk"; - } - else if (item instanceof Sdk) { - myType = "Sdk"; - } - else { - myType = null; - } - - myClassPath = item.getClasspathRoots(null); - } - - public GenericClasspathItemWrapper(final BufferedReader r) { - myType = RW.readString(r); - - RW.readTag(r, "Classpath:"); - myClassPath = (List)RW.readMany(r, RW.myStringReader, new ArrayList()); - } - - public String getType() { - return myType; - } - - public List getClassPath(final ClasspathKind kind) { - return myClassPath; - } - - public void write(final BufferedWriter w) { - RW.writeln(w, myType); - RW.writeln(w, "Classpath:"); - RW.writeln(w, myClassPath, RW.fromString); - } - } - - private final RW.Reader myFileWrapperReader = new RW.Reader() { - public FileWrapper read(final BufferedReader r) { - return new FileWrapper(r); - } - }; - - public class FileWrapper implements RW.Writable { - final String myName; - final long myModificationTime; - - FileWrapper(final File f) { - myName = f.getAbsolutePath(); - myModificationTime = f.lastModified(); - } - - FileWrapper(final BufferedReader r) { - myName = RW.readString(r); - myModificationTime = RW.readLong(r); - } - - public String getName() { - return myName; - } - - public long getStamp() { - return myModificationTime; - } - - public void write(final BufferedWriter w) { - final String name = getName(); - - RW.writeln(w, name); - RW.writeln(w, Long.toString(getStamp())); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - FileWrapper that = (FileWrapper)o; - - if (myName != null ? !myName.equals(that.myName) : that.myName != null) return false; - - return true; - } - - @Override - public int hashCode() { - return myName != null ? myName.hashCode() : 0; - } - } - - private final RW.Reader myModuleWrapperReader = new RW.Reader() { - public ModuleWrapper read(final BufferedReader r) { - return new ModuleWrapper(r); - } - }; - - public class ModuleWrapper implements ClasspathItemWrapper { - - private class Properties implements RW.Writable { - final Set myRoots; - final Map mySources; - - final String myOutput; - String myOutputStatus; - - public Set getFiles() { - final Set result = new HashSet(); - - for (FileWrapper f : mySources.keySet()) { - result.add(f.getName()); - } - - return result; - } - - public Set getOutdatedFiles(final Properties past) { - final Set result = new HashSet(); - - for (FileWrapper now : mySources.keySet()) { - final FileWrapper than = past == null ? null : past.mySources.get(now); - - if (than == null || than.getStamp() < now.getStamp() || affectedFiles.contains(now.getName())) { - result.add(now.getName()); - } - } - - return result; - } - - public Set getRemovedFiles(final Properties past) { - final Set result = new HashSet(); - - if (past != null) { - for (FileWrapper was : past.mySources.keySet()) { - final FileWrapper now = mySources.get(was); - - if (now == null) { - result.add(was.getName()); - } - } - } - - return result; - } - - public void write(final BufferedWriter w) { - RW.writeln(w, "Roots:"); - RW.writeln(w, myRoots, RW.fromString); - - RW.writeln(w, "Sources:"); - RW.writeln(w, mySources.keySet()); - - RW.writeln(w, "Output:"); - RW.writeln(w, myOutput == null ? "" : myOutput); - - RW.writeln(w, "OutputStatus:" + myOutputStatus); - } - - public Properties(final BufferedReader r) { - RW.readTag(r, "Roots:"); - - myRoots = (Set)RW.readMany(r, RW.myStringReader, new HashSet()); - - RW.readTag(r, "Sources:"); - - mySources = new HashMap(); - - for (FileWrapper fw : (Set)RW.readMany(r, myFileWrapperReader, new HashSet())) { - mySources.put(fw, fw); - } - - RW.readTag(r, "Output:"); - final String s = RW.readString(r); - myOutput = s.equals("") ? null : s; - - myOutputStatus = RW.readStringAttribute(r, "OutputStatus:"); - } - - public Properties(final List sources, final String output, final Set excludes) { - myRoots = new HashSet(sources); - final DirectoryScanner.Result result = DirectoryScanner.getFiles(myRoots, excludes, ProjectWrapper.this); - - mySources = new HashMap(); - - for (FileWrapper fw : result.getFiles()) { - mySources.put(fw, fw); - } - - myOutput = output; - updateOutputStatus(); - } - - public void updateOutputStatus() { - final String path = myOutput; - final File ok = new File(path + File.separator + Reporter.myOkFlag); - final File fail = new File(path + File.separator + Reporter.myFailFlag); - - if (ok.exists()) { - myOutputStatus = "ok"; - return; - } - - if (fail.exists()) { - myOutputStatus = "fail"; - return; - } - - myOutputStatus = "empty"; - } - - public Set getRoots() { - return myRoots; - } - - public Set getSources() { - return mySources.keySet(); - } - - public String getOutputPath() { - return myOutput; - } - - public boolean emptySource() { - return mySources.isEmpty(); - } - - public boolean outputOk() { - return myOutputStatus.equals("ok"); - } - - public boolean outputEmpty() { - return myOutputStatus.equals("empty"); - } - - public boolean isOutdated() { - return (!emptySource() && !outputOk()); - } - } - - final String myName; - final Properties mySource; - final Properties myTest; - - List myDependsOn; - List myTestDependsOn; - - final Set myExcludes; - final Module myModule; - final Set myLibraries; - - public Set getOutdatedSources() { - return mySource.getOutdatedFiles(myHistory == null ? null : myHistory.getModule(myName).mySource); - } - - public Set getOutdatedTests() { - return myTest.getOutdatedFiles(myHistory == null ? null : myHistory.getModule(myName).myTest); - } - - public Set getRemovedSources() { - return mySource.getRemovedFiles(myHistory == null ? null : myHistory.getModule(myName).mySource); - } - - public Set getRemovedTests() { - return myTest.getRemovedFiles(myHistory == null ? null : myHistory.getModule(myName).myTest); - } - - public void updateOutputStatus() { - mySource.updateOutputStatus(); - myTest.updateOutputStatus(); - } - - private ClasspathItemWrapper weaken(final ClasspathItemWrapper x) { - if (x instanceof ModuleWrapper) { - return new WeakClasspathItemWrapper((ModuleWrapper)x); - } - else if (x instanceof LibraryWrapper) { - return new WeakClasspathItemWrapper((LibraryWrapper)x); - } - else { - return x; - } - } - - public void write(final BufferedWriter w) { - RW.writeln(w, "Module:" + myName); - - RW.writeln(w, "SourceProperties:"); - mySource.write(w); - - RW.writeln(w, "TestProperties:"); - myTest.write(w); - - RW.writeln(w, "Excludes:"); - RW.writeln(w, myExcludes, RW.fromString); - - RW.writeln(w, "Libraries:"); - RW.writeln(w, myLibraries); - - RW.writeln(w, "Dependencies:"); - - final List weakened = new ArrayList(); - - for (ClasspathItemWrapper cpiw : dependsOn(false)) { - weakened.add(weaken(cpiw)); - } - - RW.writeln(w, weakened); - - weakened.clear(); - - for (ClasspathItemWrapper cpiw : dependsOn(true)) { - weakened.add(weaken(cpiw)); - } - - RW.writeln(w, weakened); - } - - public ModuleWrapper(final BufferedReader r) { - myModule = null; - myName = RW.readStringAttribute(r, "Module:"); - - RW.readTag(r, "SourceProperties:"); - mySource = new Properties(r); - - RW.readTag(r, "TestProperties:"); - myTest = new Properties(r); - - RW.readTag(r, "Excludes:"); - myExcludes = (Set)RW.readMany(r, RW.myStringReader, new HashSet()); - - RW.readTag(r, "Libraries:"); - myLibraries = (Set)RW.readMany(r, myLibraryWrapperReader, new HashSet()); - - RW.readTag(r, "Dependencies:"); - myDependsOn = (List)RW.readMany(r, myWeakClasspathItemWrapperReader, new ArrayList()); - myTestDependsOn = (List)RW.readMany(r, myWeakClasspathItemWrapperReader, new ArrayList()); - } - - public ModuleWrapper(final Module m) { - m.forceInit(); - myModule = m; - myDependsOn = null; - myTestDependsOn = null; - myName = m.getName(); - myExcludes = new HashSet(m.getExcludes()); - mySource = new Properties(m.getSourceRoots(), m.getOutputPath(), myExcludes); - myTest = new Properties(m.getTestRoots(), m.getTestOutputPath(), myExcludes); - - myLibraries = new HashSet(); - - for (Library lib : m.getLibraries().values()) { - myLibraries.add(new LibraryWrapper(lib)); - } - } - - public String getName() { - return myName; - } - - public Set getOutdatedFiles(final boolean tests) { - if (tests) { - return myTest.outputEmpty() ? getTests() : getOutdatedTests(); - } - - return mySource.outputEmpty() ? getSources() : getOutdatedSources(); - } - - public Set getRemovedFiles(final boolean tests) { - if (tests) { - return getRemovedTests(); - } - - return getRemovedSources(); - } - - public Set getSources(final boolean tests) { - if (tests) { - return myTest.getFiles(); - } - - return mySource.getFiles(); - } - - public Set getSourceRoots() { - return mySource.getRoots(); - } - - public Set getSourceFiles() { - return mySource.getSources(); - } - - public Set getTestFiles() { - return myTest.getSources(); - } - - public Set getSources() { - return mySource.getFiles(); - } - - public Set getTests() { - return myTest.getFiles(); - } - - public String getOutputPath() { - return mySource.getOutputPath(); - } - - public Set getTestSourceRoots() { - return myTest.getRoots(); - } - - public Set getTestSourceFiles() { - return myTest.getSources(); - } - - public String getTestOutputPath() { - return myTest.getOutputPath(); - } - - public List dependsOn(final boolean tests) { - if (tests) { - if (myTestDependsOn != null) { - return myTestDependsOn; - } - } - else if (myDependsOn != null) { - return myDependsOn; - } - - final List result = new ArrayList(); - - for (ClasspathItem cpi : myModule.getClasspath(ClasspathKind.compile(tests))) { - if (cpi instanceof Module) { - result.add(getModule(((Module)cpi).getName())); - } - else if (cpi instanceof Library) { - result.add(new LibraryWrapper((Library)cpi)); - } - else { - result.add(new GenericClasspathItemWrapper(cpi)); - } - } - - if (tests) { - myTestDependsOn = result; - } - else { - myDependsOn = result; - } - - return result; - } - - public List getClassPath(final ClasspathKind kind) { - final List result = new ArrayList(); - - result.add(getOutputPath()); - - if (kind.isTestsIncluded()) { - result.add(getTestOutputPath()); - } - - return result; - } - - private boolean safeEquals(final String a, final String b) { - if (a == null || b == null) return a == b; - - return a.equals(b); - } - - private boolean safeEquals(final ClasspathItemWrapper a, final ClasspathItemWrapper b) { - try { - final StringWriter as = new StringWriter(); - final StringWriter bs = new StringWriter(); - - final BufferedWriter bas = new BufferedWriter(as); - final BufferedWriter bbs = new BufferedWriter(bs); - - weaken(a).write(bas); - weaken(b).write(bbs); - - bas.flush(); - bbs.flush(); - - as.close(); - bs.close(); - - final String x = as.getBuffer().toString(); - final String y = bs.getBuffer().toString(); - - return x.equals(y); - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - - public boolean isOutdated(final boolean tests, final ProjectWrapper history) { - if (history == null) { - return true; - } - - final ModuleWrapper past = history.getModule(myName); - - if (past == null) { - return true; - } - - final boolean outputChanged = !safeEquals(past.getOutputPath(), getOutputPath()); - final boolean testOutputChanged = tests && !safeEquals(past.getTestOutputPath(), getTestOutputPath()); - final boolean sourceChanged = !past.getSourceFiles().equals(getSourceFiles()); - final boolean testSourceChanged = tests && !past.getTestSourceFiles().equals(getTestSourceFiles()); - final boolean sourceOutdated = mySource.isOutdated() || !mySource.getOutdatedFiles(past.mySource).isEmpty(); - final boolean testSourceOutdated = tests && (myTest.isOutdated() || !myTest.getOutdatedFiles(past.myTest).isEmpty()); - final boolean unsafeDependencyChange = (new Object() { - public boolean run(final List today, final List yesterday) { - final Iterator t = today.iterator(); - final Iterator y = yesterday.iterator(); - - while (true) { - if (!y.hasNext()) return false; - - if (!t.hasNext()) return true; - - if (!safeEquals(t.next(), y.next())) return true; - } - } - }.run(dependsOn(tests), past.dependsOn(tests))); - - return sourceOutdated || - testSourceOutdated || - sourceChanged || - testSourceChanged || - outputChanged || - testOutputChanged || - unsafeDependencyChange; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ModuleWrapper that = (ModuleWrapper)o; - - if (myName != null ? !myName.equals(that.myName) : that.myName != null) return false; - - return true; - } - - @Override - public int hashCode() { - return myName != null ? myName.hashCode() : 0; - } - } - - final Map myModules = new HashMap(); - final Map myLibraries = new HashMap(); - - public ModuleWrapper getModule(final String name) { - return myModules.get(name); - } - - public LibraryWrapper getLibrary(final String name) { - return myLibraries.get(name); - } - - public Collection getLibraries() { - return myLibraries.values(); - } - - public Collection getModules() { - return myModules.values(); - } - - Mappings dependencyMapping; - final Callbacks.Backend backendCallback; - final Set affectedFiles; - - final ProjectWrapper myHistory; - - private static String getCanonicalPath(final String path) { - try { - return new File(path).getCanonicalPath(); - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - - private ProjectWrapper(final GantBinding binding, - final String prjDir, - final String setupScript, - final Map pathVariables, - final boolean loadHistory) { - affectedFiles = new HashSet(); - - myProject = new GantBasedProject(binding == null ? new GantBinding() : binding); - myProjectBuilder = myProject.getBuilder(); - - final File prjFile = new File(prjDir); - final boolean dirBased = !(prjFile.isFile() && prjDir.endsWith(".ipr")); - - myRoot = dirBased ? getCanonicalPath(prjDir) : getCanonicalPath(prjFile.getParent()); - - final String loadPath = dirBased ? getAbsolutePath(myIDEADir) : prjDir; - - IdeaProjectLoader - .loadFromPath(myProject, loadPath, pathVariables != null ? pathVariables : Collections.emptyMap(), setupScript); - - myProjectSnapshot = - myHomeDir + File.separator + myJPSDir + File.separator + myRoot.replace(File.separatorChar, myFileSeparatorReplacement); - - try { - dependencyMapping = new Mappings(getMapDir(), true); - } - catch (IOException e) { - throw new RuntimeException(e); - } - backendCallback = dependencyMapping.getCallback(); - - for (Module m : myProject.getModules().values()) { - myModules.put(m.getName(), new ModuleWrapper(m)); - } - - for (Library l : myProject.getLibraries().values()) { - myLibraries.put(l.getName(), new LibraryWrapper(l)); - } - - myHistory = loadHistory ? loadSnapshot(affectedFiles) : null; - - if (loadHistory) { - dependencyMapping = myHistory.dependencyMapping; - } - } - - private File getMapDir() { - final File f = new File(myProjectSnapshot + ".dir"); - - if (f.exists()) { - return f; - } - - assert (f.mkdir()); - - return f; - } - - private ProjectWrapper(final BufferedReader r, final Set affected) { - affectedFiles = affected; - myProject = null; - myProjectBuilder = null; - myHistory = null; - - myRoot = RW.readStringAttribute(r, "Root:"); - myProjectSnapshot = - myHomeDir + File.separator + myJPSDir + File.separator + myRoot.replace(File.separatorChar, myFileSeparatorReplacement); - - RW.readTag(r, "Libraries:"); - final Set libs = (Set)RW.readMany(r, myLibraryWrapperReader, new HashSet()); - - for (LibraryWrapper l : libs) { - myLibraries.put(l.getName(), l); - } - - RW.readTag(r, "Modules:"); - final Set mods = (Set)RW.readMany(r, myModuleWrapperReader, new HashSet()); - - for (ModuleWrapper m : mods) { - myModules.put(m.getName(), m); - } - - RW.readMany(r, RW.myStringReader, affectedFiles); - - try { - dependencyMapping = new Mappings(getMapDir(), true); - } - catch (IOException e) { - throw new RuntimeException(e); - } - backendCallback = dependencyMapping.getCallback(); - } - - private String getAbsolutePath(final String relative) { - if (relative == null) return relative; - - if (new File(relative).isAbsolute()) return relative; - - return myRoot + File.separator + relative; - } - - private String getRelativePath(final String absolute) { - if (absolute == null) return absolute; - - if (absolute.startsWith(myRoot)) { - return absolute.substring(myRoot.length() + 1); - } - - return absolute; - } - - private boolean isHistory() { - return myProject == null; - } - - public void write(final BufferedWriter w) { - RW.writeln(w, "Root:" + myRoot); - - RW.writeln(w, "Libraries:"); - RW.writeln(w, getLibraries()); - - RW.writeln(w, "Modules:"); - RW.writeln(w, getModules()); - - RW.writeln(w, affectedFiles, RW.fromString); - } - - private String getProjectSnapshotFileName() { - return myProjectSnapshot; - } - - private ProjectWrapper loadSnapshot(final Set affectedFiles) { - initJPSDirectory(); - - try { - final BufferedReader r = new BufferedReader(new FileReader(getProjectSnapshotFileName())); - final ProjectWrapper w = new ProjectWrapper(r, affectedFiles); - r.close(); - - return w; - } - catch (Exception e) { - throw new RuntimeException(e); - } - } - - private void saveSnapshot() { - initJPSDirectory(); - - try { - BufferedWriter bw = new BufferedWriter(new FileWriter(getProjectSnapshotFileName())); - - write(bw); - - bw.close(); - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - - public static ProjectWrapper load(final String path, final String setupScript, final boolean loadHistory) { - return new ProjectWrapper(null, path, setupScript, null, loadHistory); - } - - public static ProjectWrapper load(final GantBinding binding, - final String path, - final String setupScript, - final Map pathVariables, - final boolean loadHistory) { - return new ProjectWrapper(binding, path, setupScript, pathVariables, loadHistory); - } - - public void report(final String module) { - final ModuleWrapper m = getModule(module); - - if (m == null) { - System.out.println("No module \"" + module + "\" found in project \""); - } - else { - System.out.println("Module " + m.myName + " " + (m.isOutdated(false, myHistory) ? "is outdated" : "is up-to-date")); - System.out.println("Module " + m.myName + " tests " + (m.isOutdated(true, myHistory) ? "are outdated" : "are up-to-date")); - } - } - - public void report() { - boolean moduleReport = true; - - System.out.println("Project \"" + myRoot + "\" report:"); - - if (myHistory == null) { - System.out.println(" no project history found"); - } - - if (moduleReport) { - for (ModuleWrapper m : myModules.values()) { - System.out.println(" module " + m.getName() + " " + (m.isOutdated(false, myHistory) ? "is outdated" : "is up-to-date")); - System.out.println(" module " + m.getName() + " tests " + (m.isOutdated(true, myHistory) ? "are outdated" : "are up-to-date")); - } - } - } - - public void save() { - dependencyMapping.close(); - saveSnapshot(); - } - - public void clean() { - myProjectBuilder.clean(); - - for (ModuleWrapper m : myModules.values()) { - m.updateOutputStatus(); - } - - new File(myProjectSnapshot).delete(); - } - - public void rebuild() { - try { - dependencyMapping.clean(); - makeModules(myProject.getModules().values(), defaultFlags); - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - - public Project getProject() { - return myProject; - } - - enum BuildStatus {FAILURE, INCREMENTAL, CONSERVATIVE} - - class BusyBeaver { - final ProjectBuilder builder; - final Set compiledFiles = new HashSet(); - final Set cleared = new HashSet(); - - BusyBeaver(ProjectBuilder builder) { - this.builder = builder; - } - - BuildStatus iterativeCompile(final ModuleChunk chunk, - final Set sources, - final Set outdated, - final Set removed, - final Flags flags) { - final Collection filesToCompile = DefaultGroovyMethods.intersect(affectedFiles, sources); - - if (outdated != null) { - for (String s : outdated) { - assert (s != null); - } - - filesToCompile.addAll(outdated); - } - - filesToCompile.removeAll(compiledFiles); - - if (!filesToCompile.isEmpty() || removed != null) { - final Set outputFiles = new HashSet(); - - for (String f : filesToCompile) { - final Set classes = dependencyMapping.getClasses(f); - - if (classes != null) { - for (ClassRepr cr : classes) { - outputFiles.add(cr.getFileName()); - } - } - } - - if (removed != null) { - for (String f : removed) { - final Set classes = dependencyMapping.getClasses(f); - if (classes != null) { - for (ClassRepr cr : classes) { - outputFiles.add(cr.getFileName()); - } - } - } - } - - if (!outputFiles.isEmpty()) { - new Logger(flags) { - @Override - public void log(PrintStream stream) { - stream.println("Cleaning output files:"); - logFilePaths(stream, outputFiles); - stream.println("End of files"); - } - }.log(); - - builder.clearChunk(chunk, outputFiles, ProjectWrapper.this); - } - - final Mappings delta = dependencyMapping.createDelta(); - final Callbacks.Backend deltaBackend = delta.getCallback(); - - new Logger(flags) { - @Override - public void log(PrintStream stream) { - stream.println("Compiling files:"); - logFilePaths(stream, filesToCompile); - stream.println("End of files"); - } - }.log(); - - boolean buildException = false; - - try { - builder.buildChunk(chunk, flags.tests(), filesToCompile, deltaBackend, ProjectWrapper.this); - } - catch (Exception e) { - e.printStackTrace(); - buildException = true; - } - - if (!buildException) { - compiledFiles.addAll(filesToCompile); - affectedFiles.removeAll(filesToCompile); - - final Collection files = new HashSet(); - final Collection compiled = new HashSet(); - - for (String f : filesToCompile) { - files.add(new File(f)); - } - - for (String f : compiledFiles) { - compiled.add(new File(f)); - } - - final Collection affected = new HashSet(); - - final boolean incremental = dependencyMapping.differentiate(delta, removed, files, compiled, affected, - Mappings.DependentFilesFilter.ALL_FILES); - - for (File a : affected) { - affectedFiles.add(FileUtil.toSystemIndependentName(a.getAbsolutePath())); - } - - dependencyMapping.integrate(delta, files, removed); - - if (!incremental) { - affectedFiles.addAll(sources); - affectedFiles.removeAll(compiledFiles); - - final BuildStatus result = iterativeCompile(chunk, sources, null, null, flags); - - if (result == BuildStatus.FAILURE) { - return result; - } - - return BuildStatus.CONSERVATIVE; - } - - return iterativeCompile(chunk, sources, null, null, flags); - } - else { - delta.close(); - return BuildStatus.FAILURE; - } - } - else { - for (Module m : chunk.getElements()) { - Reporter.reportBuildSuccess(m, flags.tests()); - } - } - - return BuildStatus.INCREMENTAL; - } - - public BuildStatus build(final Collection modules, final Flags flags) { - boolean incremental = flags.incremental(); - final List chunks = myProjectBuilder.getChunks(flags.tests()).getChunkList(); - - for (final ModuleChunk c : chunks) { - final Set chunkModules = c.getElements(); - - if (!DefaultGroovyMethods.intersect(modules, chunkModules).isEmpty()) { - final Set removedSources = new HashSet(); - - if (incremental) { - final Set chunkSources = new HashSet(); - final Set outdatedSources = new HashSet(); - - for (Module m : chunkModules) { - final ModuleWrapper mw = getModule(m.getName()); - - outdatedSources.addAll(mw.getOutdatedFiles(flags.tests())); - chunkSources.addAll(mw.getSources(flags.tests())); - removedSources.addAll(mw.getRemovedFiles(flags.tests())); - } - - final BuildStatus result = iterativeCompile(c, chunkSources, outdatedSources, removedSources, flags); - - incremental = result == BuildStatus.INCREMENTAL; - - if (result == BuildStatus.FAILURE) { - return result; - } - } - else { - new Logger(flags) { - @Override - public void log(PrintStream stream) { - stream.println("Compiling chunk " + c.getName() + " non-incrementally."); - } - }.log(); - - for (Module m : chunkModules) { - final ModuleWrapper mw = getModule(m.getName()); - removedSources.addAll(flags.tests() ? mw.getRemovedTests() : mw.getRemovedSources()); - } - - final Set toClean = new HashSet(); - - for (Module m : chunkModules) { - if (!cleared.contains(m)) { - toClean.add(m); - } - } - - if (!toClean.isEmpty() && !flags.tests()) { - builder.clearChunk(new ModuleChunk(toClean), null, ProjectWrapper.this); - cleared.addAll(toClean); - } - - final Mappings delta = dependencyMapping.createDelta(); - final Callbacks.Backend deltaCallback = delta.getCallback(); - - try { - builder.buildChunk(c, flags.tests(), null, deltaCallback, ProjectWrapper.this); - } - catch (Exception e) { - e.printStackTrace(); - delta.close(); - - return BuildStatus.FAILURE; - } - - final Set allFiles = new HashSet(); - - for (Module m : c.getElements()) { - final ModuleWrapper module = getModule(m.getName()); - affectedFiles.removeAll(module.getSources(flags.tests())); - allFiles.addAll(module.getSources(flags.tests())); - } - - final Collection files = new HashSet(); - - for (String f : allFiles) { - files.add(new File(f)); - } - - dependencyMapping.integrate(delta, files, removedSources); - - for (Module m : chunkModules) { - Reporter.reportBuildSuccess(m, flags.tests()); - } - } - } - } - - return BuildStatus.INCREMENTAL; - } - } - - public void makeModules(final Collection initial, final Flags flags) { - if (myHistory == null && !flags.tests()) { - clean(); - } - - new Logger(flags) { - @Override - public void log(final PrintStream stream) { - stream.println("Request to make modules:"); - logMany(stream, initial); - stream.println("End of request"); - } - }.log(); - - final ClasspathKind kind = ClasspathKind.compile(flags.tests()); - - final Set modules = new HashSet(); - final Set marked = new HashSet(); - final Map visited = new HashMap(); - final Set frontier = new HashSet(); - - final Map> reversedDependencies = new HashMap>(); - final DotPrinter printer = new DotPrinter(flags.logStream()); - - printer.header(); - - for (Module m : myProject.getModules().values()) { - final String mName = m.getName(); - - printer.node(mName); - - for (ClasspathItem cpi : m.getClasspath(kind)) { - if (cpi instanceof Module) { - final String name = ((Module)cpi).getName(); - - printer.edge(name, mName); - - Set sm = reversedDependencies.get(name); - - if (sm == null) { - sm = new HashSet(); - reversedDependencies.put(name, sm); - } - - sm.add(mName); - } - } - } - - printer.footer(); - - // Building "upper" subgraph - - printer.header(); - - new Object() { - public void run(final Collection initial) { - if (initial == null) return; - - for (Module module : initial) { - - final String mName = module.getName(); - - if (marked.contains(mName)) continue; - - printer.node(mName); - - final List dep = new ArrayList(); - - for (ClasspathItem cpi : module.getClasspath(kind)) { - if (cpi instanceof Module && !marked.contains(((Module)cpi).getName())) { - printer.edge(((Module)cpi).getName(), mName); - dep.add((Module)cpi); - } - } - - if (dep.size() == 0) { - frontier.add(mName); - } - - marked.add(mName); - - run(dep); - } - } - }.run(initial); - - printer.footer(); - - // Traversing "upper" subgraph and collecting outdated modules and their descendants - new Object() { - public void run(final Collection initial, final boolean force) { - if (initial == null) return; - - for (String moduleName : initial) { - if (!marked.contains(moduleName)) continue; - - final Boolean property = visited.get(moduleName); - - if (property == null || !property && force) { - final boolean outdated = getModule(moduleName).isOutdated(flags.tests(), myHistory); - - - if (force || outdated) { - visited.put(moduleName, true); - modules.add(myProject.getModules().get(moduleName)); - - run(reversedDependencies.get(moduleName), true); - } - else { - if (property == null) { - visited.put(moduleName, false); - } - run(reversedDependencies.get(moduleName), false); - } - } - } - } - }.run(frontier, flags.force()); - - new Logger(flags) { - @Override - public void log(PrintStream stream) { - stream.println("Propagated modules:"); - logMany(stream, modules); - stream.println("End of propagated"); - } - }.log(); - - if (modules.size() == 0 && !flags.force()) { - System.out.println("All requested modules are up-to-date."); - return; - } - - final BusyBeaver beaver = new BusyBeaver(myProjectBuilder); - - myProjectBuilder.buildStart(); - - if (flags.tests()) { - beaver.build(modules, new Flags() { - public boolean tests() { - return false; - } - - public boolean incremental() { - return flags.incremental(); - } - - public boolean force() { - return flags.force(); - } - - public PrintStream logStream() { - return flags.logStream(); - } - }); - } - - beaver.build(modules, flags); - - myProjectBuilder.buildStop(); - - for (Module mod : modules) { - getModule(mod.getName()).updateOutputStatus(); - } - } - - public void makeModule(final String modName, final Flags flags) { - if (modName == null) { - makeModules(myProject.getModules().values(), flags); - } - else { - final Module module = myProject.getModules().get(modName); - final List list = new ArrayList(); - - if (module == null) { - System.err.println("Module \"" + modName + "\" not found in project \"" + myRoot + "\""); - return; - } - - list.add(module); - - makeModules(list, flags); - } - } -} diff --git a/jps/src/org/jetbrains/ether/Reporter.java b/jps/src/org/jetbrains/ether/Reporter.java deleted file mode 100644 index 697b6e4163e1..000000000000 --- a/jps/src/org/jetbrains/ether/Reporter.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.jetbrains.ether; - -import org.jetbrains.jps.Module; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; - -/** - * Created by IntelliJ IDEA. - * User: db - * Date: 03.12.10 - * Time: 19:39 - * To change this template use File | Settings | File Templates. - */ -public class Reporter { - public static final String myOkFlag = ".jps.ok"; - public static final String myFailFlag = ".jps.fail"; - - private static String getSafePath(final String path) { - final File f = new File(path); - - if (!f.exists()) { - f.mkdir(); - } - - return path; - } - - private static String getOkFlag(final Module m) { - final String outputPath = m.getOutputPath(); - - if (outputPath == null) return null; - - return getSafePath(outputPath) + File.separator + myOkFlag; - } - - private static String getFailFlag(final Module m) { - final String outputPath = m.getOutputPath(); - - if (outputPath == null) return null; - - return getSafePath(outputPath) + File.separator + myFailFlag; - } - - private static String getOkTestFlag(final Module m) { - final String testOutputPath = m.getTestOutputPath(); - - if (testOutputPath == null) return null; - - return getSafePath(testOutputPath) + File.separator + myOkFlag; - } - - private static String getFailTestFlag(final Module m) { - final String testOutputPath = m.getTestOutputPath(); - - if (testOutputPath == null) { - return null; - } - - return getSafePath(testOutputPath) + File.separator + myFailFlag; - } - - private static void write(final String name, final String contents) { - if (name == null) return; - - try { - final File file = new File(name); - final String path = file.getParent(); - - new File(path).mkdirs(); - - final FileWriter writer = new FileWriter(name); - - writer.write(contents); - writer.close(); - - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - - public static void reportBuildSuccess(final Module m, final boolean tests) { - if (tests) { - write(getOkTestFlag(m), "dummy"); - } - else { - write(getOkFlag(m), "dummy"); - } - } - - public static void reportBuildFailure(final Module m, final boolean tests, final String reason) { - if (tests) { - write(getFailTestFlag(m), reason); - } - else { - write(getFailFlag(m), reason); - } - } -} diff --git a/jps/src/org/jetbrains/ether/dependencyView/AntListener.java b/jps/src/org/jetbrains/ether/dependencyView/AntListener.java deleted file mode 100644 index 7c8a7f0d8ffa..000000000000 --- a/jps/src/org/jetbrains/ether/dependencyView/AntListener.java +++ /dev/null @@ -1,307 +0,0 @@ -package org.jetbrains.ether.dependencyView; - -import org.apache.tools.ant.BuildEvent; -import org.apache.tools.ant.BuildListener; -import org.jetbrains.asm4.ClassReader; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Created by IntelliJ IDEA. - * User: db - * Date: 01.04.11 - * Time: 21:31 - * To change this template use File | Settings | File Templates. - */ -public class AntListener implements BuildListener { - private static final Pattern read = Pattern.compile("\\[parsing started (.*)\\]"); - private static final Pattern written = Pattern.compile("\\[wrote (.*)\\]"); - - private final Map> readFiles = new HashMap>(); - private final Map> writtenFiles = new HashMap>(); - private final String targetFolder; - private final int stripLength; - private final List sourceRoots; - private final Callbacks.Backend callback; - - private static String basename(final String name, final String extension) { - return name.substring(0, name.length() - extension.length()); - } - - private static ClassReader getClassReader(final String fullName) { - try { - final File f = new File(fullName); - final byte[] buffer = new byte[(int)f.length()]; - final FileInputStream i = new FileInputStream(f); - - final int n = i.read(buffer); - - i.close(); - - assert ((int)f.length() == n); - - return new ClassReader(buffer); - } - catch (IOException e) { - e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. - return null; - } - } - - private class ClassFileInfo { - final String packageName; - final String fullName; - List subClasses = null; - - public ClassFileInfo(final String fullName, final String packageName) { - this.packageName = packageName; - this.fullName = fullName; - } - - public void attachSubClass(final String name) { - if (subClasses == null) { - subClasses = new LinkedList(); - } - - subClasses.add(name); - } - - public String getFullName() { - return fullName; - } - - public String getPackageName() { - return packageName; - } - - public String toString() { - final StringBuilder builder = new StringBuilder(); - - builder.append(" Root: ").append(fullName).append(", package ").append(packageName).append("\n"); - builder.append(" Subclasses:"); - - if (subClasses != null) { - for (String s : subClasses) { - builder.append(" ").append(s); - } - } - - builder.append(".\n"); - - return builder.toString(); - } - - public void associate(final Callbacks.SourceFileNameLookup sourceFileNameLookup) { - if (callback != null) { - callback.associate(fullName, sourceFileNameLookup, getClassReader(fullName)); - - if (subClasses != null) { - for (String s : subClasses) { - callback.associate(s, sourceFileNameLookup, getClassReader(s)); - } - } - } - } - } - - public AntListener(final String targetFolder, final List sourceRoots, final Callbacks.Backend callback) { - this.targetFolder = targetFolder; - this.sourceRoots = sourceRoots; - this.callback = callback; - stripLength = targetFolder.length() + 1; - } - - public void buildStarted(BuildEvent event) { - //To change body of implemented methods use File | Settings | File Templates. - } - - public void buildFinished(BuildEvent event) { - //To change body of implemented methods use File | Settings | File Templates. - } - - public void targetStarted(BuildEvent event) { - //To change body of implemented methods use File | Settings | File Templates. - } - - public void targetFinished(BuildEvent event) { - //To change body of implemented methods use File | Settings | File Templates. - } - - public void taskStarted(BuildEvent event) { - } - - public void taskFinished(BuildEvent event) { - if (event.getTask().getTaskName().equals("javac")) { - for (Map.Entry> e : writtenFiles.entrySet()) { - final String className = e.getKey(); - - final List infos = e.getValue(); - final List read = readFiles.get(className); - - if (infos.size() == 1 && read != null && read.size() == 1) { - infos.get(0).associate(Callbacks.getDefaultLookup(read.get(0))); - continue; - } - - process: - for (ClassFileInfo c : infos) { - final String packageName = c.getPackageName(); - - final Callbacks.SourceFileNameLookup sourceNameLookup = new Callbacks.SourceFileNameLookup() { - public String get(final String sourceAttribute) { - - assert (sourceAttribute != null); - - final String className = basename(sourceAttribute, ".java"); - final List candidates = readFiles.get(className); - - assert (candidates != null); - - if (candidates.size() == 1) { - return candidates.get(0); - } - - for (String r : candidates) { - if (new PackageNameSelector().get(r).equals(packageName)) { - return r; - } - } - - assert (false); - - return null; - } - }; - - c.associate(sourceNameLookup); - } - } - - /* - System.out.println("Written files info:"); - - for (Map.Entry> e : writtenFiles.entrySet()) { - final String className = e.getKey(); - final List infos = e.getValue(); - - System.out.println(" Class name: " + className); - System.out.println(" Class file info(s): "); - - for (ClassFileInfo c : infos) { - System.out.println(c.toString()); - } - } - - System.out.println("End."); - - System.out.println("Read files info:"); - - for (Map.Entry> e : readFiles.entrySet()) { - final String className = e.getKey(); - final List files = e.getValue(); - - System.out.println(" Class name: " + className); - System.out.print(" Files:"); - - for (String file : files) { - System.out.print(" " + file); - } - - System.out.println("."); - } - System.out.println("End."); - */ - } - } - - private String extractPackage(final String s) { - if (s.length() < stripLength) return ""; - - return s.substring(stripLength); - } - - public void messageLogged(BuildEvent event) { - final String m = event.getMessage(); - final Matcher writtenMatcher = written.matcher(m); - final Matcher readMatcher = read.matcher(m); - - if (writtenMatcher.matches()) { - final String fullName = writtenMatcher.group(1); - final File file = new File(fullName); - - final String classFileName = file.getName(); - final String packageName = extractPackage(fullName.substring(0, fullName.length() - classFileName.length() - 1)); - - String className = basename(classFileName, ".class"); - boolean subClass = false; - - final int i = className.indexOf('$'); - - if (i >= 0) { - className = className.substring(0, i); - subClass = true; - } - - List info = writtenFiles.get(className); - - - if (info == null) { - info = new LinkedList(); - writtenFiles.put(className, info); - } - - boolean updated = false; - - for (ClassFileInfo ci : info) { - if (subClass) { - if (ci.getPackageName().equals(packageName)) { - ci.attachSubClass(fullName); - updated = true; - } - } - else { - if (ci.getFullName().equals(fullName)) { - updated = true; - break; - } - } - } - - if (!updated) { - if (subClass) { - final ClassFileInfo c = - new ClassFileInfo(targetFolder + File.separator + packageName + File.separator + className + ".class", packageName); - c.attachSubClass(fullName); - info.add(c); - } - else { - info.add(new ClassFileInfo(fullName, packageName)); - } - } - } - - if (readMatcher.matches()) { - final String fullName = readMatcher.group(1); - final File file = new File(fullName); - final String sourceFileName = file.getName(); - final String className = basename(sourceFileName, ".java"); - - List files = readFiles.get(className); - - if (files == null) { - files = new LinkedList(); - readFiles.put(className, files); - } - - files.add(fullName); - } - } -} diff --git a/jps/src/org/jetbrains/jps/ModuleBuildState.groovy b/jps/src/org/jetbrains/jps/ModuleBuildState.groovy index 52f15608c417..ae6c47576f5e 100644 --- a/jps/src/org/jetbrains/jps/ModuleBuildState.groovy +++ b/jps/src/org/jetbrains/jps/ModuleBuildState.groovy @@ -2,27 +2,22 @@ package org.jetbrains.jps import com.intellij.ant.InstrumentationUtil.FormInstrumenter import com.intellij.compiler.instrumentation.InstrumentationClassFinder -import org.jetbrains.ether.ProjectWrapper import org.jetbrains.ether.dependencyView.Callbacks.Backend /** * @author max */ class ModuleBuildState { - boolean iterated boolean tests Backend callback FormInstrumenter formInstrumenter InstrumentationClassFinder loader - ProjectWrapper projectWrapper - List sourceFiles List sourceRoots List excludes List classpath List tempRootsToDelete = [] List sourceRootsFromModuleWithDependencies String targetFolder - boolean incremental = false def print() { println "Sources: $sourceRoots" diff --git a/jps/src/org/jetbrains/jps/ProjectBuilder.groovy b/jps/src/org/jetbrains/jps/ProjectBuilder.groovy index 68fa8e955186..2b21b6d019ac 100644 --- a/jps/src/org/jetbrains/jps/ProjectBuilder.groovy +++ b/jps/src/org/jetbrains/jps/ProjectBuilder.groovy @@ -2,12 +2,8 @@ package org.jetbrains.jps import org.apache.tools.ant.BuildException import org.codehaus.gant.GantBinding -import org.jetbrains.ether.ProjectWrapper -import org.jetbrains.ether.Reporter -import org.jetbrains.ether.dependencyView.Callbacks.Backend import org.jetbrains.jps.artifacts.ArtifactBuilder import org.jetbrains.jps.idea.OwnServiceLoader - import org.jetbrains.jps.listeners.BuildInfoPrinter import org.jetbrains.jps.listeners.BuildStatisticsListener import org.jetbrains.jps.listeners.DefaultBuildInfoPrinter @@ -224,7 +220,7 @@ class ProjectBuilder { private def buildChunks(Collection modules, boolean tests) { getChunks(tests).getChunkList().each { if (!modules.intersect(it.modules).isEmpty()) { - buildChunk(it, tests, null, null, null) + buildChunk(it, tests) } } } @@ -270,32 +266,16 @@ class ProjectBuilder { buildModules(dependencies, includeTests) } - def clearChunk(ModuleChunk chunk, Collection files, ProjectWrapper pw) { + def clearChunk(ModuleChunk chunk) { if (!dryRun) { - if (files == null) { - stage("Cleaning module ${chunk.name}") - chunk.modules.each {cleanModule it} - } - else { - stage("Cleaning output files for module ${chunk.name}") - - files.each { - binding.ant.delete(file: pw.getAbsolutePath(it)) - } - - chunk.modules.each { - binding.ant.delete(file: it.outputPath + File.separator + Reporter.myOkFlag) - binding.ant.delete(file: it.outputPath + File.separator + Reporter.myFailFlag) - } - } + stage("Cleaning module ${chunk.name}") + chunk.modules.each {cleanModule it} } } - - - def buildChunk(ModuleChunk chunk, boolean tests, Collection files, Backend callback, ProjectWrapper pw) { + def buildChunk(ModuleChunk chunk, boolean tests) { Set compiledSet = tests ? compiledTestChunks : compiledChunks - if (compiledSet.contains(chunk) && files == null) return + if (compiledSet.contains(chunk)) return compiledSet.add(chunk) stage("Making${tests ? ' tests for' : ''} module ${chunk.name}") @@ -303,39 +283,26 @@ class ProjectBuilder { warning("Modules $chunk.modules with cyclic dependencies will be compiled to output of ${chunk.modules.toList().first()} module") } - compile(chunk, tests, files, callback, pw) + compile(chunk, tests) } private String getModuleOutputFolder(Module module, boolean tests) { return getProjectPaths().getModuleOutputDir(module, tests)?.absolutePath } - private def compile(ModuleChunk chunk, boolean tests, Collection files, Backend callback, ProjectWrapper pw) { + private def compile(ModuleChunk chunk, boolean tests) { List chunkSources = filterNonExistingFiles(tests ? chunk.testRoots : chunk.sourceRoots, true) if (chunkSources.isEmpty()) return - List sourceFiles = [] - - if (files != null) { - files.each { - sourceFiles << pw.getAbsolutePath(it) - } - } - if (!dryRun) { - List chunkClasspath = ProjectPaths.getPathsList(getProjectPaths().getClasspathFiles(chunk, ClasspathKind.compile(tests), files == null)) + List chunkClasspath = ProjectPaths.getPathsList(getProjectPaths().getClasspathFiles(chunk, ClasspathKind.compile(tests), true)) List sourceRootsWithDependencies = ProjectPaths.getPathsList(getProjectPaths().getSourcePathsWithDependents(chunk, tests)) Map states = new HashMap() def chunkState = new ModuleBuildState( - iterated: false, loader: null, formInstrumenter: null, tests: tests, - projectWrapper: pw, - incremental: files != null, - callback: callback, - sourceFiles: sourceFiles, sourceRoots: chunkSources, excludes: computeExcludes(chunk.elements, chunkSources), classpath: chunkClasspath, @@ -346,14 +313,9 @@ class ProjectBuilder { List sourceRoots = filterNonExistingFiles(tests ? it.testRoots : it.sourceRoots, false) if (!sourceRoots.isEmpty()) { def state = new ModuleBuildState( - iterated: false, loader: null, formInstrumenter: null, tests: tests, - projectWrapper: pw, - incremental: chunkState.incremental, - callback: callback, - sourceFiles: sourceFiles, sourceRoots: sourceRoots, excludes: computeExcludes([it], sourceRoots), classpath: chunkClasspath, @@ -377,28 +339,15 @@ class ProjectBuilder { listeners*.onCompilationStarted(chunk) - try { - builders().each {ModuleBuilder builder -> - listeners*.onModuleBuilderStarted(builder, chunk) - if (arrangeModuleCyclesOutputs && chunk.modules.size() > 1 && builder instanceof ModuleCycleBuilder) { - ((ModuleCycleBuilder) builder).preprocessModuleCycle(chunkState, chunk, this) - } - states.keySet().each { - builder.processModule(it, states[it], this) - } - listeners*.onModuleBuilderFinished(builder, chunk) + builders().each {ModuleBuilder builder -> + listeners*.onModuleBuilderStarted(builder, chunk) + if (arrangeModuleCyclesOutputs && chunk.modules.size() > 1 && builder instanceof ModuleCycleBuilder) { + ((ModuleCycleBuilder) builder).preprocessModuleCycle(chunkState, chunk, this) } - } - catch (Exception e) { - final String reason = e.toString(); - - if (pw != null) { - chunk.modules.each { - Reporter.reportBuildFailure(it, tests, reason) - } + states.keySet().each { + builder.processModule(it, states[it], this) } - - throw e; + listeners*.onModuleBuilderFinished(builder, chunk) } states.keySet().each { @@ -413,9 +362,6 @@ class ProjectBuilder { } chunk.modules.each { - if (pw != null) { - Reporter.reportBuildSuccess(it, tests) - } exportProperty("module.${it.name}.output.${tests ? "test" : "main"}", getModuleOutputFolder(it, tests)) } } diff --git a/jps/src/org/jetbrains/jps/builders/StandardBuilders.groovy b/jps/src/org/jetbrains/jps/builders/StandardBuilders.groovy index 1c7537687a48..07f6afb6d8f5 100644 --- a/jps/src/org/jetbrains/jps/builders/StandardBuilders.groovy +++ b/jps/src/org/jetbrains/jps/builders/StandardBuilders.groovy @@ -4,9 +4,6 @@ import com.intellij.ant.InstrumentationUtil import com.intellij.ant.InstrumentationUtil.FormInstrumenter import com.intellij.ant.PrefixedPath import com.intellij.compiler.instrumentation.InstrumentationClassFinder -import org.apache.tools.ant.BuildListener -import org.jetbrains.ether.ProjectWrapper -import org.jetbrains.ether.dependencyView.AntListener import org.jetbrains.jps.builders.javacApi.Java16ApiCompilerRunner import org.jetbrains.jps.* @@ -61,9 +58,6 @@ class JavacBuilder implements ModuleBuilder, ModuleCycleBuilder { params.debug = String.valueOf(debugInfo); params.nowarn = String.valueOf(nowarn); params.deprecation = String.valueOf(deprecation); - if (state.projectWrapper != null) { - params.verbose = "true" - } def javacExecutable = getJavacExecutable(module) if (javacExecutable != null) { @@ -72,33 +66,11 @@ class JavacBuilder implements ModuleBuilder, ModuleCycleBuilder { def ant = projectBuilder.binding.ant - if (state.projectWrapper != null) { - 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.projectWrapper != null && 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) } @@ -117,14 +89,6 @@ class JavacBuilder implements ModuleBuilder, ModuleCycleBuilder { } } } - - if (state.projectWrapper != null) { - ant.project.removeBuildListener(listener) - }; - - if (state.sourceFiles != null) { - projectBuilder.listeners*.onJavaFilesCompiled(module, state.sourceFiles.size()) - } } private String getJavacExecutable(ModuleChunk module) { @@ -153,10 +117,6 @@ class ResourceCopier implements ModuleBuilder { resourcePatternInitialized = true } - if (state.iterated) return; - - state.iterated = true - if (state.sourceRoots.isEmpty()) return; def ant = projectBuilder.binding.ant @@ -266,15 +226,6 @@ class GroovyStubGenerator implements ModuleBuilder { } } - if (state.incremental) { - Set excluded = state.excludes.collect { new File(it.toString()) } - List filesToCompile = new LinkedList() - - JavaFileCollector.collectRecursively(new File(stubsRoot), filesToCompile, excluded) - - filesToCompile.each {state.sourceFiles << it.getAbsolutePath()} - } - state.sourceRoots << stubsRoot state.tempRootsToDelete << stubsRoot } @@ -289,12 +240,6 @@ class JetBrainsInstrumentations implements ModuleBuilder { @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(formRelPath, classRelPath); - } } @Override @@ -342,19 +287,6 @@ class JetBrainsInstrumentations implements ModuleBuilder { state.loader = new InstrumentationClassFinder((URL[])urls.toArray(new URL[urls.size()])) 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 (String name: names) { - if (name.endsWith(".form")) { - formFiles.add(new File(pw.getAbsolutePath(name))) - } - } - } - } - final List nestedFormDirs = new ArrayList(); state.sourceRootsFromModuleWithDependencies.each { @@ -363,49 +295,30 @@ class JetBrainsInstrumentations implements ModuleBuilder { 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); - } + for (File formFile: formFiles) { + state.formInstrumenter.instrumentForm(formFile, state.loader); } } if (projectBuilder.useInProcessJavac) return; - if (!state.incremental) { - new Object() { - public void traverse(final File root) { - final File[] files = root.listFiles(); + new Object() { + public void traverse(final File root) { + final File[] files = root.listFiles(); - for (File f: files) { - final String name = f.getName(); + for (File f: files) { + final String name = f.getName(); - if (name.endsWith(".class")) { - InstrumentationUtil.instrumentNotNull(f, state.loader) - } - else if (f.isDirectory()) { - traverse(f) - } + 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 + ".class"), state.loader) } - } + }.traverse(new File(state.targetFolder)) if (state.loader != null) { state.loader.releaseResources(); } diff --git a/jps/src/org/jetbrains/jps/builders/javacApi/Java16ApiCompiler.groovy b/jps/src/org/jetbrains/jps/builders/javacApi/Java16ApiCompiler.groovy index a235e2fd9c97..b8775dc5320b 100644 --- a/jps/src/org/jetbrains/jps/builders/javacApi/Java16ApiCompiler.groovy +++ b/jps/src/org/jetbrains/jps/builders/javacApi/Java16ApiCompiler.groovy @@ -52,18 +52,9 @@ class Java16ApiCompiler { List filesToCompile = [] - if (state.incremental) { - 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) - } + Set excluded = state.excludes.collect { new File(it.toString()) } + state.sourceRoots.each { + JavaFileCollector.collectRecursively(new File(it.toString()), filesToCompile, excluded) } if (filesToCompile.size() > 0) {