diff --git a/jps/antLayout/antlayout.iml b/jps/antLayout/antlayout.iml index 1c77fe401738..63b6c029c41c 100644 --- a/jps/antLayout/antlayout.iml +++ b/jps/antLayout/antlayout.iml @@ -5,7 +5,7 @@ - + diff --git a/jps/jps.iml b/jps/jps.iml index 725fd836a13f..6bc3adbc818f 100644 --- a/jps/jps.iml +++ b/jps/jps.iml @@ -7,22 +7,15 @@ - + - - - - - - - - - + + diff --git a/jps/plugins/gwt/gwt.iml b/jps/plugins/gwt/gwt.iml index ced8806f42f0..8a514adfdbda 100644 --- a/jps/plugins/gwt/gwt.iml +++ b/jps/plugins/gwt/gwt.iml @@ -5,7 +5,7 @@ - + diff --git a/jps/plugins/javaee/javaee.iml b/jps/plugins/javaee/javaee.iml index f8fe61eb4d9e..b21e687f59bb 100644 --- a/jps/plugins/javaee/javaee.iml +++ b/jps/plugins/javaee/javaee.iml @@ -5,7 +5,7 @@ - + diff --git a/jps/plugins/jpa/jpa.iml b/jps/plugins/jpa/jpa.iml index f8fe61eb4d9e..b21e687f59bb 100644 --- a/jps/plugins/jpa/jpa.iml +++ b/jps/plugins/jpa/jpa.iml @@ -5,7 +5,7 @@ - + diff --git a/jps/src/org/jetbrains/ether/DirectoryScanner.java b/jps/src/org/jetbrains/ether/DirectoryScanner.java index bc318ae1a0c7..ca50b38b626a 100644 --- a/jps/src/org/jetbrains/ether/DirectoryScanner.java +++ b/jps/src/org/jetbrains/ether/DirectoryScanner.java @@ -3,8 +3,7 @@ package org.jetbrains.ether; import javax.xml.transform.Result; import java.io.File; import java.io.FileFilter; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -15,43 +14,92 @@ import java.util.regex.Pattern; * 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) { + public boolean accept(File f) { final String name = f.getName(); - return f.isDirectory() && !name.equals(".") && !name.equals("..") ; + return f.isDirectory() && !name.equals(".") && !name.equals(".."); } }; - private static FileFilter filterByExtensions (final String[] exts) { - return new FileFilter (){ - public boolean accept (File path) { - final String filename = path.getName(); - - for (int i = 0; i myFiles = new ArrayList (); - public long myEarliest = Long.MAX_VALUE; - public long myLatest = 0; - } - private static FileFilter myTrueFilter = new FileFilter() { - public boolean accept (File s) { - return true; - } - }; + public boolean accept(File s) { + return s.isFile(); + } + }; - private static FileFilter createFilter (final List excludes) { + private static FileFilter createFilter(final Collection excludes) { if (excludes == null) { return myTrueFilter; } @@ -62,7 +110,7 @@ public class DirectoryScanner { StringBuffer alternative = new StringBuffer(); if (exclude != null) { - for (int i = 0; i excludes) { - final Result result = new Result (); - final FileFilter ff = createFilter(excludes); + public static Result getFiles(final String root, final Set excludes, final ProjectWrapper pw) { + final Crawler cw = new Crawler(createFilter(excludes), pw); - new Object(){ - public void run (File root) { - if (root.exists()) { - final File[] files = root.listFiles(ff); + if (root != null) + cw.run(new File(pw.getAbsolutePath(root))); - for (int i = 0; i result.myLatest) - result.myLatest = t; + public static Result getFiles(final Set roots, final Set excludes, final ProjectWrapper pw) { + final Crawler cw = new Crawler(createFilter(excludes), pw); - if (t < result.myEarliest) - result.myEarliest = t; + for (String root : roots) + cw.run(new File(pw.getAbsolutePath(root))); - result.myFiles.add(files[i].getAbsolutePath()); - } - - final File[] subdirs = root.listFiles(myDirectoryFilter); - - for (int i=0; i 0 && output == Long.MAX_VALUE) || (output <= input); - return result; - } - - public boolean isOutdated(boolean tests) { - final boolean result = wiseCompare(mySourceStamp, myOutputStamp) || (tests && wiseCompare(myTestSourceStamp, myTestOutputStamp)); - return result; - } -} diff --git a/jps/src/org/jetbrains/ether/ProjectSnapshot.java b/jps/src/org/jetbrains/ether/ProjectSnapshot.java deleted file mode 100644 index 421f298272be..000000000000 --- a/jps/src/org/jetbrains/ether/ProjectSnapshot.java +++ /dev/null @@ -1,73 +0,0 @@ -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 List sort(final Collection coll, final Comparator comp) { + List list = new ArrayList(); + + for (T elem : coll) { + if (elem != null) { + list.add(elem); + } + } + + Collections.sort(list, comp); + + return list; + } + + private static > List sort(final Collection coll) { + return sort(coll, new Comparator() { + public int compare(T a, T b) { + return a.compareTo(b); + } + }); + } + + private interface Writable extends Comparable { + public void write(BufferedWriter w); + } + + private static void writeln(final BufferedWriter w, final Collection c, final String desc) { + writeln(w, Integer.toString(c.size())); + + if (c instanceof List) { + for (String e : c) { + writeln(w, e); + } + } else { + final List sorted = sort(c); + + for (String e : sorted) { + writeln(w, e); + } + } + } + + private static void writeln(final BufferedWriter w, final Collection c) { + writeln(w, Integer.toString(c.size())); + + if (c instanceof List) { + for (Writable e : c) { + e.write(w); + } + } else { + final List sorted = sort(c); + + for (Writable e : sorted) { + e.write(w); + } + } + } + + private static void writeln(final BufferedWriter w, final String s) { + try { + w.write(s); + w.newLine(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private interface Constructor { + public T read(BufferedReader r); + } + + private static Constructor myStringConstructor = new Constructor() { + public String read(final BufferedReader r) { + try { + return r.readLine(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + }; + + private static Collection readMany(final BufferedReader r, final Constructor c, final Collection acc) { + final int size = readInt(r); + + for (int i = 0; i < size; i++) { + acc.add(c.read(r)); + } + + return acc; + } + + private static String lookString(final BufferedReader r) { + try { + r.mark(256); + final String s = r.readLine(); + r.reset(); + + return s; + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + private static void readTag(final BufferedReader r, final String tag) { + try { + final String s = r.readLine(); + + if (!s.equals(tag)) + System.err.println("Parsing error: expected \"" + tag + "\", but found \"" + s + "\""); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private static String readString(final BufferedReader r) { + try { + return r.readLine(); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + + private static long readLong(final BufferedReader r) { + final String s = readString(r); + + try { + return Long.parseLong(s); + } catch (Exception n) { + System.err.println("Parsing error: expected long, but found \"" + s + "\""); + return 0; + } + } + + private static int readInt(final BufferedReader r) { + final String s = readString(r); + + try { + return Integer.parseInt(s); + } catch (Exception n) { + System.err.println("Parsing error: expected integer, but found \"" + s + "\""); + return 0; + } + } + + private static String readStringAttribute(final BufferedReader r, final String tag) { + try { + final String s = r.readLine(); + + if (s.startsWith(tag)) + return s.substring(tag.length()); + + System.err.println("Parsing error: expected \"" + tag + "\", but found \"" + s + "\""); + + return null; + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + // File separator replacement - private static final char myFileSeparatorReplacement = '-'; + private static final char myFileSeparatorReplacement = '.'; // Original JPS Project private final Project myProject; @@ -41,60 +206,596 @@ public class ProjectWrapper { // Project directory private final String myRoot; - // Project snapshot file + // Project snapshot file name private final String myProjectSnapshot; - // Project history - private ProjectSnapshot mySnapshot; - private ProjectSnapshot myPresent; + public interface ClasspathItemWrapper extends Writable { + public List getClassPath(ClasspathKind kind); + } - public ProjectWrapper(final String prjDir) { + public final Constructor myLibraryWrapperConstructor = + new Constructor() { + 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) { + writeln(w, "Library:" + myName); + writeln(w, "Classpath:"); + writeln(w, myClassPath, null); + } + + public LibraryWrapper(final BufferedReader r) { + myName = readStringAttribute(r, "Library:"); + + readTag(r, "Classpath:"); + myClassPath = (List) readMany(r, myStringConstructor, new ArrayList()); + } + + public LibraryWrapper(final Library lib) { + lib.forceInit(); + myName = lib.getName(); + myClassPath = (List) getRelativePaths(lib.getClasspath(), new ArrayList()); + } + + public String getName() { + return myName; + } + + public List getClassPath(final ClasspathKind kind) { + return myClassPath; + } + + public int compareTo(Object o) { + return getName().compareTo(((LibraryWrapper) o).getName()); + } + } + + public final Constructor myClasspathItemWrapperConstructor = + new Constructor() { + public ClasspathItemWrapper read(final BufferedReader r) { + final String s = lookString(r); + if (s.startsWith("Library:")) { + return new LibraryWrapper(r); + } + if (s.startsWith("Module:")) { + return new ModuleWrapper(r); + } else { + return new GenericClasspathItemWrapper(r); + } + } + }; + + 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 = (List) getRelativePaths(item.getClasspathRoots(null), new ArrayList()); + } + + public GenericClasspathItemWrapper(final BufferedReader r) { + myType = readString(r); + + readTag(r, "Classpath:"); + myClassPath = (List) readMany(r, myStringConstructor, new ArrayList()); + } + + public String getType() { + return myType; + } + + public List getClassPath(final ClasspathKind kind) { + return myClassPath; + } + + public void write(final BufferedWriter w) { + writeln(w, myType); + writeln(w, "Classpath:"); + writeln(w, myClassPath, ""); + } + + public int compareTo(Object o) { + final GenericClasspathItemWrapper w = (GenericClasspathItemWrapper) o; + final int c = getType().compareTo(w.getType()); + return + c == 0 ? + (new Object() { + public int compare(Iterator x, Iterator y) { + if (x.hasNext()) { + if (y.hasNext()) { + final int c = x.next().compareTo(y.next()); + + return c == 0 ? compare(x, y) : c; + } + + return 1; + } else if (y.hasNext()) { + return -1; + } + + return 0; + } + } + ).compare(getClassPath(null).iterator(), w.getClassPath(null).iterator()) + : c; + } + } + + public final Constructor myFileWrapperConstructor = + new Constructor() { + public FileWrapper read(final BufferedReader r) { + return new FileWrapper(r); + } + }; + + public class FileWrapper implements Writable { + final String myName; + final long myModificationTime; + + FileWrapper(final File f) { + myName = getRelativePath(f.getAbsolutePath()); + myModificationTime = f.lastModified(); + } + + FileWrapper(final BufferedReader r) { + myName = readString(r); + myModificationTime = 0; // readLong(r); + } + + public String getName() { + return myName; + } + + public long getStamp() { + return myModificationTime; + } + + public void write(final BufferedWriter w) { + writeln(w, getName()); + // writeln(w, Long.toString(getStamp())); + } + + public int compareTo(Object o) { + return getName().compareTo(((FileWrapper) o).getName()); + } + } + + public final Constructor myModuleWrapperConstructor = + new Constructor() { + public ModuleWrapper read(final BufferedReader r) { + return new ModuleWrapper(r); + } + }; + + public class ModuleWrapper implements ClasspathItemWrapper { + + private class Properties implements Writable { + + final Set myRoots; + final Set mySources; + + final String myOutput; + final Set myOutputs; + + final long myLatestSource; + final long myEarliestSource; + + final long myLatestOutput; + final long myEarliestOutput; + + public void write(final BufferedWriter w) { + writeln(w, "Roots:"); + writeln(w, myRoots, null); + + writeln(w, "Sources:"); + writeln(w, mySources); + + writeln(w, "Output:"); + writeln(w, myOutput == null ? "" : myOutput); + + writeln(w, "Outputs:"); + writeln(w, myOutputs); + + //writeln(w, "EarliestSource:"); + //writeln(w, Long.toString(myEarliestSource)); + + //writeln(w, "LatestSource:"); + //writeln(w, Long.toString(myLatestSource)); + + //writeln(w, "EarliestOutput:"); + //writeln(w, Long.toString(myEarliestOutput)); + + //writeln(w, "LatestOutput:"); + //writeln(w, Long.toString(myLatestOutput)); + } + + public Properties(final BufferedReader r) { + readTag(r, "Roots:"); + myRoots = (Set) readMany(r, myStringConstructor, new HashSet()); + + readTag(r, "Sources:"); + mySources = (Set) readMany(r, myFileWrapperConstructor, new HashSet()); + + readTag(r, "Output:"); + final String s = readString(r); + myOutput = s.equals("") ? null : s; + + readTag(r, "Outputs:"); + myOutputs = (Set) readMany(r, myFileWrapperConstructor, new HashSet()); + + //readTag(r, "EarliestSource:"); + myEarliestSource = 0;//readLong(r); + + //readTag(r, "LatestSource:"); + myLatestSource = 0;//readLong(r); + + //readTag(r, "EarliestOutput:"); + myEarliestOutput = 0;//readLong(r); + + //readTag(r, "LatestOutput:"); + myLatestOutput = 0;//readLong(r); + } + + public Properties(final List sources, final String output, final Set excludes) { + myRoots = (Set) getRelativePaths(sources, new HashSet()); + + { + final DirectoryScanner.Result result = DirectoryScanner.getFiles(myRoots, excludes, ProjectWrapper.this); + mySources = result.getFiles(); + myEarliestSource = result.getEarliest(); + myLatestSource = result.getLatest(); + } + + { + myOutput = getRelativePath(output); + final DirectoryScanner.Result result = DirectoryScanner.getFiles(myOutput, excludes, ProjectWrapper.this); + myOutputs = result.getFiles(); + myEarliestOutput = result.getEarliest(); + myLatestOutput = result.getLatest(); + } + } + + public Set getRoots() { + return myRoots; + } + + public Set getSources() { + return mySources; + } + + public String getOutputPath() { + return myOutput; + } + + public Set getOutputs() { + return myOutputs; + } + + public long getEarliestOutput() { + return myEarliestOutput; + } + + public long getLatestOutput() { + return myLatestOutput; + } + + public long getEarliestSource() { + return myEarliestSource; + } + + public long getLatestSource() { + return myLatestSource; + } + + public boolean emptySource() { + return mySources.isEmpty(); + } + + public boolean emptyOutput() { + return myOutputs.isEmpty(); + } + + public boolean isOutdated() { + return (!emptySource() && emptyOutput()) || (getLatestSource() > getEarliestOutput()); + } + + public int compareTo(Object o) { + return 0; + } + } + + final String myName; + final Properties mySource; + final Properties myTest; + + final Set myExcludes; + + final Module myModule; + List myDependsOn; + + final Set myLibraries; + + public void write(final BufferedWriter w) { + writeln(w, "Module:" + myName); + + writeln(w, "SourceProperties:"); + mySource.write(w); + + writeln(w, "TestProperties:"); + myTest.write(w); + + writeln(w, "Excludes:"); + writeln(w, myExcludes, null); + + writeln(w, "Libraries:"); + writeln(w, myLibraries); + + writeln(w, "Dependencies:"); + writeln(w, dependsOn()); + } + + public ModuleWrapper(final BufferedReader r) { + myModule = null; + myName = readStringAttribute(r, "Module:"); + + readTag(r, "SourceProperties:"); + mySource = new Properties(r); + + readTag(r, "TestProperties:"); + myTest = new Properties(r); + + readTag(r, "Excludes:"); + myExcludes = (Set) readMany(r, myStringConstructor, new HashSet()); + + readTag(r, "Libraries:"); + myLibraries = (Set) readMany(r, myLibraryWrapperConstructor, new HashSet()); + + readTag(r, "Dependencies:"); + myDependsOn = (List) readMany(r, myClasspathItemWrapperConstructor, new ArrayList()); + } + + public ModuleWrapper(final Module m) { + m.forceInit(); + myModule = m; + myDependsOn = null; + myName = m.getName(); + myExcludes = (Set) getRelativePaths(m.getExcludes(), new HashSet()); + 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 getSourceRoots() { + return mySource.getRoots(); + } + + public Set getSourceFiles() { + return mySource.getSources(); + } + + 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() { + if (myDependsOn != null) + return myDependsOn; + + myDependsOn = new ArrayList(); + + for (Module.ModuleDependency dep : myModule.getDependencies()) { + final ClasspathItem cpi = dep.getItem(); + + if (cpi instanceof Module) { + myDependsOn.add(getModule(((Module) cpi).getName())); + } else if (cpi instanceof Library) { + myDependsOn.add(new LibraryWrapper((Library) cpi)); + } else { + myDependsOn.add(new GenericClasspathItemWrapper(cpi)); + } + } + + return myDependsOn; + } + + public List getClassPath(final ClasspathKind kind) { + final List result = new ArrayList(); + + result.add(getOutputPath()); + + if (kind.isTestsIncluded()) { + result.add(getTestOutputPath()); + } + + return result; + } + + public boolean isOutdated(final boolean tests) { + return mySource.isOutdated() || (tests && myTest.isOutdated()); + } + + public int compareTo(Object o) { + return getName().compareTo(((ModuleWrapper) o).getName()); + } + } + + final Map myModules = new HashMap(); + final Map myLibraries = new HashMap(); + final ProjectWrapper myHistory; + + 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(); + } + + private ProjectWrapper(final String prjDir) { myProject = new Project(new GantBinding()); - myRoot = new File (prjDir).getAbsolutePath(); + myRoot = new File(prjDir).getAbsolutePath(); myProjectSnapshot = myHomeDir + File.separator + myJPSDir + File.separator + myRoot.replace(File.separatorChar, myFileSeparatorReplacement); + + IdeaProjectLoader.loadFromPath(myProject, getAbsolutePath(myIDEADir)); + + 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 = loadSnapshot(); + } + + public String getAbsolutePath(final String relative) { + if (relative == null) + return relative; + + if (new File(relative).isAbsolute()) + return relative; + + return myRoot + File.separator + relative; + } + + public String getRelativePath(final String absolute) { + if (absolute == null) + return absolute; + + if (absolute.startsWith(myRoot)) { + return absolute.substring(myRoot.length() + 1); + } + + return absolute; + } + + public Collection getAbsolutePaths(final Collection paths, final Collection result) { + for (String path : paths) { + if (path != null) + result.add(getAbsolutePath(path)); + } + + return result; + } + + public Collection getRelativePaths(final Collection paths, final Collection result) { + for (String path : paths) { + if (path != null) + result.add(getRelativePath(path)); + } + + return result; + } + + private boolean isHistory() { + return myProject == null; + } + + private ProjectWrapper(final BufferedReader r) { + myProject = null; + myHistory = null; + + myRoot = readStringAttribute(r, "Root:"); + myProjectSnapshot = myHomeDir + File.separator + myJPSDir + File.separator + myRoot.replace(File.separatorChar, myFileSeparatorReplacement); + + readTag(r, "Libraries:"); + final Set libs = (Set) readMany(r, myLibraryWrapperConstructor, new HashSet()); + + for (LibraryWrapper l : libs) { + myLibraries.put(l.getName(), l); + } + + readTag(r, "Modules:"); + final Set mods = (Set) readMany(r, myModuleWrapperConstructor, new HashSet()); + + for (ModuleWrapper m : mods) { + myModules.put(m.getName(), m); + } + } + + public void write(final BufferedWriter w) { + writeln(w, "Root:" + myRoot); + + writeln(w, "Libraries:"); + writeln(w, getLibraries()); + + writeln(w, "Modules:"); + writeln(w, getModules()); } private String getProjectSnapshotFileName() { return myProjectSnapshot; } - private ProjectSnapshot loadSnapshot() { + private ProjectWrapper loadSnapshot() { initJPSDirectory(); - ProjectSnapshot result = null; - try { - final String path = getProjectSnapshotFileName(); + final BufferedReader r = new BufferedReader(new FileReader(getProjectSnapshotFileName())); + final ProjectWrapper w = new ProjectWrapper(r); + r.close(); - byte[] buffer = new byte[(int) new File(path).length()]; - - BufferedInputStream f = new BufferedInputStream(new FileInputStream(path)); - - f.read(buffer); - - f.close(); - - result = new ProjectSnapshot(new String(buffer)); - } - catch (FileNotFoundException e) { - - } - catch (IOException e) { + return w; + } catch (FileNotFoundException e) { + } catch (IOException e) { e.printStackTrace(); } - return result; + return null; } private void saveSnapshot() { initJPSDirectory(); - final ProjectSnapshot snapshot = StatusCollector.collectHistory(myProject); - try { BufferedWriter bw = new BufferedWriter(new FileWriter(getProjectSnapshotFileName())); - bw.write(snapshot.toString()); + write(bw); bw.close(); } catch (IOException e) { @@ -102,14 +803,12 @@ public class ProjectWrapper { } } - public void load() { - IdeaProjectLoader.loadFromPath(myProject, myRoot); - mySnapshot = loadSnapshot(); - myPresent = StatusCollector.collectHistory(myProject); + public static ProjectWrapper load(final String path) { + return new ProjectWrapper(path); } public void report(final String module) { - final ModuleStatus m = myPresent.myModuleHistories.get(module); + final ModuleWrapper m = getModule(module); if (m == null) { System.out.println("No module \"" + module + "\" found in project \""); @@ -120,10 +819,36 @@ public class ProjectWrapper { } private boolean structureChanged() { - if (mySnapshot == null) + if (myHistory == null) return true; - return myPresent.structureChanged(mySnapshot); + try { + final StringWriter my = new StringWriter(); + final StringWriter history = new StringWriter(); + + myHistory.write(new BufferedWriter(my)); + write(new BufferedWriter(history)); + + my.close(); + history.close(); + + final String myString = my.getBuffer().toString(); + final String hisString = history.getBuffer().toString(); + + FileWriter f1 = new FileWriter("/home/db/tmp/1.jps"); + FileWriter f2 = new FileWriter("/home/db/tmp/2.jps"); + + f1.write(myString); + f2.write(hisString); + + f1.close(); + f2.close(); + + return !myString.equals(hisString); + } catch (IOException e) { + e.printStackTrace(); + return true; + } } public void report() { @@ -131,7 +856,7 @@ public class ProjectWrapper { System.out.println("Project \"" + myRoot + "\" report:"); - if (mySnapshot == null) { + if (myHistory == null) { System.out.println(" no project history found"); } else { if (structureChanged()) { @@ -141,9 +866,9 @@ public class ProjectWrapper { } if (moduleReport) { - for (ModuleStatus mh : myPresent.myModuleHistories.values()) { - System.out.println(" module " + mh.myName + " " + (mh.isOutdated(false) ? "is outdated" : "is up-to-date")); - System.out.println(" module " + mh.myName + " tests " + (mh.isOutdated(true) ? "are outdated" : "are up-to-date")); + for (ModuleWrapper m : myModules.values()) { + System.out.println(" module " + m.getName() + " " + (m.isOutdated(false) ? "is outdated" : "is up-to-date")); + System.out.println(" module " + m.getName() + " tests " + (m.isOutdated(true) ? "are outdated" : "are up-to-date")); } } } @@ -169,7 +894,7 @@ public class ProjectWrapper { final List modules = new ArrayList(); - for (Map.Entry entry : myPresent.myModuleHistories.entrySet()) { + for (Map.Entry entry : myModules.entrySet()) { if (entry.getValue().isOutdated(tests)) modules.add(myProject.getModules().get(entry.getKey())); } @@ -189,7 +914,7 @@ public class ProjectWrapper { private void makeModules(final List initial, final boolean tests) { final Set modules = new HashSet(); - final Map> reversedDependencies = new HashMap> (); + final Map> reversedDependencies = new HashMap>(); for (Module m : myProject.getModules().values()) { for (Module.ModuleDependency mdep : m.getDependencies()) { @@ -199,7 +924,7 @@ public class ProjectWrapper { Set sm = reversedDependencies.get(cpi); if (sm == null) { - sm = new HashSet (); + sm = new HashSet(); reversedDependencies.put((Module) cpi, sm); } @@ -244,7 +969,7 @@ public class ProjectWrapper { return; } - final ModuleStatus h = myPresent.myModuleHistories.get(modName); + final ModuleWrapper h = getModule(modName); if (h != null && !h.isOutdated(tests) && !force) { System.out.println("Module \"" + modName + "\" in project \"" + myRoot + "\" is up-to-date."); return; diff --git a/jps/src/org/jetbrains/ether/StatusCollector.java b/jps/src/org/jetbrains/ether/StatusCollector.java deleted file mode 100644 index 9d231313ba53..000000000000 --- a/jps/src/org/jetbrains/ether/StatusCollector.java +++ /dev/null @@ -1,186 +0,0 @@ -package org.jetbrains.ether; - -import com.sun.tools.javac.util.Pair; -import org.jetbrains.jps.*; -import org.jetbrains.jps.resolvers.PathEntry; - -import java.util.*; - -/** - * Created by IntelliJ IDEA. - * User: db - * Date: 18.11.10 - * Time: 19:57 - * To change this template use File | Settings | File Templates. - */ -public class StatusCollector { - private static Pair myDefaultPair = new Pair (Long.MAX_VALUE, 0l); - - private static Pair join (final Pair a, final Pair b) { - if (a == null) - return b; - - if (b == null) - return a; - - return new Pair (Math.min(a.fst, b.fst), Math.max(a.snd, b.snd)); - } - - private static Comparator myLibraryComparator = new Comparator() { - public int compare (Library a, Library b) { - return a.getName().compareTo(b.getName()); - } - }; - - private static Comparator myModuleComparator = new Comparator() { - public int compare (Module a, Module b) { - return a.getName().compareTo(b.getName()); - } - }; - - private static List prepare (final Collection coll, final Comparator comp) { - List list = new ArrayList (); - - for (T elem : coll) { - if (elem != null) { - list.add(elem); - } - } - - Collections.sort(list, comp); - - return list; - } - - private static > List prepare (final Collection coll) { - return prepare(coll, new Comparator () { - public int compare (T a, T b) { - return a.compareTo(b); - } - }); - } - - private static void listToBuffer (StringBuffer buf, final List list) { - for (Object o : prepare (list)) { - if (o instanceof String) { - buf.append(o + "\n"); - } - else { - buf.append("*** <" + o.getClass().getName() + "> is not String ***\n"); - } - } - } - - private static void namedListToBuffer (StringBuffer buf, final String name, final List list) { - buf.append(name + ":\n"); - listToBuffer(buf, list); - } - - private static Pair directoryToBuffer (StringBuffer buf, final String dir, final List excludes) { - if (dir != null) { - final DirectoryScanner.Result result = DirectoryScanner.getFiles(dir, excludes); - - for (String name : prepare (result.myFiles)) { - buf.append(name + "\n"); - } - - return new Pair (result.myEarliest, result.myLatest); - } - - return myDefaultPair; - } - - private static Pair sourceRootToBuffer (StringBuffer buf, final String name, final List dir, final List excludes) { - Pair result = myDefaultPair; - - buf.append(name + ":\n"); - - for (String d : prepare (dir)) { - if (dir != null) { - buf.append(d + ":\n"); - result = join (result, directoryToBuffer(buf, d, excludes)); - } - } - - return result; - } - - private static void classPathItemToBuffer (StringBuffer buf, final ClasspathItem cpi, boolean all) { - final ClasspathKind[] allKinds = {ClasspathKind.PRODUCTION_COMPILE, ClasspathKind.PRODUCTION_RUNTIME, ClasspathKind.TEST_COMPILE, ClasspathKind.TEST_RUNTIME}; - final ClasspathKind[] oneKind = {ClasspathKind.PRODUCTION_COMPILE}; - final ClasspathKind[] kinds = all ? allKinds : oneKind; - - for (int i=0; i\n"); - } - } - - return new ModuleStatus(module.getName(), ss, os, tss, tos); - } - - public static ProjectSnapshot collectHistory (final Project prj) { - StringBuffer buf = new StringBuffer(); - Map moduleHistories = new HashMap (); - - for (Library lib : prepare (prj.getLibraries().values(), myLibraryComparator)) { - libraryToBuffer(buf, lib); - } - - for (Module mod : prepare (prj.getModules().values(), myModuleComparator)) { - moduleHistories.put(mod.getName(), moduleToBuffer(buf, mod)); - } - - return new ProjectSnapshot(buf.toString(), moduleHistories); - } -}