Author: rob.stryker(a)jboss.com
Date: 2008-11-11 14:36:41 -0500 (Tue, 11 Nov 2008)
New Revision: 11685
Added:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ui/
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ui/BuildActionTest.java
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ArchivesCoreMessages.java
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ArchivesCoreMessages.properties
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ArchiveBuildDelegate.java
trunk/archives/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/actions/BuildAction.java
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/META-INF/MANIFEST.MF
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java
Log:
JBIDE-3156 / JBDS-485 - Action was dumb, forgot to check for WrappedProject. Unit tests
added
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ArchivesCoreMessages.java
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ArchivesCoreMessages.java 2008-11-11
19:21:14 UTC (rev 11684)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ArchivesCoreMessages.java 2008-11-11
19:36:41 UTC (rev 11685)
@@ -18,6 +18,7 @@
public static String RuntimeErrorDuringBuild;
public static String ProjectCannotBeBuilt;
+ public static String ErrorBuilding;
public static String ErrorLocatingRootNode;
public static String BuildingProject;
public static String BuildingArchive;
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ArchivesCoreMessages.properties
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ArchivesCoreMessages.properties 2008-11-11
19:21:14 UTC (rev 11684)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/ArchivesCoreMessages.properties 2008-11-11
19:36:41 UTC (rev 11685)
@@ -12,6 +12,7 @@
RuntimeErrorDuringBuild=A runtime error has occurred during the build.
ProjectCannotBeBuilt=Project {0} does not exist or has no .packages file. Skipping.
+ErrorBuilding=An error occurred while building project archives
ErrorLocatingRootNode=An error occurred locating the root node for {0}
BuildingProject=Building project {0}
BuildingArchive=Building archive {0}
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ArchiveBuildDelegate.java
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ArchiveBuildDelegate.java 2008-11-11
19:21:14 UTC (rev 11684)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/build/ArchiveBuildDelegate.java 2008-11-11
19:36:41 UTC (rev 11685)
@@ -29,11 +29,13 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.jboss.ide.eclipse.archives.core.ArchivesCore;
import org.jboss.ide.eclipse.archives.core.ArchivesCoreMessages;
+import org.jboss.ide.eclipse.archives.core.ArchivesCorePlugin;
import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
import org.jboss.ide.eclipse.archives.core.model.EventManager;
import org.jboss.ide.eclipse.archives.core.model.IArchive;
@@ -67,7 +69,7 @@
* A full project build has been requested.
* @param project The project containing the archive model
*/
- public void fullProjectBuild(IPath project, IProgressMonitor monitor) {
+ public IStatus fullProjectBuild(IPath project, IProgressMonitor monitor) {
EventManager.cleanProjectBuild(project);
EventManager.startedBuild(project);
@@ -77,6 +79,7 @@
ArchivesCore.bind(ArchivesCoreMessages.ErrorLocatingRootNode, project.toOSString()),
null);
EventManager.error(null, new IStatus[]{s});
monitor.done();
+ return s;
} else {
IArchiveNode[] nodes = root.getChildren(IArchiveNode.TYPE_ARCHIVE);
ArrayList<IStatus> errors = new ArrayList<IStatus>();
@@ -91,7 +94,11 @@
EventManager.finishedBuild(project);
EventManager.error(null, errors.toArray(new IStatus[errors.size()]));
+ MultiStatus ms = new MultiStatus(ArchivesCorePlugin.PLUGIN_ID, 0,
ArchivesCoreMessages.ErrorBuilding, null);
+ for( int i = 0; i < errors.size(); i++ )
+ ms.add(errors.get(i));
monitor.done();
+ return ms;
}
}
@@ -99,17 +106,17 @@
* Builds an archive entirely, overwriting whatever was in the output destination.
* @param pkg The archive to build
*/
- public IStatus[] fullArchiveBuild(IArchive pkg, IProgressMonitor monitor) {
+ public IStatus fullArchiveBuild(IArchive pkg, IProgressMonitor monitor) {
return fullArchiveBuild(pkg, monitor, true);
}
- protected IStatus[] fullArchiveBuild(IArchive pkg, IProgressMonitor monitor, boolean
log) {
+ protected IStatus fullArchiveBuild(IArchive pkg, IProgressMonitor monitor, boolean log)
{
if( !pkg.canBuild() ) {
IStatus s = new Status(IStatus.ERROR, ArchivesCore.PLUGIN_ID,
ArchivesCore.bind(ArchivesCoreMessages.CannotBuildBadConfiguration, pkg.getName()),
null);
if( log )
EventManager.error(pkg, new IStatus[]{s});
monitor.done();
- return new IStatus[]{s};
+ return s;
}
EventManager.cleanArchiveBuild(pkg);
@@ -125,7 +132,7 @@
if( log )
EventManager.error(pkg, new IStatus[]{s});
monitor.done();
- return new IStatus[]{s};
+ return s;
}
}
@@ -189,8 +196,11 @@
IStatus[] errors2 = errors.toArray(new IStatus[errors.size()]);
if( log )
EventManager.error(pkg, errors2 );
+ MultiStatus ms = new MultiStatus(ArchivesCorePlugin.PLUGIN_ID, 0,
ArchivesCoreMessages.ErrorBuilding, null);
+ for( int i = 0; i < errors.size(); i++ )
+ ms.add(errors.get(i));
monitor.done();
- return errors2;
+ return ms;
}
/**
Modified:
trunk/archives/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/actions/BuildAction.java
===================================================================
---
trunk/archives/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/actions/BuildAction.java 2008-11-11
19:21:14 UTC (rev 11684)
+++
trunk/archives/plugins/org.jboss.ide.eclipse.archives.ui/src/main/org/jboss/ide/eclipse/archives/ui/actions/BuildAction.java 2008-11-11
19:36:41 UTC (rev 11685)
@@ -1,84 +1,92 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at
http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.ide.eclipse.archives.ui.actions;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.jobs.Job;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.IWorkbenchWindowActionDelegate;
-import org.jboss.ide.eclipse.archives.core.build.ArchiveBuildDelegate;
-import org.jboss.ide.eclipse.archives.core.model.IArchive;
-import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
-import org.jboss.ide.eclipse.archives.ui.ArchivesUIMessages;
-
-/**
- * Fire off a build of the archives or project / resource selected
- * @author "Rob Stryker" <rob.stryker(a)redhat.com>
- *
- */
-public class BuildAction implements IWorkbenchWindowActionDelegate {
- private IProject selectedProject;
- public void dispose() {
- }
-
- public void init(IWorkbenchWindow window) {
- }
-
- public void run(IAction action) {
- if( selectedProject != null )
- buildSelectedNode(selectedProject);
- }
-
- public void run(Object node) {
- buildSelectedNode(node);
- }
-
- public void selectionChanged(IAction action, ISelection selection) {
- if( !selection.isEmpty() && selection instanceof IStructuredSelection ) {
- Object o = ((IStructuredSelection)selection).getFirstElement();
- if( o instanceof IAdaptable ) {
- IResource res = (IResource) ((IAdaptable)o).getAdapter(IResource.class);
- if( res != null ) {
- selectedProject = res.getProject();
- return;
- }
- }
- }
- selectedProject = null;
- }
-
- private void buildSelectedNode(final Object selected) {
- new Job(ArchivesUIMessages.BuildArchivesNode) {
- // TODO actually get the status object
- protected IStatus run(IProgressMonitor monitor) {
- if( selected == null ) return Status.OK_STATUS;
- if (selected instanceof IArchiveNode &&
- ((IArchiveNode)selected).getNodeType() == IArchiveNode.TYPE_ARCHIVE) {
- new ArchiveBuildDelegate().fullArchiveBuild((IArchive)selected, monitor);
- } else if( selected != null && selected instanceof IProject ){
- new
ArchiveBuildDelegate().fullProjectBuild(((IProject)selected).getProject().getLocation(),
monitor);
- } else {
- new
ArchiveBuildDelegate().fullArchiveBuild(((IArchiveNode)selected).getRootArchive(),
monitor);
- }
- return Status.OK_STATUS;
- }
- }.schedule();
- }
-
-}
\ No newline at end of file
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.archives.ui.actions;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.jboss.ide.eclipse.archives.core.build.ArchiveBuildDelegate;
+import org.jboss.ide.eclipse.archives.core.model.IArchive;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
+import org.jboss.ide.eclipse.archives.ui.ArchivesUIMessages;
+import
org.jboss.ide.eclipse.archives.ui.providers.ArchivesContentProviderDelegate.WrappedProject;
+
+/**
+ * Fire off a build of the archives or project / resource selected
+ * @author "Rob Stryker" <rob.stryker(a)redhat.com>
+ *
+ */
+public class BuildAction implements IWorkbenchWindowActionDelegate {
+ private Object selected;
+ public void dispose() {
+ }
+
+ public void init(IWorkbenchWindow window) {
+ }
+
+ public void run(IAction action) {
+ if( selected != null )
+ buildSelectedNode(selected);
+ }
+
+ public Job run(Object node) {
+ return buildSelectedNode(node);
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ if( !selection.isEmpty() && selection instanceof IStructuredSelection ) {
+ Object o = ((IStructuredSelection)selection).getFirstElement();
+ if(o instanceof WrappedProject )
+ o = ((WrappedProject)o).getElement();
+ if( o instanceof IAdaptable ) {
+ IResource res = (IResource) ((IAdaptable)o).getAdapter(IResource.class);
+ if( res != null ) {
+ selected = res.getProject();
+ }
+ }
+ if( o instanceof IArchiveNode )
+ selected = o;
+ return;
+ }
+ selected = null;
+ }
+
+ private Job buildSelectedNode(final Object selected) {
+ Job j = new Job(ArchivesUIMessages.BuildArchivesNode) {
+ // TODO actually get the status object
+ protected IStatus run(IProgressMonitor monitor) {
+ if( selected == null ) return Status.OK_STATUS;
+ if( selected instanceof IArchiveNode ) {
+ IArchiveNode archive = (IArchiveNode)selected;
+ if( archive.getNodeType() != IArchiveNode.TYPE_ARCHIVE)
+ archive = archive.getRootArchive();
+ return new ArchiveBuildDelegate().fullArchiveBuild((IArchive)archive, monitor);
+ } else if( selected instanceof IProject || selected instanceof WrappedProject ) {
+ IProject p = selected instanceof IProject ? (IProject)selected :
((WrappedProject)selected).getElement();
+ return new ArchiveBuildDelegate().fullProjectBuild(p.getLocation(), monitor);
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ j.schedule();
+ return j;
+ }
+
+}
Modified: trunk/archives/tests/org.jboss.ide.eclipse.archives.test/META-INF/MANIFEST.MF
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/META-INF/MANIFEST.MF 2008-11-11
19:21:14 UTC (rev 11684)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/META-INF/MANIFEST.MF 2008-11-11
19:36:41 UTC (rev 11685)
@@ -14,7 +14,9 @@
org.eclipse.debug.core;bundle-version="3.4.0",
org.apache.ant;bundle-version="1.7.0",
org.eclipse.ant.ui;bundle-version="3.3.0",
- org.eclipse.jdt.launching;bundle-version="3.4.0"
+ org.eclipse.jdt.launching;bundle-version="3.4.0",
+ org.jboss.ide.eclipse.archives.ui;bundle-version="1.0.0",
+ org.eclipse.jface;bundle-version="3.4.0"
Eclipse-LazyStart: true
Bundle-ClassPath: archivestest.jar
Export-Package: org.jboss.ide.eclipse.archives.test,
Modified:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java 2008-11-11
19:21:14 UTC (rev 11684)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java 2008-11-11
19:36:41 UTC (rev 11685)
@@ -16,6 +16,7 @@
import org.jboss.ide.eclipse.archives.test.projects.JBIDE2311Test;
import org.jboss.ide.eclipse.archives.test.projects.JBIDE2315Test;
import org.jboss.ide.eclipse.archives.test.projects.JBIDE2439Test;
+import org.jboss.ide.eclipse.archives.test.ui.BuildActionTest;
import org.jboss.ide.eclipse.archives.test.util.TruezipUtilTest;
public class ArchivesTestSuite extends TestSuite {
@@ -38,6 +39,9 @@
suite.addTestSuite(JBIDE2315Test.class);
suite.addTestSuite(JBIDE2439Test.class);
+
+ // UI
+ suite.addTestSuite(BuildActionTest.class);
return suite;
}
Added:
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ui/BuildActionTest.java
===================================================================
---
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ui/BuildActionTest.java
(rev 0)
+++
trunk/archives/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ui/BuildActionTest.java 2008-11-11
19:36:41 UTC (rev 11685)
@@ -0,0 +1,116 @@
+package org.jboss.ide.eclipse.archives.test.ui;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.jobs.IJobChangeEvent;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.jboss.ide.eclipse.archives.core.model.ArchivesModel;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveModelRootNode;
+import org.jboss.ide.eclipse.archives.core.model.IArchiveNode;
+import org.jboss.ide.eclipse.archives.test.ArchivesTest;
+import org.jboss.ide.eclipse.archives.ui.actions.BuildAction;
+import
org.jboss.ide.eclipse.archives.ui.providers.ArchivesContentProviderDelegate.WrappedProject;
+import org.jboss.tools.common.test.util.TestProjectProvider;
+
+public class BuildActionTest extends TestCase {
+ private TestProjectProvider provider;
+ private IProject project;
+ private boolean waiting = true;
+ private boolean scheduled = false;
+ private JobChangeAdapter jobChangeAdapter;
+ private CoreException ce;
+ protected void setUp() throws Exception {
+ provider = new TestProjectProvider(ArchivesTest.PLUGIN_ID,
+ "inputs" + Path.SEPARATOR + "projects" + Path.SEPARATOR +
"JBIDE2099",
+ null, true);
+ project = provider.getProject();
+ project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
+ Job.getJobManager().addJobChangeListener(getJobChangeAdapter());
+ }
+
+ protected void tearDown() throws Exception {
+ provider.dispose();
+ Job.getJobManager().removeJobChangeListener(jobChangeAdapter);
+ }
+
+ protected JobChangeAdapter getJobChangeAdapter() {
+ jobChangeAdapter = new JobChangeAdapter() {
+ public void done(IJobChangeEvent event) {
+ if(
event.getJob().getClass().getName().startsWith("org.jboss.ide.eclipse.archives.ui.actions.BuildAction"))
{
+ IStatus result = event.getResult();
+ System.out.println(result);
+ if( !result.isOK())
+ ce = new CoreException(result);
+ waiting = false;
+ }
+ }
+ public void scheduled(IJobChangeEvent event) {
+ if(
event.getJob().getClass().getName().startsWith("org.jboss.ide.eclipse.archives.ui.actions.BuildAction"))
{
+ scheduled = true;
+ }
+ }
+ };
+ return jobChangeAdapter;
+ }
+
+ public void testBuildAction() {
+ ArchivesModel.instance().registerProject(project.getLocation(), new
NullProgressMonitor());
+ BuildAction action = new BuildAction();
+ waiting = true;
+
+ action.run(project);
+ waitForGo();
+
+ ISelection sel = new StructuredSelection(new Object[]{project});
+ action.selectionChanged(null, sel);
+ action.run(null);
+ waitForGo();
+
+
+
+ action.run(new WrappedProject(project, 0));
+ waitForGo();
+
+ sel = new StructuredSelection(new Object[] { new WrappedProject(project,0)});
+ action.selectionChanged(null, sel);
+ action.run(null);
+ waitForGo();
+
+
+
+ IArchiveModelRootNode root = ArchivesModel.instance().getRoot(project.getLocation());
+ IArchiveNode[] children = root.getAllChildren();
+ action.run(children[0]);
+ waitForGo();
+
+ sel = new StructuredSelection(children);
+ action.selectionChanged(null, sel);
+ action.run(null);
+ waitForGo();
+ }
+
+ protected void waitForGo() throws RuntimeException {
+ if( !scheduled )
+ fail("Job not scheduled");
+ while(waiting)
+ try {
+ Thread.sleep(500);
+ } catch(InterruptedException ie) {}
+
+ // finished, now start waiting again
+ waiting = true;
+ scheduled = false;
+
+ if( ce != null )
+ throw new RuntimeException(ce);
+ }
+}