Skip to Content.
Sympa Menu

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

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: r1873 - in development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin: magic util
  • Date: Tue, 22 Feb 2005 14:50:45 +0100

Author: herzog AT raffael.ch
Date: Tue Feb 22 14:50:44 2005
New Revision: 1873

Added:

development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/util/

development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/util/ExceptionPropagatingRunnable.java

development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/util/UnexpectedException.java
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/SettingsForm.java
Log:
Some restructuring, more fine-grained switching to the AWT event queue to
keep the progress bar a bit more responsive and informative, fixed JUnit
library drop-down.

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 Feb 22 14:50:44 2005
@@ -35,6 +35,7 @@

import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.ModifiableModuleModel;
import com.intellij.openapi.module.Module;
@@ -43,15 +44,15 @@
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ContentEntry;
+import com.intellij.openapi.roots.LibraryOrderEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ModuleCircularDependencyException;
+import com.intellij.openapi.roots.ModuleOrderEntry;
import com.intellij.openapi.roots.ModuleRootManager;
+import com.intellij.openapi.roots.OrderEntry;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.roots.SourceFolder;
-import com.intellij.openapi.roots.OrderEntry;
-import com.intellij.openapi.roots.ModuleOrderEntry;
-import com.intellij.openapi.roots.LibraryOrderEntry;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.roots.libraries.LibraryTableUtil;
@@ -65,6 +66,7 @@
import org.apache.commons.digester.SetNestedPropertiesRule;
import org.apache.commons.lang.ObjectUtils;

+import net.dpml.ide.idea.plugin.util.ExceptionPropagatingRunnable;
import net.dpml.transit.artifact.Artifact;

/**
@@ -120,11 +122,6 @@
private final Map resolvedObjects = new HashMap();

/**
- * If some exception occurred outside the working thread, it will be
stored here for later retrieval.
- */
- private Throwable exception;
-
- /**
* The path of the index file currently being processed. Used by the
object factory in #{link collectDependencies(ProgressIndicator, File)}.
*/
private String currentIndexPath;
@@ -158,56 +155,49 @@
Throwable exception = null;
final Application app = ApplicationManager.getApplication();
final ProjectBuilder builder = new ProjectBuilder(project, log,
config);
- try {
- app.runProcessWithProgressSynchronously(new Runnable() {
- public void run() {
- ProgressManager progressManager =
ProgressManager.getInstance();
- ProgressIndicator progress =
progressManager.getProgressIndicator();
- progress.start();
- try {
- builder.scanFiles(progress);
- builder.collectDependencies(progress);
- builder.applyDependencies(progress);
- }
- catch ( IOException exc ) {
- // will be handled below
- }
- catch ( SAXException exc ) {
- // will be handled below
- }
- catch ( UnresolvedDependencyException exc ) {
- // will be handled below
- }
- catch ( ModuleCircularDependencyException exc ) {
- // will be handled below
- }
- finally {
- progress.stop();
+ final ExceptionPropagatingRunnable rebuildRunnable =
+ new ExceptionPropagatingRunnable() {
+ public void invokeImpl() {
+ Application app =
ApplicationManager.getApplication();
+ app.runProcessWithProgressSynchronously(this,
"Rebuilding project", true, project);
+ }
+ protected void runImpl() {
+ ProgressManager progressManager =
ProgressManager.getInstance();
+ ProgressIndicator progress =
progressManager.getProgressIndicator();
+ progress.start();
+ try {
+ builder.scanFiles(progress);
+ builder.collectDependencies(progress);
+ builder.applyDependencies(progress);
+ }
+ catch ( IOException exc ) {
+ // will be handled below
+ }
+ catch ( SAXException exc ) {
+ // will be handled below
+ }
+ catch ( UnresolvedDependencyException exc ) {
+ // will be handled below
+ }
+ catch ( ModuleCircularDependencyException exc ) {
+ // will be handled below
+ }
+ finally {
+ progress.stop();
+ }
}
- }
- }, "Rebuilding Project Dependencies", true, project);
- }
- catch ( RuntimeException exc ) {
- exception = exc;
- throw exc;
- }
- catch ( Error exc ) {
- exception = exc;
- throw exc;
- }
- finally {
- if ( exception == null ) {
- exception = builder.exception;
- }
- if ( exception != null ) {
- Messages.showErrorDialog(project, exception.toString(),
"Error");
- log.info("Rebuilding project finished with error.");
- }
- else {
- log.info("Rebuilding project finished successfully.");
- }
+ };
+ try {
+ rebuildRunnable.invoke();
+ //app.runProcessWithProgressSynchronously(rebuildRunnable,
"Rebuilding Project Dependencies", true, project);
+ log.info("Rebuilding project finished successfully.");
+ return true;
+ }
+ catch ( Exception exc ) {
+ Messages.showErrorDialog(project, exception.toString(), "Error");
+ log.info("Rebuilding project finished with error.");
+ return false;
}
- return builder.exception == null;
}

