[jbosstools-commits] JBoss Tools SVN: r24129 - in trunk/as/plugins: org.jboss.ide.eclipse.as.core and 16 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Fri Aug 13 01:37:31 EDT 2010
Author: rob.stryker at jboss.com
Date: 2010-08-13 01:37:30 -0400 (Fri, 13 Aug 2010)
New Revision: 24129
Added:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractJSTPublisher.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractPublishMethod.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractServerToolsPublisher.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerPublishMethodType.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/LocalJBossBehaviorDelegate.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/ServerPublishMethodType.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/LocalJBossServerStartupLaunchUtil.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHCommandUtil.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHCopyCallback.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHJstPublisher.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/DeploymentModuleOptionCompositeAssistant.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/EditorExtensionManager.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/IDeploymentTypeUI.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerModeSection.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/schema/DeployMethodUI.exsd
Removed:
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPublisher.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/LocalDeploymentModuleTab.java
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackageModuleFactory.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagesPublisher.java
trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/WTPZippedPublisher.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/ExtensionManager.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/extensions/polling/ProcessTerminatedPoller.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/modules/SingleDeployableFactory.java
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/LocalPublishMethod.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/publishers/SingleFilePublisher.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IDeployableServer.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerPublishMethod.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServer.java
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/JBossServer.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServerBehavior.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/PollThread.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/AbstractJBossLaunchConfigType.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/JBossServerStartupLaunchConfiguration.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/RunJarContainerWrapper.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/StopLaunchConfiguration.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishCopyUtil.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/DeploymentPreferenceLoader.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/IJBossToolingConstants.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/ServerConverter.java
trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.properties
trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml
trunk/as/plugins/org.jboss.ide.eclipse.as.core/schema/publishMethod.exsd
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/plugin.xml
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPackagesPublisher.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHServerBehaviourDelegate.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHSingleFilePublisher.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHZippedJSTPublisher.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.properties
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/IDeploymentEditorTab.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ModuleDeploymentPage.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PollerSection.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PortSection.java
trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml
Log:
JBIDE-6580 Merging changes into head on already-existing plugins
Modified: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackageModuleFactory.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackageModuleFactory.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackageModuleFactory.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -41,6 +41,7 @@
import org.jboss.ide.eclipse.archives.core.model.IArchiveNodeVisitor;
import org.jboss.ide.eclipse.archives.core.model.DirectoryScannerFactory.DirectoryScannerExtension.FileWrapper;
import org.jboss.ide.eclipse.archives.core.util.ModelUtil;
+import org.jboss.ide.eclipse.as.wtp.core.modules.IJBTModule;
/**
*
@@ -285,7 +286,7 @@
}
- public static class PackagedModuleDelegate extends ModuleDelegate {
+ public static class PackagedModuleDelegate extends ModuleDelegate implements IJBTModule {
private IArchive pack;
private IModuleResource rootResource;
private DelegateInitVisitor initVisitor;
@@ -317,6 +318,18 @@
public IStatus validate() {
return Status.OK_STATUS;
}
+
+ public IModule[] getModules() {
+ return new IModule[]{};
+ }
+
+ public String getURI(IModule module) {
+ return null; // not called i hope
+ }
+
+ public boolean isBinary() {
+ return rootResource instanceof IModuleFile;
+ }
}
public static class PackagesModuleFolder extends ModuleFolder {
Modified: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagesPublisher.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagesPublisher.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/PackagesPublisher.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -1,179 +1,25 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.ide.eclipse.archives.webtools.modules;
-import java.io.File;
-import java.util.ArrayList;
-
-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.osgi.util.NLS;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.model.IModuleResource;
-import org.eclipse.wst.server.core.model.IModuleResourceDelta;
-import org.jboss.ide.eclipse.archives.core.model.IArchive;
-import org.jboss.ide.eclipse.archives.core.util.PathUtils;
-import org.jboss.ide.eclipse.archives.webtools.IntegrationPlugin;
-import org.jboss.ide.eclipse.archives.webtools.Messages;
-import org.jboss.ide.eclipse.archives.webtools.modules.PackageModuleFactory.PackagedModuleDelegate;
+import org.jboss.ide.eclipse.as.core.publishers.AbstractServerToolsPublisher;
import org.jboss.ide.eclipse.as.core.publishers.LocalPublishMethod;
-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.IJBossServerPublishMethod;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
-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;
-/**
- *
- * @author rob.stryker at jboss.com
- */
-public class PackagesPublisher implements IJBossServerPublisher {
-
- protected IDeployableServer server;
- protected IModuleResourceDelta[] delta;
- protected FileUtilListener listener;
- public PackagesPublisher() {
- }
-
- public int getPublishState() {
- return IServer.PUBLISH_STATE_NONE;
- }
-
+public class PackagesPublisher extends AbstractServerToolsPublisher {
public boolean accepts(String method, IServer server, IModule[] module) {
if( LocalPublishMethod.LOCAL_PUBLISH_METHOD.equals(method) && module != null && module.length > 0
&& PackageModuleFactory.MODULE_TYPE.equals(module[0].getModuleType().getId()))
return true;
return false;
}
- public IStatus publishModule(
- IJBossServerPublishMethod method,
- IServer server, IModule[] module,
- int publishType, IModuleResourceDelta[] delta,
- IProgressMonitor monitor)
- throws CoreException {
- listener = new FileUtilListener();
- this.server = ServerConverter.getDeployableServer(server);
- this.delta = delta;
- IModule module2 = module[0];
-
- try {
- // if it's being removed
- if( publishType == REMOVE_PUBLISH ) {
- removeModule(module2, monitor);
- } else if( publishType == FULL_PUBLISH ) {
- publishModule(module2, false, monitor);
- } else if( publishType == INCREMENTAL_PUBLISH ) {
- publishModule(module2, true, monitor);
- }
- }catch(Exception e) {
- IStatus status = new Status(IStatus.ERROR, IntegrationPlugin.PLUGIN_ID,
- NLS.bind(Messages.ErrorDuringPublish, module2.getName()), e);
- return status;
- }
-
- if( listener.getStatuses().length > 0 ) {
- MultiStatus ms = new MultiStatus(IntegrationPlugin.PLUGIN_ID, IStatus.ERROR,
- NLS.bind(Messages.ErrorDuringPublish, module2.getName()), null);
- for( int i = 0; i < listener.getStatuses().length; i++ ) {
- ms.add(listener.getStatuses()[i]);
- }
- return ms;
- }
-
- IStatus ret = new Status(IStatus.OK, IntegrationPlugin.PLUGIN_ID,
- NLS.bind(Messages.PublishSuccessful, module2.getName()));
- return ret;
- }
-
- protected void removeModule(IModule module, IProgressMonitor monitor) {
- IArchive pack = getPackage(module);
- // remove all of the deployed items
- if( pack != null ) {
- IPath sourcePath = pack.getArchiveFilePath();
- IModule[] tree = new IModule[] { module };
- IPath destPath = PublishUtil.getDeployPath(tree, server);
- IPath destPath2 = destPath.append(sourcePath.lastSegment());
- // remove the entire file or folder
- FileUtil.safeDelete(destPath2.toFile(), listener);
- }
- }
-
-
-
- protected void publishModule(IModule module, boolean incremental, IProgressMonitor monitor) {
- IArchive pack = getPackage(module);
- IPath sourcePath = pack.getArchiveFilePath();
- IModule[] tree = new IModule[] { module };
- IPath destPathRoot = PublishUtil.getDeployPath(tree, server);
-
- // if destination is deploy directory... no need to re-copy!
- if( destPathRoot.toOSString().equals(PathUtils.getGlobalLocation(pack).toOSString())) {
- // fire null publish event
- return;
- }
-
- if( !incremental || !pack.isExploded() ) { // full publish, or zipped
- // full publish, copy whole folder or file
- FileUtil.fileSafeCopy(sourcePath.toFile(), destPathRoot.toFile(), listener);
- } else if( destPathRoot.toFile().exists() && destPathRoot.toFile().isFile()) {
- FileUtil.fileSafeCopy(sourcePath.toFile(), destPathRoot.toFile(), listener);
- } else {
- publishFromDelta(module, destPathRoot, sourcePath.removeLastSegments(1), delta);
- }
- }
-
- protected void publishFromDelta(IModule module, IPath destPathRoot, IPath sourcePrefix,
- IModuleResourceDelta[] delta) {
- ArrayList<IPath> changedFiles = new ArrayList<IPath>();
- for( int i = 0; i < delta.length; i++ ) {
- publishFromDeltaHandle(delta[i], destPathRoot, sourcePrefix, changedFiles);
- }
- }
-
- protected void publishFromDeltaHandle(IModuleResourceDelta delta, IPath destRoot,
- IPath sourcePrefix, ArrayList<IPath> changedFiles) {
- IModuleResource imr = delta.getModuleResource();
- File f = (File)imr.getAdapter(File.class);
- if( f != null ) {
- IPath destPath = destRoot.append(imr.getModuleRelativePath()).append(imr.getName());
- switch( delta.getKind()) {
- case IModuleResourceDelta.REMOVED:
- FileUtil.safeDelete(destPath.toFile(), listener);
- return;
- case IModuleResourceDelta.ADDED:
- FileUtil.fileSafeCopy(f, destPath.toFile(), listener);
- return;
- case IModuleResourceDelta.CHANGED:
- FileUtil.fileSafeCopy(f, destPath.toFile(), listener);
- break;
- }
- }
- IModuleResourceDelta[] children = delta.getAffectedChildren();
- if( children != null ) {
- for( int i = 0; i < children.length; i++ ) {
- publishFromDeltaHandle(children[i], destRoot, sourcePrefix, changedFiles);
- }
- }
- }
-
- protected IArchive getPackage(IModule module) {
- PackagedModuleDelegate delegate = (PackagedModuleDelegate)module.loadAdapter(PackagedModuleDelegate.class, new NullProgressMonitor());
- return delegate == null ? null : delegate.getPackage();
- }
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/WTPZippedPublisher.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/WTPZippedPublisher.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.archives.webtools/src/org/jboss/ide/eclipse/archives/webtools/modules/WTPZippedPublisher.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -1,3 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2010 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
+ *
+ * TODO: Logging and Progress Monitors
+ ******************************************************************************/
package org.jboss.ide.eclipse.archives.webtools.modules;
import org.eclipse.core.runtime.CoreException;
@@ -16,36 +28,45 @@
import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
import org.jboss.ide.eclipse.as.core.util.ServerConverter;
-public class WTPZippedPublisher extends PublishUtil implements IJBossServerPublisher {
+public class WTPZippedPublisher implements IJBossServerPublisher {
private int moduleState = IServer.PUBLISH_STATE_NONE;
public boolean accepts(String method, IServer server, IModule[] module) {
IDeployableServer ds = ServerConverter.getDeployableServer(server);
IModule lastMod = (module == null || module.length == 0 ) ? null : module[module.length -1];
- if( LocalPublishMethod.LOCAL_PUBLISH_METHOD.equals(method) && lastMod == null)
+ if( getPublishMethod().equals(method) && lastMod == null)
return true;
- return LocalPublishMethod.LOCAL_PUBLISH_METHOD.equals(method)
+ return getPublishMethod().equals(method)
&& ModuleCoreNature.isFlexibleProject(lastMod.getProject())
&& ds != null && ds.zipsWTPDeployments();
}
+
+ protected String getPublishMethod() {
+ return LocalPublishMethod.LOCAL_PUBLISH_METHOD;
+ }
public int getPublishState() {
return moduleState;
}
+ protected String getDeployRoot(IModule[] module, IDeployableServer ds) {
+ String deployRoot = PublishUtil.getDeployRootFolder(
+ module, ds, ds.getDeployFolder(),
+ IJBossToolingConstants.LOCAL_DEPLOYMENT_LOC);
+ return deployRoot;
+ }
+
public IStatus publishModule(
IJBossServerPublishMethod method,
IServer server, IModule[] module,
int publishType, IModuleResourceDelta[] delta,
IProgressMonitor monitor) throws CoreException {
+ // Build all parts together at once.
+ // When a call for [ear, childWar] comes in, ignore it.
if( module.length > 1 ) {
return Status.OK_STATUS;
}
-
IDeployableServer ds = ServerConverter.getDeployableServer(server);
- String deployRoot = PublishUtil.getDeployRootFolder(
- module, ds, ds.getDeployFolder(),
- IJBossToolingConstants.LOCAL_DEPLOYMENT_LOC);
-
+ String deployRoot = getDeployRoot(module, ds);
LocalZippedPublisherUtil util = new LocalZippedPublisherUtil();
return util.publishModule(server, deployRoot, module, publishType, delta, monitor);
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/ExtensionManager.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/ExtensionManager.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/ExtensionManager.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -11,6 +11,7 @@
package org.jboss.ide.eclipse.as.core;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
@@ -24,9 +25,11 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethodType;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
import org.jboss.ide.eclipse.as.core.server.IPollerFailureHandler;
import org.jboss.ide.eclipse.as.core.server.IServerStatePoller;
+import org.jboss.ide.eclipse.as.core.server.internal.ServerPublishMethodType;
import org.jboss.ide.eclipse.as.core.server.internal.ServerStatePollerType;
/**
@@ -147,7 +150,8 @@
PublisherWrapper wrapper;
while(i.hasNext()) {
wrapper = i.next();
- if( wrapper.publisher.accepts(deployMethod, server, module))
+ IJBossServerPublisher publisher = wrapper.publisher;
+ if( publisher.accepts(deployMethod, server, module))
return wrapper.getNewInstance();
}
return null;
@@ -182,6 +186,7 @@
} catch( NumberFormatException nfe) {}
publishers.add(new PublisherWrapper(p, zipDelegate, (IJBossServerPublisher)clazz, cf[i]));
} catch( CoreException e ) {
+ e.printStackTrace();
} catch( ClassCastException cce ) {
}
}
@@ -214,4 +219,40 @@
return publisher;
}
}
+
+ private ServerPublishMethodType[] publishMethodTypes;
+ public ServerPublishMethodType[] getPublishMethodTypes() {
+ if(publishMethodTypes == null )
+ publishMethodTypes = loadPublishMethodTypes();
+ return publishMethodTypes;
+ }
+
+ public ServerPublishMethodType[] loadPublishMethodTypes() {
+ ArrayList<ServerPublishMethodType> types = new ArrayList<ServerPublishMethodType>();
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] cf = registry.getConfigurationElementsFor(JBossServerCorePlugin.PLUGIN_ID, "publishMethod"); //$NON-NLS-1$
+ for( int i = 0; i < cf.length; i++ ) {
+ types.add(new ServerPublishMethodType(cf[i]));
+ }
+ return types.toArray(new ServerPublishMethodType[types.size()]);
+ }
+
+ public IJBossServerPublishMethodType getPublishMethod(String id) {
+ ServerPublishMethodType[] publishMethods = getPublishMethodTypes();
+ for( int i = 0; i < publishMethods.length; i++ )
+ if( publishMethods[i].getId().equals(id))
+ return publishMethods[i];
+ return null;
+ }
+
+ public IJBossServerPublishMethodType[] findPossiblePublishMethods(IServer server) {
+ ArrayList<IJBossServerPublishMethodType> list = new ArrayList<IJBossServerPublishMethodType>();
+ list.addAll(Arrays.asList(getPublishMethodTypes()));
+ Iterator<IJBossServerPublishMethodType> i = list.iterator();
+ while(i.hasNext()) {
+ if( !i.next().accepts(server.getServerType().getId()))
+ i.remove();
+ }
+ return list.toArray(new IJBossServerPublishMethodType[list.size()]);
+ }
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/extensions/polling/ProcessTerminatedPoller.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/extensions/polling/ProcessTerminatedPoller.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/extensions/polling/ProcessTerminatedPoller.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -14,9 +14,11 @@
import java.util.Properties;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.debug.core.model.IProcess;
import org.eclipse.wst.server.core.IServer;
import org.jboss.ide.eclipse.as.core.server.IServerStatePoller;
import org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior;
+import org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior.JBossBehaviourDelegate;
import org.jboss.ide.eclipse.as.core.server.internal.PollThread;
import org.jboss.ide.eclipse.as.core.server.internal.ServerStatePollerType;
@@ -32,7 +34,11 @@
public class ProcessTerminatedPoller implements IServerStatePoller {
public static final String POLLER_ID = "org.jboss.ide.eclipse.as.core.runtime.server.processTerminatedPoller"; //$NON-NLS-1$
+ public static interface IProcessProvider {
+ public IProcess getProcess();
+ }
+
private ServerStatePollerType type;
private JBossServerBehavior server;
public void beginPolling(IServer server, boolean expectedState,
@@ -55,7 +61,12 @@
}
public boolean isComplete() throws PollingException {
- return server.getProcess() == null || server.getProcess().isTerminated();
+ JBossBehaviourDelegate del = server.getDelegate();
+ if( del instanceof IProcessProvider ) {
+ IProcess p = ((IProcessProvider)del).getProcess();
+ return p == null || p.isTerminated();
+ }
+ return true;
}
public void failureHandled(Properties properties) {
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/modules/SingleDeployableFactory.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/modules/SingleDeployableFactory.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/modules/SingleDeployableFactory.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -55,6 +55,7 @@
import org.jboss.ide.eclipse.as.core.Messages;
import org.jboss.ide.eclipse.as.core.server.UnitedServerListener;
import org.jboss.ide.eclipse.as.core.server.UnitedServerListenerManager;
+import org.jboss.ide.eclipse.as.wtp.core.modules.IJBTModule;
import org.osgi.service.prefs.BackingStoreException;
/**
@@ -277,7 +278,7 @@
return moduleToDelegate.get(module);
}
- public class SingleDeployableModuleDelegate extends ModuleDelegate {
+ public class SingleDeployableModuleDelegate extends ModuleDelegate implements IJBTModule {
private IPath global;
private IPath workspaceRelative;
public SingleDeployableModuleDelegate(IPath workspaceRelative) {
@@ -291,9 +292,9 @@
public IModuleResource[] members() throws CoreException {
return new IModuleResource[] {
- new ModuleFile(global.lastSegment(),
- new Path(global.lastSegment()),
- global.toFile().lastModified()) };
+ new ModuleFile(global.toFile(),
+ global.lastSegment(),
+ global.removeLastSegments(1)) };
}
public IStatus validate() {
@@ -307,6 +308,15 @@
public IPath getWorkspaceRelativePath() {
return workspaceRelative;
}
+ public IModule[] getModules() {
+ return new IModule[0]; // no children
+ }
+ public String getURI(IModule module) {
+ return null; // never called
+ }
+ public boolean isBinary() {
+ return true;
+ }
}
public class FileDeletionListener implements IResourceChangeListener, IResourceDeltaVisitor {
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractJSTPublisher.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractJSTPublisher.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractJSTPublisher.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.core.publishers;
+
+import org.eclipse.wst.common.componentcore.ModuleCoreNature;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+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.util.ServerConverter;
+
+public abstract class AbstractJSTPublisher extends AbstractServerToolsPublisher {
+ public AbstractJSTPublisher() {}
+
+ /**
+ * This abstract publisher is only suitable for non force-zipped deployments
+ */
+ public boolean accepts(String method, IServer server, IModule[] module) {
+ if( module == null || !method.equals(getTargetedPublishMethodId()))
+ return false;
+ IDeployableServer ds = ServerConverter.getDeployableServer(server);
+ return ds != null
+ && ModuleCoreNature.isFlexibleProject(module[0].getProject())
+ && !ds.zipsWTPDeployments();
+ }
+
+ /**
+ * Get the publish method this publisher is associated with
+ * @return
+ */
+ protected abstract String getTargetedPublishMethodId();
+
+ /**
+ * JST projects require certain children (utility, etc) to be zipped up
+ */
+ @Override
+ protected boolean forceZipModule(IModule[] moduleTree) {
+ return PublishUtil.deployPackaged(moduleTree);
+ }
+}
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractPublishMethod.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractPublishMethod.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractPublishMethod.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.core.publishers;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+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;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethodType;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
+import org.jboss.ide.eclipse.as.core.server.internal.DeployableServerBehavior;
+
+public abstract class AbstractPublishMethod implements IJBossServerPublishMethod {
+ public abstract String getPublishMethodId();
+ public IJBossServerPublishMethodType getPublishMethodType() {
+ return ExtensionManager.getDefault().getPublishMethod(getPublishMethodId());
+ }
+ public void publishStart(DeployableServerBehavior behaviour,
+ IProgressMonitor monitor) throws CoreException {
+ }
+
+ public int publishFinish(DeployableServerBehavior behaviour,
+ IProgressMonitor monitor) throws CoreException {
+ IModule[] modules = behaviour.getServer().getModules();
+ boolean allpublished= true;
+ for (int i = 0; i < modules.length; i++) {
+ if(behaviour.getServer().getModulePublishState(new IModule[]{modules[i]})!=IServer.PUBLISH_STATE_NONE)
+ allpublished=false;
+ }
+ return allpublished ? IServer.PUBLISH_STATE_NONE : IServer.PUBLISH_STATE_INCREMENTAL;
+ }
+
+ public int getServerPublishState(DeployableServerBehavior behaviour) {
+ IModule[] modules = behaviour.getServer().getModules();
+ boolean allpublished= true;
+ for (int i = 0; i < modules.length; i++) {
+ if(behaviour.getServer().getModulePublishState(new IModule[]{modules[i]})!=IServer.PUBLISH_STATE_NONE)
+ allpublished=false;
+ }
+ if(allpublished)
+ return IServer.PUBLISH_STATE_NONE;
+ return IServer.PUBLISH_STATE_INCREMENTAL;
+ }
+
+ public int publishModule(DeployableServerBehavior behaviour, int kind,
+ int deltaKind, IModule[] module, IProgressMonitor monitor)
+ throws CoreException {
+ // kind = [incremental, full, auto, clean] = [1,2,3,4]
+ // delta = [no_change, added, changed, removed] = [0,1,2,3]
+ if( module.length == 0 ) return IServer.PUBLISH_STATE_NONE;
+ int modulePublishState = behaviour.getServer().getModulePublishState(module);
+ int publishType = behaviour.getPublishType(kind, deltaKind, modulePublishState);
+ IJBossServerPublisher publisher;
+
+ // Let the publisher decide what to do
+ if( module.length > 0 ) {
+ publisher = ExtensionManager.getDefault().getPublisher(behaviour.getServer(), module, getPublishMethodId());
+ IModuleResourceDelta[] deltas = new IModuleResourceDelta[]{};
+ if( deltaKind != ServerBehaviourDelegate.REMOVED)
+ deltas = behaviour.getPublishedResourceDelta(module);
+ if( publisher != null ) {
+ try {
+ IStatus result = publisher.publishModule(
+ this,
+ behaviour.getServer(), module,
+ publishType, deltas, monitor);
+ if( result != null )
+ ServerLogger.getDefault().log(behaviour.getServer(), result);
+ } catch( CoreException ce) {
+ // Let the user know
+ ServerLogger.getDefault().log(behaviour.getServer(), ce.getStatus());
+ throw ce;
+ }
+ return publisher.getPublishState();
+ }
+ return IServer.PUBLISH_STATE_INCREMENTAL;
+ }
+ return IServer.PUBLISH_STATE_NONE;
+ }
+}
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractServerToolsPublisher.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractServerToolsPublisher.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractServerToolsPublisher.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -0,0 +1,290 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.core.publishers;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+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.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.wst.common.project.facet.core.util.internal.ProgressMonitorUtil;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.model.IModuleResource;
+import org.eclipse.wst.server.core.model.IModuleResourceDelta;
+import org.eclipse.wst.server.core.util.ModuleFile;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+import org.jboss.ide.eclipse.as.core.Messages;
+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.IJBossServerConstants;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
+import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil;
+import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
+import org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader;
+import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+import org.jboss.ide.eclipse.as.wtp.core.util.ServerModelUtilities;
+
+/**
+ * Class suitable for parsing any properly formed servertools-api module
+ */
+public abstract class AbstractServerToolsPublisher implements IJBossServerPublisher {
+ protected IModuleResourceDelta[] delta;
+ protected IDeployableServer server;
+ protected int publishState = IServer.PUBLISH_STATE_NONE;
+ protected IJBossServerPublishMethod publishMethod;
+
+ public AbstractServerToolsPublisher() {}
+ public abstract boolean accepts(String method, IServer server, IModule[] module);
+
+ public int getPublishState() {
+ return publishState;
+ }
+
+ protected void setPublishState(int state) {
+ this.publishState = state;
+ }
+
+ public IStatus publishModule(IJBossServerPublishMethod method,
+ IServer server, IModule[] module, int publishType,
+ IModuleResourceDelta[] delta, IProgressMonitor monitor)
+ throws CoreException {
+ IStatus status = null;
+ this.server = ServerConverter.getDeployableServer(server);
+ this.delta = delta;
+ this.publishMethod = method;
+
+ boolean deleted = false;
+ for( int i = 0; i < module.length; i++ ) {
+ if( module[i].isExternal() )
+ deleted = true;
+ }
+
+ // Monitor at this point has been begun with 1000 monitor
+ IProgressMonitor subMon = ProgressMonitorUtil.submon(monitor, 1000);
+ if (publishType == REMOVE_PUBLISH ) {
+ status = unpublish(this.server, module, subMon);
+ } else {
+ if( deleted ) {
+ publishState = IServer.PUBLISH_STATE_UNKNOWN;
+ } else {
+ if (publishType == FULL_PUBLISH ) {
+ status = fullPublish(module, module[module.length-1], subMon);
+ } else if (publishType == INCREMENTAL_PUBLISH) {
+ status = incrementalPublish(module, module[module.length-1], subMon);
+ }
+ }
+ }
+ return status;
+ }
+
+ /**
+ * Gets the actual deploy path for this module
+ *
+ * @param moduleTree
+ * @param server
+ * @return
+ */
+ protected IPath getDeployPath(IModule[] moduleTree, IDeployableServer server) {
+ String folder = PublishUtil.getDeployRootFolder(
+ moduleTree, server,
+ publishMethod.getPublishDefaultRootFolder(server.getServer()),
+ IJBossToolingConstants.LOCAL_DEPLOYMENT_LOC);
+ return PublishUtil.getDeployPath(moduleTree, folder);
+ }
+
+ /**
+ * Finish up the publishing. This may be moving a final zipped entity into the proper
+ * folder or sending it over the wire to a remote machine.
+ *
+ * Subclasses may override
+ *
+ * @param publishType
+ * @param moduleTree
+ * @param server
+ * @param monitor
+ */
+ protected void finishPublish(int publishType, IModule[] moduleTree, IDeployableServer server, IProgressMonitor monitor){}
+
+ private IPublishCopyCallbackHandler getCallbackHandler(IPath path) {
+ return publishMethod.getCallbackHandler(path, server.getServer());
+ }
+
+ /**
+ * For certain module trees, some publishers may want to force a child to be zipped.
+ * For example, JST Publisher may want to force utility project children to be zipped.
+ *
+ * @param moduleTree
+ * @return
+ */
+ protected boolean forceZipModule(IModule[] moduleTree) {
+ return false;
+ }
+
+ protected IStatus canceledStatus() {
+ return new Status(IStatus.CANCEL, JBossServerCorePlugin.PLUGIN_ID, "Publish Canceled"); //$NON-NLS-1$
+ }
+
+ protected IStatus fullPublish(IModule[] moduleTree, IModule module, IProgressMonitor monitor) throws CoreException {
+ monitor.beginTask("Full Publish", 1000); //$NON-NLS-1$
+
+ IPath deployPath = getDeployPath(moduleTree, server);
+ IPublishCopyCallbackHandler callback = getCallbackHandler(deployPath);
+ IModuleResource[] members = PublishUtil.getResources(module, ProgressMonitorUtil.submon(monitor, 200));
+
+ if( monitor.isCanceled())
+ return canceledStatus();
+
+ // First delete it
+ // if the module we're publishing is a project, not a binary, clean it's folder
+ if( !(new Path(module.getName()).segmentCount() > 1 ))
+ callback.deleteResource(new Path("/"), ProgressMonitorUtil.submon(monitor, 100)); //$NON-NLS-1$
+
+ if( monitor.isCanceled())
+ return canceledStatus();
+
+ ArrayList<IStatus> list = new ArrayList<IStatus>();
+
+ boolean isBinaryObject = ServerModelUtilities.isBinaryModule(module);
+ boolean forceZip = forceZipModule(moduleTree);
+
+ if( !forceZip && !isBinaryObject) {
+ PublishCopyUtil util = new PublishCopyUtil(callback);
+ list.addAll(Arrays.asList(util.publishFull(members, ProgressMonitorUtil.submon(monitor, 700))));
+ } else if( isBinaryObject )
+ list.addAll(Arrays.asList(copyBinaryModule(moduleTree, ProgressMonitorUtil.submon(monitor, 700))));
+ else {
+ // A child that must be zipped, forceZip is true
+ IPath deployRoot = JBossServerCorePlugin.getServerStateLocation(server.getServer()).
+ append(IJBossServerConstants.TEMP_DEPLOY).makeAbsolute();
+
+ try {
+ File temp = deployRoot.toFile().createTempFile(module.getName(), ".tmp", deployRoot.toFile()); //$NON-NLS-1$
+ IPath tempFile = new Path(temp.getAbsolutePath());
+ list.addAll(Arrays.asList(PublishUtil.packModuleIntoJar(moduleTree[moduleTree.length-1], tempFile)));
+ IPublishCopyCallbackHandler handler = getCallbackHandler(new Path("/")); //$NON-NLS-1$
+ String parentFolder = deployPath.removeLastSegments(1).toString();
+ handler.makeDirectoryIfRequired(new Path(parentFolder), ProgressMonitorUtil.submon(monitor, 200));
+ ModuleFile mf = new ModuleFile(tempFile.toFile(), tempFile.lastSegment(), tempFile);
+ handler.copyFile(mf, deployPath, ProgressMonitorUtil.submon(monitor, 500));
+ } catch( IOException ioe) {
+ list.add(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, ioe.getMessage(), ioe));
+ }
+ }
+
+ monitor.done();
+ if( list.size() > 0 )
+ return createMultiStatus(list, module);
+ return Status.OK_STATUS;
+ }
+
+ protected IStatus incrementalPublish(IModule[] moduleTree, IModule module, IProgressMonitor monitor) throws CoreException {
+ monitor.beginTask("Incremental Publish", 100); //$NON-NLS-1$
+ IStatus[] results = new IStatus[] {};
+ IPath deployPath = getDeployPath(moduleTree, server);
+ boolean isBinaryObject = ServerModelUtilities.isBinaryModule(module);
+ boolean forceZip = forceZipModule(moduleTree);
+ if( !forceZip && !isBinaryObject) {
+ IPublishCopyCallbackHandler handler = getCallbackHandler(deployPath);
+ results = new PublishCopyUtil(handler).publishDelta(delta, ProgressMonitorUtil.submon(monitor, 100));
+ } else if( delta.length > 0 ) {
+ if( isBinaryObject)
+ results = copyBinaryModule(moduleTree, ProgressMonitorUtil.submon(monitor, 100));
+ else {
+ // forceZip a child module
+ IPath localDeployRoot = JBossServerCorePlugin.getServerStateLocation(server.getServer()).
+ append(IJBossServerConstants.TEMP_DEPLOY).makeAbsolute();
+ try {
+ File temp = File.createTempFile(module.getName(), ".tmp", localDeployRoot.toFile()); //$NON-NLS-1$
+ IPath tempFile = new Path(temp.getAbsolutePath());
+ PublishUtil.packModuleIntoJar(moduleTree[moduleTree.length-1], tempFile);
+ IPublishCopyCallbackHandler handler = getCallbackHandler(new Path("/")); //$NON-NLS-1$
+ String parentFolder = deployPath.removeLastSegments(1).toString();
+ handler.makeDirectoryIfRequired(new Path(parentFolder), ProgressMonitorUtil.submon(monitor, 50));
+ ModuleFile mf = new ModuleFile(tempFile.toFile(), tempFile.lastSegment(), tempFile);
+ handler.copyFile(mf, deployPath, ProgressMonitorUtil.submon(monitor, 50));
+ } catch( IOException ioe) {
+ IStatus s = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, ioe.getMessage(), ioe);
+ results = new IStatus[] { s };
+ }
+ }
+ }
+
+ monitor.done();
+ if( results != null && results.length > 0 ) {
+ MultiStatus ms = new MultiStatus(JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_INC_FAIL,
+ NLS.bind(Messages.IncrementalPublishFail, module.getName()), null);
+ for( int i = 0; i < results.length; i++ )
+ ms.add(results[i]);
+ return ms;
+ }
+
+ IStatus ret = new Status(IStatus.OK, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_FULL_SUCCESS,
+ NLS.bind(Messages.CountModifiedMembers, PublishUtil.countChanges(delta), module.getName()), null);
+ return ret;
+ }
+
+ protected IStatus createMultiStatus(List<IStatus> list, IModule module) {
+ MultiStatus ms = new MultiStatus(JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_FULL_FAIL,
+ NLS.bind(Messages.FullPublishFail, module.getName()), null);
+ for( int i = 0; i < list.size(); i++ )
+ ms.add(list.get(i));
+ return ms;
+ }
+
+ protected IStatus[] copyBinaryModule(IModule[] moduleTree, IProgressMonitor monitor) {
+ monitor.beginTask("Copy Binary Module", 100); //$NON-NLS-1$
+ try {
+ IPath destinationPath = getDeployPath(moduleTree, server);
+ IModuleResource[] members = PublishUtil.getResources(moduleTree);
+ File source = PublishUtil.getFile(members[0]);
+ if( source != null ) {
+ IPublishCopyCallbackHandler handler = getCallbackHandler(new Path("/")); //$NON-NLS-1$
+ IPath localFilePath = new Path(source.getAbsolutePath());
+ ModuleFile mf = new ModuleFile(localFilePath.toFile(), localFilePath.lastSegment(), localFilePath);
+ handler.copyFile(mf, destinationPath, new NullProgressMonitor());
+ } else {
+// IStatus s = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_COPY_BINARY_FAIL,
+// NLS.bind(Messages.CouldNotPublishModule,
+// moduleTree[moduleTree.length-1]), null);
+// return new IStatus[] {s};
+ // TODO
+ }
+ } catch( CoreException ce ) {
+ return new IStatus[] {ce.getStatus()};
+ }
+ monitor.done();
+ return new IStatus[]{Status.OK_STATUS};
+ }
+
+ protected IStatus unpublish(IDeployableServer jbServer, IModule[] module,
+ IProgressMonitor monitor) throws CoreException {
+ monitor.beginTask("Begin Unpublish", 100); //$NON-NLS-1$
+ IPath remotePath = getDeployPath(module, server);
+ IPublishCopyCallbackHandler handler = getCallbackHandler(new Path("/")); //$NON-NLS-1$
+ handler.deleteResource(remotePath, ProgressMonitorUtil.submon(monitor, 100));
+ monitor.done();
+ return Status.OK_STATUS;
+ }
+}
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 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/JstPublisher.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
+ * Copyright (c) 2010 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,
@@ -10,248 +10,9 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.core.publishers;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Arrays;
-import org.eclipse.core.runtime.Assert;
-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.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.wst.server.core.IModule;
-import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.model.IModuleResource;
-import org.eclipse.wst.server.core.model.IModuleResourceDelta;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.Messages;
-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.IJBossServerPublishMethod;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
-import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil;
-import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.LocalCopyCallback;
-import org.jboss.ide.eclipse.as.core.util.FileUtil;
-import org.jboss.ide.eclipse.as.core.util.FileUtil.FileUtilListener;
-import org.jboss.ide.eclipse.as.core.util.FileUtil.IFileUtilListener;
-import org.jboss.ide.eclipse.as.core.util.ServerConverter;
-import org.jboss.ide.eclipse.as.wtp.core.util.ServerModelUtilities;
-
-/**
- * This class provides a default implementation for packaging different types of
- * flexible projects. It uses the built-in heirarchy of the projects to do so.
- *
- * @author rob.stryker at jboss.com
- */
-public class JstPublisher extends PublishUtil implements IJBossServerPublisher {
-
-
- protected IModuleResourceDelta[] delta;
- protected IDeployableServer server;
- protected int publishState = IServer.PUBLISH_STATE_NONE;
-
-
- public JstPublisher() {
+public class JstPublisher extends AbstractJSTPublisher {
+ protected String getTargetedPublishMethodId() {
+ return LocalPublishMethod.LOCAL_PUBLISH_METHOD;
}
-
- public boolean accepts(String type, IServer server, IModule[] module) {
- IDeployableServer ds = ServerConverter.getDeployableServer(server);
- boolean shouldAccept = ds != null && LocalPublishMethod.LOCAL_PUBLISH_METHOD.equals(type)
- && !ds.zipsWTPDeployments()
- && PublishUtil.isModuleCoreProject(module);
- return shouldAccept;
- }
-
- public IStatus publishModule(
- IJBossServerPublishMethod method,
- IServer server, IModule[] module,
- int publishType, IModuleResourceDelta[] delta,
- IProgressMonitor monitor) throws CoreException {
- IStatus status = null;
- this.server = ServerConverter.getDeployableServer(server);
- this.delta = delta;
-
- boolean deleted = false;
- for( int i = 0; i < module.length; i++ ) {
- if( module[i].isExternal() )
- deleted = true;
- }
-
- if (publishType == REMOVE_PUBLISH ) {
- status = unpublish(this.server, module, monitor);
- } else {
- if( deleted ) {
- publishState = IServer.PUBLISH_STATE_UNKNOWN;
- } else {
- if (publishType == FULL_PUBLISH ) {
- status = fullPublish(module, module[module.length-1], monitor);
- } else if (publishType == INCREMENTAL_PUBLISH) {
- if(getDeployPath(module, this.server).toFile().isDirectory()) {
- status = incrementalPublish(module, module[module.length-1], monitor);
- } else {
- status =fullPublish(module, module[module.length-1], monitor);
- }
- }
- }
- }
- return status;
- }
-
-
- protected IStatus fullPublish(IModule[] moduleTree, IModule module, IProgressMonitor monitor) throws CoreException {
- IPath deployPath = getDeployPath(moduleTree, server);
- IPath tempDeployPath = getTempDeployFolder(moduleTree, server);
- IModuleResource[] members = getResources(module);
-
- ArrayList<IStatus> list = new ArrayList<IStatus>();
- boolean isBinary = ServerModelUtilities.isBinaryModule(module);
- boolean delete = true;
- if (isBinary) {
- delete = false;
- }
- // if the module we're publishing is a project, not a binary, clean it's folder
- if( !(new Path(module.getName()).segmentCount() > 1 ) && delete)
- list.addAll(Arrays.asList(localSafeDelete(deployPath)));
-
- if( !deployPackaged(moduleTree) && !isBinary) {
- LocalCopyCallback handler = new LocalCopyCallback(server.getServer(), deployPath, tempDeployPath);
- PublishCopyUtil util = new PublishCopyUtil(handler);
- list.addAll(Arrays.asList(util.publishFull(members, monitor)));
- }
- else if(isBinary)
- list.addAll(Arrays.asList(copyBinaryModule(moduleTree)));
- else
- list.addAll(Arrays.asList(packModuleIntoJar(moduleTree[moduleTree.length-1], deployPath)));
-
-
- touchXMLFiles(deployPath, module);
-
- if( list.size() > 0 ) {
- MultiStatus ms = new MultiStatus(JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_FULL_FAIL,
- NLS.bind(Messages.FullPublishFail, module.getName()), null);
- for( int i = 0; i < list.size(); i++ )
- ms.add(list.get(i));
- return ms;
- }
-
- publishState = IServer.PUBLISH_STATE_NONE;
- IStatus ret = new Status(IStatus.OK, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_FULL_SUCCESS,
- NLS.bind(Messages.CountModifiedMembers, countMembers(module), module.getName()), null);
- return ret;
- }
-
- private void touchXMLFiles(IPath deployPath, IModule module) {
- JSTPublisherXMLToucher.getInstance().touch(deployPath, module);
- }
-
- protected IStatus incrementalPublish(IModule[] moduleTree, IModule module, IProgressMonitor monitor) throws CoreException {
- IStatus[] results = new IStatus[] {};
- IPath deployPath = getDeployPath(moduleTree, server);
- IPath tempDeployPath = getTempDeployFolder(moduleTree, server);
- boolean isBinary = ServerModelUtilities.isBinaryModule(module);
- LocalCopyCallback handler = null;
- if( !deployPackaged(moduleTree) && !isBinary) {
- handler = new LocalCopyCallback(server.getServer(), deployPath, tempDeployPath);
- results = new PublishCopyUtil(handler).publishDelta(delta, monitor);
- } else if( delta.length > 0 ) {
- if( isBinary)
- results = copyBinaryModule(moduleTree);
- else
- results = packModuleIntoJar(moduleTree[moduleTree.length-1], deployPath);
- }
- if( results != null && results.length > 0 ) {
- MultiStatus ms = new MultiStatus(JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_INC_FAIL,
- NLS.bind(Messages.IncrementalPublishFail, module.getName()), null);
- for( int i = 0; i < results.length; i++ )
- ms.add(results[i]);
- return ms;
- }
-
- if( handler != null && handler.shouldRestartModule() )
- touchXMLFiles(deployPath, module);
-
- IStatus ret = new Status(IStatus.OK, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_FULL_SUCCESS,
- NLS.bind(Messages.CountModifiedMembers, countChanges(delta), module.getName()), null);
- return ret;
- }
-
- protected IStatus unpublish(IDeployableServer jbServer, IModule[] module,
- IProgressMonitor monitor) throws CoreException {
- IModule mod = module[module.length-1];
- IStatus[] errors = localSafeDelete(getDeployPath(module, server));
- if( errors.length > 0 ) {
- publishState = IServer.PUBLISH_STATE_FULL;
- MultiStatus ms = new MultiStatus(JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_REMOVE_FAIL,
- NLS.bind(Messages.DeleteModuleFail, mod.getName()),
- new Exception(Messages.DeleteModuleFail2));
- for( int i = 0; i < errors.length; i++ )
- ms.addAll(errors[i]);
- throw new CoreException(ms);
- }
- IStatus ret = new Status(IStatus.OK, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_REMOVE_SUCCESS,
- NLS.bind(Messages.ModuleDeleted, mod.getName()), null);
- return ret;
- }
-
-
-
- protected IStatus[] copyBinaryModule(IModule[] moduleTree) {
- try {
- IPath deployPath = getDeployPath(moduleTree, server);
- FileUtilListener listener = new FileUtilListener();
- IModuleResource[] members = getResources(moduleTree);
- File source = getFile(members[0]);
- if( source != null ) {
- FileUtil.fileSafeCopy(source, deployPath.toFile(), listener);
- return listener.getStatuses();
- } else {
- IStatus s = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_COPY_BINARY_FAIL,
- NLS.bind(Messages.CouldNotPublishModule,
- moduleTree[moduleTree.length-1]), null);
- return new IStatus[] {s};
- }
- } catch( CoreException ce ) {
- IStatus s = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_COPY_BINARY_FAIL,
- NLS.bind(Messages.CouldNotPublishModule,
- moduleTree[moduleTree.length-1]), null);
- return new IStatus[] {s};
- }
- }
- /**
- *
- * @param deployPath
- * @param event
- * @return returns whether an error was found
- */
- protected IStatus[] localSafeDelete(IPath deployPath) {
- String serverDeployFolder = server.getDeployFolder();
- Assert.isTrue(!deployPath.toFile().equals(new Path(serverDeployFolder).toFile()),
- "An attempt to delete your entire deploy folder has been prevented. This should never happen"); //$NON-NLS-1$
- 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,
- NLS.bind(Messages.DeleteFileError, file.getAbsolutePath()),e));
- }
- }
- 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,
- NLS.bind(Messages.DeleteFolderError, file.getAbsolutePath()),e));
- }
- }
- };
- FileUtil.safeDelete(deployPath.toFile(), listener);
- return (IStatus[]) status.toArray(new IStatus[status.size()]);
- }
-
- public int getPublishState() {
- return publishState;
- }
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/LocalPublishMethod.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/LocalPublishMethod.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/LocalPublishMethod.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -1,90 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.ide.eclipse.as.core.publishers;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.wst.server.core.IModule;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
import org.eclipse.wst.server.core.IServer;
-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;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
-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.server.IDeployableServer;
+import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
+import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.LocalCopyCallback;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
-public class LocalPublishMethod implements IJBossServerPublishMethod {
+
+public class LocalPublishMethod extends AbstractPublishMethod {
public static final String LOCAL_PUBLISH_METHOD = "local"; //$NON-NLS-1$
-
+
public String getPublishMethodId() {
return LOCAL_PUBLISH_METHOD;
}
-
- public boolean accepts(String methodType) {
- return getPublishMethodId().equals(methodType);
- }
- public void publishStart(DeployableServerBehavior behaviour,
- IProgressMonitor monitor) throws CoreException {
+ public IPublishCopyCallbackHandler getCallbackHandler(IPath path, IServer server) {
+ IDeployableServer ds = ServerConverter.getDeployableServer(server);
+ String tempDeployPath = ds.getTempDeployFolder();
+ LocalCopyCallback handler = new LocalCopyCallback(server,
+ path, new Path(tempDeployPath));
+ return handler;
}
- public int publishFinish(DeployableServerBehavior behaviour,
- IProgressMonitor monitor) throws CoreException {
- IModule[] modules = behaviour.getServer().getModules();
- boolean allpublished= true;
- for (int i = 0; i < modules.length; i++) {
- if(behaviour.getServer().getModulePublishState(new IModule[]{modules[i]})!=IServer.PUBLISH_STATE_NONE)
- allpublished=false;
- }
- return allpublished ? IServer.PUBLISH_STATE_NONE : IServer.PUBLISH_STATE_INCREMENTAL;
+ public String getPublishDefaultRootFolder(IServer server) {
+ IDeployableServer s = ServerConverter.getDeployableServer(server);
+ return s.getDeployFolder();
}
-
- public int getServerPublishState(DeployableServerBehavior behaviour) {
- IModule[] modules = behaviour.getServer().getModules();
- boolean allpublished= true;
- for (int i = 0; i < modules.length; i++) {
- if(behaviour.getServer().getModulePublishState(new IModule[]{modules[i]})!=IServer.PUBLISH_STATE_NONE)
- allpublished=false;
- }
- if(allpublished)
- return IServer.PUBLISH_STATE_NONE;
- return IServer.PUBLISH_STATE_INCREMENTAL;
- }
-
- public int publishModule(DeployableServerBehavior behaviour, int kind,
- int deltaKind, IModule[] module, IProgressMonitor monitor)
- throws CoreException {
- // kind = [incremental, full, auto, clean] = [1,2,3,4]
- // delta = [no_change, added, changed, removed] = [0,1,2,3]
- if( module.length == 0 ) return IServer.PUBLISH_STATE_NONE;
- int modulePublishState = behaviour.getServer().getModulePublishState(module);
- int publishType = behaviour.getPublishType(kind, deltaKind, modulePublishState);
- IJBossServerPublisher publisher;
-
- // Let the publisher decide what to do
- if( module.length > 0 ) {
- publisher = ExtensionManager.getDefault().getPublisher(behaviour.getServer(), module, getPublishMethodId());
- IModuleResourceDelta[] deltas = new IModuleResourceDelta[]{};
- if( deltaKind != ServerBehaviourDelegate.REMOVED)
- deltas = behaviour.getPublishedResourceDelta(module);
- if( publisher != null ) {
- try {
- IStatus result = publisher.publishModule(
- this,
- behaviour.getServer(), module,
- publishType, deltas, monitor);
- if( result != null )
- ServerLogger.getDefault().log(behaviour.getServer(), result);
- } catch( CoreException ce) {
- // Let the user know
- ServerLogger.getDefault().log(behaviour.getServer(), ce.getStatus());
- throw ce;
- }
- return publisher.getPublishState();
- }
- return IServer.PUBLISH_STATE_INCREMENTAL;
- }
- return IServer.PUBLISH_STATE_NONE;
- }
-
}
Modified: 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 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/PublishUtil.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -17,13 +17,14 @@
import org.eclipse.core.resources.IFile;
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.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.jst.server.core.IEnterpriseApplication;
-import org.eclipse.jst.server.core.IJ2EEModule;
import org.eclipse.wst.common.componentcore.ModuleCoreNature;
+import org.eclipse.wst.common.project.facet.core.util.internal.ProgressMonitorUtil;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.internal.DeletedModule;
import org.eclipse.wst.server.core.model.IModuleFile;
@@ -80,12 +81,28 @@
return count;
}
+ /**
+ * All preferences are stored in the "local" setting as it was decided
+ * having to replicate deploy paths for each publish method was not good
+ *
+ * @param moduleTree
+ * @param server
+ * @param defaultFolder
+ * @param moduleProperty
+ * @return
+ */
public static String getDeployRootFolder(IModule[] moduleTree,
IDeployableServer server, String defaultFolder, String moduleProperty) {
+ return getDeployRootFolder(moduleTree, LocalPublishMethod.LOCAL_PUBLISH_METHOD,
+ server, defaultFolder, moduleProperty);
+ }
+
+ public static String getDeployRootFolder(IModule[] moduleTree, String publishMethod,
+ IDeployableServer server, String defaultFolder, String moduleProperty) {
String folder = defaultFolder;
// TODO bug 286699
DeploymentPreferences prefs = DeploymentPreferenceLoader.loadPreferencesFromServer(server.getServer());
- DeploymentTypePrefs typePrefs = prefs.getOrCreatePreferences("local"); //$NON-NLS-1$
+ DeploymentTypePrefs typePrefs = prefs.getOrCreatePreferences(publishMethod);
DeploymentModulePrefs modPrefs = typePrefs.getModulePrefs(moduleTree[0]);
if( modPrefs != null ) {
String loc = modPrefs.getProperty(moduleProperty);
@@ -129,7 +146,6 @@
IPath root = new Path( deployFolder );
String type, modName, name, uri, suffixedName;
for( int i = 0; i < moduleTree.length; i++ ) {
- IJ2EEModule j2eeModule = (IJ2EEModule) moduleTree[i].loadAdapter(IJ2EEModule.class, null);
type = moduleTree[i].getModuleType().getId();
modName = moduleTree[i].getName();
name = new Path(modName).lastSegment();
@@ -176,6 +192,9 @@
private static String getSuffix(String type) {
+ // TODO
+ // VirtualReferenceUtilities.INSTANCE. has utility methods to help!!
+
String suffix = null;
if( IJBossServerConstants.FACET_EAR.equals(type))
suffix = IJBossServerConstants.EXT_EAR;
@@ -188,6 +207,8 @@
else if( "jboss.package".equals(type)) //$NON-NLS-1$
// no suffix required, name already has it
suffix = ""; //$NON-NLS-1$
+ else if( "jboss.singlefile".equals(type)) //$NON-NLS-1$
+ suffix = ""; //$NON-NLS-1$
else
suffix = IJBossServerConstants.EXT_JAR;
return suffix;
@@ -199,11 +220,19 @@
return ServerModelUtilities.isBinaryModule(lastMod);
}
+ @Deprecated
public static IModuleResource[] getResources(IModule module) throws CoreException {
- ModuleDelegate md = (ModuleDelegate)module.loadAdapter(ModuleDelegate.class, new NullProgressMonitor());
+ return getResources(module, new NullProgressMonitor());
+ }
+
+ public static IModuleResource[] getResources(IModule module, IProgressMonitor monitor) throws CoreException {
+ monitor.beginTask("Fetching Module Resources", 100); //$NON-NLS-1$
+ ModuleDelegate md = (ModuleDelegate)module.loadAdapter(ModuleDelegate.class, ProgressMonitorUtil.submon(monitor, 100));
IModuleResource[] members = md.members();
+ monitor.done();
return members;
}
+
public static IModuleResource[] getResources(IModule[] tree) throws CoreException {
return getResources(tree[tree.length-1]);
}
@@ -234,18 +263,23 @@
* Just package into a jar raw. Don't think about it, just do it
*/
public static IStatus[] packModuleIntoJar(IModule module, IPath destination)throws CoreException {
+ ProjectModule pm = (ProjectModule) module.loadAdapter(ProjectModule.class, null);
+ IModuleResource[] resources = pm.members();
+ return packModuleIntoJar(module.getName(), resources, destination);
+ }
+
+ public static IStatus[] packModuleIntoJar(String moduleName, IModuleResource[] resources, IPath destination)throws CoreException {
+
String dest = destination.toString();
ModulePackager packager = null;
try {
packager = new ModulePackager(dest, false);
- ProjectModule pm = (ProjectModule) module.loadAdapter(ProjectModule.class, null);
- IModuleResource[] resources = pm.members();
for (int i = 0; i < resources.length; i++) {
doPackModule(resources[i], packager);
}
} catch (IOException e) {
IStatus status = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_ASSEMBLE_FAIL,
- "unable to assemble module " + module.getName(), e); //$NON-NLS-1$
+ "unable to assemble module " + moduleName, e); //$NON-NLS-1$
return new IStatus[]{status};
}
finally{
@@ -255,7 +289,7 @@
}
catch(IOException e){
IStatus status = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_ASSEMBLE_FAIL,
- "unable to assemble module "+ module.getName(), e); //$NON-NLS-1$
+ "unable to assemble module "+ moduleName, e); //$NON-NLS-1$
return new IStatus[]{status};
}
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/SingleFilePublisher.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/SingleFilePublisher.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/SingleFilePublisher.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -10,44 +10,11 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.core.publishers;
-import java.io.File;
-import java.util.Date;
-
-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.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.osgi.util.NLS;
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.IModuleResourceDelta;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.Messages;
-import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
import org.jboss.ide.eclipse.as.core.modules.SingleDeployableFactory;
-import org.jboss.ide.eclipse.as.core.modules.SingleDeployableFactory.SingleDeployableModuleDelegate;
-import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
-import org.jboss.ide.eclipse.as.core.util.FileUtil;
-import org.jboss.ide.eclipse.as.core.util.FileUtil.IFileUtilListener;
-import org.jboss.ide.eclipse.as.core.util.ServerConverter;
-public class SingleFilePublisher implements IJBossServerPublisher {
-
- private IDeployableServer server;
- private int publishState = IServer.PUBLISH_STATE_NONE;
- public SingleFilePublisher() {
- }
-
- public int getPublishState() {
- return publishState;
- }
-
+public class SingleFilePublisher extends AbstractServerToolsPublisher {
public boolean accepts(String method, IServer server, IModule[] module) {
if( LocalPublishMethod.LOCAL_PUBLISH_METHOD.equals(method)
&& module != null && module.length > 0
@@ -56,120 +23,4 @@
return true;
return false;
}
-
- public IStatus publishModule(
- IJBossServerPublishMethod method,
- IServer server, IModule[] module,
- int publishType, IModuleResourceDelta[] delta,
- IProgressMonitor monitor) throws CoreException {
-
- this.server = ServerConverter.getDeployableServer(server);
-
- IModule module2 = module[0];
-
- IStatus status = null;
- if(publishType == REMOVE_PUBLISH){
- status = unpublish(this.server, module2, monitor);
- } else if( publishType == FULL_PUBLISH ){
- // if there's no change, do nothing. Otherwise, on change or add, re-publish
- status = publish(this.server, module2, true, monitor);
- } else if( publishType == INCREMENTAL_PUBLISH ) {
- status = publish(this.server, module2, false, monitor);
- }
- return status;
-
- }
-
- protected IStatus publish(IDeployableServer server, IModule module, boolean updateTimestamp, IProgressMonitor monitor) throws CoreException {
- SingleDeployableModuleDelegate delegate = (SingleDeployableModuleDelegate)module.loadAdapter(SingleDeployableModuleDelegate.class, new NullProgressMonitor());
- if( delegate != null ) {
- IPath sourcePath = delegate.getGlobalSourcePath();
-
- IPath destFolder = PublishUtil.getDeployPath(new IModule[]{module}, server).removeLastSegments(1);;
- IPath tempDestFolder = PublishUtil.getTempDeployFolder(new IModule[]{module}, server).removeLastSegments(1);;
- File destFile = destFolder.append(sourcePath.lastSegment()).toFile();
- File tempDestFile = tempDestFolder.append(sourcePath.lastSegment()).toFile();
- if( destFile.exists())
- destFile.delete();
- FileUtilListener l = new FileUtilListener();
- FileUtil.fileSafeCopy(sourcePath.toFile(), tempDestFile, l);
- boolean success = tempDestFile.renameTo(destFile);
- if( success && updateTimestamp )
- destFile.setLastModified(new Date().getTime());
- if( l.errorFound || !success ) {
- publishState = IServer.PUBLISH_STATE_FULL;
- Exception e = l.e != null ? l.e : new Exception(
- NLS.bind(Messages.CopyFileError, tempDestFile, destFile));
- return new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.SINGLE_FILE_PUBLISH_FAIL,
- NLS.bind(Messages.CouldNotPublishModule, module.getName()), e);
- }
- } else {
- // deleted module. o noes. Ignore it. We can't re-publish it, so just ignore it.
- publishState = IServer.PUBLISH_STATE_UNKNOWN;
- Status status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.SINGLE_FILE_PUBLISH_MNF,
- NLS.bind(Messages.CouldNotPublishModule, module.getName()), null);
- return status;
- }
-
- Status status = new Status(IStatus.OK, JBossServerCorePlugin.PLUGIN_ID,
- IEventCodes.SINGLE_FILE_PUBLISH_SUCCESS,
- NLS.bind(Messages.ModulePublished,module.getName()), null);
- return status;
- }
-
- protected IStatus unpublish(IDeployableServer server, IModule module, IProgressMonitor monitor) throws CoreException {
- // delete file
- String fileName = null;
- if( module instanceof DeletedModule ) {
- String path = module.getId().substring(SingleDeployableFactory.FACTORY_ID.length()+1);
- fileName = new Path(path).lastSegment();
- } else {
- SingleDeployableModuleDelegate delegate = (SingleDeployableModuleDelegate)module.loadAdapter(SingleDeployableModuleDelegate.class, new NullProgressMonitor());
- IPath sourcePath = delegate.getGlobalSourcePath();
- fileName = sourcePath.lastSegment();
- }
- if( fileName != null ) {
- IPath destFolder = PublishUtil.getDeployPath(new IModule[]{module}, server).removeLastSegments(1);
- FileUtilListener l = new FileUtilListener();
- File destFile = destFolder.append(fileName).toFile();
- FileUtil.safeDelete(destFile, l);
- if( l.errorFound ) {
- publishState = IServer.PUBLISH_STATE_FULL;
- return new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.SINGLE_FILE_UNPUBLISH_FAIL,
- NLS.bind(Messages.DeleteModuleFail, module.getName()), l.e);
- }
- } else {
- // deleted module. o noes. Ignore it.
- publishState = IServer.PUBLISH_STATE_UNKNOWN;
- Status status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.SINGLE_FILE_UNPUBLISH_MNF,
- NLS.bind(Messages.DeleteModuleFail, module.getName()), null);
- return status;
- }
- Status status = new Status(IStatus.OK, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.SINGLE_FILE_UNPUBLISH_SUCCESS,
- NLS.bind(Messages.ModuleDeleted, module.getName()), null);
- return status;
- }
-
- public static class FileUtilListener implements IFileUtilListener {
- protected boolean errorFound = false;
- protected Exception e;
- public void fileCopied(File source, File dest, boolean result,Exception e) {
- if( result == false || e != null ) {
- errorFound = true;
- this.e = e;
- }
- }
- public void fileDeleted(File file, boolean result, Exception e) {
- if( result == false || e != null ) {
- errorFound = true;
- this.e = e;
- }
- }
- public void folderDeleted(File file, boolean result, Exception e) {
- if( result == false || e != null ) {
- errorFound = true;
- this.e = e;
- }
- }
- }
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IDeployableServer.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IDeployableServer.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IDeployableServer.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -19,6 +19,7 @@
* @author rob.stryker at jboss.com
*/
public interface IDeployableServer {
+ public static final String SERVER_MODE = "org.jboss.ide.eclipse.as.core.server.serverMode"; //$NON-NLS-1$
public static final String DEPLOY_DIRECTORY = "org.jboss.ide.eclipse.as.core.server.deployDirectory"; //$NON-NLS-1$
public static final String TEMP_DEPLOY_DIRECTORY = "org.jboss.ide.eclipse.as.core.server.tempDeployDirectory"; //$NON-NLS-1$
public static final String DEPLOY_DIRECTORY_TYPE = "org.jboss.ide.eclipse.as.core.server.deployDirectoryType"; //$NON-NLS-1$
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerPublishMethod.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerPublishMethod.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerPublishMethod.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -1,14 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.ide.eclipse.as.core.server;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
import org.jboss.ide.eclipse.as.core.server.internal.DeployableServerBehavior;
+import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
public interface IJBossServerPublishMethod {
- public String getPublishMethodId();
- public boolean accepts(String methodType);
+ public IJBossServerPublishMethodType getPublishMethodType();
public void publishStart(DeployableServerBehavior behaviour, IProgressMonitor monitor) throws CoreException;
public int publishFinish(DeployableServerBehavior behaviour, IProgressMonitor monitor) throws CoreException;
public int publishModule(DeployableServerBehavior behaviour, int kind, int deltaKind, IModule[] module, IProgressMonitor monitor) throws CoreException;
+
+ // Methods moved from publishers into the publish method
+ public IPublishCopyCallbackHandler getCallbackHandler(IPath path, IServer server);
+ public String getPublishDefaultRootFolder(IServer server);
}
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerPublishMethodType.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerPublishMethodType.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerPublishMethodType.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.core.server;
+
+public interface IJBossServerPublishMethodType {
+ public String getId();
+ public String getName();
+ public boolean accepts(String serverTypeId);
+ public IJBossServerPublishMethod createPublishMethod();
+}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServer.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServer.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServer.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -18,7 +18,6 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
-import org.eclipse.jst.server.core.IEnterpriseApplication;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.IServer;
@@ -27,9 +26,7 @@
import org.eclipse.wst.server.core.model.ServerDelegate;
import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
-import org.jboss.ide.eclipse.as.core.util.ModuleUtil;
import org.jboss.ide.eclipse.as.core.util.ServerUtil;
-import org.jboss.ide.eclipse.as.wtp.core.modules.IJBTModule;
import org.jboss.ide.eclipse.as.wtp.core.util.ServerModelUtilities;
public class DeployableServer extends ServerDelegate implements IDeployableServer {
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 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/DeployableServerBehavior.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -26,8 +26,10 @@
import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
import org.jboss.ide.eclipse.as.core.publishers.LocalPublishMethod;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethodType;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
import org.jboss.ide.eclipse.as.core.server.internal.launch.DeployableLaunchConfiguration;
+import org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader;
public class DeployableServerBehavior extends ServerBehaviourDelegate {
@@ -73,8 +75,11 @@
*
* @return
*/
- protected IJBossServerPublishMethod createPublishMethod() {
- return new LocalPublishMethod(); // TODO FIX THIS
+ public IJBossServerPublishMethod createPublishMethod() {
+ IJBossServerPublishMethodType type = DeploymentPreferenceLoader.getCurrentDeploymentMethodType(getServer());
+ if( type != null )
+ return type.createPublishMethod();
+ return new LocalPublishMethod(); // sensible default
}
public IModuleResourceDelta[] getPublishedResourceDelta(IModule[] module) {
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServer.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServer.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServer.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -10,37 +10,23 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.core.server.internal;
-import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
-import java.util.Map;
-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.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
import org.eclipse.jst.server.core.IWebModule;
-import org.eclipse.osgi.util.NLS;
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.IURLProvider;
import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.Messages;
import org.jboss.ide.eclipse.as.core.extensions.descriptors.XPathModel;
import org.jboss.ide.eclipse.as.core.extensions.descriptors.XPathQuery;
import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
import org.jboss.ide.eclipse.as.core.server.IJBossServerConstants;
import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
-import org.jboss.ide.eclipse.as.core.util.ArgsUtil;
-import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeConstants;
import org.jboss.ide.eclipse.as.core.util.ServerUtil;
/**
@@ -59,85 +45,16 @@
setAttribute("auto-publish-time", 1); //$NON-NLS-1$
setAttribute("id", getAttribute("id", (String)"") + new Date().getTime()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
-
- public void saveConfiguration(IProgressMonitor monitor) throws CoreException {
- // here we update the launch configuration with any details that might have changed.
- try {
- Server s = (Server)getServer();
- ILaunchConfiguration lc = s.getLaunchConfiguration(false, new NullProgressMonitor());
- if( lc != null ) {
- String startArgs = lc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null);
- String originalArgs = startArgs;
- if( !getServer().getHost().equals(getHost(true)))
- startArgs = ArgsUtil.setArg(startArgs,
- IJBossRuntimeConstants.STARTUP_ARG_HOST_SHORT,
- IJBossRuntimeConstants.STARTUP_ARG_HOST_LONG,
- getServer().getHost());
-
- IJBossServerRuntime runtime = (IJBossServerRuntime)
- getServer().getRuntime().loadAdapter(IJBossServerRuntime.class, null);
- String config = runtime.getJBossConfiguration();
- startArgs = ArgsUtil.setArg(startArgs,
- IJBossRuntimeConstants.STARTUP_ARG_CONFIG_SHORT,
- IJBossRuntimeConstants.STARTUP_ARG_CONFIG_LONG, config);
-
- if( startArgs != null && !startArgs.trim().equals(originalArgs)) {
- ILaunchConfigurationWorkingCopy wc = lc.getWorkingCopy();
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, startArgs);
- wc.doSave();
- }
- }
- } catch( CoreException ce ) {
- IStatus s = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
- NLS.bind(Messages.CannotSaveServersStartArgs, getServer().getName()), ce);
- JBossServerCorePlugin.getDefault().getLog().log(s);
- }
- }
public String getHost() {
- String host = getHost(true);
- return host == null ? getServer().getHost() : host;
+ return getServer().getHost();
}
-
- public String getHost(boolean checkLaunchConfig) {
- String host = null;
- if( checkLaunchConfig ) {
- try {
- Server s = (Server)getServer();
- ILaunchConfiguration lc = s.getLaunchConfiguration(true, new NullProgressMonitor());
- if(lc!=null) {
- String startArgs = lc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null);
- String val = ArgsUtil.getValue(startArgs,
- IJBossRuntimeConstants.STARTUP_ARG_HOST_SHORT,
- IJBossRuntimeConstants.STARTUP_ARG_HOST_LONG);
- if( val != null ) {
- host = val;
- }
- }
- } catch( CoreException ce ) {}
- }
- return host;
- }
-
+
public String getConfigDirectory() {
- return getConfigDirectory(true);
+ IJBossServerRuntime runtime = (IJBossServerRuntime)getServer().getRuntime().loadAdapter(IJBossServerRuntime.class, null);
+ return runtime.getConfigLocationFullPath().toOSString();
}
- public String getConfigDirectory(boolean checkLaunchConfig) {
- if( !checkLaunchConfig )
- return getRuntimeConfigDirectory();
-
- String configDir = getLaunchConfigConfigurationDirectory();
- if( configDir == null )
- return getRuntimeConfigDirectory();
-
- File f = new File(configDir);
- if( !f.exists() || !f.canRead() || !f.isDirectory())
- return getRuntimeConfigDirectory();
-
- return new Path(configDir).toOSString();
- }
-
public String getDeployFolder() {
return getDeployFolder(this, getDeployLocationType());
}
@@ -167,18 +84,17 @@
return null;
}
- protected String getDeployFolder(boolean checkLaunchConfig) {
- return new Path(getConfigDirectory(checkLaunchConfig) + Path.SEPARATOR + DEPLOY).toOSString();
+ public String getTempDeployFolder() {
+ return getTempDeployFolder(this, getDeployLocationType());
}
-
- public String getTempDeployFolder() {
- IJBossServerRuntime jbsrt = getRuntime();
- String type = getDeployLocationType();
+ public static String getTempDeployFolder(JBossServer jbs, String type) {
+ IServer server = jbs.getServer();
+ IJBossServerRuntime jbsrt = getRuntime(server);
if( type.equals(DEPLOY_CUSTOM))
- return ServerUtil.makeGlobal(jbsrt, new Path(getAttribute(TEMP_DEPLOY_DIRECTORY, ""))).toString(); //$NON-NLS-1$
+ return ServerUtil.makeGlobal(jbsrt, new Path(server.getAttribute(TEMP_DEPLOY_DIRECTORY, ""))).toString(); //$NON-NLS-1$
if( type.equals(DEPLOY_METADATA)) {
- return JBossServerCorePlugin.getServerStateLocation(getServer()).
+ return JBossServerCorePlugin.getServerStateLocation(server).
append(IJBossServerConstants.TEMP_DEPLOY).makeAbsolute().toString();
} else if( type.equals(DEPLOY_SERVER)) {
String loc = jbsrt.getConfigLocation();
@@ -190,41 +106,7 @@
}
return null;
}
-
- protected String getLaunchConfigConfigurationDirectory() {
- try {
- Server s = (Server)getServer();
- ILaunchConfiguration lc = s.getLaunchConfiguration(true, new NullProgressMonitor());
- String startArgs = lc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, (String)null);
- Map map = ArgsUtil.getSystemProperties(startArgs);
-
- if( map.get(JBOSS_SERVER_HOME_DIR) != null )
- return (String)map.get(JBOSS_SERVER_HOME_DIR);
-
- if( map.get(JBOSS_SERVER_BASE_DIR) != null ) {
- String name = map.get(JBOSS_SERVER_NAME) != null ?
- (String)map.get(JBOSS_SERVER_NAME) : DEFAULT_CONFIGURATION;
- return (String)map.get(JBOSS_SERVER_BASE_DIR) + Path.SEPARATOR + name;
- }
-
- if( map.get(JBOSS_HOME_DIR) != null ) {
- return (String)map.get(JBOSS_HOME_DIR) + Path.SEPARATOR + SERVER
- + Path.SEPARATOR + DEFAULT_CONFIGURATION;
- }
- } catch( CoreException ce ) {
- }
- return null;
- }
-
- protected String getRuntimeConfigDirectory() {
- IJBossServerRuntime runtime = (IJBossServerRuntime)
- getServer().getRuntime().loadAdapter(IJBossServerRuntime.class, null);
- String p = getServer().getRuntime().getLocation().toOSString() + Path.SEPARATOR + SERVER +
- Path.SEPARATOR + runtime.getJBossConfiguration();
- return new Path(p).toOSString();
- }
-
public int getJNDIPort() {
return findPort(JNDI_PORT, JNDI_PORT_DETECT, JNDI_PORT_DETECT_XPATH,
JNDI_PORT_DEFAULT_XPATH, JNDI_DEFAULT_PORT);
@@ -258,8 +140,6 @@
return defaultValue;
}
-
-
public URL getModuleRootURL(IModule module) {
if (module == null || module.loadAdapter(IWebModule.class,null)==null )
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServerBehavior.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServerBehavior.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/JBossServerBehavior.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -20,35 +20,15 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.core.server.internal;
-import javax.management.MBeanServerConnection;
-import javax.management.ObjectName;
+import java.util.HashMap;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.DebugEvent;
-import org.eclipse.debug.core.DebugException;
-import org.eclipse.debug.core.DebugPlugin;
-import org.eclipse.debug.core.IDebugEventSetListener;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.debug.core.model.IProcess;
-import org.eclipse.wst.server.core.IRuntime;
-import org.eclipse.wst.server.core.IServer;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.Messages;
-import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
-import org.jboss.ide.eclipse.as.core.extensions.events.ServerLogger;
-import org.jboss.ide.eclipse.as.core.extensions.jmx.JBossServerConnectionProvider;
-import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXClassLoaderRepository;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
-import org.jboss.ide.eclipse.as.core.server.IServerStatePoller;
-import org.jboss.ide.eclipse.as.core.server.internal.launch.JBossServerStartupLaunchConfiguration;
-import org.jboss.ide.eclipse.as.core.server.internal.launch.StopLaunchConfiguration;
-import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeConstants;
-import org.jboss.tools.jmx.core.IJMXRunnable;
-import org.jboss.tools.jmx.core.JMXException;
+import org.jboss.ide.eclipse.as.core.publishers.LocalPublishMethod;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethodType;
+import org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader;
/**
*
@@ -57,239 +37,82 @@
*/
public class JBossServerBehavior extends DeployableServerBehavior {
- private PollThread pollThread = null;
- protected IProcess process;
- protected boolean nextStopRequiresForce = false;
+ public static interface JBossBehaviourDelegate {
+ public void setActualBehaviour(JBossServerBehavior actualBehaviour);
+ public void stop(boolean force);
+ public void setupLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy, IProgressMonitor monitor) throws CoreException;
+ public void publishStart(final IProgressMonitor monitor) throws CoreException;
+ public void publishFinish(final IProgressMonitor monitor) throws CoreException;
+ public void serverStarting();
+ public void serverStopping();
+ public IStatus canChangeState(String launchMode);
+ }
+
+ public static HashMap<String, Class> delegateClassMap;
+ static {
+ delegateClassMap = new HashMap<String, Class>();
+ delegateClassMap.put(LocalPublishMethod.LOCAL_PUBLISH_METHOD, LocalJBossBehaviorDelegate.class);
+ }
+ public static void addDelegateMapping(String s, Class c) {
+ delegateClassMap.put(s, c);
+ }
+
public JBossServerBehavior() {
super();
}
- public void stop(boolean force) {
- int state = getServer().getServerState();
- if( force || process == null || process.isTerminated() || state == IServer.STATE_STOPPED || nextStopRequiresForce) {
- forceStop();
- return;
- }
+ private JBossBehaviourDelegate delegate;
+ private String lastModeId;
+ public JBossBehaviourDelegate getDelegate() {
+ IJBossServerPublishMethodType type = DeploymentPreferenceLoader.getCurrentDeploymentMethodType(getServer());
+ String id = type == null ? LocalPublishMethod.LOCAL_PUBLISH_METHOD : type.getId();
+ if( id.equals(lastModeId))
+ return delegate;
- // if we're starting up or shutting down and they've tried again,
- // then force it to stop.
- if( state == IServer.STATE_STARTING || state == IServer.STATE_STOPPING ) {
- pollThread.cancel();
- forceStop();
- return;
+ Class c = delegateClassMap.get(id);
+ try {
+ JBossBehaviourDelegate o = (JBossBehaviourDelegate)c.newInstance();
+ o.setActualBehaviour(this);
+ lastModeId = id;
+ delegate = o;
+ } catch( InstantiationException ie) {
+ } catch( IllegalAccessException iae) {
}
-
- serverStopping();
- new Thread() {public void run() {
- boolean success = StopLaunchConfiguration.stop(getServer());
- if( !success ) {
- if( process != null && !process.isTerminated() ) {
- setServerStarted();
- pollThread.cancel(Messages.STOP_FAILED_MESSAGE);
- nextStopRequiresForce = true;
- }
- }
- }}.start();
+ return delegate;
}
- public synchronized void forceStop() {
- // just terminate the process.
- if( process != null && !process.isTerminated()) {
- try {
- process.terminate();
- addForceStopEvent();
- } catch( DebugException e ) {
- addForceStopFailedEvent(e);
- }
- }
- process = null;
- setServerStopped();
+ public void stop(boolean force) {
+ getDelegate().stop(force);
}
- protected void addForceStopFailedEvent(DebugException e) {
- IStatus status = new Status(IStatus.ERROR,
- JBossServerCorePlugin.PLUGIN_ID, IEventCodes.BEHAVIOR_FORCE_STOP_FAILED,
- Messages.FORCE_TERMINATE_FAILED, e);
- ServerLogger.getDefault().log(getServer(), status);
- }
- protected void addForceStopEvent() {
- IStatus status = new Status(IStatus.ERROR,
- JBossServerCorePlugin.PLUGIN_ID, IEventCodes.BEHAVIOR_FORCE_STOP,
- Messages.FORCE_TERMINATED, null);
- ServerLogger.getDefault().log(getServer(), status);
- }
-
- protected void addProcessTerminatedEvent() {
- IStatus status = new Status(IStatus.INFO,
- JBossServerCorePlugin.PLUGIN_ID, IEventCodes.BEHAVIOR_PROCESS_TERMINATED,
- Messages.TERMINATED, null);
- ServerLogger.getDefault().log(getServer(), status);
- }
-
public void setupLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy, IProgressMonitor monitor) throws CoreException {
- JBossServerStartupLaunchConfiguration.setupLaunchConfiguration(workingCopy, getServer());
+ getDelegate().setupLaunchConfiguration(workingCopy, monitor);
}
-
- protected transient IDebugEventSetListener processListener;
- public synchronized void setProcess(final IProcess newProcess) {
- if (process != null) {
- return;
- }
- process = newProcess;
- if (processListener != null)
- DebugPlugin.getDefault().removeDebugEventListener(processListener);
- if (newProcess == null)
- return;
-
- processListener = new IDebugEventSetListener() {
- public void handleDebugEvents(DebugEvent[] events) {
- if (events != null) {
- int size = events.length;
- for (int i = 0; i < size; i++) {
- if (process != null && process.equals(events[i].getSource()) && events[i].getKind() == DebugEvent.TERMINATE) {
- DebugPlugin.getDefault().removeDebugEventListener(this);
- forceStop();
- addProcessTerminatedEvent();
- }
- }
- }
- }
- };
- DebugPlugin.getDefault().addDebugEventListener(processListener);
- }
-
-
public void setRunMode(String mode) {
setMode(mode);
}
public void serverStarting() {
- nextStopRequiresForce = false;
setServerStarting();
- pollServer(IServerStatePoller.SERVER_UP);
+ getDelegate().serverStarting();
}
public void serverStopping() {
setServerStopping();
- pollServer(IServerStatePoller.SERVER_DOWN);
+ getDelegate().serverStopping();
}
- public synchronized IProcess getProcess() {
- return process;
- }
-
- protected void pollServer(final boolean expectedState) {
- if( this.pollThread != null ) {
- pollThread.cancel();
- }
- this.pollThread = new PollThread(Messages.ServerPollerThreadName, expectedState, this);
- pollThread.start();
- }
-
-
protected void publishStart(final IProgressMonitor monitor) throws CoreException {
super.publishStart(monitor);
- if( shouldSuspendScanner()) {
- JMXClassLoaderRepository.getDefault().addConcerned(getServer(), this);
- IJMXRunnable r = new IJMXRunnable() {
- public void run(MBeanServerConnection connection) throws Exception {
- suspendDeployment(connection, monitor);
- }
- };
- try {
- JBossServerConnectionProvider.run(getServer(), r);
- } catch( JMXException jmxe ) {
- IStatus status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.SUSPEND_DEPLOYMENT_SCANNER, Messages.JMXPauseScannerError, jmxe);
- ServerLogger.getDefault().log(getServer(), status);
- }
- }
+ getDelegate().publishStart(monitor);
}
protected void publishFinish(final IProgressMonitor monitor) throws CoreException {
- if( shouldSuspendScanner()) {
- IJMXRunnable r = new IJMXRunnable() {
- public void run(MBeanServerConnection connection) throws Exception {
- resumeDeployment(connection, monitor);
- }
- };
- try {
- JBossServerConnectionProvider.run(getServer(), r);
- } catch( JMXException jmxe ) {
- IStatus status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.RESUME_DEPLOYMENT_SCANNER, Messages.JMXResumeScannerError, jmxe);
- ServerLogger.getDefault().log(getServer(), status);
- } finally {
- JMXClassLoaderRepository.getDefault().removeConcerned(getServer(), this);
- }
- }
+ getDelegate().publishFinish(monitor);
super.publishFinish(monitor);
}
- protected boolean shouldSuspendScanner() {
-// if( getServer().getServerType().getId().equals(IConstants.AS_50))
-// return false;
- if( getServer().getServerState() != IServer.STATE_STARTED)
- return false;
- return true;
- }
-
- protected void suspendDeployment(final MBeanServerConnection connection, IProgressMonitor monitor) throws Exception {
- ObjectName name = new ObjectName(IJBossRuntimeConstants.DEPLOYMENT_SCANNER_MBEAN_NAME);
- launchDeployCommand(connection, name, IJBossRuntimeConstants.STOP, monitor);
- }
-
-
-
- protected void resumeDeployment(final MBeanServerConnection connection, IProgressMonitor monitor) throws Exception {
- ObjectName name = new ObjectName(IJBossRuntimeConstants.DEPLOYMENT_SCANNER_MBEAN_NAME);
- launchDeployCommand(connection, name, IJBossRuntimeConstants.START, monitor);
- }
-
- protected void launchDeployCommand(final MBeanServerConnection connection, final ObjectName objectName,
- final String methodName, IProgressMonitor monitor) throws Exception {
- final Exception[] e = new Exception[1];
- final Object waitObject = new Object();
- final Boolean[] subtaskComplete = new Boolean[1];
- subtaskComplete[0] = new Boolean(false);
- Thread t = new Thread() {
- public void run() {
- Exception exception = null;
- try {
- executeDeploymentCommand(connection, objectName, methodName);
- } catch( Exception ex ) {
- exception = ex;
- }
- synchronized(waitObject) {
- e[0] = exception;
- subtaskComplete[0] = new Boolean(true);
- waitObject.notifyAll();
- }
- }
- };
- t.start();
- int count = 0;
- while(t.isAlive() && !monitor.isCanceled() && count <= 4000) {
- count+= 1000;
- synchronized(waitObject) {
- if( subtaskComplete[0].booleanValue() )
- break;
- waitObject.wait(1000);
- }
- }
- synchronized(waitObject) {
- if( !subtaskComplete[0].booleanValue()) {
- t.interrupt();
- IStatus status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.DEPLOYMENT_SCANNER_TRANSITION_CANCELED, Messages.JMXScannerCanceled, null);
- ServerLogger.getDefault().log(getServer(), status);
- }
- }
- }
-
- protected void executeDeploymentCommand(MBeanServerConnection connection, ObjectName objectName, String methodName) throws Exception {
- connection.invoke(objectName, methodName, new Object[] { }, new String[] {});
- }
-
-
// Can start / stop / restart etc
public IStatus canStart(String launchMode) {
return canChangeState(launchMode);
@@ -304,21 +127,6 @@
return canChangeState(launchMode);
}
protected IStatus canChangeState(String launchMode) {
- if( getServer() != null && getServer().getRuntime() != null &&
- getRuntime().getVM() != null )
- return Status.OK_STATUS;
- return new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
- "This server does not have a valid runtime environment"); //$NON-NLS-1$
+ return getDelegate().canChangeState(launchMode);
}
-
- private IJBossServerRuntime getRuntime() {
- IRuntime r = getServer().getRuntime();
- IJBossServerRuntime ajbsrt = null;
- if (r != null) {
- ajbsrt = (IJBossServerRuntime) r
- .loadAdapter(IJBossServerRuntime.class,
- new NullProgressMonitor());
- }
- return ajbsrt;
- }
}
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/LocalJBossBehaviorDelegate.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/LocalJBossBehaviorDelegate.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/LocalJBossBehaviorDelegate.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -0,0 +1,327 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.core.server.internal;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugEvent;
+import org.eclipse.debug.core.DebugException;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.IDebugEventSetListener;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.IServer;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+import org.jboss.ide.eclipse.as.core.Messages;
+import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
+import org.jboss.ide.eclipse.as.core.extensions.events.ServerLogger;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JBossServerConnectionProvider;
+import org.jboss.ide.eclipse.as.core.extensions.jmx.JMXClassLoaderRepository;
+import org.jboss.ide.eclipse.as.core.extensions.polling.ProcessTerminatedPoller.IProcessProvider;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
+import org.jboss.ide.eclipse.as.core.server.IServerStatePoller;
+import org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior.JBossBehaviourDelegate;
+import org.jboss.ide.eclipse.as.core.server.internal.launch.LocalJBossServerStartupLaunchUtil;
+import org.jboss.ide.eclipse.as.core.server.internal.launch.StopLaunchConfiguration;
+import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeConstants;
+import org.jboss.tools.jmx.core.IJMXRunnable;
+import org.jboss.tools.jmx.core.JMXException;
+
+/**
+ *
+ * @author Rob Stryker
+ *
+ */
+public class LocalJBossBehaviorDelegate implements JBossBehaviourDelegate, IProcessProvider {
+
+ private PollThread pollThread = null;
+ protected IProcess process;
+ protected boolean nextStopRequiresForce = false;
+ private JBossServerBehavior actualBehavior;
+ public LocalJBossBehaviorDelegate() {
+ super();
+ }
+
+ public void setActualBehaviour(JBossServerBehavior actualBehaviour) {
+ this.actualBehavior = actualBehaviour;
+ }
+
+ protected IServer getServer() {
+ return actualBehavior.getServer();
+ }
+
+ public void stop(boolean force) {
+ int state = getServer().getServerState();
+ if( force || process == null || process.isTerminated() || state == IServer.STATE_STOPPED || nextStopRequiresForce) {
+ forceStop();
+ return;
+ }
+
+ // if we're starting up or shutting down and they've tried again,
+ // then force it to stop.
+ if( state == IServer.STATE_STARTING || state == IServer.STATE_STOPPING ) {
+ pollThread.cancel();
+ forceStop();
+ return;
+ }
+
+ serverStopping();
+ new Thread() {public void run() {
+ boolean success = StopLaunchConfiguration.stop(getServer());
+ if( !success ) {
+ if( process != null && !process.isTerminated() ) {
+ actualBehavior.setServerStarted();
+ pollThread.cancel(Messages.STOP_FAILED_MESSAGE);
+ nextStopRequiresForce = true;
+ }
+ }
+ }}.start();
+ }
+
+ public synchronized void forceStop() {
+ // just terminate the process.
+ if( process != null && !process.isTerminated()) {
+ try {
+ process.terminate();
+ addForceStopEvent();
+ } catch( DebugException e ) {
+ addForceStopFailedEvent(e);
+ }
+ }
+ process = null;
+ actualBehavior.setServerStopped();
+ }
+
+ protected void addForceStopFailedEvent(DebugException e) {
+ IStatus status = new Status(IStatus.ERROR,
+ JBossServerCorePlugin.PLUGIN_ID, IEventCodes.BEHAVIOR_FORCE_STOP_FAILED,
+ Messages.FORCE_TERMINATE_FAILED, e);
+ ServerLogger.getDefault().log(getServer(), status);
+ }
+ protected void addForceStopEvent() {
+ IStatus status = new Status(IStatus.ERROR,
+ JBossServerCorePlugin.PLUGIN_ID, IEventCodes.BEHAVIOR_FORCE_STOP,
+ Messages.FORCE_TERMINATED, null);
+ ServerLogger.getDefault().log(getServer(), status);
+ }
+
+ protected void addProcessTerminatedEvent() {
+ IStatus status = new Status(IStatus.INFO,
+ JBossServerCorePlugin.PLUGIN_ID, IEventCodes.BEHAVIOR_PROCESS_TERMINATED,
+ Messages.TERMINATED, null);
+ ServerLogger.getDefault().log(getServer(), status);
+ }
+
+ public void setupLaunchConfiguration(ILaunchConfigurationWorkingCopy workingCopy, IProgressMonitor monitor) throws CoreException {
+ LocalJBossServerStartupLaunchUtil.setupLaunchConfiguration(workingCopy, getServer());
+ }
+
+
+ protected transient IDebugEventSetListener processListener;
+ public synchronized void setProcess(final IProcess newProcess) {
+ if (process != null) {
+ return;
+ }
+ process = newProcess;
+ if (processListener != null)
+ DebugPlugin.getDefault().removeDebugEventListener(processListener);
+ if (newProcess == null)
+ return;
+
+ processListener = new IDebugEventSetListener() {
+ public void handleDebugEvents(DebugEvent[] events) {
+ if (events != null) {
+ int size = events.length;
+ for (int i = 0; i < size; i++) {
+ if (process != null && process.equals(events[i].getSource()) && events[i].getKind() == DebugEvent.TERMINATE) {
+ DebugPlugin.getDefault().removeDebugEventListener(this);
+ forceStop();
+ addProcessTerminatedEvent();
+ }
+ }
+ }
+ }
+ };
+ DebugPlugin.getDefault().addDebugEventListener(processListener);
+ }
+
+
+ public void serverStarting() {
+ nextStopRequiresForce = false;
+ pollServer(IServerStatePoller.SERVER_UP);
+ }
+
+ public void serverStopping() {
+ actualBehavior.setServerStopping();
+ pollServer(IServerStatePoller.SERVER_DOWN);
+ }
+
+ public synchronized IProcess getProcess() {
+ return process;
+ }
+
+ protected void pollServer(final boolean expectedState) {
+ if( this.pollThread != null ) {
+ pollThread.cancel();
+ }
+ this.pollThread = new PollThread(Messages.ServerPollerThreadName, expectedState, actualBehavior);
+ pollThread.start();
+ }
+
+
+ public void publishStart(final IProgressMonitor monitor) throws CoreException {
+ if( shouldSuspendScanner()) {
+ JMXClassLoaderRepository.getDefault().addConcerned(getServer(), this);
+ IJMXRunnable r = new IJMXRunnable() {
+ public void run(MBeanServerConnection connection) throws Exception {
+ suspendDeployment(connection, monitor);
+ }
+ };
+ try {
+ JBossServerConnectionProvider.run(getServer(), r);
+ } catch( JMXException jmxe ) {
+ IStatus status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.SUSPEND_DEPLOYMENT_SCANNER, Messages.JMXPauseScannerError, jmxe);
+ ServerLogger.getDefault().log(getServer(), status);
+ }
+ }
+ }
+
+ public void publishFinish(final IProgressMonitor monitor) throws CoreException {
+ if( shouldSuspendScanner()) {
+ IJMXRunnable r = new IJMXRunnable() {
+ public void run(MBeanServerConnection connection) throws Exception {
+ resumeDeployment(connection, monitor);
+ }
+ };
+ try {
+ JBossServerConnectionProvider.run(getServer(), r);
+ } catch( JMXException jmxe ) {
+ IStatus status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.RESUME_DEPLOYMENT_SCANNER, Messages.JMXResumeScannerError, jmxe);
+ ServerLogger.getDefault().log(getServer(), status);
+ } finally {
+ JMXClassLoaderRepository.getDefault().removeConcerned(getServer(), this);
+ }
+ }
+ }
+
+ protected boolean shouldSuspendScanner() {
+ if( getServer().getServerState() != IServer.STATE_STARTED)
+ return false;
+ return true;
+ }
+
+ protected void suspendDeployment(final MBeanServerConnection connection, IProgressMonitor monitor) throws Exception {
+ ObjectName name = new ObjectName(IJBossRuntimeConstants.DEPLOYMENT_SCANNER_MBEAN_NAME);
+ launchDeployCommand(connection, name, IJBossRuntimeConstants.STOP, monitor);
+ }
+
+
+
+ protected void resumeDeployment(final MBeanServerConnection connection, IProgressMonitor monitor) throws Exception {
+ ObjectName name = new ObjectName(IJBossRuntimeConstants.DEPLOYMENT_SCANNER_MBEAN_NAME);
+ launchDeployCommand(connection, name, IJBossRuntimeConstants.START, monitor);
+ }
+
+ protected void launchDeployCommand(final MBeanServerConnection connection, final ObjectName objectName,
+ final String methodName, IProgressMonitor monitor) throws Exception {
+ final Exception[] e = new Exception[1];
+ final Object waitObject = new Object();
+ final Boolean[] subtaskComplete = new Boolean[1];
+ subtaskComplete[0] = new Boolean(false);
+ Thread t = new Thread() {
+ public void run() {
+ Exception exception = null;
+ try {
+ executeDeploymentCommand(connection, objectName, methodName);
+ } catch( Exception ex ) {
+ exception = ex;
+ }
+ synchronized(waitObject) {
+ e[0] = exception;
+ subtaskComplete[0] = new Boolean(true);
+ waitObject.notifyAll();
+ }
+ }
+ };
+ t.start();
+ int count = 0;
+ while(t.isAlive() && !monitor.isCanceled() && count <= 4000) {
+ count+= 1000;
+ synchronized(waitObject) {
+ if( subtaskComplete[0].booleanValue() )
+ break;
+ waitObject.wait(1000);
+ }
+ }
+ synchronized(waitObject) {
+ if( !subtaskComplete[0].booleanValue()) {
+ t.interrupt();
+ IStatus status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.DEPLOYMENT_SCANNER_TRANSITION_CANCELED, Messages.JMXScannerCanceled, null);
+ ServerLogger.getDefault().log(getServer(), status);
+ }
+ }
+ }
+
+ protected void executeDeploymentCommand(MBeanServerConnection connection, ObjectName objectName, String methodName) throws Exception {
+ connection.invoke(objectName, methodName, new Object[] { }, new String[] {});
+ }
+
+
+ // Can start / stop / restart etc
+ public IStatus canStart(String launchMode) {
+ return canChangeState(launchMode);
+ }
+ public IStatus canRestart(String launchMode) {
+ return canChangeState(launchMode);
+ }
+ public IStatus canStop() {
+ return canChangeState(null);
+ }
+ public IStatus canStop(String launchMode) {
+ return canChangeState(launchMode);
+ }
+
+ public IStatus canChangeState(String launchMode) {
+ if( getServer() != null && getServer().getRuntime() != null &&
+ getRuntime().getVM() != null )
+ return Status.OK_STATUS;
+ return new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
+ "This server does not have a valid runtime environment"); //$NON-NLS-1$
+ }
+
+ private IJBossServerRuntime getRuntime() {
+ IRuntime r = getServer().getRuntime();
+ IJBossServerRuntime ajbsrt = null;
+ if (r != null) {
+ ajbsrt = (IJBossServerRuntime) r
+ .loadAdapter(IJBossServerRuntime.class,
+ new NullProgressMonitor());
+ }
+ return ajbsrt;
+ }
+}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/PollThread.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/PollThread.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/PollThread.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -218,14 +218,14 @@
protected void alertBehavior(boolean currentState, boolean finalAlert) {
if (currentState != expectedState) {
// it didnt work... cancel all processes! force stop
- behavior.forceStop();
+ behavior.stop(true);
if (finalAlert)
alertEventLogFailure();
} else {
if (currentState == IServerStatePoller.SERVER_UP)
behavior.setServerStarted();
else
- behavior.forceStop();
+ behavior.stop(true);
if (finalAlert)
alertEventLogSuccess(currentState);
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/ServerPublishMethodType.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/ServerPublishMethodType.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/ServerPublishMethodType.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -0,0 +1,55 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.core.server.internal;
+
+import java.util.Arrays;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethodType;
+
+public class ServerPublishMethodType implements IJBossServerPublishMethodType {
+
+ private String typeId, name;
+ private String[] serverTypes;
+ private IConfigurationElement element;
+ public ServerPublishMethodType(IConfigurationElement element) {
+ this.element = element;
+ this.typeId = element.getAttribute("id"); //$NON-NLS-1$
+ this.name = element.getAttribute("name"); //$NON-NLS-1$
+ String tmp = element.getAttribute("serverTypes"); //$NON-NLS-1$
+ serverTypes = tmp.split(","); //$NON-NLS-1$
+ // clean
+ for( int i = 0; i < serverTypes.length; i++ )
+ serverTypes[i] = serverTypes[i].trim();
+ }
+
+ public String getId() {
+ return typeId;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public boolean accepts(String serverTypeId) {
+ return Arrays.asList(serverTypes).contains(serverTypeId);
+ }
+
+ public IJBossServerPublishMethod createPublishMethod() {
+ try {
+ return (IJBossServerPublishMethod) element.createExecutableExtension("class"); //$NON-NLS-1$
+ } catch( CoreException ce ) {
+ }
+ return null;
+ }
+}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/AbstractJBossLaunchConfigType.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/AbstractJBossLaunchConfigType.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/AbstractJBossLaunchConfigType.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -55,11 +55,11 @@
return true;
}
- protected void preLaunch(ILaunchConfiguration configuration,
+ public void preLaunch(ILaunchConfiguration configuration,
String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
// override me
}
- protected void postLaunch(ILaunchConfiguration configuration,
+ public void postLaunch(ILaunchConfiguration configuration,
String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
// override me
}
@@ -135,7 +135,7 @@
}
- protected static JBossServer findJBossServer(String serverId) throws CoreException {
+ public static JBossServer findJBossServer(String serverId) throws CoreException {
if( serverId == null )
throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
NLS.bind(Messages.ServerNotFound, serverId)));
@@ -153,7 +153,7 @@
return jbs;
}
- protected static IJBossServerRuntime findJBossServerRuntime(IServer server) throws CoreException {
+ public static IJBossServerRuntime findJBossServerRuntime(IServer server) throws CoreException {
IRuntime rt = server.getRuntime();
IJBossServerRuntime jbrt = null;
if( rt != null )
@@ -164,14 +164,14 @@
return jbrt;
}
- protected static void addCPEntry(ArrayList<IRuntimeClasspathEntry> list, JBossServer jbs, String relative) {
+ public static void addCPEntry(ArrayList<IRuntimeClasspathEntry> list, JBossServer jbs, String relative) {
addCPEntry(list, new Path(getServerHome(jbs)).append(relative));
}
- protected static void addCPEntry(ArrayList<IRuntimeClasspathEntry> list, IPath path) {
+ public static void addCPEntry(ArrayList<IRuntimeClasspathEntry> list, IPath path) {
list.add(JavaRuntime.newArchiveRuntimeClasspathEntry(path));
}
- protected static void addJREEntry(ArrayList<IRuntimeClasspathEntry> cp, IVMInstall vmInstall) {
+ public static void addJREEntry(ArrayList<IRuntimeClasspathEntry> cp, IVMInstall vmInstall) {
if (vmInstall != null) {
try {
cp.add(JavaRuntime.newRuntimeContainerClasspathEntry(
@@ -186,7 +186,7 @@
}
}
- protected static void addToolsJar(ArrayList<IRuntimeClasspathEntry> cp, IVMInstall vmInstall) {
+ public static void addToolsJar(ArrayList<IRuntimeClasspathEntry> cp, IVMInstall vmInstall) {
File f = vmInstall.getInstallLocation();
File c1 = new File(f, IConstants.LIB);
File c2 = new File(c1, IConstants.TOOLS_JAR);
@@ -195,7 +195,7 @@
}
- protected static ArrayList<String> convertClasspath(ArrayList<IRuntimeClasspathEntry> cp) {
+ public static ArrayList<String> convertClasspath(ArrayList<IRuntimeClasspathEntry> cp) {
Iterator<IRuntimeClasspathEntry> cpi = cp.iterator();
ArrayList<String> list = new ArrayList<String>();
while (cpi.hasNext()) {
@@ -211,7 +211,7 @@
return list;
}
- protected static void addDirectory(String serverHome, ArrayList<IRuntimeClasspathEntry> classpath,
+ public static void addDirectory(String serverHome, ArrayList<IRuntimeClasspathEntry> classpath,
String dirName) {
String libPath = serverHome + File.separator + dirName;
File libDir = new File(libPath);
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/JBossServerStartupLaunchConfiguration.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/JBossServerStartupLaunchConfiguration.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/JBossServerStartupLaunchConfiguration.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -10,384 +10,69 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.core.server.internal.launch;
-import java.io.File;
-import java.net.MalformedURLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-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.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.ILaunchConfigurationType;
-import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
-import org.eclipse.debug.core.ILaunchManager;
-import org.eclipse.debug.core.model.IProcess;
-import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
-import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
-import org.eclipse.jdt.launching.IVMInstall;
-import org.eclipse.jdt.launching.JavaRuntime;
-import org.eclipse.jdt.launching.StandardClasspathProvider;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.ServerCore;
import org.eclipse.wst.server.core.ServerUtil;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.Messages;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerConstants;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
-import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
-import org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior;
-import org.jboss.ide.eclipse.as.core.util.ArgsUtil;
-import org.jboss.ide.eclipse.as.core.util.IConstants;
-import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeConstants;
-import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeResourceConstants;
-import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
+import org.jboss.ide.eclipse.as.core.publishers.LocalPublishMethod;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethodType;
+import org.jboss.ide.eclipse.as.core.server.internal.DeployableServerBehavior;
+import org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
public class JBossServerStartupLaunchConfiguration extends AbstractJBossLaunchConfigType {
-
- static final char[] INVALID_CHARS = new char[] {'\\', '/', ':', '*', '?', '"', '<', '>', '|', '\0', '@', '&'};
- static final String LAUNCH_TYPE = "org.jboss.ide.eclipse.as.core.server.startupConfiguration"; //$NON-NLS-1$
- static final String DEFAULTS_SET = "jboss.defaults.been.set"; //$NON-NLS-1$
- static final String START_JAR_LOC = IJBossRuntimeResourceConstants.BIN + Path.SEPARATOR + IJBossRuntimeResourceConstants.START_JAR;
- static final String START_MAIN_TYPE = IJBossRuntimeConstants.START_MAIN_TYPE;
-
- public static ILaunchConfigurationWorkingCopy setupLaunchConfiguration(IServer server, String action) throws CoreException {
- ILaunchConfigurationWorkingCopy config = createLaunchConfiguration(server);
- setupLaunchConfiguration(config, server);
- return config;
- }
-
- public static void setupLaunchConfiguration(
- ILaunchConfigurationWorkingCopy workingCopy, IServer server) throws CoreException {
- if(!workingCopy.getAttributes().containsKey(DEFAULTS_SET)) {
- forceDefaultsSet(workingCopy, server);
- }
+ public static interface StartLaunchDelegate {
+ public void actualLaunch(JBossServerStartupLaunchConfiguration launchConfig,
+ ILaunchConfiguration configuration,
+ String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException;
- // Upgrade old launch configs
- JBossServer jbs = findJBossServer(server.getId());
- if( jbs == null )
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
- NLS.bind(Messages.CannotSetUpImproperServer, server.getName())));
-
- String cpProvider = workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, (String)null);
- if( !DEFAULT_CP_PROVIDER_ID.equals(cpProvider)) {
- workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, DEFAULT_CP_PROVIDER_ID);
- workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, getClasspath(jbs));
- workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
- }
+ public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException;
+ public void preLaunch(ILaunchConfiguration configuration,
+ String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException;
+ public void postLaunch(ILaunchConfiguration configuration, String mode,
+ ILaunch launch, IProgressMonitor monitor) throws CoreException;
- // Force the launch to get certain fields from the runtime
- updateMandatedFields(workingCopy, jbs);
}
-
- /*
- * Ensures that the working directory and classpath are 100% accurate.
- * Merges proper required params into args and vm args
- */
- protected static void updateMandatedFields(ILaunchConfigurationWorkingCopy wc, JBossServer jbs) throws CoreException{
- String serverHome = getServerHome(jbs);
- if( serverHome == null )
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
- NLS.bind(Messages.CannotLocateServerHome, jbs.getServer().getName())));
-
- IRuntime rt = jbs.getServer().getRuntime();
- IJBossServerRuntime jbrt = null;
- if( rt != null )
- jbrt = (IJBossServerRuntime)rt.getAdapter(IJBossServerRuntime.class);
-
- if( jbrt == null )
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
- NLS.bind(Messages.ServerRuntimeNotFound, jbs.getServer().getName())));
-
- /* Args and vm args */
-
- String args = wc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, ""); //$NON-NLS-1$
- String vmArgs = wc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, ""); //$NON-NLS-1$
- String host = jbs.getServer().getHost();
- String host2 = ArgsUtil.getValue(args,
- IJBossRuntimeConstants.STARTUP_ARG_HOST_SHORT,
- IJBossRuntimeConstants.STARTUP_ARG_HOST_LONG);
- if( !host.equals(host2))
- args = ArgsUtil.setArg(args,
- IJBossRuntimeConstants.STARTUP_ARG_HOST_SHORT,
- IJBossRuntimeConstants.STARTUP_ARG_HOST_LONG, host);
-
- IJBossServerRuntime runtime = (IJBossServerRuntime)
- jbs.getServer().getRuntime().loadAdapter(IJBossServerRuntime.class, null);
- String config = runtime.getJBossConfiguration();
- args = ArgsUtil.setArg(args,
- IJBossRuntimeConstants.STARTUP_ARG_CONFIG_SHORT,
- IJBossRuntimeConstants.STARTUP_ARG_CONFIG_LONG, config);
-
- try {
- if( !runtime.getConfigLocation().equals(IConstants.SERVER)) {
- args = ArgsUtil.setArg(args, null,
- IJBossRuntimeConstants.SYSPROP + IJBossRuntimeConstants.JBOSS_SERVER_HOME_URL,
- runtime.getConfigLocationFullPath().toFile().toURL().toString());
- }
- } catch( MalformedURLException murle) {}
-
-
- vmArgs= ArgsUtil.setArg(vmArgs, null,
- IJBossRuntimeConstants.SYSPROP + IJBossRuntimeConstants.ENDORSED_DIRS,
- runtime.getRuntime().getLocation().append(
- IJBossRuntimeResourceConstants.LIB).append(
- IJBossRuntimeResourceConstants.ENDORSED).toOSString(), true);
-
- if( runtime.getRuntime().getLocation().append(
- IJBossRuntimeResourceConstants.BIN).append(
- IJBossRuntimeResourceConstants.NATIVE).toFile().exists() ) {
- String argVal = ArgsUtil.getValue(vmArgs, null,
- IJBossRuntimeConstants.SYSPROP + IJBossRuntimeConstants.JAVA_LIB_PATH);
-
- String libPath =
- runtime.getRuntime().getLocation()
- .append(IJBossRuntimeResourceConstants.BIN)
- .append(IJBossRuntimeResourceConstants.NATIVE).toOSString();
- if( argVal != null ) {
- if( argVal.startsWith("\"")) //$NON-NLS-1$
- argVal = argVal.substring(1);
- if( argVal.endsWith("\"")) //$NON-NLS-1$
- argVal = argVal.substring(0, argVal.length()-1);
- if( argVal.startsWith(":")) //$NON-NLS-1$
- argVal = argVal.substring(1);
-
- String[] asArr = argVal.split(File.pathSeparator);
- asArr[0] = libPath;
- String implode = ""; //$NON-NLS-1$
- for( int i = 0; i < asArr.length; i++ )
- implode += asArr[i] + File.pathSeparator;
- libPath = implode;
- }
- vmArgs = ArgsUtil.setArg(vmArgs, null,
- IJBossRuntimeConstants.SYSPROP + IJBossRuntimeConstants.JAVA_LIB_PATH,
- libPath, true);
+ private StartLaunchDelegate del = null;
+ protected StartLaunchDelegate getDelegate(ILaunchConfiguration configuration) throws CoreException {
+ if( del != null )
+ return del;
+ IServer server = ServerUtil.getServer(configuration);
+ DeployableServerBehavior beh = ServerConverter.getDeployableServerBehavior(server);
+ IJBossServerPublishMethodType type = beh.createPublishMethod().getPublishMethodType();
+ if( type.getId().equals(LocalPublishMethod.LOCAL_PUBLISH_METHOD)) {
+ del = new LocalJBossServerStartupLaunchUtil();
}
-
- /* Claspath */
- List<String> cp = wc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, new ArrayList<String>());
- List<String> newCP = fixCP(cp, jbs);
-
- IVMInstall vmInstall = runtime.getVM();
- if( vmInstall != null )
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, JavaRuntime.newJREContainerPath(vmInstall).toPortableString());
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, serverHome + Path.SEPARATOR + IJBossRuntimeResourceConstants.BIN);
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, args.trim());
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArgs.trim());
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, newCP);
- wc.setAttribute(SERVER_ID,jbs.getServer().getId());
-
+ return del;
}
-
- protected static List<String> fixCP(List<String> list, JBossServer jbs) {
- try {
- boolean found = false;
- String[] asString = (String[]) list.toArray(new String[list.size()]);
- for( int i = 0; i < asString.length; i++ ) {
- if( asString[i].contains(RunJarContainerWrapper.ID)) {
- found = true;
- asString[i] = getRunJarRuntimeCPEntry(jbs).getMemento();
- }
- }
- ArrayList<String> result = new ArrayList<String>();
- result.addAll(Arrays.asList(asString));
- if( !found )
- result.add(getRunJarRuntimeCPEntry(jbs).getMemento());
- return result;
- } catch( CoreException ce) {
- return list;
- }
+ public void actualLaunch(ILaunchConfiguration configuration,
+ String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
+ getDelegate(configuration).actualLaunch(this, configuration, mode, launch, monitor);
}
- protected static void forceDefaultsSet(ILaunchConfigurationWorkingCopy wc, IServer server) throws CoreException {
- JBossServer jbs = findJBossServer(server.getId());
- if( jbs == null )
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
- NLS.bind(Messages.CannotSetUpImproperServer, server.getName())));
-
- String serverHome = getServerHome(jbs);
- if( serverHome == null )
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
- NLS.bind(Messages.CannotLocateServerHome, server.getName())));
-
- IRuntime rt = jbs.getServer().getRuntime();
- IJBossServerRuntime jbrt = null;
- if( rt != null ) {
- jbrt = (IJBossServerRuntime)rt.getAdapter(IJBossServerRuntime.class);
- }
-
- if( jbrt == null )
- throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
- NLS.bind(Messages.ServerRuntimeNotFound, jbs.getServer().getName())));
-
- IVMInstall vmInstall = jbrt.getVM();
- if( vmInstall != null )
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, JavaRuntime.newJREContainerPath(vmInstall).toPortableString());
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, getDefaultArgs(jbs));
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, jbrt.getDefaultRunVMArgs());
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, START_MAIN_TYPE);
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, serverHome + Path.SEPARATOR + IJBossRuntimeResourceConstants.BIN);
- wc.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, jbrt.getDefaultRunEnvVars());
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, getClasspath(jbs));
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, DEFAULT_CP_PROVIDER_ID);
- wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
-
- wc.setAttribute(DEFAULTS_SET, true);
- }
-
- protected static ArrayList<String> getClasspath(JBossServer jbs) throws CoreException {
- IJBossServerRuntime jbrt = findJBossServerRuntime(jbs.getServer());
- ArrayList<IRuntimeClasspathEntry> classpath = new ArrayList<IRuntimeClasspathEntry>();
- classpath.add(getRunJarRuntimeCPEntry(jbs));
- addJREEntry(classpath, jbrt.getVM());
-
- String version = jbs.getServer().getRuntime().getRuntimeType().getVersion();
- if( version.equals(IJBossToolingConstants.AS_40))
- addToolsJar(classpath, jbrt.getVM());
-
- ArrayList<String> runtimeClassPaths = convertClasspath(classpath);
- return runtimeClassPaths;
-
- }
+ public void superActualLaunch(ILaunchConfiguration configuration,
+ String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
+ super.actualLaunch(configuration, mode, launch, monitor);
+ }
+ /*
+ * Ensures that the working directory and classpath are 100% accurate.
+ * Merges proper required params into args and vm args
+ */
- protected static IRuntimeClasspathEntry getRunJarRuntimeCPEntry(JBossServer jbs) throws CoreException {
- IPath containerPath = new Path(RunJarContainerWrapper.ID).append(jbs.getServer().getName());
- return JavaRuntime.newRuntimeContainerClasspathEntry(containerPath, IRuntimeClasspathEntry.USER_CLASSES);
- }
-
- protected static String getDefaultArgs(JBossServer jbs) throws CoreException {
- IJBossServerRuntime rt = findJBossServerRuntime(jbs.getServer());
- if (rt != null) {
- return rt.getDefaultRunArgs() +
- IJBossRuntimeConstants.SPACE + IJBossRuntimeConstants.STARTUP_ARG_HOST_SHORT +
- IJBossRuntimeConstants.SPACE + jbs.getServer().getHost();
- }
- return null;
- }
-
public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
- JBossServerBehavior jbsBehavior = getServerBehavior(configuration);
- if( !jbsBehavior.canStart(mode).isOK())
- throw new CoreException(jbsBehavior.canStart(mode));
- return true;
+ return getDelegate(configuration).preLaunchCheck(configuration, mode, monitor);
}
- protected void preLaunch(ILaunchConfiguration configuration,
+ public void preLaunch(ILaunchConfiguration configuration,
String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
- try {
- JBossServerBehavior jbsBehavior = getServerBehavior(configuration);
- jbsBehavior.setRunMode(mode);
- jbsBehavior.serverStarting();
- } catch( CoreException ce ) {
- // report it
- }
+ getDelegate(configuration).preLaunch(configuration, mode, launch, monitor);
}
public void postLaunch(ILaunchConfiguration configuration, String mode,
ILaunch launch, IProgressMonitor monitor) throws CoreException {
- try {
- IProcess[] processes = launch.getProcesses();
- JBossServerBehavior jbsBehavior = getServerBehavior(configuration);
- jbsBehavior.setProcess(processes[0]);
- } catch( CoreException ce ) {
- // report
- }
+ getDelegate(configuration).postLaunch(configuration, mode, launch, monitor);
}
-
- public static JBossServerBehavior getServerBehavior(ILaunchConfiguration configuration) throws CoreException {
- IServer server = ServerUtil.getServer(configuration);
- JBossServerBehavior jbossServerBehavior = (JBossServerBehavior) server.getAdapter(JBossServerBehavior.class);
- return jbossServerBehavior;
- }
-
- protected static String getValidLaunchConfigurationName(String s) {
- if (s == null || s.length() == 0)
- return "1"; //$NON-NLS-1$
- int size = INVALID_CHARS.length;
- for (int i = 0; i < size; i++) {
- s = s.replace(INVALID_CHARS[i], '_');
- }
- return s;
- }
-
- /**
- * Will create a launch configuration for the server
- * if one does not already exist.
- */
- public static ILaunchConfigurationWorkingCopy createLaunchConfiguration(IServer server) throws CoreException {
- ILaunchConfigurationType launchConfigType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(LAUNCH_TYPE);
- if (launchConfigType == null)
- return null;
-
- ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
- ILaunchConfiguration[] launchConfigs = null;
- try {
- launchConfigs = launchManager.getLaunchConfigurations(launchConfigType);
- } catch (CoreException e) {
- // ignore
- }
-
- if (launchConfigs != null) {
- int size = launchConfigs.length;
- for (int i = 0; i < size; i++) {
- try {
- String serverId = launchConfigs[i].getAttribute(SERVER_ID, (String) null);
- if (server.getId().equals(serverId)) {
- ILaunchConfigurationWorkingCopy wc = launchConfigs[i].getWorkingCopy();
- return wc;
- }
- } catch (CoreException e) {
- }
- }
- }
-
- // create a new launch configuration
- String launchName = getValidLaunchConfigurationName(server.getName());
- launchName = launchManager.generateUniqueLaunchConfigurationNameFrom(launchName);
- ILaunchConfigurationWorkingCopy wc = launchConfigType.newInstance(null, launchName);
- wc.setAttribute(SERVER_ID, server.getId());
- return wc;
- }
-
- /* For "restore defaults" functionality */
- private static final String DEFAULT_CP_PROVIDER_ID = "org.jboss.ide.eclipse.as.core.server.internal.launch.serverClasspathProvider"; //$NON-NLS-1$
- public static class JBossServerDefaultClasspathProvider extends StandardClasspathProvider {
- public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration configuration) throws CoreException {
- boolean useDefault = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true);
- if (useDefault) {
- return defaultEntries(configuration);
- }
- return super.computeUnresolvedClasspath(configuration);
- }
-
- protected IRuntimeClasspathEntry[] defaultEntries(ILaunchConfiguration config) {
- try {
- String server = config.getAttribute(SERVER_ID, (String)null);
- IServer s = ServerCore.findServer(server);
- IJBossServerRuntime ibjsrt = (IJBossServerRuntime)s.getRuntime().loadAdapter(IJBossServerRuntime.class, new NullProgressMonitor());
- JBossServer jbs = (JBossServer)s.loadAdapter(JBossServer.class, new NullProgressMonitor());
- IVMInstall install = ibjsrt.getVM();
- ArrayList<IRuntimeClasspathEntry> list = new ArrayList<IRuntimeClasspathEntry>();
- addJREEntry(list, install);
- list.add(getRunJarRuntimeCPEntry(jbs));
- return (IRuntimeClasspathEntry[]) list
- .toArray(new IRuntimeClasspathEntry[list.size()]);
- } catch( CoreException ce) {
- }
- try {
- return super.computeUnresolvedClasspath(config);
- } catch( CoreException ce ) {}
- return new IRuntimeClasspathEntry[]{};
- }
- }
}
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/LocalJBossServerStartupLaunchUtil.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/LocalJBossServerStartupLaunchUtil.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/LocalJBossServerStartupLaunchUtil.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -0,0 +1,408 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.core.server.internal.launch;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+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.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
+import org.eclipse.jdt.launching.IVMInstall;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jdt.launching.StandardClasspathProvider;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerCore;
+import org.eclipse.wst.server.core.ServerUtil;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+import org.jboss.ide.eclipse.as.core.Messages;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
+import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
+import org.jboss.ide.eclipse.as.core.server.internal.JBossServerBehavior;
+import org.jboss.ide.eclipse.as.core.server.internal.LocalJBossBehaviorDelegate;
+import org.jboss.ide.eclipse.as.core.server.internal.launch.JBossServerStartupLaunchConfiguration.StartLaunchDelegate;
+import org.jboss.ide.eclipse.as.core.util.ArgsUtil;
+import org.jboss.ide.eclipse.as.core.util.IConstants;
+import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeConstants;
+import org.jboss.ide.eclipse.as.core.util.IJBossRuntimeResourceConstants;
+import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
+
+public class LocalJBossServerStartupLaunchUtil implements StartLaunchDelegate {
+
+ static final char[] INVALID_CHARS = new char[] {'\\', '/', ':', '*', '?', '"', '<', '>', '|', '\0', '@', '&'};
+ static final String LAUNCH_TYPE = "org.jboss.ide.eclipse.as.core.server.startupConfiguration"; //$NON-NLS-1$
+ static final String DEFAULTS_SET = "jboss.defaults.been.set"; //$NON-NLS-1$
+ static final String START_JAR_LOC = IJBossRuntimeResourceConstants.BIN + Path.SEPARATOR + IJBossRuntimeResourceConstants.START_JAR;
+ static final String START_MAIN_TYPE = IJBossRuntimeConstants.START_MAIN_TYPE;
+
+ public static ILaunchConfigurationWorkingCopy setupLaunchConfiguration(IServer server, String action) throws CoreException {
+ ILaunchConfigurationWorkingCopy config = createLaunchConfiguration(server);
+ setupLaunchConfiguration(config, server);
+ return config;
+ }
+
+ public static void setupLaunchConfiguration(
+ ILaunchConfigurationWorkingCopy workingCopy, IServer server) throws CoreException {
+ if(!workingCopy.getAttributes().containsKey(DEFAULTS_SET)) {
+ forceDefaultsSet(workingCopy, server);
+ }
+
+ // Upgrade old launch configs
+ JBossServer jbs = AbstractJBossLaunchConfigType.findJBossServer(server.getId());
+ if( jbs == null )
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
+ NLS.bind(Messages.CannotSetUpImproperServer, server.getName())));
+
+ String cpProvider = workingCopy.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, (String)null);
+ if( !DEFAULT_CP_PROVIDER_ID.equals(cpProvider)) {
+ workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, DEFAULT_CP_PROVIDER_ID);
+ workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, getClasspath(jbs));
+ workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
+ }
+
+ // Force the launch to get certain fields from the runtime
+ updateMandatedFields(workingCopy, jbs);
+ }
+
+ /*
+ * Ensures that the working directory and classpath are 100% accurate.
+ * Merges proper required params into args and vm args
+ */
+
+ protected static void updateMandatedFields(ILaunchConfigurationWorkingCopy wc, JBossServer jbs) throws CoreException{
+ String serverHome = AbstractJBossLaunchConfigType.getServerHome(jbs);
+ if( serverHome == null )
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
+ NLS.bind(Messages.CannotLocateServerHome, jbs.getServer().getName())));
+
+ IRuntime rt = jbs.getServer().getRuntime();
+ IJBossServerRuntime jbrt = null;
+ if( rt != null )
+ jbrt = (IJBossServerRuntime)rt.getAdapter(IJBossServerRuntime.class);
+
+ if( jbrt == null )
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
+ NLS.bind(Messages.ServerRuntimeNotFound, jbs.getServer().getName())));
+
+ /* Args and vm args */
+
+ String args = wc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, ""); //$NON-NLS-1$
+ String vmArgs = wc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, ""); //$NON-NLS-1$
+ String host = jbs.getServer().getHost();
+ String host2 = ArgsUtil.getValue(args,
+ IJBossRuntimeConstants.STARTUP_ARG_HOST_SHORT,
+ IJBossRuntimeConstants.STARTUP_ARG_HOST_LONG);
+ if( !host.equals(host2))
+ args = ArgsUtil.setArg(args,
+ IJBossRuntimeConstants.STARTUP_ARG_HOST_SHORT,
+ IJBossRuntimeConstants.STARTUP_ARG_HOST_LONG, host);
+
+ IJBossServerRuntime runtime = (IJBossServerRuntime)
+ jbs.getServer().getRuntime().loadAdapter(IJBossServerRuntime.class, null);
+ String config = runtime.getJBossConfiguration();
+ args = ArgsUtil.setArg(args,
+ IJBossRuntimeConstants.STARTUP_ARG_CONFIG_SHORT,
+ IJBossRuntimeConstants.STARTUP_ARG_CONFIG_LONG, config);
+
+ try {
+ if( !runtime.getConfigLocation().equals(IConstants.SERVER)) {
+ args = ArgsUtil.setArg(args, null,
+ IJBossRuntimeConstants.SYSPROP + IJBossRuntimeConstants.JBOSS_SERVER_HOME_URL,
+ runtime.getConfigLocationFullPath().toFile().toURL().toString());
+ }
+ } catch( MalformedURLException murle) {}
+
+
+ vmArgs= ArgsUtil.setArg(vmArgs, null,
+ IJBossRuntimeConstants.SYSPROP + IJBossRuntimeConstants.ENDORSED_DIRS,
+ runtime.getRuntime().getLocation().append(
+ IJBossRuntimeResourceConstants.LIB).append(
+ IJBossRuntimeResourceConstants.ENDORSED).toOSString(), true);
+
+ if( runtime.getRuntime().getLocation().append(
+ IJBossRuntimeResourceConstants.BIN).append(
+ IJBossRuntimeResourceConstants.NATIVE).toFile().exists() ) {
+ String argVal = ArgsUtil.getValue(vmArgs, null,
+ IJBossRuntimeConstants.SYSPROP + IJBossRuntimeConstants.JAVA_LIB_PATH);
+
+ String libPath =
+ runtime.getRuntime().getLocation()
+ .append(IJBossRuntimeResourceConstants.BIN)
+ .append(IJBossRuntimeResourceConstants.NATIVE).toOSString();
+ if( argVal != null ) {
+ if( argVal.startsWith("\"")) //$NON-NLS-1$
+ argVal = argVal.substring(1);
+ if( argVal.endsWith("\"")) //$NON-NLS-1$
+ argVal = argVal.substring(0, argVal.length()-1);
+ if( argVal.startsWith(":")) //$NON-NLS-1$
+ argVal = argVal.substring(1);
+
+ String[] asArr = argVal.split(File.pathSeparator);
+ asArr[0] = libPath;
+ String implode = ""; //$NON-NLS-1$
+ for( int i = 0; i < asArr.length; i++ )
+ implode += asArr[i] + File.pathSeparator;
+ libPath = implode;
+ }
+ vmArgs = ArgsUtil.setArg(vmArgs, null,
+ IJBossRuntimeConstants.SYSPROP + IJBossRuntimeConstants.JAVA_LIB_PATH,
+ libPath, true);
+ }
+
+ /* Claspath */
+ List<String> cp = wc.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, new ArrayList<String>());
+ List<String> newCP = fixCP(cp, jbs);
+
+ IVMInstall vmInstall = runtime.getVM();
+ if( vmInstall != null )
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, JavaRuntime.newJREContainerPath(vmInstall).toPortableString());
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, serverHome + Path.SEPARATOR + IJBossRuntimeResourceConstants.BIN);
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, args.trim());
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, vmArgs.trim());
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, newCP);
+ wc.setAttribute(AbstractJBossLaunchConfigType.SERVER_ID,jbs.getServer().getId());
+
+ }
+
+ protected static List<String> fixCP(List<String> list, JBossServer jbs) {
+ try {
+ boolean found = false;
+ String[] asString = (String[]) list.toArray(new String[list.size()]);
+ for( int i = 0; i < asString.length; i++ ) {
+ if( asString[i].contains(RunJarContainerWrapper.ID)) {
+ found = true;
+ asString[i] = getRunJarRuntimeCPEntry(jbs).getMemento();
+ }
+ }
+ ArrayList<String> result = new ArrayList<String>();
+ result.addAll(Arrays.asList(asString));
+ if( !found )
+ result.add(getRunJarRuntimeCPEntry(jbs).getMemento());
+ return result;
+ } catch( CoreException ce) {
+ return list;
+ }
+ }
+
+ protected static void forceDefaultsSet(ILaunchConfigurationWorkingCopy wc, IServer server) throws CoreException {
+ JBossServer jbs = AbstractJBossLaunchConfigType.findJBossServer(server.getId());
+ if( jbs == null )
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
+ NLS.bind(Messages.CannotSetUpImproperServer, server.getName())));
+
+ String serverHome = AbstractJBossLaunchConfigType.getServerHome(jbs);
+ if( serverHome == null )
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
+ NLS.bind(Messages.CannotLocateServerHome, server.getName())));
+
+ IRuntime rt = jbs.getServer().getRuntime();
+ IJBossServerRuntime jbrt = null;
+ if( rt != null ) {
+ jbrt = (IJBossServerRuntime)rt.getAdapter(IJBossServerRuntime.class);
+ }
+
+ if( jbrt == null )
+ throw new CoreException(new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID,
+ NLS.bind(Messages.ServerRuntimeNotFound, jbs.getServer().getName())));
+
+ IVMInstall vmInstall = jbrt.getVM();
+ if( vmInstall != null )
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, JavaRuntime.newJREContainerPath(vmInstall).toPortableString());
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, getDefaultArgs(jbs));
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, jbrt.getDefaultRunVMArgs());
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, START_MAIN_TYPE);
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, serverHome + Path.SEPARATOR + IJBossRuntimeResourceConstants.BIN);
+ wc.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, jbrt.getDefaultRunEnvVars());
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, getClasspath(jbs));
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, DEFAULT_CP_PROVIDER_ID);
+ wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, false);
+
+ wc.setAttribute(DEFAULTS_SET, true);
+ }
+
+ protected static ArrayList<String> getClasspath(JBossServer jbs) throws CoreException {
+ IJBossServerRuntime jbrt = AbstractJBossLaunchConfigType.findJBossServerRuntime(jbs.getServer());
+ ArrayList<IRuntimeClasspathEntry> classpath = new ArrayList<IRuntimeClasspathEntry>();
+ classpath.add(getRunJarRuntimeCPEntry(jbs));
+ AbstractJBossLaunchConfigType.addJREEntry(classpath, jbrt.getVM());
+
+ String version = jbs.getServer().getRuntime().getRuntimeType().getVersion();
+ if( version.equals(IJBossToolingConstants.AS_40))
+ AbstractJBossLaunchConfigType.addToolsJar(classpath, jbrt.getVM());
+
+ ArrayList<String> runtimeClassPaths = AbstractJBossLaunchConfigType.convertClasspath(classpath);
+ return runtimeClassPaths;
+
+ }
+
+ protected static IRuntimeClasspathEntry getRunJarRuntimeCPEntry(JBossServer jbs) throws CoreException {
+ IPath containerPath = new Path(RunJarContainerWrapper.ID).append(jbs.getServer().getName());
+ return JavaRuntime.newRuntimeContainerClasspathEntry(containerPath, IRuntimeClasspathEntry.USER_CLASSES);
+ }
+
+ protected static String getDefaultArgs(JBossServer jbs) throws CoreException {
+ IJBossServerRuntime rt = AbstractJBossLaunchConfigType.findJBossServerRuntime(jbs.getServer());
+ if (rt != null) {
+ return rt.getDefaultRunArgs() +
+ IJBossRuntimeConstants.SPACE + IJBossRuntimeConstants.STARTUP_ARG_HOST_SHORT +
+ IJBossRuntimeConstants.SPACE + jbs.getServer().getHost();
+ }
+ return null;
+ }
+
+
+ public static JBossServerBehavior getServerBehavior(ILaunchConfiguration configuration) throws CoreException {
+ IServer server = ServerUtil.getServer(configuration);
+ JBossServerBehavior jbossServerBehavior = (JBossServerBehavior) server.getAdapter(JBossServerBehavior.class);
+ return jbossServerBehavior;
+ }
+
+ protected static String getValidLaunchConfigurationName(String s) {
+ if (s == null || s.length() == 0)
+ return "1"; //$NON-NLS-1$
+ int size = INVALID_CHARS.length;
+ for (int i = 0; i < size; i++) {
+ s = s.replace(INVALID_CHARS[i], '_');
+ }
+ return s;
+ }
+
+ /**
+ * Will create a launch configuration for the server
+ * if one does not already exist.
+ */
+ public static ILaunchConfigurationWorkingCopy createLaunchConfiguration(IServer server) throws CoreException {
+ ILaunchConfigurationType launchConfigType = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationType(LAUNCH_TYPE);
+ if (launchConfigType == null)
+ return null;
+
+ ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfiguration[] launchConfigs = null;
+ try {
+ launchConfigs = launchManager.getLaunchConfigurations(launchConfigType);
+ } catch (CoreException e) {
+ // ignore
+ }
+
+ if (launchConfigs != null) {
+ int size = launchConfigs.length;
+ for (int i = 0; i < size; i++) {
+ try {
+ String serverId = launchConfigs[i].getAttribute(AbstractJBossLaunchConfigType.SERVER_ID, (String) null);
+ if (server.getId().equals(serverId)) {
+ ILaunchConfigurationWorkingCopy wc = launchConfigs[i].getWorkingCopy();
+ return wc;
+ }
+ } catch (CoreException e) {
+ }
+ }
+ }
+
+ // create a new launch configuration
+ String launchName = getValidLaunchConfigurationName(server.getName());
+ launchName = launchManager.generateUniqueLaunchConfigurationNameFrom(launchName);
+ ILaunchConfigurationWorkingCopy wc = launchConfigType.newInstance(null, launchName);
+ wc.setAttribute(AbstractJBossLaunchConfigType.SERVER_ID, server.getId());
+ return wc;
+ }
+
+ /* For "restore defaults" functionality */
+ private static final String DEFAULT_CP_PROVIDER_ID = "org.jboss.ide.eclipse.as.core.server.internal.launch.serverClasspathProvider"; //$NON-NLS-1$
+ public static class JBossServerDefaultClasspathProvider extends StandardClasspathProvider {
+ public IRuntimeClasspathEntry[] computeUnresolvedClasspath(ILaunchConfiguration configuration) throws CoreException {
+ boolean useDefault = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true);
+ if (useDefault) {
+ return defaultEntries(configuration);
+ }
+ return super.computeUnresolvedClasspath(configuration);
+ }
+
+ protected IRuntimeClasspathEntry[] defaultEntries(ILaunchConfiguration config) {
+ try {
+ String server = config.getAttribute(AbstractJBossLaunchConfigType.SERVER_ID, (String)null);
+ IServer s = ServerCore.findServer(server);
+ IJBossServerRuntime ibjsrt = (IJBossServerRuntime)s.getRuntime().loadAdapter(IJBossServerRuntime.class, new NullProgressMonitor());
+ JBossServer jbs = (JBossServer)s.loadAdapter(JBossServer.class, new NullProgressMonitor());
+ IVMInstall install = ibjsrt.getVM();
+ ArrayList<IRuntimeClasspathEntry> list = new ArrayList<IRuntimeClasspathEntry>();
+ AbstractJBossLaunchConfigType.addJREEntry(list, install);
+ list.add(getRunJarRuntimeCPEntry(jbs));
+ return (IRuntimeClasspathEntry[]) list
+ .toArray(new IRuntimeClasspathEntry[list.size()]);
+ } catch( CoreException ce) {
+ }
+ try {
+ return super.computeUnresolvedClasspath(config);
+ } catch( CoreException ce ) {}
+ return new IRuntimeClasspathEntry[]{};
+ }
+ }
+
+
+
+ /*
+ * Actual instance methods
+ */
+ public void actualLaunch(
+ JBossServerStartupLaunchConfiguration launchConfig,
+ ILaunchConfiguration configuration, String mode, ILaunch launch,
+ IProgressMonitor monitor) throws CoreException {
+ launchConfig.superActualLaunch(configuration, mode, launch, monitor);
+ }
+
+ public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
+ JBossServerBehavior jbsBehavior = getServerBehavior(configuration);
+ if( !jbsBehavior.canStart(mode).isOK())
+ throw new CoreException(jbsBehavior.canStart(mode));
+ return true;
+ }
+
+ public void preLaunch(ILaunchConfiguration configuration,
+ String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
+ try {
+ JBossServerBehavior jbsBehavior = getServerBehavior(configuration);
+ jbsBehavior.setRunMode(mode);
+ jbsBehavior.serverStarting();
+ } catch( CoreException ce ) {
+ // report it
+ }
+ }
+
+ public void postLaunch(ILaunchConfiguration configuration, String mode,
+ ILaunch launch, IProgressMonitor monitor) throws CoreException {
+ try {
+ IProcess[] processes = launch.getProcesses();
+ JBossServerBehavior jbsBehavior = getServerBehavior(configuration);
+ ((LocalJBossBehaviorDelegate)(jbsBehavior.getDelegate())).setProcess(processes[0]);
+ } catch( CoreException ce ) {
+ // report
+ }
+ }
+
+}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/RunJarContainerWrapper.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/RunJarContainerWrapper.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/RunJarContainerWrapper.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -82,7 +82,7 @@
if( s != null ) {
IRuntime rt = s.getRuntime();
IPath home = rt.getLocation();
- IPath runJar = home.append(JBossServerStartupLaunchConfiguration.START_JAR_LOC);
+ IPath runJar = home.append(LocalJBossServerStartupLaunchUtil.START_JAR_LOC);
return new IClasspathEntry[] {
JavaRuntime.newArchiveRuntimeClasspathEntry(
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/StopLaunchConfiguration.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/StopLaunchConfiguration.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/StopLaunchConfiguration.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -68,7 +68,7 @@
}
}
- protected void preLaunch(ILaunchConfiguration configuration,
+ public void preLaunch(ILaunchConfiguration configuration,
String mode, ILaunch launch, IProgressMonitor monitor) {
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishCopyUtil.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishCopyUtil.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/xpl/PublishCopyUtil.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -26,9 +26,11 @@
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.osgi.util.NLS;
+import org.eclipse.wst.common.project.facet.core.util.internal.ProgressMonitorUtil;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.internal.Messages;
import org.eclipse.wst.server.core.internal.ProgressUtil;
@@ -37,6 +39,7 @@
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.JBossServerCorePlugin;
import org.jboss.ide.eclipse.as.core.publishers.PublishUtil;
import org.jboss.ide.eclipse.as.core.util.ServerConverter;
/**
@@ -426,7 +429,13 @@
this.handler = handler;
}
+ protected IStatus[] canceledStatus() {
+ return new IStatus[]{
+ new Status(IStatus.CANCEL, JBossServerCorePlugin.PLUGIN_ID, "Publish Canceled") //$NON-NLS-1$
+ }; // todo
+ }
+
/**
* Handle a delta publish.
*
@@ -465,7 +474,9 @@
*/
public IStatus[] publishDelta(IModuleResourceDelta delta, IPath path, IProgressMonitor monitor) throws CoreException {
List status = new ArrayList(2);
-
+ if( monitor.isCanceled())
+ return canceledStatus();
+
IModuleResource resource = delta.getModuleResource();
int kind2 = delta.getKind();
@@ -496,6 +507,8 @@
IModuleResourceDelta[] childDeltas = delta.getAffectedChildren();
int size = childDeltas.length;
for (int i = 0; i < size; i++) {
+ if( monitor.isCanceled())
+ return canceledStatus();
IStatus[] stat = publishDelta(childDeltas[i], path, monitor);
addArrayToList(status, stat);
}
@@ -524,8 +537,13 @@
* @return a possibly-empty array of error and warning status
*/
public IStatus[] publishFull(IModuleResource[] resources, IProgressMonitor monitor) throws CoreException {
- handler.makeDirectoryIfRequired(new Path("/"), monitor); //$NON-NLS-1$
- return publishFull(resources, new Path("/"), monitor); //$NON-NLS-1$
+ monitor.beginTask("Publishing " + resources.length + " resources", 100 * (resources.length) + 100); //$NON-NLS-1$ //$NON-NLS-2$
+ handler.makeDirectoryIfRequired(new Path("/"), ProgressMonitorUtil.submon(monitor, 100)); //$NON-NLS-1$
+ if( monitor.isCanceled())
+ return canceledStatus();
+ IStatus[] results = publishFull(resources, new Path("/"), ProgressMonitorUtil.submon(monitor, 100*resources.length)); //$NON-NLS-1$
+ monitor.done();
+ return results;
}
public IStatus[] publishFull(IModuleResource[] resources, IPath relative, IProgressMonitor monitor) throws CoreException {
@@ -533,14 +551,16 @@
return EMPTY_STATUS;
monitor = ProgressUtil.getMonitorFor(monitor);
-
+ monitor.beginTask("Publishing " + resources.length + " resources", 100 * (resources.length)); //$NON-NLS-1$ //$NON-NLS-2$
List status = new ArrayList(2);
int size = resources.length;
for (int i = 0; i < size; i++) {
- IStatus[] stat = copy(resources[i], relative, monitor);
+ if( monitor.isCanceled())
+ return canceledStatus();
+ IStatus[] stat = copy(resources[i], relative, ProgressMonitorUtil.submon(monitor, 100));
addArrayToList(status, stat);
}
-
+ monitor.done();
IStatus[] stat = new IStatus[status.size()];
status.toArray(stat);
return stat;
@@ -554,7 +574,7 @@
IModuleFolder folder = (IModuleFolder) resource;
IModuleResource[] children = folder.members();
if( children.length == 0 )
- handler.makeDirectoryIfRequired(folder.getModuleRelativePath().append(folder.getName()), monitor);
+ handler.makeDirectoryIfRequired(folder.getModuleRelativePath().append(folder.getName()), monitor);
else {
IStatus[] stat = publishFull(children, path, monitor);
addArrayToList(status, stat);
@@ -562,8 +582,8 @@
} else {
IModuleFile mf = (IModuleFile) resource;
path = path.append(mf.getModuleRelativePath()).append(name);
- IStatus[] stats = handler.makeDirectoryIfRequired(path.removeLastSegments(1), monitor);
- if( stats.length > 0 && !stats[0].isOK())
+ IStatus[] stats = handler.makeDirectoryIfRequired(path.removeLastSegments(1), new NullProgressMonitor());
+ if( stats != null && stats.length > 0 && !stats[0].isOK())
addArrayToList(status, stats);
addArrayToList(status, handler.copyFile(mf, path, monitor));
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/DeploymentPreferenceLoader.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/DeploymentPreferenceLoader.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/DeploymentPreferenceLoader.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.ide.eclipse.as.core.util;
import java.io.ByteArrayInputStream;
@@ -13,12 +23,35 @@
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.internal.Server;
+import org.jboss.ide.eclipse.as.core.ExtensionManager;
+import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethodType;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
import org.jboss.tools.jmx.core.IMemento;
import org.jboss.tools.jmx.core.util.XMLMemento;
public class DeploymentPreferenceLoader {
public static final String DEPLOYMENT_PREFERENCES_KEY = "org.jboss.ide.eclipse.as.core.util.deploymentPreferenceKey"; //$NON-NLS-1$
+ public static final String CURRENT_METHOD_PROPERTY = "publishMethod"; //$NON-NLS-1$
+ /**
+ * This method can return null and is only meant to show what deployment method
+ * is currently stored in a server's deployment preferences.
+ *
+ * To get a more accurate version (with a default) please use
+ * DeployableServerBehavior.createPublishMethod().getPublishMethodType()
+ *
+ * @param server
+ * @return
+ */
+ public static IJBossServerPublishMethodType getCurrentDeploymentMethodType(IServer server) {
+ String type = server.getAttribute(IDeployableServer.SERVER_MODE, (String)null);
+ if( type != null ) {
+ return ExtensionManager.getDefault().getPublishMethod(type);
+ }
+ return null;
+ }
+
public static DeploymentPreferences loadPreferencesFromFile(IServer server) {
File f = getFile(server);
InputStream is = null;
@@ -92,6 +125,30 @@
protected XMLMemento getMemento() {
return memento;
}
+ public String getProperty(String key) {
+ IMemento[] children = memento.getChildren("property"); //$NON-NLS-1$
+ for( int i = 0; i < children.length; i++ ) {
+ if( key.equals(children[i].getString("key"))) { //$NON-NLS-1$
+ return children[i].getString("value"); //$NON-NLS-1$
+ }
+ }
+ return null;
+ }
+
+ public void setProperty(String key, String val) {
+ IMemento[] children = memento.getChildren("property"); //$NON-NLS-1$
+ for( int i = 0; i < children.length; i++ ) {
+ if( key.equals(children[i].getString("key"))) { //$NON-NLS-1$
+ children[i].putString("key", key); //$NON-NLS-1$
+ children[i].putString("value", val);//$NON-NLS-1$
+ return;
+ }
+ }
+ // not found
+ IMemento child = memento.createChild("property"); //$NON-NLS-1$
+ child.putString("key", key);//$NON-NLS-1$
+ child.putString("value", val);//$NON-NLS-1$
+ }
}
public static class DeploymentTypePrefs {
@@ -107,7 +164,6 @@
String id = mementos[i].getString("id"); //$NON-NLS-1$
this.children.put(id, new DeploymentModulePrefs(id, mementos[i]));
}
- // TODO properties?
}
public DeploymentModulePrefs getModulePrefs(IModule module) {
@@ -123,6 +179,31 @@
}
return children.get(module.getId());
}
+
+ public String getProperty(String key) {
+ IMemento[] children = memento.getChildren("property"); //$NON-NLS-1$
+ for( int i = 0; i < children.length; i++ ) {
+ if( key.equals(children[i].getString("key"))) { //$NON-NLS-1$
+ return children[i].getString("value"); //$NON-NLS-1$
+ }
+ }
+ return null;
+ }
+
+ public void setProperty(String key, String val) {
+ IMemento[] children = memento.getChildren("property"); //$NON-NLS-1$
+ for( int i = 0; i < children.length; i++ ) {
+ if( key.equals(children[i].getString("key"))) { //$NON-NLS-1$
+ children[i].putString("key", key); //$NON-NLS-1$
+ children[i].putString("value", val);//$NON-NLS-1$
+ return;
+ }
+ }
+ // not found
+ IMemento child = memento.createChild("property"); //$NON-NLS-1$
+ child.putString("key", key);//$NON-NLS-1$
+ child.putString("value", val);//$NON-NLS-1$
+ }
}
public static class DeploymentModulePrefs {
private String id;
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/IJBossToolingConstants.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/IJBossToolingConstants.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/IJBossToolingConstants.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -48,6 +48,7 @@
/* Files or folders inside the TOOLING */
public static final String LOG = "log"; //$NON-NLS-1$
public static final String TEMP_DEPLOY = "tempDeploy"; //$NON-NLS-1$
+ public static final String TEMP_REMOTE_DEPLOY = "tempRemoteDeploy"; //$NON-NLS-1$
public static final String JBOSSTOOLS_TMP = "jbosstoolsTemp"; //$NON-NLS-1$
public static final String TMP = "tmp"; //$NON-NLS-1$
public static final String CONFIG_IN_METADATA = "jbossConfig"; //$NON-NLS-1$
@@ -72,7 +73,6 @@
/*
* Property keys stored in the server object
*/
- public static final String DEPLOYMENT_METHOD = "org.jboss.ide.eclipse.as.core.server.attributes.deploymentMethod"; //$NON-NLS-1$
public static final String STARTUP_POLLER_KEY = "org.jboss.ide.eclipse.as.core.server.attributes.startupPollerKey"; //$NON-NLS-1$
public static final String SHUTDOWN_POLLER_KEY = "org.jboss.ide.eclipse.as.core.server.attributes.shutdownPollerKey"; //$NON-NLS-1$
public static final String SERVER_USERNAME = "org.jboss.ide.eclipse.as.core.server.userName"; //$NON-NLS-1$
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/ServerConverter.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/ServerConverter.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/util/ServerConverter.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -13,10 +13,13 @@
import java.util.ArrayList;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.wst.server.core.IRuntime;
import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.IServerAttributes;
import org.eclipse.wst.server.core.IServerWorkingCopy;
import org.eclipse.wst.server.core.ServerCore;
import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
import org.jboss.ide.eclipse.as.core.server.internal.DeployableServerBehavior;
import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
@@ -106,5 +109,12 @@
servers.toArray(ret);
return ret;
}
+ public static IJBossServerRuntime getJBossRuntime(IServer server) {
+ return getJBossRuntime((IServerAttributes)server);
+ }
+ public static IJBossServerRuntime getJBossRuntime(IServerAttributes server) {
+ IRuntime rt = server.getRuntime();
+ return (IJBossServerRuntime)rt.loadAdapter(IJBossServerRuntime.class, null);
+ }
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.properties
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.properties 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.properties 2010-08-13 05:37:30 UTC (rev 24129)
@@ -43,4 +43,9 @@
deploy.server.description=A server which only provides a deploy folder for publishing.
Bundle-Vendor.0 = JBoss by Red Hat
-Bundle-Name.0 = JBoss AS Core Plug-in
\ No newline at end of file
+Bundle-Name.0 = JBoss AS Core Plug-in
+
+AllJBossRuntimeTypes=org.jboss.ide.eclipse.as.runtime.32,org.jboss.ide.eclipse.as.runtime.40,org.jboss.ide.eclipse.as.runtime.42,org.jboss.ide.eclipse.as.runtime.50,org.jboss.ide.eclipse.as.runtime.51,org.jboss.ide.eclipse.as.runtime.60,org.jboss.ide.eclipse.as.runtime.eap.43,org.jboss.ide.eclipse.as.runtime.eap.50
+AllJBossServerTypes=org.jboss.ide.eclipse.as.32,org.jboss.ide.eclipse.as.40,org.jboss.ide.eclipse.as.42,org.jboss.ide.eclipse.as.50,org.jboss.ide.eclipse.as.51,org.jboss.ide.eclipse.as.60,org.jboss.ide.eclipse.as.eap.43,org.jboss.ide.eclipse.as.eap.50
+AllJBTServerTypes=org.jboss.ide.eclipse.as.32,org.jboss.ide.eclipse.as.40,org.jboss.ide.eclipse.as.42,org.jboss.ide.eclipse.as.50,org.jboss.ide.eclipse.as.51,org.jboss.ide.eclipse.as.60,org.jboss.ide.eclipse.as.eap.43,org.jboss.ide.eclipse.as.eap.50,org.jboss.ide.eclipse.as.systemCopyServer
+ServerTypesJBoss6OrHigher=org.jboss.ide.eclipse.as.60
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/plugin.xml 2010-08-13 05:37:30 UTC (rev 24129)
@@ -351,7 +351,7 @@
versions="5.0"/>
<moduleType
types="jst.web"
- versions="2.2, 2.3, 2.4, 2.5, 3.0"/>
+ versions="2.2, 2.3, 2.4, 2.5"/>
<moduleType
types="jst.ejb"
versions="1.0, 1.1, 2.0, 2.1, 3.0"/>
@@ -795,7 +795,7 @@
<runtime-component
id="org.jboss.ide.eclipse.as.runtime.component"
version="6.0"/>
- <facet id="jst.web" version="2.2,2.3,2.4,2.5,3.0"/>
+ <facet id="jst.web" version="2.2,2.3,2.4,2.5"/>
<facet id="jst.java" version="5.0,6.0"/>
<facet id="jst.utility" version="1.0"/>
<facet id="jst.connector" version="1.0,1.5"/>
@@ -855,7 +855,7 @@
</runtime-component>
<facet
id="jst.java"
- version="6.0">
+ version="5.0">
</facet>
</default-facets>
<default-facets>
@@ -1019,7 +1019,7 @@
<extension
point="org.eclipse.jdt.launching.classpathProviders">
<classpathProvider
- class="org.jboss.ide.eclipse.as.core.server.internal.launch.JBossServerStartupLaunchConfiguration$JBossServerDefaultClasspathProvider"
+ class="org.jboss.ide.eclipse.as.core.server.internal.launch.LocalJBossServerStartupLaunchUtil$JBossServerDefaultClasspathProvider"
id="org.jboss.ide.eclipse.as.core.server.internal.launch.serverClasspathProvider">
</classpathProvider>
</extension>
@@ -1038,4 +1038,13 @@
supportsArgument="true">
</variable>
</extension>
+ <extension
+ point="org.jboss.ide.eclipse.as.core.publishMethod">
+ <publishMethod
+ id="local"
+ name="Local"
+ class="org.jboss.ide.eclipse.as.core.publishers.LocalPublishMethod"
+ serverTypes="%AllJBTServerTypes">
+ </publishMethod>
+ </extension>
</plugin>
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/schema/publishMethod.exsd
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/schema/publishMethod.exsd 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/schema/publishMethod.exsd 2010-08-13 05:37:30 UTC (rev 24129)
@@ -49,6 +49,20 @@
<element name="publishMethod">
<complexType>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string" use="required">
+ <annotation>
+ <documentation>
+ String representation of this publish method
+ </documentation>
+ </annotation>
+ </attribute>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
@@ -59,6 +73,13 @@
</appInfo>
</annotation>
</attribute>
+ <attribute name="serverTypes" type="string" use="required">
+ <annotation>
+ <documentation>
+ A list of comma-separated server types this publish method is available to.
+ </documentation>
+ </annotation>
+ </attribute>
</complexType>
</element>
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/plugin.xml
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/plugin.xml 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/plugin.xml 2010-08-13 05:37:30 UTC (rev 24129)
@@ -69,7 +69,7 @@
zipDelegate="true">
</publisher>
<publisher
- class="org.jboss.ide.eclipse.as.ssh.server.SSHPublisher"
+ class="org.jboss.ide.eclipse.as.ssh.server.SSHJstPublisher"
priority="3"
zipDelegate="false">
</publisher>
@@ -112,5 +112,14 @@
typeIds="org.jboss.ide.eclipse.as.ssh.server.remoteServerType">
</fragment>
</extension>
+ <extension
+ point="org.jboss.ide.eclipse.as.core.publishMethod">
+ <publishMethod
+ class="org.jboss.ide.eclipse.as.ssh.server.SSHServerBehaviourDelegate$SSHPublishMethod"
+ id="ssh"
+ name="SSH Remote Deployment"
+ serverTypes="org.jboss.ide.eclipse.as.ssh.server.remoteServerType">
+ </publishMethod>
+ </extension>
</plugin>
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHCommandUtil.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHCommandUtil.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHCommandUtil.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -0,0 +1,213 @@
+package org.jboss.ide.eclipse.as.ssh.server;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
+import org.jboss.ide.eclipse.as.ssh.SSHDeploymentPlugin;
+
+import com.jcraft.jsch.Channel;
+import com.jcraft.jsch.ChannelExec;
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.Session;
+
+public class SSHCommandUtil {
+ public static void launchRemoveCommand(Session session, String remoteLocation, IProgressMonitor monitor) throws CoreException {
+ String command = "rm " + remoteLocation;
+ launchCommand(session, command, monitor);
+ }
+
+ public static void launchCommand(Session session, String command, IProgressMonitor monitor) throws CoreException {
+ launchThreadedCommand(session, command, monitor);
+ }
+
+ public static void launchThreadedCommand(final Session session, final String command, final IProgressMonitor monitor) throws CoreException {
+ // thread and watch the monitor for cancelations and interrupt the thread
+ LaunchRunnable r = new LaunchRunnable() { public void run() throws CoreException {
+ launchCommandNoThread(session, command, monitor);
+ } };
+ launchThreadedCommand(r, monitor);
+ }
+
+ public static void launchCommandNoThread(Session session, String command, IProgressMonitor monitor) throws CoreException {
+ Channel channel = null;
+ try {
+ channel = session.openChannel("exec");
+ ((ChannelExec) channel).setCommand(command);
+
+ channel.connect();
+ while(!channel.isClosed()) {
+ try {Thread.sleep(300);} catch(InterruptedException ie) {}
+ }
+ } catch( JSchException jsche ) {
+ throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error executing command: " + command, null));
+ } finally {
+ channel.disconnect();
+ }
+ }
+
+ public static class LaunchRunnable {
+ public void run() throws CoreException {
+ }
+ }
+
+ public static void launchCopyCommand(final Session session, final String localFile,
+ final String remoteFile, final IProgressMonitor monitor) throws CoreException {
+ // thread and watch the monitor for cancelations and interrupt the thread
+ LaunchRunnable r = new LaunchRunnable() { public void run() throws CoreException {
+ launchCopyCommandImpl(session, localFile, remoteFile, monitor);
+ } };
+ launchThreadedCommand(r, monitor);
+ }
+
+ public static void launchThreadedCommand(final LaunchRunnable runnable, IProgressMonitor monitor) throws CoreException {
+ final Exception[] e = new Exception[1];
+ e[0] = null;
+ final Object waitObject = new Object();
+ final Boolean[] subtaskComplete = new Boolean[1];
+ subtaskComplete[0] = new Boolean(false);
+ Thread t = new Thread() {
+ public void run() {
+ Exception exception = null;
+ try {
+ runnable.run();
+ } catch( Exception ex ) {
+ exception = ex;
+ }
+ synchronized(waitObject) {
+ e[0] = exception;
+ subtaskComplete[0] = new Boolean(true);
+ waitObject.notifyAll();
+ }
+ }
+ };
+ t.start();
+ while(t.isAlive() && !monitor.isCanceled() ) {
+ synchronized(waitObject) {
+ if( subtaskComplete[0].booleanValue() )
+ break;
+ try {
+ waitObject.wait(500);
+ } catch(InterruptedException ie) {}
+ }
+ }
+ synchronized(waitObject) {
+ if( !subtaskComplete[0].booleanValue()) {
+ t.interrupt();
+ IStatus status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.ISTATUS_CODE_ERROR, "SSH command canceled", e[0]);
+ CoreException ce = new CoreException(status);
+ throw ce;
+ }
+ if( e[0] != null ) {
+ IStatus status = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.ISTATUS_CODE_ERROR, "Error running remote command", e[0]);
+ CoreException ce = new CoreException(status);
+ throw ce;
+ }
+
+ }
+ }
+
+ public static void launchCopyCommandImpl(Session session, String localFile, String remoteFile, IProgressMonitor monitor) throws CoreException {
+ Channel channel = null;
+ OutputStream out = null;
+ try {
+ // exec 'scp -t rfile' remotely
+ String command = "scp -p -t " + remoteFile;
+ channel = session.openChannel("exec");
+ ((ChannelExec) channel).setCommand(command);
+
+ // get I/O streams for remote scp
+ out = channel.getOutputStream();
+ InputStream in = channel.getInputStream();
+ channel.connect();
+ if (checkAck(in) != 0) {
+ throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, null));
+ }
+
+ // send "C0644 filesize filename", where filename should not include
+ // '/'
+ long filesize = (new File(localFile)).length();
+ command = "C0644 " + filesize + " ";
+ if (localFile.lastIndexOf('/') > 0) {
+ command += localFile.substring(localFile.lastIndexOf('/') + 1);
+ } else {
+ command += localFile;
+ }
+ command += "\n";
+ out.write(command.getBytes());
+ out.flush();
+ if (checkAck(in) != 0) {
+ throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, null));
+ }
+
+ // send a content of lfile
+ FileInputStream fis = new FileInputStream(localFile);
+ byte[] buf = new byte[1024];
+ while (true) {
+ int len = fis.read(buf, 0, buf.length);
+ if (len <= 0)
+ break;
+ out.write(buf, 0, len); // out.flush();
+ }
+ fis.close();
+ fis = null;
+ // send '\0'
+ buf[0] = 0;
+ out.write(buf, 0, 1);
+ out.flush();
+ if (checkAck(in) != 0) {
+ throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, null));
+ }
+
+ } catch( JSchException jsche ) {
+ throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, jsche));
+ } catch( IOException ioe) {
+ throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, ioe));
+ } finally {
+ if( channel != null )
+ channel.disconnect();
+ if( out != null ) {
+ try {
+ out.close();
+ } catch(IOException ioe) {}
+ }
+ }
+ }
+
+ static int checkAck(InputStream in) throws IOException {
+ int b = in.read();
+ // b may be 0 for success,
+ // 1 for error,
+ // 2 for fatal error,
+ // -1
+ if (b == 0)
+ return b;
+ if (b == -1)
+ return b;
+
+ if (b == 1 || b == 2) {
+ StringBuffer sb = new StringBuffer();
+ int c;
+ do {
+ c = in.read();
+ sb.append((char) c);
+ } while (c != '\n');
+// if (b == 1) { // error
+// System.out.print(sb.toString());
+// }
+// if (b == 2) { // fatal error
+// System.out.print(sb.toString());
+// }
+ }
+ return b;
+ }
+
+}
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHCopyCallback.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHCopyCallback.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHCopyCallback.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.ssh.server;
+
+import java.io.File;
+
+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.NullProgressMonitor;
+import org.eclipse.wst.server.core.model.IModuleFile;
+import org.jboss.ide.eclipse.as.core.publishers.PublishUtil;
+import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
+import org.jboss.ide.eclipse.as.ssh.server.SSHServerBehaviourDelegate.SSHPublishMethod;
+
+import com.jcraft.jsch.Session;
+
+public class SSHCopyCallback implements IPublishCopyCallbackHandler {
+
+ private IPath root;
+ private SSHPublishMethod method;
+ public SSHCopyCallback(IPath deployRoot, SSHPublishMethod method) {
+ this.root = deployRoot;
+ this.method = method;
+ }
+
+ public IStatus[] copyFile(IModuleFile mf, IPath path,
+ IProgressMonitor monitor) throws CoreException {
+ File sourceFile = PublishUtil.getFile(mf);
+ IPath destination = root.append(path);
+ String parentFolder = destination.removeLastSegments(1).toString();
+ SSHCommandUtil.launchCommand(getSession(), "mkdir -p " + parentFolder, new NullProgressMonitor());
+ SSHCommandUtil.launchCopyCommand(getSession(), sourceFile.getAbsolutePath(), destination.toString(), new NullProgressMonitor());
+ return new IStatus[]{};
+ }
+
+ protected Session getSession() {
+ return method.getSession();
+ }
+
+ public IStatus[] deleteResource(IPath path, IProgressMonitor monitor) {
+ IPath remotePath = root.append(path);
+ try {
+ SSHCommandUtil.launchCommand(method.getSession(), "rm -rf " + remotePath.toString(), monitor);
+ } catch( CoreException ce ) {
+ return new IStatus[]{ce.getStatus()};
+ }
+ return new IStatus[] {};
+ }
+
+ public IStatus[] makeDirectoryIfRequired(IPath dir, IProgressMonitor monitor) {
+ IPath remotePath = root.append(dir);
+ try {
+ SSHCommandUtil.launchCommand(method.getSession(), "mkdir -p " + remotePath.toString(), monitor);
+ } catch( CoreException ce ) {
+ return new IStatus[]{ce.getStatus()};
+ }
+ return new IStatus[] {};
+ }
+}
\ No newline at end of file
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHJstPublisher.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHJstPublisher.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHJstPublisher.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.ssh.server;
+
+
+import org.jboss.ide.eclipse.as.core.publishers.AbstractJSTPublisher;
+import org.jboss.ide.eclipse.as.ssh.server.SSHServerBehaviourDelegate.SSHPublishMethod;
+
+
+public class SSHJstPublisher extends AbstractJSTPublisher {
+ public SSHJstPublisher() {}
+
+ @Override
+ protected String getTargetedPublishMethodId() {
+ return SSHPublishMethod.SSH_PUBLISH_METHOD;
+ }
+}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPackagesPublisher.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPackagesPublisher.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPackagesPublisher.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -1,149 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.ide.eclipse.as.ssh.server;
-import java.util.ArrayList;
-import java.util.Arrays;
-
-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.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.osgi.util.NLS;
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.IModuleResource;
-import org.eclipse.wst.server.core.model.IModuleResourceDelta;
-import org.jboss.ide.eclipse.archives.core.model.IArchive;
-import org.jboss.ide.eclipse.archives.webtools.IntegrationPlugin;
-import org.jboss.ide.eclipse.archives.webtools.Messages;
import org.jboss.ide.eclipse.archives.webtools.modules.PackageModuleFactory;
-import org.jboss.ide.eclipse.archives.webtools.modules.PackageModuleFactory.PackagedModuleDelegate;
-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.IJBossServerPublishMethod;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
-import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil;
-import org.jboss.ide.eclipse.as.core.util.ServerConverter;
-import org.jboss.ide.eclipse.as.ssh.server.SSHPublisher.SSHCopyCallback;
+import org.jboss.ide.eclipse.as.core.publishers.AbstractServerToolsPublisher;
import org.jboss.ide.eclipse.as.ssh.server.SSHServerBehaviourDelegate.SSHPublishMethod;
-public class SSHPackagesPublisher implements IJBossServerPublisher {
-
- protected IDeployableServer server;
- protected IModuleResourceDelta[] delta;
- protected ArrayList<IStatus> statuses = new ArrayList<IStatus>();
- protected SSHPublishMethod method;
- public SSHPackagesPublisher() {
- }
-
- public int getPublishState() {
- return IServer.PUBLISH_STATE_NONE;
- }
-
+public class SSHPackagesPublisher extends AbstractServerToolsPublisher {
public boolean accepts(String method, IServer server, IModule[] module) {
if( SSHPublishMethod.SSH_PUBLISH_METHOD.equals(method) && module != null && module.length > 0
&& PackageModuleFactory.MODULE_TYPE.equals(module[0].getModuleType().getId()))
return true;
return false;
}
- public IStatus publishModule(
- IJBossServerPublishMethod method,
- IServer server, IModule[] module,
- int publishType, IModuleResourceDelta[] delta,
- IProgressMonitor monitor)
- throws CoreException {
- this.method = (SSHPublishMethod)method;
- this.server = ServerConverter.getDeployableServer(server);
- this.delta = delta;
- IModule module2 = module[0];
-
- try {
- // if it's being removed
- if( publishType == REMOVE_PUBLISH ) {
- statuses.addAll(Arrays.asList(removeModule(module2, monitor)));
- } else if( publishType == FULL_PUBLISH ) {
- statuses.addAll(Arrays.asList(publishModule(module2, false, monitor)));
- } else if( publishType == INCREMENTAL_PUBLISH ) {
- statuses.addAll(Arrays.asList(publishModule(module2, true, monitor)));
- }
- }catch(Exception e) {
- e.printStackTrace();
- IStatus status = new Status(IStatus.ERROR, IntegrationPlugin.PLUGIN_ID,
- NLS.bind(Messages.ErrorDuringPublish, module2.getName()), e);
- return status;
- }
-
- if( statuses.size() > 0 ) {
- MultiStatus ms = new MultiStatus(IntegrationPlugin.PLUGIN_ID, IStatus.ERROR,
- NLS.bind(Messages.ErrorDuringPublish, module2.getName()), null);
- for( int i = 0; i < statuses.size(); i++ ) {
- ms.add(statuses.get(i));
- }
- return ms;
- }
-
- IStatus ret = new Status(IStatus.OK, IntegrationPlugin.PLUGIN_ID,
- NLS.bind(Messages.PublishSuccessful, module2.getName()));
- return ret;
- }
-
- protected IStatus[] removeModule(IModule module, IProgressMonitor monitor) {
- IArchive pack = getPackage(module);
- // remove all of the deployed items
- if( pack != null ) {
- IPath sourcePath = pack.getArchiveFilePath();
- String deployFolder = getRemoteDeployFolder(server.getServer());
- String deployFile = new Path(deployFolder).append(sourcePath.lastSegment()).toString();
- try {
- SSHZippedJSTPublisher.launchRemoveCommand(method.getSession(), deployFile, monitor);
- } catch( CoreException ce ) {
- return new IStatus[] { ce.getStatus() };
- }
- }
- return new IStatus[] { }; // nothing to report
- }
-
-
-
- protected IStatus[] publishModule(IModule module, boolean incremental, IProgressMonitor monitor) {
- IArchive pack = getPackage(module);
- IPath sourcePath = pack.getArchiveFilePath();
- String remoteContainer = getRemoteDeployFolder(server.getServer());
- IPath remoteRoot = new Path(remoteContainer).append(sourcePath.lastSegment());
-
- try {
- if( !pack.isExploded() ) {
- // copy the output file
- SSHZippedJSTPublisher.launchCommand(method.getSession(), "rm -rf " + remoteRoot.toString(), monitor);
- SSHZippedJSTPublisher.launchCopyCommand(method.getSession(), sourcePath.toOSString(), remoteRoot.toString(), monitor);
- } else {
- if( incremental ) {
- SSHCopyCallback callback = new SSHCopyCallback(remoteRoot, method);
- PublishCopyUtil util = new PublishCopyUtil(callback);
- return util.publishDelta(delta, monitor);
- } else {
- SSHZippedJSTPublisher.launchCommand(method.getSession(), "rm -rf " + remoteRoot.toString(), monitor);
- IModuleResource[] members = PublishUtil.getResources(module);
- SSHCopyCallback callback = new SSHCopyCallback(remoteRoot, method);
- PublishCopyUtil util = new PublishCopyUtil(callback);
- return util.publishFull(members, monitor);
- }
- }
- } catch( CoreException ce ) {
- return new IStatus[] { ce.getStatus() };
- }
- return new IStatus[] { };
- }
-
- protected IArchive getPackage(IModule module) {
- PackagedModuleDelegate delegate = (PackagedModuleDelegate)module.loadAdapter(PackagedModuleDelegate.class, new NullProgressMonitor());
- return delegate == null ? null : delegate.getPackage();
- }
- protected String getRemoteDeployFolder(IServer server) {
- return ((Server)server).getAttribute(ISSHDeploymentConstants.DEPLOY_DIRECTORY, (String)null);
- }
}
\ No newline at end of file
Deleted: trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPublisher.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPublisher.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHPublisher.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -1,267 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.ide.eclipse.as.ssh.server;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-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.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.osgi.util.NLS;
-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.IModuleResource;
-import org.eclipse.wst.server.core.model.IModuleResourceDelta;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.Messages;
-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.IJBossServerConstants;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
-import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil;
-import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
-import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.LocalCopyCallback;
-import org.jboss.ide.eclipse.as.core.util.ServerConverter;
-import org.jboss.ide.eclipse.as.ssh.SSHDeploymentPlugin;
-import org.jboss.ide.eclipse.as.ssh.server.SSHServerBehaviourDelegate.SSHPublishMethod;
-
-import com.jcraft.jsch.Session;
-
-public class SSHPublisher implements IJBossServerPublisher {
- protected IModuleResourceDelta[] delta;
- protected IDeployableServer server;
- protected int publishState = IServer.PUBLISH_STATE_NONE;
- protected SSHPublishMethod publishMethod;
-
- public SSHPublisher() {}
-
- public boolean accepts(String method, IServer server, IModule[] module) {
- if( !method.equals(SSHPublishMethod.SSH_PUBLISH_METHOD))
- return false;
- if( module == null )
- return true;
- IDeployableServer ds = ServerConverter.getDeployableServer(server);
- boolean shouldAccept = ds != null
- && ModuleCoreNature.isFlexibleProject(module[0].getProject())
- && !SSHPublishUtil.getZipsSSHDeployments(server);
- return shouldAccept;
- }
-
- public int getPublishState() {
- return publishState;
- }
-
- public IStatus publishModule(IJBossServerPublishMethod method,
- IServer server, IModule[] module, int publishType,
- IModuleResourceDelta[] delta, IProgressMonitor monitor)
- throws CoreException {
- IStatus status = null;
- this.server = ServerConverter.getDeployableServer(server);
- this.delta = delta;
- this.publishMethod = (SSHPublishMethod)method;
-
- boolean deleted = false;
- for( int i = 0; i < module.length; i++ ) {
- if( module[i].isExternal() )
- deleted = true;
- }
-
- if (publishType == REMOVE_PUBLISH ) {
- status = unpublish(this.server, module, monitor);
- } else {
- if( deleted ) {
- publishState = IServer.PUBLISH_STATE_UNKNOWN;
- } else {
- if (publishType == FULL_PUBLISH ) {
- status = fullPublish(module, module[module.length-1], monitor);
- } else if (publishType == INCREMENTAL_PUBLISH) {
- status = incrementalPublish(module, module[module.length-1], monitor);
- }
- }
- }
- return status;
- }
-
- protected IStatus fullPublish(IModule[] moduleTree, IModule module, IProgressMonitor monitor) throws CoreException {
- IPath remoteDeployPath = getDeployPath(moduleTree, server);
- IModuleResource[] members = PublishUtil.getResources(module);
-
- // First delete it
- // if the module we're publishing is a project, not a binary, clean it's folder
- if( !(new Path(module.getName()).segmentCount() > 1 ))
- SSHZippedJSTPublisher.launchCommand(publishMethod.getSession(), "rm -rf " + remoteDeployPath.toString(), monitor);
-
- ArrayList<IStatus> list = new ArrayList<IStatus>();
-
- if( !PublishUtil.deployPackaged(moduleTree) && !PublishUtil.isBinaryObject(moduleTree)) {
- SSHCopyCallback callback = new SSHCopyCallback(remoteDeployPath, publishMethod);
- PublishCopyUtil util = new PublishCopyUtil(callback);
- list.addAll(Arrays.asList(util.publishFull(members, monitor)));
- }
- else if( PublishUtil.isBinaryObject(moduleTree))
- list.addAll(Arrays.asList(copyBinaryModule(moduleTree, monitor)));
- else {
- IPath deployRoot = JBossServerCorePlugin.getServerStateLocation(server.getServer()).
- append(IJBossServerConstants.DEPLOY).makeAbsolute();
- try {
- File temp = deployRoot.toFile().createTempFile(module.getName(), ".tmp", deployRoot.toFile());
- IPath tempFile = new Path(temp.getAbsolutePath());
- list.addAll(Arrays.asList(PublishUtil.packModuleIntoJar(moduleTree[moduleTree.length-1], tempFile)));
- mkdirAndCopy(publishMethod.getSession(), tempFile.toString(), remoteDeployPath.toString());
- } catch( IOException ioe) {
- list.add(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, ioe.getMessage(), ioe));
- }
- }
-
- if( list.size() > 0 )
- return createMultiStatus(list, module);
- return Status.OK_STATUS;
- }
-
- protected IStatus incrementalPublish(IModule[] moduleTree, IModule module, IProgressMonitor monitor) throws CoreException {
- IStatus[] results = new IStatus[] {};
- IPath remoteDeployPath = getDeployPath(moduleTree, server);
- if( !PublishUtil.deployPackaged(moduleTree) && !PublishUtil.isBinaryObject(moduleTree)) {
- SSHCopyCallback handler = new SSHCopyCallback(remoteDeployPath, publishMethod);
- results = new PublishCopyUtil(handler).publishDelta(delta, monitor);
- } else if( delta.length > 0 ) {
- if( PublishUtil.isBinaryObject(moduleTree))
- results = copyBinaryModule(moduleTree, monitor);
- else {
- IPath localDeployRoot = JBossServerCorePlugin.getServerStateLocation(server.getServer()).
- append(IJBossServerConstants.DEPLOY).makeAbsolute();
- try {
- File temp = localDeployRoot.toFile().createTempFile(module.getName(), ".tmp", localDeployRoot.toFile());
- IPath tempFile = new Path(temp.getAbsolutePath());
- PublishUtil.packModuleIntoJar(moduleTree[moduleTree.length-1], tempFile);
- mkdirAndCopy(publishMethod.getSession(), tempFile.toString(), remoteDeployPath.toString());
- } catch( IOException ioe) {
- IStatus s = new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, ioe.getMessage(), ioe);
- results = new IStatus[] { s };
- }
- }
- }
-
- if( results != null && results.length > 0 ) {
- MultiStatus ms = new MultiStatus(JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_INC_FAIL,
- NLS.bind(Messages.IncrementalPublishFail, module.getName()), null);
- for( int i = 0; i < results.length; i++ )
- ms.add(results[i]);
- return ms;
- }
-
- IStatus ret = new Status(IStatus.OK, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_FULL_SUCCESS,
- NLS.bind(Messages.CountModifiedMembers, PublishUtil.countChanges(delta), module.getName()), null);
- return ret;
- }
-
-
- protected IStatus createMultiStatus(List<IStatus> list, IModule module) {
- MultiStatus ms = new MultiStatus(JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_FULL_FAIL,
- NLS.bind(Messages.FullPublishFail, module.getName()), null);
- for( int i = 0; i < list.size(); i++ )
- ms.add(list.get(i));
- return ms;
- }
-
- protected IStatus[] copyBinaryModule(IModule[] moduleTree, IProgressMonitor monitor) {
- try {
- IPath remoteDeployPath = getDeployPath(moduleTree, server);
- IModuleResource[] members = PublishUtil.getResources(moduleTree);
- File source = PublishUtil.getFile(members[0]);
- if( source != null ) {
- SSHZippedJSTPublisher.launchCopyCommand(publishMethod.getSession(), source.toString(), remoteDeployPath.toString(), monitor);
- } else {
-// IStatus s = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.JST_PUB_COPY_BINARY_FAIL,
-// NLS.bind(Messages.CouldNotPublishModule,
-// moduleTree[moduleTree.length-1]), null);
-// return new IStatus[] {s};
- // TODO
- }
- } catch( CoreException ce ) {
- return new IStatus[] {ce.getStatus()};
- }
- return new IStatus[]{Status.OK_STATUS};
- }
-
- protected IStatus unpublish(IDeployableServer jbServer, IModule[] module,
- IProgressMonitor monitor) throws CoreException {
- IPath remotePath = getDeployPath(module, server);
- SSHZippedJSTPublisher.launchCommand(publishMethod.getSession(), "rm -rf " + remotePath.toString(), monitor);
- return Status.OK_STATUS;
- }
-
- public static IPath getDeployPath(IModule[] moduleTree, IDeployableServer server) {
- return PublishUtil.getDeployPath(moduleTree, getRemoteDeployFolder(server.getServer()));
- }
-
- public static String getRemoteDeployFolder(IServer server) {
- return ((Server)server).getAttribute(ISSHDeploymentConstants.DEPLOY_DIRECTORY, (String)null);
- }
-
- public static void mkdirAndCopy(Session session, String localFile, String remoteFile) throws CoreException {
- String parentFolder = new Path(remoteFile).removeLastSegments(1).toString();
- SSHZippedJSTPublisher.launchCommand(session, "mkdir -p " + parentFolder, new NullProgressMonitor());
- SSHZippedJSTPublisher.launchCopyCommand(session, localFile, remoteFile, new NullProgressMonitor());
- }
-
- public static class SSHCopyCallback implements IPublishCopyCallbackHandler {
-
- private IPath root;
- private SSHPublishMethod method;
- public SSHCopyCallback(IPath deployRoot, SSHPublishMethod method) {
- this.root = deployRoot;
- this.method = method;
- }
-
- public IStatus[] copyFile(IModuleFile mf, IPath path,
- IProgressMonitor monitor) throws CoreException {
- File sourceFile = PublishUtil.getFile(mf);
- IPath destination = root.append(path);
- mkdirAndCopy(method.getSession(), sourceFile.getAbsolutePath(), destination.toString());
- return new IStatus[]{};
- }
-
- public IStatus[] deleteResource(IPath path, IProgressMonitor monitor) {
- IPath remotePath = root.append(path);
- try {
- SSHZippedJSTPublisher.launchCommand(method.getSession(), "rm -rf " + remotePath.toString(), monitor);
- } catch( CoreException ce ) {
- return new IStatus[]{ce.getStatus()};
- }
- return new IStatus[] {};
- }
-
- public IStatus[] makeDirectoryIfRequired(IPath dir, IProgressMonitor monitor) {
- IPath remotePath = root.append(dir);
- try {
- SSHZippedJSTPublisher.launchCommand(method.getSession(), "mkdir -p " + remotePath.toString(), monitor);
- } catch( CoreException ce ) {
- return new IStatus[]{ce.getStatus()};
- }
- return new IStatus[] {};
- }
- }
-}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHServerBehaviourDelegate.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHServerBehaviourDelegate.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHServerBehaviourDelegate.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -11,14 +11,19 @@
package org.jboss.ide.eclipse.as.ssh.server;
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.Status;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.ServerCore;
+import org.eclipse.wst.server.core.internal.Server;
+import org.jboss.ide.eclipse.as.core.ExtensionManager;
import org.jboss.ide.eclipse.as.core.publishers.LocalPublishMethod;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethodType;
import org.jboss.ide.eclipse.as.core.server.internal.DeployableServerBehavior;
+import org.jboss.ide.eclipse.as.core.server.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
import org.jboss.ide.eclipse.as.ssh.SSHDeploymentPlugin;
import com.jcraft.jsch.JSch;
@@ -37,24 +42,22 @@
setServerState(IServer.STATE_STOPPED);
}
- protected IJBossServerPublishMethod createPublishMethod() {
+ @Override
+ public IJBossServerPublishMethod createPublishMethod() {
return new SSHPublishMethod(); // TODO FIX THIS in superclass
}
public class SSHPublishMethod extends LocalPublishMethod {
public static final String SSH_PUBLISH_METHOD = "ssh"; //$NON-NLS-1$
-
- @Override
- public String getPublishMethodId() {
- return SSH_PUBLISH_METHOD;
- }
-
private Session session;
public Session getSession() {
return session;
}
-
@Override
+ public IJBossServerPublishMethodType getPublishMethodType() {
+ return ExtensionManager.getDefault().getPublishMethod(SSH_PUBLISH_METHOD);
+ }
+ @Override
public void publishStart(DeployableServerBehavior behaviour,
IProgressMonitor monitor) throws CoreException {
@@ -79,6 +82,10 @@
session = null;
return ret;
}
+
+ public String getPublishDefaultRootFolder(IServer server) {
+ return ((Server)server).getAttribute(ISSHDeploymentConstants.DEPLOY_DIRECTORY, (String)null);
+ }
}
@@ -127,4 +134,15 @@
}
}
+ public IPublishCopyCallbackHandler getCallbackHandler(IPath path,
+ IServer server, IJBossServerPublishMethod method) {
+ return new SSHCopyCallback(path, (SSHPublishMethod)method);
+ }
+
+ public String getPublishDefaultRootFolder(IServer server) {
+ return getPublishDefaultRootFolder(server);
+ }
+
+
+
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHSingleFilePublisher.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHSingleFilePublisher.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHSingleFilePublisher.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -10,33 +10,16 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.ssh.server;
-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.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
-import org.eclipse.wst.server.core.model.IModuleResourceDelta;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.Messages;
-import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
import org.jboss.ide.eclipse.as.core.modules.SingleDeployableFactory;
-import org.jboss.ide.eclipse.as.core.modules.SingleDeployableFactory.SingleDeployableModuleDelegate;
+import org.jboss.ide.eclipse.as.core.publishers.AbstractServerToolsPublisher;
import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
import org.jboss.ide.eclipse.as.core.util.ServerConverter;
import org.jboss.ide.eclipse.as.ssh.server.SSHServerBehaviourDelegate.SSHPublishMethod;
-public class SSHSingleFilePublisher implements IJBossServerPublisher {
+public class SSHSingleFilePublisher extends AbstractServerToolsPublisher {
- public SSHSingleFilePublisher() {
- }
-
public boolean accepts(String method, IServer server, IModule[] module) {
if( !method.equals(SSHPublishMethod.SSH_PUBLISH_METHOD))
return false;
@@ -48,68 +31,4 @@
&& module[0].getModuleType().getId().equals(SingleDeployableFactory.MODULE_TYPE);
return shouldAccept;
}
-
- public int getPublishState() {
- return IServer.PUBLISH_STATE_NONE;
- }
-
- private IDeployableServer server;
- private SSHPublishMethod publishMethod;
- private int publishState = IServer.PUBLISH_STATE_NONE;
- public IStatus publishModule(IJBossServerPublishMethod method,
- IServer server, IModule[] module, int publishType,
- IModuleResourceDelta[] delta, IProgressMonitor monitor)
- throws CoreException {
- this.server = ServerConverter.getDeployableServer(server);
- this.publishMethod = (SSHPublishMethod)method;
- IModule module2 = module[0];
-
- IStatus status = null;
- if(publishType == REMOVE_PUBLISH){
- status = unpublish(this.server, module2, monitor);
- } else if( publishType == FULL_PUBLISH || publishType == INCREMENTAL_PUBLISH){
- // if there's no change, do nothing. Otherwise, on change or add, re-publish
- status = publish(this.server, module2, monitor);
- }
- return status;
- }
-
- protected IStatus publish(IDeployableServer server, IModule module, IProgressMonitor monitor) {
- SingleDeployableModuleDelegate delegate = (SingleDeployableModuleDelegate)module.loadAdapter(SingleDeployableModuleDelegate.class, new NullProgressMonitor());
- if( delegate != null ) {
- IPath sourcePath = delegate.getGlobalSourcePath();
- String destFolder = SSHPublisher.getRemoteDeployFolder(server.getServer());
- IPath destFile = new Path(destFolder).append(sourcePath.lastSegment());
- try {
- SSHPublisher.mkdirAndCopy(publishMethod.getSession(), sourcePath.toOSString(), destFile.toString());
- } catch( CoreException ce ) {
- return ce.getStatus();
- }
- } else {
- // error can't do nuffin, should never happen
- publishState = IServer.PUBLISH_STATE_UNKNOWN;
- }
- return Status.OK_STATUS;
- }
-
- protected IStatus unpublish(IDeployableServer server, IModule module, IProgressMonitor monitor) throws CoreException {
- SingleDeployableModuleDelegate delegate = (SingleDeployableModuleDelegate)module.loadAdapter(SingleDeployableModuleDelegate.class, new NullProgressMonitor());
- if( delegate != null ) {
- IPath sourcePath = delegate.getGlobalSourcePath();
- String destFolder = SSHPublisher.getRemoteDeployFolder(server.getServer());
- IPath destFile = new Path(destFolder).append(sourcePath.lastSegment());
- SSHZippedJSTPublisher.launchCommand(publishMethod.getSession(), "rm -rf " + destFile.toString(), monitor);
- } else {
- // deleted module. o noes. Ignore it.
- publishState = IServer.PUBLISH_STATE_UNKNOWN;
- Status status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.SINGLE_FILE_UNPUBLISH_MNF,
- NLS.bind(Messages.DeleteModuleFail, module.getName()), null);
- return status;
- }
- Status status = new Status(IStatus.OK, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.SINGLE_FILE_UNPUBLISH_SUCCESS,
- NLS.bind(Messages.ModuleDeleted, module.getName()), null);
- return status;
- }
-
-
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHZippedJSTPublisher.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHZippedJSTPublisher.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ssh/src/org/jboss/ide/eclipse/as/ssh/server/SSHZippedJSTPublisher.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
+ * Copyright (c) 2010 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,
@@ -10,282 +10,48 @@
******************************************************************************/
package org.jboss.ide.eclipse.as.ssh.server;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
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.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.Server;
import org.eclipse.wst.server.core.model.IModuleResourceDelta;
-import org.jboss.ide.eclipse.archives.webtools.modules.LocalZippedPublisherUtil;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.Messages;
-import org.jboss.ide.eclipse.as.core.extensions.events.IEventCodes;
-import org.jboss.ide.eclipse.as.core.extensions.events.ServerLogger;
+import org.jboss.ide.eclipse.archives.webtools.modules.WTPZippedPublisher;
+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.IJBossServerConstants;
import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethod;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
import org.jboss.ide.eclipse.as.core.util.ServerConverter;
-import org.jboss.ide.eclipse.as.ssh.SSHDeploymentPlugin;
import org.jboss.ide.eclipse.as.ssh.server.SSHServerBehaviourDelegate.SSHPublishMethod;
-import com.jcraft.jsch.Channel;
-import com.jcraft.jsch.ChannelExec;
-import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
-public class SSHZippedJSTPublisher implements IJBossServerPublisher {
-
- public SSHZippedJSTPublisher() {
+public class SSHZippedJSTPublisher extends WTPZippedPublisher {
+ protected String getPublishMethod() {
+ return SSHPublishMethod.SSH_PUBLISH_METHOD;
}
-
- public boolean accepts(String method, IServer server, IModule[] module) {
- if( !method.equals(SSHPublishMethod.SSH_PUBLISH_METHOD))
- return false;
- if( module == null )
- return true;
- IDeployableServer ds = ServerConverter.getDeployableServer(server);
- boolean shouldAccept = ds != null
- && ModuleCoreNature.isFlexibleProject(module[0].getProject())
- && SSHPublishUtil.getZipsSSHDeployments(server);
- return shouldAccept;
- }
-
- public int getPublishState() {
- return IServer.PUBLISH_STATE_NONE;
- }
-
+
public IStatus publishModule(
IJBossServerPublishMethod method,
IServer server, IModule[] module,
int publishType, IModuleResourceDelta[] delta,
IProgressMonitor monitor) throws CoreException {
- // Let the local zipped publisher do the work in a local / metadata folder
- IStatus returnStatus = null;
- SSHPublishMethod method2 = (SSHPublishMethod)method;
- IPath deployRoot = JBossServerCorePlugin.getServerStateLocation(server).
- append(IJBossServerConstants.DEPLOY).makeAbsolute();
+ IStatus s = super.publishModule(method, server, module, publishType, delta, monitor);
+ // set up needed vars
+ IDeployableServer server2 = ServerConverter.getDeployableServer(server);
+ String builtArchivesFolder = getDeployRoot(module, ServerConverter.getDeployableServer(server));
+ IPath builtArchive = PublishUtil.getDeployPath(module, builtArchivesFolder);
+ String defaultDeployRoot = ((SSHPublishMethod)method).getPublishDefaultRootFolder(server);
+ String folder = PublishUtil.getDeployRootFolder(
+ module, server2, defaultDeployRoot,
+ SSHPublishMethod.SSH_PUBLISH_METHOD);
+ IPath remoteFile = PublishUtil.getDeployPath(module, folder);
+ Session session = ((SSHPublishMethod)method).getSession();
- LocalZippedPublisherUtil localDelegate = new LocalZippedPublisherUtil();
- IStatus localCopyStatus = localDelegate.publishModule(server,
- deployRoot.toOSString(), module, publishType, delta, monitor);
- IPath outputFilepath = localDelegate.getOutputFilePath(module);
-
- String deployFolder = getRemoteDeployFolder(server);
- String deployFile = new Path(deployFolder).append(outputFilepath.lastSegment()).toString();
-
- // Am I a removal? If yes, remove me, and return
- if( publishType == IJBossServerPublisher.REMOVE_PUBLISH) {
- launchRemoveCommand(method2.getSession(), deployFile, monitor);
- } else {
- launchCopyCommand(method2.getSession(),
- outputFilepath.toString(), deployFile, monitor);
- }
- return null;
+ // Now transfer the file via ssh
+ SSHCommandUtil.launchCopyCommand(session, builtArchive.toString(), remoteFile.toString(), monitor);
+ return s;
}
-
- protected String getRemoteDeployFolder(IServer server) {
- return ((Server)server).getAttribute(ISSHDeploymentConstants.DEPLOY_DIRECTORY, (String)null);
- }
- public static void launchRemoveCommand(Session session, String remoteLocation, IProgressMonitor monitor) throws CoreException {
- String command = "rm " + remoteLocation;
- launchCommand(session, command, monitor);
- }
- public static void launchCommand(Session session, String command, IProgressMonitor monitor) throws CoreException {
- launchThreadedCommand(session, command, monitor);
- }
-
- protected static void launchThreadedCommand(final Session session, final String command, final IProgressMonitor monitor) throws CoreException {
- // thread and watch the monitor for cancelations and interrupt the thread
- LaunchRunnable r = new LaunchRunnable() { public void run() throws CoreException {
- launchCommandNoThread(session, command, monitor);
- } };
- launchThreadedCommand(r, monitor);
- }
-
- protected static void launchCommandNoThread(Session session, String command, IProgressMonitor monitor) throws CoreException {
- Channel channel = null;
- try {
- channel = session.openChannel("exec");
- ((ChannelExec) channel).setCommand(command);
-
- channel.connect();
- while(!channel.isClosed()) {
- try {Thread.sleep(300);} catch(InterruptedException ie) {}
- }
- } catch( JSchException jsche ) {
- throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error executing command: " + command, null));
- } finally {
- channel.disconnect();
- }
- }
-
- public static class LaunchRunnable {
- public void run() throws CoreException {
- }
- }
-
- public static void launchCopyCommand(final Session session, final String localFile,
- final String remoteFile, final IProgressMonitor monitor) throws CoreException {
- // thread and watch the monitor for cancelations and interrupt the thread
- LaunchRunnable r = new LaunchRunnable() { public void run() throws CoreException {
- launchCopyCommandImpl(session, localFile, remoteFile, monitor);
- } };
- launchThreadedCommand(r, monitor);
- }
-
- protected static void launchThreadedCommand(final LaunchRunnable runnable, IProgressMonitor monitor) throws CoreException {
- final Exception[] e = new Exception[1];
- e[0] = null;
- final Object waitObject = new Object();
- final Boolean[] subtaskComplete = new Boolean[1];
- subtaskComplete[0] = new Boolean(false);
- Thread t = new Thread() {
- public void run() {
- Exception exception = null;
- try {
- runnable.run();
- } catch( Exception ex ) {
- exception = ex;
- }
- synchronized(waitObject) {
- e[0] = exception;
- subtaskComplete[0] = new Boolean(true);
- waitObject.notifyAll();
- }
- }
- };
- t.start();
- while(t.isAlive() && !monitor.isCanceled() ) {
- synchronized(waitObject) {
- if( subtaskComplete[0].booleanValue() )
- break;
- try {
- waitObject.wait(500);
- } catch(InterruptedException ie) {}
- }
- }
- synchronized(waitObject) {
- if( !subtaskComplete[0].booleanValue()) {
- t.interrupt();
- IStatus status = new Status(IStatus.WARNING, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.ISTATUS_CODE_ERROR, "SSH command canceled", e[0]);
- CoreException ce = new CoreException(status);
- throw ce;
- }
- if( e[0] != null ) {
- IStatus status = new Status(IStatus.ERROR, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.ISTATUS_CODE_ERROR, "Error running remote command", e[0]);
- CoreException ce = new CoreException(status);
- throw ce;
- }
-
- }
- }
-
- protected static void launchCopyCommandImpl(Session session, String localFile, String remoteFile, IProgressMonitor monitor) throws CoreException {
- Channel channel = null;
- OutputStream out = null;
- try {
- // exec 'scp -t rfile' remotely
- String command = "scp -p -t " + remoteFile;
- channel = session.openChannel("exec");
- ((ChannelExec) channel).setCommand(command);
-
- // get I/O streams for remote scp
- out = channel.getOutputStream();
- InputStream in = channel.getInputStream();
- channel.connect();
- if (checkAck(in) != 0) {
- throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, null));
- }
-
- // send "C0644 filesize filename", where filename should not include
- // '/'
- long filesize = (new File(localFile)).length();
- command = "C0644 " + filesize + " ";
- if (localFile.lastIndexOf('/') > 0) {
- command += localFile.substring(localFile.lastIndexOf('/') + 1);
- } else {
- command += localFile;
- }
- command += "\n";
- out.write(command.getBytes());
- out.flush();
- if (checkAck(in) != 0) {
- throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, null));
- }
-
- // send a content of lfile
- FileInputStream fis = new FileInputStream(localFile);
- byte[] buf = new byte[1024];
- while (true) {
- int len = fis.read(buf, 0, buf.length);
- if (len <= 0)
- break;
- out.write(buf, 0, len); // out.flush();
- }
- fis.close();
- fis = null;
- // send '\0'
- buf[0] = 0;
- out.write(buf, 0, 1);
- out.flush();
- if (checkAck(in) != 0) {
- throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, null));
- }
-
- } catch( JSchException jsche ) {
- throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, jsche));
- } catch( IOException ioe) {
- throw new CoreException(new Status(IStatus.ERROR, SSHDeploymentPlugin.PLUGIN_ID, IEventCodes.SSH_PUBLISHING_ROOT_CODE, "Error transfering file: " + localFile, ioe));
- } finally {
- if( channel != null )
- channel.disconnect();
- if( out != null ) {
- try {
- out.close();
- } catch(IOException ioe) {}
- }
- }
- }
-
- static int checkAck(InputStream in) throws IOException {
- int b = in.read();
- // b may be 0 for success,
- // 1 for error,
- // 2 for fatal error,
- // -1
- if (b == 0)
- return b;
- if (b == -1)
- return b;
-
- if (b == 1 || b == 2) {
- StringBuffer sb = new StringBuffer();
- int c;
- do {
- c = in.read();
- sb.append((char) c);
- } while (c != '\n');
-// if (b == 1) { // error
-// System.out.print(sb.toString());
-// }
-// if (b == 2) { // fatal error
-// System.out.print(sb.toString());
-// }
- }
- return b;
- }
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -73,6 +73,7 @@
public static String swf_NameInUse;
public static String swf_DeployEditorHeading;
public static String swf_DeploymentDescription;
+ public static String swf_DeploymentDescriptionLabel;
public static String swf_DeployDirectory;
public static String swf_TempDeployDirectory;
public static String swf_CloneConfiguration;
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.properties
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.properties 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/Messages.properties 2010-08-13 05:37:30 UTC (rev 24129)
@@ -41,7 +41,8 @@
swf_BaseName=JBoss _VERSION_ Server
swf_NameInUse=Server name already in use
swf_DeployEditorHeading=Default Settings
-swf_DeploymentDescription=This section sets where any non-customized module will be deployed to.\nThe temporary deploy folder should be on the same file-system as the deploy folder.\nThis will ensure safe and complete file copies.\nCustomizations can be made in the table below on a per-module basis.\nBlank columns will use the default values.\nChanges should *not* be made to this page while the server is running.
+swf_DeploymentDescriptionLabel=Set the default publish settings for your deployments.\nSettings can be overridden per-module in the table below.
+swf_DeploymentDescription=This section sets the default deploy folders for your deployments. To ensure safe and fast file copies, the temporary deploy folder should be on the same file-system as the main deploy folder.\n\nCustomizations can be made in the table below on a per-module basis. Blank (uncustomized) modules will continue to use the default values. Customized paths may be absolute or relative to the server's root directory (eg: server/default/deploy/custom/folder).\n\nChanges should *not* be made to this page while the server is running.
swf_DeployDirectory=Deploy Directory
swf_TempDeployDirectory=Temporary Deploy Directory
swf_CloneConfiguration=Copy this configuration into workspace metadata
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/DeploymentModuleOptionCompositeAssistant.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/DeploymentModuleOptionCompositeAssistant.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/DeploymentModuleOptionCompositeAssistant.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -0,0 +1,770 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.ui.editor;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.util.HashMap;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.ICellModifier;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TextCellEditor;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.TreeColumn;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.forms.IFormColors;
+import org.eclipse.ui.forms.widgets.ExpandableComposite;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.Section;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IRuntime;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+import org.eclipse.wst.server.ui.ServerUICore;
+import org.eclipse.wst.server.ui.internal.command.ServerCommand;
+import org.jboss.ide.eclipse.as.core.ExtensionManager;
+import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
+import org.jboss.ide.eclipse.as.core.publishers.LocalPublishMethod;
+import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerConstants;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
+import org.jboss.ide.eclipse.as.core.server.internal.JBossServer;
+import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
+import org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader.DeploymentModulePrefs;
+import org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader.DeploymentPreferences;
+import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+import org.jboss.ide.eclipse.as.ui.Messages;
+
+public class DeploymentModuleOptionCompositeAssistant implements PropertyChangeListener {
+ public static interface IDeploymentPageCallback {
+ public boolean metadataEnabled();
+ public String getServerLocation(IServerWorkingCopy wc);
+ public String getServerConfigName(IServerWorkingCopy wc);
+ public void propertyChange(PropertyChangeEvent evt, DeploymentModuleOptionCompositeAssistant composite);
+ }
+
+ public static class LocalDeploymentPageCallback implements IDeploymentPageCallback {
+ public boolean metadataEnabled() {
+ return true;
+ }
+
+ @Override
+ public String getServerLocation(IServerWorkingCopy wc) {
+ IJBossServerRuntime jbsrt = (IJBossServerRuntime)wc.getRuntime().loadAdapter(IJBossServerRuntime.class, null);
+ return jbsrt.getConfigLocation();
+ }
+
+ @Override
+ public String getServerConfigName(IServerWorkingCopy wc) {
+ IJBossServerRuntime jbsrt = (IJBossServerRuntime)wc.getRuntime().loadAdapter(IJBossServerRuntime.class, null);
+ return jbsrt.getJBossConfiguration();
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt,
+ DeploymentModuleOptionCompositeAssistant composite) {
+ // TODO Auto-generated method stub
+
+ }
+ }
+
+ private static HashMap<String, IDeploymentPageCallback> callbackMappings;
+ static {
+ callbackMappings = new HashMap<String, IDeploymentPageCallback>();
+ callbackMappings.put(LocalPublishMethod.LOCAL_PUBLISH_METHOD, new LocalDeploymentPageCallback());
+ }
+
+ public static void addMapping(String mode, IDeploymentPageCallback callback) {
+ callbackMappings.put(mode, callback);
+ }
+
+ private ModuleDeploymentPage page;
+ private DeploymentPreferences preferences;
+ private TreeViewer viewer;
+ protected String COLUMN_NAME;
+ protected String COLUMN_LOC;
+ protected String COLUMN_TEMP_LOC;
+ protected String currentDeployType;
+
+ private IServerWorkingCopy lastWC;
+
+ public DeploymentModuleOptionCompositeAssistant() {
+ COLUMN_NAME = IJBossToolingConstants.LOCAL_DEPLOYMENT_NAME;
+ COLUMN_LOC = IJBossToolingConstants.LOCAL_DEPLOYMENT_LOC;
+ COLUMN_TEMP_LOC = IJBossToolingConstants.LOCAL_DEPLOYMENT_TEMP_LOC;
+ currentDeployType = LocalPublishMethod.LOCAL_PUBLISH_METHOD;
+ }
+
+ public ModuleDeploymentPage getPage() {
+ return page;
+ }
+
+ public String getCurrentDeployType() {
+ return currentDeployType;
+ }
+
+ public void setCurrentDeployType(String type) {
+ this.currentDeployType = type;
+ }
+
+ public void setDeploymentPage(ModuleDeploymentPage page) {
+ this.page = page;
+ }
+
+ public void setDeploymentPrefs(DeploymentPreferences prefs) {
+ this.preferences = prefs;
+ }
+
+ protected ServerAttributeHelper getHelper() {
+ return page.getHelper();
+ }
+
+ private Text deployText, tempDeployText;
+ private Button metadataRadio, serverRadio, customRadio, currentSelection;
+ private Button deployButton, tempDeployButton;
+ private ModifyListener deployListener, tempDeployListener;
+ private SelectionListener radioListener, zipListener;
+ private Button zipDeployWTPProjects;
+ private String lastCustomDeploy, lastCustomTemp;
+
+ public Button getServerRadio() {
+ return serverRadio;
+ }
+
+ public Button getCurrentSelection() {
+ return currentSelection;
+ }
+
+ protected Composite createDefaultComposite(Composite parent) {
+
+ FormToolkit toolkit = new FormToolkit(parent.getDisplay());
+
+ Section section = toolkit.createSection(parent,
+ ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED
+ | ExpandableComposite.TITLE_BAR);
+ section.setText(Messages.swf_DeployEditorHeading);
+ section.setToolTipText(Messages.swf_DeploymentDescription);
+ section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL
+ | GridData.VERTICAL_ALIGN_FILL));
+
+ Composite composite = toolkit.createComposite(section);
+
+ composite.setLayout(new FormLayout());
+
+ Label descriptionLabel = toolkit.createLabel(composite,
+ Messages.swf_DeploymentDescriptionLabel);
+ descriptionLabel.setToolTipText(Messages.swf_DeploymentDescription);
+ Control top = descriptionLabel;
+ Composite inner = toolkit.createComposite(composite);
+ inner.setLayout(new GridLayout(1, false));
+
+ IRuntime rt = getServer().getServer().getRuntime();
+ boolean showRadios = true;
+ if( rt == null || rt.loadAdapter(IJBossServerRuntime.class, null) == null)
+ showRadios = false;
+
+ if( showRadios ) {
+ metadataRadio = toolkit.createButton(inner,
+ Messages.EditorUseWorkspaceMetadata, SWT.RADIO);
+ serverRadio = toolkit.createButton(inner,
+ Messages.EditorUseServersDeployFolder, SWT.RADIO);
+ customRadio = toolkit.createButton(inner,
+ Messages.EditorUseCustomDeployFolder, SWT.RADIO);
+
+ radioListener = new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ radioSelected(e.getSource());
+ }
+ };
+ metadataRadio.addSelectionListener(radioListener);
+ serverRadio.addSelectionListener(radioListener);
+ customRadio.addSelectionListener(radioListener);
+ lastWC = page.getServer();
+ lastWC.addPropertyChangeListener(this);
+ }
+
+ FormData radios = new FormData();
+ radios.top = new FormAttachment(descriptionLabel, 5);
+ radios.left = new FormAttachment(0, 5);
+ radios.right = new FormAttachment(100, -5);
+ inner.setLayoutData(radios);
+ top = inner;
+
+ Label label = toolkit.createLabel(composite,
+ Messages.swf_DeployDirectory);
+ label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
+ deployText = toolkit.createText(composite, getDeployDir(), SWT.BORDER);
+ deployListener = new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ page.execute(new SetDeployDirCommand());
+ }
+ };
+ deployText.addModifyListener(deployListener);
+
+ deployButton = toolkit.createButton(composite, Messages.browse,
+ SWT.PUSH);
+ deployButton.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ DirectoryDialog d = new DirectoryDialog(new Shell());
+ d.setFilterPath(page.makeGlobal(deployText.getText()));
+ String x = d.open();
+ if (x != null) {
+ deployText.setText(page.makeRelative(x));
+ }
+ }
+ });
+
+ Label tempDeployLabel = toolkit.createLabel(composite,
+ Messages.swf_TempDeployDirectory);
+ tempDeployLabel.setForeground(toolkit.getColors().getColor(
+ IFormColors.TITLE));
+
+ tempDeployText = toolkit.createText(composite, getTempDeployDir(),
+ SWT.BORDER);
+ tempDeployListener = new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ page.execute(new SetTempDeployDirCommand());
+ }
+ };
+ tempDeployText.addModifyListener(tempDeployListener);
+
+ tempDeployButton = toolkit.createButton(composite, Messages.browse,
+ SWT.PUSH);
+ tempDeployButton.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+
+ public void widgetSelected(SelectionEvent e) {
+ DirectoryDialog d = new DirectoryDialog(new Shell());
+ d.setFilterPath(page.makeGlobal(tempDeployText.getText()));
+ String x = d.open();
+ if (x != null)
+ tempDeployText.setText(page.makeRelative(x));
+ }
+ });
+
+ FormData descriptionLabelData = new FormData();
+ descriptionLabelData.left = new FormAttachment(0, 5);
+ descriptionLabelData.top = new FormAttachment(0, 5);
+ descriptionLabel.setLayoutData(descriptionLabelData);
+
+ // first row
+ FormData labelData = new FormData();
+ labelData.left = new FormAttachment(0, 5);
+ labelData.right = new FormAttachment(deployText, -5);
+ labelData.top = new FormAttachment(top, 5);
+ label.setLayoutData(labelData);
+
+ FormData textData = new FormData();
+ textData.left = new FormAttachment(deployButton, -305);
+ textData.top = new FormAttachment(top, 5);
+ textData.right = new FormAttachment(deployButton, -5);
+ deployText.setLayoutData(textData);
+
+ FormData buttonData = new FormData();
+ buttonData.right = new FormAttachment(100, -5);
+ buttonData.left = new FormAttachment(100, -100);
+ buttonData.top = new FormAttachment(top, 2);
+ deployButton.setLayoutData(buttonData);
+
+ // second row
+ FormData tempLabelData = new FormData();
+ tempLabelData.left = new FormAttachment(0, 5);
+ tempLabelData.right = new FormAttachment(deployText, -5);
+ tempLabelData.top = new FormAttachment(deployText, 5);
+ tempDeployLabel.setLayoutData(tempLabelData);
+
+ FormData tempTextData = new FormData();
+ tempTextData.left = new FormAttachment(tempDeployButton, -305);
+ tempTextData.top = new FormAttachment(deployText, 5);
+ tempTextData.right = new FormAttachment(tempDeployButton, -5);
+ tempDeployText.setLayoutData(tempTextData);
+
+ FormData tempButtonData = new FormData();
+ tempButtonData.right = new FormAttachment(100, -5);
+ tempButtonData.left = new FormAttachment(100, -100);
+ tempButtonData.top = new FormAttachment(deployText, 5);
+ tempDeployButton.setLayoutData(tempButtonData);
+
+ zipDeployWTPProjects = toolkit.createButton(composite,
+ Messages.EditorZipDeployments, SWT.CHECK);
+ boolean zippedPublisherAvailable = isZippedPublisherAvailable();
+ boolean value = getServer().zipsWTPDeployments();
+ zipDeployWTPProjects.setEnabled(zippedPublisherAvailable);
+ zipDeployWTPProjects.setSelection(zippedPublisherAvailable && value);
+
+ FormData zipButtonData = new FormData();
+ zipButtonData.right = new FormAttachment(100, -5);
+ zipButtonData.left = new FormAttachment(0, 5);
+ zipButtonData.top = new FormAttachment(tempDeployText, 5);
+ zipDeployWTPProjects.setLayoutData(zipButtonData);
+
+ zipListener = new SelectionListener() {
+ public void widgetSelected(SelectionEvent e) {
+ page.execute(new SetZipCommand());
+ }
+
+ public void widgetDefaultSelected(SelectionEvent e) {
+ widgetSelected(e);
+ }
+ };
+ zipDeployWTPProjects.addSelectionListener(zipListener);
+
+ toolkit.paintBordersFor(composite);
+ section.setClient(composite);
+ page.getSaveStatus();
+ updateWidgets();
+ return section;
+ }
+
+ private void updateWidgets() {
+ metadataRadio.setSelection(getDeployType().equals(
+ IDeployableServer.DEPLOY_METADATA));
+ serverRadio.setSelection(getDeployType().equals(
+ IDeployableServer.DEPLOY_SERVER));
+ customRadio.setSelection(getDeployType().equals(
+ IDeployableServer.DEPLOY_CUSTOM));
+ currentSelection = metadataRadio.getSelection() ? metadataRadio
+ : serverRadio.getSelection() ? serverRadio : customRadio;
+
+ String mode = page.getServer().getAttribute(IDeployableServer.SERVER_MODE, LocalPublishMethod.LOCAL_PUBLISH_METHOD);
+ boolean metaEnabled = callbackMappings.get(mode).metadataEnabled();
+ metadataRadio.setEnabled(metaEnabled);
+ JBossServer jbs = ServerConverter.getJBossServer(page.getServer().getOriginal());
+ String newDir = getHelper().getAttribute(IDeployableServer.DEPLOY_DIRECTORY,
+ jbs == null ? "" : jbs.getDeployFolder(jbs, getDeployType()));
+ String newTemp = getHelper().getAttribute(IDeployableServer.TEMP_DEPLOY_DIRECTORY,
+ jbs == null ? "" : jbs.getTempDeployFolder(jbs, getDeployType()));
+ deployText.removeModifyListener(deployListener);
+ deployText.setText(newDir);
+ deployText.addModifyListener(deployListener);
+ tempDeployText.removeModifyListener(tempDeployListener);
+ tempDeployText.setText(newTemp);
+ tempDeployText.addModifyListener(tempDeployListener);
+
+ deployText.setEnabled(getDeployType().equals(IDeployableServer.DEPLOY_CUSTOM));
+ tempDeployText.setEnabled(getDeployType().equals(IDeployableServer.DEPLOY_CUSTOM));
+ deployButton.setEnabled(getDeployType().equals(IDeployableServer.DEPLOY_CUSTOM));
+ tempDeployButton.setEnabled(getDeployType().equals(IDeployableServer.DEPLOY_CUSTOM));
+ }
+
+ public void radioSelected(Object c) {
+ if (c == currentSelection)
+ return; // do nothing
+ page.execute(new RadioClickedCommand((Button)c, currentSelection));
+ currentSelection = (Button)c;
+ }
+
+ protected boolean isZippedPublisherAvailable() {
+ /*
+ * Maybe use IJBossServerPublishMethodType type = DeploymentPreferenceLoader.getCurrentDeploymentMethodType(getServer());
+ * But this class has no reference to the server, and it also might not want to go by stored data,
+ * but rather the combo in the ModuleDeploymentPage somehow?
+ */
+
+ // String method = DeploymentPreferenceLoader.getCurrentDeploymentMethodType(getServer()).getId();
+ String method = LocalPublishMethod.LOCAL_PUBLISH_METHOD;
+ IJBossServerPublisher[] publishers =
+ ExtensionManager.getDefault().getZippedPublishers();
+ for( int i = 0; i < publishers.length; i++ ) {
+ if( publishers[i].accepts(method, getServer().getServer(), null))
+ return true;
+ }
+ return false;
+ }
+
+ public class SetDeployDirCommand extends ServerCommand {
+ private String oldDir;
+ private String newDir;
+ private Text text;
+ private ModifyListener listener;
+ public SetDeployDirCommand() {
+ super(page.getServer(), Messages.EditorSetDeployLabel);
+ this.text = deployText;
+ this.newDir = deployText.getText();
+ this.listener = deployListener;
+ this.oldDir = getHelper().getAttribute(IDeployableServer.DEPLOY_DIRECTORY, ""); //$NON-NLS-1$
+ }
+ public void execute() {
+ getHelper().setAttribute(IDeployableServer.DEPLOY_DIRECTORY, newDir);
+ lastCustomDeploy = newDir;
+ updateWidgets();
+ page.getSaveStatus();
+ }
+ public void undo() {
+ getHelper().setAttribute(IDeployableServer.DEPLOY_DIRECTORY, oldDir);
+ updateWidgets();
+ page.getSaveStatus();
+ }
+ }
+
+ public class SetZipCommand extends ServerCommand {
+ boolean oldVal;
+ boolean newVal;
+ public SetZipCommand() {
+ super(page.getServer(), Messages.EditorZipDeployments);
+ oldVal = getHelper().getAttribute(IDeployableServer.ZIP_DEPLOYMENTS_PREF, false);
+ newVal = zipDeployWTPProjects.getSelection();
+ }
+ public void execute() {
+ getHelper().setAttribute(IDeployableServer.ZIP_DEPLOYMENTS_PREF, newVal);
+ page.getSaveStatus();
+ }
+ public void undo() {
+ zipDeployWTPProjects.removeSelectionListener(zipListener);
+ zipDeployWTPProjects.setSelection(oldVal);
+ getHelper().setAttribute(IDeployableServer.ZIP_DEPLOYMENTS_PREF, oldVal);
+ zipDeployWTPProjects.addSelectionListener(zipListener);
+ page.getSaveStatus();
+ }
+ }
+
+ public class SetTempDeployDirCommand extends ServerCommand {
+ private String oldDir;
+ private String newDir;
+ private Text text;
+ private ModifyListener listener;
+ public SetTempDeployDirCommand() {
+ super(page.getServer(), Messages.EditorSetTempDeployLabel);
+ text = tempDeployText;
+ newDir = tempDeployText.getText();
+ listener = tempDeployListener;
+ oldDir = getHelper().getAttribute(IDeployableServer.TEMP_DEPLOY_DIRECTORY, ""); //$NON-NLS-1$
+ }
+ public void execute() {
+ getHelper().setAttribute(IDeployableServer.TEMP_DEPLOY_DIRECTORY, newDir);
+ lastCustomTemp = newDir;
+ updateWidgets();
+ page.getSaveStatus();
+ }
+ public void undo() {
+ getHelper().setAttribute(IDeployableServer.TEMP_DEPLOY_DIRECTORY, oldDir);
+ updateWidgets();
+ page.getSaveStatus();
+ }
+ }
+
+ public class RadioClickedCommand extends ServerCommand {
+ private Button newSelection, oldSelection;
+ private String oldDir, newDir;
+ private String oldTemp, newTemp;
+ private String id;
+ public RadioClickedCommand(Button clicked, Button previous) {
+ super(page.getServer(), Messages.EditorSetRadioClicked);
+ newSelection = clicked;
+ oldSelection = previous;
+ id = server.getId();
+ }
+ public void execute() {
+ oldDir = deployText.getText();
+ oldTemp = tempDeployText.getText();
+ String newType = newSelection == customRadio ? IDeployableServer.DEPLOY_CUSTOM :
+ newSelection == serverRadio ? IDeployableServer.DEPLOY_SERVER :
+ IDeployableServer.DEPLOY_METADATA;
+ discoverNewFolders();
+ ServerAttributeHelper helper = getHelper();
+ helper.setAttribute(IDeployableServer.DEPLOY_DIRECTORY, newDir);
+ helper.setAttribute(IDeployableServer.TEMP_DEPLOY_DIRECTORY, newTemp);
+ helper.setAttribute(IDeployableServer.DEPLOY_DIRECTORY_TYPE, newType);
+ updateWidgets();
+ page.getSaveStatus();
+ }
+
+ protected void discoverNewFolders() {
+ // Discover the new folders
+ if( newSelection == metadataRadio ) {
+ newDir = JBossServerCorePlugin.getServerStateLocation(id)
+ .append(IJBossServerConstants.DEPLOY).makeAbsolute().toString();
+ newTemp = JBossServerCorePlugin.getServerStateLocation(id)
+ .append(IJBossServerConstants.TEMP_DEPLOY).makeAbsolute().toString();
+ new File(newDir).mkdirs();
+ new File(newTemp).mkdirs();
+ } else if( newSelection == serverRadio ) {
+ if( server.getRuntime() != null &&
+ server.getRuntime().loadAdapter(IJBossServerRuntime.class, null) != null) {
+ String loc, config;
+ loc = config = null;
+ String mode = getHelper().getAttribute(IDeployableServer.SERVER_MODE, LocalPublishMethod.LOCAL_PUBLISH_METHOD);
+ IDeploymentPageCallback cb = callbackMappings.get(mode);
+ loc = cb.getServerLocation(page.getServer());
+ config = cb.getServerConfigName(page.getServer());
+ newDir = new Path(loc)
+ .append(config)
+ .append(IJBossServerConstants.DEPLOY).toString();
+ newTemp = new Path(loc).append(config)
+ .append(IJBossServerConstants.TMP)
+ .append(IJBossServerConstants.JBOSSTOOLS_TMP).toString();
+ if( mode.equals(LocalPublishMethod.LOCAL_PUBLISH_METHOD))
+ new File(newTemp).mkdirs();
+ }
+ } else {
+ newDir = lastCustomDeploy;
+ newTemp = lastCustomTemp;
+ }
+ newDir = newDir == null ? oldDir : newDir;
+ newTemp = newTemp == null ? oldTemp : newTemp;
+ }
+
+ public void undo() {
+ String oldType = oldSelection == customRadio ? IDeployableServer.DEPLOY_CUSTOM :
+ oldSelection == serverRadio ? IDeployableServer.DEPLOY_SERVER :
+ IDeployableServer.DEPLOY_METADATA;
+ getHelper().setAttribute(IDeployableServer.DEPLOY_DIRECTORY, oldDir);
+ getHelper().setAttribute(IDeployableServer.TEMP_DEPLOY_DIRECTORY, oldTemp);
+ getHelper().setAttribute(IDeployableServer.DEPLOY_DIRECTORY_TYPE, oldType);
+ updateWidgets();
+ page.getSaveStatus();
+ }
+ }
+
+ private String getDeployType() {
+ return getServer().getDeployLocationType();
+ }
+
+ private String getDeployDir() {
+ return page.getServer().getRuntime() == null ? "" : //$NON-NLS-1$
+ ModuleDeploymentPage.makeRelative(getServer().getDeployFolder(),
+ page.getServer().getRuntime());
+ }
+
+ private String getTempDeployDir() {
+ return page.getServer().getRuntime() == null ? "" : //$NON-NLS-1$
+ ModuleDeploymentPage.makeRelative(getServer().getTempDeployFolder(),
+ page.getServer().getRuntime());
+ }
+
+ private IDeployableServer getServer() {
+ return (IDeployableServer) page.getServer().loadAdapter(
+ IDeployableServer.class, new NullProgressMonitor());
+ }
+/*
+ *
+ *
+ *
+ * This is where the second half goes
+ *
+ *
+ *
+ */
+ protected Composite createViewerPortion(Composite random) {
+ Composite root = new Composite(random, SWT.NONE);
+ root.setLayout(new FormLayout());
+
+ page.getFormToolkit(random).adapt(root);
+
+ viewer = new TreeViewer(root, SWT.BORDER);
+ viewer.getTree().setHeaderVisible(true);
+ viewer.getTree().setLinesVisible(true);
+ TreeColumn moduleColumn = new TreeColumn(viewer.getTree(), SWT.NONE);
+ TreeColumn publishLocColumn = new TreeColumn(viewer.getTree(), SWT.NONE);
+ TreeColumn publishTempLocColumn = new TreeColumn(viewer.getTree(),
+ SWT.NONE);
+ moduleColumn.setText(Messages.EditorModule);
+ publishLocColumn.setText(Messages.EditorSetDeployLabel);
+ publishTempLocColumn.setText(Messages.EditorSetTempDeployLabel);
+
+ moduleColumn.setWidth(200);
+ publishLocColumn.setWidth(200);
+ publishTempLocColumn.setWidth(200);
+
+ FormData treeData = new FormData();
+ treeData.top = new FormAttachment(0, 5);
+ treeData.bottom = new FormAttachment(100, -5);
+ treeData.left = new FormAttachment(0, 5);
+ treeData.right = new FormAttachment(100, -5);
+ viewer.getTree().setLayoutData(treeData);
+ viewer.setContentProvider(new ModulePageContentProvider());
+
+ viewer.setLabelProvider(new ModulePageLabelProvider());
+ viewer.setColumnProperties(new String[] { COLUMN_NAME,
+ COLUMN_LOC, COLUMN_TEMP_LOC });
+ viewer.setInput(""); // irrelevent
+ CellEditor[] editors = new CellEditor[] {
+ new TextCellEditor(viewer.getTree()),
+ new TextCellEditor(viewer.getTree()),
+ new TextCellEditor(viewer.getTree()) };
+ viewer.setCellModifier(new LocalDeploymentCellModifier());
+ viewer.setCellEditors(editors);
+
+ return root;
+ }
+
+ private class LocalDeploymentCellModifier implements ICellModifier {
+ public boolean canModify(Object element, String property) {
+ if( property == COLUMN_NAME)
+ return false;
+ return true;
+ }
+
+ public Object getValue(Object element, String property) {
+ DeploymentModulePrefs p = preferences.getOrCreatePreferences(currentDeployType)
+ .getOrCreateModulePrefs((IModule) element);
+ if (property == COLUMN_LOC) {
+ String ret = p.getProperty(COLUMN_LOC);
+ return ret == null ? "" : ret;
+ }
+ if (property == COLUMN_TEMP_LOC) {
+ String ret = p.getProperty(COLUMN_TEMP_LOC);
+ return ret == null ? "" : ret;
+ }
+
+ return "";
+ }
+
+ public void modify(Object element, String property, Object value) {
+
+ IModule module = (IModule) ((TreeItem) element).getData();
+ DeploymentModulePrefs p = preferences.getOrCreatePreferences(currentDeployType)
+ .getOrCreateModulePrefs(module);
+ if (property == COLUMN_LOC) {
+ page.firePropertyChangeCommand(p, COLUMN_LOC,
+ (String) value, Messages.EditorEditDeployLocCommand);
+ viewer.refresh();
+ } else if (property == COLUMN_TEMP_LOC) {
+ page.firePropertyChangeCommand(p, COLUMN_TEMP_LOC,
+ (String) value, Messages.EditorEditDeployLocCommand);
+ viewer.refresh();
+ }
+ }
+ }
+
+ private class ModulePageContentProvider implements ITreeContentProvider {
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ }
+
+ public void dispose() {
+ }
+
+ public Object[] getElements(Object inputElement) {
+ return page.getPossibleModules();
+ }
+
+ public boolean hasChildren(Object element) {
+ return false;
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ return null;
+ }
+ }
+
+ private class ModulePageLabelProvider implements ITableLabelProvider {
+ public Image getColumnImage(Object element, int columnIndex) {
+ if (element instanceof IModule && columnIndex == 0) {
+ ILabelProvider labelProvider = ServerUICore.getLabelProvider();
+ Image image = labelProvider.getImage((IModule) element);
+ labelProvider.dispose();
+ return image;
+ }
+ return null;
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ if (element instanceof IModule) {
+ IModule m = (IModule) element;
+ if (columnIndex == 0)
+ return m.getName();
+ if (columnIndex == 1) {
+ DeploymentModulePrefs modPref = preferences
+ .getOrCreatePreferences(currentDeployType)
+ .getOrCreateModulePrefs(m);
+ String result = modPref.getProperty(COLUMN_LOC);
+ if (result != null)
+ return result;
+ modPref.setProperty(COLUMN_LOC, "");
+ return "";
+ }
+ if (columnIndex == 2) {
+ DeploymentModulePrefs modPref = preferences
+ .getOrCreatePreferences(currentDeployType)
+ .getOrCreateModulePrefs(m);
+ String result = modPref.getProperty(COLUMN_TEMP_LOC);
+ if (result != null)
+ return result;
+ modPref.setProperty(COLUMN_TEMP_LOC, "");
+ return "";
+ }
+ }
+ return element.toString();
+ }
+
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ public void dispose() {
+ }
+
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ public void removeListener(ILabelProviderListener listener) {
+ }
+ }
+
+ public void updateListeners() {
+ // server has been saved. Remove property change listener from last wc and add to newest
+ lastWC.removePropertyChangeListener(this);
+ lastWC = page.getServer();
+ lastWC.addPropertyChangeListener(this);
+ }
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt) {
+ if( evt.getPropertyName().equals( IDeployableServer.SERVER_MODE)) {
+ String mode = page.getServer().getAttribute(IDeployableServer.SERVER_MODE, LocalPublishMethod.LOCAL_PUBLISH_METHOD);
+ metadataRadio.setEnabled(callbackMappings.get(mode).metadataEnabled());
+ String originalDeployLocation = page.getServer().getOriginal().getAttribute(IDeployableServer.DEPLOY_DIRECTORY_TYPE, IDeployableServer.DEPLOY_CUSTOM);
+ String wcDeployLocation = page.getServer().getAttribute(IDeployableServer.DEPLOY_DIRECTORY_TYPE, IDeployableServer.DEPLOY_CUSTOM);
+ if(!metadataRadio.isEnabled() && metadataRadio.getSelection()) {
+ page.execute(new RadioClickedCommand(serverRadio, currentSelection));
+ }
+ }
+ }
+}
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/EditorExtensionManager.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/EditorExtensionManager.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/EditorExtensionManager.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.ui.editor;
+
+import java.util.Collection;
+import java.util.HashMap;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+import org.jboss.ide.eclipse.as.ui.JBossServerUIPlugin;
+
+public class EditorExtensionManager {
+
+ private static EditorExtensionManager instance;
+ public static EditorExtensionManager getDefault() {
+ if( instance == null )
+ instance = new EditorExtensionManager();
+ return instance;
+ }
+
+ private HashMap<String, IDeploymentTypeUI> publishMethodUIMap = null;
+ public IDeploymentTypeUI getPublishPreferenceUI(String deployType) {
+ if( publishMethodUIMap == null )
+ loadPublishPreferenceEditors();
+ return publishMethodUIMap.get(deployType);
+ }
+
+ public IDeploymentTypeUI[] getPublishPreferenceUIs() {
+ if( publishMethodUIMap == null )
+ loadPublishPreferenceEditors();
+ Collection<IDeploymentTypeUI> col = publishMethodUIMap.values();
+ return (IDeploymentTypeUI[]) col.toArray(new IDeploymentTypeUI[col.size()]);
+ }
+ private void loadPublishPreferenceEditors() {
+ publishMethodUIMap = new HashMap<String, IDeploymentTypeUI>();
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] cf = registry.getConfigurationElementsFor(
+ JBossServerUIPlugin.PLUGIN_ID, "DeployMethodUI"); //$NON-NLS-1$
+ for( int i = 0; i < cf.length; i++ ) {
+ try {
+ IDeploymentTypeUI ui = (IDeploymentTypeUI) cf[i].createExecutableExtension("class"); //$NON-NLS-1$
+ if( ui != null && cf[i].getAttribute("deployMethodId") != null) { //$NON-NLS-1$
+ publishMethodUIMap.put(cf[i].getAttribute("deployMethodId"), ui); //$NON-NLS-1$
+ }
+ } catch(CoreException ce ) {
+ // TODO log
+ }
+ }
+ }
+}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/IDeploymentEditorTab.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/IDeploymentEditorTab.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/IDeploymentEditorTab.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.ide.eclipse.as.ui.editor;
import org.eclipse.swt.widgets.Composite;
@@ -4,6 +14,7 @@
import org.eclipse.swt.widgets.Control;
import org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader.DeploymentPreferences;
+ at Deprecated
public interface IDeploymentEditorTab {
public void setDeploymentPage(ModuleDeploymentPage page);
public void setDeploymentPrefs(DeploymentPreferences prefs);
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/IDeploymentTypeUI.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/IDeploymentTypeUI.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/IDeploymentTypeUI.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.ui.editor;
+
+import org.eclipse.swt.widgets.Composite;
+import org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader.DeploymentPreferences;
+
+public interface IDeploymentTypeUI {
+ /**
+ * The parent in this call has no layout and is basically a positioned,
+ * but unconfigured, composite.
+ *
+ * Fill her up!
+ *
+ * Don't forget this UI element is a singleton, similar to a factory,
+ * so you should probably make your first widget in the parent a
+ * new class which extends Composite and can maintain state.
+ *
+ * @param parent
+ * @param modeSection
+ */
+ public void fillComposite(Composite parent, ServerModeSection modeSection);
+}
Deleted: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/LocalDeploymentModuleTab.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/LocalDeploymentModuleTab.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/LocalDeploymentModuleTab.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -1,723 +0,0 @@
-package org.jboss.ide.eclipse.as.ui.editor;
-
-import java.io.File;
-
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.ICellModifier;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.TextCellEditor;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.FormAttachment;
-import org.eclipse.swt.layout.FormData;
-import org.eclipse.swt.layout.FormLayout;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.DirectoryDialog;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.swt.widgets.TreeColumn;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.ui.forms.IFormColors;
-import org.eclipse.ui.forms.widgets.ExpandableComposite;
-import org.eclipse.ui.forms.widgets.FormToolkit;
-import org.eclipse.ui.forms.widgets.Section;
-import org.eclipse.wst.server.core.IModule;
-import org.eclipse.wst.server.core.IRuntime;
-import org.eclipse.wst.server.ui.ServerUICore;
-import org.eclipse.wst.server.ui.internal.command.ServerCommand;
-import org.jboss.ide.eclipse.as.core.ExtensionManager;
-import org.jboss.ide.eclipse.as.core.JBossServerCorePlugin;
-import org.jboss.ide.eclipse.as.core.publishers.LocalPublishMethod;
-import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerConstants;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerPublisher;
-import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
-import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
-import org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader.DeploymentModulePrefs;
-import org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader.DeploymentPreferences;
-import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
-import org.jboss.ide.eclipse.as.ui.Messages;
-
-public class LocalDeploymentModuleTab implements IDeploymentEditorTab {
- private ModuleDeploymentPage page;
- private DeploymentPreferences preferences;
-
- public LocalDeploymentModuleTab() {
- }
-
- public String getTabName() {
- return Messages.EditorLocalDeployment;
- }
-
- public void setDeploymentPage(ModuleDeploymentPage page) {
- this.page = page;
- }
-
- public void setDeploymentPrefs(DeploymentPreferences prefs) {
- this.preferences = prefs;
- }
-
- private TreeViewer viewer;
- private static final String LOCAL_COLUMN_NAME = IJBossToolingConstants.LOCAL_DEPLOYMENT_NAME;
- private static final String LOCAL_COLUMN_LOC = IJBossToolingConstants.LOCAL_DEPLOYMENT_LOC;
- private static final String LOCAL_COLUMN_TEMP_LOC = IJBossToolingConstants.LOCAL_DEPLOYMENT_TEMP_LOC;
-
- protected ServerAttributeHelper getHelper() {
- if( helper == null ) {
- helper = new ServerAttributeHelper(page.getServer().getOriginal(), page.getServer());
- } else {
- String helperTS = helper.getWorkingCopy().getAttribute("timestamp", (String)null);
- String officialTS = page.getServer().getAttribute("timestamp", (String)null);
- if( !helperTS.equals(officialTS)) {
- helper = new ServerAttributeHelper(page.getServer().getOriginal(), page.getServer());
- }
- }
- return helper;
- }
-
- public Control createControl(Composite parent) {
- getHelper();
-
- Composite random = new Composite(parent, SWT.NONE);
- GridData randomData = new GridData(GridData.FILL_BOTH);
- random.setLayoutData(randomData);
- random.setLayout(new FormLayout());
-
- Composite defaultComposite = createDefaultComposite(random);
- FormData fd = new FormData();
- fd.left = new FormAttachment(0, 5);
- fd.top = new FormAttachment(0, 5);
- fd.right = new FormAttachment(100, -5);
- defaultComposite.setLayoutData(fd);
-
- Composite viewComposite = createViewerPortion(random);
- fd = new FormData();
- fd.left = new FormAttachment(0, 5);
- fd.top = new FormAttachment(defaultComposite, 5);
- fd.right = new FormAttachment(100, -5);
- fd.bottom = new FormAttachment(100, -5);
- viewComposite.setLayoutData(fd);
-
- return random;
- }
-
- private Text deployText, tempDeployText;
- private Button metadataRadio, serverRadio, customRadio, currentSelection;
- private Button deployButton, tempDeployButton;
- private ModifyListener deployListener, tempDeployListener;
- private SelectionListener radioListener, zipListener;
- private ServerAttributeHelper helper;
- private Button zipDeployWTPProjects;
- private String lastCustomDeploy, lastCustomTemp;
-
- protected Composite createDefaultComposite(Composite parent) {
-
- FormToolkit toolkit = new FormToolkit(parent.getDisplay());
-
- Section section = toolkit.createSection(parent,
- ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED
- | ExpandableComposite.TITLE_BAR);
- section.setText(Messages.swf_DeployEditorHeading);
- section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL
- | GridData.VERTICAL_ALIGN_FILL));
-
- Composite composite = toolkit.createComposite(section);
-
- composite.setLayout(new FormLayout());
-
- Label descriptionLabel = toolkit.createLabel(composite,
- Messages.swf_DeploymentDescription);
- Control top = descriptionLabel;
- Composite inner = toolkit.createComposite(composite);
- inner.setLayout(new GridLayout(1, false));
-
- IRuntime rt = getServer().getServer().getRuntime();
- boolean showRadios = true;
- if( rt == null )
- showRadios = false;
- else {
- IJBossServerRuntime jbsrt = (IJBossServerRuntime)rt.loadAdapter(IJBossServerRuntime.class, new NullProgressMonitor());
- if( jbsrt == null )
- showRadios = false;
- }
-
- if( showRadios ) {
- metadataRadio = toolkit.createButton(inner,
- Messages.EditorUseWorkspaceMetadata, SWT.RADIO);
- serverRadio = toolkit.createButton(inner,
- Messages.EditorUseServersDeployFolder, SWT.RADIO);
- customRadio = toolkit.createButton(inner,
- Messages.EditorUseCustomDeployFolder, SWT.RADIO);
-
- metadataRadio.setSelection(getDeployType().equals(
- IDeployableServer.DEPLOY_METADATA));
- serverRadio.setSelection(getDeployType().equals(
- IDeployableServer.DEPLOY_SERVER));
- customRadio.setSelection(getDeployType().equals(
- IDeployableServer.DEPLOY_CUSTOM));
- currentSelection = metadataRadio.getSelection() ? metadataRadio
- : serverRadio.getSelection() ? serverRadio : customRadio;
-
- radioListener = new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
-
- public void widgetSelected(SelectionEvent e) {
- if (e.getSource() == currentSelection)
- return; // do nothing
- page.execute(new RadioClickedCommand((Button) e.getSource(),
- currentSelection));
- currentSelection = (Button) e.getSource();
- }
- };
- metadataRadio.addSelectionListener(radioListener);
- serverRadio.addSelectionListener(radioListener);
- customRadio.addSelectionListener(radioListener);
- }
-
- FormData radios = new FormData();
- radios.top = new FormAttachment(descriptionLabel, 5);
- radios.left = new FormAttachment(0, 5);
- radios.right = new FormAttachment(100, -5);
- inner.setLayoutData(radios);
- top = inner;
-
- Label label = toolkit.createLabel(composite,
- Messages.swf_DeployDirectory);
- label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE));
- deployText = toolkit.createText(composite, getDeployDir(), SWT.BORDER);
- deployListener = new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- page.execute(new SetDeployDirCommand());
- }
- };
- deployText.addModifyListener(deployListener);
-
- deployButton = toolkit.createButton(composite, Messages.browse,
- SWT.PUSH);
- deployButton.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
-
- public void widgetSelected(SelectionEvent e) {
- DirectoryDialog d = new DirectoryDialog(new Shell());
- d.setFilterPath(page.makeGlobal(deployText.getText()));
- String x = d.open();
- if (x != null) {
- deployText.setText(page.makeRelative(x));
- }
- }
- });
-
- Label tempDeployLabel = toolkit.createLabel(composite,
- Messages.swf_TempDeployDirectory);
- tempDeployLabel.setForeground(toolkit.getColors().getColor(
- IFormColors.TITLE));
-
- tempDeployText = toolkit.createText(composite, getTempDeployDir(),
- SWT.BORDER);
- tempDeployListener = new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- page.execute(new SetTempDeployDirCommand());
- }
- };
- tempDeployText.addModifyListener(tempDeployListener);
-
- tempDeployButton = toolkit.createButton(composite, Messages.browse,
- SWT.PUSH);
- tempDeployButton.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent e) {
- }
-
- public void widgetSelected(SelectionEvent e) {
- DirectoryDialog d = new DirectoryDialog(new Shell());
- d.setFilterPath(page.makeGlobal(tempDeployText.getText()));
- String x = d.open();
- if (x != null)
- tempDeployText.setText(page.makeRelative(x));
- }
- });
-
- deployText
- .setEnabled(customRadio == null || customRadio.getSelection());
- tempDeployText.setEnabled(customRadio == null
- || customRadio.getSelection());
-
- FormData descriptionLabelData = new FormData();
- descriptionLabelData.left = new FormAttachment(0, 5);
- descriptionLabelData.top = new FormAttachment(0, 5);
- descriptionLabel.setLayoutData(descriptionLabelData);
-
- // first row
- FormData labelData = new FormData();
- labelData.left = new FormAttachment(0, 5);
- labelData.right = new FormAttachment(deployText, -5);
- labelData.top = new FormAttachment(top, 5);
- label.setLayoutData(labelData);
-
- FormData textData = new FormData();
- textData.left = new FormAttachment(deployButton, -305);
- textData.top = new FormAttachment(top, 5);
- textData.right = new FormAttachment(deployButton, -5);
- deployText.setLayoutData(textData);
-
- FormData buttonData = new FormData();
- buttonData.right = new FormAttachment(100, -5);
- buttonData.left = new FormAttachment(100, -100);
- buttonData.top = new FormAttachment(top, 2);
- deployButton.setLayoutData(buttonData);
-
- // second row
- FormData tempLabelData = new FormData();
- tempLabelData.left = new FormAttachment(0, 5);
- tempLabelData.right = new FormAttachment(deployText, -5);
- tempLabelData.top = new FormAttachment(deployText, 5);
- tempDeployLabel.setLayoutData(tempLabelData);
-
- FormData tempTextData = new FormData();
- tempTextData.left = new FormAttachment(tempDeployButton, -305);
- tempTextData.top = new FormAttachment(deployText, 5);
- tempTextData.right = new FormAttachment(tempDeployButton, -5);
- tempDeployText.setLayoutData(tempTextData);
-
- FormData tempButtonData = new FormData();
- tempButtonData.right = new FormAttachment(100, -5);
- tempButtonData.left = new FormAttachment(100, -100);
- tempButtonData.top = new FormAttachment(deployText, 5);
- tempDeployButton.setLayoutData(tempButtonData);
-
- zipDeployWTPProjects = toolkit.createButton(composite,
- Messages.EditorZipDeployments, SWT.CHECK);
- boolean zippedPublisherAvailable = isLocalZippedPublisherAvailable();
- boolean value = getServer().zipsWTPDeployments();
- zipDeployWTPProjects.setEnabled(zippedPublisherAvailable);
- zipDeployWTPProjects.setSelection(zippedPublisherAvailable && value);
-
- FormData zipButtonData = new FormData();
- zipButtonData.right = new FormAttachment(100, -5);
- zipButtonData.left = new FormAttachment(0, 5);
- zipButtonData.top = new FormAttachment(tempDeployText, 5);
- zipDeployWTPProjects.setLayoutData(zipButtonData);
-
- zipListener = new SelectionListener() {
- public void widgetSelected(SelectionEvent e) {
- page.execute(new SetZipCommand());
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
- widgetSelected(e);
- }
- };
- zipDeployWTPProjects.addSelectionListener(zipListener);
-
- toolkit.paintBordersFor(composite);
- section.setClient(composite);
- page.getSaveStatus();
- return section;
- }
-
- protected boolean isLocalZippedPublisherAvailable() {
- IJBossServerPublisher[] publishers =
- ExtensionManager.getDefault().getZippedPublishers();
- for( int i = 0; i < publishers.length; i++ ) {
- if( publishers[i].accepts(LocalPublishMethod.LOCAL_PUBLISH_METHOD, getServer().getServer(), null))
- return true;
- }
- return false;
- }
-
- public class SetDeployDirCommand extends ServerCommand {
- private String oldDir;
- private String newDir;
- private Text text;
- private ModifyListener listener;
- public SetDeployDirCommand() {
- super(page.getServer(), Messages.EditorSetDeployLabel);
- this.text = deployText;
- this.newDir = deployText.getText();
- this.listener = deployListener;
- this.oldDir = getHelper().getAttribute(IDeployableServer.DEPLOY_DIRECTORY, ""); //$NON-NLS-1$
- }
- public void execute() {
- getHelper().setAttribute(IDeployableServer.DEPLOY_DIRECTORY, newDir);
- lastCustomDeploy = newDir;
- page.getSaveStatus();
- }
- public void undo() {
- text.removeModifyListener(listener);
- getHelper().setAttribute(IDeployableServer.DEPLOY_DIRECTORY, oldDir);
- text.setText(oldDir);
- text.addModifyListener(listener);
- page.getSaveStatus();
- }
- }
-
- public class SetZipCommand extends ServerCommand {
- boolean oldVal;
- boolean newVal;
- public SetZipCommand() {
- super(page.getServer(), Messages.EditorZipDeployments);
- oldVal = getHelper().getAttribute(IDeployableServer.ZIP_DEPLOYMENTS_PREF, false);
- newVal = zipDeployWTPProjects.getSelection();
- }
- public void execute() {
- getHelper().setAttribute(IDeployableServer.ZIP_DEPLOYMENTS_PREF, newVal);
- page.getSaveStatus();
- }
- public void undo() {
- zipDeployWTPProjects.removeSelectionListener(zipListener);
- zipDeployWTPProjects.setSelection(oldVal);
- getHelper().setAttribute(IDeployableServer.ZIP_DEPLOYMENTS_PREF, oldVal);
- zipDeployWTPProjects.addSelectionListener(zipListener);
- page.getSaveStatus();
- }
- }
-
- public class SetTempDeployDirCommand extends ServerCommand {
- private String oldDir;
- private String newDir;
- private Text text;
- private ModifyListener listener;
- public SetTempDeployDirCommand() {
- super(page.getServer(), Messages.EditorSetTempDeployLabel);
- text = tempDeployText;
- newDir = tempDeployText.getText();
- listener = tempDeployListener;
- oldDir = getHelper().getAttribute(IDeployableServer.TEMP_DEPLOY_DIRECTORY, ""); //$NON-NLS-1$
- }
- public void execute() {
- getHelper().setAttribute(IDeployableServer.TEMP_DEPLOY_DIRECTORY, newDir);
- lastCustomTemp = newDir;
- page.getSaveStatus();
- }
- public void undo() {
- text.removeModifyListener(listener);
- getHelper().setAttribute(IDeployableServer.TEMP_DEPLOY_DIRECTORY, oldDir);
- text.setText(oldDir);
- text.addModifyListener(listener);
- page.getSaveStatus();
- }
- }
-
- public class RadioClickedCommand extends ServerCommand {
- private Button newSelection, oldSelection;
- private String oldDir, newDir;
- private String oldTemp, newTemp;
- private String id;
- public RadioClickedCommand(Button clicked, Button previous) {
- super(page.getServer(), Messages.EditorSetRadioClicked);
- newSelection = clicked;
- oldSelection = previous;
- id = server.getId();
- }
- public void execute() {
- boolean custom = newSelection == customRadio;
- deployText.setEnabled(custom);
- tempDeployText.setEnabled(custom);
- deployButton.setEnabled(custom);
- tempDeployButton.setEnabled(custom);
- oldDir = deployText.getText();
- oldTemp = tempDeployText.getText();
-
- String type = null;
- String oldType = oldSelection == customRadio ? IDeployableServer.DEPLOY_CUSTOM :
- oldSelection == serverRadio ? IDeployableServer.DEPLOY_SERVER :
- IDeployableServer.DEPLOY_METADATA;
-
- if( newSelection == metadataRadio ) {
- newDir = JBossServerCorePlugin.getServerStateLocation(id)
- .append(IJBossServerConstants.DEPLOY).makeAbsolute().toString();
- newTemp = JBossServerCorePlugin.getServerStateLocation(id)
- .append(IJBossServerConstants.TEMP_DEPLOY).makeAbsolute().toString();
- type = IDeployableServer.DEPLOY_METADATA;
- new File(newDir).mkdirs();
- new File(newTemp).mkdirs();
- } else if( newSelection == serverRadio ) {
- IRuntime rt = server.getRuntime();
- if( rt != null ) {
- IJBossServerRuntime jbsrt = (IJBossServerRuntime)rt.loadAdapter(IJBossServerRuntime.class, new NullProgressMonitor());
- if( jbsrt != null ) {
- String loc = jbsrt.getConfigLocation();
- String config = jbsrt.getJBossConfiguration();
- newDir = new Path(loc)
- .append(config)
- .append(IJBossServerConstants.DEPLOY).toString();
- newTemp = new Path(loc).append(config)
- .append(IJBossServerConstants.TMP)
- .append(IJBossServerConstants.JBOSSTOOLS_TMP).toString();
- new File(newTemp).mkdirs();
- type = IDeployableServer.DEPLOY_SERVER;
- }
- }
- } else {
- newDir = lastCustomDeploy;
- newTemp = lastCustomTemp;
- type = IDeployableServer.DEPLOY_CUSTOM;
- }
-
- if( !newSelection.getSelection() ) {
- // REDO, so no one actually clicked the radio. UGH!
- oldSelection.removeSelectionListener(radioListener);
- oldSelection.setSelection(false);
- oldSelection.addSelectionListener(radioListener);
-
- newSelection.removeSelectionListener(radioListener);
- newSelection.setSelection(true);
- newSelection.addSelectionListener(radioListener);
- }
-
- type = type == null ? oldType : type;
- newDir = newDir == null ? oldDir : newDir;
- newTemp = newTemp == null ? oldTemp : newTemp;
-
- deployText.removeModifyListener(deployListener);
- getHelper().setAttribute(IDeployableServer.DEPLOY_DIRECTORY, newDir);
- deployText.setText(newDir);
- deployText.addModifyListener(deployListener);
-
- tempDeployText.removeModifyListener(tempDeployListener);
- getHelper().setAttribute(IDeployableServer.TEMP_DEPLOY_DIRECTORY, newTemp);
- tempDeployText.setText(newTemp);
- tempDeployText.addModifyListener(tempDeployListener);
-
- getHelper().setAttribute(IDeployableServer.DEPLOY_DIRECTORY_TYPE, type);
- page.getSaveStatus();
- }
- public void undo() {
- deployText.removeModifyListener(deployListener);
- getHelper().setAttribute(IDeployableServer.DEPLOY_DIRECTORY, oldDir);
- deployText.setText(oldDir);
- deployText.addModifyListener(deployListener);
-
- tempDeployText.removeModifyListener(tempDeployListener);
- getHelper().setAttribute(IDeployableServer.TEMP_DEPLOY_DIRECTORY, oldTemp);
- tempDeployText.setText(oldTemp);
- tempDeployText.addModifyListener(tempDeployListener);
-
- oldSelection.removeSelectionListener(radioListener);
- oldSelection.setSelection(true);
- oldSelection.addSelectionListener(radioListener);
-
- newSelection.removeSelectionListener(radioListener);
- newSelection.setSelection(false);
- newSelection.addSelectionListener(radioListener);
-
- deployText.setEnabled(customRadio.getSelection());
- tempDeployText.setEnabled(customRadio.getSelection());
-
- String oldType = oldSelection == customRadio ? IDeployableServer.DEPLOY_CUSTOM :
- oldSelection == serverRadio ? IDeployableServer.DEPLOY_SERVER :
- IDeployableServer.DEPLOY_METADATA;
- getHelper().setAttribute(IDeployableServer.DEPLOY_DIRECTORY_TYPE, oldType);
- page.getSaveStatus();
- }
- }
-
-
- private String getDeployType() {
- return getServer().getDeployLocationType();
- }
-
- private String getDeployDir() {
- return page.getServer().getRuntime() == null ? "" : //$NON-NLS-1$
- ModuleDeploymentPage.makeRelative(getServer().getDeployFolder(),
- page.getServer().getRuntime());
- }
-
- private String getTempDeployDir() {
- return page.getServer().getRuntime() == null ? "" : //$NON-NLS-1$
- ModuleDeploymentPage.makeRelative(getServer().getTempDeployFolder(),
- page.getServer().getRuntime());
- }
-
- private IDeployableServer getServer() {
- return (IDeployableServer) page.getServer().loadAdapter(
- IDeployableServer.class, new NullProgressMonitor());
- }
-/*
- *
- *
- *
- * This is where the second half goes
- *
- *
- *
- */
- protected Composite createViewerPortion(Composite random) {
- Composite root = new Composite(random, SWT.NONE);
- root.setLayout(new FormLayout());
-
- page.getFormToolkit(random).adapt(root);
-
- viewer = new TreeViewer(root, SWT.BORDER);
- viewer.getTree().setHeaderVisible(true);
- viewer.getTree().setLinesVisible(true);
- TreeColumn moduleColumn = new TreeColumn(viewer.getTree(), SWT.NONE);
- TreeColumn publishLocColumn = new TreeColumn(viewer.getTree(), SWT.NONE);
- TreeColumn publishTempLocColumn = new TreeColumn(viewer.getTree(),
- SWT.NONE);
- moduleColumn.setText(Messages.EditorModule);
- publishLocColumn.setText(Messages.EditorSetDeployLabel);
- publishTempLocColumn.setText(Messages.EditorSetTempDeployLabel);
-
- moduleColumn.setWidth(200);
- publishLocColumn.setWidth(200);
- publishTempLocColumn.setWidth(200);
-
- FormData treeData = new FormData();
- treeData.top = new FormAttachment(0, 5);
- treeData.bottom = new FormAttachment(100, -5);
- treeData.left = new FormAttachment(0, 5);
- treeData.right = new FormAttachment(100, -5);
- viewer.getTree().setLayoutData(treeData);
- viewer.setContentProvider(new ModulePageContentProvider());
-
- viewer.setLabelProvider(new ModulePageLabelProvider());
- viewer.setColumnProperties(new String[] { LOCAL_COLUMN_NAME,
- LOCAL_COLUMN_LOC, LOCAL_COLUMN_TEMP_LOC });
- viewer.setInput(""); // irrelevent
- CellEditor[] editors = new CellEditor[] {
- new TextCellEditor(viewer.getTree()),
- new TextCellEditor(viewer.getTree()),
- new TextCellEditor(viewer.getTree()) };
- viewer.setCellModifier(new LocalDeploymentCellModifier());
- viewer.setCellEditors(editors);
-
- return root;
- }
-
- private class LocalDeploymentCellModifier implements ICellModifier {
- public boolean canModify(Object element, String property) {
- if( property == LOCAL_COLUMN_NAME)
- return false;
- return true;
- }
-
- public Object getValue(Object element, String property) {
- DeploymentModulePrefs p = preferences.getPreferences("local")
- .getModulePrefs((IModule) element);
- if (property == LOCAL_COLUMN_LOC) {
- String ret = p.getProperty(LOCAL_COLUMN_LOC);
- return ret == null ? "" : ret;
- }
- if (property == LOCAL_COLUMN_TEMP_LOC) {
- String ret = p.getProperty(LOCAL_COLUMN_TEMP_LOC);
- return ret == null ? "" : ret;
- }
-
- return "";
- }
-
- public void modify(Object element, String property, Object value) {
-
- IModule module = (IModule) ((TreeItem) element).getData();
- DeploymentModulePrefs p = preferences.getPreferences("local")
- .getModulePrefs(module);
- if (property == LOCAL_COLUMN_LOC) {
- page.firePropertyChangeCommand(p, LOCAL_COLUMN_LOC,
- (String) value, Messages.EditorEditDeployLocCommand);
- viewer.refresh();
- } else if (property == LOCAL_COLUMN_TEMP_LOC) {
- page.firePropertyChangeCommand(p, LOCAL_COLUMN_TEMP_LOC,
- (String) value, Messages.EditorEditDeployLocCommand);
- viewer.refresh();
- }
- }
- }
-
- private class ModulePageContentProvider implements ITreeContentProvider {
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
-
- public void dispose() {
- }
-
- public Object[] getElements(Object inputElement) {
- return page.getPossibleModules();
- }
-
- public boolean hasChildren(Object element) {
- return false;
- }
-
- public Object getParent(Object element) {
- return null;
- }
-
- public Object[] getChildren(Object parentElement) {
- return null;
- }
- }
-
- private class ModulePageLabelProvider implements ITableLabelProvider {
- public Image getColumnImage(Object element, int columnIndex) {
- if (element instanceof IModule && columnIndex == 0) {
- ILabelProvider labelProvider = ServerUICore.getLabelProvider();
- Image image = labelProvider.getImage((IModule) element);
- labelProvider.dispose();
- return image;
- }
- return null;
- }
-
- public String getColumnText(Object element, int columnIndex) {
- if (element instanceof IModule) {
- IModule m = (IModule) element;
- if (columnIndex == 0)
- return m.getName();
- if (columnIndex == 1) {
- DeploymentModulePrefs modPref = preferences
- .getOrCreatePreferences("local")
- .getOrCreateModulePrefs(m);
- String result = modPref.getProperty(LOCAL_COLUMN_LOC);
- if (result != null)
- return result;
- modPref.setProperty(LOCAL_COLUMN_LOC, "");
- return "";
- }
- if (columnIndex == 2) {
- DeploymentModulePrefs modPref = preferences
- .getOrCreatePreferences("local")
- .getOrCreateModulePrefs(m);
- String result = modPref.getProperty(LOCAL_COLUMN_TEMP_LOC);
- if (result != null)
- return result;
- modPref.setProperty(LOCAL_COLUMN_TEMP_LOC, "");
- return "";
- }
- }
- return element.toString();
- }
-
- public void addListener(ILabelProviderListener listener) {
- }
-
- public void dispose() {
- }
-
- public boolean isLabelProperty(Object element, String property) {
- return false;
- }
-
- public void removeListener(ILabelProviderListener listener) {
- }
- }
-
-}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ModuleDeploymentPage.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ModuleDeploymentPage.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ModuleDeploymentPage.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.ide.eclipse.as.ui.editor;
import java.io.ByteArrayOutputStream;
@@ -9,18 +19,19 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.TabFolder;
-import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IRuntime;
-import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.IServerWorkingCopy;
import org.eclipse.wst.server.ui.editor.IServerEditorPartInput;
import org.eclipse.wst.server.ui.editor.ServerEditorPart;
@@ -30,17 +41,30 @@
import org.jboss.ide.eclipse.as.core.server.IJBossServerRuntime;
import org.jboss.ide.eclipse.as.core.server.internal.ServerAttributeHelper;
import org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader;
-import org.jboss.ide.eclipse.as.core.util.ServerUtil;
import org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader.DeploymentModulePrefs;
import org.jboss.ide.eclipse.as.core.util.DeploymentPreferenceLoader.DeploymentPreferences;
+import org.jboss.ide.eclipse.as.core.util.ServerUtil;
public class ModuleDeploymentPage extends ServerEditorPart {
protected ServerResourceCommandManager commandManager;
protected ArrayList<IModule> possibleModules;
protected DeploymentPreferences preferences;
- protected ArrayList<IDeploymentEditorTab> tabs;
protected ServerAttributeHelper helper;
+ protected DeploymentModuleOptionCompositeAssistant tab;
+ public ServerAttributeHelper getHelper() {
+ if( helper == null ) {
+ helper = new ServerAttributeHelper(getServer().getOriginal(), getServer());
+ } else {
+ String helperTS = helper.getWorkingCopy().getAttribute("timestamp", (String)null);
+ String officialTS = getServer().getAttribute("timestamp", (String)null);
+ if( !helperTS.equals(officialTS)) {
+ helper = new ServerAttributeHelper(getServer().getOriginal(), getServer());
+ }
+ }
+ return helper;
+ }
+
public IModule[] getPossibleModules() {
return (IModule[]) possibleModules.toArray(new IModule[possibleModules.size()]);
}
@@ -79,38 +103,48 @@
public void createPartControl(Composite parent) {
preferences = DeploymentPreferenceLoader.loadPreferencesFromServer(server.getOriginal());
- tabs = new ArrayList<IDeploymentEditorTab>();
-
+ Composite innerContent = createPageStructure(parent);
+ addDeploymentLocationControls(innerContent, null);
+ }
+
+ private Composite createPageStructure(Composite parent) {
FormToolkit toolkit = getFormToolkit(parent);
-
- ScrolledForm form = toolkit.createScrolledForm(parent);
- toolkit.decorateFormHeading(form.getForm());
- form.setText("Deployment");
- form.getBody().setLayout(new GridLayout());
-
- final TabFolder tabFolder = new TabFolder(form.getBody(), SWT.NONE);
- tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
- toolkit.adapt(tabFolder);
- toolkit.adapt(form);
- toolkit.adapt(form.getBody());
- IDeploymentEditorTab[] newItems = createTabs(toolkit, tabFolder);
- for( int i = 0; i < newItems.length; i++ ) {
- tabs.add(newItems[i]);
- }
+ ScrolledForm allContent = toolkit.createScrolledForm(parent);
+ toolkit.decorateFormHeading(allContent.getForm());
+ allContent.setText("Deployment");
+ allContent.getBody().setLayout(new GridLayout());
+ Composite random = new Composite(allContent.getBody(), SWT.NONE);
+ GridData randomData = new GridData(GridData.FILL_BOTH);
+ random.setLayoutData(randomData);
+ random.setLayout(new FormLayout());
+ return random;
}
- protected IDeploymentEditorTab[] createTabs(FormToolkit toolkit, TabFolder tabFolder) {
- TabItem tabItem = new TabItem(tabFolder, SWT.NULL);
- IDeploymentEditorTab tab = new LocalDeploymentModuleTab();
- tabItem.setText(tab.getTabName());
+ private void addDeploymentLocationControls(Composite parent, Control top) {
+ tab = new DeploymentModuleOptionCompositeAssistant();
tab.setDeploymentPage(this);
tab.setDeploymentPrefs(preferences);
- tabItem.setControl(tab.createControl(tabFolder));
- toolkit.adapt((Composite)tabItem.getControl());
-
- return new IDeploymentEditorTab[] { tab };
+ Composite defaultComposite = tab.createDefaultComposite(parent);
+ FormData fd = new FormData();
+ fd.left = new FormAttachment(0, 5);
+ if( top == null )
+ fd.top = new FormAttachment(0, 5);
+ else
+ fd.top = new FormAttachment(top, 5);
+ fd.right = new FormAttachment(100, -5);
+ defaultComposite.setLayoutData(fd);
+
+ Composite viewComposite = tab.createViewerPortion(parent);
+ fd = new FormData();
+ fd.left = new FormAttachment(0, 5);
+ fd.top = new FormAttachment(defaultComposite, 5);
+ fd.right = new FormAttachment(100, -5);
+ fd.bottom = new FormAttachment(100, -5);
+ viewComposite.setLayoutData(fd);
}
+
+
public void execute(ServerCommand command) {
commandManager.execute(command);
}
@@ -119,9 +153,6 @@
commandManager.execute(new ChangePropertyCommand(p,key,val,cmdName));
}
-
-
-
private class ChangePropertyCommand extends ServerCommand {
private DeploymentModulePrefs p;
private String key;
@@ -136,23 +167,21 @@
}
public void execute() {
p.setProperty(key, newVal);
- saveToWC();
+ savePreferencesToWorkingCopy();
}
public void undo() {
p.setProperty(key, oldVal);
- saveToWC();
+ savePreferencesToWorkingCopy();
}
-
- protected void saveToWC() {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- DeploymentPreferenceLoader.savePreferences(bos, preferences);
- String asXML = new String(bos.toByteArray());
- helper.setAttribute(DeploymentPreferenceLoader.DEPLOYMENT_PREFERENCES_KEY, asXML);
- }
}
+ public void savePreferencesToWorkingCopy() {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ DeploymentPreferenceLoader.savePreferences(bos, preferences);
+ String asXML = new String(bos.toByteArray());
+ getHelper().setAttribute(DeploymentPreferenceLoader.DEPLOYMENT_PREFERENCES_KEY, asXML);
+ }
-
public String makeGlobal(String path) {
return makeGlobal(path, server.getRuntime());
}
@@ -196,10 +225,11 @@
// Currently inactive!!! See bug 286699
public void doSave(IProgressMonitor monitor) {
- try {
- DeploymentPreferenceLoader.savePreferences(server.getOriginal(), preferences);
- } catch( IOException ioe ) {
- // TODO eh?
- }
+ tab.updateListeners();
+// try {
+// DeploymentPreferenceLoader.savePreferences(server.getOriginal(), preferences);
+// } catch( IOException ioe ) {
+// // TODO eh?
+// }
}
}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PollerSection.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PollerSection.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PollerSection.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -1,3 +1,13 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.ide.eclipse.as.ui.editor;
import org.eclipse.swt.SWT;
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PortSection.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PortSection.java 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/PortSection.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -179,7 +179,7 @@
Composite child = new Composite(parent, SWT.NONE);
child.setLayout(new FormLayout());
label = new Label(child, SWT.NONE);
- text = new Text(child, SWT.DEFAULT);
+ text = new Text(child, SWT.SINGLE | SWT.BORDER);
detect = new Button(child, SWT.CHECK);
link = new Link(child, SWT.NONE);
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerModeSection.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerModeSection.java (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/jbossui/org/jboss/ide/eclipse/as/ui/editor/ServerModeSection.java 2010-08-13 05:37:30 UTC (rev 24129)
@@ -0,0 +1,189 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.ide.eclipse.as.ui.editor;
+
+import java.util.ArrayList;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.forms.widgets.ExpandableComposite;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.ScrolledPageBook;
+import org.eclipse.ui.forms.widgets.Section;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+import org.eclipse.wst.server.ui.editor.IServerEditorPartInput;
+import org.eclipse.wst.server.ui.editor.ServerEditorSection;
+import org.eclipse.wst.server.ui.internal.command.ServerCommand;
+import org.eclipse.wst.server.ui.internal.editor.ServerEditorPartInput;
+import org.eclipse.wst.server.ui.internal.editor.ServerResourceCommandManager;
+import org.jboss.ide.eclipse.as.core.ExtensionManager;
+import org.jboss.ide.eclipse.as.core.publishers.LocalPublishMethod;
+import org.jboss.ide.eclipse.as.core.server.IDeployableServer;
+import org.jboss.ide.eclipse.as.core.server.IJBossServerPublishMethodType;
+import org.jboss.ide.eclipse.as.core.server.internal.DeployableServerBehavior;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+import org.jboss.ide.eclipse.as.ui.UIUtil;
+
+public class ServerModeSection extends ServerEditorSection {
+ private ArrayList<DeployUIAdditions> deployAdditions;
+ private ScrolledPageBook preferencePageBook;
+ private Combo deployTypeCombo;
+ private Section publishTypeSection;
+ private ServerResourceCommandManager commandManager;
+
+ public void init(IEditorSite site, IEditorInput input) {
+ super.init(site, input);
+ if (input instanceof IServerEditorPartInput) {
+ IServerEditorPartInput sepi = (IServerEditorPartInput) input;
+ server = sepi.getServer();
+ commandManager = ((ServerEditorPartInput) sepi).getServerCommandManager();
+ }
+ }
+
+ public ServerResourceCommandManager getCommandManager() {
+ return commandManager;
+ }
+
+ public IServerWorkingCopy getServer() {
+ return server;
+ }
+
+ public void createSection(Composite parent) {
+ super.createSection(parent);
+ createPublishMethodSection(parent);
+ }
+
+
+ private class DeployUIAdditions {
+ private IJBossServerPublishMethodType publishType;
+ private IDeploymentTypeUI ui;
+ private boolean registered = false;
+ public DeployUIAdditions(IJBossServerPublishMethodType type,IDeploymentTypeUI ui) {
+ this.publishType = type;
+ this.ui = ui;
+ }
+ public boolean isRegistered() {
+ return registered;
+ }
+ public IJBossServerPublishMethodType getPublishType() {
+ return publishType;
+ }
+ public void createComposite(Composite parent) {
+ // UI can be null
+ if( ui != null ) {
+ ui.fillComposite(parent, ServerModeSection.this);
+ registered = true;
+ }
+ }
+ }
+
+ private void loadDeployTypeData() {
+ deployAdditions = new ArrayList<DeployUIAdditions>();
+ IJBossServerPublishMethodType[] publishMethodTypes = ExtensionManager.getDefault().findPossiblePublishMethods(server.getOriginal());
+ for( int i = 0; i < publishMethodTypes.length; i++) {
+ IDeploymentTypeUI ui = EditorExtensionManager.getDefault().getPublishPreferenceUI(publishMethodTypes[i].getId());
+ deployAdditions.add(new DeployUIAdditions(publishMethodTypes[i], ui));
+ }
+ }
+
+ private Control createPublishMethodSection(Composite parent) {
+ loadDeployTypeData();
+
+ FormToolkit toolkit2 = new FormToolkit(parent.getDisplay());
+ publishTypeSection = toolkit2.createSection(parent,
+ ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED
+ | ExpandableComposite.TITLE_BAR);
+ publishTypeSection.setText("Server Behaviour");
+ Composite c = toolkit2.createComposite(publishTypeSection);
+ publishTypeSection.setClient(c);
+ publishTypeSection.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
+ c.setLayout(new FormLayout());
+ deployTypeCombo = new Combo(c, SWT.DEFAULT);
+ FormData fd = UIUtil.createFormData2(0, 5, null, 0, 0, 5, 50, -5);
+ deployTypeCombo.setLayoutData(fd);
+
+
+ preferencePageBook = toolkit2.createPageBook(c, SWT.FLAT|SWT.TOP);
+ preferencePageBook.setLayoutData(UIUtil.createFormData2(
+ deployTypeCombo, 5, 0, 150, 0, 5, 100, -5));
+
+ // fill widgets
+ String[] nameList = new String[deployAdditions.size()];
+ for( int i = 0; i < nameList.length; i++ ) {
+ nameList[i] = deployAdditions.get(i).getPublishType().getName();
+ }
+ deployTypeCombo.setItems(nameList);
+ DeployableServerBehavior ds = ServerConverter.getDeployableServerBehavior(server.getOriginal());
+ if( ds != null ) {
+ String current = ds.createPublishMethod().getPublishMethodType().getName();
+ int index = deployTypeCombo.indexOf(current);
+ if( index != -1 )
+ deployTypeCombo.select(index);
+ }
+ deployTypeCombo.addModifyListener(new ModifyListener(){
+ @Override
+ public void modifyText(ModifyEvent e) {
+ deployTypeChanged(true);
+ }});
+ deployTypeChanged(false);
+ return publishTypeSection;
+ }
+
+ private void deployTypeChanged(boolean fireEvent) {
+ int index = deployTypeCombo.getSelectionIndex();
+ if( index != -1 ) {
+ DeployUIAdditions ui = deployAdditions.get(index);
+ if( !ui.isRegistered()) {
+ Composite newRoot = preferencePageBook.createPage(ui);
+ ui.createComposite(newRoot);
+ }
+ preferencePageBook.showPage(ui);
+ if( fireEvent ) {
+ commandManager.execute(new ChangeServerPropertyCommand(
+ server, IDeployableServer.SERVER_MODE,
+ ui.getPublishType().getId(), "Change server mode"));
+ }
+ } else {
+ // null selection
+ }
+ }
+
+
+ public static class ChangeServerPropertyCommand extends ServerCommand {
+ private IServerWorkingCopy server;
+ private String key;
+ private String oldVal;
+ private String newVal;
+ public ChangeServerPropertyCommand(IServerWorkingCopy server, String key, String val, String commandName) {
+ super(server, commandName);
+ this.server = server;
+ this.key = key;
+ this.newVal = val;
+ this.oldVal = server.getAttribute(key, LocalPublishMethod.LOCAL_PUBLISH_METHOD);
+ }
+ public void execute() {
+ server.setAttribute(key, newVal);
+ }
+ public void undo() {
+ server.setAttribute(key, oldVal);
+ }
+ }
+
+}
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml 2010-08-13 00:15:40 UTC (rev 24128)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/plugin.xml 2010-08-13 05:37:30 UTC (rev 24129)
@@ -4,6 +4,7 @@
<extension-point id="EventLogLabelProvider" name="org.jboss.ide.as.ui.eventLogLabelProvider" schema="schema/EventLogLabelProvider.exsd"/>
<extension-point id="EventLogMajorType" name="org.jboss.ide.eclipse.as.ui.eventLogMajorType" schema="schema/EventLogMajorType.exsd"/>
<extension-point id="ServerEditorPortSection" name="org.jboss.ide.as.ui.editor.portSection" schema="schema/ServerEditorPortSection.exsd"/>
+ <extension-point id="DeployMethodUI" name="org.jboss.ide.as.ui.deployMethodUI" schema="schema/DeployMethodUI.exsd"/>
<extension
point="org.eclipse.wst.server.ui.serverImages">
@@ -174,6 +175,12 @@
insertionId="org.eclipse.wst.server.editor.overview.left"
order="10"
typeIds="%AllJBossServerTypes"/>
+ <section
+ class="org.jboss.ide.eclipse.as.ui.editor.ServerModeSection"
+ id="org.jboss.ide.eclipse.as.ui.editor.serverModeSection"
+ insertionId="org.eclipse.wst.server.editor.overview.left"
+ order="9"
+ typeIds="%AllJBossServerTypes"/>
</extension>
@@ -578,13 +585,11 @@
typeIds="%AllJBossServerTypes">
</runtimeLocator>
</extension>
-
- <extension point="org.eclipse.ui.popupMenus">
+ <extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
id="org.jboss.ide.eclipse.as.ui.actions.exploreAction"
objectClass="org.eclipse.wst.server.core.IServer">
- enablesFor="1"
<enablement>
<adapt type="org.eclipse.wst.server.core.IServer">
<test forcePluginActivation="true"
@@ -599,10 +604,9 @@
class="org.jboss.ide.eclipse.as.ui.actions.ExploreActionDelegate"
tooltip="Explore"
menubarPath="org.eclipse.wst.server.ui.internal.cnf.controlServerSectionEnd"
+ enablesFor="1"
id="org.jboss.ide.eclipse.as.ui.actions.ExploreAction">
</action>
</objectContribution>
-
</extension>
-
</plugin>
Added: trunk/as/plugins/org.jboss.ide.eclipse.as.ui/schema/DeployMethodUI.exsd
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.ui/schema/DeployMethodUI.exsd (rev 0)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.ui/schema/DeployMethodUI.exsd 2010-08-13 05:37:30 UTC (rev 24129)
@@ -0,0 +1,109 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.jboss.ide.eclipse.as.ui" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.jboss.ide.eclipse.as.ui" id="DeployMethodUI" name="org.jboss.ide.as.ui.deployMethodUI"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
+ <complexType>
+ <sequence minOccurs="1" maxOccurs="unbounded">
+ <element ref="ui"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="ui">
+ <complexType>
+ <attribute name="deployMethodId" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn=":org.jboss.ide.eclipse.as.ui.editor.IDeploymentTypeUI"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiinfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
More information about the jbosstools-commits
mailing list