You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by st...@apache.org on 2014/06/05 13:39:05 UTC
svn commit: r1600612 - in /sling/trunk/tooling/ide:
eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/
eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/
Author: stefanegli
Date: Thu Jun 5 11:39:04 2014
New Revision: 1600612
URL: http://svn.apache.org/r1600612
Log:
SLING-3638 : adding support for 'publish' and 'clean-publish' also on a module (1/multiple) level - plus added 'doNotAskAgain' (without using preferences though atm)
Added:
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ServerBehaviourDelegateWithModulePublishSupport.java (with props)
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/refresh.gif (with props)
Removed:
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/refresh.png
Modified:
sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ServersActionModeFiddlerActionDelegate.java
Added: sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ServerBehaviourDelegateWithModulePublishSupport.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ServerBehaviourDelegateWithModulePublishSupport.java?rev=1600612&view=auto
==============================================================================
--- sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ServerBehaviourDelegateWithModulePublishSupport.java (added)
+++ sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ServerBehaviourDelegateWithModulePublishSupport.java Thu Jun 5 11:39:04 2014
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.ide.eclipse.core.internal;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.model.PublishOperation;
+import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
+
+/**
+ * Extension of ServerBehaviourDelegate which is capable of publishing
+ * individual IModules - which the parent ServerBehaviourDelegate does
+ * not support.
+ * <p>
+ * Copyright note: parts of this class have been migrated and adjusted from parent.
+ * <p>
+ * TODO remove once WST supports this
+ */
+public abstract class ServerBehaviourDelegateWithModulePublishSupport extends
+ ServerBehaviourDelegate {
+
+ private IAdaptable info3;
+ private List<IModule[]> modules3;
+
+ @Override
+ public void publish(int kind, List<IModule[]> modules,
+ IProgressMonitor monitor, IAdaptable info) throws CoreException {
+ info3 = info;
+ modules3 = modules==null ? null : new LinkedList<IModule[]>(modules);
+ super.publish(kind, modules, monitor, info);
+ }
+
+ // from WST's ServerBehavior
+ private List<Integer> computeDelta(final List<IModule[]> moduleList) {
+
+ final List<Integer> deltaKindList = new ArrayList<Integer>();
+ final Iterator<IModule[]> iterator = moduleList.iterator();
+ while (iterator.hasNext()) {
+ IModule[] module = iterator.next();
+ if (hasBeenPublished(module)) {
+ IModule m = module[module.length - 1];
+ if ((m.getProject() != null && !m.getProject().isAccessible())
+ || getPublishedResourceDelta(module).length == 0) {
+ deltaKindList.add(new Integer(ServerBehaviourDelegate.NO_CHANGE));
+ }
+ else {
+ deltaKindList.add(new Integer(ServerBehaviourDelegate.CHANGED));
+ }
+ }
+ else {
+ deltaKindList.add(new Integer(ServerBehaviourDelegate.ADDED));
+ }
+ }
+// this.addRemovedModules(moduleList, null);
+// while (deltaKindList.size() < moduleList.size()) {
+// deltaKindList.add(new Integer(ServerBehaviourDelegate.REMOVED));
+// }
+ return deltaKindList;
+ }
+
+ // from WST's ServerBehavior
+ public IStatus publish(int kind, IProgressMonitor monitor) {
+ Activator.getDefault().getPluginLogger().trace("-->-- Publishing to server: " + getServer().toString() + " -->--");
+
+ if (getServer().getServerType().hasRuntime() && getServer().getRuntime() == null)
+ return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "No runtime available", null);
+
+ final List<IModule[]> moduleList = modules3==null ? getAllModules() : new LinkedList<IModule[]>(modules3);//getAllModules();
+ List<Integer> deltaKindList = computeDelta(moduleList);
+
+ PublishOperation[] tasks = getTasks(kind, moduleList, deltaKindList);
+ int size = 2000 + 3500 * moduleList.size() + 500 * tasks.length;
+
+// monitor = ProgressUtil.getMonitorFor(monitor); //TODO
+ String mainTaskMsg = "Publishing to "+getServer().getName();//NLS.bind(Messages.publishing, getServer().getName());
+ monitor.beginTask(mainTaskMsg, size);
+
+ MultiStatus tempMulti = new MultiStatus(Activator.PLUGIN_ID, 0, "", null);
+
+ if (monitor.isCanceled())
+ return Status.CANCEL_STATUS;
+
+ try {
+ Activator.getDefault().getPluginLogger().trace("Starting publish");
+ publishStart(monitor);//ProgressUtil.getSubMonitorFor(monitor, 1000)); //TODO
+
+ if (monitor.isCanceled())
+ return Status.CANCEL_STATUS;
+
+ // execute tasks
+ MultiStatus taskStatus = performTasks(tasks, monitor);
+ monitor.setTaskName(mainTaskMsg);
+ if (taskStatus != null && !taskStatus.isOK())
+ tempMulti.addAll(taskStatus);
+
+ // execute publishers
+ taskStatus = executePublishers(kind, moduleList, deltaKindList, monitor, info3);
+ monitor.setTaskName(mainTaskMsg);
+ if (taskStatus != null && !taskStatus.isOK())
+ tempMulti.addAll(taskStatus);
+
+ if (monitor.isCanceled())
+ return Status.CANCEL_STATUS;
+
+ // publish the server
+ publishServer(kind, monitor);//ProgressUtil.getSubMonitorFor(monitor, 1000));//TODO
+ monitor.setTaskName(mainTaskMsg);
+
+ if (monitor.isCanceled())
+ return Status.CANCEL_STATUS;
+
+ // publish modules
+ publishModules(kind, moduleList, deltaKindList, tempMulti, monitor);
+
+ if (monitor.isCanceled())
+ return Status.CANCEL_STATUS;
+
+ monitor.done();
+ } catch (CoreException ce) {
+ Activator.getDefault().getPluginLogger().error("CoreException publishing to " + toString(), ce);
+ return ce.getStatus();
+ } catch (Exception e) {
+ Activator.getDefault().getPluginLogger().error( "Error publishing to " + toString(), e);
+ tempMulti.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Error publishing", e));
+ } finally {
+ // end the publishing
+ try {
+ publishFinish(monitor);//ProgressUtil.getSubMonitorFor(monitor, 500));
+ } catch (CoreException ce) {
+ Activator.getDefault().getPluginLogger().error("CoreException publishing to " + toString(), ce);
+ tempMulti.add(ce.getStatus());
+ } catch (Exception e) {
+ Activator.getDefault().getPluginLogger().error("Error stopping publish to " + toString(), e);
+ tempMulti.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Error publishing", e));
+ }
+ }
+
+ Activator.getDefault().getPluginLogger().trace("--<-- Done publishing --<--");
+
+ if (tempMulti.getChildren().length == 1)
+ return tempMulti.getChildren()[0];
+
+ MultiStatus multi = null;
+ if (tempMulti.getSeverity() == IStatus.OK)
+ return Status.OK_STATUS;
+ else if (tempMulti.getSeverity() == IStatus.INFO)
+ multi = new MultiStatus(Activator.PLUGIN_ID, 0, "Publishing completed with information", null);
+ else if (tempMulti.getSeverity() == IStatus.WARNING)
+ multi = new MultiStatus(Activator.PLUGIN_ID, 0, "Publishing completed with a warning", null);
+ else if (tempMulti.getSeverity() == IStatus.ERROR)
+ multi = new MultiStatus(Activator.PLUGIN_ID, 0, "Publishing failed", null);
+
+ if (multi != null)
+ multi.addAll(tempMulti);
+
+ return multi;
+ }
+
+
+}
Propchange: sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/ServerBehaviourDelegateWithModulePublishSupport.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java?rev=1600612&r1=1600611&r2=1600612&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java (original)
+++ sling/trunk/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/internal/SlingLaunchpadBehaviour.java Thu Jun 5 11:39:04 2014
@@ -53,7 +53,7 @@ import org.eclipse.wst.server.core.model
import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
import org.osgi.framework.Version;
-public class SlingLaunchpadBehaviour extends ServerBehaviourDelegate {
+public class SlingLaunchpadBehaviour extends ServerBehaviourDelegateWithModulePublishSupport {
private ResourceChangeCommandFactory commandFactory;
private ILaunch launch;
Modified: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ServersActionModeFiddlerActionDelegate.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ServersActionModeFiddlerActionDelegate.java?rev=1600612&r1=1600611&r2=1600612&view=diff
==============================================================================
--- sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ServersActionModeFiddlerActionDelegate.java (original)
+++ sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/ServersActionModeFiddlerActionDelegate.java Thu Jun 5 11:39:04 2014
@@ -16,6 +16,7 @@
*/
package org.apache.sling.ide.eclipse.ui.internal;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -33,11 +34,14 @@ import org.eclipse.jface.viewers.Decorat
import org.eclipse.jface.viewers.IDecoration;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IViewActionDelegate;
import org.eclipse.ui.IViewPart;
+import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.ui.IServerModule;
import org.eclipse.wst.server.ui.internal.ImageResource;
import org.eclipse.wst.server.ui.internal.Messages;
@@ -51,10 +55,16 @@ public class ServersActionModeFiddlerAct
private IPropertyChangeListener debugTooltipListener;
private IPropertyChangeListener disconnectTooltipListener;
- private List<IAction> prependedToolbarActions = new LinkedList<IAction>();
- private List<IAction> appendedToolbarActions = new LinkedList<IAction>();
+ private List<ActionContributionItem> prependedToolbarActions = new LinkedList<ActionContributionItem>();
+ private List<ActionContributionItem> appendedToolbarActionContributionItems = new LinkedList<ActionContributionItem>();
private IServer server;
+ private List<IModule[]> modules;
private Action cleanAction;
+ private Action publishAction;
+ private ActionContributionItem wstPublishAction;
+ private ActionContributionItem cleanActionContributionItem;
+ private ActionContributionItem publishActionContributionItem;
+ protected boolean doNotAskAgain = false; //TODO: move to preferences
@Override
public void run(IAction action) {
@@ -63,13 +73,55 @@ public class ServersActionModeFiddlerAct
@Override
public void selectionChanged(IAction action, ISelection selection) {
- if (selection!=null && (selection instanceof IStructuredSelection) &&
- (((IStructuredSelection)selection).getFirstElement() instanceof IServer)) {
- server = (IServer)(((IStructuredSelection)selection).getFirstElement());
- cleanAction.setEnabled(true);
- } else {
- cleanAction.setEnabled(false);
+ server = null;
+ modules = null;
+ if (selection!=null && (selection instanceof IStructuredSelection)) {
+ IStructuredSelection iss = (IStructuredSelection) selection;
+ Object first = iss.getFirstElement();
+ if (first instanceof IServer) {
+ server = (IServer)first;
+ modules = null;
+ if (iss.size()>1) {
+ // verify that all selected elements are of type IServer
+ Iterator it = iss.iterator();
+ it.next(); // skip the first, we have that above already
+ while(it.hasNext()) {
+ Object next = it.next();
+ if (!(next instanceof IServer)) {
+ server = null;
+ modules = null;
+ break;
+ }
+ }
+ }
+ } else if (first instanceof IServerModule) {
+ modules = new LinkedList<IModule[]>();
+ IServerModule module = (IServerModule)first;
+ modules.add(module.getModule());
+ server = module.getServer();
+ if (iss.size()>1) {
+ // verify that all selected elements are of type IServerModule
+ // plus add the module[] to the modules list
+ Iterator it = iss.iterator();
+ it.next(); // skip the first, we have that above already
+ while(it.hasNext()) {
+ Object next = it.next();
+ if (!(next instanceof IServerModule)) {
+ server = null;
+ module = null;
+ break;
+ } else {
+ module = (IServerModule) next;
+ modules.add(module.getModule());
+ }
+ }
+ }
+ }
}
+
+ cleanAction.setEnabled(server!=null);
+ publishAction.setEnabled(server!=null);
+
action.setEnabled(true);
final IAction serverRunAction = actionBars.getGlobalActionHandler("org.eclipse.wst.server.run");
final IAction serverDebugAction = actionBars.getGlobalActionHandler("org.eclipse.wst.server.debug");
@@ -82,12 +134,21 @@ public class ServersActionModeFiddlerAct
serverDebugAction.setHoverImageDescriptor(SharedImages.DEBUG_CONNECT);
stopRunAction.setHoverImageDescriptor(SharedImages.DISCONNECT);
- for (Iterator it = appendedToolbarActions.iterator(); it.hasNext();) {
- IAction appendedAction = (IAction) it.next();
- if (!actionAdded(appendedAction)) {
+ findWstPublishAction();
+
+ for (Iterator it = appendedToolbarActionContributionItems.iterator(); it.hasNext();) {
+ ActionContributionItem appendedAction = (ActionContributionItem) it.next();
+ if (!contributionAdded(appendedAction)) {
actionBars.getToolBarManager().add(appendedAction);
}
}
+ if (wstPublishAction!=null) {
+ wstPublishAction.setVisible(false);
+ publishActionContributionItem.setVisible(true);
+ } else {
+ // otherwise hide it, as it is an unexpected situation
+ publishActionContributionItem.setVisible(false);
+ }
final String runText = "Connect to server in run mode";
if (runTooltipListener==null) {
@@ -141,15 +202,31 @@ public class ServersActionModeFiddlerAct
}
- private boolean actionAdded(IAction action) {
+ private void findWstPublishAction() {
+ if (wstPublishAction!=null) {
+ return;
+ }
IContributionItem[] items = actionBars.getToolBarManager().getItems();
for (int i = 0; i < items.length; i++) {
- IContributionItem iContributionItem = items[i];
- final String id = iContributionItem.getId();
- if (id==null) {
- continue;
+ IContributionItem item = items[i];
+ if (item instanceof ActionContributionItem) {
+ ActionContributionItem actionItem = (ActionContributionItem) item;
+ IAction a = actionItem.getAction();
+ if ("org.eclipse.wst.server.publish".equals(a.getActionDefinitionId())) {
+ wstPublishAction = actionItem;
+// item.setVisible(false);
+// actionBars.getToolBarManager().remove(item);
+ }
}
- if (id.equals(action.getId())) {
+ }
+
+ }
+
+ private boolean contributionAdded(ActionContributionItem action) {
+ IContributionItem[] items = actionBars.getToolBarManager().getItems();
+ for (int i = 0; i < items.length; i++) {
+ IContributionItem iContributionItem = items[i];
+ if (iContributionItem==action) {
return true;
}
}
@@ -171,7 +248,27 @@ public class ServersActionModeFiddlerAct
private void initToolbarContributedActions() {
cleanAction = new Action("Clean Publish...", IAction.AS_PUSH_BUTTON) {
public void run() {
- if (MessageDialog.openConfirm(view.getSite().getShell(), Messages.defaultDialogTitle, Messages.dialogPublishClean)) {
+ if (server==null) {
+ MessageDialog.openInformation(view.getSite().getShell(), "No server selected", "A server must be selected");
+ return;
+ }
+ int selection = 2;
+ if (!doNotAskAgain) {
+ MessageDialog dialog = new MessageDialog(view.getSite().getShell(), Messages.defaultDialogTitle, null, Messages.dialogPublishClean,
+ MessageDialog.QUESTION_WITH_CANCEL,
+ new String[] {"Cancel", "OK (do not ask again)", "OK"}, 1) {
+ @Override
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ setShellStyle(getShellStyle() | SWT.SHEET);
+ }
+ };
+ selection = dialog.open();
+ }
+ if (selection != 0) {
+ if (selection==1) {
+ doNotAskAgain = true;
+ }
IAdaptable info = new IAdaptable() {
public Object getAdapter(Class adapter) {
if (Shell.class.equals(adapter))
@@ -182,18 +279,48 @@ public class ServersActionModeFiddlerAct
}
};
- server.publish(IServer.PUBLISH_CLEAN, null, info, null);
+ server.publish(IServer.PUBLISH_CLEAN, modules, info, null);
}
}
};
cleanAction.setText("Clean Publish...");
cleanAction.setToolTipText("Clean and Publish...");
ImageDescriptor cleanAndPublishImageDesc = new DecorationOverlayIcon(
- ImageResource.getImageDescriptor(ImageResource.IMG_ELCL_PUBLISH).createImage(),
- ImageDescriptor.createFromFile(SharedImages.class, "refresh.png"), IDecoration.BOTTOM_RIGHT);
+ ImageResource.getImageDescriptor(ImageResource.IMG_CLCL_PUBLISH).createImage(),
+ ImageDescriptor.createFromFile(SharedImages.class, "refresh.gif"), IDecoration.BOTTOM_RIGHT);
cleanAction.setImageDescriptor(cleanAndPublishImageDesc);
- cleanAction.setId("org.apache.sling.ide.eclipse.ui.actions.ClearAction");
- appendedToolbarActions.add(cleanAction);
+ cleanAction.setId("org.apache.sling.ide.eclipse.ui.actions.CleanPublishAction");
+ publishAction = new Action("Publish", IAction.AS_PUSH_BUTTON) {
+ public void run() {
+ if (server==null) {
+ MessageDialog.openInformation(view.getSite().getShell(), "No server selected", "A server must be selected");
+ return;
+ }
+ IAdaptable info = new IAdaptable() {
+ public Object getAdapter(Class adapter) {
+ if (Shell.class.equals(adapter))
+ return view.getSite().getShell();
+ if (String.class.equals(adapter))
+ return "user";
+ return null;
+ }
+ };
+
+ server.publish(IServer.PUBLISH_INCREMENTAL, modules, info, null);
+ }
+ };
+ publishAction.setText("Publish");
+ publishAction.setToolTipText("Publish");
+ publishAction.setImageDescriptor(ImageResource.getImageDescriptor(ImageResource.IMG_CLCL_PUBLISH));
+ publishAction.setId("org.apache.sling.ide.eclipse.ui.actions.PublishAction");
+ cleanAction.setEnabled(false);
+ publishAction.setEnabled(false);
+
+ cleanActionContributionItem = new ActionContributionItem(cleanAction);
+ publishActionContributionItem = new ActionContributionItem(publishAction);
+
+ appendedToolbarActionContributionItems.add(publishActionContributionItem);
+ appendedToolbarActionContributionItems.add(cleanActionContributionItem);
}
}
Added: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/refresh.gif
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/refresh.gif?rev=1600612&view=auto
==============================================================================
Binary file - no diff available.
Propchange: sling/trunk/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/refresh.gif
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream