Author: rombert
Date: Thu Sep 26 20:39:39 2013
New Revision: 1526675
URL: http://svn.apache.org/r1526675
Log:
SLING-3120 - Allow installing/updating the install support bundle from
the servers view
Refresh the server status after installing the tooling support bundle.
Added:
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetBundleVersionCommand.java
(with props)
Modified:
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/InstallEditorSection.java
Added:
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetBundleVersionCommand.java
URL:
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetBundleVersionCommand.java?rev=1526675&view=auto
==============================================================================
---
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetBundleVersionCommand.java
(added)
+++
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetBundleVersionCommand.java
Thu Sep 26 20:39:39 2013
@@ -0,0 +1,68 @@
+/*
+ * 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;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.AbstractOperation;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.wst.server.core.IServerWorkingCopy;
+
+public class SetBundleVersionCommand extends AbstractOperation {
+
+ private IServerWorkingCopy server;
+ private final String bundleSymbolicName;
+ private final String bundleVersion;
+ private String oldBundleVersion;
+
+ public SetBundleVersionCommand(IServerWorkingCopy server, String
bundleSymbolicName, String bundleVersion) {
+ super("Setting bundle version...");
+
+ this.server = server;
+ this.bundleSymbolicName = bundleSymbolicName;
+ this.bundleVersion = bundleVersion;
+ }
+
+ @Override
+ public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws
ExecutionException {
+ String propertyName = propertyName();
+
+ oldBundleVersion = server.getAttribute(propertyName, (String) null);
+ server.setAttribute(propertyName, bundleVersion);
+
+ return Status.OK_STATUS;
+ }
+
+ private String propertyName() {
+ return String.format(ISlingLaunchpadServer.PROP_BUNDLE_VERSION_FORMAT,
this.bundleSymbolicName);
+ }
+
+ @Override
+ public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws
ExecutionException {
+ return execute(monitor, info);
+ }
+
+ @Override
+ public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws
ExecutionException {
+ server.setAttribute(propertyName(), oldBundleVersion);
+
+ return Status.OK_STATUS;
+ }
+
+}
Propchange:
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetBundleVersionCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-core/src/org/apache/sling/ide/eclipse/core/SetBundleVersionCommand.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Modified:
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/InstallEditorSection.java
URL:
http://svn.apache.org/viewvc/sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/InstallEditorSection.java?rev=1526675&r1=1526674&r2=1526675&view=diff
==============================================================================
---
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/InstallEditorSection.java
(original)
+++
sling/branches/tooling-ide-vlt/tooling/ide/eclipse-ui/src/org/apache/sling/ide/eclipse/ui/internal/InstallEditorSection.java
Thu Sep 26 20:39:39 2013
@@ -30,12 +30,17 @@ import org.apache.sling.ide.eclipse.core
import org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer;
import org.apache.sling.ide.eclipse.core.ServerUtil;
import org.apache.sling.ide.eclipse.core.SetBundleInstallLocallyCommand;
+import org.apache.sling.ide.eclipse.core.SetBundleVersionCommand;
import org.apache.sling.ide.osgi.OsgiClient;
import org.apache.sling.ide.osgi.OsgiClientException;
import org.apache.sling.ide.osgi.OsgiClientFactory;
import org.apache.sling.ide.transport.RepositoryInfo;
+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.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
@@ -72,6 +77,7 @@ public class InstallEditorSection extend
private PropertyChangeListener serverListener;
private Label supportBundleVersionLabel;
private Composite actionArea;
+ private EmbeddedArtifactLocator artifactLocator;
@Override
public void createSection(Composite parent) {
@@ -129,6 +135,14 @@ public class InstallEditorSection extend
if
(ISlingLaunchpadServer.PROP_INSTALL_LOCALLY.equals(evt.getPropertyName())) {
quickLocalInstallButton.setSelection((Boolean)evt.getNewValue());
mvnSlingInstallButton.setSelection(!(Boolean)evt.getNewValue());
+ } else if (evt.getPropertyName().equals(
+
String.format(ISlingLaunchpadServer.PROP_BUNDLE_VERSION_FORMAT,
+
EmbeddedArtifactLocator.SUPPORT_BUNDLE_SYMBOLIC_NAME))) {
+
+ Version launchpadVersion = new Version((String)
evt.getNewValue());
+ Version embeddedVersion = new
Version(artifactLocator.loadToolingSupportBundle().getVersion());
+
+ updateActionArea(launchpadVersion, embeddedVersion);
}
}
};
@@ -141,6 +155,8 @@ public class InstallEditorSection extend
launchpadServer = (ISlingLaunchpadServer)
server.loadAdapter(ISlingLaunchpadServer.class,
new NullProgressMonitor());
}
+
+ artifactLocator = Activator.getDefault().getArtifactLocator();
}
private void initialize() {
@@ -161,28 +177,12 @@ public class InstallEditorSection extend
quickLocalInstallButton.addSelectionListener(listener);
mvnSlingInstallButton.addSelectionListener(listener);
- Version version;
- final EmbeddedArtifact supportBundle;
- try {
- version =
launchpadServer.getBundleVersion(EmbeddedArtifactLocator.SUPPORT_BUNDLE_SYMBOLIC_NAME);
- EmbeddedArtifactLocator artifactLocator =
Activator.getDefault().getArtifactLocator();
- supportBundle = artifactLocator.loadToolingSupportBundle();
- } catch (RuntimeException e2) {
- // TODO Auto-generated catch block
- e2.printStackTrace();
- throw e2;
- }
+ Version serverVersion =
launchpadServer.getBundleVersion(EmbeddedArtifactLocator.SUPPORT_BUNDLE_SYMBOLIC_NAME);
+ final EmbeddedArtifact supportBundle =
artifactLocator.loadToolingSupportBundle();
final Version embeddedVersion = new
Version(supportBundle.getVersion());
- if (version == null || embeddedVersion.compareTo(version) > 0) {
- supportBundleVersionLabel
- .setText("Installation support bundle is not present our
outdated, local deployment will not work");
- installOrUpdateSupportBundleLink.setEnabled(true);
- } else {
- supportBundleVersionLabel.setText("Installation support bundle is
present and up to date.");
- installOrUpdateSupportBundleLink.setEnabled(false);
- }
+ updateActionArea(serverVersion, embeddedVersion);
installOrUpdateSupportBundleLink.addHyperlinkListener(new
HyperlinkAdapter() {
@@ -198,10 +198,11 @@ public class InstallEditorSection extend
public void run(IProgressMonitor monitor) throws
InvocationTargetException,
InterruptedException {
final Version remoteVersion;
- monitor.beginTask("Installing support bundle", 2);
+ monitor.beginTask("Installing support bundle", 3);
// double-check, just in case
monitor.setTaskName("Getting remote bundle
version");
+ Version deployedVersion;
final String message;
try {
RepositoryInfo repositoryInfo =
ServerUtil.getRepositoryInfo(server.getOriginal(),
@@ -209,6 +210,7 @@ public class InstallEditorSection extend
OsgiClient client = new
OsgiClientFactory().createOsgiClient(repositoryInfo);
remoteVersion = client
.getBundleVersion(EmbeddedArtifactLocator.SUPPORT_BUNDLE_SYMBOLIC_NAME);
+ deployedVersion = remoteVersion;
monitor.worked(1);
@@ -225,11 +227,29 @@ public class InstallEditorSection extend
} finally {
IOUtils.closeQuietly(contents);
}
+ deployedVersion = embeddedVersion;
message = "Bundle version " +
embeddedVersion + " installed";
}
monitor.worked(1);
+ monitor.setTaskName("Updating server
configuration");
+ final Version finalDeployedVersion =
deployedVersion;
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ execute(new
SetBundleVersionCommand(server,
+
EmbeddedArtifactLocator.SUPPORT_BUNDLE_SYMBOLIC_NAME,
+
finalDeployedVersion.toString()));
+ try {
+ server.save(false, new
NullProgressMonitor());
+ } catch (CoreException e) {
+
Activator.getDefault().getLog().log(e.getStatus());
+ }
+ }
+ });
+ monitor.worked(1);
+
} catch (OsgiClientException e) {
throw new InvocationTargetException(e);
} catch (URISyntaxException e) {
@@ -250,8 +270,12 @@ public class InstallEditorSection extend
}
});
} catch (InvocationTargetException e1) {
- // TODO error reporting
- e1.printStackTrace();
+
+ IStatus status = new Status(Status.ERROR,
Activator.PLUGIN_ID,
+ "Error while installing support bundle: " +
e1.getTargetException().getMessage(), e1
+ .getTargetException());
+
+ ErrorDialog.openError(getShell(), "Error while installing
support bundle", e1.getMessage(), status);
} catch (InterruptedException e1) {
Thread.currentThread().interrupt();
return;
@@ -260,6 +284,19 @@ public class InstallEditorSection extend
});
}
+ private void updateActionArea(Version serverVersion, final Version
embeddedVersion) {
+ if (serverVersion == null || embeddedVersion.compareTo(serverVersion)
> 0) {
+ supportBundleVersionLabel
+ .setText("Installation support bundle is not present our
outdated, local deployment will not work");
+ installOrUpdateSupportBundleLink.setEnabled(true);
+ } else {
+ supportBundleVersionLabel.setText("Installation support bundle is
present and up to date.");
+ installOrUpdateSupportBundleLink.setEnabled(false);
+ }
+
+ actionArea.pack();
+ }
+
/*
* (non-Javadoc)
*