diff --git a/jps/src/org/jetbrains/ether/DirectoryScanner.java b/jps/src/org/jetbrains/ether/DirectoryScanner.java index 17a8c1a611a9..1e53416f293a 100644 --- a/jps/src/org/jetbrains/ether/DirectoryScanner.java +++ b/jps/src/org/jetbrains/ether/DirectoryScanner.java @@ -5,6 +5,8 @@ import java.io.File; import java.io.FileFilter; import java.util.ArrayList; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Created by IntelliJ IDEA. @@ -43,13 +45,81 @@ public class DirectoryScanner { public long myLatest = 0; } - public static Result getFiles (final String root) { + private static FileFilter myTrueFilter = new FileFilter() { + public boolean accept (File s) { + return true; + } + }; + + private static FileFilter createFilter (final List excludes) { + if (excludes == null) { + return myTrueFilter; + } + + StringBuffer buf = new StringBuffer(); + + for (String exclude : excludes) { + StringBuffer alternative = new StringBuffer(); + + if (exclude != null) { + for (int i = 0; i 0) { + if (buf.length() > 0) { + 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.getName()); + + return !m.matches(); + } + }; + } + + return myTrueFilter; + } + + public static Result getFiles (final String root, final List excludes) { final Result result = new Result (); + final FileFilter ff = createFilter(excludes); new Object(){ public void run (File root) { if (root.exists()) { - final File[] files = root.listFiles(); + final File[] files = root.listFiles(ff); for (int i = 0; i notes = myOptions.parse(args); for (String note : notes) { System.err.println("Warning: " + note); } + 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) { final ProjectWrapper project = new ProjectWrapper(prj); + boolean saved = false; if (doClean()) { System.out.println("Cleaning project \"" + prj + "\""); project.load(); project.clean(); project.save(); + saved = true; } if (doRebuild()) { @@ -82,6 +102,7 @@ public class Main { project.load(); project.rebuild(); project.save(); + saved = true; } final Options.Argument make = doMake(); @@ -93,12 +114,14 @@ public class Main { project.load(); project.makeModule(module, doForce(), doTests()); project.save(); + saved = true; } else if (make instanceof Options.Switch) { System.out.println("Making project \"" + prj + "\""); project.load(); project.make(doForce (), doTests()); project.save(); + saved = true; } final Options.Argument inspect = doInspect(); @@ -106,9 +129,22 @@ public class Main { if (inspect instanceof Options.Switch) { project.load(); project.report(); + if (doSave()) { + project.save(); + saved = true; + } } else if (inspect instanceof Options.Value) { project.load(); project.report(((Options.Value) inspect).get()); + if (doSave()) { + project.save(); + saved = true; + } + } + + if (doSave() && !saved) { + project.load(); + project.save(); } } } diff --git a/jps/src/org/jetbrains/ether/ModuleHistory.java b/jps/src/org/jetbrains/ether/ModuleHistory.java deleted file mode 100644 index a3c7024aa064..000000000000 --- a/jps/src/org/jetbrains/ether/ModuleHistory.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.jetbrains.ether; - -import java.io.Serializable; - -/** - * Created by IntelliJ IDEA. - * User: db - * Date: 19.11.10 - * Time: 3:40 - * To change this template use File | Settings | File Templates. - */ -public class ModuleHistory implements Serializable { - String myName; - long mySourceStamp; - long myOutputStamp; - long myTestSourceStamp; - long myTestOutputStamp; - - public ModuleHistory (String name, long ss, long os, long tss, long tos) { - myName = name; - mySourceStamp = ss; - myOutputStamp = os; - myTestSourceStamp = tss; - myTestOutputStamp = tos; - } - - public boolean isDirty (){ - return (myOutputStamp <= mySourceStamp) || (myTestOutputStamp <= myTestSourceStamp); - } -} diff --git a/jps/src/org/jetbrains/ether/ModuleStatus.java b/jps/src/org/jetbrains/ether/ModuleStatus.java new file mode 100644 index 000000000000..46b072e4cd25 --- /dev/null +++ b/jps/src/org/jetbrains/ether/ModuleStatus.java @@ -0,0 +1,56 @@ +package org.jetbrains.ether; + +import java.io.Serializable; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Created by IntelliJ IDEA. + * User: db + * Date: 19.11.10 + * Time: 3:40 + * To change this template use File | Settings | File Templates. + */ +public class ModuleStatus { + private static Pattern myPattern = Pattern.compile("([^ ]+) ([0-9]+) ([0-9]+) ([0-9]+) ([0-9]+)"); + + String myName; + long mySourceStamp; + long myOutputStamp; + long myTestSourceStamp; + long myTestOutputStamp; + + public ModuleStatus(String name, long ss, long os, long tss, long tos) { + myName = name; + mySourceStamp = ss; + myOutputStamp = os; + myTestSourceStamp = tss; + myTestOutputStamp = tos; + } + + public String getName () { + return myName; + } + + public String toString () { + return myName + " " + mySourceStamp + " " + myOutputStamp + " " + myTestSourceStamp + " " + myTestOutputStamp; + } + + public ModuleStatus(final String s) { + final Matcher m = myPattern.matcher(s); + + if (m.matches()) { + myName = m.group(1); + mySourceStamp = Long.parseLong(m.group(2)); + myOutputStamp = Long.parseLong(m.group(3)); + myTestSourceStamp = Long.parseLong(m.group(4)); + myTestOutputStamp = Long.parseLong(m.group(5)); + } + else + System.err.println("Error converting string \"" + s + "\" to ModuleStatus"); + } + + public boolean isOutdated(){ + return (myOutputStamp <= mySourceStamp) || (myTestOutputStamp <= myTestSourceStamp); + } +} diff --git a/jps/src/org/jetbrains/ether/Options.java b/jps/src/org/jetbrains/ether/Options.java index 48e8c88e6e75..08430c9de529 100644 --- a/jps/src/org/jetbrains/ether/Options.java +++ b/jps/src/org/jetbrains/ether/Options.java @@ -78,7 +78,7 @@ public class Options { } public boolean nextIsArg () { - return (! endOf()) && ! myArgs[myPos+1].startsWith("-"); + return (myPos < myLength - 1 && ! myArgs[myPos+1].startsWith("-")); } public boolean endOf () { @@ -97,18 +97,47 @@ public class Options { 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) { + 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 StringBuffer buf = new StringBuffer(); + 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; @@ -133,6 +162,7 @@ public class Options { else switch (myArgumentSpecifier) { case OPTIONAL: + callback.update(myKey, SWITCH); break; case MANDATORY: callback.report("option \"" + arg + "\" requires an argument, discarding"); @@ -224,4 +254,14 @@ public class Options { public List getFree () { return myFree; } + + public String memo () { + StringBuffer buf = new StringBuffer (); + + for (int i = 0; i myModuleHistories; - - public ProjectHistory (final String prjStruct, final Map moduleHistories) { - myProjectStructure = prjStruct; - myModuleHistories = moduleHistories; - } - - public boolean structureChanged (final ProjectHistory p) { - /* - try { - Writer fo1 = new BufferedWriter(new FileWriter("/home/db/tmp/1.history")); - Writer fo2 = new BufferedWriter(new FileWriter("/home/db/tmp/2.history")); - - fo1.write(p.myProjectStructure); - fo2.write(myProjectStructure); - - fo1.close(); - fo2.close(); - } - catch (IOException e) { - - } - */ - - return ! p.myProjectStructure.equals(myProjectStructure); - } -} diff --git a/jps/src/org/jetbrains/ether/ProjectSnapshot.java b/jps/src/org/jetbrains/ether/ProjectSnapshot.java new file mode 100644 index 000000000000..4f37a4c1de8c --- /dev/null +++ b/jps/src/org/jetbrains/ether/ProjectSnapshot.java @@ -0,0 +1,89 @@ +package org.jetbrains.ether; + +import java.io.*; +import java.util.HashMap; +import java.util.Map; + +/** + * Created by IntelliJ IDEA. + * User: db + * Date: 19.11.10 + * Time: 3:05 + * To change this template use File | Settings | File Templates. + */ +public class ProjectSnapshot { + String myProjectStructure; + Map myModuleHistories; + + public ProjectSnapshot(final String prjStruct, final Map moduleHistories) { + myProjectStructure = prjStruct; + myModuleHistories = moduleHistories; + } + + public String toString () { + StringBuffer buf = new StringBuffer(); + + buf.append(myModuleHistories.size() + "\n"); + + for (ModuleStatus h : myModuleHistories.values()) { + buf.append(h.toString() + "\n"); + } + + buf.append(myProjectStructure); + + return buf.toString(); + } + + public ProjectSnapshot(final String s) { + BufferedReader rd = new BufferedReader(new StringReader(s)); + + try { + final int n = Integer.parseInt(rd.readLine()); + + myModuleHistories = new HashMap(); + + for (int i = 0; i modules = new ArrayList(); - for (Map.Entry entry : myPresent.myModuleHistories.entrySet()) { - if (entry.getValue().isDirty()) + for (Map.Entry entry : myPresent.myModuleHistories.entrySet()) { + if (entry.getValue().isOutdated()) modules.add(myProject.getModules().get(entry.getKey())); } if (modules.isEmpty() && !force) { - System.out.println("All module are up-to-date."); + System.out.println("All modules are up-to-date."); return; } @@ -200,8 +229,8 @@ public class ProjectWrapper { return; } - final ModuleHistory h = myPresent.myModuleHistories.get(modName); - if (h != null && !h.isDirty() && !force) { + final ModuleStatus h = myPresent.myModuleHistories.get(modName); + if (h != null && !h.isOutdated() && !force) { System.out.println("Module \"" + modName + "\" in project \"" + myRoot + "\" is up-to-date."); return; } diff --git a/jps/src/org/jetbrains/ether/HistoryCollector.java b/jps/src/org/jetbrains/ether/StatusCollector.java similarity index 87% rename from jps/src/org/jetbrains/ether/HistoryCollector.java rename to jps/src/org/jetbrains/ether/StatusCollector.java index 5fec00982b2f..9d231313ba53 100644 --- a/jps/src/org/jetbrains/ether/HistoryCollector.java +++ b/jps/src/org/jetbrains/ether/StatusCollector.java @@ -1,9 +1,6 @@ package org.jetbrains.ether; import com.sun.tools.javac.util.Pair; -import org.jetbrains.ether.DirectoryScanner; -import org.jetbrains.ether.ModuleHistory; -import org.jetbrains.ether.ProjectHistory; import org.jetbrains.jps.*; import org.jetbrains.jps.resolvers.PathEntry; @@ -16,7 +13,7 @@ import java.util.*; * Time: 19:57 * To change this template use File | Settings | File Templates. */ -public class HistoryCollector { +public class StatusCollector { private static Pair myDefaultPair = new Pair (Long.MAX_VALUE, 0l); private static Pair join (final Pair a, final Pair b) { @@ -79,9 +76,9 @@ public class HistoryCollector { listToBuffer(buf, list); } - private static Pair directoryToBuffer (StringBuffer buf, final String dir) { + private static Pair directoryToBuffer (StringBuffer buf, final String dir, final List excludes) { if (dir != null) { - final DirectoryScanner.Result result = DirectoryScanner.getFiles(dir); + final DirectoryScanner.Result result = DirectoryScanner.getFiles(dir, excludes); for (String name : prepare (result.myFiles)) { buf.append(name + "\n"); @@ -93,7 +90,7 @@ public class HistoryCollector { return myDefaultPair; } - private static Pair sourceRootToBuffer (StringBuffer buf, final String name, final List dir) { + private static Pair sourceRootToBuffer (StringBuffer buf, final String name, final List dir, final List excludes) { Pair result = myDefaultPair; buf.append(name + ":\n"); @@ -101,7 +98,7 @@ public class HistoryCollector { for (String d : prepare (dir)) { if (dir != null) { buf.append(d + ":\n"); - result = join (result, directoryToBuffer(buf, d)); + result = join (result, directoryToBuffer(buf, d, excludes)); } } @@ -127,7 +124,7 @@ public class HistoryCollector { classPathItemToBuffer(buf, library, false); } - public static ModuleHistory moduleToBuffer (StringBuffer buf, final Module module) { + public static ModuleStatus moduleToBuffer (StringBuffer buf, final Module module) { buf.append("Module: " + module.getName() + "\n"); classPathItemToBuffer(buf, module, true); @@ -138,13 +135,13 @@ public class HistoryCollector { libraryToBuffer(buf, lib); } - long ss = sourceRootToBuffer(buf, "SourceRoots", module.getSourceRoots()).snd; + long ss = sourceRootToBuffer(buf, "SourceRoots", module.getSourceRoots(), module.getExcludes()).snd; buf.append("OutputPath: " + module.getOutputPath() + "\n"); - long os = directoryToBuffer(buf, module.getOutputPath()).fst; + long os = directoryToBuffer(buf, module.getOutputPath(), null).fst; - long tss = sourceRootToBuffer(buf, "TestRoots", module.getTestRoots()).snd; + long tss = sourceRootToBuffer(buf, "TestRoots", module.getTestRoots(), module.getExcludes()).snd; buf.append("TestOutputPath: " + module.getTestOutputPath() + "\n"); - long tos = directoryToBuffer(buf, module.getTestOutputPath()).fst; + long tos = directoryToBuffer(buf, module.getTestOutputPath(), null).fst; buf.append("Dependencies:\n"); for (Module.ModuleDependency dep : module.getDependencies()){ @@ -169,12 +166,12 @@ public class HistoryCollector { } } - return new ModuleHistory(module.getName(), ss, os, tss, tos); + return new ModuleStatus(module.getName(), ss, os, tss, tos); } - public static ProjectHistory collectHistory (final Project prj) { + public static ProjectSnapshot collectHistory (final Project prj) { StringBuffer buf = new StringBuffer(); - Map moduleHistories = new HashMap (); + Map moduleHistories = new HashMap (); for (Library lib : prepare (prj.getLibraries().values(), myLibraryComparator)) { libraryToBuffer(buf, lib); @@ -184,6 +181,6 @@ public class HistoryCollector { moduleHistories.put(mod.getName(), moduleToBuffer(buf, mod)); } - return new ProjectHistory(buf.toString(), moduleHistories); + return new ProjectSnapshot(buf.toString(), moduleHistories); } }