JBoss Tools SVN: r14771 - trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2009-04-16 11:01:54 -0400 (Thu, 16 Apr 2009)
New Revision: 14771
Modified:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseResourceUtil.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4195
Modified: trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseResourceUtil.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseResourceUtil.java 2009-04-16 13:30:50 UTC (rev 14770)
+++ trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/EclipseResourceUtil.java 2009-04-16 15:01:54 UTC (rev 14771)
@@ -152,19 +152,19 @@
public static XModelObject addFileSystem(IResource resource, XModel model) {
XModelObject fss = FileSystemsHelper.getFileSystems(model);
if(fss == null) return null;
- while(resource != null && resource != resource.getProject() && resource.getParent() != null && resource.getParent() != resource.getProject()) {
- resource = resource.getParent();
- }
if(resource == null) return null;
- if(resource != resource.getProject() && resource.getParent() != resource.getProject()) return null;
- if(resource.isLinked()) return null;
Properties properties = new Properties();
String fsLoc = resource.getLocation().toString();
if(resource == resource.getProject()) {
fsLoc = "%" + IModelNature.ECLIPSE_PROJECT + "%";
} else {
fsLoc = getRelativeLocation(model, fsLoc);
- }
+ }
+ XModelObject[] cs = fss.getChildren("FileSystemFolder");
+ for (int i = 0; i < cs.length; i++) {
+ String loc = cs[i].getAttributeValue("location");
+ if(fsLoc.equals(loc)) return null;
+ }
properties.setProperty("location", fsLoc);
String name = resource.getName();
name = XModelObjectUtil.createNewChildName(name, fss);
@@ -288,6 +288,13 @@
fs = addFileSystem(resource.getProject(), sp.getModel());
if(fs != null) result = getObjectByResource(resource);
}
+ if(result == null && resource != project) {
+ IResource r = resource.getParent();
+ if(r != null && r != project) {
+ fs = addFileSystem(r, sp.getModel());
+ if(fs != null) result = getObjectByResource(resource);
+ }
+ }
}
return result;
}
@@ -295,7 +302,15 @@
XModel model = models.get(project);
if(model != null) {
validateJarSystem(FileSystemsHelper.getFileSystems(model), resource);
- return getObjectByResource(model, resource);
+ XModelObject result = getObjectByResource(model, resource);
+ if(result == null && resource instanceof IFile) {
+ IResource r = resource.getParent();
+ if(r != null && project != r) {
+ XModelObject fs = addFileSystem(r, model);
+ if(fs != null) return getObjectByResource(model, resource);
+ }
+ }
+ return result;
}
Properties properties = new Properties();
@@ -388,8 +403,16 @@
s.update();
o = s.getChildByPath(relpath.substring(1));
}
+ if(o == null) return null;
XModelObject p = o;
while(p != null && !"true".equals(p.get("overlapped"))) p = p.getParent();
+ if(p == null) {
+ IResource r = (IResource)o.getAdapter(IResource.class);
+ if(r == null || !resource.getLocation().equals(r.getLocation())) {
+ //failure, more detailed file system is needed.
+ return null;
+ }
+ }
return (p == null) ? o : null;
}
15 years, 8 months
JBoss Tools SVN: r14770 - trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util.
by jbosstools-commits@lists.jboss.org
Author: dmaliarevich
Date: 2009-04-16 09:30:50 -0400 (Thu, 16 Apr 2009)
New Revision: 14770
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4105, when image path is not specified NPE could be thrown, additional check was added.
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2009-04-16 10:19:21 UTC (rev 14769)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/VpeStyleUtil.java 2009-04-16 13:30:50 UTC (rev 14770)
@@ -603,7 +603,16 @@
*/
public static String addFullPathToImgSrc(String path,
VpePageContext pageContext, boolean showUnresolvedImage) {
-
+
+ if (path == null) {
+ if (showUnresolvedImage) {
+ return FILE_PROTOCOL + SLASH + SLASH
+ + getAbsoluteResourcePath(UNRESOLVED_IMAGE_PATH).replace('\\', '/');
+ } else {
+ return EMPTY_STRING;
+ }
+ }
+
IPath tagPath = new Path(path);
if (tagPath.isEmpty()) {
if (showUnresolvedImage) {
@@ -613,8 +622,6 @@
return path.replace('\\', '/');
}
}
-
-
String device = (tagPath.getDevice() == null ? tagPath.segment(0)
: tagPath.getDevice());
15 years, 8 months
JBoss Tools SVN: r14769 - trunk/jmx/plugins/org.jboss.tools.jmx.ui/src/org/jboss/tools/jmx/ui/internal/views/navigator.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2009-04-16 06:19:21 -0400 (Thu, 16 Apr 2009)
New Revision: 14769
Modified:
trunk/jmx/plugins/org.jboss.tools.jmx.ui/src/org/jboss/tools/jmx/ui/internal/views/navigator/JMXNavigator.java
trunk/jmx/plugins/org.jboss.tools.jmx.ui/src/org/jboss/tools/jmx/ui/internal/views/navigator/UpdateSelectionJob.java
Log:
JBIDE-3991 jmx compilation
Modified: trunk/jmx/plugins/org.jboss.tools.jmx.ui/src/org/jboss/tools/jmx/ui/internal/views/navigator/JMXNavigator.java
===================================================================
--- trunk/jmx/plugins/org.jboss.tools.jmx.ui/src/org/jboss/tools/jmx/ui/internal/views/navigator/JMXNavigator.java 2009-04-16 09:22:04 UTC (rev 14768)
+++ trunk/jmx/plugins/org.jboss.tools.jmx.ui/src/org/jboss/tools/jmx/ui/internal/views/navigator/JMXNavigator.java 2009-04-16 10:19:21 UTC (rev 14769)
@@ -20,7 +20,9 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.internal.navigator.NavigatorContentService;
import org.eclipse.ui.navigator.CommonNavigator;
+import org.eclipse.ui.navigator.LinkHelperService;
import org.jboss.tools.jmx.ui.internal.actions.NewConnectionAction;
/**
@@ -72,6 +74,11 @@
return filterText;
}
+ public synchronized LinkHelperService getLinkHelperService() {
+ return super.getLinkHelperService();
+ }
+
+
public void fillActionBars() {
// queryContribution = new QueryContribution(this);
// getViewSite().getActionBars().getToolBarManager().add(queryContribution);
Modified: trunk/jmx/plugins/org.jboss.tools.jmx.ui/src/org/jboss/tools/jmx/ui/internal/views/navigator/UpdateSelectionJob.java
===================================================================
--- trunk/jmx/plugins/org.jboss.tools.jmx.ui/src/org/jboss/tools/jmx/ui/internal/views/navigator/UpdateSelectionJob.java 2009-04-16 09:22:04 UTC (rev 14768)
+++ trunk/jmx/plugins/org.jboss.tools.jmx.ui/src/org/jboss/tools/jmx/ui/internal/views/navigator/UpdateSelectionJob.java 2009-04-16 10:19:21 UTC (rev 14769)
@@ -29,8 +29,8 @@
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.navigator.NavigatorContentService;
import org.eclipse.ui.internal.navigator.NavigatorPlugin;
-import org.eclipse.ui.internal.navigator.extensions.LinkHelperService;
import org.eclipse.ui.navigator.CommonNavigator;
+import org.eclipse.ui.navigator.LinkHelperService;
import org.eclipse.ui.progress.UIJob;
public class UpdateSelectionJob extends UIJob {
@@ -55,12 +55,14 @@
public UpdateSelectionJob(CommonNavigator commonNavigator) {
super("Updating Selection Job"); // TODO
this.commonNavigator = commonNavigator;
- linkService = new LinkHelperService((NavigatorContentService)commonNavigator.getCommonViewer().getNavigatorContentService());
+ if( commonNavigator instanceof JMXNavigator ) {
+ linkService = ((JMXNavigator)commonNavigator).getLinkHelperService();
+ }
}
public IStatus runInUIThread(IProgressMonitor monitor) {
- if (!commonNavigator.getCommonViewer().getControl().isDisposed()) {
+ if (linkService!= null && !commonNavigator.getCommonViewer().getControl().isDisposed()) {
SafeRunner.run(new ISafeRunnable() {
public void run() throws Exception {
15 years, 8 months
JBoss Tools SVN: r14768 - in trunk/as/plugins: org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers and 2 other directories.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2009-04-16 05:22:04 -0400 (Thu, 16 Apr 2009)
New Revision: 14768
Added:
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/TestPublisher.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/PublishUtil.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishCopyUtil.java
Removed:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishUtil.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServerBehavior.java
Log:
JBIDE-4193
Added: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/TestPublisher.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/TestPublisher.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/TestPublisher.java 2009-04-16 09:22:04 UTC (rev 14768)
@@ -0,0 +1,290 @@
+package org.jboss.ide.eclipse.archives.webtools.modules;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+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.wst.common.componentcore.ModuleCoreNature;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.internal.Server;
+import org.eclipse.wst.server.core.model.IModuleFile;
+import org.eclipse.wst.server.core.model.IModuleFolder;
+import org.eclipse.wst.server.core.model.IModuleResource;
+import org.eclipse.wst.server.core.model.IModuleResourceDelta;
+import org.jboss.ide.eclipse.archives.core.util.internal.TrueZipUtil;
+import org.jboss.ide.eclipse.archives.webtools.IntegrationPlugin;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
+import org.jboss.ide.eclipse.as.core.publishers.PublishUtil;
+import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
+import org.jboss.ide.eclipse.as.core.server.internal.DeployableServerBehavior;
+import org.jboss.ide.eclipse.as.core.util.FileUtil;
+import org.jboss.ide.eclipse.as.core.util.FileUtil.IFileUtilListener;
+
+import de.schlichtherle.io.ArchiveDetector;
+
+public class TestPublisher extends PublishUtil implements IJBossServerPublisher {
+ private int moduleState = IServer.PUBLISH_STATE_NONE;
+ public boolean accepts(IServer server, IModule[] module) {
+ // TODO check for zip preference
+ return ModuleCoreNature.isFlexibleProject(module[0].getProject());
+ }
+
+ public int getPublishState() {
+ return moduleState;
+ }
+
+ protected IDeployableServer getDeployableServer(IServer server) {
+ return (IDeployableServer)server.loadAdapter(IDeployableServer.class, new NullProgressMonitor());
+ }
+ protected DeployableServerBehavior getBehaviour(IServer server) {
+ return (DeployableServerBehavior)server.loadAdapter(DeployableServerBehavior.class, new NullProgressMonitor());
+ }
+
+ protected List<IModule[]> getRemovedModules(IServer s) {
+ return getBehaviour(s).getRemovedModules();
+ }
+
+ public boolean isNew(IModule[] module, IServer s) {
+ return !getBehaviour(s).hasBeenPublished(module);
+ }
+
+
+ public IStatus publishModule(IServer server, IModule[] module,
+ int publishType, IModuleResourceDelta[] delta,
+ IProgressMonitor monitor) throws CoreException {
+ if( module.length > 1 ) {
+ return Status.OK_STATUS;
+ }
+
+ IStatus[] returnStatus;
+ // Am I a removal? If yes, remove me, and return
+ if( publishType == IJBossServerPublisher.REMOVE_PUBLISH)
+ returnStatus = removeModule(server, module);
+
+ // Am I a full publish? If yes, full publish me, and return
+ else if( publishType == IJBossServerPublisher.FULL_PUBLISH)
+ returnStatus = fullPublish(server, module);
+
+ else {
+ // Am I changed? If yes, handle my changes
+ ArrayList<IStatus> results = new ArrayList<IStatus>();
+ if( countChanges(delta) > 0) {
+ results.addAll(Arrays.asList(publishChanges(server, module)));
+ }
+
+ IModule[] children = server.getChildModules(module, new NullProgressMonitor());
+ results.addAll(Arrays.asList(handleChildrenDeltas(server, module, children)));
+
+ // Handle the removed children that are not returned by getChildModules
+ List<IModule[]> removed = getBehaviour(server).getRemovedModules();
+ Iterator<IModule[]> i = removed.iterator();
+ while(i.hasNext()) {
+ IModule[] removedArray = i.next();
+ if( removedArray[0].getId().equals(module[0].getId())) {
+ results.addAll(Arrays.asList(removeModule(server, removedArray)));
+ }
+ }
+ returnStatus = (IStatus[]) results.toArray(new IStatus[results.size()]);
+ }
+ TrueZipUtil.umount();
+
+ IStatus finalStatus;
+ if( returnStatus.length > 0 ) {
+ MultiStatus ms = new MultiStatus(JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_INC_FAIL,
+ "Publish Failed for module " + module[0].getName(), null); //$NON-NLS-1$
+ for( int i = 0; i < returnStatus.length; i++ )
+ ms.add(returnStatus[i]);
+ finalStatus = ms;
+ } else
+ finalStatus = Status.OK_STATUS;
+
+ return finalStatus;
+ }
+
+ protected IStatus[] handleChildrenDeltas(IServer server, IModule[] module, IModule[] children) {
+ // For each child:
+ ArrayList<IStatus> results = new ArrayList<IStatus>();
+ for( int i = 0; i < children.length; i++ ) {
+ IModule[] combinedChild = combine(module, children[i]);
+ // if it's new, full publish it
+ if( !getBehaviour(server).hasBeenPublished(combinedChild)) {
+ results.addAll(Arrays.asList(fullPublish(server, combinedChild)));
+ }
+ // else if it's removed, full remove it
+ else if( isRemoved(server, combinedChild)) {
+ results.addAll(Arrays.asList(removeModule(server, combinedChild)));
+ }
+ // else
+ else {
+ // handle changed resources
+ results.addAll(Arrays.asList(publishChanges(server, combinedChild)));
+
+ // recurse
+ IModule[] children2 = server.getChildModules(combinedChild, new NullProgressMonitor());
+ results.addAll(Arrays.asList(handleChildrenDeltas(server, children, children2)));
+ }
+ }
+ return (IStatus[]) results.toArray(new IStatus[results.size()]);
+ }
+
+ protected boolean isRemoved(IServer server, IModule[] child) {
+ List<IModule[]> removed = getBehaviour(server).getRemovedModules();
+ Iterator<IModule[]> i = removed.iterator();
+ while(i.hasNext()) {
+ IModule[] next = i.next();
+ if( next.length == child.length) {
+ for( int j = 0; j < next.length; j++ ) {
+ if( !next[j].getId().equals(child[j].getId())) {
+ continue;
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected IStatus[] removeModule(IServer server, IModule[] module) {
+ String depFolder = getDeployableServer(server).getDeployFolder();
+ IPath deployPath = getDeployPath(module, depFolder);
+ final ArrayList<IStatus> status = new ArrayList<IStatus>();
+ IFileUtilListener listener = new IFileUtilListener() {
+ public void fileCopied(File source, File dest, boolean result,Exception e) {}
+ public void fileDeleted(File file, boolean result, Exception e) {
+ if( result == false || e != null ) {
+ status.add(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_FILE_DELETE_FAIL,
+ "Attempt to delete " + file.getAbsolutePath() + " failed",e)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ public void folderDeleted(File file, boolean result, Exception e) {
+ if( result == false || e != null ) {
+ status.add(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_FILE_DELETE_FAIL,
+ "Attempt to delete " + file.getAbsolutePath() + " failed",e)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ };
+ FileUtil.safeDelete(deployPath.toFile(), listener);
+ return (IStatus[]) status.toArray(new IStatus[status.size()]);
+ }
+
+ protected IStatus[] fullPublish(IServer server, IModule[] module) {
+ ArrayList<IStatus> results = new ArrayList<IStatus>();
+ try {
+ String depFolder = getDeployableServer(server).getDeployFolder();
+ IPath path = getDeployPath(module, depFolder);
+ // Get rid of the old
+ path.toFile().delete();
+
+ TrueZipUtil.createArchive(path);
+ de.schlichtherle.io.File root = TrueZipUtil.getFile(path, TrueZipUtil.getJarArchiveDetector());
+ IModuleResource[] resources = getResources(module);
+ results.addAll(Arrays.asList(copy(root, resources)));
+
+ IModule[] children = server.getChildModules(module, new NullProgressMonitor());
+ for( int i = 0; i < children.length; i++ )
+ results.addAll(Arrays.asList(fullPublish(server, combine(module, children[i]))));
+ return (IStatus[]) results.toArray(new IStatus[results.size()]);
+ } catch( CoreException ce) {
+ results.add(generateCoreExceptionStatus(ce));
+ return (IStatus[]) results.toArray(new IStatus[results.size()]);
+ }
+ }
+
+ protected IStatus[] publishChanges(IServer server, IModule[] module) {
+ String depFolder = getDeployableServer(server).getDeployFolder();
+ IPath path = getDeployPath(module, depFolder);
+ de.schlichtherle.io.File root = TrueZipUtil.getFile(path, TrueZipUtil.getJarArchiveDetector());
+ IModuleResourceDelta[] deltas = ((Server)server).getPublishedResourceDelta(module);
+ return publishChanges(server, deltas, root);
+ }
+
+ protected IStatus[] publishChanges(IServer server, IModuleResourceDelta[] deltas, de.schlichtherle.io.File root) {
+ ArrayList<IStatus> results = new ArrayList<IStatus>();
+ if( deltas == null || deltas.length == 0 )
+ return new IStatus[]{};
+ int dKind;
+ IModuleResource resource;
+ for( int i = 0; i < deltas.length; i++ ) {
+ dKind = deltas[i].getKind();
+ resource = deltas[i].getModuleResource();
+ if( dKind == IModuleResourceDelta.ADDED ) {
+ results.addAll(Arrays.asList(copy(root, new IModuleResource[]{resource})));
+ } else if( dKind == IModuleResourceDelta.CHANGED ) {
+ if( resource instanceof IModuleFile )
+ results.addAll(Arrays.asList(copy(root, new IModuleResource[]{resource})));
+ results.addAll(Arrays.asList(publishChanges(server, deltas[i].getAffectedChildren(), root)));
+ } else if( dKind == IModuleResourceDelta.REMOVED) {
+ de.schlichtherle.io.File f = getFileInArchive(root,
+ resource.getModuleRelativePath().append(
+ resource.getName()));
+ boolean b = f.deleteAll();
+ if( !b )
+ results.add(generateDeleteFailedStatus(f));
+ } else if( dKind == IModuleResourceDelta.NO_CHANGE ) {
+ results.addAll(Arrays.asList(publishChanges(server, deltas[i].getAffectedChildren(), root)));
+ }
+ }
+
+ return (IStatus[]) results.toArray(new IStatus[results.size()]);
+ }
+
+
+ protected IStatus[] copy(de.schlichtherle.io.File root, IModuleResource[] children) {
+ ArrayList<IStatus> results = new ArrayList<IStatus>();
+ for( int i = 0; i < children.length; i++ ) {
+ if( children[i] instanceof IModuleFile ) {
+ IModuleFile mf = (IModuleFile)children[i];
+ java.io.File source = getFile(mf);
+ de.schlichtherle.io.File destination = getFileInArchive(root, mf.getModuleRelativePath().append(mf.getName()));
+ boolean b = new de.schlichtherle.io.File(source).copyAllTo(destination);
+ if( !b )
+ results.add(generateCopyFailStatus(source, destination));
+ } else if( children[i] instanceof IModuleFolder ) {
+ de.schlichtherle.io.File destination = getFileInArchive(root, children[i].getModuleRelativePath().append(children[i].getName()));
+ destination.mkdirs();
+ IModuleFolder mf = (IModuleFolder)children[i];
+ results.addAll(Arrays.asList(copy(root, mf.members())));
+ }
+ }
+ return (IStatus[]) results.toArray(new IStatus[results.size()]);
+ }
+
+ protected IStatus generateDeleteFailedStatus(java.io.File file) {
+ return new Status(IStatus.ERROR, IntegrationPlugin.PLUGIN_ID, "Could not delete file " + file); //$NON-NLS-1$
+ }
+ protected IStatus generateCoreExceptionStatus(CoreException ce) {
+ return new Status(IStatus.ERROR, IntegrationPlugin.PLUGIN_ID, ce.getMessage(), ce);
+ }
+ protected IStatus generateCopyFailStatus(java.io.File source, java.io.File destination) {
+ return new Status(IStatus.ERROR, IntegrationPlugin.PLUGIN_ID, "Copy of " + source + " to " + destination + " has failed");//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
+ }
+
+ protected de.schlichtherle.io.File getFileInArchive(de.schlichtherle.io.File root, IPath relative) {
+ while(relative.segmentCount() > 0 ) {
+ root = new de.schlichtherle.io.File(root,
+ relative.segment(0), ArchiveDetector.DEFAULT);
+ relative = relative.removeFirstSegments(1);
+ }
+ return root;
+ }
+
+ private IModule[] combine(IModule[] module, IModule newMod) {
+ IModule[] retval = new IModule[module.length + 1];
+ for( int i = 0; i < module.length; i++ )
+ retval[i]=module[i];
+ retval[retval.length-1] = newMod;
+ return retval;
+ }
+}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java 2009-04-16 07:48:52 UTC (rev 14767)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java 2009-04-16 09:22:04 UTC (rev 14768)
@@ -34,25 +34,22 @@
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.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.wst.common.componentcore.ModuleCoreNature;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.internal.DeletedModule;
-import org.eclipse.wst.server.core.model.IModuleFile;
import org.eclipse.wst.server.core.model.IModuleFolder;
import org.eclipse.wst.server.core.model.IModuleResource;
import org.eclipse.wst.server.core.model.IModuleResourceDelta;
-import org.eclipse.wst.server.core.model.ModuleDelegate;
import org.eclipse.wst.server.core.util.ProjectModule;
import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
import org.jboss.ide.eclipse.as.core.server.xpl.ModulePackager;
-import org.jboss.ide.eclipse.as.core.server.xpl.PublishUtil;
+import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil;
import org.jboss.ide.eclipse.as.core.util.FileUtil;
import org.jboss.ide.eclipse.as.core.util.ServerConverter;
import org.jboss.ide.eclipse.as.core.util.FileUtil.FileUtilListener;
@@ -64,7 +61,7 @@
*
* @author rob.stryker(a)jboss.com
*/
-public class JstPublisher implements IJBossServerPublisher {
+public class JstPublisher extends PublishUtil implements IJBossServerPublisher {
protected IModuleResourceDelta[] delta;
@@ -74,15 +71,6 @@
public JstPublisher() {
}
-
- protected String getModulePath(IModule[] module ) {
- String modulePath = "";
- for( int i = 0; i < module.length; i++ ) {
- modulePath += module[i].getName() + Path.SEPARATOR;
- }
- modulePath = modulePath.substring(0, modulePath.length()-1);
- return modulePath;
- }
public IStatus publishModule(IServer server, IModule[] module,
int publishType, IModuleResourceDelta[] delta, IProgressMonitor monitor) throws CoreException {
@@ -114,9 +102,8 @@
protected IStatus fullPublish(IModule[] moduleTree, IModule module, IProgressMonitor monitor) throws CoreException {
- IPath deployPath = getDeployPath(moduleTree);
- ModuleDelegate md = (ModuleDelegate)module.loadAdapter(ModuleDelegate.class, monitor);
- IModuleResource[] members = md.members();
+ IPath deployPath = getDeployPath(moduleTree, server.getDeployFolder());
+ IModuleResource[] members = getResources(module);
ArrayList<IStatus> list = new ArrayList<IStatus>();
// if the module we're publishing is a project, not a binary, clean it's folder
@@ -124,7 +111,7 @@
list.addAll(Arrays.asList(localSafeDelete(deployPath)));
if( !deployPackaged(moduleTree) && !isBinaryObject(moduleTree))
- list.addAll(Arrays.asList(new PublishUtil(server.getServer()).publishFull(members, deployPath, monitor)));
+ list.addAll(Arrays.asList(new PublishCopyUtil(server.getServer()).publishFull(members, deployPath, monitor)));
else if( isBinaryObject(moduleTree))
list.addAll(Arrays.asList(copyBinaryModule(moduleTree)));
else
@@ -157,9 +144,9 @@
protected IStatus incrementalPublish(IModule[] moduleTree, IModule module, IProgressMonitor monitor) throws CoreException {
IStatus[] results = new IStatus[] {};
- IPath deployPath = getDeployPath(moduleTree);
+ IPath deployPath = getDeployPath(moduleTree, server.getDeployFolder());
if( !deployPackaged(moduleTree) && !isBinaryObject(moduleTree))
- results = new PublishUtil(server.getServer()).publishDelta(delta, deployPath, monitor);
+ results = new PublishCopyUtil(server.getServer()).publishDelta(delta, deployPath, monitor);
else if( delta.length > 0 ) {
if( isBinaryObject(moduleTree))
results = copyBinaryModule(moduleTree);
@@ -181,7 +168,7 @@
protected IStatus unpublish(IDeployableServer jbServer, IModule[] module,
IProgressMonitor monitor) throws CoreException {
IModule mod = module[module.length-1];
- IStatus[] errors = localSafeDelete(getDeployPath(module));
+ IStatus[] errors = localSafeDelete(getDeployPath(module, server.getDeployFolder()));
if( errors.length > 0 ) {
publishState = IServer.PUBLISH_STATE_FULL;
MultiStatus ms = new MultiStatus(JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_REMOVE_FAIL,
@@ -195,48 +182,13 @@
return ret;
}
- protected IPath getDeployPath(IModule[] moduleTree) {
- IPath root = new Path( server.getDeployFolder() );
- String type, name;
- for( int i = 0; i < moduleTree.length; i++ ) {
- type = moduleTree[i].getModuleType().getId();
- name = moduleTree[i].getName();
- if( new Path(name).segmentCount() > 1 )
- // we strongly suspect this is a binary object and not a project
- return root.append(new Path(name).lastSegment());
- if( "jst.ear".equals(type))
- root = root.append(name + ".ear");
- else if( "jst.web".equals(type))
- root = root.append(name + ".war");
- else if( "jst.utility".equals(type) && i >= 1 && "jst.web".equals(moduleTree[i-1].getModuleType().getId()))
- root = root.append("WEB-INF").append("lib").append(name + ".jar");
- else if( "jst.connector".equals(type)) {
- root = root.append(name + ".rar");
- } else if( "jst.jboss.esb".equals(type)){
- root = root.append(name + ".esb");
- }else
- root = root.append(name + ".jar");
- }
- return root;
- }
+
- protected boolean isBinaryObject(IModule[] moduleTree) {
- String name;
- for( int i = 0; i < moduleTree.length; i++ ) {
- name = moduleTree[i].getName();
- if( new Path(name).segmentCount() > 1 )
- // we strongly suspect this is a binary object and not a project
- return true;
- }
- return false;
- }
-
protected IStatus[] copyBinaryModule(IModule[] moduleTree) {
try {
- IPath deployPath = getDeployPath(moduleTree);
+ IPath deployPath = getDeployPath(moduleTree, server.getDeployFolder());
FileUtilListener listener = new FileUtilListener();
- ModuleDelegate deployable =(ModuleDelegate)moduleTree[moduleTree.length-1].loadAdapter(ModuleDelegate.class, new NullProgressMonitor());
- IModuleResource[] members = deployable.members();
+ IModuleResource[] members = getResources(moduleTree);
File source = (File)members[0].getAdapter(File.class);
if( source == null ) {
IFile ifile = (IFile)members[0].getAdapter(IFile.class);
@@ -285,7 +237,7 @@
FileUtil.safeDelete(deployPath.toFile(), listener);
return (IStatus[]) status.toArray(new IStatus[status.size()]);
}
- protected boolean deployPackaged(IModule[] moduleTree) {
+ public static boolean deployPackaged(IModule[] moduleTree) {
if( moduleTree[moduleTree.length-1].getModuleType().getId().equals("jst.utility")) return true;
if( moduleTree[moduleTree.length-1].getModuleType().getId().equals("jst.appclient")) return true;
return false;
@@ -349,40 +301,6 @@
}
}
}
-
- protected int countChanges(IModuleResourceDelta[] deltas) {
- IModuleResource res;
- int count = 0;
- if( deltas == null ) return 0;
- for( int i = 0; i < deltas.length; i++ ) {
- res = deltas[i].getModuleResource();
- if( res != null && res instanceof IModuleFile)
- count++;
- count += countChanges(deltas[i].getAffectedChildren());
- }
- return count;
- }
-
- protected int countMembers(IModule module) {
- try {
- ModuleDelegate delegate = (ModuleDelegate)module.loadAdapter(ModuleDelegate.class, new NullProgressMonitor());
- return delegate == null ? 0 : countMembers(delegate.members());
- } catch( CoreException ce ) {}
- return 0;
- }
- protected int countMembers(IModuleResource[] resources) {
- int count = 0;
- if( resources == null ) return 0;
- for( int i = 0; i < resources.length; i++ ) {
- if( resources[i] instanceof IModuleFile ) {
- count++;
- } else if( resources[i] instanceof IModuleFolder ) {
- count += countMembers(((IModuleFolder)resources[i]).members());
- }
- }
- return count;
- }
-
public boolean accepts(IServer server, IModule[] module) {
return ModuleCoreNature.isFlexibleProject(module[0].getProject());
}
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/PublishUtil.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/PublishUtil.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/PublishUtil.java 2009-04-16 09:22:04 UTC (rev 14768)
@@ -0,0 +1,101 @@
+package org.jboss.ide.eclipse.as.core.publishers;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.model.IModuleFile;
+import org.eclipse.wst.server.core.model.IModuleFolder;
+import org.eclipse.wst.server.core.model.IModuleResource;
+import org.eclipse.wst.server.core.model.IModuleResourceDelta;
+import org.eclipse.wst.server.core.model.ModuleDelegate;
+
+public class PublishUtil {
+ public static int countChanges(IModuleResourceDelta[] deltas) {
+ IModuleResource res;
+ int count = 0;
+ if( deltas == null ) return 0;
+ for( int i = 0; i < deltas.length; i++ ) {
+ res = deltas[i].getModuleResource();
+ if( res != null && res instanceof IModuleFile)
+ count++;
+ count += countChanges(deltas[i].getAffectedChildren());
+ }
+ return count;
+ }
+
+
+ public static int countMembers(IModule module) {
+ try {
+ ModuleDelegate delegate = (ModuleDelegate)module.loadAdapter(ModuleDelegate.class, new NullProgressMonitor());
+ return delegate == null ? 0 : countMembers(delegate.members());
+ } catch( CoreException ce ) {}
+ return 0;
+ }
+ public static int countMembers(IModuleResource[] resources) {
+ int count = 0;
+ if( resources == null ) return 0;
+ for( int i = 0; i < resources.length; i++ ) {
+ if( resources[i] instanceof IModuleFile ) {
+ count++;
+ } else if( resources[i] instanceof IModuleFolder ) {
+ count += countMembers(((IModuleFolder)resources[i]).members());
+ }
+ }
+ return count;
+ }
+
+ public static IPath getDeployPath(IModule[] moduleTree, String deployFolder) {
+ // TODO This should probably change once 241466 is solved
+ IPath root = new Path( deployFolder );
+ String type, name;
+ for( int i = 0; i < moduleTree.length; i++ ) {
+ type = moduleTree[i].getModuleType().getId();
+ name = moduleTree[i].getName();
+ if( new Path(name).segmentCount() > 1 )
+ // we strongly suspect this is a binary object and not a project
+ return root.append(new Path(name).lastSegment());
+ if( "jst.ear".equals(type))
+ root = root.append(name + ".ear");
+ else if( "jst.web".equals(type))
+ root = root.append(name + ".war");
+ else if( "jst.utility".equals(type) && i >= 1 && "jst.web".equals(moduleTree[i-1].getModuleType().getId()))
+ root = root.append("WEB-INF").append("lib").append(name + ".jar");
+ else if( "jst.connector".equals(type)) {
+ root = root.append(name + ".rar");
+ } else if( "jst.jboss.esb".equals(type)){
+ root = root.append(name + ".esb");
+ }else
+ root = root.append(name + ".jar");
+ }
+ return root;
+ }
+
+ public static boolean isBinaryObject(IModule[] moduleTree) {
+ String name;
+ for( int i = 0; i < moduleTree.length; i++ ) {
+ name = moduleTree[i].getName();
+ if( new Path(name).segmentCount() > 1 )
+ // we strongly suspect this is a binary object and not a project
+ return true;
+ }
+ return false;
+ }
+
+ public static IModuleResource[] getResources(IModule module) throws CoreException {
+ ModuleDelegate md = (ModuleDelegate)module.loadAdapter(ModuleDelegate.class, new NullProgressMonitor());
+ IModuleResource[] members = md.members();
+ return members;
+ }
+ public static IModuleResource[] getResources(IModule[] tree) throws CoreException {
+ return getResources(tree[tree.length-1]);
+ }
+
+ public static java.io.File getFile(IModuleFile mf) {
+ return (IFile)mf.getAdapter(IFile.class) != null ?
+ ((IFile)mf.getAdapter(IFile.class)).getLocation().toFile() :
+ (java.io.File)mf.getAdapter(java.io.File.class);
+ }
+}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServerBehavior.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServerBehavior.java 2009-04-16 07:48:52 UTC (rev 14767)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServerBehavior.java 2009-04-16 09:22:04 UTC (rev 14768)
@@ -21,6 +21,8 @@
*/
package org.jboss.ide.eclipse.as.core.server.internal;
+import java.util.List;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -29,6 +31,7 @@
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.IServerListener;
import org.eclipse.wst.server.core.ServerEvent;
+import org.eclipse.wst.server.core.model.IModuleResourceDelta;
import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
import org.jboss.ide.eclipse.as.core.ExtensionManager;
import org.jboss.ide.eclipse.as.core.extensions.events.ServerLogger;
@@ -79,12 +82,16 @@
int publishType = getPublishType(kind, deltaKind, modulePublishState);
IJBossServerPublisher publisher;
- if( module.length > 0 && publishType != IJBossServerPublisher.NO_PUBLISH) {
+ // Let the publisher decide what to do
+ if( module.length > 0 ) {
publisher = ExtensionManager.getDefault().getPublisher(getServer(), module);
+ IModuleResourceDelta[] deltas = new IModuleResourceDelta[]{};
+ if( deltaKind != ServerBehaviourDelegate.REMOVED)
+ deltas = getPublishedResourceDelta(module);
if( publisher != null ) {
try {
- IStatus result = publisher.publishModule(getServer(), module, publishType,
- getPublishedResourceDelta(module), monitor);
+ IStatus result = publisher.publishModule(getServer(), module,
+ publishType, deltas, monitor);
if( result != null )
ServerLogger.getDefault().log(getServer(), result);
} catch( CoreException ce ) {
@@ -109,6 +116,22 @@
return IJBossServerPublisher.NO_PUBLISH;
}
+ // Expose
+ public List<IModule[]> getRemovedModules() {
+ final List<IModule[]> moduleList = getAllModules();
+ int size = moduleList.size();
+ super.addRemovedModules(moduleList, null);
+ for( int i = 0; i < size; i++ )
+ moduleList.remove(0);
+ return moduleList;
+ }
+
+ public boolean hasBeenPublished(IModule[] module) {
+ return super.hasBeenPublished(module);
+ }
+
+
+
/*
* Change the state of the server
* Also, cache the state we think we're setting it to.
Copied: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishCopyUtil.java (from rev 14008, trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishUtil.java)
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishCopyUtil.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishCopyUtil.java 2009-04-16 09:22:04 UTC (rev 14768)
@@ -0,0 +1,782 @@
+/*******************************************************************************
+ * Copyright (c) 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are 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:
+ * IBM Corporation - Initial API and implementation
+ *******************************************************************************/
+package org.jboss.ide.eclipse.as.core.server.xpl;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+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.Status;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.internal.Messages;
+import org.eclipse.wst.server.core.internal.ProgressUtil;
+import org.eclipse.wst.server.core.internal.ServerPlugin;
+import org.eclipse.wst.server.core.internal.Trace;
+import org.eclipse.wst.server.core.model.IModuleFile;
+import org.eclipse.wst.server.core.model.IModuleFolder;
+import org.eclipse.wst.server.core.model.IModuleResource;
+import org.eclipse.wst.server.core.model.IModuleResourceDelta;
+import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
+import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+/**
+ * Utility class with an assortment of useful file methods.
+ * <p>
+ * This class provides all its functionality through static members.
+ * It is not intended to be subclassed or instantiated.
+ * </p>
+ * <p>
+ * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
+ * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
+ * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
+ * (repeatedly) as the API evolves.
+ * </p>
+ * @since 2.0
+ */
+public final class PublishCopyUtil {
+ // size of the buffer
+ private static final int BUFFER = 65536;
+
+ // the buffer
+ private static byte[] buf = new byte[BUFFER];
+
+ private static final IStatus[] EMPTY_STATUS = new IStatus[0];
+
+ private static final File tempDir = ServerPlugin.getInstance().getStateLocation().toFile();
+
+ private static final String TEMPFILE_PREFIX = "tmp";
+
+ /**
+ * PublishUtil cannot be created. Use static methods.
+ */
+ private IServer server;
+ public PublishCopyUtil(IServer server) {
+ this.server = server;
+ }
+
+ /**
+ * Copy a file from a to b. Closes the input stream after use.
+ *
+ * @param in an input stream
+ * @param to a path to copy to. the directory must already exist
+ * @param ts timestamp
+ * @throws CoreException if anything goes wrong
+ */
+ private void copyFile(InputStream in, IPath to, long ts, IModuleFile mf) throws CoreException {
+ OutputStream out = null;
+
+ File tempFile = null;
+ try {
+ File file = to.toFile();
+
+ // Change from original PublishUtil, will require
+ tempFile = File.createTempFile(TEMPFILE_PREFIX, "." + to.getFileExtension(), getTempFolder());
+
+ out = new FileOutputStream(tempFile);
+
+ int avail = in.read(buf);
+ while (avail > 0) {
+ out.write(buf, 0, avail);
+ avail = in.read(buf);
+ }
+
+ out.close();
+ out = null;
+
+ moveTempFile(tempFile, file);
+
+ if (ts != IResource.NULL_STAMP && ts != 0)
+ file.setLastModified(ts);
+ } catch (CoreException e) {
+ throw e;
+ } catch (Exception e) {
+ IPath path = mf.getModuleRelativePath().append(mf.getName());
+ Trace.trace(Trace.SEVERE, "Error copying file: " + to.toOSString() + " to " + path.toOSString(), e);
+ throw new CoreException(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCopyingFile, path.toOSString(), e.getLocalizedMessage()), null));
+ } finally {
+ if (tempFile != null && tempFile.exists())
+ tempFile.deleteOnExit();
+ try {
+ if (in != null)
+ in.close();
+ } catch (Exception ex) {
+ // ignore
+ }
+ try {
+ if (out != null)
+ out.close();
+ } catch (Exception ex) {
+ // ignore
+ }
+ }
+ }
+
+ /**
+ * Utility method to recursively delete a directory.
+ *
+ * @param dir a directory
+ * @param monitor a progress monitor, or <code>null</code> if progress
+ * reporting and cancellation are not desired
+ * @return a possibly-empty array of error and warning status
+ */
+ public IStatus[] deleteDirectory(File dir, IProgressMonitor monitor) {
+ if (!dir.exists() || !dir.isDirectory())
+ return new IStatus[] { new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorNotADirectory, dir.getAbsolutePath()), null) };
+
+ List status = new ArrayList(2);
+
+ try {
+ File[] files = dir.listFiles();
+ int size = files.length;
+ monitor = ProgressUtil.getMonitorFor(monitor);
+ monitor.beginTask(NLS.bind(Messages.deletingTask, new String[] { dir.getAbsolutePath() }), size * 10);
+
+ // cycle through files
+ boolean deleteCurrent = true;
+ for (int i = 0; i < size; i++) {
+ File current = files[i];
+ if (current.isFile()) {
+ if (!current.delete()) {
+ status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, files[i].getAbsolutePath()), null));
+ deleteCurrent = false;
+ }
+ monitor.worked(10);
+ } else if (current.isDirectory()) {
+ monitor.subTask(NLS.bind(Messages.deletingTask, new String[] {current.getAbsolutePath()}));
+ IStatus[] stat = deleteDirectory(current, ProgressUtil.getSubMonitorFor(monitor, 10));
+ if (stat != null && stat.length > 0) {
+ deleteCurrent = false;
+ addArrayToList(status, stat);
+ }
+ }
+ }
+ if (deleteCurrent && !dir.delete())
+ status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, dir.getAbsolutePath()), null));
+ monitor.done();
+ } catch (Exception e) {
+ Trace.trace(Trace.SEVERE, "Error deleting directory " + dir.getAbsolutePath(), e);
+ status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, e.getLocalizedMessage(), null));
+ }
+
+ IStatus[] stat = new IStatus[status.size()];
+ status.toArray(stat);
+ return stat;
+ }
+
+ /**
+ * Smart copy the given module resources to the given path.
+ *
+ * @param resources an array of module resources
+ * @param path an external path to copy to
+ * @param monitor a progress monitor, or <code>null</code> if progress
+ * reporting and cancellation are not desired
+ * @return a possibly-empty array of error and warning status
+ */
+ public IStatus[] publishSmart(IModuleResource[] resources, IPath path, IProgressMonitor monitor) {
+ if (resources == null)
+ return EMPTY_STATUS;
+
+ monitor = ProgressUtil.getMonitorFor(monitor);
+
+ List status = new ArrayList(2);
+ File toDir = path.toFile();
+ int fromSize = resources.length;
+ String[] fromFileNames = new String[fromSize];
+ for (int i = 0; i < fromSize; i++)
+ fromFileNames[i] = resources[i].getName();
+
+ // cache files and file names for performance
+ File[] toFiles = null;
+ String[] toFileNames = null;
+
+ boolean foundExistingDir = false;
+ if (toDir.exists()) {
+ if (toDir.isDirectory()) {
+ foundExistingDir = true;
+ toFiles = toDir.listFiles();
+ int toSize = toFiles.length;
+ toFileNames = new String[toSize];
+
+ // check if this exact file exists in the new directory
+ for (int i = 0; i < toSize; i++) {
+ toFileNames[i] = toFiles[i].getName();
+ boolean isDir = toFiles[i].isDirectory();
+ boolean found = false;
+ for (int j = 0; j < fromSize; j++) {
+ if (toFileNames[i].equals(fromFileNames[j]) && isDir == resources[j] instanceof IModuleFolder)
+ found = true;
+ }
+
+ // delete file if it can't be found or isn't the correct type
+ if (!found) {
+ if (isDir) {
+ IStatus[] stat = deleteDirectory(toFiles[i], null);
+ addArrayToList(status, stat);
+ } else {
+ if (!toFiles[i].delete())
+ status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, toFiles[i].getAbsolutePath()), null));
+ }
+ toFiles[i] = null;
+ toFileNames[i] = null;
+ }
+ }
+ } else { //if (toDir.isFile())
+ if (!toDir.delete()) {
+ status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, toDir.getAbsolutePath()), null));
+ IStatus[] stat = new IStatus[status.size()];
+ status.toArray(stat);
+ return stat;
+ }
+ }
+ }
+ if (!foundExistingDir && !toDir.mkdirs()) {
+ status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorMkdir, toDir.getAbsolutePath()), null));
+ IStatus[] stat = new IStatus[status.size()];
+ status.toArray(stat);
+ return stat;
+ }
+
+ if (monitor.isCanceled())
+ return new IStatus[] { Status.CANCEL_STATUS };
+
+ monitor.worked(50);
+
+ // cycle through files and only copy when it doesn't exist
+ // or is newer
+ if (toFiles == null)
+ toFiles = toDir.listFiles();
+ int toSize = 0;
+ if (toFiles != null)
+ toSize = toFiles.length;
+
+ int dw = 0;
+ if (toSize > 0)
+ dw = 500 / toSize;
+
+ // cache file names and last modified dates for performance
+ if (toFileNames == null)
+ toFileNames = new String[toSize];
+ long[] toFileMod = new long[toSize];
+ for (int i = 0; i < toSize; i++) {
+ if (toFiles[i] != null) {
+ if (toFileNames[i] != null)
+ toFileNames[i] = toFiles[i].getName();
+ toFileMod[i] = toFiles[i].lastModified();
+ }
+ }
+
+ for (int i = 0; i < fromSize; i++) {
+ IModuleResource current = resources[i];
+ String name = fromFileNames[i];
+ boolean currentIsDir = current instanceof IModuleFolder;
+
+ if (!currentIsDir) {
+ // check if this is a new or newer file
+ boolean copy = true;
+ IModuleFile mf = (IModuleFile) current;
+
+ long mod = -1;
+ IFile file = (IFile) mf.getAdapter(IFile.class);
+ if (file != null) {
+ mod = file.getLocalTimeStamp();
+ } else {
+ File file2 = (File) mf.getAdapter(File.class);
+ mod = file2.lastModified();
+ }
+
+ for (int j = 0; j < toSize; j++) {
+ if (name.equals(toFileNames[j]) && mod == toFileMod[j])
+ copy = false;
+ }
+
+ if (copy) {
+ try {
+ copyFile(mf, path.append(name));
+ } catch (CoreException ce) {
+ status.add(ce.getStatus());
+ }
+ }
+ monitor.worked(dw);
+ } else { //if (currentIsDir) {
+ IModuleFolder folder = (IModuleFolder) current;
+ IModuleResource[] children = folder.members();
+ monitor.subTask(NLS.bind(Messages.copyingTask, new String[] {name, name}));
+ IStatus[] stat = publishSmart(children, path.append(name), ProgressUtil.getSubMonitorFor(monitor, dw));
+ addArrayToList(status, stat);
+ }
+ }
+ if (monitor.isCanceled())
+ return new IStatus[] { Status.CANCEL_STATUS };
+
+ monitor.worked(500 - dw * toSize);
+ monitor.done();
+
+ IStatus[] stat = new IStatus[status.size()];
+ status.toArray(stat);
+ return stat;
+ }
+
+ /**
+ * Handle a delta publish.
+ *
+ * @param delta a module resource delta
+ * @param path the path to publish to
+ * @param monitor a progress monitor, or <code>null</code> if progress
+ * reporting and cancellation are not desired
+ * @return a possibly-empty array of error and warning status
+ */
+ public IStatus[] publishDelta(IModuleResourceDelta[] delta, IPath path, IProgressMonitor monitor) {
+ if (delta == null)
+ return EMPTY_STATUS;
+
+ monitor = ProgressUtil.getMonitorFor(monitor);
+
+ List status = new ArrayList(2);
+ int size2 = delta.length;
+ for (int i = 0; i < size2; i++) {
+ IStatus[] stat = publishDelta(delta[i], path, monitor);
+ addArrayToList(status, stat);
+ }
+
+ IStatus[] stat = new IStatus[status.size()];
+ status.toArray(stat);
+ return stat;
+ }
+
+ /**
+ * Handle a delta publish.
+ *
+ * @param delta a module resource delta
+ * @param path the path to publish to
+ * @param monitor a progress monitor, or <code>null</code> if progress
+ * reporting and cancellation are not desired
+ * @return a possibly-empty array of error and warning status
+ */
+ public IStatus[] publishDelta(IModuleResourceDelta delta, IPath path, IProgressMonitor monitor) {
+ List status = new ArrayList(2);
+
+ IModuleResource resource = delta.getModuleResource();
+ int kind2 = delta.getKind();
+
+ if (resource instanceof IModuleFile) {
+ IModuleFile file = (IModuleFile) resource;
+ try {
+ if (kind2 == IModuleResourceDelta.REMOVED)
+ deleteFile2(path, file);
+ else {
+ IPath path2 = path.append(file.getModuleRelativePath()).append(file.getName());
+ File f = path2.toFile().getParentFile();
+ if (!f.exists())
+ f.mkdirs();
+
+ copyFile(file, path2);
+ }
+ } catch (CoreException ce) {
+ status.add(ce.getStatus());
+ }
+ IStatus[] stat = new IStatus[status.size()];
+ status.toArray(stat);
+ return stat;
+ }
+
+ if (kind2 == IModuleResourceDelta.ADDED) {
+ IPath path2 = path.append(resource.getModuleRelativePath()).append(resource.getName());
+ File file = path2.toFile();
+ if (!file.exists() && !file.mkdirs()) {
+ status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorMkdir, path2), null));
+ IStatus[] stat = new IStatus[status.size()];
+ status.toArray(stat);
+ return stat;
+ }
+ }
+
+ IModuleResourceDelta[] childDeltas = delta.getAffectedChildren();
+ int size = childDeltas.length;
+ for (int i = 0; i < size; i++) {
+ IStatus[] stat = publishDelta(childDeltas[i], path, monitor);
+ addArrayToList(status, stat);
+ }
+
+ if (kind2 == IModuleResourceDelta.REMOVED) {
+ IPath path2 = path.append(resource.getModuleRelativePath()).append(resource.getName());
+ File file = path2.toFile();
+ if (file.exists() && !file.delete()) {
+ status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, path2), null));
+ }
+ }
+
+ IStatus[] stat = new IStatus[status.size()];
+ status.toArray(stat);
+ return stat;
+ }
+
+ private void deleteFile2(IPath path, IModuleFile file) throws CoreException {
+ Trace.trace(Trace.PUBLISHING, "Deleting: " + file.getName() + " from " + path.toString());
+ IPath path2 = path.append(file.getModuleRelativePath()).append(file.getName());
+ if (path2.toFile().exists() && !path2.toFile().delete())
+ throw new CoreException(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, path2), null));
+ }
+
+ private void copyFile(IModuleFile mf, IPath path) throws CoreException {
+ Trace.trace(Trace.PUBLISHING, "Copying: " + mf.getName() + " to " + path.toString());
+
+ IFile file = (IFile) mf.getAdapter(IFile.class);
+ if (file != null)
+ copyFile(file.getContents(), path, file.getLocalTimeStamp(), mf);
+ else {
+ File file2 = (File) mf.getAdapter(File.class);
+ InputStream in = null;
+ try {
+ in = new FileInputStream(file2);
+ } catch (IOException e) {
+ throw new CoreException(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorReading, file2.getAbsolutePath()), e));
+ }
+ copyFile(in, path, file2.lastModified(), mf);
+ }
+ }
+
+ /**
+ * Publish the given module resources to the given path.
+ *
+ * @param resources an array of module resources
+ * @param path a path to publish to
+ * @param monitor a progress monitor, or <code>null</code> if progress
+ * reporting and cancellation are not desired
+ * @return a possibly-empty array of error and warning status
+ */
+ public IStatus[] publishFull(IModuleResource[] resources, IPath path, IProgressMonitor monitor) {
+ if (resources == null)
+ return EMPTY_STATUS;
+
+ monitor = ProgressUtil.getMonitorFor(monitor);
+
+ List status = new ArrayList(2);
+ int size = resources.length;
+ for (int i = 0; i < size; i++) {
+ IStatus[] stat = copy(resources[i], path, monitor);
+ addArrayToList(status, stat);
+ }
+
+ IStatus[] stat = new IStatus[status.size()];
+ status.toArray(stat);
+ return stat;
+ }
+
+ private IStatus[] copy(IModuleResource resource, IPath path, IProgressMonitor monitor) {
+ String name = resource.getName();
+ Trace.trace(Trace.PUBLISHING, "Copying: " + name + " to " + path.toString());
+ List status = new ArrayList(2);
+ if (resource instanceof IModuleFolder) {
+ IModuleFolder folder = (IModuleFolder) resource;
+ IStatus[] stat = publishFull(folder.members(), path, monitor);
+ addArrayToList(status, stat);
+ } else {
+ IModuleFile mf = (IModuleFile) resource;
+ path = path.append(mf.getModuleRelativePath()).append(name);
+ File f = path.toFile().getParentFile();
+ if (!f.exists())
+ f.mkdirs();
+ try {
+ copyFile(mf, path);
+ } catch (CoreException ce) {
+ status.add(ce.getStatus());
+ }
+ }
+ IStatus[] stat = new IStatus[status.size()];
+ status.toArray(stat);
+ return stat;
+ }
+
+ /**
+ * Creates a new zip file containing the given module resources. Deletes the existing file
+ * (and doesn't create a new one) if resources is null or empty.
+ *
+ * @param resources an array of module resources
+ * @param path the path where the zip file should be created
+ * @param monitor a progress monitor, or <code>null</code> if progress
+ * reporting and cancellation are not desired
+ * @return a possibly-empty array of error and warning status
+ */
+ public IStatus[] publishZip(IModuleResource[] resources, IPath path, IProgressMonitor monitor) {
+ if (resources == null || resources.length == 0) {
+ // should also check if resources consists of all empty directories
+ File file = path.toFile();
+ if (file.exists())
+ file.delete();
+ return EMPTY_STATUS;
+ }
+
+ monitor = ProgressUtil.getMonitorFor(monitor);
+
+ File tempFile = null;
+ try {
+ File file = path.toFile();
+ tempFile = File.createTempFile(TEMPFILE_PREFIX, "." + path.getFileExtension(), getTempFolder());
+ BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(tempFile));
+ ZipOutputStream zout = new ZipOutputStream(bout);
+ addZipEntries(zout, resources);
+ zout.close();
+
+ moveTempFile(tempFile, file);
+ } catch (CoreException e) {
+ return new IStatus[] { e.getStatus() };
+ } catch (Exception e) {
+ Trace.trace(Trace.SEVERE, "Error zipping", e);
+ return new Status[] { new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCreatingZipFile, path.lastSegment(), e.getLocalizedMessage()), e) };
+ } finally {
+ if (tempFile != null && tempFile.exists())
+ tempFile.deleteOnExit();
+ }
+ return EMPTY_STATUS;
+ }
+
+ private void addZipEntries(ZipOutputStream zout, IModuleResource[] resources) throws Exception {
+ if (resources == null)
+ return;
+
+ int size = resources.length;
+ for (int i = 0; i < size; i++) {
+ if (resources[i] instanceof IModuleFolder) {
+ IModuleFolder mf = (IModuleFolder) resources[i];
+ IModuleResource[] res = mf.members();
+
+ IPath path = mf.getModuleRelativePath().append(mf.getName());
+ String entryPath = path.toPortableString();
+ if (!entryPath.endsWith("/"))
+ entryPath += '/';
+
+ ZipEntry ze = new ZipEntry(entryPath);
+
+ long ts = 0;
+ IContainer folder = (IContainer) mf.getAdapter(IContainer.class);
+ if (folder != null)
+ ts = folder.getLocalTimeStamp();
+
+ if (ts != IResource.NULL_STAMP && ts != 0)
+ ze.setTime(ts);
+
+ zout.putNextEntry(ze);
+ zout.closeEntry();
+
+ addZipEntries(zout, res);
+ continue;
+ }
+
+ IModuleFile mf = (IModuleFile) resources[i];
+ IPath path = mf.getModuleRelativePath().append(mf.getName());
+
+ ZipEntry ze = new ZipEntry(path.toPortableString());
+
+ InputStream in = null;
+ long ts = 0;
+ IFile file = (IFile) mf.getAdapter(IFile.class);
+ if (file != null) {
+ ts = file.getLocalTimeStamp();
+ in = file.getContents();
+ } else {
+ File file2 = (File) mf.getAdapter(File.class);
+ ts = file2.lastModified();
+ in = new FileInputStream(file2);
+ }
+
+ if (ts != IResource.NULL_STAMP && ts != 0)
+ ze.setTime(ts);
+
+ zout.putNextEntry(ze);
+
+ try {
+ int n = 0;
+ while (n > -1) {
+ n = in.read(buf);
+ if (n > 0)
+ zout.write(buf, 0, n);
+ }
+ } finally {
+ in.close();
+ }
+
+ zout.closeEntry();
+ }
+ }
+
+ /**
+ * Utility method to move a temp file into position by deleting the original and
+ * swapping in a new copy.
+ *
+ * @param tempFile
+ * @param file
+ * @throws CoreException
+ */
+ private void moveTempFile(File tempFile, File file) throws CoreException {
+ if (file.exists()) {
+ if (!safeDelete(file, 2)) {
+ // attempt to rewrite an existing file with the tempFile contents if
+ // the existing file can't be deleted to permit the move
+ try {
+ InputStream in = new FileInputStream(tempFile);
+ IStatus status = copyFile(in, file.getPath());
+ if (!status.isOK()) {
+ MultiStatus status2 = new MultiStatus(ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, file.toString()), null);
+ status2.add(status);
+ throw new CoreException(status2);
+ }
+ return;
+ } catch (FileNotFoundException e) {
+ // shouldn't occur
+ } finally {
+ tempFile.delete();
+ }
+ /*if (!safeDelete(file, 8)) {
+ tempFile.delete();
+ throw new CoreException(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, file.toString()), null));
+ }*/
+ }
+ }
+ if (!safeRename(tempFile, file, 10))
+ throw new CoreException(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorRename, tempFile.toString()), null));
+ }
+
+ /**
+ * Copy a file from a to b. Closes the input stream after use.
+ *
+ * @param in java.io.InputStream
+ * @param to java.lang.String
+ * @return a status
+ */
+ private IStatus copyFile(InputStream in, String to) {
+ OutputStream out = null;
+
+ try {
+ out = new FileOutputStream(to);
+
+ int avail = in.read(buf);
+ while (avail > 0) {
+ out.write(buf, 0, avail);
+ avail = in.read(buf);
+ }
+ return Status.OK_STATUS;
+ } catch (Exception e) {
+ Trace.trace(Trace.SEVERE, "Error copying file", e);
+ return new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCopyingFile, new String[] {to, e.getLocalizedMessage()}), e);
+ } finally {
+ try {
+ if (in != null)
+ in.close();
+ } catch (Exception ex) {
+ // ignore
+ }
+ try {
+ if (out != null)
+ out.close();
+ } catch (Exception ex) {
+ // ignore
+ }
+ }
+ }
+
+ /**
+ * Safe delete. Tries to delete multiple times before giving up.
+ *
+ * @param f
+ * @return <code>true</code> if it succeeds, <code>false</code> otherwise
+ */
+ private boolean safeDelete(File f, int retrys) {
+ int count = 0;
+ while (count < retrys) {
+ if (!f.exists())
+ return true;
+
+ f.delete();
+
+ if (!f.exists())
+ return true;
+
+ count++;
+ // delay if we are going to try again
+ if (count < retrys) {
+ try {
+ Thread.sleep(100);
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Safe rename. Will try multiple times before giving up.
+ *
+ * @param from
+ * @param to
+ * @param retrys number of times to retry
+ * @return <code>true</code> if it succeeds, <code>false</code> otherwise
+ */
+ private boolean safeRename(File from, File to, int retrys) {
+ // make sure parent dir exists
+ File dir = to.getParentFile();
+ if (dir != null && !dir.exists())
+ dir.mkdirs();
+
+ int count = 0;
+ while (count < retrys) {
+ if (from.renameTo(to))
+ return true;
+
+ count++;
+ // delay if we are going to try again
+ if (count < retrys) {
+ try {
+ Thread.sleep(100);
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ }
+ return false;
+ }
+
+ private void addArrayToList(List list, IStatus[] a) {
+ if (list == null || a == null || a.length == 0)
+ return;
+
+ int size = a.length;
+ for (int i = 0; i < size; i++)
+ list.add(a[i]);
+ }
+
+ protected File getTempFolder() {
+ if( server == null ) return tempDir;
+ String path = ServerConverter.getDeployableServer(server).getTempDeployFolder();
+ File f = new File(path);
+ if( !f.exists() )
+ f.mkdirs();
+ return new File(path);
+ }
+}
\ No newline at end of file
Deleted: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishUtil.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishUtil.java 2009-04-16 07:48:52 UTC (rev 14767)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishUtil.java 2009-04-16 09:22:04 UTC (rev 14768)
@@ -1,782 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are 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:
- * IBM Corporation - Initial API and implementation
- *******************************************************************************/
-package org.jboss.ide.eclipse.as.core.server.xpl;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-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.Status;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.internal.Messages;
-import org.eclipse.wst.server.core.internal.ProgressUtil;
-import org.eclipse.wst.server.core.internal.ServerPlugin;
-import org.eclipse.wst.server.core.internal.Trace;
-import org.eclipse.wst.server.core.model.IModuleFile;
-import org.eclipse.wst.server.core.model.IModuleFolder;
-import org.eclipse.wst.server.core.model.IModuleResource;
-import org.eclipse.wst.server.core.model.IModuleResourceDelta;
-import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
-import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
-import org.jboss.ide.eclipse.as.core.util.ServerConverter;
-/**
- * Utility class with an assortment of useful file methods.
- * <p>
- * This class provides all its functionality through static members.
- * It is not intended to be subclassed or instantiated.
- * </p>
- * <p>
- * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
- * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
- * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
- * (repeatedly) as the API evolves.
- * </p>
- * @since 2.0
- */
-public final class PublishUtil {
- // size of the buffer
- private static final int BUFFER = 65536;
-
- // the buffer
- private static byte[] buf = new byte[BUFFER];
-
- private static final IStatus[] EMPTY_STATUS = new IStatus[0];
-
- private static final File tempDir = ServerPlugin.getInstance().getStateLocation().toFile();
-
- private static final String TEMPFILE_PREFIX = "tmp";
-
- /**
- * PublishUtil cannot be created. Use static methods.
- */
- private IServer server;
- public PublishUtil(IServer server) {
- this.server = server;
- }
-
- /**
- * Copy a file from a to b. Closes the input stream after use.
- *
- * @param in an input stream
- * @param to a path to copy to. the directory must already exist
- * @param ts timestamp
- * @throws CoreException if anything goes wrong
- */
- private void copyFile(InputStream in, IPath to, long ts, IModuleFile mf) throws CoreException {
- OutputStream out = null;
-
- File tempFile = null;
- try {
- File file = to.toFile();
-
- // Change from original PublishUtil, will require
- tempFile = File.createTempFile(TEMPFILE_PREFIX, "." + to.getFileExtension(), getTempFolder());
-
- out = new FileOutputStream(tempFile);
-
- int avail = in.read(buf);
- while (avail > 0) {
- out.write(buf, 0, avail);
- avail = in.read(buf);
- }
-
- out.close();
- out = null;
-
- moveTempFile(tempFile, file);
-
- if (ts != IResource.NULL_STAMP && ts != 0)
- file.setLastModified(ts);
- } catch (CoreException e) {
- throw e;
- } catch (Exception e) {
- IPath path = mf.getModuleRelativePath().append(mf.getName());
- Trace.trace(Trace.SEVERE, "Error copying file: " + to.toOSString() + " to " + path.toOSString(), e);
- throw new CoreException(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCopyingFile, path.toOSString(), e.getLocalizedMessage()), null));
- } finally {
- if (tempFile != null && tempFile.exists())
- tempFile.deleteOnExit();
- try {
- if (in != null)
- in.close();
- } catch (Exception ex) {
- // ignore
- }
- try {
- if (out != null)
- out.close();
- } catch (Exception ex) {
- // ignore
- }
- }
- }
-
- /**
- * Utility method to recursively delete a directory.
- *
- * @param dir a directory
- * @param monitor a progress monitor, or <code>null</code> if progress
- * reporting and cancellation are not desired
- * @return a possibly-empty array of error and warning status
- */
- public IStatus[] deleteDirectory(File dir, IProgressMonitor monitor) {
- if (!dir.exists() || !dir.isDirectory())
- return new IStatus[] { new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorNotADirectory, dir.getAbsolutePath()), null) };
-
- List status = new ArrayList(2);
-
- try {
- File[] files = dir.listFiles();
- int size = files.length;
- monitor = ProgressUtil.getMonitorFor(monitor);
- monitor.beginTask(NLS.bind(Messages.deletingTask, new String[] { dir.getAbsolutePath() }), size * 10);
-
- // cycle through files
- boolean deleteCurrent = true;
- for (int i = 0; i < size; i++) {
- File current = files[i];
- if (current.isFile()) {
- if (!current.delete()) {
- status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, files[i].getAbsolutePath()), null));
- deleteCurrent = false;
- }
- monitor.worked(10);
- } else if (current.isDirectory()) {
- monitor.subTask(NLS.bind(Messages.deletingTask, new String[] {current.getAbsolutePath()}));
- IStatus[] stat = deleteDirectory(current, ProgressUtil.getSubMonitorFor(monitor, 10));
- if (stat != null && stat.length > 0) {
- deleteCurrent = false;
- addArrayToList(status, stat);
- }
- }
- }
- if (deleteCurrent && !dir.delete())
- status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, dir.getAbsolutePath()), null));
- monitor.done();
- } catch (Exception e) {
- Trace.trace(Trace.SEVERE, "Error deleting directory " + dir.getAbsolutePath(), e);
- status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, e.getLocalizedMessage(), null));
- }
-
- IStatus[] stat = new IStatus[status.size()];
- status.toArray(stat);
- return stat;
- }
-
- /**
- * Smart copy the given module resources to the given path.
- *
- * @param resources an array of module resources
- * @param path an external path to copy to
- * @param monitor a progress monitor, or <code>null</code> if progress
- * reporting and cancellation are not desired
- * @return a possibly-empty array of error and warning status
- */
- public IStatus[] publishSmart(IModuleResource[] resources, IPath path, IProgressMonitor monitor) {
- if (resources == null)
- return EMPTY_STATUS;
-
- monitor = ProgressUtil.getMonitorFor(monitor);
-
- List status = new ArrayList(2);
- File toDir = path.toFile();
- int fromSize = resources.length;
- String[] fromFileNames = new String[fromSize];
- for (int i = 0; i < fromSize; i++)
- fromFileNames[i] = resources[i].getName();
-
- // cache files and file names for performance
- File[] toFiles = null;
- String[] toFileNames = null;
-
- boolean foundExistingDir = false;
- if (toDir.exists()) {
- if (toDir.isDirectory()) {
- foundExistingDir = true;
- toFiles = toDir.listFiles();
- int toSize = toFiles.length;
- toFileNames = new String[toSize];
-
- // check if this exact file exists in the new directory
- for (int i = 0; i < toSize; i++) {
- toFileNames[i] = toFiles[i].getName();
- boolean isDir = toFiles[i].isDirectory();
- boolean found = false;
- for (int j = 0; j < fromSize; j++) {
- if (toFileNames[i].equals(fromFileNames[j]) && isDir == resources[j] instanceof IModuleFolder)
- found = true;
- }
-
- // delete file if it can't be found or isn't the correct type
- if (!found) {
- if (isDir) {
- IStatus[] stat = deleteDirectory(toFiles[i], null);
- addArrayToList(status, stat);
- } else {
- if (!toFiles[i].delete())
- status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, toFiles[i].getAbsolutePath()), null));
- }
- toFiles[i] = null;
- toFileNames[i] = null;
- }
- }
- } else { //if (toDir.isFile())
- if (!toDir.delete()) {
- status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, toDir.getAbsolutePath()), null));
- IStatus[] stat = new IStatus[status.size()];
- status.toArray(stat);
- return stat;
- }
- }
- }
- if (!foundExistingDir && !toDir.mkdirs()) {
- status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorMkdir, toDir.getAbsolutePath()), null));
- IStatus[] stat = new IStatus[status.size()];
- status.toArray(stat);
- return stat;
- }
-
- if (monitor.isCanceled())
- return new IStatus[] { Status.CANCEL_STATUS };
-
- monitor.worked(50);
-
- // cycle through files and only copy when it doesn't exist
- // or is newer
- if (toFiles == null)
- toFiles = toDir.listFiles();
- int toSize = 0;
- if (toFiles != null)
- toSize = toFiles.length;
-
- int dw = 0;
- if (toSize > 0)
- dw = 500 / toSize;
-
- // cache file names and last modified dates for performance
- if (toFileNames == null)
- toFileNames = new String[toSize];
- long[] toFileMod = new long[toSize];
- for (int i = 0; i < toSize; i++) {
- if (toFiles[i] != null) {
- if (toFileNames[i] != null)
- toFileNames[i] = toFiles[i].getName();
- toFileMod[i] = toFiles[i].lastModified();
- }
- }
-
- for (int i = 0; i < fromSize; i++) {
- IModuleResource current = resources[i];
- String name = fromFileNames[i];
- boolean currentIsDir = current instanceof IModuleFolder;
-
- if (!currentIsDir) {
- // check if this is a new or newer file
- boolean copy = true;
- IModuleFile mf = (IModuleFile) current;
-
- long mod = -1;
- IFile file = (IFile) mf.getAdapter(IFile.class);
- if (file != null) {
- mod = file.getLocalTimeStamp();
- } else {
- File file2 = (File) mf.getAdapter(File.class);
- mod = file2.lastModified();
- }
-
- for (int j = 0; j < toSize; j++) {
- if (name.equals(toFileNames[j]) && mod == toFileMod[j])
- copy = false;
- }
-
- if (copy) {
- try {
- copyFile(mf, path.append(name));
- } catch (CoreException ce) {
- status.add(ce.getStatus());
- }
- }
- monitor.worked(dw);
- } else { //if (currentIsDir) {
- IModuleFolder folder = (IModuleFolder) current;
- IModuleResource[] children = folder.members();
- monitor.subTask(NLS.bind(Messages.copyingTask, new String[] {name, name}));
- IStatus[] stat = publishSmart(children, path.append(name), ProgressUtil.getSubMonitorFor(monitor, dw));
- addArrayToList(status, stat);
- }
- }
- if (monitor.isCanceled())
- return new IStatus[] { Status.CANCEL_STATUS };
-
- monitor.worked(500 - dw * toSize);
- monitor.done();
-
- IStatus[] stat = new IStatus[status.size()];
- status.toArray(stat);
- return stat;
- }
-
- /**
- * Handle a delta publish.
- *
- * @param delta a module resource delta
- * @param path the path to publish to
- * @param monitor a progress monitor, or <code>null</code> if progress
- * reporting and cancellation are not desired
- * @return a possibly-empty array of error and warning status
- */
- public IStatus[] publishDelta(IModuleResourceDelta[] delta, IPath path, IProgressMonitor monitor) {
- if (delta == null)
- return EMPTY_STATUS;
-
- monitor = ProgressUtil.getMonitorFor(monitor);
-
- List status = new ArrayList(2);
- int size2 = delta.length;
- for (int i = 0; i < size2; i++) {
- IStatus[] stat = publishDelta(delta[i], path, monitor);
- addArrayToList(status, stat);
- }
-
- IStatus[] stat = new IStatus[status.size()];
- status.toArray(stat);
- return stat;
- }
-
- /**
- * Handle a delta publish.
- *
- * @param delta a module resource delta
- * @param path the path to publish to
- * @param monitor a progress monitor, or <code>null</code> if progress
- * reporting and cancellation are not desired
- * @return a possibly-empty array of error and warning status
- */
- public IStatus[] publishDelta(IModuleResourceDelta delta, IPath path, IProgressMonitor monitor) {
- List status = new ArrayList(2);
-
- IModuleResource resource = delta.getModuleResource();
- int kind2 = delta.getKind();
-
- if (resource instanceof IModuleFile) {
- IModuleFile file = (IModuleFile) resource;
- try {
- if (kind2 == IModuleResourceDelta.REMOVED)
- deleteFile2(path, file);
- else {
- IPath path2 = path.append(file.getModuleRelativePath()).append(file.getName());
- File f = path2.toFile().getParentFile();
- if (!f.exists())
- f.mkdirs();
-
- copyFile(file, path2);
- }
- } catch (CoreException ce) {
- status.add(ce.getStatus());
- }
- IStatus[] stat = new IStatus[status.size()];
- status.toArray(stat);
- return stat;
- }
-
- if (kind2 == IModuleResourceDelta.ADDED) {
- IPath path2 = path.append(resource.getModuleRelativePath()).append(resource.getName());
- File file = path2.toFile();
- if (!file.exists() && !file.mkdirs()) {
- status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorMkdir, path2), null));
- IStatus[] stat = new IStatus[status.size()];
- status.toArray(stat);
- return stat;
- }
- }
-
- IModuleResourceDelta[] childDeltas = delta.getAffectedChildren();
- int size = childDeltas.length;
- for (int i = 0; i < size; i++) {
- IStatus[] stat = publishDelta(childDeltas[i], path, monitor);
- addArrayToList(status, stat);
- }
-
- if (kind2 == IModuleResourceDelta.REMOVED) {
- IPath path2 = path.append(resource.getModuleRelativePath()).append(resource.getName());
- File file = path2.toFile();
- if (file.exists() && !file.delete()) {
- status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, path2), null));
- }
- }
-
- IStatus[] stat = new IStatus[status.size()];
- status.toArray(stat);
- return stat;
- }
-
- private void deleteFile2(IPath path, IModuleFile file) throws CoreException {
- Trace.trace(Trace.PUBLISHING, "Deleting: " + file.getName() + " from " + path.toString());
- IPath path2 = path.append(file.getModuleRelativePath()).append(file.getName());
- if (path2.toFile().exists() && !path2.toFile().delete())
- throw new CoreException(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, path2), null));
- }
-
- private void copyFile(IModuleFile mf, IPath path) throws CoreException {
- Trace.trace(Trace.PUBLISHING, "Copying: " + mf.getName() + " to " + path.toString());
-
- IFile file = (IFile) mf.getAdapter(IFile.class);
- if (file != null)
- copyFile(file.getContents(), path, file.getLocalTimeStamp(), mf);
- else {
- File file2 = (File) mf.getAdapter(File.class);
- InputStream in = null;
- try {
- in = new FileInputStream(file2);
- } catch (IOException e) {
- throw new CoreException(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorReading, file2.getAbsolutePath()), e));
- }
- copyFile(in, path, file2.lastModified(), mf);
- }
- }
-
- /**
- * Publish the given module resources to the given path.
- *
- * @param resources an array of module resources
- * @param path a path to publish to
- * @param monitor a progress monitor, or <code>null</code> if progress
- * reporting and cancellation are not desired
- * @return a possibly-empty array of error and warning status
- */
- public IStatus[] publishFull(IModuleResource[] resources, IPath path, IProgressMonitor monitor) {
- if (resources == null)
- return EMPTY_STATUS;
-
- monitor = ProgressUtil.getMonitorFor(monitor);
-
- List status = new ArrayList(2);
- int size = resources.length;
- for (int i = 0; i < size; i++) {
- IStatus[] stat = copy(resources[i], path, monitor);
- addArrayToList(status, stat);
- }
-
- IStatus[] stat = new IStatus[status.size()];
- status.toArray(stat);
- return stat;
- }
-
- private IStatus[] copy(IModuleResource resource, IPath path, IProgressMonitor monitor) {
- String name = resource.getName();
- Trace.trace(Trace.PUBLISHING, "Copying: " + name + " to " + path.toString());
- List status = new ArrayList(2);
- if (resource instanceof IModuleFolder) {
- IModuleFolder folder = (IModuleFolder) resource;
- IStatus[] stat = publishFull(folder.members(), path, monitor);
- addArrayToList(status, stat);
- } else {
- IModuleFile mf = (IModuleFile) resource;
- path = path.append(mf.getModuleRelativePath()).append(name);
- File f = path.toFile().getParentFile();
- if (!f.exists())
- f.mkdirs();
- try {
- copyFile(mf, path);
- } catch (CoreException ce) {
- status.add(ce.getStatus());
- }
- }
- IStatus[] stat = new IStatus[status.size()];
- status.toArray(stat);
- return stat;
- }
-
- /**
- * Creates a new zip file containing the given module resources. Deletes the existing file
- * (and doesn't create a new one) if resources is null or empty.
- *
- * @param resources an array of module resources
- * @param path the path where the zip file should be created
- * @param monitor a progress monitor, or <code>null</code> if progress
- * reporting and cancellation are not desired
- * @return a possibly-empty array of error and warning status
- */
- public IStatus[] publishZip(IModuleResource[] resources, IPath path, IProgressMonitor monitor) {
- if (resources == null || resources.length == 0) {
- // should also check if resources consists of all empty directories
- File file = path.toFile();
- if (file.exists())
- file.delete();
- return EMPTY_STATUS;
- }
-
- monitor = ProgressUtil.getMonitorFor(monitor);
-
- File tempFile = null;
- try {
- File file = path.toFile();
- tempFile = File.createTempFile(TEMPFILE_PREFIX, "." + path.getFileExtension(), getTempFolder());
- BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(tempFile));
- ZipOutputStream zout = new ZipOutputStream(bout);
- addZipEntries(zout, resources);
- zout.close();
-
- moveTempFile(tempFile, file);
- } catch (CoreException e) {
- return new IStatus[] { e.getStatus() };
- } catch (Exception e) {
- Trace.trace(Trace.SEVERE, "Error zipping", e);
- return new Status[] { new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCreatingZipFile, path.lastSegment(), e.getLocalizedMessage()), e) };
- } finally {
- if (tempFile != null && tempFile.exists())
- tempFile.deleteOnExit();
- }
- return EMPTY_STATUS;
- }
-
- private void addZipEntries(ZipOutputStream zout, IModuleResource[] resources) throws Exception {
- if (resources == null)
- return;
-
- int size = resources.length;
- for (int i = 0; i < size; i++) {
- if (resources[i] instanceof IModuleFolder) {
- IModuleFolder mf = (IModuleFolder) resources[i];
- IModuleResource[] res = mf.members();
-
- IPath path = mf.getModuleRelativePath().append(mf.getName());
- String entryPath = path.toPortableString();
- if (!entryPath.endsWith("/"))
- entryPath += '/';
-
- ZipEntry ze = new ZipEntry(entryPath);
-
- long ts = 0;
- IContainer folder = (IContainer) mf.getAdapter(IContainer.class);
- if (folder != null)
- ts = folder.getLocalTimeStamp();
-
- if (ts != IResource.NULL_STAMP && ts != 0)
- ze.setTime(ts);
-
- zout.putNextEntry(ze);
- zout.closeEntry();
-
- addZipEntries(zout, res);
- continue;
- }
-
- IModuleFile mf = (IModuleFile) resources[i];
- IPath path = mf.getModuleRelativePath().append(mf.getName());
-
- ZipEntry ze = new ZipEntry(path.toPortableString());
-
- InputStream in = null;
- long ts = 0;
- IFile file = (IFile) mf.getAdapter(IFile.class);
- if (file != null) {
- ts = file.getLocalTimeStamp();
- in = file.getContents();
- } else {
- File file2 = (File) mf.getAdapter(File.class);
- ts = file2.lastModified();
- in = new FileInputStream(file2);
- }
-
- if (ts != IResource.NULL_STAMP && ts != 0)
- ze.setTime(ts);
-
- zout.putNextEntry(ze);
-
- try {
- int n = 0;
- while (n > -1) {
- n = in.read(buf);
- if (n > 0)
- zout.write(buf, 0, n);
- }
- } finally {
- in.close();
- }
-
- zout.closeEntry();
- }
- }
-
- /**
- * Utility method to move a temp file into position by deleting the original and
- * swapping in a new copy.
- *
- * @param tempFile
- * @param file
- * @throws CoreException
- */
- private void moveTempFile(File tempFile, File file) throws CoreException {
- if (file.exists()) {
- if (!safeDelete(file, 2)) {
- // attempt to rewrite an existing file with the tempFile contents if
- // the existing file can't be deleted to permit the move
- try {
- InputStream in = new FileInputStream(tempFile);
- IStatus status = copyFile(in, file.getPath());
- if (!status.isOK()) {
- MultiStatus status2 = new MultiStatus(ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, file.toString()), null);
- status2.add(status);
- throw new CoreException(status2);
- }
- return;
- } catch (FileNotFoundException e) {
- // shouldn't occur
- } finally {
- tempFile.delete();
- }
- /*if (!safeDelete(file, 8)) {
- tempFile.delete();
- throw new CoreException(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, file.toString()), null));
- }*/
- }
- }
- if (!safeRename(tempFile, file, 10))
- throw new CoreException(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorRename, tempFile.toString()), null));
- }
-
- /**
- * Copy a file from a to b. Closes the input stream after use.
- *
- * @param in java.io.InputStream
- * @param to java.lang.String
- * @return a status
- */
- private IStatus copyFile(InputStream in, String to) {
- OutputStream out = null;
-
- try {
- out = new FileOutputStream(to);
-
- int avail = in.read(buf);
- while (avail > 0) {
- out.write(buf, 0, avail);
- avail = in.read(buf);
- }
- return Status.OK_STATUS;
- } catch (Exception e) {
- Trace.trace(Trace.SEVERE, "Error copying file", e);
- return new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorCopyingFile, new String[] {to, e.getLocalizedMessage()}), e);
- } finally {
- try {
- if (in != null)
- in.close();
- } catch (Exception ex) {
- // ignore
- }
- try {
- if (out != null)
- out.close();
- } catch (Exception ex) {
- // ignore
- }
- }
- }
-
- /**
- * Safe delete. Tries to delete multiple times before giving up.
- *
- * @param f
- * @return <code>true</code> if it succeeds, <code>false</code> otherwise
- */
- private boolean safeDelete(File f, int retrys) {
- int count = 0;
- while (count < retrys) {
- if (!f.exists())
- return true;
-
- f.delete();
-
- if (!f.exists())
- return true;
-
- count++;
- // delay if we are going to try again
- if (count < retrys) {
- try {
- Thread.sleep(100);
- } catch (Exception e) {
- // ignore
- }
- }
- }
- return false;
- }
-
- /**
- * Safe rename. Will try multiple times before giving up.
- *
- * @param from
- * @param to
- * @param retrys number of times to retry
- * @return <code>true</code> if it succeeds, <code>false</code> otherwise
- */
- private boolean safeRename(File from, File to, int retrys) {
- // make sure parent dir exists
- File dir = to.getParentFile();
- if (dir != null && !dir.exists())
- dir.mkdirs();
-
- int count = 0;
- while (count < retrys) {
- if (from.renameTo(to))
- return true;
-
- count++;
- // delay if we are going to try again
- if (count < retrys) {
- try {
- Thread.sleep(100);
- } catch (Exception e) {
- // ignore
- }
- }
- }
- return false;
- }
-
- private void addArrayToList(List list, IStatus[] a) {
- if (list == null || a == null || a.length == 0)
- return;
-
- int size = a.length;
- for (int i = 0; i < size; i++)
- list.add(a[i]);
- }
-
- protected File getTempFolder() {
- if( server == null ) return tempDir;
- String path = ServerConverter.getDeployableServer(server).getTempDeployFolder();
- File f = new File(path);
- if( !f.exists() )
- f.mkdirs();
- return new File(path);
- }
-}
\ No newline at end of file
15 years, 8 months
JBoss Tools SVN: r14767 - in trunk/ws/plugins: org.jboss.tools.ws.creation.core/.settings and 5 other directories.
by jbosstools-commits@lists.jboss.org
Author: Grid.Qian
Date: 2009-04-16 03:48:52 -0400 (Thu, 16 Apr 2009)
New Revision: 14767
Added:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/.settings/
trunk/ws/plugins/org.jboss.tools.ws.creation.core/.settings/org.eclipse.jdt.core.prefs
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/Java2WSCommand.java
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/ClasspathParser.java
Removed:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSProviderInvokeCommand.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.creation.core/.classpath
trunk/ws/plugins/org.jboss.tools.ws.creation.core/META-INF/MANIFEST.MF
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/AbstractGenerateCodeCommand.java
trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSDL2JavaCommand.java
trunk/ws/plugins/org.jboss.tools.ws.creation.ui/plugin.xml
trunk/ws/plugins/org.jboss.tools.ws.creation.ui/src/org/jboss/tools/ws/creation/ui/wsrt/JBossWebService.java
Log:
JBIDE-3783:can't generate WS from a java class in the java project not dynamic web project
Modified: trunk/ws/plugins/org.jboss.tools.ws.creation.core/.classpath
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.creation.core/.classpath 2009-04-16 07:47:06 UTC (rev 14766)
+++ trunk/ws/plugins/org.jboss.tools.ws.creation.core/.classpath 2009-04-16 07:48:52 UTC (rev 14767)
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
- <classpathentry exported="true" kind="lib" path="lib/wsdl4j.jar"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry exported="true" kind="lib" path="lib/wsdl4j.jar" sourcepath="org.jboss.tools.ws.creation.coresrc.zip"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Added: trunk/ws/plugins/org.jboss.tools.ws.creation.core/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.creation.core/.settings/org.eclipse.jdt.core.prefs (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.creation.core/.settings/org.eclipse.jdt.core.prefs 2009-04-16 07:48:52 UTC (rev 14767)
@@ -0,0 +1,7 @@
+#Tue Mar 03 14:01:40 CST 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
Modified: trunk/ws/plugins/org.jboss.tools.ws.creation.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.creation.core/META-INF/MANIFEST.MF 2009-04-16 07:47:06 UTC (rev 14766)
+++ trunk/ws/plugins/org.jboss.tools.ws.creation.core/META-INF/MANIFEST.MF 2009-04-16 07:48:52 UTC (rev 14767)
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name.0
-Bundle-SymbolicName: org.jboss.tools.ws.creation.core
+Bundle-SymbolicName: org.jboss.tools.ws.creation.core;singleton:=true
Bundle-Version: 1.0.0
Bundle-Activator: org.jboss.tools.ws.creation.core.JBossWSCreationCore
Bundle-Vendor: %Bundle-Vendor.0
@@ -16,7 +16,6 @@
org.eclipse.wst.wsdl,
org.eclipse.wst.command.env.core,
org.eclipse.wst.command.env,
- org.eclipse.jst.ws.axis2.consumption.core,
org.apache.ant,
org.apache.xerces,
org.eclipse.jst.j2ee,
@@ -32,7 +31,9 @@
org.jboss.tools.common,
org.jboss.ide.eclipse.as.classpath.core;bundle-version="1.0.0",
org.eclipse.jst.server.core;bundle-version="1.1.0",
- org.eclipse.jdt;bundle-version="3.4.0"
+ org.eclipse.jdt;bundle-version="3.4.0",
+ org.eclipse.jdt.launching;bundle-version="3.4.0",
+ org.eclipse.debug.core;bundle-version="3.4.0"
Bundle-ActivationPolicy: lazy
Export-Package: org.jboss.tools.ws.creation.core,
org.jboss.tools.ws.creation.core.commands,
Modified: trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/AbstractGenerateCodeCommand.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/AbstractGenerateCodeCommand.java 2009-04-16 07:47:06 UTC (rev 14766)
+++ trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/AbstractGenerateCodeCommand.java 2009-04-16 07:48:52 UTC (rev 14767)
@@ -5,6 +5,8 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
+import java.util.ArrayList;
+import java.util.List;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IProject;
@@ -16,6 +18,7 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.osgi.util.NLS;
@@ -54,12 +57,17 @@
.getJBossWSRuntimeLocation(project);
String commandLocation = runtimeLocation + Path.SEPARATOR + "bin";
IPath path = new Path(commandLocation);
- StringBuffer command = new StringBuffer();
+
+ List<String> command = new ArrayList<String>();
+
if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) {
- command.append("cmd.exe /c ").append(cmdFileName_win);
+ command.add("cmd.exe");
+ command.add("/c");
+ command.add(cmdFileName_win);
path = path.append(cmdFileName_win);
} else {
- command.append("sh ").append(cmdFileName_linux);
+ command.add("sh");
+ command.add(cmdFileName_linux);
path = path.append(cmdFileName_linux);
}
@@ -71,18 +79,18 @@
new String[] { path.toOSString() }));
}
- String args = getCommandlineArgs();
- command.append(" -k ").append(args).append(" ");
+ command.add("-k");
+ addCommandlineArgs(command);
if(model.getWsdlURI() != null){
- command.append(model.getWsdlURI());
+ command.add(model.getWsdlURI());
}
- command.append(" -o ").append(projectRoot).append(Path.SEPARATOR)
- .append(
- javaProject.getOutputLocation()
- .removeFirstSegments(1).toOSString());
- Runtime rt = Runtime.getRuntime();
- Process proc = rt.exec(command.toString(), null, new File(
- commandLocation));
+
+ command.add("-o");
+ StringBuffer opDir = new StringBuffer();
+ opDir.append(projectRoot).append(Path.SEPARATOR).append(javaProject.getOutputLocation().removeFirstSegments(1).toOSString());
+ command.add(opDir.toString());
+
+ Process proc = DebugPlugin.exec(command.toArray(new String[command.size()]), new File(commandLocation));
StringBuffer errorResult = new StringBuffer();
StringBuffer inputResult = new StringBuffer();
@@ -107,15 +115,16 @@
}
}
- } catch (IOException e) {
+ } catch (InterruptedException e) {
JBossWSCreationCore.getDefault().logError(e);
-
- } catch (InterruptedException e) {
- // ignore
+ return StatusUtils.errorStatus(e);
} catch (CoreException e) {
JBossWSCreationCore.getDefault().logError(e);
// unable to get runtime location
return e.getStatus();
+ } catch (Exception e) {
+ JBossWSCreationCore.getDefault().logError(e);
+ return StatusUtils.errorStatus(e);
}
refreshProject(model.getWebProjectName(), monitor);
@@ -160,7 +169,7 @@
}
}
- abstract protected String getCommandlineArgs();
+ abstract protected void addCommandlineArgs(List<String> command) throws Exception;
abstract protected String getCommandLineFileName_linux();
Added: trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/Java2WSCommand.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/Java2WSCommand.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/Java2WSCommand.java 2009-04-16 07:48:52 UTC (rev 14767)
@@ -0,0 +1,184 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.tools.ws.creation.core.commands;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Path;
+import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.ws.creation.core.data.ServiceModel;
+import org.jboss.tools.ws.creation.core.utils.ClasspathParser;
+import org.jboss.tools.ws.creation.core.utils.JBossWSCreationUtils;
+
+/**
+ * @author Grid Qian
+ */
+public class Java2WSCommand extends AbstractGenerateCodeCommand {
+
+ private static String WSPROVIDER_FILE_NAME_LINUX = "wsprovide.sh";
+ private static String WSPROVIDER_FILE_NAME_WIN = "wsprovide.bat";
+
+ public Java2WSCommand(ServiceModel model) {
+ super(model);
+ }
+
+ @Override
+ protected String getCommandLineFileName_linux() {
+ return WSPROVIDER_FILE_NAME_LINUX;
+ }
+
+ @Override
+ protected String getCommandLineFileName_win() {
+ return WSPROVIDER_FILE_NAME_WIN;
+ }
+
+ @Override
+ protected void addCommandlineArgs(List<String> command) throws IOException {
+
+ String projectName = model.getWebProjectName();
+ String projectRoot = JBossWSCreationUtils.getProjectRoot(projectName)
+ .toOSString();
+
+ IProject iProject = ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(projectName);
+
+ command.add("-s");
+ command.add(projectRoot + Path.SEPARATOR + "src");
+
+ if (model.isGenWSDL()) {
+ command.add("-w");
+ }
+ command.add("-r");
+ command.add(projectRoot + Path.SEPARATOR + "wsdl");
+ command.add(model.getServiceClasses().get(0));
+
+ command.add("-c");
+ command.add(getClasspath(iProject));
+ }
+
+ private String getClasspath(IProject iProject) throws IOException {
+ String cpStr = ClasspathParser.getInstance().getClasspathString(
+ iProject);
+
+ if (isLongCommandLines(cpStr)) {
+ File tempJar = null;
+ tempJar = File.createTempFile("temp", ".jar");
+ Manifest mf = new Manifest();
+
+ // replace space with "%20"
+ cpStr = cpStr.replace(" ", "%20");
+ // replace \ with /
+ cpStr = cpStr.replace("\\", "/");
+ // get classpath array
+ String[] cpArray = cpStr.split(";");
+ StringBuffer cpBF = new StringBuffer();
+ for (int i = 0; i < cpArray.length; i++) {
+ // if the classpath entry is a directory, it should be added a /
+ // after it
+ if (!cpArray[i].endsWith(".jar") && !cpArray[i].endsWith("/")) {
+ cpArray[i] = cpArray[i] + "/";
+ }
+ // if the system is windows, the classpath entry should be added
+ // a / before it
+ if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0)
+ cpArray[i] = "/" + cpArray[i];
+ // there should be a space between classpath entries
+ cpBF.append(cpArray[i]).append(" ");
+ }
+ cpStr = cpBF.toString();
+ cpStr.trim();
+
+ mf.getMainAttributes().put(Attributes.Name.CLASS_PATH, cpStr);
+ mf.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.2");
+
+ try {
+ FileUtil.jar(new File[0], tempJar.getAbsolutePath(), mf);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ cpStr = tempJar.getAbsolutePath();
+ } else {
+ // if the system is not windows, the split should be :
+ if (System.getProperty("os.name").toLowerCase().indexOf("win") < 0)
+ cpStr = cpStr.replace(";", ":");
+ }
+ return cpStr;
+ }
+
+ public boolean isLongCommandLines(String command) {
+ if (command == null)
+ return false;
+ return command.length() > 1024 ? true : false;
+ }
+
+ // private String getClasspathEntries(IJavaProject javaProject) {
+ // IClasspathEntry[] iniEntries = null;
+ // List<IClasspathEntry> pathList = new ArrayList<IClasspathEntry>();
+ // IClasspathEntry[] resolvedEntries = null;
+ // try {
+ // iniEntries = javaProject.getRawClasspath();
+ // for (IClasspathEntry entry : iniEntries) {
+ // IClasspathContainer container = JavaCore.getClasspathContainer(
+ // entry.getPath(), javaProject);
+ // if (!(container instanceof JBossWSRuntimeClasspathContainer)) {
+ // if (!(container instanceof RuntimeClasspathContainer && container
+ // .getDescription().contains("JBoss"))) {
+ // pathList.add(entry);
+ // }
+ // }
+ // }
+ // resolvedEntries = ((JavaProject) javaProject)
+ // .resolveClasspath(pathList
+ // .toArray(new IClasspathEntry[pathList.size()]));
+ // } catch (JavaModelException e) { // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ // StringBuffer path = new StringBuffer();
+ // for (IClasspathEntry entry : resolvedEntries) {
+ // if (entry.getEntryKind() == 3) {
+ // path.append(workspaceRoot);
+ // continue;
+ // }
+ // if (entry.getEntryKind() == 2) {
+ // String projectRoot = JBossWSCreationUtils.getProjectRoot(
+ // entry.getPath().segment(0)).toOSString();
+ // IProject refProject = ResourcesPlugin.getWorkspace().getRoot()
+ // .getProject(entry.getPath().segment(0));
+ // IJavaProject refJavaProject = JavaCore.create(refProject);
+ // try {
+ // path.append(projectRoot).append(Path.SEPARATOR).append(
+ // refJavaProject.getOutputLocation()
+ // .removeFirstSegments(1).toOSString())
+ // .append(seperator);
+ // } catch (JavaModelException e) {
+ // e.printStackTrace();
+ // }
+ // } else {
+ // path.append(entry.getPath().toOSString()).append(seperator);
+ // }
+ // }
+ // String str = path.toString();
+ // if (str.endsWith(seperator)) {
+ // str = str.substring(0, str.length() - 1);
+ // }
+ // return str;
+ //
+ // }
+
+}
\ No newline at end of file
Modified: trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSDL2JavaCommand.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSDL2JavaCommand.java 2009-04-16 07:47:06 UTC (rev 14766)
+++ trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSDL2JavaCommand.java 2009-04-16 07:48:52 UTC (rev 14767)
@@ -26,39 +26,41 @@
protected String getCommandLineFileName_win() {
return WSCONSUEM_FILE_NAME_WIN;
}
-
+
@Override
- protected String getCommandlineArgs() {
- String commandLine;
+ protected void addCommandlineArgs(List<String> command) {
String project = model.getWebProjectName();
String projectRoot = JBossWSCreationUtils.getProjectRoot(project).toOSString();
- commandLine = "-s " + projectRoot + Path.SEPARATOR + "src";
+ command.add("-s");
+ command.add(projectRoot + Path.SEPARATOR + "src");
+
if(model.getCustomPackage() != null && !"".equals(model.getCustomPackage())){
- commandLine += " -p " + model.getCustomPackage();
+ command.add("-p");
+ command.add(model.getCustomPackage());
}
List<String> bindingFiles = model.getBindingFiles();
for(String bindingFileLocation: bindingFiles){
File bindingFile = new File(bindingFileLocation);
if(bindingFile.exists()){
- commandLine += " -b " + bindingFileLocation;
+ command.add("-b");
+ command.add(bindingFileLocation);
}
}
if(model.getCatalog() != null && !"".equals(model.getCatalog().trim())){
File catalog = new File(model.getCatalog());
if(catalog.exists()){
- commandLine += " -c " + model.getCatalog();
+ command.add("-c");
+ command.add(model.getCatalog());
}
}
if(model.getTarget() != null){
- commandLine += " -t " + model.getTarget();
+ command.add("-t");
+ command.add(model.getTarget());
}
-
-
- return commandLine;
}
}
Deleted: trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSProviderInvokeCommand.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSProviderInvokeCommand.java 2009-04-16 07:47:06 UTC (rev 14766)
+++ trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/commands/WSProviderInvokeCommand.java 2009-04-16 07:48:52 UTC (rev 14767)
@@ -1,142 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008 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.tools.ws.creation.core.commands;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jdt.core.IClasspathContainer;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.internal.core.JavaProject;
-import org.eclipse.jst.server.core.internal.RuntimeClasspathContainer;
-import org.jboss.tools.ws.core.classpath.JBossWSRuntimeClassPathInitializer.JBossWSRuntimeClasspathContainer;
-import org.jboss.tools.ws.creation.core.data.ServiceModel;
-import org.jboss.tools.ws.creation.core.utils.JBossWSCreationUtils;
-
-/**
- * @author Grid Qian
- */
-@SuppressWarnings("restriction")
-public class WSProviderInvokeCommand extends AbstractGenerateCodeCommand {
-
- private static String WSPROVIDER_FILE_NAME_LINUX = "wsprovide.sh";
- private static String WSPROVIDER_FILE_NAME_WIN = "wsprovide.bat";
- private static String SEPERATOR_WIN = ";";
- private static String SEPERATOR_LINUX = ":";
- private String seperator;
-
- public WSProviderInvokeCommand(ServiceModel model) {
- super(model);
- }
-
- @Override
- protected String getCommandLineFileName_linux() {
- return WSPROVIDER_FILE_NAME_LINUX;
- }
-
- @Override
- protected String getCommandLineFileName_win() {
- return WSPROVIDER_FILE_NAME_WIN;
- }
-
- @Override
- protected String getCommandlineArgs() {
- if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) {
- seperator = SEPERATOR_WIN;
- } else {
- seperator = SEPERATOR_LINUX;
- }
- StringBuffer commandLine = new StringBuffer();
- String projectName = model.getWebProjectName();
- String projectRoot = JBossWSCreationUtils.getProjectRoot(projectName)
- .toOSString();
-
- IProject iProject = ResourcesPlugin.getWorkspace().getRoot()
- .getProject(projectName);
- IJavaProject javaProject = JavaCore.create(iProject);
-
- commandLine.append(" -s ").append(projectRoot).append(Path.SEPARATOR)
- .append("src");
-
- try {
- commandLine.append(" -c ");
- if(seperator.equals(SEPERATOR_WIN)){
- commandLine.append("\"");
- }
-
- commandLine.append(projectRoot).append(Path.SEPARATOR).append(
- javaProject.getOutputLocation().removeFirstSegments(1)
- .toOSString()).append(seperator);
- commandLine.append(getClasspathEntries(javaProject));
- if(seperator.equals(SEPERATOR_WIN)){
- commandLine.append("\"");
- }
- commandLine.append(" ");
- } catch (JavaModelException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- if (model.isGenWSDL()) {
- commandLine.append(" -w ");
- }
- commandLine.append(" -r ").append(projectRoot).append(Path.SEPARATOR).append("wsdl ");
- commandLine.append(model.getServiceClasses().get(0));
-
- return commandLine.toString();
-
- }
-
- private String getClasspathEntries(IJavaProject javaProject) {
- IClasspathEntry[] iniEntries = null;
- List<IClasspathEntry> pathList = new ArrayList<IClasspathEntry>();
- IClasspathEntry[] resolvedEntries = null;
- try {
- iniEntries = javaProject.getRawClasspath();
- for (IClasspathEntry entry : iniEntries) {
- IClasspathContainer container = JavaCore.getClasspathContainer(
- entry.getPath(), javaProject);
- if (!(container instanceof JBossWSRuntimeClasspathContainer)) {
- if (!(container instanceof RuntimeClasspathContainer && container
- .getDescription().contains("JBoss"))) {
- pathList.add(entry);
- }
- }
- }
- resolvedEntries = ((JavaProject) javaProject)
- .resolveClasspath(pathList
- .toArray(new IClasspathEntry[pathList.size()]));
- } catch (JavaModelException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- StringBuffer path = new StringBuffer();
- for (IClasspathEntry entry : resolvedEntries) {
- if (entry.getEntryKind() == 3 || entry.getEntryKind() == 2) {
- // path.append(workspaceRoot);
- continue;
- }
- path.append(entry.getPath().toOSString()).append(seperator);
- }
- String str = path.toString();
- if(str.endsWith(seperator)){
- str = str.substring(0, str.length()-1);
- }
- return str;
-
- }
-}
Added: trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/ClasspathParser.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/ClasspathParser.java (rev 0)
+++ trunk/ws/plugins/org.jboss.tools.ws.creation.core/src/org/jboss/tools/ws/creation/core/utils/ClasspathParser.java 2009-04-16 07:48:52 UTC (rev 14767)
@@ -0,0 +1,278 @@
+package org.jboss.tools.ws.creation.core.utils;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities;
+import org.eclipse.jst.ws.internal.common.J2EEUtils;
+import org.eclipse.jst.ws.internal.common.ResourceUtils;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.common.componentcore.resources.IVirtualFolder;
+import org.eclipse.wst.common.componentcore.resources.IVirtualResource;
+
+public class ClasspathParser {
+
+ private static ClasspathParser instance;
+
+ private ClasspathParser() {
+ }
+
+ public static ClasspathParser getInstance() {
+ if (instance == null)
+ instance = new ClasspathParser();
+ return instance;
+ }
+
+ public String getClasspathString(IProject project) {
+ StringBuffer classpath = new StringBuffer();
+ String[] classpathEntries = getClasspath(project, false);
+
+ Vector<String> classpathVector = new Vector<String>();
+ for (int i = 0; i < classpathEntries.length; i++) {
+ if (!classpathVector.contains(classpathEntries[i])) {
+ classpathVector.add(classpathEntries[i]);
+ classpath.append(classpathEntries[i]);
+ classpath.append(";");
+ }
+ }
+ return classpath.toString();
+ }
+
+ @SuppressWarnings("restriction")
+ private String[] getClasspath(IProject project, boolean isDependent) {
+ String[] cClasspath = new String[0];
+ ArrayList<String> projectClasspath = new ArrayList<String>();
+ boolean needJavaClasspath = false;
+
+ IVirtualComponent comp = ComponentCore.createComponent(project);
+ if (comp != null) {
+
+ // get a ear component classpath
+ if (J2EEUtils.isEARComponent(comp)) {
+ cClasspath = getClasspathOfEARProject(project, comp
+ .getName());
+
+ // add component classpath to the project classpath
+ for (int j = 0; j < cClasspath.length; j++) {
+ projectClasspath.add(cClasspath[j]);
+ }
+ } else if (J2EEUtils.isWebComponent(comp)
+ || J2EEUtils.isJavaComponent(comp)) {
+ needJavaClasspath = true;
+
+ IContainer outputContainer = null;
+ IResource fragmentRoot = null;
+ IPackageFragmentRoot[] pkgFragmentRoot = ResourceUtils
+ .getJavaPackageFragmentRoots(project);
+ ArrayList<String> webComponentClasspath = new ArrayList<String>();
+ try {
+ for (int i = 0; i < pkgFragmentRoot.length; i++) {
+ fragmentRoot = pkgFragmentRoot[i]
+ .getCorrespondingResource();
+ if (fragmentRoot != null
+ && (fragmentRoot.getProject().equals(project))
+ && (fragmentRoot.getType() != IResource.FILE)) {
+ outputContainer = J2EEProjectUtilities
+ .getOutputContainer(project,
+ pkgFragmentRoot[i]);
+ if (outputContainer != null) {
+ webComponentClasspath.add(outputContainer
+ .getLocation().toOSString());
+ }
+ }
+ }
+ } catch (JavaModelException e) {
+ }
+
+ // add Web component classpath to the project classpath
+ Iterator<String> iter = webComponentClasspath.iterator();
+ while (iter.hasNext()) {
+ projectClasspath.add((String) iter.next());
+ }
+ }
+
+ if (!isDependent) {
+ if (J2EEUtils.isWebComponent(comp)) {
+ needJavaClasspath = true;
+ cClasspath = getWebInfLib(project);
+ for (int j = 0; j < cClasspath.length; j++) {
+ projectClasspath.add(cClasspath[j]);
+ }
+ }
+ }
+
+ } else {
+ needJavaClasspath = true;
+ }
+
+ // a Web or Java component in the project, get the project's Java classpath
+ if (needJavaClasspath) {
+ String[] javaClasspath;
+ try {
+ IJavaProject javaProj = (IJavaProject) project
+ .getNature(JavaCore.NATURE_ID);
+ if (javaProj != null) {
+ javaClasspath = getClasspathForJavaProject(javaProj);
+ for (int j = 0; j < javaClasspath.length; j++) {
+ projectClasspath.add(javaClasspath[j]);
+ }
+ }
+ } catch (CoreException e) {
+ // can't get Java classpath, ignore
+ }
+ }
+
+ return (String[]) projectClasspath.toArray(new String[projectClasspath
+ .size()]);
+ }
+
+ // Need to get all components in the project. If there's a EAR component, get the
+ // utility Jars
+ @SuppressWarnings("restriction")
+ private String[] getUtilityJarClasspath(IProject project) {
+ String[] utilityJarString = new String[0];
+ String[] cClasspath = new String[0];
+ ArrayList<String> utilityJarsClasspath = new ArrayList<String>();
+
+ String component;
+ IVirtualComponent comp = ComponentCore.createComponent(project);
+ if (comp != null) {
+ component = comp.getName();
+ if (J2EEUtils.isEARComponent(comp)) {
+ cClasspath = getClasspathOfEARProject(project, component);
+ for (int j = 0; j < cClasspath.length; j++) {
+ utilityJarsClasspath.add(cClasspath[j]);
+ }
+ utilityJarString = (String[]) utilityJarsClasspath
+ .toArray(new String[utilityJarsClasspath.size()]);
+ }
+ }
+
+ return utilityJarString;
+ }
+
+ private String[] getClasspathOfEARProject(IProject project, String component) {
+ IPath projectPath = project.getProject().getLocation()
+ .addTrailingSeparator().append(component).addTrailingSeparator();
+ return getDirectoryJarFiles(projectPath);
+ }
+
+ private String[] getDirectoryJarFiles(IPath iPath) {
+ File dir = iPath.toFile();
+ Vector<Object> jarsVector = new Vector<Object>();
+ if (dir.exists() && dir.isDirectory()) {
+ String[] filenames = dir.list();
+ for (int i = 0; i < filenames.length; i++) {
+ if (filenames[i].endsWith(".jar"))
+ jarsVector.add(pathToString(iPath) + filenames[i]);
+ }
+ }
+ String[] jars = new String[jarsVector.size()];
+ jarsVector.copyInto(jars);
+ return jars;
+ }
+
+ private String[] getWebInfLib(IProject project) {
+ String[] webinfLibJars = new String[0];
+ ArrayList<String> anArrayList = new ArrayList<String>();
+ try {
+ IVirtualComponent component = ComponentCore
+ .createComponent(project);
+ if (component != null) {
+
+ IVirtualFolder webInfLib = component.getRootFolder().getFolder(
+ new Path("/WEB-INF/lib"));
+ if (webInfLib != null) {
+ IVirtualResource[] resources = webInfLib.members();
+ IResource aResource = null;
+ for (int i = 0; i < resources.length; i++) {
+ aResource = resources[i].getUnderlyingResource();
+ if ("jar".equalsIgnoreCase(aResource.getFileExtension()))
+ anArrayList.add(aResource.getLocation()
+ .toOSString());
+ }
+ if (anArrayList.size() != 0)
+ webinfLibJars = (String[]) anArrayList
+ .toArray(new String[anArrayList.size()]);
+ }
+ }
+ } catch (CoreException e) {
+ }
+ return webinfLibJars;
+ }
+
+ private String[] getClasspathForJavaProject(IJavaProject javaProject) {
+ ArrayList<String> projectClasspath = new ArrayList<String>();
+ try {
+ IClasspathEntry[] buildPath = javaProject
+ .getResolvedClasspath(true);
+ for (int i = 0; i < buildPath.length; i++) {
+ String[] buildPathString = classpathEntryToString(buildPath[i],
+ javaProject.getProject());
+ for (int j = 0; j < buildPathString.length; j++) {
+ projectClasspath.add(buildPathString[j]);
+ }
+ }
+ } catch (JavaModelException jme) {
+ }
+
+ String[] utilityJarsClasspath;
+ IProject project = javaProject.getProject();
+ IProject[] referencingProjects = project.getReferencingProjects();
+ for (int i = 0; i < referencingProjects.length; i++) {
+ utilityJarsClasspath = getUtilityJarClasspath(referencingProjects[i]);
+ for (int j = 0; j < utilityJarsClasspath.length; j++) {
+ projectClasspath.add(utilityJarsClasspath[j]);
+ }
+ }
+
+ return (String[]) projectClasspath.toArray(new String[projectClasspath
+ .size()]);
+ }
+
+ private String[] classpathEntryToString(IClasspathEntry entry,
+ IProject project) {
+ switch (entry.getEntryKind()) {
+ case IClasspathEntry.CPE_LIBRARY: {
+ return new String[] { pathToString(entry.getPath()) };
+ }
+ case IClasspathEntry.CPE_PROJECT: {
+ return getClasspath(ResourcesPlugin.getWorkspace().getRoot()
+ .getProject(entry.getPath().lastSegment()), true);
+ }
+ case IClasspathEntry.CPE_SOURCE: {
+ IPath path = entry.getPath();
+ if (path.segment(0).equals(project.getName()))
+ path = path.removeFirstSegments(1);
+ return new String[] { pathToString(project.getLocation()
+ .addTrailingSeparator().append(path)) };
+ }
+ case IClasspathEntry.CPE_VARIABLE: {
+ return classpathEntryToString(JavaCore
+ .getResolvedClasspathEntry(entry), project);
+ }
+ default: {
+ return new String[] { pathToString(entry.getPath()) };
+ }
+ }
+ }
+
+ private String pathToString(IPath path) {
+ return path.toOSString();
+ }
+}
Modified: trunk/ws/plugins/org.jboss.tools.ws.creation.ui/plugin.xml
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.creation.ui/plugin.xml 2009-04-16 07:47:06 UTC (rev 14766)
+++ trunk/ws/plugins/org.jboss.tools.ws.creation.ui/plugin.xml 2009-04-16 07:48:52 UTC (rev 14767)
@@ -50,7 +50,7 @@
<widgetFactory
class="org.jboss.tools.ws.creation.ui.wsrt.JBossWSProviderInvokeConfigWidgetFactory"
id="JBossWSProviderInvokeConfig"
- insertBeforeCommandId="org.jboss.tools.ws.creation.core.commands.WSProviderInvokeCommand">
+ insertBeforeCommandId="org.jboss.tools.ws.creation.core.commands.Java2WSCommand">
</widgetFactory>
</extension>
<extension
Modified: trunk/ws/plugins/org.jboss.tools.ws.creation.ui/src/org/jboss/tools/ws/creation/ui/wsrt/JBossWebService.java
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.creation.ui/src/org/jboss/tools/ws/creation/ui/wsrt/JBossWebService.java 2009-04-16 07:47:06 UTC (rev 14766)
+++ trunk/ws/plugins/org.jboss.tools.ws.creation.ui/src/org/jboss/tools/ws/creation/ui/wsrt/JBossWebService.java 2009-04-16 07:48:52 UTC (rev 14767)
@@ -13,10 +13,10 @@
import org.jboss.tools.ws.creation.core.commands.BindingFilesValidationCommand;
import org.jboss.tools.ws.creation.core.commands.ImplementationClassCreationCommand;
import org.jboss.tools.ws.creation.core.commands.InitialCommand;
+import org.jboss.tools.ws.creation.core.commands.Java2WSCommand;
import org.jboss.tools.ws.creation.core.commands.MergeWebXMLCommand;
import org.jboss.tools.ws.creation.core.commands.ValidateWSImplCommand;
import org.jboss.tools.ws.creation.core.commands.WSDL2JavaCommand;
-import org.jboss.tools.ws.creation.core.commands.WSProviderInvokeCommand;
import org.jboss.tools.ws.creation.core.data.ServiceModel;
public class JBossWebService extends AbstractWebService {
@@ -57,7 +57,7 @@
else if (ctx.getScenario().getValue() == WebServiceScenario.BOTTOMUP){
commands.add(new InitialCommand(model, this, WebServiceScenario.BOTTOMUP));
commands.add(new ValidateWSImplCommand(model));
- commands.add(new WSProviderInvokeCommand(model));
+ commands.add(new Java2WSCommand(model));
commands.add(new MergeWebXMLCommand(model));
//commands.add(new JBossWSRuntimeCommand(ResourcesPlugin.getWorkspace().getRoot().getProject(project)));
}
15 years, 8 months
JBoss Tools SVN: r14766 - in trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org: jboss/tools/smooks/configuration/editors/edireader and 4 other directories.
by jbosstools-commits@lists.jboss.org
Author: DartPeng
Date: 2009-04-16 03:47:06 -0400 (Thu, 16 Apr 2009)
New Revision: 14766
Added:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/milyn/
Modified:
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/edireader/EDIReaderUICreator.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/freemarker/TemplateUICreator.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/smooks/ImportTypeUICreator.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/smooks/ParamTypeUICreator.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java
trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/xsl/TemplateUICreator.java
Log:
JBIDE-4192
mission complete
Modified: trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/edireader/EDIReaderUICreator.java
===================================================================
--- trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/edireader/EDIReaderUICreator.java 2009-04-15 18:23:04 UTC (rev 14765)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/edireader/EDIReaderUICreator.java 2009-04-16 07:47:06 UTC (rev 14766)
@@ -10,27 +10,15 @@
******************************************************************************/
package org.jboss.tools.smooks.configuration.editors.edireader;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Path;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.events.IHyperlinkListener;
import org.eclipse.ui.forms.widgets.FormToolkit;
-import org.eclipse.ui.part.FileEditorInput;
-import org.jboss.tools.smooks.configuration.SmooksConfigurationActivator;
import org.jboss.tools.smooks.configuration.editors.PropertyUICreator;
import org.jboss.tools.smooks.configuration.editors.SmooksMultiFormEditor;
import org.jboss.tools.smooks.configuration.editors.uitls.SmooksUIUtils;
@@ -52,38 +40,7 @@
}
try {
IResource resource = SmooksUIUtils.getResource((EObject) model);
- IFile file1 = null;
- if (resource != null) {
- IProject project = resource.getProject();
- IJavaProject javaProject = JavaCore.create(project);
- if (javaProject != null) {
- IClasspathEntry[] classPathEntrys = javaProject.getRawClasspath();
- for (int i = 0; i < classPathEntrys.length; i++) {
- IClasspathEntry entry = classPathEntrys[i];
- if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
- IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(entry.getPath());
- if (folder != null && folder.exists()) {
- IFile file = folder.getFile(new Path(p));
- if (file != null && file.exists()) {
- file1 = file;
- break;
- }
- }
- }
- }
- }
- if (file1 != null) {
- IWorkbenchWindow window = SmooksConfigurationActivator.getDefault().getWorkbench().getActiveWorkbenchWindow();
- window.getActivePage().openEditor(new FileEditorInput(file1), SmooksMultiFormEditor.EDITOR_ID);
- } else {
- String message = "Path is null";
- if (p != null && p.length() != 0) {
- message = "Can't find file : " + p;
- }
- MessageDialog.openInformation(SmooksConfigurationActivator.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(),
- "Can't open editor", message);
- }
- }
+ SmooksUIUtils.openFile(p, resource.getProject(), SmooksMultiFormEditor.EDITOR_ID);
} catch (Exception e) {
}
@@ -103,33 +60,6 @@
if (feature == EdiPackage.eINSTANCE.getEDIReader_Encoding()) {
}
if (feature == EdiPackage.eINSTANCE.getEDIReader_MappingModel()) {
- // IResource resource =SmooksUIUtils.getResource((EObject)model);
- // if(resource != null){
- // final IProject project = resource.getProject();
- // ViewerFilter viewerFilter = new ViewerFilter(){
- // @Override
- // public boolean select(Viewer viewer, Object parentElement, Object
- // element) {
- // IResource re = null;
- // if(element instanceof IResource){
- // re = (IResource)element;
- // }
- // if(element instanceof IAdaptable){
- // re = (IResource)
- // ((IAdaptable)element).getAdapter(IResource.class);
- // }
- // if(re != null){
- // if(re.getProject() == project){
- // return true;
- // }
- // }
- // return false;
- // }
- // };
- // List<ViewerFilter> list = new ArrayList<ViewerFilter>();
- // list.add(viewerFilter);
- // setDialogViewerFilters(list);
- // }
final Object fm = model;
final IItemPropertyDescriptor fpd = propertyDescriptor;
IHyperlinkListener listener = new IHyperlinkListener() {
Modified: trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/freemarker/TemplateUICreator.java
===================================================================
--- trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/freemarker/TemplateUICreator.java 2009-04-15 18:23:04 UTC (rev 14765)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/freemarker/TemplateUICreator.java 2009-04-16 07:47:06 UTC (rev 14766)
@@ -10,15 +10,21 @@
******************************************************************************/
package org.jboss.tools.smooks.configuration.editors.freemarker;
+import org.eclipse.core.resources.IResource;
import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.xml.type.AnyType;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.forms.events.HyperlinkEvent;
+import org.eclipse.ui.forms.events.IHyperlinkListener;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.jboss.tools.smooks.configuration.editors.PropertyUICreator;
import org.jboss.tools.smooks.configuration.editors.SmooksMultiFormEditor;
import org.jboss.tools.smooks.configuration.editors.uitls.SmooksUIUtils;
import org.jboss.tools.smooks.model.freemarker.FreemarkerPackage;
+import org.jboss.tools.smooks10.model.smooks.util.SmooksModelUtils;
/**
* @author Dart Peng (dpeng(a)redhat.com) Date Apr 10, 2009
@@ -34,9 +40,8 @@
* org.eclipse.emf.edit.provider.IItemPropertyDescriptor, java.lang.Object,
* org.eclipse.emf.ecore.EAttribute)
*/
- public Composite createPropertyUI(FormToolkit toolkit, Composite parent,
- IItemPropertyDescriptor propertyDescriptor, Object model, EAttribute feature,
- SmooksMultiFormEditor formEditor) {
+ public Composite createPropertyUI(FormToolkit toolkit, Composite parent, IItemPropertyDescriptor propertyDescriptor, Object model,
+ EAttribute feature, SmooksMultiFormEditor formEditor) {
if (feature == FreemarkerPackage.eINSTANCE.getTemplate_Value()) {
}
if (feature == FreemarkerPackage.eINSTANCE.getTemplate_Encoding()) {
@@ -46,9 +51,35 @@
}
@Override
- public void createExtendUI(AdapterFactoryEditingDomain editingdomain, FormToolkit toolkit,
- Composite parent, Object model, SmooksMultiFormEditor formEditor) {
- SmooksUIUtils.createMixedTextFieldEditor("Text Value", editingdomain, toolkit, parent, model);
+ public void createExtendUI(AdapterFactoryEditingDomain editingdomain, FormToolkit toolkit, Composite parent, Object model,
+ SmooksMultiFormEditor formEditor) {
+ final Object path = SmooksModelUtils.getAnyTypeText((AnyType)model);
+ final Object fm = model;
+ IHyperlinkListener listener = new IHyperlinkListener() {
+
+ public void linkActivated(HyperlinkEvent e) {
+ String p = null;
+ if (path != null && path instanceof String) {
+ p = ((String) path).trim();
+ }
+ try {
+ IResource resource = SmooksUIUtils.getResource((EObject) fm);
+ SmooksUIUtils.openFile(p, resource.getProject(),null);
+ } catch (Exception e1) {
+
+ }
+ }
+
+ public void linkEntered(HyperlinkEvent e) {
+
+ }
+
+ public void linkExited(HyperlinkEvent e) {
+
+ }
+
+ };
+ SmooksUIUtils.createMixedTextFieldEditor("Text Value", editingdomain, toolkit, parent, model,true,listener);
SmooksUIUtils.createCDATAFieldEditor("Template Contents(CDATA)", editingdomain, toolkit, parent, model);
SmooksUIUtils.createCommentFieldEditor("Template Contents(Comment)", editingdomain, toolkit, parent, model);
}
@@ -60,7 +91,5 @@
}
return super.ignoreProperty(feature);
}
-
-
}
\ No newline at end of file
Modified: trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/smooks/ImportTypeUICreator.java
===================================================================
--- trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/smooks/ImportTypeUICreator.java 2009-04-15 18:23:04 UTC (rev 14765)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/smooks/ImportTypeUICreator.java 2009-04-16 07:47:06 UTC (rev 14766)
@@ -10,12 +10,18 @@
******************************************************************************/
package org.jboss.tools.smooks.configuration.editors.smooks;
+import org.eclipse.core.resources.IResource;
import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.forms.events.HyperlinkEvent;
+import org.eclipse.ui.forms.events.IHyperlinkListener;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.jboss.tools.smooks.configuration.editors.PropertyUICreator;
import org.jboss.tools.smooks.configuration.editors.SmooksMultiFormEditor;
+import org.jboss.tools.smooks.configuration.editors.uitls.SmooksUIUtils;
import org.jboss.tools.smooks.model.smooks.SmooksPackage;
/**
@@ -35,6 +41,35 @@
public Composite createPropertyUI(FormToolkit toolkit, Composite parent,
IItemPropertyDescriptor propertyDescriptor, Object model, EAttribute feature,SmooksMultiFormEditor formEditor) {
if (feature == SmooksPackage.eINSTANCE.getImportType_File()) {
+ final Object fm = model;
+ final Object path = SmooksUIUtils.getEditValue(propertyDescriptor, model);
+ IHyperlinkListener listener = new IHyperlinkListener() {
+ public void linkActivated(HyperlinkEvent e) {
+ String p = null;
+ if (path != null && path instanceof String) {
+ p = ((String) path).trim();
+ }
+ try {
+ IResource resource = SmooksUIUtils.getResource((EObject) fm);
+ SmooksUIUtils.openFile(p, resource.getProject(),null);
+ } catch (Exception e1) {
+
+ }
+ }
+
+ public void linkEntered(HyperlinkEvent e) {
+
+ }
+
+ public void linkExited(HyperlinkEvent e) {
+
+ }
+
+ };
+ SmooksUIUtils.createLinkTextValueFieldEditor(null, (AdapterFactoryEditingDomain) formEditor.getEditingDomain(), propertyDescriptor,
+ toolkit, parent, model, false, 0, true, listener);
+
+ return parent;
}
return super.createPropertyUI(toolkit, parent, propertyDescriptor, model, feature, formEditor);
}
Modified: trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/smooks/ParamTypeUICreator.java
===================================================================
--- trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/smooks/ParamTypeUICreator.java 2009-04-15 18:23:04 UTC (rev 14765)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/smooks/ParamTypeUICreator.java 2009-04-16 07:47:06 UTC (rev 14766)
@@ -46,7 +46,7 @@
@Override
public void createExtendUI(AdapterFactoryEditingDomain editingdomain, FormToolkit toolkit,
Composite parent, Object model, SmooksMultiFormEditor formEditor) {
- SmooksUIUtils.createMixedTextFieldEditor("Text Value", editingdomain, toolkit, parent, model , false , 500);
+ SmooksUIUtils.createMixedTextFieldEditor("Text Value", editingdomain, toolkit, parent, model , false , 500,false,null);
SmooksUIUtils.createCDATAFieldEditor("CDATA Value", editingdomain, toolkit, parent, model);
}
}
\ No newline at end of file
Modified: trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java
===================================================================
--- trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java 2009-04-15 18:23:04 UTC (rev 14765)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/uitls/SmooksUIUtils.java 2009-04-16 07:47:06 UTC (rev 14766)
@@ -18,6 +18,7 @@
import java.util.List;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -32,6 +33,7 @@
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.ItemPropertyDescriptor.PropertyValueWrapper;
+import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
@@ -53,6 +55,7 @@
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.forms.IFormColors;
import org.eclipse.ui.forms.events.HyperlinkEvent;
@@ -60,6 +63,8 @@
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Hyperlink;
import org.eclipse.ui.forms.widgets.Section;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.part.FileEditorInput;
import org.jboss.tools.smooks.configuration.SmooksConfigurationActivator;
import org.jboss.tools.smooks.configuration.editors.IXMLStructuredObject;
import org.jboss.tools.smooks.configuration.editors.SelectorAttributes;
@@ -89,17 +94,17 @@
public static final String XSL_NAMESPACE = " xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" ";
public static void createMixedTextFieldEditor(String label, AdapterFactoryEditingDomain editingdomain, FormToolkit toolkit, Composite parent,
- Object model) {
- createMixedTextFieldEditor(label, editingdomain, toolkit, parent, model, false, 0);
+ Object model,boolean linkLabel, IHyperlinkListener listener) {
+ createMixedTextFieldEditor(label, editingdomain, toolkit, parent, model, false, 0,linkLabel,listener);
}
public static void createMultiMixedTextFieldEditor(String label, AdapterFactoryEditingDomain editingdomain, FormToolkit toolkit,
Composite parent, Object model, int height) {
- createMixedTextFieldEditor(label, editingdomain, toolkit, parent, model, true, height);
+ createMixedTextFieldEditor(label, editingdomain, toolkit, parent, model, true, height,false,null);
}
public static void createMixedTextFieldEditor(String label, AdapterFactoryEditingDomain editingdomain, FormToolkit toolkit, Composite parent,
- Object model, boolean multiText, int height) {
+ Object model, boolean multiText, int height, boolean linkLabel, IHyperlinkListener listener) {
GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
Section section = null;
Composite textContainer = null;
@@ -123,7 +128,14 @@
section.setLayoutData(gd);
textContainer = textComposite;
} else {
- toolkit.createLabel(parent, label + " :").setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
+ if (linkLabel) {
+ Hyperlink link = toolkit.createHyperlink(parent, label + " :", SWT.NONE);
+ if (listener != null) {
+ link.addHyperlinkListener(listener);
+ }
+ } else {
+ toolkit.createLabel(parent, label + " :").setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
+ }
textContainer = parent;
}
gd = new GridData(GridData.FILL_HORIZONTAL);
@@ -237,14 +249,13 @@
public static void createLinkTextValueFieldEditor(String label, AdapterFactoryEditingDomain editingdomain,
IItemPropertyDescriptor propertyDescriptor, FormToolkit toolkit, Composite parent, Object model, boolean multiText, int height,
boolean linkLabel, IHyperlinkListener listener) {
+ Control control = createFiledEditorLabel(parent, toolkit, propertyDescriptor, model, linkLabel);
if (linkLabel) {
- Hyperlink link = toolkit.createHyperlink(parent, label, SWT.NONE);
+ Hyperlink link = (Hyperlink)control;
if (listener != null) {
link.addHyperlinkListener(listener);
}
- } else {
- toolkit.createLabel(parent, label + " :").setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
- }
+ }
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
int textType = SWT.FLAT;
if (multiText) {
@@ -762,6 +773,51 @@
return classTextComposite;
}
+ public static void openFile(String uri, IProject project) throws PartInitException {
+ openFile(uri, project, null);
+ }
+
+ public static void openFile(String uri, IProject project, String editorID) throws PartInitException {
+ if (uri.charAt(0) == '\\' || uri.charAt(0) == '/') {
+ uri = uri.substring(1);
+ }
+ IFile file = project.getFile(uri);
+ IWorkbenchWindow window = SmooksConfigurationActivator.getDefault().getWorkbench().getActiveWorkbenchWindow();
+ // it's workspace resource
+ if (file.exists()) {
+
+ } else {
+ // maybe it's a classpath resource
+ try {
+ IJavaProject javaProject = JavaCore.create(project);
+ if (javaProject != null) {
+ IClasspathEntry[] classPathEntrys = javaProject.getRawClasspath();
+ for (int i = 0; i < classPathEntrys.length; i++) {
+ IClasspathEntry entry = classPathEntrys[i];
+ IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(entry.getPath());
+ if (folder != null && folder.exists()) {
+ IFile temp = folder.getFile(new Path(uri));
+ if (temp != null && temp.exists()) {
+ file = temp;
+ break;
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+
+ }
+ }
+ if (file.exists()) {
+ FileEditorInput editorInput = new FileEditorInput(file);
+ if (editorID != null) {
+ window.getActivePage().openEditor(editorInput, editorID);
+ } else {
+ IDE.openEditor(window.getActivePage(), file);
+ }
+ }
+ }
+
public static void showErrorDialog(Shell shell, Status status) {
ErrorDialog.openError(shell, "Error", "error", status); //$NON-NLS-1$ //$NON-NLS-2$
}
Modified: trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/xsl/TemplateUICreator.java
===================================================================
--- trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/xsl/TemplateUICreator.java 2009-04-15 18:23:04 UTC (rev 14765)
+++ trunk/smooks/plugins/org.jboss.tools.smooks.ui/src/org/jboss/tools/smooks/configuration/editors/xsl/TemplateUICreator.java 2009-04-16 07:47:06 UTC (rev 14766)
@@ -10,15 +10,21 @@
******************************************************************************/
package org.jboss.tools.smooks.configuration.editors.xsl;
+import org.eclipse.core.resources.IResource;
import org.eclipse.emf.ecore.EAttribute;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.xml.type.AnyType;
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.forms.events.HyperlinkEvent;
+import org.eclipse.ui.forms.events.IHyperlinkListener;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.jboss.tools.smooks.configuration.editors.PropertyUICreator;
import org.jboss.tools.smooks.configuration.editors.SmooksMultiFormEditor;
import org.jboss.tools.smooks.configuration.editors.uitls.SmooksUIUtils;
import org.jboss.tools.smooks.model.xsl.XslPackage;
+import org.jboss.tools.smooks10.model.smooks.util.SmooksModelUtils;
/**
* @author Dart Peng (dpeng(a)redhat.com) Date Apr 10, 2009
@@ -34,8 +40,8 @@
* org.eclipse.emf.edit.provider.IItemPropertyDescriptor, java.lang.Object,
* org.eclipse.emf.ecore.EAttribute)
*/
- public Composite createPropertyUI(FormToolkit toolkit, Composite parent,
- IItemPropertyDescriptor propertyDescriptor, Object model, EAttribute feature,SmooksMultiFormEditor formEditor) {
+ public Composite createPropertyUI(FormToolkit toolkit, Composite parent, IItemPropertyDescriptor propertyDescriptor, Object model,
+ EAttribute feature, SmooksMultiFormEditor formEditor) {
if (feature == XslPackage.eINSTANCE.getTemplate_Value()) {
}
if (feature == XslPackage.eINSTANCE.getTemplate_Encoding()) {
@@ -43,11 +49,13 @@
return super.createPropertyUI(toolkit, parent, propertyDescriptor, model, feature, formEditor);
}
-
-
- /* (non-Javadoc)
- * @see org.jboss.tools.smooks.configuration.editors.PropertyUICreator#ignoreProperty(org.eclipse.emf.ecore.EAttribute)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.jboss.tools.smooks.configuration.editors.PropertyUICreator#ignoreProperty
+ * (org.eclipse.emf.ecore.EAttribute)
*/
@Override
public boolean ignoreProperty(EAttribute feature) {
@@ -57,12 +65,36 @@
return super.ignoreProperty(feature);
}
+ @Override
+ public void createExtendUI(AdapterFactoryEditingDomain editingdomain, FormToolkit toolkit, Composite parent, Object model,
+ SmooksMultiFormEditor formEditor) {
+ final Object path = SmooksModelUtils.getAnyTypeText((AnyType) model);
+ final Object fm = model;
+ IHyperlinkListener listener = new IHyperlinkListener() {
+ public void linkActivated(HyperlinkEvent e) {
+ String p = null;
+ if (path != null && path instanceof String) {
+ p = ((String) path).trim();
+ }
+ try {
+ IResource resource = SmooksUIUtils.getResource((EObject) fm);
+ SmooksUIUtils.openFile(p, resource.getProject(), null);
+ } catch (Exception e1) {
- @Override
- public void createExtendUI(AdapterFactoryEditingDomain editingdomain, FormToolkit toolkit,
- Composite parent, Object model, SmooksMultiFormEditor formEditor) {
- SmooksUIUtils.createMixedTextFieldEditor("Text Value", editingdomain, toolkit, parent, model);
+ }
+ }
+
+ public void linkEntered(HyperlinkEvent e) {
+
+ }
+
+ public void linkExited(HyperlinkEvent e) {
+
+ }
+
+ };
+ SmooksUIUtils.createMixedTextFieldEditor("Text Value", editingdomain, toolkit, parent, model, true, listener);
SmooksUIUtils.createCDATAFieldEditor("Template Contents (CDATA)", editingdomain, toolkit, parent, model);
SmooksUIUtils.createCommentFieldEditor("Template Contents (Comment)", editingdomain, toolkit, parent, model);
}
15 years, 8 months
JBoss Tools SVN: r14765 - trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF.
by jbosstools-commits@lists.jboss.org
Author: akazakov
Date: 2009-04-15 14:23:04 -0400 (Wed, 15 Apr 2009)
New Revision: 14765
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF
Log:
https://jira.jboss.org/jira/browse/JBIDE-4163 Migrate usage of javascript plugin to jsdt plugins
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF 2009-04-15 18:22:49 UTC (rev 14764)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/META-INF/MANIFEST.MF 2009-04-15 18:23:04 UTC (rev 14765)
@@ -1,5 +1,5 @@
Manifest-Version: 1.0
-Eclipse-LazyStart: true
+Bundle-ActivationPolicy: lazy
Bundle-Name: %Bundle-Name.0
Bundle-ClassPath: jspeditor.jar
Bundle-Activator: org.jboss.tools.jst.jsp.JspEditorPlugin
@@ -47,8 +47,6 @@
org.eclipse.jst.jsp.ui,
org.eclipse.wst.css.core,
org.eclipse.wst.css.ui,
- org.eclipse.wst.javascript.core,
- org.eclipse.wst.javascript.ui,
org.eclipse.help,
org.eclipse.help.ui,
org.eclipse.help.appserver,
15 years, 8 months
JBoss Tools SVN: r14764 - trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist.
by jbosstools-commits@lists.jboss.org
Author: akazakov
Date: 2009-04-15 14:22:49 -0400 (Wed, 15 Apr 2009)
New Revision: 14764
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/ExtendedJSPContentAssistProcessor.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-4163 Migrate usage of javascript plugin to jsdt plugins
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/ExtendedJSPContentAssistProcessor.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/ExtendedJSPContentAssistProcessor.java 2009-04-15 18:20:58 UTC (rev 14763)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/ExtendedJSPContentAssistProcessor.java 2009-04-15 18:22:49 UTC (rev 14764)
@@ -31,7 +31,6 @@
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.css.ui.internal.contentassist.CSSContentAssistProcessor;
-import org.eclipse.wst.javascript.ui.internal.common.contentassist.JavaScriptContentAssistProcessor;
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
@@ -82,7 +81,6 @@
private IDocument document;
private boolean dontOpenTag = false;
-
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentPosition) {
try {
String text = viewer.getDocument().get(0, documentPosition);
@@ -105,7 +103,7 @@
if(proposals.length == 0) {
String partitionType = getPartitionType((StructuredTextViewer) viewer, documentPosition);
IContentAssistProcessor p = (IContentAssistProcessor) fPartitionToProcessorMap.get(partitionType);
- if (!(p instanceof JavaScriptContentAssistProcessor || p instanceof CSSContentAssistProcessor)) {
+ if (!(p instanceof CSSContentAssistProcessor)) {
IndexedRegion treeNode = ContentAssistUtils.getNodeAt((StructuredTextViewer) viewer, documentPosition);
Node node = (Node) treeNode;
15 years, 8 months