aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbveliev2011-07-10 14:05:40 (EDT)
committerbveliev2011-07-10 14:05:40 (EDT)
commite256ca7dc708a717f2cfcb4e19cf82fd449c07d5 (patch)
tree68a19f8931b0c6c1dfdab8ebd44eb674c13cffed
parent0ec8ad307624b9dfb8a061a273fd6576dfe61bc2 (diff)
downloadorg.eclipse.rtp-e256ca7dc708a717f2cfcb4e19cf82fd449c07d5.zip
org.eclipse.rtp-e256ca7dc708a717f2cfcb4e19cf82fd449c07d5.tar.gz
org.eclipse.rtp-e256ca7dc708a717f2cfcb4e19cf82fd449c07d5.tar.bz2
bug 351654: [Configurator] Implement "list" command
https://bugs.eclipse.org/bugs/show_bug.cgi?id=351654
-rw-r--r--configurator.test/org.eclipse.rtp.configurator.service.provider.test/.settings/org.eclipse.jdt.core.prefs2
-rw-r--r--configurator.test/org.eclipse.rtp.configurator.service.provider.test/META-INF/MANIFEST.MF6
-rw-r--r--configurator.test/org.eclipse.rtp.configurator.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceListCommandTest.java165
-rw-r--r--configurator/org.eclipes.rtp.configurator.core/META-INF/MANIFEST.MF1
-rw-r--r--configurator/org.eclipes.rtp.configurator.core/src/org/eclipse/rtp/configurator/core/IConfiguratorService.java19
-rw-r--r--configurator/org.eclipse.rtp.configurator.console/META-INF/MANIFEST.MF3
-rw-r--r--configurator/org.eclipse.rtp.configurator.console/src/org/eclipse/rtp/configurator/console/CommandDelegateImpl.java18
-rw-r--r--configurator/org.eclipse.rtp.configurator.releng/target.target27
-rw-r--r--configurator/org.eclipse.rtp.configurator.service.provider/.settings/org.eclipse.pde.core.prefs3
-rw-r--r--configurator/org.eclipse.rtp.configurator.service.provider/META-INF/MANIFEST.MF6
-rw-r--r--configurator/org.eclipse.rtp.configurator.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/DefaultConfiguratorService.java98
-rw-r--r--configurator/org.eclipse.rtp.configurator.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/ProviderActivator.java34
-rw-r--r--configurator/org.eclipse.rtp.configurator.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/P2Util.java55
-rw-r--r--configurator/org.eclipse.rtp.configurator.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/StatusUtil.java22
14 files changed, 409 insertions, 50 deletions
diff --git a/configurator.test/org.eclipse.rtp.configurator.service.provider.test/.settings/org.eclipse.jdt.core.prefs b/configurator.test/org.eclipse.rtp.configurator.service.provider.test/.settings/org.eclipse.jdt.core.prefs
index b205f9d..e5bdb81 100644
--- a/configurator.test/org.eclipse.rtp.configurator.service.provider.test/.settings/org.eclipse.jdt.core.prefs
+++ b/configurator.test/org.eclipse.rtp.configurator.service.provider.test/.settings/org.eclipse.jdt.core.prefs
@@ -1,4 +1,4 @@
-#Sun Jun 26 11:30:07 CEST 2011
+#Sun Jul 10 14:16:35 CEST 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
diff --git a/configurator.test/org.eclipse.rtp.configurator.service.provider.test/META-INF/MANIFEST.MF b/configurator.test/org.eclipse.rtp.configurator.service.provider.test/META-INF/MANIFEST.MF
index cecfbb6..a5a7728 100644
--- a/configurator.test/org.eclipse.rtp.configurator.service.provider.test/META-INF/MANIFEST.MF
+++ b/configurator.test/org.eclipse.rtp.configurator.service.provider.test/META-INF/MANIFEST.MF
@@ -1,7 +1,9 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
-Bundle-Name: Service Provider Test
+Bundle-Name: Test
Bundle-SymbolicName: org.eclipse.rtp.configurator.service.provider.test
Bundle-Version: 1.0.0.qualifier
-Bundle-Vendor: EclipseSource
+Fragment-Host: org.eclipse.rtp.configurator.service.provider;bundle-version="1.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Require-Bundle: org.junit,
+ org.mockito;bundle-version="1.0.0"
diff --git a/configurator.test/org.eclipse.rtp.configurator.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceListCommandTest.java b/configurator.test/org.eclipse.rtp.configurator.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceListCommandTest.java
new file mode 100644
index 0000000..3b87ddb
--- /dev/null
+++ b/configurator.test/org.eclipse.rtp.configurator.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceListCommandTest.java
@@ -0,0 +1,165 @@
+/*******************************************************************************
+* 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);
+ when(p2UtilMock.getAgent()).thenReturn(provisioningAgent);
+ }
+
+ 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/configurator/org.eclipes.rtp.configurator.core/META-INF/MANIFEST.MF b/configurator/org.eclipes.rtp.configurator.core/META-INF/MANIFEST.MF
index 0173a75..2574479 100644
--- a/configurator/org.eclipes.rtp.configurator.core/META-INF/MANIFEST.MF
+++ b/configurator/org.eclipes.rtp.configurator.core/META-INF/MANIFEST.MF
@@ -7,3 +7,4 @@ Bundle-Vendor: EclipseSource
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Service-Component: OSGI-INF/rtpConfiguratorServiceComponent.xml
Export-Package: org.eclipse.rtp.configurator.core
+Import-Package: org.eclipse.core.runtime
diff --git a/configurator/org.eclipes.rtp.configurator.core/src/org/eclipse/rtp/configurator/core/IConfiguratorService.java b/configurator/org.eclipes.rtp.configurator.core/src/org/eclipse/rtp/configurator/core/IConfiguratorService.java
index 30635b0..3890089 100644
--- a/configurator/org.eclipes.rtp.configurator.core/src/org/eclipse/rtp/configurator/core/IConfiguratorService.java
+++ b/configurator/org.eclipes.rtp.configurator.core/src/org/eclipse/rtp/configurator/core/IConfiguratorService.java
@@ -11,21 +11,24 @@ package org.eclipse.rtp.configurator.core;
import java.util.List;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+
public interface IConfiguratorService {
- void install( List<String> parameter );
+ IStatus install( List<String> parameter );
- void update( List<String> anyListOf );
+ IStatus update( List<String> anyListOf );
- void remove( List<String> anyListOf );
+ IStatus remove( List<String> anyListOf );
- void search( List<String> anyListOf );
+ List<String> search( List<String> anyListOf );
- void show( List<String> anyListOf );
+ List<String> show( List<String> anyListOf );
- void list( );
+ List<String> list( ) throws CoreException;
- void updateWorld( );
+ IStatus updateWorld( );
- void refresh( );
+ IStatus refresh( );
}
diff --git a/configurator/org.eclipse.rtp.configurator.console/META-INF/MANIFEST.MF b/configurator/org.eclipse.rtp.configurator.console/META-INF/MANIFEST.MF
index 32522cb..b85b557 100644
--- a/configurator/org.eclipse.rtp.configurator.console/META-INF/MANIFEST.MF
+++ b/configurator/org.eclipse.rtp.configurator.console/META-INF/MANIFEST.MF
@@ -5,6 +5,7 @@ Bundle-SymbolicName: org.eclipse.rtp.configurator.console
Bundle-Version: 0.1.0.qualifier
Bundle-Vendor: EclipseSource
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Import-Package: org.eclipse.osgi.framework.console;version="1.1.0"
+Import-Package: org.eclipse.core.runtime;version="3.4.0",
+ org.eclipse.osgi.framework.console;version="1.1.0"
Service-Component: OSGI-INF/rtpCommandProviderComponent.xml, OSGI-INF/rtpConfiguratorServiceReference.xml
Require-Bundle: org.eclipes.rtp.configurator.core;bundle-version="1.0.0"
diff --git a/configurator/org.eclipse.rtp.configurator.console/src/org/eclipse/rtp/configurator/console/CommandDelegateImpl.java b/configurator/org.eclipse.rtp.configurator.console/src/org/eclipse/rtp/configurator/console/CommandDelegateImpl.java
index 02d1b2a..ae61154 100644
--- a/configurator/org.eclipse.rtp.configurator.console/src/org/eclipse/rtp/configurator/console/CommandDelegateImpl.java
+++ b/configurator/org.eclipse.rtp.configurator.console/src/org/eclipse/rtp/configurator/console/CommandDelegateImpl.java
@@ -11,6 +11,8 @@ package org.eclipse.rtp.configurator.console;
import java.util.List;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.rtp.configurator.core.IConfiguratorService;
@@ -76,12 +78,20 @@ public class CommandDelegateImpl implements CommandDelegate {
configurationService.show( anyListOf );
}
+ /**
+ * Lists all IUs in the rtp repos.
+ */
@Override
public void list() {
- /*
- * Should list all IUs in the rtp repos.
- */
- configurationService.list();
+ try {
+ List<String> list = configurationService.list();
+ for( String iu : list ) {
+ System.out.println(iu);
+ }
+ } catch( CoreException e ) {
+ IStatus status = e.getStatus();
+ System.out.println(status);
+ }
}
@Override
diff --git a/configurator/org.eclipse.rtp.configurator.releng/target.target b/configurator/org.eclipse.rtp.configurator.releng/target.target
index 6d66ac4..bf11e68 100644
--- a/configurator/org.eclipse.rtp.configurator.releng/target.target
+++ b/configurator/org.eclipse.rtp.configurator.releng/target.target
@@ -1,18 +1,31 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.6"?>
-<target name="target" sequenceNumber="8">
+<target name="target" sequenceNumber="13">
<locations>
<location includeAllPlatforms="false" includeMode="slicer" includeSource="true" type="InstallableUnit">
-<unit id="org.eclipse.rcp.sdk.id" version="3.7.0.I20110613-1736"/>
-<unit id="org.eclipse.equinox.p2.sdk.feature.group" version="3.7.0.v20110519-9N7sHDJGMMn4xUrxSmFfL7O39XLL"/>
-<unit id="org.eclipse.pde.junit.runtime.addon.feature.group" version="1.0.100.v20110331-7C7GDHAkHgHr9v0L4DF585202816"/>
-<repository location="http://download.eclipse.org/eclipse/updates/3.7"/>
-</location>
-<location includeAllPlatforms="false" includeMode="slicer" includeSource="true" type="InstallableUnit">
+<unit id="org.hamcrest.core" version="1.1.0.v20090501071000"/>
+<unit id="org.hamcrest.core.source" version="1.1.0.v20090501071000"/>
+<unit id="org.hamcrest.integration.source" version="1.1.0.v20090501071000"/>
+<unit id="org.hamcrest.generator" version="1.1.0.v20090501071000"/>
+<unit id="org.hamcrest.generator.source" version="1.1.0.v20090501071000"/>
+<unit id="org.hamcrest.integration" version="1.1.0.v20090501071000"/>
+<unit id="org.hamcrest.library" version="1.1.0.v20090501071000"/>
+<unit id="org.hamcrest.library.source" version="1.1.0.v20090501071000"/>
+<unit id="org.hamcrest" version="1.1.0.v20090501071000"/>
+<unit id="org.hamcrest.text" version="1.1.0.v20090501071000"/>
+<unit id="org.hamcrest.text.source" version="1.1.0.v20090501071000"/>
+<unit id="org.objenesis" version="1.0.0.v201105211943"/>
+<unit id="org.objenesis.source" version="1.0.0.v201105211943"/>
<unit id="org.mockito.source" version="1.8.4.v201102171835"/>
<unit id="org.mockito" version="1.8.4.v201102171835"/>
<repository location="http://download.eclipse.org/tools/orbit/downloads/drops/R20110523182458/repository/"/>
</location>
+<location includeAllPlatforms="false" includeMode="slicer" includeSource="true" type="InstallableUnit">
+<unit id="org.eclipse.platform.sdk" version="3.7.0.I20110613-1736"/>
+<unit id="org.eclipse.sdk.ide" version="3.7.0.I20110613-1736"/>
+<unit id="org.eclipse.test.feature.group" version="3.5.0.v20110503-7R7aBjBgLiJz0Cv6Q4DG58520281"/>
+<repository location="http://download.eclipse.org/eclipse/updates/3.7"/>
+</location>
</locations>
</target>
diff --git a/configurator/org.eclipse.rtp.configurator.service.provider/.settings/org.eclipse.pde.core.prefs b/configurator/org.eclipse.rtp.configurator.service.provider/.settings/org.eclipse.pde.core.prefs
new file mode 100644
index 0000000..ed2673a
--- /dev/null
+++ b/configurator/org.eclipse.rtp.configurator.service.provider/.settings/org.eclipse.pde.core.prefs
@@ -0,0 +1,3 @@
+#Sun Jul 10 17:25:43 CEST 2011
+eclipse.preferences.version=1
+resolve.requirebundle=false
diff --git a/configurator/org.eclipse.rtp.configurator.service.provider/META-INF/MANIFEST.MF b/configurator/org.eclipse.rtp.configurator.service.provider/META-INF/MANIFEST.MF
index d3bae12..5a50d9e 100644
--- a/configurator/org.eclipse.rtp.configurator.service.provider/META-INF/MANIFEST.MF
+++ b/configurator/org.eclipse.rtp.configurator.service.provider/META-INF/MANIFEST.MF
@@ -9,3 +9,9 @@ Require-Bundle: org.eclipse.core.runtime,
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Service-Component: OSGI-INF/rtpConfiguratorServiceProvider.xml
+Bundle-Activator: org.eclipse.rtp.configurator.service.provider.internal.ProviderActivator
+Import-Package: org.eclipse.equinox.p2.core,
+ org.eclipse.equinox.p2.metadata;version="2.1.0",
+ org.eclipse.equinox.p2.query;version="2.0.0",
+ org.eclipse.equinox.p2.repository;version="2.0.0",
+ org.eclipse.equinox.p2.repository.metadata;version="2.0.0"
diff --git a/configurator/org.eclipse.rtp.configurator.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/DefaultConfiguratorService.java b/configurator/org.eclipse.rtp.configurator.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/DefaultConfiguratorService.java
index 14914cd..e5db933 100644
--- a/configurator/org.eclipse.rtp.configurator.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/DefaultConfiguratorService.java
+++ b/configurator/org.eclipse.rtp.configurator.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/DefaultConfiguratorService.java
@@ -1,67 +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
-*******************************************************************************/
+ * 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 java.net.URI;
+import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
+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.core.IConfiguratorService;
+import org.eclipse.rtp.configurator.service.provider.internal.util.P2Util;
-public class DefaultConfiguratorService implements IConfiguratorService{
+public class DefaultConfiguratorService implements IConfiguratorService {
+ private P2Util p2Util;
+
+ public void setUp() {
+ setP2Util(new P2Util());
+ }
+
+ public void shutDown() {
+ setP2Util(null);
+ }
+
+ public void setP2Util(P2Util p2Util) {
+ this.p2Util = p2Util;
+ }
@Override
- public void install(List<String> parameter) {
+ public IStatus install(List<String> parameter) {
// TODO Auto-generated method stub
-
+ return null;
}
@Override
- public void update(List<String> anyListOf) {
+ public IStatus update(List<String> anyListOf) {
// TODO Auto-generated method stub
-
+ return null;
}
@Override
- public void remove(List<String> anyListOf) {
+ public IStatus remove(List<String> anyListOf) {
// TODO Auto-generated method stub
-
+ return null;
}
@Override
- public void search(List<String> anyListOf) {
+ public List<String> search(List<String> anyListOf) {
// TODO Auto-generated method stub
-
+ return null;
}
@Override
- public void show(List<String> anyListOf) {
+ public List<String> show(List<String> anyListOf) {
// TODO Auto-generated method stub
-
+ return null;
}
@Override
- public void list() {
- // TODO Auto-generated method stub
-
+ public List<String> list() throws CoreException {
+ List<String> resutl = new ArrayList<String>();
+ IProvisioningAgent agent = p2Util.getAgent();
+ IMetadataRepositoryManager metadataRepositoryManager = (IMetadataRepositoryManager) agent
+ .getService(IMetadataRepositoryManager.class.getName());
+ URI [] knownRepositories = metadataRepositoryManager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL);
+ for (URI repositoryURI : knownRepositories) {
+ IMetadataRepository repository = metadataRepositoryManager.loadRepository(repositoryURI, null);
+ IQueryResult<IInstallableUnit> queryResult = repository.query(QueryUtil.createIUAnyQuery(), null);
+ addResult(resutl, queryResult);
+ }
+ return resutl;
+ }
+
+ private void addResult(List<String> resutl, IQueryResult<IInstallableUnit> queryResult) {
+ Iterator<IInstallableUnit> iterator = queryResult.iterator();
+ while (iterator.hasNext()) {
+ IInstallableUnit installableUnit = (IInstallableUnit) iterator.next();
+ if(!resutl.contains(installableUnit)){
+ resutl.add(installableUnit.getId());
+ }
+ }
}
@Override
- public void updateWorld() {
+ public IStatus updateWorld() {
// TODO Auto-generated method stub
-
+ return null;
}
@Override
- public void refresh() {
+ public IStatus refresh() {
// TODO Auto-generated method stub
-
+ return null;
}
-
+
}
diff --git a/configurator/org.eclipse.rtp.configurator.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/ProviderActivator.java b/configurator/org.eclipse.rtp.configurator.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/ProviderActivator.java
new file mode 100644
index 0000000..beec000
--- /dev/null
+++ b/configurator/org.eclipse.rtp.configurator.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/ProviderActivator.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+* 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 org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public class ProviderActivator implements BundleActivator {
+
+ public static String BUNDLE_ID = "org.eclipse.rtp.configurator.service.provider";
+ private static BundleContext bundleContext;
+
+ @Override
+ public void start(BundleContext context) throws Exception {
+ ProviderActivator.bundleContext = context;
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ bundleContext = null;
+ }
+
+ public static BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+}
diff --git a/configurator/org.eclipse.rtp.configurator.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/P2Util.java b/configurator/org.eclipse.rtp.configurator.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/P2Util.java
new file mode 100644
index 0000000..b59a926
--- /dev/null
+++ b/configurator/org.eclipse.rtp.configurator.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/P2Util.java
@@ -0,0 +1,55 @@
+/*******************************************************************************
+* 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.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.p2.core.IProvisioningAgent;
+import org.eclipse.equinox.p2.core.IProvisioningAgentProvider;
+import org.eclipse.rtp.configurator.service.provider.internal.ProviderActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+public class P2Util {
+
+ public IProvisioningAgent getAgent() throws CoreException {
+ BundleContext bundleContext = ProviderActivator.getBundleContext();
+ String packageLocation = bundleContext.getProperty("package.location");
+ URI packageLocationURI = new Path(packageLocation).append("p2").toFile().toURI();
+ IProvisioningAgentProvider agentProvider = (IProvisioningAgentProvider) getService(bundleContext, IProvisioningAgentProvider.SERVICE_NAME);
+ checkAgentAvailable(agentProvider);
+ return agentProvider.createAgent(packageLocationURI);
+ }
+
+ private void checkAgentAvailable(IProvisioningAgentProvider agentProvider) throws CoreException {
+ if (agentProvider == null) {
+ String message = "Agent provider service not available"; //$NON-NLS-1$
+ IStatus status = StatusUtil.createStatus(IStatus.ERROR, message, null);
+ throw new CoreException(status);
+ }
+ }
+
+ public Object getService(BundleContext context, String name) {
+ if (context == null || name == null) {
+ throw new IllegalArgumentException();
+ }
+ ServiceReference reference = context.getServiceReference(name);
+ Object result = null;
+ if (reference != null) {
+ result = context.getService(reference);
+ context.ungetService(reference);
+ }
+ return result;
+ }
+
+}
diff --git a/configurator/org.eclipse.rtp.configurator.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/StatusUtil.java b/configurator/org.eclipse.rtp.configurator.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/StatusUtil.java
new file mode 100644
index 0000000..8376c16
--- /dev/null
+++ b/configurator/org.eclipse.rtp.configurator.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/StatusUtil.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+* 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.util;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.rtp.configurator.service.provider.internal.ProviderActivator;
+
+public class StatusUtil {
+
+ public static IStatus createStatus(int severity, String message, Object object) {
+ return new Status(severity, ProviderActivator.BUNDLE_ID, message);
+ }
+
+}