aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Schmidt2011-11-06 17:51:37 (EST)
committerSebastian Schmidt2011-11-06 17:51:37 (EST)
commit9f553ba95dc91896b9bc55cc20ffae0961a7b015 (patch)
treed2f7ad975622edb64b30837af4a68a047b726872
parenta36355b91cbcfea097740fc169149a5762a341ab (diff)
downloadorg.eclipse.rtp-9f553ba95dc91896b9bc55cc20ffae0961a7b015.zip
org.eclipse.rtp-9f553ba95dc91896b9bc55cc20ffae0961a7b015.tar.gz
org.eclipse.rtp-9f553ba95dc91896b9bc55cc20ffae0961a7b015.tar.bz2
Updated HttpDeployer to use IRTPService instead of P2-APIs
-rw-r--r--bundles/org.eclipse.rtp.httpdeployer.releng/feature.xml13
-rw-r--r--bundles/org.eclipse.rtp.httpdeployer/HTTP Deployer.launch4
-rw-r--r--bundles/org.eclipse.rtp.httpdeployer/META-INF/MANIFEST.MF14
-rw-r--r--bundles/org.eclipse.rtp.httpdeployer/OSGI-INF/httpdeployer-component.xml3
-rw-r--r--bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/feature/FeatureManager.java131
-rw-r--r--bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/internal/HttpDeployerComponent.java34
-rw-r--r--bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/internal/HttpDeployerInitializer.java28
-rwxr-xr-xbundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/repository/RepositoryManager.java73
-rw-r--r--tests/org.eclipse.rtp.tests.httpdeployer/src/org/eclipse/rtp/httpdeployer/feature/FeatureManagerTest.java78
-rw-r--r--tests/org.eclipse.rtp.tests.httpdeployer/src/org/eclipse/rtp/httpdeployer/internal/HttpDeployerComponentTest.java19
-rw-r--r--tests/org.eclipse.rtp.tests.httpdeployer/src/org/eclipse/rtp/httpdeployer/repository/RepositoryManagerTest.java45
11 files changed, 113 insertions, 329 deletions
diff --git a/bundles/org.eclipse.rtp.httpdeployer.releng/feature.xml b/bundles/org.eclipse.rtp.httpdeployer.releng/feature.xml
index 69df4e2..32cd306 100644
--- a/bundles/org.eclipse.rtp.httpdeployer.releng/feature.xml
+++ b/bundles/org.eclipse.rtp.httpdeployer.releng/feature.xml
@@ -2,7 +2,7 @@
<feature
id="org.eclipse.rtp.httpdeployer"
label="Http Deployer"
- version="0.2.3">
+ version="0.2.3.qualifier">
<description url="http://www.example.com/description">
[Enter Feature Description here.]
@@ -16,6 +16,10 @@
[Enter License Description here.]
</license>
+ <includes
+ id="org.eclipse.rtp.configurator.feature"
+ version="0.0.0"/>
+
<requires>
<import plugin="org.jdom"/>
<import plugin="org.eclipse.osgi.services"/>
@@ -116,4 +120,11 @@
version="0.0.0"
unpack="false"/>
+ <plugin
+ id="com.google.gson"
+ download-size="0"
+ install-size="0"
+ version="0.0.0"
+ unpack="false"/>
+
</feature>
diff --git a/bundles/org.eclipse.rtp.httpdeployer/HTTP Deployer.launch b/bundles/org.eclipse.rtp.httpdeployer/HTTP Deployer.launch
index 87eb163..0bc1afa 100644
--- a/bundles/org.eclipse.rtp.httpdeployer/HTTP Deployer.launch
+++ b/bundles/org.eclipse.rtp.httpdeployer/HTTP Deployer.launch
@@ -16,9 +16,9 @@
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Declipse.ignoreApp=true -Dosgi.noShutdown=true -Dorg.osgi.service.http.port=9090"/>
<stringAttribute key="pde.version" value="3.3"/>
<booleanAttribute key="show_selected_only" value="false"/>
-<stringAttribute key="target_bundles" value="javax.servlet@default:default,org.apache.commons.codec@default:default,org.apache.commons.fileupload@default:default,org.apache.commons.httpclient@default:default,org.apache.commons.io@default:default,org.apache.commons.logging@default:default,org.eclipse.core.contenttype@default:default,org.eclipse.core.jobs@default:default,org.eclipse.core.net@default:default,org.eclipse.core.runtime@default:true,org.eclipse.ecf.filetransfer@default:default,org.eclipse.ecf.identity@default:default,org.eclipse.ecf.provider.filetransfer.httpclient.ssl@default:false,org.eclipse.ecf.provider.filetransfer.httpclient@default:default,org.eclipse.ecf.provider.filetransfer@default:default,org.eclipse.ecf@default:default,org.eclipse.equinox.app@default:default,org.eclipse.equinox.common@2:true,org.eclipse.equinox.concurrent@default:default,org.eclipse.equinox.ds@1:true,org.eclipse.equinox.frameworkadmin.equinox@default:default,org.eclipse.equinox.frameworkadmin@default:default,org.eclipse.equinox.http.jetty@default:default,org.eclipse.equinox.http.registry@default:default,org.eclipse.equinox.http.servlet@default:default,org.eclipse.equinox.launcher.gtk.linux.x86@default:false,org.eclipse.equinox.launcher@default:default,org.eclipse.equinox.p2.artifact.repository@default:default,org.eclipse.equinox.p2.console@default:default,org.eclipse.equinox.p2.core@default:default,org.eclipse.equinox.p2.director@default:default,org.eclipse.equinox.p2.engine@default:default,org.eclipse.equinox.p2.garbagecollector@default:default,org.eclipse.equinox.p2.jarprocessor@default:default,org.eclipse.equinox.p2.metadata.repository@default:default,org.eclipse.equinox.p2.metadata@default:default,org.eclipse.equinox.p2.operations@default:default,org.eclipse.equinox.p2.publisher.eclipse@default:default,org.eclipse.equinox.p2.publisher@default:default,org.eclipse.equinox.p2.ql@default:default,org.eclipse.equinox.p2.repository@default:default,org.eclipse.equinox.p2.touchpoint.eclipse@default:default,org.eclipse.equinox.p2.touchpoint.natives@default:default,org.eclipse.equinox.p2.transport.ecf@default:default,org.eclipse.equinox.preferences@default:default,org.eclipse.equinox.registry@default:default,org.eclipse.equinox.security@default:default,org.eclipse.equinox.simpleconfigurator.manipulator@default:default,org.eclipse.equinox.simpleconfigurator@1:true,org.eclipse.equinox.util@default:default,org.eclipse.osgi.services@default:default,org.eclipse.osgi@-1:true,org.jdom@default:default,org.mortbay.jetty.server@default:default,org.mortbay.jetty.util@default:default,org.sat4j.core@default:default,org.sat4j.pb@default:default"/>
+<stringAttribute key="target_bundles" value="com.google.gson@default:default,javax.servlet@default:default,org.apache.commons.codec@default:default,org.apache.commons.fileupload@default:default,org.apache.commons.httpclient@default:default,org.apache.commons.io@default:default,org.apache.commons.logging*1.0.4.v201101211617@default:default,org.apache.commons.logging*1.1.1.v201101211721@default:default,org.eclipse.core.contenttype@default:default,org.eclipse.core.jobs@default:default,org.eclipse.core.net@default:default,org.eclipse.core.runtime@default:true,org.eclipse.ecf.filetransfer@default:default,org.eclipse.ecf.identity@default:default,org.eclipse.ecf.provider.filetransfer.httpclient.ssl@default:false,org.eclipse.ecf.provider.filetransfer.httpclient@default:default,org.eclipse.ecf.provider.filetransfer@default:default,org.eclipse.ecf@default:default,org.eclipse.equinox.app@default:default,org.eclipse.equinox.common@2:true,org.eclipse.equinox.concurrent@default:default,org.eclipse.equinox.ds@1:true,org.eclipse.equinox.frameworkadmin.equinox@default:default,org.eclipse.equinox.frameworkadmin@default:default,org.eclipse.equinox.http.jetty@default:default,org.eclipse.equinox.http.registry@default:default,org.eclipse.equinox.http.servlet@default:default,org.eclipse.equinox.launcher.gtk.linux.x86@default:false,org.eclipse.equinox.launcher@default:default,org.eclipse.equinox.p2.artifact.repository@default:default,org.eclipse.equinox.p2.console@default:default,org.eclipse.equinox.p2.core@default:default,org.eclipse.equinox.p2.director@default:default,org.eclipse.equinox.p2.engine@default:default,org.eclipse.equinox.p2.garbagecollector@default:default,org.eclipse.equinox.p2.jarprocessor@default:default,org.eclipse.equinox.p2.metadata.repository@default:default,org.eclipse.equinox.p2.metadata@default:default,org.eclipse.equinox.p2.operations@default:default,org.eclipse.equinox.p2.publisher.eclipse@default:default,org.eclipse.equinox.p2.publisher@default:default,org.eclipse.equinox.p2.ql@default:default,org.eclipse.equinox.p2.repository@default:default,org.eclipse.equinox.p2.touchpoint.eclipse@default:default,org.eclipse.equinox.p2.touchpoint.natives@default:default,org.eclipse.equinox.p2.transport.ecf@default:default,org.eclipse.equinox.preferences@default:default,org.eclipse.equinox.registry@default:default,org.eclipse.equinox.security@default:default,org.eclipse.equinox.simpleconfigurator.manipulator@default:default,org.eclipse.equinox.simpleconfigurator@1:true,org.eclipse.equinox.util@default:default,org.eclipse.osgi.services@default:default,org.eclipse.osgi@-1:true,org.jdom@default:default,org.mortbay.jetty.server@default:default,org.mortbay.jetty.util@default:default,org.sat4j.core@default:default,org.sat4j.pb@default:default"/>
<booleanAttribute key="tracing" value="false"/>
<booleanAttribute key="useCustomFeatures" value="false"/>
<booleanAttribute key="useDefaultConfigArea" value="true"/>
-<stringAttribute key="workspace_bundles" value="org.eclipse.rtp.httpdeployer*0.1.0@default:default"/>
+<stringAttribute key="workspace_bundles" value="org.eclipse.rtp.core.model@default:default,org.eclipse.rtp.core.service.provider@default:default,org.eclipse.rtp.core@default:default,org.eclipse.rtp.httpdeployer@default:default"/>
</launchConfiguration>
diff --git a/bundles/org.eclipse.rtp.httpdeployer/META-INF/MANIFEST.MF b/bundles/org.eclipse.rtp.httpdeployer/META-INF/MANIFEST.MF
index ff9ab73..5ac14db 100644
--- a/bundles/org.eclipse.rtp.httpdeployer/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.rtp.httpdeployer/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: HttpDeployer
Bundle-SymbolicName: org.eclipse.rtp.httpdeployer
-Bundle-Version: 0.2.2
+Bundle-Version: 0.2.3.qualifier
Bundle-ActivationPolicy: lazy
Import-Package: javax.servlet;version="[2.5.0,3.0.0)",
javax.servlet.http;version="[2.5.0,3.0.0)",
@@ -11,16 +11,8 @@ Import-Package: javax.servlet;version="[2.5.0,3.0.0)",
org.apache.commons.fileupload.servlet;version="[1.0.0,2.0.0)",
org.apache.commons.io;version="[2.0.0,3.0.0)",
org.eclipse.core.runtime,
- org.eclipse.core.runtime.jobs,
- org.eclipse.equinox.internal.provisional.configurator,
- org.eclipse.equinox.p2.core;version="[2.0.0,3.0.0)",
- org.eclipse.equinox.p2.engine;version="[2.0.0,3.0.0)",
- org.eclipse.equinox.p2.metadata;version="[2.0.0,3.0.0)",
- org.eclipse.equinox.p2.operations,
- org.eclipse.equinox.p2.query;version="[2.0.0,3.0.0)",
- org.eclipse.equinox.p2.repository;version="2.0.0",
- org.eclipse.equinox.p2.repository.artifact;version="[2.0.0,3.0.0)",
- org.eclipse.equinox.p2.repository.metadata;version="[2.0.0,3.0.0)",
+ org.eclipse.rtp.core,
+ org.eclipse.rtp.core.model;version="1.0.0",
org.jdom,
org.jdom.input,
org.jdom.output,
diff --git a/bundles/org.eclipse.rtp.httpdeployer/OSGI-INF/httpdeployer-component.xml b/bundles/org.eclipse.rtp.httpdeployer/OSGI-INF/httpdeployer-component.xml
index 43efd6e..e49885a 100644
--- a/bundles/org.eclipse.rtp.httpdeployer/OSGI-INF/httpdeployer-component.xml
+++ b/bundles/org.eclipse.rtp.httpdeployer/OSGI-INF/httpdeployer-component.xml
@@ -2,6 +2,5 @@
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="startService" deactivate="shutdownService" name="org.eclipse.rtp.httpdeployer.component">
<implementation class="org.eclipse.rtp.httpdeployer.internal.HttpDeployerComponent" />
<reference name="httpService" bind="setHttpService" unbind="unsetHttpService" interface="org.osgi.service.http.HttpService" />
- <reference name="provisioningAgent" bind="setProvisioningAgent" unbind="unsetProvisioningAgent" interface="org.eclipse.equinox.p2.core.IProvisioningAgent" />
- <reference bind="setConfigurator" cardinality="1..1" interface="org.eclipse.equinox.internal.provisional.configurator.Configurator" name="Configurator" policy="static" unbind="unsetConfigurator"/>
+ <reference bind="setRtpService" cardinality="1..1" interface="org.eclipse.rtp.core.IRTPService" name="IRTPService" policy="static" unbind="unsetRtpService"/>
</scr:component>
diff --git a/bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/feature/FeatureManager.java b/bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/feature/FeatureManager.java
index 94fa38d..53a21a6 100644
--- a/bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/feature/FeatureManager.java
+++ b/bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/feature/FeatureManager.java
@@ -8,130 +8,45 @@
******************************************************************************/
package org.eclipse.rtp.httpdeployer.feature;
-import java.io.IOException;
-import java.util.Collection;
+import java.util.ArrayList;
+import java.util.List;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.equinox.internal.provisional.configurator.Configurator;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
-import org.eclipse.equinox.p2.engine.ProvisioningContext;
-import org.eclipse.equinox.p2.metadata.IInstallableUnit;
-import org.eclipse.equinox.p2.metadata.Version;
-import org.eclipse.equinox.p2.operations.InstallOperation;
-import org.eclipse.equinox.p2.operations.ProfileChangeOperation;
-import org.eclipse.equinox.p2.operations.ProvisioningJob;
-import org.eclipse.equinox.p2.operations.ProvisioningSession;
-import org.eclipse.equinox.p2.operations.UninstallOperation;
-import org.eclipse.equinox.p2.query.QueryUtil;
-import org.eclipse.rtp.httpdeployer.repository.RepositoryManager;
+import org.eclipse.rtp.core.IRTPService;
+import org.eclipse.rtp.core.model.Feature;
+import org.eclipse.rtp.core.model.SourceVersion;
-@SuppressWarnings("restriction")
public class FeatureManager {
- public enum Action {
- UNINSTALL, INSTALL
- }
-
- private final IProvisioningAgent provisioningAgent;
- private final RepositoryManager repositoryManager;
- private final Configurator configurator;
+ private IRTPService rtpService;
- public FeatureManager(IProvisioningAgent provisioningAgent, RepositoryManager repositoryManager, Configurator configurator) {
- this.provisioningAgent = provisioningAgent;
- this.repositoryManager = repositoryManager;
- this.configurator = configurator;
- }
-
- // TODO: Not tested
- public void installFeature(String featureId, String version) throws FeatureInstallException {
- ProfileChangeOperation operation = resolveProfileChangeOperation(featureId, version, Action.INSTALL);
- executeProfileChangeOperation(operation);
- applyChanges();
+ public FeatureManager(IRTPService rtpService) {
+ this.rtpService = rtpService;
}
// TODO: Not tested
- public void uninstallFeature(String featureId, String version) throws FeatureInstallException {
- ProfileChangeOperation operation = resolveProfileChangeOperation(featureId, version, Action.UNINSTALL);
- executeProfileChangeOperation(operation);
- applyChanges();
- }
-
- // TODO: Not tested
- private ProfileChangeOperation resolveProfileChangeOperation(String featureId, String version, Action action)
+ public void installFeature(String featureId, String version)
throws FeatureInstallException {
- ProvisioningSession session = new ProvisioningSession(provisioningAgent);
- ProvisioningContext context = createProvisioningContext();
-
- Collection<IInstallableUnit> units = getInstallableUnits(context, featureId, version);
- ProfileChangeOperation operation = getOperation(session, units, action);
- operation.setProvisioningContext(context);
- resolveOperation(operation);
-
- return operation;
- }
-
- private ProfileChangeOperation getOperation(ProvisioningSession session, Collection<IInstallableUnit> units, Action action)
- throws FeatureInstallException {
- ProfileChangeOperation operation;
- if (action.equals(Action.UNINSTALL)) {
- operation = new UninstallOperation(session, units);
- } else {
- operation = new InstallOperation(session, units);
- }
-
- return operation;
- }
-
- private void resolveOperation(ProfileChangeOperation operation) throws FeatureInstallException {
- IStatus result = operation.resolveModal(null);
-
+ Feature feature = new Feature(featureId, version);
+ SourceVersion sourceVersion = new SourceVersion();
+ sourceVersion.addFeature(feature);
+ IStatus result = rtpService.install(sourceVersion);
if (!result.isOK()) {
- String errorMessage = generateErrorMessage(result);
- throw new FeatureInstallException(errorMessage);
- }
- }
-
- private void applyChanges() throws FeatureInstallException {
- try {
- configurator.applyConfiguration();
- } catch (IOException e) {
- throw new FeatureInstallException(e);
+ throw new FeatureInstallException(result.getMessage());
}
}
- protected ProvisioningContext createProvisioningContext() {
- ProvisioningContext context = new ProvisioningContext(provisioningAgent);
- context.setArtifactRepositories(repositoryManager.getRepositories());
- context.setArtifactRepositories(repositoryManager.getRepositories());
- return context;
- }
-
- protected void executeProfileChangeOperation(ProfileChangeOperation operation) throws FeatureInstallException {
- ProvisioningJob provisioningJob = operation.getProvisioningJob(new NullProgressMonitor());
- if (provisioningJob == null) {
- return;
- }
-
- IStatus result = provisioningJob.runModal(new NullProgressMonitor());
-
+ // TODO: Not tested
+ public void uninstallFeature(String featureId, String version)
+ throws FeatureInstallException {
+ Feature feature = new Feature(featureId, version);
+ SourceVersion sourceVersion = new SourceVersion();
+ sourceVersion.addFeature(feature);
+ List<SourceVersion> sourceVersionsToUninstall = new ArrayList<SourceVersion>();
+ sourceVersionsToUninstall.add(sourceVersion);
+ IStatus result = rtpService.remove(sourceVersionsToUninstall);
if (!result.isOK()) {
throw new FeatureInstallException(result.getMessage());
}
}
-
- private String generateErrorMessage(IStatus result) {
- IStatus[] children = result.getChildren();
- String message = "";
- for (int i = 0; i < children.length; i++) {
- message = children[i].getMessage() + "\n";
- }
- return message;
- }
-
- protected Collection<IInstallableUnit> getInstallableUnits(ProvisioningContext context, String id, String version) {
- Collection<IInstallableUnit> toInstall = context.getMetadata(null)
- .query(QueryUtil.createIUQuery(id, Version.create(version)), null).toUnmodifiableSet();
- return toInstall;
- }
} \ No newline at end of file
diff --git a/bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/internal/HttpDeployerComponent.java b/bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/internal/HttpDeployerComponent.java
index e28ab04..5b0ce63 100644
--- a/bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/internal/HttpDeployerComponent.java
+++ b/bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/internal/HttpDeployerComponent.java
@@ -10,47 +10,35 @@ package org.eclipse.rtp.httpdeployer.internal;
import javax.servlet.ServletException;
-import org.eclipse.equinox.internal.provisional.configurator.Configurator;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
+import org.eclipse.rtp.core.IRTPService;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
-@SuppressWarnings("restriction")
public class HttpDeployerComponent {
private HttpDeployerInitializer initializer = new HttpDeployerInitializer();
protected HttpService httpService;
- protected IProvisioningAgent provisioningAgent;
- protected Configurator configurator;
+ protected IRTPService rtpService;
- public void setHttpService(HttpService httpService) {
- this.httpService = httpService;
- }
-
- public void unsetHttpService(HttpService httpService) {
- this.httpService = null;
+ public void setRtpService(IRTPService rtpService) {
+ this.rtpService = rtpService;
}
- public void setConfigurator(Configurator configurator) {
- this.configurator = configurator;
+ public void unsetRtpService(IRTPService rtpService) {
+ this.rtpService = null;
}
- public void unsetConfigurator(Configurator configurator) {
- this.configurator = null;
- }
-
- public void setProvisioningAgent(IProvisioningAgent provisioningAgent) {
- this.provisioningAgent = provisioningAgent;
+ public void setHttpService(HttpService httpService) {
+ this.httpService = httpService;
}
- public void unsetProvisioningAgent(IProvisioningAgent provisioningAgent) {
- this.provisioningAgent = null;
+ public void unsetHttpService(HttpService httpService) {
+ this.httpService = null;
}
protected void startService() throws ServletException, NamespaceException {
- initializer.setProvisioningAgent(provisioningAgent);
- initializer.setConfigurator(configurator);
+ initializer.setRtpService(rtpService);
initializer.setHttpService(httpService);
initializer.init();
}
diff --git a/bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/internal/HttpDeployerInitializer.java b/bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/internal/HttpDeployerInitializer.java
index 08293b6..1a76dc5 100644
--- a/bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/internal/HttpDeployerInitializer.java
+++ b/bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/internal/HttpDeployerInitializer.java
@@ -10,8 +10,7 @@ package org.eclipse.rtp.httpdeployer.internal;
import javax.servlet.ServletException;
-import org.eclipse.equinox.internal.provisional.configurator.Configurator;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
+import org.eclipse.rtp.core.IRTPService;
import org.eclipse.rtp.httpdeployer.bundle.BundleServlet;
import org.eclipse.rtp.httpdeployer.feature.FeatureManager;
import org.eclipse.rtp.httpdeployer.feature.FeatureServlet;
@@ -20,7 +19,6 @@ import org.eclipse.rtp.httpdeployer.repository.RepositoryServlet;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
-@SuppressWarnings("restriction")
public class HttpDeployerInitializer {
public static final String ALIAS_BUNDLE = "/bundle"; //$NON-NLS-N$
@@ -29,14 +27,13 @@ public class HttpDeployerInitializer {
public static final String ALIAS_SYSTEM = "/system"; //$NON-NLS-N$
private HttpService httpService;
- private Configurator configurator;
- private IProvisioningAgent provisioningAgent;
private BundleServlet bundleServlet;
private RepositoryServlet repositoryServlet;
private FeatureServlet featureServlet;
private SystemServlet systemServlet;
private RepositoryManager repositoryManager;
private FeatureManager featureManager;
+ private IRTPService rtpService;
public void init() throws ServletException, NamespaceException {
createManager();
@@ -45,8 +42,8 @@ public class HttpDeployerInitializer {
}
private void createManager() {
- repositoryManager = new RepositoryManager(provisioningAgent);
- featureManager = new FeatureManager(provisioningAgent, repositoryManager, configurator);
+ repositoryManager = new RepositoryManager(rtpService);
+ featureManager = new FeatureManager(rtpService);
}
private void createServlets() {
@@ -58,21 +55,19 @@ public class HttpDeployerInitializer {
private void registerServlets() throws ServletException, NamespaceException {
httpService.registerServlet(ALIAS_BUNDLE, bundleServlet, null, null);
- httpService.registerServlet(ALIAS_REPOSITORY, repositoryServlet, null, null);
+ httpService.registerServlet(ALIAS_REPOSITORY, repositoryServlet, null,
+ null);
httpService.registerServlet(ALIAS_FEATURE, featureServlet, null, null);
httpService.registerServlet(ALIAS_SYSTEM, systemServlet, null, null);
+ System.out.println("Registered HttpDeployer Servlets");
}
- public void setHttpService(HttpService httpService) {
- this.httpService = httpService;
- }
-
- public void setConfigurator(Configurator configurator) {
- this.configurator = configurator;
+ public void setRtpService(IRTPService rtpService) {
+ this.rtpService = rtpService;
}
- public void setProvisioningAgent(IProvisioningAgent provisioningAgent) {
- this.provisioningAgent = provisioningAgent;
+ public void setHttpService(HttpService httpService) {
+ this.httpService = httpService;
}
public void unregister() {
@@ -81,4 +76,5 @@ public class HttpDeployerInitializer {
httpService.unregister(ALIAS_FEATURE);
httpService.unregister(ALIAS_SYSTEM);
}
+
}
diff --git a/bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/repository/RepositoryManager.java b/bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/repository/RepositoryManager.java
index 39ba064..a5c2236 100755
--- a/bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/repository/RepositoryManager.java
+++ b/bundles/org.eclipse.rtp.httpdeployer/src/org/eclipse/rtp/httpdeployer/repository/RepositoryManager.java
@@ -19,9 +19,7 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.apache.commons.io.FileUtils;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
-import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
-import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
+import org.eclipse.rtp.core.IRTPService;
import org.eclipse.rtp.httpdeployer.internal.CommonConstants;
public class RepositoryManager {
@@ -30,27 +28,23 @@ public class RepositoryManager {
private static final String FILENAME_CONTENT = "content.jar"; //$NON-NLS-N$
private static final String FILENAME_ARTIFACTS = "artifacts.jar"; //$NON-NLS-N$
private static final int FILE_BUFFER = 8192;
- private final IProvisioningAgent provisioningAgent;
+ private final IRTPService rtpService;
- public RepositoryManager(IProvisioningAgent provisioningAgent) {
- this.provisioningAgent = provisioningAgent;
+ public RepositoryManager(IRTPService rtpService) {
+ this.rtpService = rtpService;
}
public URI[] getRepositories() {
- IMetadataRepositoryManager metaRepoManager = getMetadataRepositoryManager();
-
- return metaRepoManager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL);
+ return rtpService.getRepositories();
}
public void addRepository(URI repository) {
- IMetadataRepositoryManager metaRepoManager = getMetadataRepositoryManager();
- IArtifactRepositoryManager artiRepoManager = getArtifactRepositoryManager();
-
- metaRepoManager.addRepository(repository);
- artiRepoManager.addRepository(repository);
+ rtpService.addRepository(repository);
}
- public URI addRepository(InputStream inputStream) throws InvalidRepositoryException, FileNotFoundException, IOException {
+ public URI addRepository(InputStream inputStream)
+ throws InvalidRepositoryException, FileNotFoundException,
+ IOException {
ZipInputStream zis = new ZipInputStream(inputStream);
File repository = createLocalRepository(zis);
URI repositoryURI = repository.toURI();
@@ -59,8 +53,11 @@ public class RepositoryManager {
return repositoryURI;
}
- private File createLocalRepository(ZipInputStream zis) throws InvalidRepositoryException, IOException, FileNotFoundException {
- File repository = new File(System.getProperty("java.io.tmpdir") + CommonConstants.DIR_SEPARATOR + LOCAL_REPOSITORY_PREFIX
+ private File createLocalRepository(ZipInputStream zis)
+ throws InvalidRepositoryException, IOException,
+ FileNotFoundException {
+ File repository = new File(System.getProperty("java.io.tmpdir")
+ + CommonConstants.DIR_SEPARATOR + LOCAL_REPOSITORY_PREFIX
+ Long.toString(System.nanoTime()));
repository.mkdirs();
createLocalRepositoryStructure(zis, repository);
@@ -76,14 +73,11 @@ public class RepositoryManager {
}
public void removeRepository(URI repository) {
- IMetadataRepositoryManager metaRepoManager = getMetadataRepositoryManager();
- IArtifactRepositoryManager artiRepoManager = getArtifactRepositoryManager();
-
- metaRepoManager.removeRepository(repository);
- artiRepoManager.removeRepository(repository);
+ rtpService.removeRepository(repository);
}
- private void createLocalRepositoryStructure(ZipInputStream zis, File repository) throws IOException, FileNotFoundException {
+ private void createLocalRepositoryStructure(ZipInputStream zis,
+ File repository) throws IOException, FileNotFoundException {
ZipEntry currentFile;
while ((currentFile = zis.getNextEntry()) != null) {
if (currentFile.isDirectory()) {
@@ -95,13 +89,15 @@ public class RepositoryManager {
}
private void createLocalDirectory(File repository, ZipEntry currentFile) {
- File file = new File(repository.getAbsolutePath() + CommonConstants.DIR_SEPARATOR + currentFile.getName());
+ File file = new File(repository.getAbsolutePath()
+ + CommonConstants.DIR_SEPARATOR + currentFile.getName());
file.mkdirs();
}
- private void createLocalFile(ZipInputStream zis, File repository, ZipEntry currentFile) throws IOException,
- FileNotFoundException {
- File file = new File(repository.getAbsolutePath() + CommonConstants.DIR_SEPARATOR + currentFile.getName());
+ private void createLocalFile(ZipInputStream zis, File repository,
+ ZipEntry currentFile) throws IOException, FileNotFoundException {
+ File file = new File(repository.getAbsolutePath()
+ + CommonConstants.DIR_SEPARATOR + currentFile.getName());
file.getParentFile().mkdirs();
file.createNewFile();
FileOutputStream fos = new FileOutputStream(file);
@@ -109,7 +105,8 @@ public class RepositoryManager {
saveFileData(zis, bfos);
}
- private void saveFileData(ZipInputStream zis, BufferedOutputStream bfos) throws IOException {
+ private void saveFileData(ZipInputStream zis, BufferedOutputStream bfos)
+ throws IOException {
int resultLength;
byte[] data = new byte[FILE_BUFFER];
while ((resultLength = zis.read(data, 0, FILE_BUFFER)) != -1) {
@@ -119,7 +116,8 @@ public class RepositoryManager {
bfos.close();
}
- public void validateLocalRepository(File repository) throws InvalidRepositoryException {
+ public void validateLocalRepository(File repository)
+ throws InvalidRepositoryException {
File[] files = repository.listFiles();
boolean artifactsFound = false;
boolean contentFound = false;
@@ -133,24 +131,11 @@ public class RepositoryManager {
}
if (!artifactsFound || !contentFound) {
- throw new InvalidRepositoryException("invalid repository: required files not found");
+ throw new InvalidRepositoryException(
+ "invalid repository: required files not found");
}
}
- public IMetadataRepositoryManager getMetadataRepositoryManager() {
- IMetadataRepositoryManager service = (IMetadataRepositoryManager) provisioningAgent
- .getService(IMetadataRepositoryManager.SERVICE_NAME);
-
- return service;
- }
-
- public IArtifactRepositoryManager getArtifactRepositoryManager() {
- IArtifactRepositoryManager service = (IArtifactRepositoryManager) provisioningAgent
- .getService(IArtifactRepositoryManager.SERVICE_NAME);
-
- return service;
- }
-
public void removeLocalRepository(URI repository) throws IOException {
FileUtils.deleteDirectory(new File(repository));
removeRepository(repository);
diff --git a/tests/org.eclipse.rtp.tests.httpdeployer/src/org/eclipse/rtp/httpdeployer/feature/FeatureManagerTest.java b/tests/org.eclipse.rtp.tests.httpdeployer/src/org/eclipse/rtp/httpdeployer/feature/FeatureManagerTest.java
index c415918..5bd04df 100644
--- a/tests/org.eclipse.rtp.tests.httpdeployer/src/org/eclipse/rtp/httpdeployer/feature/FeatureManagerTest.java
+++ b/tests/org.eclipse.rtp.tests.httpdeployer/src/org/eclipse/rtp/httpdeployer/feature/FeatureManagerTest.java
@@ -8,59 +8,20 @@
******************************************************************************/
package org.eclipse.rtp.httpdeployer.feature;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-import java.net.URI;
-
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.SubMonitor;
-import org.eclipse.equinox.internal.provisional.configurator.Configurator;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
-import org.eclipse.equinox.p2.engine.IProfile;
-import org.eclipse.equinox.p2.engine.IProfileRegistry;
-import org.eclipse.equinox.p2.engine.IProvisioningPlan;
-import org.eclipse.equinox.p2.engine.ProvisioningContext;
import org.eclipse.equinox.p2.planner.IPlanner;
-import org.eclipse.equinox.p2.planner.IProfileChangeRequest;
-import org.eclipse.equinox.p2.repository.IRepositoryManager;
-import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.rtp.httpdeployer.repository.RepositoryManager;
import org.junit.Before;
-import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-@SuppressWarnings("restriction")
public class FeatureManagerTest {
@Mock
- IProvisioningAgent provisioningAgent;
-
- @Mock
RepositoryManager repositoryManager;
@Mock
- Configurator configurator;
-
- @Mock
- IMetadataRepositoryManager metadataRepositoryMock;
-
- @Mock
- IProfileRegistry profileRegistry;
-
- @Mock
- IProfile profile;
-
- @Mock
IPlanner planner;
- @Mock
- IProvisioningPlan provisioningPlan;
-
FeatureManager objectUnderTest;
static final String FEATURE_NAME = "testFeature";
@@ -69,44 +30,5 @@ public class FeatureManagerTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- this.objectUnderTest = new FeatureManager(provisioningAgent, repositoryManager, configurator);
- when(repositoryManager.getRepositories()).thenReturn(null);
- when(provisioningAgent.getService(IMetadataRepositoryManager.SERVICE_NAME)).thenReturn(metadataRepositoryMock);
- when(metadataRepositoryMock.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL)).thenReturn(new URI[] {});
- when(provisioningAgent.getService(IProfileRegistry.SERVICE_NAME)).thenReturn(profileRegistry);
- when(profileRegistry.getProfile(IProfileRegistry.SELF)).thenReturn(profile);
- when(provisioningAgent.getService(IPlanner.SERVICE_NAME)).thenReturn(planner);
- }
-
- @Test
- public void testInstallUnknownFeature() throws FeatureInstallException {
- when(provisioningPlan.getStatus()).thenReturn(new Status(Status.ERROR, FEATURE_NAME, "some error message"));
- when(planner.getProvisioningPlan(any(IProfileChangeRequest.class), any(ProvisioningContext.class), any(SubMonitor.class)))
- .thenReturn(provisioningPlan);
-
- try {
- this.objectUnderTest.installFeature(FEATURE_NAME, FEATURE_VERSION);
- fail();
- } catch (FeatureInstallException e) {
- assertEquals("Cannot complete the request. See the error log for details.\n", e.getMessage());
- }
-
- verifyZeroInteractions(configurator);
- }
-
- @Test
- public void testUninstallUnknownFeature() throws FeatureInstallException {
- when(provisioningPlan.getStatus()).thenReturn(new Status(Status.ERROR, FEATURE_NAME, "some error message"));
- when(planner.getProvisioningPlan(any(IProfileChangeRequest.class), any(ProvisioningContext.class), any(SubMonitor.class)))
- .thenReturn(provisioningPlan);
-
- try {
- this.objectUnderTest.uninstallFeature(FEATURE_NAME, FEATURE_VERSION);
- fail();
- } catch (FeatureInstallException e) {
- assertEquals("Cannot complete the request. See the error log for details.\n", e.getMessage());
- }
-
- verifyZeroInteractions(configurator);
}
}
diff --git a/tests/org.eclipse.rtp.tests.httpdeployer/src/org/eclipse/rtp/httpdeployer/internal/HttpDeployerComponentTest.java b/tests/org.eclipse.rtp.tests.httpdeployer/src/org/eclipse/rtp/httpdeployer/internal/HttpDeployerComponentTest.java
index d4ec5a8..95a970a 100644
--- a/tests/org.eclipse.rtp.tests.httpdeployer/src/org/eclipse/rtp/httpdeployer/internal/HttpDeployerComponentTest.java
+++ b/tests/org.eclipse.rtp.tests.httpdeployer/src/org/eclipse/rtp/httpdeployer/internal/HttpDeployerComponentTest.java
@@ -18,8 +18,7 @@ import java.util.Dictionary;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
-import org.eclipse.equinox.internal.provisional.configurator.Configurator;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
+import org.eclipse.rtp.core.IRTPService;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
@@ -28,17 +27,13 @@ import org.osgi.service.http.HttpContext;
import org.osgi.service.http.HttpService;
import org.osgi.service.http.NamespaceException;
-@SuppressWarnings("restriction")
public class HttpDeployerComponentTest {
@Mock
- IProvisioningAgent agent;
-
- @Mock
HttpService service;
@Mock
- Configurator configurator;
+ IRTPService rtpService;
@Before
public void setUp() {
@@ -49,8 +44,7 @@ public class HttpDeployerComponentTest {
public void deployerComponentTest() throws ServletException, NamespaceException {
HttpDeployerComponent component = new HttpDeployerComponent();
component.setHttpService(service);
- component.setProvisioningAgent(agent);
- component.setConfigurator(configurator);
+ component.setRtpService(rtpService);
component.startService();
verify(service).registerServlet(eq(HttpDeployerInitializer.ALIAS_REPOSITORY), any(Servlet.class), any(Dictionary.class),
@@ -61,7 +55,6 @@ public class HttpDeployerComponentTest {
any(HttpContext.class));
verify(service).registerServlet(eq(HttpDeployerInitializer.ALIAS_SYSTEM), any(Servlet.class), any(Dictionary.class),
any(HttpContext.class));
- assertEquals(configurator, component.configurator);
component.shutdownService();
verify(service).unregister(HttpDeployerInitializer.ALIAS_BUNDLE);
@@ -70,11 +63,9 @@ public class HttpDeployerComponentTest {
verify(service).unregister(HttpDeployerInitializer.ALIAS_SYSTEM);
component.unsetHttpService(service);
- component.unsetProvisioningAgent(agent);
- component.unsetConfigurator(configurator);
+ component.unsetRtpService(rtpService);
- assertEquals(null, component.configurator);
assertEquals(null, component.httpService);
- assertEquals(null, component.provisioningAgent);
+ assertEquals(null, component.rtpService);
}
}
diff --git a/tests/org.eclipse.rtp.tests.httpdeployer/src/org/eclipse/rtp/httpdeployer/repository/RepositoryManagerTest.java b/tests/org.eclipse.rtp.tests.httpdeployer/src/org/eclipse/rtp/httpdeployer/repository/RepositoryManagerTest.java
index b5f2ede..2396d08 100644
--- a/tests/org.eclipse.rtp.tests.httpdeployer/src/org/eclipse/rtp/httpdeployer/repository/RepositoryManagerTest.java
+++ b/tests/org.eclipse.rtp.tests.httpdeployer/src/org/eclipse/rtp/httpdeployer/repository/RepositoryManagerTest.java
@@ -11,7 +11,6 @@ package org.eclipse.rtp.httpdeployer.repository;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -23,9 +22,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import org.apache.commons.io.FileUtils;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
-import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
-import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
+import org.eclipse.rtp.core.IRTPService;
import org.eclipse.rtp.httpdeployer.internal.CommonConstants;
import org.junit.Before;
import org.junit.Test;
@@ -35,87 +32,75 @@ import org.mockito.MockitoAnnotations;
public class RepositoryManagerTest {
@Mock
- private IProvisioningAgent paMock;
- @Mock
- private IMetadataRepositoryManager mrmMock;
- @Mock
- private IArtifactRepositoryManager armMock;
+ private IRTPService rtpMock;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
-
- when(paMock.getService(IMetadataRepositoryManager.SERVICE_NAME)).thenReturn(mrmMock);
- when(paMock.getService(IArtifactRepositoryManager.SERVICE_NAME)).thenReturn(armMock);
}
@Test
public void addRemoteRepositoryTest() throws URISyntaxException {
- RepositoryManager manager = new RepositoryManager(paMock);
+ RepositoryManager manager = new RepositoryManager(rtpMock);
URI repository = new URI("file:/tmp");
manager.addRepository(repository);
- verify(mrmMock).addRepository(repository);
- verify(armMock).addRepository(repository);
+ verify(rtpMock).addRepository(repository);
}
@Test
public void removeRemoteRepositoryTest() throws URISyntaxException {
- RepositoryManager manager = new RepositoryManager(paMock);
+ RepositoryManager manager = new RepositoryManager(rtpMock);
URI repository = new URI("file:/tmp");
manager.removeRepository(repository);
- verify(mrmMock).removeRepository(repository);
- verify(armMock).removeRepository(repository);
+ verify(rtpMock).removeRepository(repository);
}
@Test
public void getAllRepositoriesTest() {
- RepositoryManager manager = new RepositoryManager(paMock);
+ RepositoryManager manager = new RepositoryManager(rtpMock);
manager.getRepositories();
- verify(mrmMock).getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL);
+ verify(rtpMock).getRepositories();
}
@Test(expected = InvalidRepositoryException.class)
public void addEmptyLocalRepositoryTest() throws InvalidRepositoryException, FileNotFoundException, IOException {
- RepositoryManager manager = new RepositoryManager(paMock);
+ RepositoryManager manager = new RepositoryManager(rtpMock);
InputStream stream = new ByteArrayInputStream(new byte[1]);
manager.addRepository(stream);
}
@Test(expected = InvalidRepositoryException.class)
public void addInvalidLocalRepositoryTest() throws InvalidRepositoryException, IOException {
- RepositoryManager manager = new RepositoryManager(paMock);
+ RepositoryManager manager = new RepositoryManager(rtpMock);
InputStream stream = new FileInputStream("fixtures/invalidRepositoryPackage.zip");
manager.addRepository(stream);
}
@Test
public void addValidLocalRepository() throws InvalidRepositoryException, IOException {
- RepositoryManager manager = new RepositoryManager(paMock);
+ RepositoryManager manager = new RepositoryManager(rtpMock);
InputStream stream = new FileInputStream("fixtures/validRepositoryPackage.zip");
URI uri = manager.addRepository(stream);
assertNotNull(uri);
- verify(mrmMock).addRepository(uri);
- verify(armMock).addRepository(uri);
+ verify(rtpMock).addRepository(uri);
FileUtils.deleteDirectory(new File(uri));
}
@Test
public void removeLocalRepositoryTest() throws URISyntaxException, IOException {
- RepositoryManager manager = new RepositoryManager(paMock);
+ RepositoryManager manager = new RepositoryManager(rtpMock);
File repository = new File(System.getProperty("java.io.tmpdir") + CommonConstants.DIR_SEPARATOR + "repo_"
+ Long.toString(System.nanoTime()));
repository.mkdirs();
URI repo = repository.toURI();
manager.removeLocalRepository(repo);
-
+
assertFalse(repository.exists());
- verify(mrmMock).removeRepository(repo);
- verify(armMock).removeRepository(repo);
+ verify(rtpMock).removeRepository(repo);
}
-
}