aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbveliev2011-09-28 03:26:38 (EDT)
committerbveliev2011-09-28 03:26:38 (EDT)
commit588e8ba655686cc2c5b8f7d5ef4759a3930500df (patch)
tree0b0858ededba1d72dab4db34cba1250bd74e5b59
parent00b392d7c9ef1e26492c6383a7a7c4cd88b523e4 (diff)
downloadorg.eclipse.rtp-588e8ba655686cc2c5b8f7d5ef4759a3930500df.zip
org.eclipse.rtp-588e8ba655686cc2c5b8f7d5ef4759a3930500df.tar.gz
org.eclipse.rtp-588e8ba655686cc2c5b8f7d5ef4759a3930500df.tar.bz2
358493: [Configurator] Implement default configurator service
https://bugs.eclipse.org/bugs/show_bug.cgi?id=358493
-rw-r--r--configurator.test/org.eclipse.rtp.configurator.model.test/data/example-sources.json3
-rw-r--r--configurator.test/org.eclipse.rtp.configurator.model.test/src/org/eclipse/rtp/configurator/model/SourceUnMarshallerTest.java3
-rw-r--r--configurator.test/org.eclipse.rtp.configurator.model.test/src/org/eclipse/rtp/configurator/model/SourceVersionTest.java4
-rw-r--r--configurator.test/org.eclipse.rtp.configurator.model.test/src/org/eclipse/rtp/configurator/model/example-sources.json30
-rw-r--r--configurator/org.eclipse.rtp.configurator.console/RT Configurator Console (1).launch25
-rw-r--r--configurator/org.eclipse.rtp.configurator.model/src/org/eclipse/rtp/configurator/model/SourceVersion.java8
-rw-r--r--core.test/org.eclipse.rtp.core.service.provider.test/META-INF/MANIFEST.MF3
-rw-r--r--core.test/org.eclipse.rtp.core.service.provider.test/fixtures/invalidRepositoryPackage.zipbin0 -> 316 bytes
-rw-r--r--core.test/org.eclipse.rtp.core.service.provider.test/fixtures/validRepositoryPackage.zipbin0 -> 3227 bytes
-rw-r--r--core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceInstallCommandTest.java164
-rw-r--r--core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceListCommandTest.java164
-rw-r--r--core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceSearchTest.java75
-rw-r--r--core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceTest.java111
-rw-r--r--core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/FeatureManagerTest.java114
-rw-r--r--core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/RepositoryManagerTest.java115
-rw-r--r--core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/util/Fixture.java32
-rw-r--r--core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/DefaultConfiguratorService.java151
-rw-r--r--core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/FeatureManager.java254
-rw-r--r--core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/ConfiguratorModelUtil.java18
-rw-r--r--core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/P2Util.java7
-rw-r--r--packages/org.eclipse.rtp.package.web.feature/rootfiles/Start EclipseRT Web Starter Kit.launch56
21 files changed, 757 insertions, 580 deletions
diff --git a/configurator.test/org.eclipse.rtp.configurator.model.test/data/example-sources.json b/configurator.test/org.eclipse.rtp.configurator.model.test/data/example-sources.json
index c6ec22f..a761680 100644
--- a/configurator.test/org.eclipse.rtp.configurator.model.test/data/example-sources.json
+++ b/configurator.test/org.eclipse.rtp.configurator.model.test/data/example-sources.json
@@ -6,10 +6,12 @@
"infoUrl": "http://foo.bar/info",
"versions": [
{
+ "id": "org.eclipse.rap.feature.group",
"version": "1.4",
"repositoryUrl": "http://foo.bar"
},
{
+ "id": "org.eclipse.rap.feature.group",
"version": "1.5",
"repositoryUrl": "http://foo.bar2"
}
@@ -21,6 +23,7 @@
"infoUrl": "http://foo.bar/info3",
"versions": [
{
+ "id": "org.eclipse.equinox.feature.group",
"version": "3.8.1",
"repositoryUrl": "http://foo.bar3"
}
diff --git a/configurator.test/org.eclipse.rtp.configurator.model.test/src/org/eclipse/rtp/configurator/model/SourceUnMarshallerTest.java b/configurator.test/org.eclipse.rtp.configurator.model.test/src/org/eclipse/rtp/configurator/model/SourceUnMarshallerTest.java
index 44b60b8..5e6edd1 100644
--- a/configurator.test/org.eclipse.rtp.configurator.model.test/src/org/eclipse/rtp/configurator/model/SourceUnMarshallerTest.java
+++ b/configurator.test/org.eclipse.rtp.configurator.model.test/src/org/eclipse/rtp/configurator/model/SourceUnMarshallerTest.java
@@ -49,12 +49,14 @@ public class SourceUnMarshallerTest {
private void checkFirstRapVersion( Source source ) {
SourceVersion source1 = source.getVersions().get( 0 );
+ assertEquals( "org.eclipse.rap.feature.group", source1.getId() );
assertEquals( "1.4", source1.getVersion() );
assertEquals( "http://foo.bar", source1.getRepositoryUrl() );
}
private void checkSecondRapVersion( Source source ) {
SourceVersion source2 = source.getVersions().get( 1 );
+ assertEquals( "org.eclipse.rap.feature.group", source2.getId() );
assertEquals( "1.5", source2.getVersion() );
assertEquals( "http://foo.bar2", source2.getRepositoryUrl() );
}
@@ -69,6 +71,7 @@ public class SourceUnMarshallerTest {
private void checkEquinoxVersion( Source source ) {
SourceVersion source1 = source.getVersions().get( 0 );
+ assertEquals( "org.eclipse.equinox.feature.group", source1.getId() );
assertEquals( "3.8.1", source1.getVersion() );
assertEquals( "http://foo.bar3", source1.getRepositoryUrl() );
}
diff --git a/configurator.test/org.eclipse.rtp.configurator.model.test/src/org/eclipse/rtp/configurator/model/SourceVersionTest.java b/configurator.test/org.eclipse.rtp.configurator.model.test/src/org/eclipse/rtp/configurator/model/SourceVersionTest.java
index 400af85..8272b78 100644
--- a/configurator.test/org.eclipse.rtp.configurator.model.test/src/org/eclipse/rtp/configurator/model/SourceVersionTest.java
+++ b/configurator.test/org.eclipse.rtp.configurator.model.test/src/org/eclipse/rtp/configurator/model/SourceVersionTest.java
@@ -18,11 +18,13 @@ public class SourceVersionTest {
@Test
public void testGetValues() {
- SourceVersion version = new SourceVersion( "1.4",
+ SourceVersion version = new SourceVersion( "org.eclipse.rap.feature.group",
+ "1.4",
"http://foo.bar",
"description",
"http://info.bar" );
+ assertEquals( "org.eclipse.rap.feature.group", version.getId() );
assertEquals( "1.4", version.getVersion() );
assertEquals( "http://foo.bar", version.getRepositoryUrl() );
}
diff --git a/configurator.test/org.eclipse.rtp.configurator.model.test/src/org/eclipse/rtp/configurator/model/example-sources.json b/configurator.test/org.eclipse.rtp.configurator.model.test/src/org/eclipse/rtp/configurator/model/example-sources.json
deleted file mode 100644
index c6ec22f..0000000
--- a/configurator.test/org.eclipse.rtp.configurator.model.test/src/org/eclipse/rtp/configurator/model/example-sources.json
+++ /dev/null
@@ -1,30 +0,0 @@
-{
- "sources": [
- {
- "name": "rap",
- "description": "Some text",
- "infoUrl": "http://foo.bar/info",
- "versions": [
- {
- "version": "1.4",
- "repositoryUrl": "http://foo.bar"
- },
- {
- "version": "1.5",
- "repositoryUrl": "http://foo.bar2"
- }
- ]
- },
- {
- "name": "equinox",
- "description": "Some text3",
- "infoUrl": "http://foo.bar/info3",
- "versions": [
- {
- "version": "3.8.1",
- "repositoryUrl": "http://foo.bar3"
- }
- ]
- }
- ]
-} \ No newline at end of file
diff --git a/configurator/org.eclipse.rtp.configurator.console/RT Configurator Console (1).launch b/configurator/org.eclipse.rtp.configurator.console/RT Configurator Console (1).launch
new file mode 100644
index 0000000..e7c59b6
--- /dev/null
+++ b/configurator/org.eclipse.rtp.configurator.console/RT Configurator Console (1).launch
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.pde.ui.EquinoxLauncher">
+<booleanAttribute key="append.args" value="true"/>
+<booleanAttribute key="automaticAdd" value="true"/>
+<booleanAttribute key="automaticValidate" value="false"/>
+<stringAttribute key="bootstrap" value=""/>
+<stringAttribute key="checked" value="[NONE]"/>
+<booleanAttribute key="clearConfig" value="false"/>
+<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/RTP Console"/>
+<booleanAttribute key="default" value="true"/>
+<booleanAttribute key="default_auto_start" value="true"/>
+<intAttribute key="default_start_level" value="4"/>
+<stringAttribute key="deselected_workspace_plugins" value="org.eclipse.rtp.configurator.test"/>
+<booleanAttribute key="includeOptional" value="true"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog -console"/>
+<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Declipse.ignoreApp=true -Dosgi.noShutdown=true"/>
+<stringAttribute key="pde.version" value="3.3"/>
+<booleanAttribute key="show_selected_only" value="false"/>
+<stringAttribute key="target_bundles" value="org.eclipse.equinox.ds@default:true,org.eclipse.equinox.util@default:default,org.eclipse.osgi.services@default:default,org.eclipse.osgi@-1:true"/>
+<booleanAttribute key="tracing" value="false"/>
+<booleanAttribute key="useCustomFeatures" value="false"/>
+<booleanAttribute key="useDefaultConfigArea" value="true"/>
+<stringAttribute key="workspace_bundles" value="org.eclipes.rtp.core@default:default,org.eclipse.rtp.configurator.console@default:default,org.eclipse.rtp.configurator.model.test@default:false,org.eclipse.rtp.configurator.model@default:default,org.eclipse.rtp.core.service.provider.test@default:false,org.eclipse.rtp.core.service.provider@default:default,org.eclipse.rtp.core.test@default:default"/>
+</launchConfiguration>
diff --git a/configurator/org.eclipse.rtp.configurator.model/src/org/eclipse/rtp/configurator/model/SourceVersion.java b/configurator/org.eclipse.rtp.configurator.model/src/org/eclipse/rtp/configurator/model/SourceVersion.java
index 389b02f..b22e37f 100644
--- a/configurator/org.eclipse.rtp.configurator.model/src/org/eclipse/rtp/configurator/model/SourceVersion.java
+++ b/configurator/org.eclipse.rtp.configurator.model/src/org/eclipse/rtp/configurator/model/SourceVersion.java
@@ -14,12 +14,14 @@ public class SourceVersion {
private String version;
private String repositoryUrl;
+ private String id;
SourceVersion() {
// only for Gson
}
- public SourceVersion( String version, String repositoryUrl, String description, String infoUrl ) {
+ public SourceVersion( String id, String version, String repositoryUrl, String description, String infoUrl ) {
+ this.id = id;
this.version = version;
this.repositoryUrl = repositoryUrl;
}
@@ -32,6 +34,10 @@ public class SourceVersion {
return repositoryUrl;
}
+ public String getId(){
+ return id;
+ }
+
@Override
public String toString() {
StringBuilder result = new StringBuilder();
diff --git a/core.test/org.eclipse.rtp.core.service.provider.test/META-INF/MANIFEST.MF b/core.test/org.eclipse.rtp.core.service.provider.test/META-INF/MANIFEST.MF
index 87ee934..c623185 100644
--- a/core.test/org.eclipse.rtp.core.service.provider.test/META-INF/MANIFEST.MF
+++ b/core.test/org.eclipse.rtp.core.service.provider.test/META-INF/MANIFEST.MF
@@ -6,4 +6,5 @@ Bundle-Version: 1.0.0.qualifier
Fragment-Host: org.eclipse.rtp.core.service.provider;bundle-version="1.0.0.qualifier"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.junit;bundle-version="[4.8.2,4.9.0)",
- org.mockito;bundle-version="[1.8.0,1.9.0)"
+ org.mockito;bundle-version="[1.8.0,1.9.0)",
+ org.eclipse.equinox.p2.director;bundle-version="2.1.0"
diff --git a/core.test/org.eclipse.rtp.core.service.provider.test/fixtures/invalidRepositoryPackage.zip b/core.test/org.eclipse.rtp.core.service.provider.test/fixtures/invalidRepositoryPackage.zip
new file mode 100644
index 0000000..22710ce
--- /dev/null
+++ b/core.test/org.eclipse.rtp.core.service.provider.test/fixtures/invalidRepositoryPackage.zip
Binary files differ
diff --git a/core.test/org.eclipse.rtp.core.service.provider.test/fixtures/validRepositoryPackage.zip b/core.test/org.eclipse.rtp.core.service.provider.test/fixtures/validRepositoryPackage.zip
new file mode 100644
index 0000000..e7d961d
--- /dev/null
+++ b/core.test/org.eclipse.rtp.core.service.provider.test/fixtures/validRepositoryPackage.zip
Binary files differ
diff --git a/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceInstallCommandTest.java b/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceInstallCommandTest.java
deleted file mode 100644
index 8ded208..0000000
--- a/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceInstallCommandTest.java
+++ /dev/null
@@ -1,164 +0,0 @@
-package org.eclipse.rtp.configurator.service.provider.internal;
-/*******************************************************************************
-* Copyright (c) 2011 EclipseSource and others. All rights reserved. This
-* program and the accompanying materials are 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:
-* EclipseSource - initial API and implementation
-*******************************************************************************/
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.net.URI;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
-import org.eclipse.equinox.p2.core.ProvisionException;
-import org.eclipse.equinox.p2.metadata.IInstallableUnit;
-import org.eclipse.equinox.p2.query.IQueryResult;
-import org.eclipse.equinox.p2.query.QueryUtil;
-import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
-import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
-import org.eclipse.rtp.configurator.service.provider.internal.util.P2Util;
-import org.junit.Before;
-import org.junit.Test;
-
-@SuppressWarnings("rawtypes")
-public class ConfiguratorServiceInstallCommandTest {
-
- private DefaultConfiguratorService configuratorService;
- private P2Util p2UtilMock;
-
- @Before
- public void setUp() {
- configuratorService = new DefaultConfiguratorService();
- p2UtilMock = mock(P2Util.class);
- configuratorService.setP2Util(p2UtilMock);
- }
-
- @Test
- public void testListNoRepositoryLoaded() throws CoreException {
- URI[] knownRepositories = new URI[] { };
- IMetadataRepository[] metadataRepositories = new IMetadataRepository[] { };
- IMetadataRepositoryManager metadataRepositoryManagerMock = createMetadataRepositoryManagerMock(metadataRepositories, knownRepositories);
- createAgentMock(metadataRepositoryManagerMock);
-
- List<String> list = configuratorService.list();
-
- assertTrue(list.isEmpty());
- }
-
- @Test
- public void testListFromEmptyRepository() throws CoreException {
- Iterator iteratorMock = mock(Iterator.class);
- when(iteratorMock.hasNext()).thenReturn(false);
- IQueryResult queryResultMock = createQueryResultMock(iteratorMock);
- IMetadataRepository metadataRepositoryMock = createMetadataRepositoryMock(queryResultMock);
- URI[] knownRepositories = new URI[] { URI.create("http://test.repository") };
- IMetadataRepository[] metadataRepositories = new IMetadataRepository[] { metadataRepositoryMock };
- IMetadataRepositoryManager metadataRepositoryManagerMock = createMetadataRepositoryManagerMock(metadataRepositories, knownRepositories);
- createAgentMock(metadataRepositoryManagerMock);
-
- List<String> list = configuratorService.list();
-
- assertTrue(list.isEmpty());
- }
-
- @Test
- public void testListFromOneRepository() throws CoreException {
- String expectedIuId = "org.eclipse.test.bundle";
- String expectedIuId2 = "org.eclipse.test.bundle2";
- IInstallableUnit installableUnitMock = createIuMock(expectedIuId);
- IInstallableUnit installableUnitMock2 = createIuMock(expectedIuId2);
- Iterator iteratorMock = mock(Iterator.class);
- when(iteratorMock.hasNext()).thenReturn(true, true, false);
- when(iteratorMock.next()).thenReturn(installableUnitMock, installableUnitMock2);
- IQueryResult queryResultMock = createQueryResultMock(iteratorMock);
- IMetadataRepository metadataRepositoryMock = createMetadataRepositoryMock(queryResultMock);
- URI[] knownRepositories = new URI[] { URI.create("http://test.repository") };
- IMetadataRepository[] metadataRepositories = new IMetadataRepository[] { metadataRepositoryMock };
- IMetadataRepositoryManager metadataRepositoryManagerMock = createMetadataRepositoryManagerMock(metadataRepositories, knownRepositories);
- createAgentMock(metadataRepositoryManagerMock);
-
- List<String> list = configuratorService.list();
-
- assertTrue(list.size() == 2);
- assertTrue(list.contains(expectedIuId));
- assertTrue(list.contains(expectedIuId2));
- }
-
- @Test
- public void testListFromTwoRepositories() throws CoreException {
- String expectedIuId = "org.eclipse.test.bundle";
- String expectedIuId2 = "org.eclipse.test.bundle2";
- IInstallableUnit installableUnitMock = createIuMock(expectedIuId);
- IInstallableUnit installableUnitMock2 = createIuMock(expectedIuId2);
- Iterator iteratorMock = createIteratorMoc(installableUnitMock);
- Iterator iteratorMock2 = createIteratorMoc(installableUnitMock2);
- IQueryResult queryResultMock = createQueryResultMock(iteratorMock);
- IQueryResult queryResultMock2 = createQueryResultMock(iteratorMock2);
- IMetadataRepository metadataRepositoryMock = createMetadataRepositoryMock(queryResultMock);
- IMetadataRepository metadataRepositoryMock2 = createMetadataRepositoryMock(queryResultMock2);
- URI[] knownRepositories = new URI[] { URI.create("http://test.repository"), URI.create("http://test.repository2") };
- IMetadataRepository[] metadataRepositories = new IMetadataRepository[] { metadataRepositoryMock, metadataRepositoryMock2 };
- IMetadataRepositoryManager metadataRepositoryManagerMock =
- createMetadataRepositoryManagerMock(metadataRepositories, knownRepositories);
- createAgentMock(metadataRepositoryManagerMock);
-
- List<String> list = configuratorService.list();
-
- assertTrue(list.size() == 2);
- assertTrue(list.contains(expectedIuId));
- assertTrue(list.contains(expectedIuId2));
- }
-
- private void createAgentMock(
- IMetadataRepositoryManager metadataRepositoryManagerMock)
- throws CoreException {
- IProvisioningAgent provisioningAgent = mock(IProvisioningAgent.class);
- when(provisioningAgent.getService(IMetadataRepositoryManager.class.getName())).thenReturn(metadataRepositoryManagerMock);
- }
-
- private IMetadataRepositoryManager createMetadataRepositoryManagerMock(
- IMetadataRepository[] metadataRepositories, URI[] knownRepositories)
- throws ProvisionException {
- IMetadataRepositoryManager metadataRepositoryManagerMock = mock(IMetadataRepositoryManager.class);
- when(metadataRepositoryManagerMock.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL)).thenReturn(knownRepositories);
- for (int i = 0; i < metadataRepositories.length; i++) {
- when(metadataRepositoryManagerMock.loadRepository(knownRepositories[i], null)).thenReturn(metadataRepositories[i]);
- }
- return metadataRepositoryManagerMock;
- }
-
- private IMetadataRepository createMetadataRepositoryMock(IQueryResult queryResultMock) {
- IMetadataRepository metadataRepositoryMock = mock(IMetadataRepository.class);
- when(metadataRepositoryMock.query(QueryUtil.createIUAnyQuery(), null)).thenReturn(queryResultMock);
- return metadataRepositoryMock;
- }
-
- private IQueryResult createQueryResultMock(Iterator iteratorMock) {
- IQueryResult queryResultMock = mock(IQueryResult.class);
- when(queryResultMock.iterator()).thenReturn(iteratorMock);
- return queryResultMock;
- }
-
- private Iterator createIteratorMoc(IInstallableUnit installableUnitMock) {
- Iterator iteratorMock = mock(Iterator.class);
- when(iteratorMock.hasNext()).thenReturn(true, false);
- when(iteratorMock.next()).thenReturn(installableUnitMock);
- return iteratorMock;
- }
-
- private IInstallableUnit createIuMock(String expectedIuId) {
- IInstallableUnit installableUnitMock = mock(IInstallableUnit.class);
- when(installableUnitMock.getId()).thenReturn(expectedIuId);
- return installableUnitMock;
- }
-
-}
diff --git a/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceListCommandTest.java b/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceListCommandTest.java
deleted file mode 100644
index 4e4ccd7..0000000
--- a/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceListCommandTest.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2011 EclipseSource and others. All rights reserved. This
-* program and the accompanying materials are 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:
-* EclipseSource - initial API and implementation
-*******************************************************************************/
-package org.eclipse.rtp.configurator.service.provider.internal;
-
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.net.URI;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
-import org.eclipse.equinox.p2.core.ProvisionException;
-import org.eclipse.equinox.p2.metadata.IInstallableUnit;
-import org.eclipse.equinox.p2.query.IQueryResult;
-import org.eclipse.equinox.p2.query.QueryUtil;
-import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
-import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
-import org.eclipse.rtp.configurator.service.provider.internal.util.P2Util;
-import org.junit.Before;
-import org.junit.Test;
-
-@SuppressWarnings("rawtypes")
-public class ConfiguratorServiceListCommandTest {
-
- private DefaultConfiguratorService configuratorService;
- private P2Util p2UtilMock;
-
- @Before
- public void setUp() {
- configuratorService = new DefaultConfiguratorService();
- p2UtilMock = mock(P2Util.class);
- configuratorService.setP2Util(p2UtilMock);
- }
-
- @Test
- public void testListNoRepositoryLoaded() throws CoreException {
- URI[] knownRepositories = new URI[] { };
- IMetadataRepository[] metadataRepositories = new IMetadataRepository[] { };
- IMetadataRepositoryManager metadataRepositoryManagerMock = createMetadataRepositoryManagerMock(metadataRepositories, knownRepositories);
- createAgentMock(metadataRepositoryManagerMock);
-
- List<String> list = configuratorService.list();
-
- assertTrue(list.isEmpty());
- }
-
- @Test
- public void testListFromEmptyRepository() throws CoreException {
- Iterator iteratorMock = mock(Iterator.class);
- when(iteratorMock.hasNext()).thenReturn(false);
- IQueryResult queryResultMock = createQueryResultMock(iteratorMock);
- IMetadataRepository metadataRepositoryMock = createMetadataRepositoryMock(queryResultMock);
- URI[] knownRepositories = new URI[] { URI.create("http://test.repository") };
- IMetadataRepository[] metadataRepositories = new IMetadataRepository[] { metadataRepositoryMock };
- IMetadataRepositoryManager metadataRepositoryManagerMock = createMetadataRepositoryManagerMock(metadataRepositories, knownRepositories);
- createAgentMock(metadataRepositoryManagerMock);
-
- List<String> list = configuratorService.list();
-
- assertTrue(list.isEmpty());
- }
-
- @Test
- public void testListFromOneRepository() throws CoreException {
- String expectedIuId = "org.eclipse.test.bundle";
- String expectedIuId2 = "org.eclipse.test.bundle2";
- IInstallableUnit installableUnitMock = createIuMock(expectedIuId);
- IInstallableUnit installableUnitMock2 = createIuMock(expectedIuId2);
- Iterator iteratorMock = mock(Iterator.class);
- when(iteratorMock.hasNext()).thenReturn(true, true, false);
- when(iteratorMock.next()).thenReturn(installableUnitMock, installableUnitMock2);
- IQueryResult queryResultMock = createQueryResultMock(iteratorMock);
- IMetadataRepository metadataRepositoryMock = createMetadataRepositoryMock(queryResultMock);
- URI[] knownRepositories = new URI[] { URI.create("http://test.repository") };
- IMetadataRepository[] metadataRepositories = new IMetadataRepository[] { metadataRepositoryMock };
- IMetadataRepositoryManager metadataRepositoryManagerMock = createMetadataRepositoryManagerMock(metadataRepositories, knownRepositories);
- createAgentMock(metadataRepositoryManagerMock);
-
- List<String> list = configuratorService.list();
-
- assertTrue(list.size() == 2);
- assertTrue(list.contains(expectedIuId));
- assertTrue(list.contains(expectedIuId2));
- }
-
- @Test
- public void testListFromTwoRepositories() throws CoreException {
- String expectedIuId = "org.eclipse.test.bundle";
- String expectedIuId2 = "org.eclipse.test.bundle2";
- IInstallableUnit installableUnitMock = createIuMock(expectedIuId);
- IInstallableUnit installableUnitMock2 = createIuMock(expectedIuId2);
- Iterator iteratorMock = createIteratorMoc(installableUnitMock);
- Iterator iteratorMock2 = createIteratorMoc(installableUnitMock2);
- IQueryResult queryResultMock = createQueryResultMock(iteratorMock);
- IQueryResult queryResultMock2 = createQueryResultMock(iteratorMock2);
- IMetadataRepository metadataRepositoryMock = createMetadataRepositoryMock(queryResultMock);
- IMetadataRepository metadataRepositoryMock2 = createMetadataRepositoryMock(queryResultMock2);
- URI[] knownRepositories = new URI[] { URI.create("http://test.repository"), URI.create("http://test.repository2") };
- IMetadataRepository[] metadataRepositories = new IMetadataRepository[] { metadataRepositoryMock, metadataRepositoryMock2 };
- IMetadataRepositoryManager metadataRepositoryManagerMock =
- createMetadataRepositoryManagerMock(metadataRepositories, knownRepositories);
- createAgentMock(metadataRepositoryManagerMock);
-
- List<String> list = configuratorService.list();
-
- assertTrue(list.size() == 2);
- assertTrue(list.contains(expectedIuId));
- assertTrue(list.contains(expectedIuId2));
- }
-
- private void createAgentMock(
- IMetadataRepositoryManager metadataRepositoryManagerMock)
- throws CoreException {
- IProvisioningAgent provisioningAgent = mock(IProvisioningAgent.class);
- when(provisioningAgent.getService(IMetadataRepositoryManager.class.getName())).thenReturn(metadataRepositoryManagerMock);
- }
-
- private IMetadataRepositoryManager createMetadataRepositoryManagerMock(
- IMetadataRepository[] metadataRepositories, URI[] knownRepositories)
- throws ProvisionException {
- IMetadataRepositoryManager metadataRepositoryManagerMock = mock(IMetadataRepositoryManager.class);
- when(metadataRepositoryManagerMock.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL)).thenReturn(knownRepositories);
- for (int i = 0; i < metadataRepositories.length; i++) {
- when(metadataRepositoryManagerMock.loadRepository(knownRepositories[i], null)).thenReturn(metadataRepositories[i]);
- }
- return metadataRepositoryManagerMock;
- }
-
- private IMetadataRepository createMetadataRepositoryMock(IQueryResult queryResultMock) {
- IMetadataRepository metadataRepositoryMock = mock(IMetadataRepository.class);
- when(metadataRepositoryMock.query(QueryUtil.createIUAnyQuery(), null)).thenReturn(queryResultMock);
- return metadataRepositoryMock;
- }
-
- private IQueryResult createQueryResultMock(Iterator iteratorMock) {
- IQueryResult queryResultMock = mock(IQueryResult.class);
- when(queryResultMock.iterator()).thenReturn(iteratorMock);
- return queryResultMock;
- }
-
- private Iterator createIteratorMoc(IInstallableUnit installableUnitMock) {
- Iterator iteratorMock = mock(Iterator.class);
- when(iteratorMock.hasNext()).thenReturn(true, false);
- when(iteratorMock.next()).thenReturn(installableUnitMock);
- return iteratorMock;
- }
-
- private IInstallableUnit createIuMock(String expectedIuId) {
- IInstallableUnit installableUnitMock = mock(IInstallableUnit.class);
- when(installableUnitMock.getId()).thenReturn(expectedIuId);
- return installableUnitMock;
- }
-
-}
diff --git a/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceSearchTest.java b/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceSearchTest.java
index 399f603..032a913 100644
--- a/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceSearchTest.java
+++ b/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceSearchTest.java
@@ -1,29 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2011 EclipseSource and others. All rights reserved. This program and the
+ * accompanying materials are 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: EclipseSource - initial API and
+ * implementation
+ *******************************************************************************/
package org.eclipse.rtp.configurator.service.provider.internal;
import static org.junit.Assert.assertTrue;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
import org.eclipse.rtp.configurator.model.Source;
import org.eclipse.rtp.configurator.model.SourceProvider;
-import org.eclipse.rtp.configurator.model.SourceUnMarshaller;
import org.eclipse.rtp.configurator.service.provider.internal.util.ConfiguratorModelUtil;
+import org.eclipse.rtp.configurator.service.provider.internal.util.Fixture;
import org.junit.Before;
import org.junit.Test;
-import org.osgi.framework.Bundle;
-
public class ConfiguratorServiceSearchTest {
@@ -31,58 +30,51 @@ public class ConfiguratorServiceSearchTest {
private DefaultConfiguratorService configuratorService;
@Before
- public void setUp() throws IOException{
+ public void setUp() throws IOException {
configuratorService = new DefaultConfiguratorService();
- InputStream stream = readExampleSources();
- SourceUnMarshaller marshaller = ConfiguratorModelUtil.getSourceUnMarshaller();
- provider = marshaller.marshal( stream );
+ InputStream stream = Fixture.readExampleSources();
+ provider = Fixture.getSourceProvider( stream );
ConfiguratorModelUtil.setSourceProvider( provider );
}
-
+
@Test
- public void testList() throws CoreException
- {
+ public void testList() throws CoreException {
List<String> listExpected = getSortedTestData();
-
List<String> list = configuratorService.list();
-
- assertTrue( Arrays.equals( listExpected.toArray( ), list.toArray( ) ) );
+ assertTrue( Arrays.equals( listExpected.toArray(), list.toArray() ) );
}
-
+
@Test
- public void testShow() throws CoreException
- {
+ public void testShow() throws CoreException {
List<String> listExpected = getSortedTestData();
List<String> showParameters = new ArrayList<String>();
showParameters.add( "equinox" );
-
List<String> list = configuratorService.show( showParameters );
-
- assertTrue( Arrays.equals( new String[]{ listExpected.get( 0 ) }, list.toArray( ) ) );
+ assertTrue( Arrays.equals( new String[]{
+ listExpected.get( 0 )
+ }, list.toArray() ) );
}
-
+
@Test
- public void testShowManyParameters() throws CoreException
- {
+ public void testShowManyParameters() throws CoreException {
List<String> listExpected = getSortedTestData();
List<String> showParameters = new ArrayList<String>();
showParameters.add( "equinox" );
-
List<String> list = configuratorService.show( showParameters );
-
- assertTrue( Arrays.equals( new String[]{ listExpected.get( 0 ) }, list.toArray( ) ) );
+ assertTrue( Arrays.equals( new String[]{
+ listExpected.get( 0 )
+ }, list.toArray() ) );
}
-
+
@Test
- public void testSearch() throws CoreException
- {
+ public void testSearch() throws CoreException {
List<String> listExpected = getSortedTestData();
List<String> searchParameters = new ArrayList<String>();
searchParameters.add( "ra" );
-
List<String> list = configuratorService.search( searchParameters );
-
- assertTrue( Arrays.equals( new String[]{ listExpected.get( 1 ) }, list.toArray( ) ) );
+ assertTrue( Arrays.equals( new String[]{
+ listExpected.get( 1 )
+ }, list.toArray() ) );
}
private List<String> getSortedTestData() {
@@ -93,13 +85,4 @@ public class ConfiguratorServiceSearchTest {
Collections.sort( listExpected );
return listExpected;
}
-
- private InputStream readExampleSources() throws IOException {
- Bundle bundle = Platform.getBundle( "org.eclipse.rtp.configurator.model.test" );
- URL unResolvedUrl = FileLocator.find( bundle, new Path("data/example-sources.json"), null );
- URL testDataUrl = FileLocator.resolve( unResolvedUrl );
- File testDataFile = new Path( testDataUrl.getFile() ).toFile();
- return new FileInputStream( testDataFile );
- }
-
}
diff --git a/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceTest.java b/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceTest.java
new file mode 100644
index 0000000..60b2f8f
--- /dev/null
+++ b/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceTest.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+* Copyright (c) 2011 EclipseSource and others. All rights reserved. This
+* program and the accompanying materials are 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:
+* EclipseSource - initial API and implementation
+*******************************************************************************/
+package org.eclipse.rtp.configurator.service.provider.internal;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.rtp.configurator.model.SourceProvider;
+import org.eclipse.rtp.configurator.model.SourceVersion;
+import org.eclipse.rtp.configurator.service.provider.internal.deploy.FeatureInstallException;
+import org.eclipse.rtp.configurator.service.provider.internal.deploy.FeatureManager;
+import org.eclipse.rtp.configurator.service.provider.internal.deploy.RepositoryManager;
+import org.eclipse.rtp.configurator.service.provider.internal.util.ConfiguratorModelUtil;
+import org.eclipse.rtp.configurator.service.provider.internal.util.Fixture;
+import org.eclipse.rtp.configurator.service.provider.internal.util.P2Util;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ConfiguratorServiceTest {
+
+ private DefaultConfiguratorService configuratorService;
+ private P2Util p2UtilMock;
+ private SourceProvider sourceProvider;
+ private FeatureManager featureManager;
+ private RepositoryManager repositoryManager;
+
+ @Before
+ public void setUp() throws IOException {
+ configuratorService = new DefaultConfiguratorService();
+ p2UtilMock = mock(P2Util.class);
+ configuratorService.setP2Util(p2UtilMock);
+ InputStream inputStream = Fixture.readExampleSources();
+ sourceProvider = Fixture.getSourceProvider( inputStream );
+ ConfiguratorModelUtil.setSourceProvider( sourceProvider );
+ }
+
+
+ @Test
+ public void testInstall() throws CoreException, FeatureInstallException, URISyntaxException {
+ featureManager = mock( FeatureManager.class );
+ repositoryManager = mock( RepositoryManager.class );
+ when( p2UtilMock.getFeatureManager() ).thenReturn( featureManager );
+ when( p2UtilMock.getRepositoryManager() ).thenReturn( repositoryManager );
+ SourceVersion sourceVersion = sourceProvider.getSources().get( 0 ).getVersions().get( 0 );
+ List<String> parameters = new ArrayList<String>();
+ parameters.add( "rap" );
+ parameters.add( "1.4" );
+ IStatus status = configuratorService.install( parameters );
+
+ verify( featureManager, atLeastOnce() ).installFeature( sourceVersion );
+ verify( repositoryManager, atLeastOnce() ).addRepository( new URI("http://foo.bar") );
+ assertTrue( status.isOK() );
+ }
+
+ @Test
+ public void testNothingToInstall() throws CoreException, FeatureInstallException, URISyntaxException {
+ List<String> parameters = new ArrayList<String>();
+ parameters.add( "rap" );
+ parameters.add( "1.6" );
+ IStatus status = configuratorService.install( parameters );
+
+ assertFalse( status.isOK() );
+ }
+
+ @Test
+ public void testRemove() throws CoreException, FeatureInstallException, URISyntaxException {
+ SourceVersion sourceVersion = sourceProvider.getSources().get( 0 ).getVersions().get( 0 );
+ featureManager = mock( FeatureManager.class );
+ when( p2UtilMock.getFeatureManager() ).thenReturn( featureManager );
+ when(featureManager.isInstalled( "org.eclipse.rap.feature.group", "1.4" )).thenReturn( true );
+
+ List<String> parameters = new ArrayList<String>();
+ parameters.add( "rap" );
+ IStatus status = configuratorService.remove( parameters );
+
+ verify( featureManager, atLeastOnce() ).uninstallFeature( sourceVersion );
+ assertTrue( status.isOK() );
+ }
+
+ @Test
+ public void testNothingToRemove() throws CoreException, FeatureInstallException, URISyntaxException {
+ featureManager = mock( FeatureManager.class );
+ when( p2UtilMock.getFeatureManager() ).thenReturn( featureManager );
+
+ List<String> parameters = new ArrayList<String>();
+ parameters.add( "rap" );
+ IStatus status = configuratorService.remove( parameters );
+
+ assertTrue( status.isOK() );
+ }
+}
diff --git a/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/FeatureManagerTest.java b/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/FeatureManagerTest.java
new file mode 100644
index 0000000..c017640
--- /dev/null
+++ b/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/FeatureManagerTest.java
@@ -0,0 +1,114 @@
+/*******************************************************************************
+ * Copyright (c) 2011 EclipseSource and others. All rights reserved. This program and the
+ * accompanying materials are 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: EclipseSource - initial API and
+ * implementation
+ *******************************************************************************/
+package org.eclipse.rtp.configurator.service.provider.internal.deploy;
+
+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.configurator.model.SourceVersion;
+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";
+ static final String FEATURE_VERSION = "1.0.0";
+
+ @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( new SourceVersion( 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( new SourceVersion( 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/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/RepositoryManagerTest.java b/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/RepositoryManagerTest.java
new file mode 100644
index 0000000..5aeae3b
--- /dev/null
+++ b/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/RepositoryManagerTest.java
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ * Copyright (c) 2011 EclipseSource and others. All rights reserved. This program and the
+ * accompanying materials are 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: EclipseSource - initial API and
+ * implementation
+ *******************************************************************************/
+package org.eclipse.rtp.configurator.service.provider.internal.deploy;
+
+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;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+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.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public class RepositoryManagerTest {
+
+ @Mock
+ private IProvisioningAgent paMock;
+ @Mock
+ private IMetadataRepositoryManager mrmMock;
+ @Mock
+ private IArtifactRepositoryManager armMock;
+
+ @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 );
+ URI repository = new URI( "file:/tmp" );
+ manager.addRepository( repository );
+ verify( mrmMock ).addRepository( repository );
+ verify( armMock ).addRepository( repository );
+ }
+
+ @Test
+ public void removeRemoteRepositoryTest() throws URISyntaxException {
+ RepositoryManager manager = new RepositoryManager( paMock );
+ URI repository = new URI( "file:/tmp" );
+ manager.removeRepository( repository );
+ verify( mrmMock ).removeRepository( repository );
+ verify( armMock ).removeRepository( repository );
+ }
+
+ @Test
+ public void getAllRepositoriesTest() {
+ RepositoryManager manager = new RepositoryManager( paMock );
+ manager.getRepositories();
+ verify( mrmMock ).getKnownRepositories( IMetadataRepositoryManager.REPOSITORIES_ALL );
+ }
+
+ @Test( expected = InvalidRepositoryException.class )
+ public void addEmptyLocalRepositoryTest()
+ throws InvalidRepositoryException, FileNotFoundException, IOException
+ {
+ RepositoryManager manager = new RepositoryManager( paMock );
+ 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 );
+ InputStream stream = new FileInputStream( "fixtures/invalidRepositoryPackage.zip" );
+ manager.addRepository( stream );
+ }
+
+ @Test
+ public void addValidLocalRepository() throws InvalidRepositoryException, IOException {
+ RepositoryManager manager = new RepositoryManager( paMock );
+ InputStream stream = new FileInputStream( "fixtures/validRepositoryPackage.zip" );
+ URI uri = manager.addRepository( stream );
+ assertNotNull( uri );
+ verify( mrmMock ).addRepository( uri );
+ verify( armMock ).addRepository( uri );
+ FileUtils.deleteDirectory( new File( uri ) );
+ }
+
+ @Test
+ public void removeLocalRepositoryTest() throws URISyntaxException, IOException {
+ RepositoryManager manager = new RepositoryManager( paMock );
+ File repository = new File( System.getProperty( "java.io.tmpdir" )
+ + File.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 );
+ }
+}
diff --git a/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/util/Fixture.java b/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/util/Fixture.java
new file mode 100644
index 0000000..558a87c
--- /dev/null
+++ b/core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/util/Fixture.java
@@ -0,0 +1,32 @@
+package org.eclipse.rtp.configurator.service.provider.internal.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.rtp.configurator.model.SourceProvider;
+import org.eclipse.rtp.configurator.model.SourceUnMarshaller;
+import org.osgi.framework.Bundle;
+
+
+public class Fixture {
+
+ public static InputStream readExampleSources() throws IOException {
+ Bundle bundle = Platform.getBundle( "org.eclipse.rtp.configurator.model.test" );
+ URL unResolvedUrl = FileLocator.find( bundle, new Path("data/example-sources.json"), null );
+ URL testDataUrl = FileLocator.resolve( unResolvedUrl );
+ File testDataFile = new Path( testDataUrl.getFile() ).toFile();
+ return new FileInputStream( testDataFile );
+ }
+
+ public static SourceProvider getSourceProvider(InputStream inputStream){
+ SourceUnMarshaller marshaller = ConfiguratorModelUtil.getSourceUnMarshaller();
+ return marshaller.marshal( inputStream );
+ }
+
+}
diff --git a/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/DefaultConfiguratorService.java b/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/DefaultConfiguratorService.java
index 4fdb8da..ff2254e 100644
--- a/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/DefaultConfiguratorService.java
+++ b/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/DefaultConfiguratorService.java
@@ -7,15 +7,23 @@
*******************************************************************************/
package org.eclipse.rtp.configurator.service.provider.internal;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Status;
import org.eclipse.rtp.configurator.core.IConfiguratorService;
import org.eclipse.rtp.configurator.model.Source;
import org.eclipse.rtp.configurator.model.SourceProvider;
+import org.eclipse.rtp.configurator.model.SourceVersion;
+import org.eclipse.rtp.configurator.service.provider.internal.deploy.FeatureInstallException;
+import org.eclipse.rtp.configurator.service.provider.internal.deploy.FeatureManager;
+import org.eclipse.rtp.configurator.service.provider.internal.deploy.RepositoryManager;
import org.eclipse.rtp.configurator.service.provider.internal.util.ConfiguratorModelUtil;
import org.eclipse.rtp.configurator.service.provider.internal.util.P2Util;
@@ -37,8 +45,57 @@ public class DefaultConfiguratorService implements IConfiguratorService {
@Override
public IStatus install( List<String> parameter ) {
- // TODO Auto-generated method stub
- return null;
+ IStatus result = null;
+ try {
+ SourceVersion sourceVersion = getSourceVersions( parameter );
+ if(sourceVersion != null){
+ loadRepository( sourceVersion );
+ install( sourceVersion );
+ result = Status.OK_STATUS;
+ }else{
+ System.out.println("No source found to install");
+ result = Status.CANCEL_STATUS;
+ }
+ } catch( Exception e ) {
+ System.out.println( "Feature will not be installed. Failed to load repository" );
+ result = new Status( IStatus.ERROR,
+ ProviderActivator.BUNDLE_ID,
+ "Failed to isntall features",
+ e );
+ }
+ return result;
+ }
+
+ private SourceVersion getSourceVersions( List<String> parameter ) {
+ List<Source> sources = ConfiguratorModelUtil.getSourceProvider().getSources();
+ List<String> sourceName = new ArrayList<String>();
+ sourceName.add( parameter.get( 0 ) );
+ List<Source> searchSources = searchSources( sourceName, sources );
+ SourceVersion sourceVersion = searchSourceVerions( parameter.get( 1 ), searchSources );
+ return sourceVersion;
+ }
+
+ private void install( SourceVersion sourceVersion ) throws FeatureInstallException {
+ FeatureManager featureManager = p2Util.getFeatureManager();
+ featureManager.installFeature( sourceVersion );
+ }
+
+ private void loadRepository( SourceVersion sourceVersion ) throws URISyntaxException {
+ RepositoryManager repositoryManager = p2Util.getRepositoryManager();
+ repositoryManager.addRepository( new URI( sourceVersion.getRepositoryUrl() ) );
+ }
+
+ private SourceVersion searchSourceVerions( String sourceVersion, List<Source> sources ) {
+ SourceVersion result = null;
+ for( Source source : sources ) {
+ List<SourceVersion> versions = source.getVersions();
+ for( SourceVersion version : versions ) {
+ if( version.getVersion().equals( sourceVersion ) ) {
+ result = version;
+ }
+ }
+ }
+ return result;
}
@Override
@@ -49,48 +106,94 @@ public class DefaultConfiguratorService implements IConfiguratorService {
@Override
public IStatus remove( List<String> anyListOf ) {
- // TODO Auto-generated method stub
- return null;
+ FeatureManager featureManager = p2Util.getFeatureManager();
+ List<SourceVersion> sourceVersionsToUnisntall = getSourceVersionsToUninstall( anyListOf,
+ featureManager );
+ List<IStatus> errorStatus = uninstall( featureManager, sourceVersionsToUnisntall );
+ return errorStatus.isEmpty()
+ ? Status.OK_STATUS
+ : new MultiStatus( ProviderActivator.BUNDLE_ID,
+ 0,
+ errorStatus.toArray( new IStatus[ 0 ] ),
+ "Uinstall status",
+ null );
}
- @Override
- public List<String> search( List<String> anyListOf ) {
+ private List<SourceVersion> getSourceVersionsToUninstall( List<String> anyListOf,
+ FeatureManager featureManager )
+ {
+ List<SourceVersion> result = new ArrayList<SourceVersion>();
List<Source> sources = ConfiguratorModelUtil.getSourceProvider().getSources();
- List<String> result = new ArrayList<String>();
- for( Source source : sources ) {
- String name = source.getName();
- for( String term : anyListOf ) {
- if( name.contains( term ) ) {
- result.add( source.toString() );
+ List<Source> sourceToUinstall = searchSources( anyListOf, sources );
+ for( Source source : sourceToUinstall ) {
+ List<SourceVersion> versions = source.getVersions();
+ for( SourceVersion sourceVersion : versions ) {
+ if( featureManager.isInstalled( sourceVersion.getId(), sourceVersion.getVersion() ) ) {
+ result.add( sourceVersion );
}
}
}
- Collections.sort( result );
return result;
}
+ private List<IStatus> uninstall( FeatureManager featureManager,
+ List<SourceVersion> sourceVersionsToUnisntall )
+ {
+ List<IStatus> errorStatus = new ArrayList<IStatus>();
+ for( SourceVersion sourceVersion : sourceVersionsToUnisntall ) {
+ try {
+ featureManager.uninstallFeature( sourceVersion );
+ } catch( FeatureInstallException e ) {
+ System.out.println( "Failed to uninstall source version: " + sourceVersion.toString() );
+ e.printStackTrace();
+ Status status = new Status( IStatus.ERROR,
+ ProviderActivator.BUNDLE_ID,
+ "Failed to uninstall source version: "
+ + sourceVersion.toString(),
+ e );
+ errorStatus.add( status );
+ }
+ }
+ return errorStatus;
+ }
+
+ @Override
+ public List<String> search( List<String> anyListOf ) {
+ List<Source> sources = ConfiguratorModelUtil.getSourceProvider().getSources();
+ List<Source> result = searchSources( anyListOf, sources );
+ return getSortedSources( result );
+ }
+
@Override
public List<String> show( List<String> anyListOf ) {
List<Source> sources = ConfiguratorModelUtil.getSourceProvider().getSources();
- List<String> result = new ArrayList<String>();
- String showName = anyListOf.get( 0 );
- for( Source source : sources ) {
- if( source.getName().contains( showName ) ) {
- result.add( source.toString() );
- }
- }
- Collections.sort( result );
- return result;
+ List<String> showSource = new ArrayList<String>();
+ showSource.add( anyListOf.get( 0 ) );
+ List<Source> result = searchSources( showSource, sources );
+ return getSortedSources( result );
}
@Override
public List<String> list() throws CoreException {
List<Source> sources = ConfiguratorModelUtil.getSourceProvider().getSources();
- List<String> sourcesAsString = getSourtedSources( sources );
+ List<String> sourcesAsString = getSortedSources( sources );
return sourcesAsString;
}
- private List<String> getSourtedSources( List<Source> sources ) {
+ private List<Source> searchSources( List<String> anyListOf, List<Source> sources ) {
+ List<Source> result = new ArrayList<Source>();
+ for( Source source : sources ) {
+ String name = source.getName();
+ for( String term : anyListOf ) {
+ if( name.contains( term ) ) {
+ result.add( source );
+ }
+ }
+ }
+ return result;
+ }
+
+ private List<String> getSortedSources( List<Source> sources ) {
List<String> sourcesAsString = new ArrayList<String>();
for( Source source : sources ) {
sourcesAsString.add( source.toString() );
diff --git a/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/FeatureManager.java b/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/FeatureManager.java
index 2e751e5..0ab3ade 100644
--- a/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/FeatureManager.java
+++ b/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/FeatureManager.java
@@ -1,21 +1,23 @@
-/*******************************************************************************
-* Copyright (c) 2011 EclipseSource and others. All rights reserved. This
-* program and the accompanying materials are 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:
-* EclipseSource - initial API and implementation
-*******************************************************************************/
+/*******************************************************************************
+ * Copyright (c) 2011 EclipseSource and others. All rights reserved. This program and the
+ * accompanying materials are 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: EclipseSource - initial API and
+ * implementation
+ *******************************************************************************/
package org.eclipse.rtp.configurator.service.provider.internal.deploy;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Collection;
+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.IProfile;
+import org.eclipse.equinox.p2.engine.IProfileRegistry;
import org.eclipse.equinox.p2.engine.ProvisioningContext;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.Version;
@@ -25,113 +27,133 @@ 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.configurator.model.SourceVersion;
-@SuppressWarnings("restriction")
+@SuppressWarnings( "restriction" )
public class FeatureManager {
- public enum Action {
- UNINSTALL, INSTALL
- }
-
- private final IProvisioningAgent provisioningAgent;
- private final RepositoryManager repositoryManager;
- private final Configurator configurator;
-
- 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();
- }
-
- // 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)
- 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);
-
- 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);
- }
- }
-
- 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());
-
- 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
+ public enum Action {
+ UNINSTALL, INSTALL
+ }
+ private final IProvisioningAgent provisioningAgent;
+ private final RepositoryManager repositoryManager;
+ private final Configurator configurator;
+
+ public FeatureManager( IProvisioningAgent provisioningAgent,
+ RepositoryManager repositoryManager,
+ Configurator configurator )
+ {
+ this.provisioningAgent = provisioningAgent;
+ this.repositoryManager = repositoryManager;
+ this.configurator = configurator;
+ }
+
+ // TODO: Not tested
+ public void installFeature( SourceVersion sourceVersion ) throws FeatureInstallException {
+ ProfileChangeOperation operation = resolveProfileChangeOperation( sourceVersion, Action.INSTALL );
+ executeProfileChangeOperation( operation );
+ applyChanges();
+ }
+
+ // TODO: Not tested
+ public void uninstallFeature( SourceVersion sourceVersion ) throws FeatureInstallException {
+ ProfileChangeOperation operation = resolveProfileChangeOperation( sourceVersion,
+ Action.UNINSTALL );
+ executeProfileChangeOperation( operation );
+ applyChanges();
+ }
+
+ // TODO: Not tested
+ private ProfileChangeOperation resolveProfileChangeOperation( SourceVersion sourceVersion,
+ Action action )
+ throws FeatureInstallException
+ {
+ ProvisioningSession session = new ProvisioningSession( provisioningAgent );
+ ProvisioningContext context = createProvisioningContext();
+ Collection<IInstallableUnit> units = getInstallableUnits( context,
+ sourceVersion.getId(),
+ sourceVersion.getVersion() );
+ 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 );
+ 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 );
+ }
+ }
+
+ 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() );
+ 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;
+ }
+
+ public boolean isInstalled( String id, String version ) {
+ IProfileRegistry profileRegistry = ( IProfileRegistry )provisioningAgent.getService( IProfileRegistry.SERVICE_NAME );
+ IProfile profile = profileRegistry.getProfile( IProfileRegistry.SELF );
+ Collection<IInstallableUnit> toInstall = profile.query( QueryUtil.createIUQuery( id,
+ Version.create( version ) ),
+ null )
+ .toUnmodifiableSet();
+ return !toInstall.isEmpty();
+ }
+}
diff --git a/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/ConfiguratorModelUtil.java b/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/ConfiguratorModelUtil.java
index 1f52861..5fc4532 100644
--- a/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/ConfiguratorModelUtil.java
+++ b/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/ConfiguratorModelUtil.java
@@ -1,5 +1,7 @@
package org.eclipse.rtp.configurator.service.provider.internal.util;
+import java.net.URL;
+
import org.eclipse.rtp.configurator.model.SourceProvider;
import org.eclipse.rtp.configurator.model.SourceUnMarshaller;
@@ -7,6 +9,7 @@ public class ConfiguratorModelUtil {
private static SourceUnMarshaller sourceUnMarshaller;
private static SourceProvider sourceProvider;
+ private static String defaultModeURL = "http://foo";
public static void setUnMarshaller( SourceUnMarshaller sourceUnMarshaller ) {
ConfiguratorModelUtil.sourceUnMarshaller = sourceUnMarshaller;
@@ -25,8 +28,23 @@ public class ConfiguratorModelUtil {
}
public static SourceProvider getSourceProvider(){
+ if(sourceProvider == null){
+ sourceProvider = getDefaultModel();
+ }
return ConfiguratorModelUtil.sourceProvider;
}
+
+ private static SourceProvider getDefaultModel() {
+ SourceProvider result = null;
+ try {
+ URL url = new URL( defaultModeURL );
+ result = sourceUnMarshaller.marshal( url.openStream( ) );
+ } catch( Exception e ) {
+ System.out.println("Failed to load model");
+ e.printStackTrace();
+ }
+ return result;
+ }
}
diff --git a/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/P2Util.java b/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/P2Util.java
index ac62bb6..623fde5 100644
--- a/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/P2Util.java
+++ b/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/P2Util.java
@@ -9,11 +9,8 @@
*******************************************************************************/
package org.eclipse.rtp.configurator.service.provider.internal.util;
-import java.net.URI;
-
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Path;
import org.eclipse.equinox.internal.provisional.configurator.Configurator;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.IProvisioningAgentProvider;
@@ -30,11 +27,11 @@ public class P2Util {
private static IProvisioningAgent provisioningAgent;
private static FeatureManager featureManager;
- public static FeatureManager getFeatureManager(){
+ public FeatureManager getFeatureManager(){
return featureManager;
}
- public static RepositoryManager getRepositoryManager(){
+ public RepositoryManager getRepositoryManager(){
return repositoryManager;
}
diff --git a/packages/org.eclipse.rtp.package.web.feature/rootfiles/Start EclipseRT Web Starter Kit.launch b/packages/org.eclipse.rtp.package.web.feature/rootfiles/Start EclipseRT Web Starter Kit.launch
index 42cfdbe..8d93d8d 100644
--- a/packages/org.eclipse.rtp.package.web.feature/rootfiles/Start EclipseRT Web Starter Kit.launch
+++ b/packages/org.eclipse.rtp.package.web.feature/rootfiles/Start EclipseRT Web Starter Kit.launch
@@ -1,28 +1,28 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<launchConfiguration type="org.eclipse.pde.ui.EquinoxLauncher">
-<booleanAttribute key="append.args" value="true"/>
-<booleanAttribute key="automaticAdd" value="true"/>
-<booleanAttribute key="automaticValidate" value="true"/>
-<stringAttribute key="bootstrap" value=""/>
-<stringAttribute key="checked" value="[NONE]"/>
-<booleanAttribute key="clearConfig" value="false"/>
-<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/Start EclipseRT Web Starter Kit"/>
-<booleanAttribute key="default" value="true"/>
-<booleanAttribute key="default_auto_start" value="true"/>
-<intAttribute key="default_start_level" value="4"/>
-<booleanAttribute key="includeOptional" value="true"/>
-<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
-<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
-<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
-</listAttribute>
-<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog -console"/>
-<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
-<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Declipse.ignoreApp=true -Dosgi.noShutdown=true -Djetty.home=${workspace_loc:EclipseRTWebStarterKit} -Dlogback.configurationFile=${workspace_loc:EclipseRTWebStarterKit}/etc/logback.xml"/>
-<stringAttribute key="pde.version" value="3.3"/>
-<booleanAttribute key="show_selected_only" value="false"/>
-<stringAttribute key="target_bundles" value="org.eclipse.ecf@default:default,org.eclipse.ecf.provider.filetransfer.ssl@default:false,org.apache.commons.codec@default:default,org.eclipse.equinox.launcher@default:default,org.eclipse.equinox.p2.reconciler.dropins@default:default,org.eclipse.equinox.p2.repository@default:default,org.eclipse.equinox.common@2:true,org.eclipse.equinox.p2.ql@default:default,org.sat4j.pb@default:default,org.apache.commons.logging@default:default,org.eclipse.equinox.ds@default:true,org.eclipse.ecf.identity@default:default,org.eclipse.equinox.p2.metadata@default:default,org.eclipse.equinox.p2.operations@default:default,javax.servlet@default:default,javax.servlet.jsp@default:default,org.eclipse.equinox.p2.publisher@default:default,org.eclipse.ecf.ssl@default:false,org.eclipse.ecf.provider.filetransfer.httpclient.ssl@default:false,org.eclipse.equinox.p2.extensionlocation@default:default,org.eclipse.equinox.p2.console@default:default,org.eclipse.equinox.frameworkadmin.equinox@default:default,org.eclipse.equinox.http.servlet@default:default,org.eclipse.equinox.p2.director@default:default,org.eclipse.osgi.services@default:default,org.eclipse.equinox.p2.touchpoint.natives@default:default,org.eclipse.equinox.simpleconfigurator.manipulator@default:default,org.eclipse.core.runtime@default:true,org.eclipse.equinox.simpleconfigurator@1:true,org.eclipse.equinox.p2.touchpoint.eclipse@default:default,org.eclipse.equinox.util@default:default,org.eclipse.ecf.provider.filetransfer@default:default,org.eclipse.equinox.security@default:default,org.eclipse.equinox.p2.metadata.repository@default:default,org.eclipse.osgi@-1:true,org.eclipse.equinox.p2.core@default:default,org.eclipse.equinox.http.registry@default:default,org.eclipse.osgi.util@default:default,org.eclipse.equinox.p2.jarprocessor@default:default,org.eclipse.equinox.frameworkadmin@default:default,org.eclipse.equinox.p2.garbagecollector@default:default,org.eclipse.equinox.app@default:default,org.eclipse.equinox.p2.engine@default:default,org.eclipse.ecf.provider.filetransfer.httpclient@default:default,org.eclipse.equinox.p2.director.app@default:default,org.eclipse.ecf.filetransfer@default:default,org.apache.commons.httpclient@default:default,org.sat4j.core@default:default,org.eclipse.core.contenttype@default:default,org.eclipse.equinox.p2.directorywatcher@default:default,org.eclipse.equinox.p2.artifact.repository@default:default,org.eclipse.core.jobs@default:default,org.eclipse.equinox.preferences@default:default,org.eclipse.equinox.registry@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.configurator.console@default:default,org.eclipse.rtp.configurator.test@default:false"/>
-</launchConfiguration>
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.pde.ui.EquinoxLauncher">
+<booleanAttribute key="append.args" value="true"/>
+<booleanAttribute key="automaticAdd" value="true"/>
+<booleanAttribute key="automaticValidate" value="true"/>
+<stringAttribute key="bootstrap" value=""/>
+<stringAttribute key="checked" value="[NONE]"/>
+<booleanAttribute key="clearConfig" value="false"/>
+<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/Start EclipseRT Web Starter Kit"/>
+<booleanAttribute key="default" value="true"/>
+<booleanAttribute key="default_auto_start" value="true"/>
+<intAttribute key="default_start_level" value="4"/>
+<booleanAttribute key="includeOptional" value="true"/>
+<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
+<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
+<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
+</listAttribute>
+<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog -console"/>
+<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
+<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Declipse.ignoreApp=true -Dosgi.noShutdown=true -Djetty.home=${workspace_loc:EclipseRTWebStarterKit} -Dlogback.configurationFile=${workspace_loc:EclipseRTWebStarterKit}/etc/logback.xml"/>
+<stringAttribute key="pde.version" value="3.3"/>
+<booleanAttribute key="show_selected_only" value="false"/>
+<stringAttribute key="target_bundles" value="javax.servlet.jsp@default:default,javax.servlet@default:default,org.apache.commons.codec@default:default,org.apache.commons.httpclient@default:default,org.apache.commons.logging@default:default,org.eclipse.core.contenttype@default:default,org.eclipse.core.jobs@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.ssl@default:false,org.eclipse.ecf.provider.filetransfer@default:default,org.eclipse.ecf.ssl@default:false,org.eclipse.ecf@default:default,org.eclipse.equinox.app@default:default,org.eclipse.equinox.common@2:true,org.eclipse.equinox.ds@default:true,org.eclipse.equinox.frameworkadmin.equinox@default:default,org.eclipse.equinox.frameworkadmin@default:default,org.eclipse.equinox.http.registry@default:default,org.eclipse.equinox.http.servlet@default:default,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.app@default:default,org.eclipse.equinox.p2.director@default:default,org.eclipse.equinox.p2.directorywatcher@default:default,org.eclipse.equinox.p2.engine@default:default,org.eclipse.equinox.p2.extensionlocation@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@default:default,org.eclipse.equinox.p2.ql@default:default,org.eclipse.equinox.p2.reconciler.dropins@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.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.util@default:default,org.eclipse.osgi@-1:true,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.eclipes.rtp.core@default:default,org.eclipse.rtp.configurator.console@default:default,org.eclipse.rtp.configurator.model.test@default:false,org.eclipse.rtp.configurator.model@default:default,org.eclipse.rtp.configurator.test@default:false,org.eclipse.rtp.core.service.provider.test@default:false,org.eclipse.rtp.core.service.provider@default:default,org.eclipse.rtp.core.test@default:default"/>
+</launchConfiguration>