[jbosstools-commits] JBoss Tools SVN: r23585 - in workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as: core/publishers and 4 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Tue Jul 20 06:02:37 EDT 2010
Author: rob.stryker at jboss.com
Date: 2010-07-20 06:02:36 -0400 (Tue, 20 Jul 2010)
New Revision: 23585
Added:
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractPublishMethod.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerPublishMethodType.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/ServerPublishMethodType.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/AbstractJSTPublisher.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSEJSTPublisher.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSEPublishMethod.java
workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/SingleFileRSEPublisher.java
Log:
RSE branch why weren't these files added??
Added: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractPublishMethod.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractPublishMethod.java (rev 0)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/publishers/AbstractPublishMethod.java 2010-07-20 10:02:36 UTC (rev 23585)
@@ -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: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerPublishMethodType.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerPublishMethodType.java (rev 0)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/IJBossServerPublishMethodType.java 2010-07-20 10:02:36 UTC (rev 23585)
@@ -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();
+}
Added: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/ServerPublishMethodType.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/ServerPublishMethodType.java (rev 0)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/ServerPublishMethodType.java 2010-07-20 10:02:36 UTC (rev 23585)
@@ -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;
+ }
+}
Added: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/AbstractJSTPublisher.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/AbstractJSTPublisher.java (rev 0)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/AbstractJSTPublisher.java 2010-07-20 10:02:36 UTC (rev 23585)
@@ -0,0 +1,270 @@
+/*******************************************************************************
+ * 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.rse.core;
+
+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.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.ServerConverter;
+
+public abstract class AbstractJSTPublisher implements IJBossServerPublisher {
+ protected IModuleResourceDelta[] delta;
+ protected IDeployableServer server;
+ protected int publishState = IServer.PUBLISH_STATE_NONE;
+ protected IJBossServerPublishMethod publishMethod;
+
+ public AbstractJSTPublisher() {}
+ public boolean accepts(String method, IServer server, IModule[] module) {
+ if( !method.equals(getTargetedPublishMethodId()))
+ return false;
+ if( module == null )
+ return true;
+ IDeployableServer ds = ServerConverter.getDeployableServer(server);
+ boolean shouldAccept = ds != null
+ && ModuleCoreNature.isFlexibleProject(module[0].getProject())
+ && zipSettingsMatch();
+ 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 = 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;
+ }
+
+ /**
+ * Get the publish method this publisher is associated with
+ * @return
+ */
+ protected abstract String getTargetedPublishMethodId();
+
+ /**
+ * Get the callback handler to be used for building the module.
+ * If the module is to be published locally, this may be a handler which only copies locally.
+ * If the module is to be zipped & published locally, this may be
+ * a handler which zips to a temporary directory, and allows the finish method to move the file
+ *
+ * @param path
+ * @param server
+ * @param method
+ * @return
+ */
+ protected abstract IPublishCopyCallbackHandler getCallbackHandler(IPath path, IServer server, IJBossServerPublishMethod method);
+
+ /**
+ * Gets the actual deploy path for this module
+ *
+ * @param moduleTree
+ * @param server
+ * @return
+ */
+ protected abstract IPath getDeployPath(IModule[] moduleTree, IDeployableServer server);
+
+ /**
+ * 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.
+ *
+ * @param publishType
+ * @param moduleTree
+ * @param server
+ * @param monitor
+ */
+ protected abstract void finishPublish(int publishType, IModule[] moduleTree, IDeployableServer server, IProgressMonitor monitor);
+
+ /**
+ * Check whether the current zip settings for the publish method
+ * match with what this publisher expects.
+ * @return
+ */
+ protected abstract boolean zipSettingsMatch();
+
+ private IPublishCopyCallbackHandler getCallbackHandler(IPath path) {
+ return getCallbackHandler(path, server.getServer(), publishMethod);
+ }
+
+ protected IStatus fullPublish(IModule[] moduleTree, IModule module, IProgressMonitor monitor) throws CoreException {
+ IPath deployPath = getDeployPath(moduleTree, server);
+ IPublishCopyCallbackHandler callback = getCallbackHandler(deployPath);
+ 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 ))
+ callback.deleteResource(new Path("/"), monitor); //$NON-NLS-1$
+
+ ArrayList<IStatus> list = new ArrayList<IStatus>();
+
+ if( !PublishUtil.deployPackaged(moduleTree) && !PublishUtil.isBinaryObject(moduleTree)) {
+ 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 {
+ // A child that must be zipped
+ 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), new NullProgressMonitor());
+ ModuleFile mf = new ModuleFile(tempFile.toFile(), tempFile.lastSegment(), tempFile);
+ handler.copyFile(mf, deployPath, new NullProgressMonitor());
+ } catch( IOException ioe) {
+ list.add(new Status(IStatus.ERROR, JBossServerCorePlugin.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 deployPath = getDeployPath(moduleTree, server);
+ if( !PublishUtil.deployPackaged(moduleTree) && !PublishUtil.isBinaryObject(moduleTree)) {
+ IPublishCopyCallbackHandler handler = getCallbackHandler(deployPath);
+ 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.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), new NullProgressMonitor());
+ ModuleFile mf = new ModuleFile(tempFile.toFile(), tempFile.lastSegment(), tempFile);
+ handler.copyFile(mf, deployPath, new NullProgressMonitor());
+ } catch( IOException ioe) {
+ IStatus s = new Status(IStatus.ERROR, JBossServerCorePlugin.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 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()};
+ }
+ return new IStatus[]{Status.OK_STATUS};
+ }
+
+ protected IStatus unpublish(IDeployableServer jbServer, IModule[] module,
+ IProgressMonitor monitor) throws CoreException {
+ IPath remotePath = getDeployPath(module, server);
+ IPublishCopyCallbackHandler handler = getCallbackHandler(new Path("/")); //$NON-NLS-1$
+ handler.deleteResource(remotePath, monitor);
+ return Status.OK_STATUS;
+ }
+}
Added: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSEJSTPublisher.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSEJSTPublisher.java (rev 0)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSEJSTPublisher.java 2010-07-20 10:02:36 UTC (rev 23585)
@@ -0,0 +1,125 @@
+/*******************************************************************************
+ * 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.as.rse.core;
+
+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.Status;
+import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.model.IModuleFile;
+import org.eclipse.wst.server.core.model.IModuleResourceDelta;
+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.xpl.PublishCopyUtil.IPublishCopyCallbackHandler;
+import org.jboss.ide.eclipse.as.core.util.IJBossToolingConstants;
+
+public class RSEJSTPublisher extends AbstractJSTPublisher {
+
+ private RSEPublishMethod method;
+
+ @Override
+ protected String getTargetedPublishMethodId() {
+ return RSEPublishMethod.RSE_ID;
+ }
+
+ @Override
+ protected boolean zipSettingsMatch() {
+ // TODO handle this
+ return false;
+ }
+
+ @Override
+ public IStatus publishModule(IJBossServerPublishMethod method,
+ IServer server, IModule[] module, int publishType,
+ IModuleResourceDelta[] delta, IProgressMonitor monitor)
+ throws CoreException {
+ this.method = (RSEPublishMethod)method;
+ return super.publishModule(method, server, module, publishType, delta, monitor);
+ }
+
+ @Override
+ protected IPath getDeployPath(IModule[] moduleTree, IDeployableServer server) {
+ String folder = PublishUtil.getDeployRootFolder(
+ moduleTree, server,
+ method.getRemoteRootFolder().toString(),
+ IJBossToolingConstants.LOCAL_DEPLOYMENT_LOC);
+ return PublishUtil.getDeployPath(moduleTree, folder);
+ }
+
+ @Override
+ protected IPublishCopyCallbackHandler getCallbackHandler(IPath path, IServer server,
+ IJBossServerPublishMethod method) {
+ return new RSERemotePublishHandler(path);
+ }
+
+ protected class RSERemotePublishHandler implements IPublishCopyCallbackHandler {
+ public IPath root;
+ private ArrayList<IPath> createdFolders = new ArrayList<IPath>();
+ public RSERemotePublishHandler(IPath path) {
+ this.root = path;
+ }
+ public IStatus[] copyFile(IModuleFile mf, IPath path,
+ IProgressMonitor monitor) throws CoreException {
+ File file = PublishUtil.getFile(mf);
+ IPath remotePath = root.append(path);
+ try {
+ method.getFileService().upload(file, remotePath.removeLastSegments(1).toString(),
+ remotePath.lastSegment(), true, null, null, monitor);
+ } catch( SystemMessageException sme ) {
+ System.err.println("failed to copy to " + remotePath.toString()); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ public IStatus[] deleteResource(IPath path, IProgressMonitor monitor)
+ throws CoreException {
+ IPath remotePath = root.append(path);
+ try {
+ method.getFileService().delete(remotePath.removeLastSegments(1).toString(), remotePath.lastSegment(), monitor);
+ } catch( SystemMessageException sme ) {
+ System.err.println("failed to delete " + remotePath.toString()); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ public IStatus[] makeDirectoryIfRequired(IPath dir,
+ IProgressMonitor monitor) throws CoreException {
+ if( dir.segmentCount() > 0 )
+ makeDirectoryIfRequired(dir.removeLastSegments(1), monitor);
+ IPath toMake = root.append(dir);
+ if( createdFolders.contains(toMake))
+ return new IStatus[]{Status.OK_STATUS};
+ try {
+ method.getFileService().createFolder(toMake.removeLastSegments(1).toString(), toMake.lastSegment(), monitor);
+ } catch( SystemMessageException sme ) {
+ System.err.println("failed to make folder " + toMake.toString()); //$NON-NLS-1$
+ }
+ createdFolders.add(toMake);
+ return null;
+ }
+ }
+
+ @Override
+ protected void finishPublish(int publishType, IModule[] moduleTree,
+ IDeployableServer server, IProgressMonitor monitor) {
+ // do nothing
+ }
+}
Added: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSEPublishMethod.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSEPublishMethod.java (rev 0)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/RSEPublishMethod.java 2010-07-20 10:02:36 UTC (rev 23585)
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * 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.rse.core;
+
+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.Path;
+import org.eclipse.rse.core.RSECorePlugin;
+import org.eclipse.rse.core.model.IHost;
+import org.eclipse.rse.core.subsystems.ISubSystem;
+import org.eclipse.rse.services.files.IFileService;
+import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
+import org.jboss.ide.eclipse.as.core.publishers.AbstractPublishMethod;
+import org.jboss.ide.eclipse.as.core.server.internal.DeployableServerBehavior;
+
+public class RSEPublishMethod extends AbstractPublishMethod {
+
+ public static final String RSE_ID = "rse"; //$NON-NLS-1$
+
+ @Override
+ public String getPublishMethodId() {
+ return RSE_ID;
+ }
+
+ private IFileServiceSubSystem fileSubSystem = null;
+ private IPath remoteRootFolder;
+ private IPath remoteTemporaryFolder;
+ public void publishStart(DeployableServerBehavior behaviour,
+ IProgressMonitor monitor) throws CoreException {
+ loadRemoteDeploymentDetails();
+ if (fileSubSystem != null && !fileSubSystem.isConnected()) {
+ try {
+ fileSubSystem.connect(monitor, false);
+ } catch (Exception e) {
+ }
+ }
+ super.publishStart(behaviour, monitor);
+ }
+ public IPath getRemoteRootFolder() {
+ return remoteRootFolder;
+ }
+ public IPath getRemoteTemporaryFolder() {
+ return remoteTemporaryFolder;
+ }
+ public IFileServiceSubSystem getFileServiceSubSystem() {
+ return fileSubSystem;
+ }
+ public IFileService getFileService() {
+ return fileSubSystem.getFileService();
+ }
+
+ public int publishFinish(DeployableServerBehavior behaviour,
+ IProgressMonitor monitor) throws CoreException {
+ return super.publishFinish(behaviour, monitor);
+ }
+
+ protected void loadRemoteDeploymentDetails() throws CoreException{
+ // TODO obviously fix this
+ this.remoteRootFolder = new Path("/home/rob/redhat/deploy"); //$NON-NLS-1$
+ this.remoteTemporaryFolder = new Path("/home/rob/redhat/tmp"); //$NON-NLS-1$
+ String CONNECTION_NAME = "Local"; //$NON-NLS-1$ //TODO obviously get this from somewhere else
+ IHost host = findHost(CONNECTION_NAME);
+ if( host != null ) {
+ fileSubSystem = findFileTransferSubSystem(host);
+ } else {
+ // TODO error host not found in RSE
+ }
+ }
+
+ protected IHost findHost(String connectionName) {
+ IHost[] allHosts = RSECorePlugin.getTheSystemRegistry().getHosts();
+ for( int i = 0; i < allHosts.length; i++ ) {
+ if( allHosts[i].getAliasName().equals(connectionName))
+ return allHosts[i];
+ }
+ return null;
+ }
+
+ /* approved files subsystems *
+ ftp.files
+ local.files
+ ssh.files
+ */
+ protected static List<String> APPROVED_FILE_SYSTEMS =
+ Arrays.asList(new String[]{ "ftp.files", "local.files", "ssh.files"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ protected IFileServiceSubSystem findFileTransferSubSystem(IHost host) {
+ ISubSystem[] systems = RSECorePlugin.getTheSystemRegistry().getSubSystems(host);
+ for( int i = 0; i < systems.length; i++ ) {
+ if( APPROVED_FILE_SYSTEMS.contains(systems[i].getConfigurationId()))
+ return (IFileServiceSubSystem)systems[i];
+ }
+ return null;
+ }
+
+}
Added: workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/SingleFileRSEPublisher.java
===================================================================
--- workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/SingleFileRSEPublisher.java (rev 0)
+++ workspace/rstryker/rse/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/rse/core/SingleFileRSEPublisher.java 2010-07-20 10:02:36 UTC (rev 23585)
@@ -0,0 +1,138 @@
+/*******************************************************************************
+ * 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.rse.core;
+
+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.Status;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
+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.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.IJBossToolingConstants;
+import org.jboss.ide.eclipse.as.core.util.ServerConverter;
+
+public class SingleFileRSEPublisher implements IJBossServerPublisher {
+
+ private IDeployableServer server;
+ private RSEPublishMethod method;
+ private int publishState = IServer.PUBLISH_STATE_NONE;
+ public SingleFileRSEPublisher() {
+ }
+
+ public int getPublishState() {
+ return publishState;
+ }
+
+ public boolean accepts(String method, IServer server, IModule[] module) {
+ if( RSEPublishMethod.RSE_ID.equals(method)
+ && module != null && module.length > 0
+ && module[module.length-1] != null
+ && module[module.length-1].getModuleType().getId().equals(SingleDeployableFactory.MODULE_TYPE))
+ 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);
+ this.method = (RSEPublishMethod)method;
+ 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 IPath findModuleFolderWithDefault(IModule module, IDeployableServer server, IPath startingPath) {
+ IModule[] moduleTree = new IModule[]{module};
+ String folder = PublishUtil.getDeployRootFolder(
+ moduleTree, server, startingPath.toString(),
+ IJBossToolingConstants.LOCAL_DEPLOYMENT_LOC);
+ return PublishUtil.getDeployPath(moduleTree, folder).removeLastSegments(1);
+ }
+ protected IPath findDestinationFolder(IModule module, IDeployableServer server) {
+ return findModuleFolderWithDefault(module, server, method.getRemoteRootFolder());
+ }
+ protected IPath findTempDestinationFolder(IModule module, IDeployableServer server) {
+ return findModuleFolderWithDefault(module, server, method.getRemoteTemporaryFolder());
+ }
+
+ 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 = findDestinationFolder(module, server);
+ IPath tempDestFolder = findTempDestinationFolder(module, server);
+ String name = sourcePath.lastSegment();
+
+ try {
+ method.getFileService().upload(sourcePath.toFile(), tempDestFolder.toString(), name, true, null, null, new NullProgressMonitor());
+ method.getFileService().move(tempDestFolder.toString(), name, destFolder.toString(), name, new NullProgressMonitor());
+ } catch( SystemMessageException sme ) {
+ // TODO fix
+ sme.printStackTrace();
+ }
+ // TODO log?
+// 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);
+ }
+ 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 {
+ SingleDeployableModuleDelegate delegate = (SingleDeployableModuleDelegate)module.loadAdapter(SingleDeployableModuleDelegate.class, new NullProgressMonitor());
+ if( delegate != null ) {
+ IPath sourcePath = delegate.getGlobalSourcePath();
+ IPath destFolder = findDestinationFolder(module, server);
+ String name = sourcePath.lastSegment();
+ try {
+ method.getFileService().delete(destFolder.toString(), name, new NullProgressMonitor());
+ } catch( SystemMessageException sme ) {
+ // TODO fix
+ sme.printStackTrace();
+ }
+ }
+ Status status = new Status(IStatus.OK, JBossServerCorePlugin.PLUGIN_ID, IEventCodes.SINGLE_FILE_UNPUBLISH_SUCCESS,
+ NLS.bind(Messages.ModuleDeleted, module.getName()), null);
+ return status;
+ }
+}
More information about the jbosstools-commits
mailing list