/**
@@ -216,68 +206,56 @@
* @param progress A progress indicator.
*/
public void scanFiles(final ProgressIndicator progress) throws
IOException {
- try {
- 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 ) {
- exception = exc;
- return FileUtil.FileVisitor.STOP;
+ 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);
}
- 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 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 {
+ moduleFiles.put(dir, file);
}
}
- else if (file.isDirectory()) {
- progress.setText2("Scanning directory "
+ file);
- }
- return FileUtil.FileVisitor.PROCEED;
}
- });
- if ( exception != null ) {
- throw (IOException)exception;
+ else if (file.isDirectory()) {
+ progress.setText2("Scanning directory " +
file);
+ }
+ return FileUtil.FileVisitor.PROCEED;
}
- }
- else {
- log.info("Skipping " + files[j].toString());
- }
+ });
+ }
+ else {
+ log.info("Skipping " + files[j].toString());
}
}
}
- catch ( RuntimeException exc ) {
- exception = exc;
- throw exc;
- }
- catch ( Error exc ) {
- exception = exc;
- throw exc;
- }
}

/**
@@ -290,73 +268,51 @@
* @throws UnresolvedDependencyException
*/
public void collectDependencies(ProgressIndicator progress) throws
SAXException, IOException, UnresolvedDependencyException {
- try {
- Iterator iter = indexFiles.iterator();
- double currentProgress = 0;
- double progressStep = 1.0/indexFiles.size();
- progress.setIndeterminate(false);
- progress.setText("Parsing index files...");
- progress.setFraction(0);
- while (iter.hasNext()) {
- File f = (File) iter.next();
- progress.setText2("Parsing file " + f + "...");
- currentIndexPath = f.getParent().toString();
- collectDependencies(progress, f);
- currentProgress += progressStep;
- progress.setFraction(currentProgress);
+ Iterator iter = indexFiles.iterator();
+ double currentProgress = 0;
+ double progressStep = 1.0/indexFiles.size();
+ progress.setIndeterminate(false);
+ progress.setText("Parsing index files...");
+ progress.setFraction(0);
+ while (iter.hasNext()) {
+ File f = (File) iter.next();
+ progress.setText2("Parsing file " + f + "...");
+ currentIndexPath = f.getParent().toString();
+ collectDependencies(progress, f);
+ currentProgress += progressStep;
+ progress.setFraction(currentProgress);
+ }
+
+ if ( config.getRecursiveDependencies() ) {
+ Iterator depIter = magicProjects.values().iterator();
+ while ( depIter.hasNext() ) {
+ MagicProject mp = (MagicProject)depIter.next();
+ flattenDependencies(mp);
}
+ }

- if ( config.getRecursiveDependencies() ) {
- Iterator depIter = magicProjects.values().iterator();
- while ( depIter.hasNext() ) {
- MagicProject mp = (MagicProject)depIter.next();
- flattenDependencies(mp);
+ if ( DUMP ) {
+ iter = magicProjects.values().iterator();
+ while (iter.hasNext()) {
+ MagicProject m = (MagicProject)iter.next();
+ log.info("Project: " + m.getGroup() + ":" + m.getName() + "
(" + m.getBasedir() + ")");
+ Iterator iter2 = m.getDependencies().iterator();
+ while (iter2.hasNext()) {
+ Dependency d = (Dependency)iter2.next();
+ log.info(" Dependency: "+d.getKey()+"; build:
"+d.isBuild()+"; test: "+d.isTest()+"; runtime: "+d.isRuntime());
}
}
-
- if ( DUMP ) {
- iter = magicProjects.values().iterator();
- while (iter.hasNext()) {
- MagicProject m = (MagicProject)iter.next();
- log.info("Project: " + m.getGroup() + ":" + m.getName()
+ " (" + m.getBasedir() + ")");
- Iterator iter2 = m.getDependencies().iterator();
- while (iter2.hasNext()) {
- Dependency d = (Dependency)iter2.next();
- log.info(" Dependency: "+d.getKey()+"; build:
"+d.isBuild()+"; test: "+d.isTest()+"; runtime: "+d.isRuntime());
- }
- }
- iter = magicResources.values().iterator();
- while (iter.hasNext()) {
- MagicResource r = (MagicResource)iter.next();
- log.info("Resource: " + r.getGroup() + ":" + r.getName()
+ "#" + r.getVersion());
- Iterator iter2 = r.getDependencies().iterator();
- while (iter2.hasNext()) {
- Dependency d = (Dependency)iter2.next();
- log.info(" Dependency: "+d.getKey()+"; build:
"+d.isBuild()+"; test: "+d.isTest()+"; runtime: "+d.isRuntime());
- }
+ iter = magicResources.values().iterator();
+ while (iter.hasNext()) {
+ MagicResource r = (MagicResource)iter.next();
+ log.info("Resource: " + r.getGroup() + ":" + r.getName() +
"#" + r.getVersion());
+ Iterator iter2 = r.getDependencies().iterator();
+ while (iter2.hasNext()) {
+ Dependency d = (Dependency)iter2.next();
+ log.info(" Dependency: "+d.getKey()+"; build:
"+d.isBuild()+"; test: "+d.isTest()+"; runtime: "+d.isRuntime());
}
}
}
- catch ( UnresolvedDependencyException exc ) {
- exception = exc;
- throw exc;
- }
- catch ( SAXException exc ) {
- exception = exc;
- throw exc;
- }
- catch ( IOException exc ) {
- exception = exc;
- throw exc;
- }
- catch ( RuntimeException exc ) {
- exception = exc;
- throw exc;
- }
- catch ( Error exc ) {
- exception = exc;
- throw exc;
- }
}

/**
@@ -434,26 +390,10 @@
digester.addCallMethod("*/import", "doImport", 2);
digester.addCallParam("*/import", 0, "index");
digester.addCallParam("*/import", 1, "uri");
-// digester.addObjectCreate("index/resource", MagicResource.class);
-// snp = new SetNestedPropertiesRule();
-// snp.setAllowUnknownChildElements(true);
-// digester.addRule("index/resource/info", snp);
-// digester.addObjectCreate("index/resource/dependencies/include",
Dependency.class);
-// digester.addSetProperties("index/resource/dependencies/include");
-// digester.addSetNext("index/resource/dependencies/include",
"addDependency");
-// digester.addSetNext("index/resource", "addMagicResource");
-// digester.addObjectCreate("module/resources/resource",
MagicResource.class);
-// snp = new SetNestedPropertiesRule();
-// snp.setAllowUnknownChildElements(true);
-// digester.addRule("module/resources/resource/info", snp);
-//
digester.addObjectCreate("module/resources/resource/dependencies/include",
Dependency.class);
-//
digester.addSetProperties("module/resources/resource/dependencies/include");
-//
digester.addSetNext("module/resources/resource/dependencies/include",
"addDependency");
-// digester.addSetNext("module/resources/resource",
"addMagicResource");
addMessage(Message.MSG_INFO, "Parsing file " + file);
progress.setText2("Parsing file "+file);
digester.clear();
- digester.push(this);
+ digester.push(new DigesterRootHooks());
digester.parse(file);
}

@@ -508,120 +448,62 @@
* @throws ModuleCircularDependencyException
*/
public void applyDependencies(final ProgressIndicator progress) throws
UnresolvedDependencyException, ModuleCircularDependencyException, IOException
{
- try {
- boolean success = false;
+ boolean success = false;

- // IDEA module cache. Maps Magic projects to IDEA modules.
- final Map modules = collectModules();
+ // IDEA module cache. Maps Magic projects to IDEA modules.
+ final Map modules = collectModules();

- final Application app = ApplicationManager.getApplication();
- // a cache of root models; also used to commit/dispose the
changes
- final Set rootModels = new LinkedHashSet();
- // a cache of libraries (names mapped to IDEA Library objects);
also used to commit/dispose the changes
- final Map libs = new LinkedHashMap();
- model = moduleManager.getModifiableModel();
- libraryModel =
LibraryTableUtil.getLibraryTable(project).getModifiableModel();
-
- double currentProgress = 0;
- double progressStep = 1.0/modules.size();
- progress.setFraction(0);
- progress.setText("Setting up modules...");
- try {
- Iterator iter = modules.entrySet().iterator();
- while ( iter.hasNext() ) {
- Map.Entry entry = (Map.Entry)iter.next();
- final MagicProject magicProject =
(MagicProject)entry.getKey();
- final Module module = (Module)entry.getValue();
- progress.setText2("Setting up module " +
module.getName());
- updateProgress();
- app.invokeAndWait(new Runnable() {
- public void run() {
- app.runWriteAction(new Runnable() {
- public void run() {
- try {
- setupModule(modules, rootModels,
libs, magicProject, module);
- }
- catch ( Throwable exc ) {
- exception = exc;
- }
+ final Application app = ApplicationManager.getApplication();
+ // a cache of root models; also used to commit/dispose the changes
+ final Set rootModels = new LinkedHashSet();
+ // a cache of libraries (names mapped to IDEA Library objects); also
used to commit/dispose the changes
+ final Map libs = new LinkedHashMap();
+ model = moduleManager.getModifiableModel();
+ libraryModel =
LibraryTableUtil.getLibraryTable(project).getModifiableModel();
+
+ double currentProgress = 0;
+ double progressStep = 1.0/modules.size();
+ progress.setFraction(0);
+ progress.setText("Setting up modules...");
+ try {
+ Iterator iter = modules.entrySet().iterator();
+ while ( iter.hasNext() ) {
+ Map.Entry entry = (Map.Entry)iter.next();
+ final MagicProject magicProject =
(MagicProject)entry.getKey();
+ final Module module = (Module)entry.getValue();
+ progress.setText2("Setting up module " + module.getName());
+
+ try {
+ new InvokeAndWaitRunnable() {
+ protected void runImpl() throws Exception {
+ new WriteActionRunnable() {
+ protected void runImpl() throws Exception {
+ setupModule(modules, rootModels, libs,
magicProject, module);
}
- });
- }
- }, app.getDefaultModalityState());
- if ( exception != null ) {
- if ( exception instanceof
UnresolvedDependencyException ) {
- throw (UnresolvedDependencyException)exception;
- }
- if ( exception instanceof IOException ) {
- throw (IOException)exception;
+ }.invoke();
}
- else if ( exception instanceof RuntimeException ) {
- throw (RuntimeException)exception;
- }
- else if ( exception instanceof Error ) {
- throw (Error)exception;
- }
- else {
- throw new RuntimeException("Unknown exception
caught", exception);
- }
- }
- currentProgress += progressStep;
- final double finalProgress = currentProgress;
- progress.setFraction(finalProgress);
- Thread.yield();
- }
- success = true;
- }
- finally {
- progress.setText2("Committing changes...");
- progress.startNonCancelableSection();
- updateProgress();
- final boolean finalSuccess = success;
- app.invokeAndWait(new Runnable() {
- public void run() {
- app.runWriteAction(new Runnable() {
- public void run() {
- try {
- cleanupBuild(finalSuccess, rootModels,
libs.values());
- }
- catch ( Throwable exc ) {
- exception = exc;
- }
- }
- });
- }
- }, app.getDefaultModalityState());
- if ( exception != null ) {
- if ( exception instanceof
ModuleCircularDependencyException ) {
- throw (ModuleCircularDependencyException)exception;
- }
- else if ( exception instanceof RuntimeException ) {
- throw (RuntimeException)exception;
- }
- else if ( exception instanceof Error ) {
- throw (Error)exception;
- }
- else {
- throw new RuntimeException("Unknown exception
caught", exception);
- }
+ }.invoke();
+ }
+ catch ( UnresolvedDependencyException exc ) {
+ throw exc;
+ }
+ catch ( IOException exc ) {
+ throw exc;
}
+ catch ( Exception exc ) {
+ throw
ExceptionPropagatingRunnable.getRuntimeException(exc);
+ }
+ currentProgress += progressStep;
+ final double finalProgress = currentProgress;
+ progress.setFraction(finalProgress);
+ Thread.yield();
}
+ success = true;
}
- catch ( UnresolvedDependencyException exc ) {
- exception = exc;
- throw exc;
- }
- catch ( IOException exc ) {
- exception = exc;
- throw exc;
- }
- catch ( RuntimeException exc ) {
- exception = exc;
- throw exc;
- }
- catch ( Error exc ) {
- exception = exc;
- throw exc;
+ finally {
+ progress.setText2("Committing changes...");
+ progress.startNonCancelableSection();
+ cleanupBuild(success, rootModels, libs.values());
}
}

@@ -912,40 +794,95 @@
* @throws ModuleCircularDependencyException If a circular module
dependency has been detected.
*/
private void cleanupBuild(boolean success, Collection rootModels,
Collection libs) throws ModuleCircularDependencyException {
+
try {
Iterator iter = rootModels.iterator();
while ( iter.hasNext() ) {
- ModifiableRootModel m = (ModifiableRootModel)iter.next();
+ final ModifiableRootModel m =
(ModifiableRootModel)iter.next();
if ( success ) {
- addMessage(Message.MSG_INFO, "Committing root model " +
m);
- m.commit();
+ new InvokeAndWaitRunnable() {
+ protected void runImpl() throws Exception {
+ new WriteActionRunnable() {
+ protected void runImpl() throws Exception {
+ addMessage(Message.MSG_INFO, "Committing
root model " + m);
+ m.commit();
+ }
+ }.invoke();
+ }
+ }.invoke();
}
else {
- addMessage(Message.MSG_INFO, "Disposing root model " +
m);
- m.dispose();
+ new InvokeAndWaitRunnable() {
+ protected void runImpl() throws Exception {
+ new WriteActionRunnable() {
+ protected void runImpl() throws Exception {
+ addMessage(Message.MSG_INFO, "Disposing
root model " + m);
+ m.dispose();
+ }
+ }.invoke();
+ }
+ }.invoke();
}
}
if ( model != null ) {
if ( success ) {
- addMessage(Message.MSG_INFO, "Committing module model");
- model.commit();
+ new InvokeAndWaitRunnable() {
+ protected void runImpl() throws Exception {
+ new WriteActionRunnable() {
+ protected void runImpl() throws Exception {
+ addMessage(Message.MSG_INFO, "Committing
module model");
+ model.commit();
+ }
+ }.invoke();
+ }
+ }.invoke();
}
else {
- addMessage(Message.MSG_INFO, "Disposing module model");
- model.dispose();
+ new InvokeAndWaitRunnable() {
+ protected void runImpl() throws Exception {
+ new WriteActionRunnable() {
+ protected void runImpl() throws Exception {
+ addMessage(Message.MSG_INFO, "Disposing
module model");
+ model.dispose();
+ }
+ }.invoke();
+ }
+ }.invoke();
}
}
if ( success && libraryModel != null ) {
- addMessage(Message.MSG_INFO, "Committing library table
model");
- libraryModel.commit();
+ new InvokeAndWaitRunnable() {
+ protected void runImpl() throws Exception {
+ new WriteActionRunnable() {
+ protected void runImpl() throws Exception {
+ addMessage(Message.MSG_INFO, "Committing
library table model");
+ libraryModel.commit();
+ }
+ }.invoke();
+ }
+ }.invoke();
iter = libs.iterator();
while ( iter.hasNext() ) {
- LibraryEntry e = (LibraryEntry)iter.next();
- addMessage(Message.MSG_INFO, "Committing library model
for " + e.lib.getName());
- e.model.commit();
+ final LibraryEntry e = (LibraryEntry)iter.next();
+ new InvokeAndWaitRunnable() {
+ protected void runImpl() throws Exception {
+ new WriteActionRunnable() {
+ protected void runImpl() throws Exception {
+ addMessage(Message.MSG_INFO, "Committing
library model for " + e.lib.getName());
+ e.model.commit();
+ }
+ }.invoke();
+ }
+ }.invoke();
}
}
}
+ catch ( ModuleCircularDependencyException exc ) {
+ throw exc;
+ }
+ catch ( Exception exc ) {
+ throw ExceptionPropagatingRunnable.getRuntimeException(exc);
+ }
finally {
model = null;
libraryModel = null;
@@ -953,24 +890,6 @@
}

/**
- * Workaround; finde something nicer here; wait a bit hoping the AWT
event queue find some time to update the
- * progress indicator.
- */
- private void updateProgress() {
- try {
- Thread.sleep(100);
- }
- catch ( InterruptedException e ) {
- // ignore
- }
-
- }
-
-// private void addMessage(String msg) {
-// addMessage(Message.MSG_INFO, msg);
-// }
-
- /**
* Add a message to the list of messages. Also logs the messages.
*
* @param type The message type ({@link Message#MSG_INFO}, {@link
Message#MSG_WARNING} or {@link Message#MSG_ERROR}).
@@ -993,50 +912,6 @@



-
- /*
- * hooks for digester
- */
-
- /**
- * Called by the digester to add a new Magic project.
- * <p>
- * <strong>FIXME: put this into an inner class</strong>
- *
- * @param project The new Magic project.
- */
- public void addMagicProject(MagicProject project) {
- magicProjects.put(project.getName(), project);
- }
-
- /**
- * Called by the digester to add a new Magic resource.
- * <p>
- * <strong>FIXME: put this into an inner class</strong>
- *
- * @param resource The new Magic resource.
- */
- public void addMagicResource(MagicResource resource) {
- magicResources.put(resource.getName(), resource);
- }
-
-
-
- /*
- * getters and setters
- */
-
- /**
- * Get the exception that has occurred, if any.
- *
- * @return The exception or <code>null</code>, if none occurred.
- */
- public Throwable getException() {
- return exception;
- }
-
-
-
/*
* inner classes
*/
@@ -1050,7 +925,7 @@
}
}

- final static class UnresolvedDependencyException extends Exception {
+ public final static class UnresolvedDependencyException extends
Exception {
public UnresolvedDependencyException() {
super();
}
@@ -1065,241 +940,35 @@
}
}

+ private static abstract class InvokeAndWaitRunnable extends
ExceptionPropagatingRunnable {
+ public void invokeImpl() {
+ ApplicationManager.getApplication().invokeAndWait(this,
ModalityState.defaultModalityState());
+ }
+ }

+ private static abstract class WriteActionRunnable extends
ExceptionPropagatingRunnable {
+ public void invokeImpl() {
+ ApplicationManager.getApplication().runWriteAction(this);
+ }
+ }

- /*
- * obsolete stuff
- */
-
-// void old_collect() throws SAXException, IOException {
-// SetNestedPropertiesRule snp;
-// Digester digester = new Digester();
-// digester.addFactoryCreate("index/project", new
AbstractObjectCreationFactory() {
-// public Object createObject(Attributes attributes) throws
Exception {
-// MagicProject prj = new MagicProject();
-// prj.setIndexPath(currentIndexPath);
-// return prj;
-// }
-// });
-// digester.addSetProperties("index/project");
-// snp = new SetNestedPropertiesRule();
-// snp.setAllowUnknownChildElements(true);
-// digester.addRule("index/project/info", snp);
-// digester.addSetNext("index/project", "addMagicProject");
-// digester.addObjectCreate("index/project/dependencies/include",
Dependency.class);
-// digester.addSetProperties("index/project/dependencies/include");
-// digester.addSetNext("index/project/dependencies/include",
"addDependency");
-// digester.addObjectCreate("index/resource", MagicResource.class);
-// snp = new SetNestedPropertiesRule();
-// snp.setAllowUnknownChildElements(true);
-// digester.addRule("index/resource/info", snp);
-// digester.addObjectCreate("index/resource/dependencies/include",
Dependency.class);
-// digester.addSetProperties("index/resource/dependencies/include");
-// digester.addSetNext("index/resource/dependencies/include",
"addDependency");
-// digester.addSetNext("index/resource", "addMagicResource");
-//
-// Iterator iter = indexFiles.iterator();
-// while (iter.hasNext()) {
-// progress.checkCanceled();
-// File f = (File) iter.next();
-// currentIndexPath = f.getParent().toString();
-// log.info("Parsing file " + f);
-// progress.setText2("Parsing file "+f);
-// digester.clear();
-// digester.push(this);
-// digester.parse(f);
-// }
-//
-// if ( DUMP ) {
-// iter = magicProjects.values().iterator();
-// while (iter.hasNext()) {
-// MagicProject m = (MagicProject)iter.next();
-// log.info("Project: " + m.getGroup() + ":" + m.getName() +
" (" + m.getBasedir() + ")");
-// Iterator iter2 = m.getDependencies().iterator();
-// while (iter2.hasNext()) {
-// Dependency d = (Dependency)iter2.next();
-// log.info(" Dependency: "+d.getKey()+"; build:
"+d.isBuild()+"; test: "+d.isTest()+"; runtime: "+d.isRuntime());
-// }
-// }
-// iter = magicResources.values().iterator();
-// while (iter.hasNext()) {
-// MagicResource r = (MagicResource)iter.next();
-// log.info("Resource: " + r.getGroup() + ":" + r.getName() +
"#" + r.getVersion());
-// Iterator iter2 = r.getDependencies().iterator();
-// while (iter2.hasNext()) {
-// Dependency d = (Dependency)iter2.next();
-// log.info(" Dependency: "+d.getKey()+"; build:
"+d.isBuild()+"; test: "+d.isTest()+"; runtime: "+d.isRuntime());
-// }
-// }
-// }
-// }
-//
-// public void old_build() {
-// progress.setText("Checking dependencies...");
-// Comparator topSortComparator;
-// try {
-// topSortComparator = circularDependencyCheck();
-// }
-// catch ( UnresolvedDependencyException exc ) {
-// log.error(exc);
-// return;
-// }
-// catch ( TopSort.CyclicGraphException exc ) {
-// log.error(exc);
-// return;
-// }
-// List sortedProjects = new ArrayList(magicProjects.values());
-// Collections.sort(sortedProjects, topSortComparator);
-//
-// boolean success = false;
-// List rootModels = new LinkedList();
-// List libModels = new LinkedList();
-// model = moduleManager.getModifiableModel();
-// libraryModel =
LibraryTableUtil.getLibraryTable(project).getModifiableModel();
-// try {
-// double progressValue = 0.0;
-//
-// progress.setText("Building modules...");
-// Iterator iter = sortedProjects.iterator();
-// final double step = 1.0 / magicProjects.size();
-// progress.setIndeterminate(false);
-// while ( iter.hasNext() ) {
-// progress.checkCanceled();
-// MagicProject magicProject = (MagicProject)iter.next();
-// String moduleName = magicProject.getModuleName();
-// log.info("Setting up module " + moduleName);
-// progress.setText2("Setting up module " + moduleName);
-// progressValue += step;
-// progress.setFraction(progressValue);
-// Module module = moduleManager.findModuleByName(moduleName);
-// if ( module == null ) {
-// String path = new File(magicProject.getIndexPath(),
magicProject.getBasedir()).toString();
-// log.info("Creating module at " + path);
-// module = moduleManager.newModule(path,
ModuleType.JAVA);
-// }
-// ModuleRootManager rootManager =
ModuleRootManager.getInstance(module);
-// ModifiableRootModel rootModel =
rootManager.getModifiableModel();
-// rootModels.add(rootModel);
-//
rootModel.addContentEntry(LocalFileSystem.getInstance().findFileByIoFile(
-// new File(magicProject.getIndexPath(),
magicProject.getBasedir())
-// ));
-//
-// if ( false && !ObjectUtils.equals(module.getName(),
moduleName) ) {
-// log.info("Renaming module named " + module.getName() +
" to " + moduleName);
-// model.renameModule(module, moduleName);
-// }
-//
-// Iterator deps = magicProject.getDependencies().iterator();
-// while ( deps.hasNext() ) {
-// progress.checkCanceled();
-// Dependency d = (Dependency)deps.next();
-// DependentObject resolved =
(DependentObject)resolvedObjects.get(d.getKey());
-// if ( resolved instanceof MagicProject ) {
-// MagicProject projectDependency =
(MagicProject)resolved;
-// log.info("Adding module " +
projectDependency.getModuleName());
-// Module other =
moduleManager.findModuleByName(projectDependency.getModuleName());
-// if ( other == null ) {
-// other =
model.getModuleToBeRenamed(projectDependency.getModuleName());
-// }
-// if ( other == null ) {
-// throw new IllegalStateException("Module " +
projectDependency.getModuleName() + " not found");
-// }
-// rootModel.addModuleOrderEntry(other);
-// }
-// else if ( resolved instanceof MagicResource ) {
-// MagicResource resource = (MagicResource)resolved;
-// log.info("Adding resource " + resource);
-// String groupPath =
resource.getGroup().replace('/', File.separatorChar);
-// File path = new File(config.getCacheDir(),
groupPath);
-// path = new File(path, resource.getType() + "s");
-// path = new File(path, resource.getName() + "-" +
resource.getVersion() + "." + resource.getType());
-// String libName = resource.getLibraryName();
-// Library lib =
libraryModel.getLibraryByName(libName);
-// if ( lib == null ) {
-// log.info("Creating library " + libName);
-// lib = libraryModel.createLibrary(libName);
-// }
-// Library.ModifiableModel libModel =
lib.getModifiableModel();
-// libModels.add(libModel);
-// String url = "jar://" + path + "!/";
-// String[] libRoots =
libModel.getUrls(OrderRootType.CLASSES);
-// boolean foundRoot = false;
-// for ( int i = 0; i < libRoots.length; i++ ) {
-// if ( libRoots[i].equals(url) ) {
-// foundRoot = true;
-// break;
-// }
-// }
-// if ( !foundRoot ) {
-// log.info("Adding root " + url + " to library "
+ libName);
-// libModel.addRoot(url, OrderRootType.CLASSES);
-// }
-// rootModel.addLibraryEntry(lib);
-// }
-// else {
-// log.error("Invalid DependentObject instance: " +
resolved);
-// throw new IllegalStateException("Invalid
DependentObject instance: " + resolved);
-// }
-// }
-// }
-// success = true;
-// }
-// catch ( ModuleWithNameAlreadyExists exc ) {
-// log.error(exc);
-// }
-// finally {
-// cleanupBuild(success, rootModels, libModels);
-// }
-// }
-//
-//
-// private Comparator circularDependencyCheck() throws
UnresolvedDependencyException, TopSort.CyclicGraphException {
-// TopSort ts = new TopSort();
-// Set seen = new HashSet(magicProjects.size()+magicResources.size());
-// circularDependencyCheck(ts, seen, magicProjects.values());
-// circularDependencyCheck(ts, seen, magicResources.values());
-// ts.topSort();
-// return ts.getComparator();
-// }
-//
-// private void circularDependencyCheck(TopSort ts, Set seen, Collection
check) throws UnresolvedDependencyException {
-// Iterator iter = check.iterator();
-// while ( iter.hasNext() ) {
-// DependentObject o = (DependentObject)iter.next();
-// seen.add(o);
-// circularDependencyCheck(ts, seen, o);
-// }
-// }
-//
-// private void circularDependencyCheck(TopSort ts, Set seen,
DependentObject o) throws UnresolvedDependencyException {
-// progress.checkCanceled();
-// Iterator iter = o.getDependencies().iterator();
-// while ( iter.hasNext() ) {
-// Dependency d = (Dependency)iter.next();
-// DependentObject resolved =
(DependentObject)resolvedObjects.get(d.getKey());
-// boolean updateResolved = false;
-// if ( resolved == null ) {
-// resolved = (DependentObject)magicProjects.get(d.getKey());
-// updateResolved = true;
-// }
-// if ( resolved == null ) {
-// resolved = (DependentObject)magicResources.get(d.getKey());
-// }
-// if ( resolved == null ) {
-// throw new UnresolvedDependencyException("Could not resolve
dependency with key " + d.getKey());
-// }
-// if ( updateResolved ) {
-// resolvedObjects.put(d.getKey(), resolved);
-// }
-// boolean descend = !seen.contains(d);
-// if ( !descend ) {
-// seen.add(resolved);
-// }
-// ts.addArc(o, resolved);
-// if ( descend ) {
-// circularDependencyCheck(ts, seen, resolved);
-// }
-// }
-// }
+ private final class DigesterRootHooks {
+ /**
+ * Called by the digester to add a new Magic project.
+ *
+ * @param project The new Magic project.
+ */
+ public void addMagicProject(MagicProject project) {
+ magicProjects.put(project.getName(), project);
+ }
+ /**
+ * Called by the digester to add a new Magic resource.
+ *
+ * @param resource The new Magic resource.
+ */
+ public void addMagicResource(MagicResource resource) {
+ magicResources.put(resource.getName(), resource);
+ }
+ }

}

Modified:
development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic/SettingsForm.java
==============================================================================
---
development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic/SettingsForm.java
(original)
+++
development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/magic/SettingsForm.java
Tue Feb 22 14:50:44 2005
@@ -129,7 +129,7 @@
includeRuntime.setSelected(config.getIncludeRuntimeDependencies());
cache.setText(config.getCacheDir());
if ( config.getJUnitLibrary() != null ) {
- junit.setSelectedItem(libraries.get(config.getJUnitLibrary()));
+ junit.setSelectedItem(config.getJUnitLibrary());
}
else {
junit.setSelectedItem(null);

Added:
development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/util/ExceptionPropagatingRunnable.java
==============================================================================
--- (empty file)
+++
development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/util/ExceptionPropagatingRunnable.java
Tue Feb 22 14:50:44 2005
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2005 Raffael Herzog
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.ide.idea.plugin.util;
+
+
+
+/**
+ * Created by IntelliJ IDEA. User: rherzog Date: 20.02.2005 Time: 17:20:04
To change this template use File | Settings |
+ * File Templates.
+ */
+abstract public class ExceptionPropagatingRunnable implements Runnable {
+
+ /*
+ * fields
+ */
+
+ private Throwable exception = null;
+
+
+
+ /*
+ * constructors
+ */
+
+ protected ExceptionPropagatingRunnable() {
+ }
+
+
+
+ /*
+ * implementation
+ */
+
+ public final void invoke() throws Exception {
+ invokeImpl();
+ if ( exception != null ) {
+ if ( exception instanceof Error ) {
+ throw (Error)exception;
+ }
+ else if ( exception instanceof Exception ) {
+ throw (Exception)exception;
+ }
+ else {
+ throw new RuntimeException("Illegal exception: " +
exception, exception);
+ }
+ }
+ }
+
+ public final void run() {
+ try {
+ runImpl();
+ }
+ catch ( Throwable e ) {
+ exception = e;
+ }
+ }
+
+
+
+ /*
+ * utilities
+ */
+
+ public static RuntimeException getRuntimeException(Exception exc) {
+ if ( exc instanceof RuntimeException ) {
+ return (RuntimeException)exc;
+ }
+ else {
+ return new UnexpectedException("Unexpected exception caught",
exc);
+ }
+ }
+
+
+
+ /*
+ * abstract method declarations
+ */
+
+ protected abstract void invokeImpl();
+ protected abstract void runImpl() throws Exception;
+
+}

Added:
development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/util/UnexpectedException.java
==============================================================================
--- (empty file)
+++
development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin/util/UnexpectedException.java
Tue Feb 22 14:50:44 2005
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2005 Raffael Herzog
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.dpml.ide.idea.plugin.util;
+
+/**
+ * Created by IntelliJ IDEA. User: rherzog Date: 20.02.2005 Time: 18:00:47
To change this template use File | Settings |
+ * File Templates.
+ */
+public class UnexpectedException extends RuntimeException {
+
+ public UnexpectedException() {
+ super();
+ }
+
+ public UnexpectedException(String message) {
+ super(message);
+ }
+
+ public UnexpectedException(Throwable cause) {
+ super(cause);
+ }
+
+ public UnexpectedException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}



  • svn commit: r1873 - in development/laboratory/ide/idea-plugin/magic/src/main/net/dpml/ide/idea/plugin: magic util, herzog, 02/22/2005

Archive powered by MHonArc 2.6.24.

Top of Page