Skip to Content.
Sympa Menu

notify-dpml - svn commit: r1993 - development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: herzog AT raffael.ch
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r1993 - development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic
  • Date: Tue, 08 Mar 2005 22:03:38 -0500

Author: herzog AT raffael.ch
Date: Tue Mar 8 22:03:35 2005
New Revision: 1993

Modified:

development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic/ProjectBuilder.java
Log:
Massive speed improvements by a) scanning files using cached project contents
instead of scanning the file system directly and b) only commiting changed
modules disposing the unchanged ones.

Modified:
development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic/ProjectBuilder.java
==============================================================================
---
development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic/ProjectBuilder.java
(original)
+++
development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic/ProjectBuilder.java
Tue Mar 8 22:03:35 2005
@@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.HashSet;

import org.xml.sax.SAXException;

@@ -50,6 +51,7 @@
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.roots.SourceFolder;
+import com.intellij.openapi.roots.ContentIterator;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.libraries.LibraryTableUtil;
@@ -57,6 +59,7 @@
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.openapi.vfs.VirtualFileSystem;

import org.apache.commons.lang.ObjectUtils;

@@ -105,6 +108,8 @@

private final IdeIndex index = new IdeIndex();

+ private final Set changedRootModels = new HashSet();
+
/**
* Create a new project builder. Each project builder can only be used
<em>once</em>!
*
@@ -169,54 +174,46 @@
public void scanFiles(final ProgressIndicator progress) throws
IOException {
progress.setIndeterminate(true);
progress.setText("Scanning Files...");
- Module[] modules = ModuleManager.getInstance(project).getModules();
- for (int i = 0; i < modules.length; i++) {
- ModuleRootManager mrm =
ModuleRootManager.getInstance(modules[i]);
- VirtualFile[] files = mrm.getContentRoots();
- for (int j = 0; j < files.length; j++) {
- if
(files[j].getFileSystem().getProtocol().equals(LocalFileSystem.PROTOCOL)) {
- log.info("Scanning " + files[j].toString());
- FileUtil.visitFilesRecursively(new
File(files[j].getPath()), new FileUtil.FileVisitor() {
- public int accept(File file) {
- try {
- file = file.getCanonicalFile();
- }
- catch ( IOException exc ) {
- // FIXME: handle this
- //exception = exc;
- return FileUtil.FileVisitor.STOP;
- }
- progress.checkCanceled();
- if (file.isFile()) {
- progress.setText2("Scanning directory " +
file.getParent());
- if (file.getName().equals("index.xml")) {
- addMessage(Message.MSG_INFO, "Found
index file: " + file);
- indexFiles.add(file);
- }
- else if ( file.getName().endsWith(".iml") ) {
- addMessage(Message.MSG_INFO, "Found IDEA
module file: " + file);
- String dir = file.getParent();
- File current =
(File)moduleFiles.get(dir);
- if ( current != null ) {
- addMessage(Message.MSG_WARNING, "Two
module files found in directory " + dir + "; using " + current);
- }
- else {
- moduleFiles.put(dir, file);
- }
- }
- }
- else if (file.isDirectory()) {
- progress.setText2("Scanning directory " +
file);
- }
- return FileUtil.FileVisitor.PROCEED;
+ ProjectRootManager projectRoot =
ProjectRootManager.getInstance(project);
+ projectRoot.getFileIndex().iterateContent(new ContentIterator() {
+ public boolean processFile(VirtualFile virtualFile) {
+ if (
!virtualFile.getFileSystem().getProtocol().equals(LocalFileSystem.PROTOCOL) )
{
+ return true;
+ }
+ File file = new File(virtualFile.getPath());
+ try {
+ file = file.getCanonicalFile();
+ }
+ catch ( IOException exc ) {
+ // FIXME: handle this
+ //exception = exc;
+ return false;
+ }
+ progress.checkCanceled();
+ if ( file.isFile() ) {
+ progress.setText2("Scanning directory " +
file.getParent());
+ if ( file.getName().equals("index.xml") ) {
+ addMessage(Message.MSG_INFO, "Found index file: " +
file);
+ indexFiles.add(file);
+ }
+ else if ( file.getName().endsWith(".iml") ) {
+ addMessage(Message.MSG_INFO, "Found IDEA module
file: " + file);
+ String dir = file.getParent();
+ File current = (File)moduleFiles.get(dir);
+ if ( current != null ) {
+ addMessage(Message.MSG_WARNING, "Two module
files found in directory " + dir + "; using " + current);
+ }
+ else {
+ moduleFiles.put(dir, file);
}
- });
+ }
}
- else {
- log.info("Skipping " + files[j].toString());
+ else if ( file.isDirectory() ) {
+ progress.setText2("Scanning directory " + file);
}
+ return true;
}
- }
+ });
}

/**
@@ -332,6 +329,8 @@
* @param module The IDEA module.
*/
private void setupModule(Map modules, Set rootModels, Map libs,
IdeProjectDefinition project, Module module) throws IOException {
+ boolean changed = false;
+
addMessage(Message.MSG_INFO, "Setting up module " +
module.getName());
ModuleRootManager rootManager =
ModuleRootManager.getInstance(module);
ModifiableRootModel rootModel = rootManager.getModifiableModel();
@@ -348,11 +347,13 @@
else if ( config.getStrictSyncing() ) {
addMessage(Message.MSG_INFO, "Removing content entry " +
contentEntries[i].getFile());
rootModel.removeContentEntry(contentEntries[i]);
+ changed = true;
}
}
if ( mainContent == null ) {
addMessage(Message.MSG_INFO, "Adding content entry " +
contentFile);
rootModel.addContentEntry(contentFile);
+ changed = true;
}
File sourcePath = new File(moduleRootFile, "src");
VirtualFile mainFile =
LocalFileSystem.getInstance().findFileByIoFile(new File(sourcePath, "main"));
@@ -389,18 +390,29 @@
addMessage(Message.MSG_INFO, "Removing source folder " +
sourceFolders[i].getFile());
}
mainContent.removeSourceFolder(sourceFolders[i]);
+ changed = true;
}
}
if ( !foundMain && mainFile != null ) {
addMessage(Message.MSG_INFO, "Adding source folder " + mainFile);
mainContent.addSourceFolder(mainFile, false);
+ changed = true;
}
if ( !foundTest && testFile != null ) {
mainContent.addSourceFolder(testFile, true);
+ changed = true;
}
String basedir =
project.getFullBaseDir().getCanonicalFile().toURI().toString();
- rootModel.setCompilerOutputPath(basedir+"/target/classes");
-
rootModel.setCompilerOutputPathForTests(basedir+"/target/test-classes");
+ String compilerOutput = basedir+"/target/classes";
+ String testOutput = basedir+"/target/test-classes";
+ if ( rootModel.getCompilerOutputPath() != null &&
!rootModel.getCompilerOutputPath().getPath().equals(compilerOutput) ) {
+ rootModel.setCompilerOutputPath(compilerOutput);
+ changed = true;
+ }
+ if ( rootModel.getCompilerOutputPathForTests() != null &&
!rootModel.getCompilerOutputPathForTests().getPath().equals(testOutput) ) {
+ rootModel.setCompilerOutputPathForTests(compilerOutput);
+ changed = true;
+ }

Map currentOrderEntries = new HashMap();
OrderEntry[] orderEntries = rootModel.getOrderEntries();
@@ -427,6 +439,7 @@
if ( !currentOrderEntries.containsKey(other) ) {
addMessage(Message.MSG_INFO, "Adding module " +
module.getName());
rootModel.addModuleOrderEntry(other);
+ changed = true;
}
else {
// remove from current order entries -- we'll
delete the remaining dependencies afterwards,
@@ -476,6 +489,7 @@
}
if ( !currentOrderEntries.containsKey(lib.lib) ) {
rootModel.addLibraryEntry(lib.lib);
+ changed = true;
}
else {
// remove from current order entries -- we'll delete
the remaining dependencies afterwards,
@@ -491,6 +505,7 @@
if ( junit != null ) {
if ( !currentOrderEntries.containsKey(junit) ) {
rootModel.addLibraryEntry(junit);
+ changed = true;
}
else {
currentOrderEntries.remove(junit);
@@ -515,8 +530,14 @@
addMessage(Message.MSG_INFO, "Removing order entry " +
entry);
}
rootModel.removeOrderEntry(entry);
+ changed = true;
}
}
+
+ if ( changed ) {
+ changedRootModels.add(rootModel);
+ }
+
}

/**
@@ -567,7 +588,7 @@
Iterator iter = rootModels.iterator();
while ( iter.hasNext() ) {
final ModifiableRootModel m =
(ModifiableRootModel)iter.next();
- if ( success ) {
+ if ( success && changedRootModels.contains(m) ) {
new InvokeAndWaitRunnable() {
protected void runImpl() throws Exception {
new WriteActionRunnable() {
@@ -593,7 +614,7 @@
}
}
if ( model != null ) {
- if ( success ) {
+ if ( success && !changedRootModels.isEmpty() ) {
new InvokeAndWaitRunnable() {
protected void runImpl() throws Exception {
new WriteActionRunnable() {



  • svn commit: r1993 - development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic, herzog, 03/08/2005

Archive powered by MHonArc 2.6.24.

Top of Page