Author: rob.stryker(a)jboss.com
Date: 2008-09-12 21:59:24 -0400 (Fri, 12 Sep 2008)
New Revision: 10236
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/model/other/internal/WorkspaceVFS.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ant/AntArchivesCore.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ant/AntVFS.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ant/GenerateArchivesTask.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ArchiveBuildDelegate.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/EventManager.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IVariableManager.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeImpl.java
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/util/ModelUtil.java
Log:
JBIDE-1426 - archives / ant archives error handling
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/model/other/internal/WorkspaceVFS.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/model/other/internal/WorkspaceVFS.java 2008-09-13
00:33:26 UTC (rev 10235)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/eclipse/org/jboss/ide/eclipse/archives/core/model/other/internal/WorkspaceVFS.java 2008-09-13
01:59:24 UTC (rev 10236)
@@ -12,6 +12,7 @@
import org.eclipse.core.variables.VariablesPlugin;
import org.jboss.ide.eclipse.archives.core.ArchivesCore;
import org.jboss.ide.eclipse.archives.core.model.IArchivesVFS;
+import org.jboss.ide.eclipse.archives.core.model.IVariableManager;
public class WorkspaceVFS implements IArchivesVFS, IDynamicVariableResolver {
public WorkspaceVFS() {
@@ -75,7 +76,7 @@
public String resolveValue(IDynamicVariable variable, String argument)
throws CoreException {
if( this == ArchivesCore.getInstance().getVFS()) {
- if( variable.getName().equals("archives_current_project"))
+ if( variable.getName().equals(IVariableManager.CURRENT_PROJECT))
return currentProject;
} else {
return ((WorkspaceVFS)ArchivesCore.getInstance().getVFS()).resolveValue(variable,
argument);
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ant/AntArchivesCore.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ant/AntArchivesCore.java 2008-09-13
00:33:26 UTC (rev 10235)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ant/AntArchivesCore.java 2008-09-13
01:59:24 UTC (rev 10236)
@@ -1,13 +1,19 @@
package org.jboss.ide.eclipse.archives.core.ant;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.jboss.ide.eclipse.archives.core.ArchivesCore;
import org.jboss.ide.eclipse.archives.core.build.ModelChangeListener;
import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
+import org.jboss.ide.eclipse.archives.core.model.IActionType;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveType;
import org.jboss.ide.eclipse.archives.core.model.IArchivesLogger;
+import org.jboss.ide.eclipse.archives.core.model.IArchivesVFS;
import org.jboss.ide.eclipse.archives.core.model.IExtensionManager;
import org.jboss.ide.eclipse.archives.core.model.IPreferenceManager;
-import org.jboss.ide.eclipse.archives.core.model.IArchivesVFS;
/**
* A core API entry point for ant.
@@ -15,18 +21,34 @@
*
*/
public class AntArchivesCore extends ArchivesCore {
-
+ private Project currentProject;
+ private Task currentTask;
public AntArchivesCore () {
super(STANDALONE);
ArchivesModel.instance().addModelListener(new ModelChangeListener());
}
+ public void setProject(Project p) {
+ currentProject = p;
+ }
+
+ public Project getProject() {
+ return currentProject;
+ }
+
+ public void setTask(Task t) {
+ currentTask= t;
+ }
+
+ public Task getTask() {
+ return currentTask;
+ }
protected IExtensionManager createExtensionManager() {
- return null; // not necessary right now
+ return new AntExtensionManager();
}
protected IPreferenceManager createPreferenceManager() {
- return null; // not necessary right now
+ return new AntPreferences();
}
protected IArchivesVFS createVFS() {
@@ -38,6 +60,66 @@
}
protected IArchivesLogger createLogger() {
- return null;
+ return new AntLogger();
}
+
+ protected class AntExtensionManager implements IExtensionManager {
+ public IActionType getActionType(String id) {
+ return null;
+ }
+
+ public IArchiveType getArchiveType(String id) {
+ final String id2 = id;
+ return new IArchiveType() {
+ public IArchive createDefaultConfiguration(String projectName,
+ IProgressMonitor monitor) {
+ return null;
+ }
+ public IArchive fillDefaultConfiguration(String projectName,
+ IArchive topLevel, IProgressMonitor monitor) {
+ return null;
+ }
+ public String getId() {
+ return id2;
+ }
+ public String getLabel() {
+ return id2;
+ }
+ };
+ }
+
+ public IActionType[] getActionTypes() {
+ return new IActionType[]{};
+ }
+
+ public IArchiveType[] getArchiveTypes() {
+ return new IArchiveType[]{};
+ }
+ }
+
+ protected class AntPreferences implements IPreferenceManager {
+
+ public boolean areProjectSpecificPrefsEnabled(IPath path) {
+ return false;
+ }
+
+ public boolean isBuilderEnabled(IPath path) {
+ return true;
+ }
+
+ public void setBuilderEnabled(IPath path, boolean val) {
+ // not implemented
+ }
+
+ public void setProjectSpecificPrefsEnabled(IPath path, boolean val) {
+ // not implemented
+ }
+ }
+ protected class AntLogger implements IArchivesLogger {
+ public void log(int severity, String message, Throwable throwable) {
+ currentProject.log(message, throwable, severity);
+ if( throwable != null && severity == IArchivesLogger.MSG_ERR)
+ throwable.printStackTrace();
+ }
+ }
}
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ant/AntVFS.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ant/AntVFS.java 2008-09-13
00:33:26 UTC (rev 10235)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ant/AntVFS.java 2008-09-13
01:59:24 UTC (rev 10236)
@@ -1,51 +1,75 @@
package org.jboss.ide.eclipse.archives.core.ant;
-import org.apache.tools.ant.Task;
+import java.util.ArrayList;
+import java.util.Iterator;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.jboss.ide.eclipse.archives.core.ArchivesCore;
import org.jboss.ide.eclipse.archives.core.model.IArchivesVFS;
import org.jboss.ide.eclipse.archives.core.model.IVariableManager;
import org.jboss.ide.eclipse.archives.core.xpl.StringSubstitutionEngineClone;
public class AntVFS implements IArchivesVFS, IVariableManager {
- private Task currentTask;
- public void setCurrentTask(Task task) { currentTask = task; }
- public Task getCurrentTask() { return currentTask; }
-
+ private String currentProject;
public String performStringSubstitution(String expression,
boolean reportUndefinedVariables) throws CoreException {
return new StringSubstitutionEngineClone().performStringSubstitution(expression,
reportUndefinedVariables, this);
}
- public String performStringSubstitution(String expression,
+ public synchronized String performStringSubstitution(String expression,
String projectName, boolean reportUndefinedVariables)
throws CoreException {
- // TODO Auto-generated method stub
- return null;
+ currentProject = projectName;
+ String result = new
StringSubstitutionEngineClone().performStringSubstitution(expression,
reportUndefinedVariables, this);
+ currentProject = null;
+ return result;
}
- public String[] getVariableNames() {
- return new String[0];
- }
public boolean containsVariable(String variable) {
+ if( IVariableManager.CURRENT_PROJECT.equals(variable) ) return true;
+ if( ((AntArchivesCore)ArchivesCore.getInstance()).getProject().getProperty(variable) !=
null ) return true;
return false;
}
+
+ public String getVariableValue(String variable) {
+ if( IVariableManager.CURRENT_PROJECT.equals(variable))
+ return currentProject;
+ return
((AntArchivesCore)ArchivesCore.getInstance()).getProject().getProperty(variable);
+ }
- public String getVariableValue(String variable, String arg) {
- return null;
- }
public IPath[] getWorkspaceChildren(IPath path) {
- // TODO Auto-generated method stub
- return null;
+ ArrayList<IPath> list = new ArrayList<IPath>();
+ IPath pathAbsolute = workspacePathToAbsolutePath(path);
+
+ if( pathAbsolute != null && pathAbsolute.toFile().exists() ) {
+ String[] children = pathAbsolute.toFile().list();
+ for( int i = 0; i < children.length; i++ ) {
+ IPath tmp = path.append(children[i]);
+ list.add(tmp);
+ }
+ }
+ return (IPath[]) list.toArray(new IPath[list.size()]);
}
public IPath workspacePathToAbsolutePath(IPath path) {
- // TODO Auto-generated method stub
+ if( path.segmentCount() > 0 && path.segment(0) != null ) {
+ String projNameProperty = path.segment(0) + ".dir";
+ Object result =
((AntArchivesCore)ArchivesCore.getInstance()).getProject().getProperties().get(projNameProperty);
+ if( result != null && result instanceof String)
+ return new Path((String)result).append(path.removeFirstSegments(1));
+ }
return null;
}
- public String getVariableValue(String variable) {
- // TODO Auto-generated method stub
- return null;
- }
+
public String getProjectName(IPath absolutePath) {
- // TODO Auto-generated method stub
+ for (Iterator iter =
((AntArchivesCore)ArchivesCore.getInstance()).getProject().getProperties().keySet().iterator();
iter.hasNext(); ) {
+ String property = (String) iter.next();
+ if (property.endsWith(".dir")) {
+ String val =
((AntArchivesCore)ArchivesCore.getInstance()).getProject().getProperty(property);
+ if( val != null && new Path(val).equals(absolutePath)) {
+ return property.substring(0, property.lastIndexOf("."));
+ }
+ }
+ }
return null;
}
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ant/GenerateArchivesTask.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ant/GenerateArchivesTask.java 2008-09-13
00:33:26 UTC (rev 10235)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ant/GenerateArchivesTask.java 2008-09-13
01:59:24 UTC (rev 10236)
@@ -32,6 +32,7 @@
import org.jboss.ide.eclipse.archives.core.ArchivesCore;
import org.jboss.ide.eclipse.archives.core.build.ArchiveBuildDelegate;
import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
+import org.jboss.ide.eclipse.archives.core.model.IArchivesLogger;
/**
* @author rob.stryker <rob.stryker(a)redhat.com>
@@ -43,18 +44,22 @@
public void init() throws BuildException {
// Force standalone mode
- ArchivesCore standalone = new AntArchivesCore();
+ AntArchivesCore standalone = new AntArchivesCore();
ArchivesCore.setInstance(standalone);
}
+ protected AntArchivesCore getCore() {
+ return (AntArchivesCore)ArchivesCore.getInstance();
+ }
public void execute() throws BuildException {
+ getCore().setProject(getProject());
+ getCore().setTask(this);
ClassLoader original = Thread.currentThread().getContextClassLoader();
try {
IPath projectPath = new Path(this.projectPath);
IProgressMonitor monitor = new NullProgressMonitor();
- for (Iterator iter = getProject().getProperties().keySet().iterator(); iter.hasNext();
)
- {
+ for (Iterator iter = getProject().getProperties().keySet().iterator(); iter.hasNext();
) {
String property = (String) iter.next();
if (property.endsWith(".dir")) {
System.setProperty(property, getProject().getProperty(property));
@@ -64,15 +69,19 @@
// needed so the correct XML binding / TrueZIP jars are loaded
ClassLoader myCL = getClass().getClassLoader();
Thread.currentThread().setContextClassLoader(myCL);
-
- ArchivesModel.instance().registerProject(projectPath, monitor);
- new ArchiveBuildDelegate().fullProjectBuild(projectPath);
+ if( ArchivesModel.instance().canReregister(projectPath)) {
+ ArchivesModel.instance().registerProject(projectPath, monitor);
+ new ArchiveBuildDelegate().fullProjectBuild(projectPath);
+ } else {
+ getCore().getLogger().log(IArchivesLogger.MSG_ERR, "Project \"" +
projectPath + "\" does not exist or has no .packages file. Skipping.",
null);
+ }
} catch(RuntimeException e ) {
- e.printStackTrace();
- throw e;
+ getCore().getLogger().log(IArchivesLogger.MSG_ERR, "A runtime error has occurred
during build.", e);
}
finally {
Thread.currentThread().setContextClassLoader(original);
+ getCore().setProject(null);
+ getCore().setTask(null);
}
}
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ArchiveBuildDelegate.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ArchiveBuildDelegate.java 2008-09-13
00:33:26 UTC (rev 10235)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ArchiveBuildDelegate.java 2008-09-13
01:59:24 UTC (rev 10236)
@@ -36,6 +36,7 @@
import org.jboss.ide.eclipse.archives.core.model.IArchiveFolder;
import org.jboss.ide.eclipse.archives.core.model.IArchiveModelRootNode;
import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
+import org.jboss.ide.eclipse.archives.core.model.IArchivesLogger;
import
org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory.DirectoryScannerExtension.FileWrapper;
import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
import org.jboss.ide.eclipse.archives.core.util.PathUtils;
@@ -81,7 +82,7 @@
*/
public void fullArchiveBuild(IArchive pkg) {
if( !pkg.canBuild() ) {
- ArchivesCore.getInstance().getLogger().log(IStatus.WARNING,
+ ArchivesCore.getInstance().getLogger().log(IArchivesLogger.MSG_ERR,
"Cannot Build archive \"" + pkg.getName() +
"\" due to a problem in the archive's configuration.", null);
return;
@@ -94,7 +95,7 @@
IPath dest = PathUtils.getGlobalLocation(pkg);
if( dest != null && !dest.toFile().exists() ) {
if( !dest.toFile().mkdirs() ) {
- ArchivesCore.getInstance().getLogger().log(IStatus.WARNING,
+ ArchivesCore.getInstance().getLogger().log(IArchivesLogger.MSG_ERR,
"Cannot Build archive \"" + pkg.getName() +
"\". Output location " + dest +
" is not writeable", null);
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/EventManager.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/EventManager.java 2008-09-13
00:33:26 UTC (rev 10235)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/EventManager.java 2008-09-13
01:59:24 UTC (rev 10236)
@@ -198,6 +198,7 @@
}
protected static void logError(Exception e) {
+ e.printStackTrace();
try {
StackTraceElement[] trace = Thread.currentThread().getStackTrace();
ArchivesCore.getInstance().getLogger().log(IArchivesLogger.MSG_WARN, "Archives
Listener error in " + trace[1].getMethodName(), e);
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IVariableManager.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IVariableManager.java 2008-09-13
00:33:26 UTC (rev 10235)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/IVariableManager.java 2008-09-13
01:59:24 UTC (rev 10236)
@@ -29,5 +29,4 @@
public static final String CURRENT_PROJECT = "archives_current_project";
public boolean containsVariable(String variable);
public String getVariableValue(String variable);
- public String[] getVariableNames();
}
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeImpl.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeImpl.java 2008-09-13
00:33:26 UTC (rev 10235)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/ArchiveNodeImpl.java 2008-09-13
01:59:24 UTC (rev 10236)
@@ -280,7 +280,7 @@
childChanges(child, IArchiveNodeDelta.CHILD_ADDED);
if( !validateModel()) {
removeChild(child);
- throw new ArchivesModelException("Unable to add child node");
+ throw new ArchivesModelException("Unable to add child node: " +
child.toString());
}
}
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/util/ModelUtil.java
===================================================================
---
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/util/ModelUtil.java 2008-09-13
00:33:26 UTC (rev 10235)
+++
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/util/ModelUtil.java 2008-09-13
01:59:24 UTC (rev 10236)
@@ -227,7 +227,7 @@
else
modelNode.addChild(childImpl);
} catch( ArchivesModelException ame ) {
- ArchivesCore.getInstance().getLogger().log(IArchivesLogger.MSG_WARN, "Error
Adding Child", ame);
+ ArchivesCore.getInstance().getLogger().log(IArchivesLogger.MSG_ERR,
ame.getMessage(), ame);
}
}
}