aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbveliev2011-10-03 08:22:24 (EDT)
committerbveliev2011-10-03 08:22:24 (EDT)
commit82945e2e711e2b440123a2cbe2b065bd2ddd87b7 (patch)
tree5405792aa81a79b8acb9e9a55d98330566abc2c5
parent6235d8a5fcb90679f66ed9290891fadcc7582f5f (diff)
downloadorg.eclipse.rtp-82945e2e711e2b440123a2cbe2b065bd2ddd87b7.zip
org.eclipse.rtp-82945e2e711e2b440123a2cbe2b065bd2ddd87b7.tar.gz
org.eclipse.rtp-82945e2e711e2b440123a2cbe2b065bd2ddd87b7.tar.bz2
* update and updateWorld commands implemented
-rw-r--r--configurator/org.eclipse.rtp.configurator.console/RT Configurator Console.launch5
-rw-r--r--configurator/org.eclipse.rtp.configurator.console/src/org/eclipse/rtp/configurator/console/CommandDelegateImpl.java53
-rw-r--r--core.test/org.eclipse.rtp.core.service.provider.test/src/org/eclipse/rtp/configurator/service/provider/internal/ConfiguratorServiceTest.java91
-rw-r--r--core/org.eclipes.rtp.core/META-INF/MANIFEST.MF1
-rw-r--r--core/org.eclipse.rtp.core.service.provider/OSGI-INF/rtpConfiguratorServiceProvider.xml2
-rw-r--r--core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/DefaultConfiguratorService.java82
-rw-r--r--core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/FeatureManager.java15
-rw-r--r--core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/RepositoryManager.java299
-rw-r--r--core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/util/ConfiguratorModelUtil.java18
9 files changed, 355 insertions, 211 deletions
diff --git a/configurator/org.eclipse.rtp.configurator.console/RT Configurator Console.launch b/configurator/org.eclipse.rtp.configurator.console/RT Configurator Console.launch
index e7c59b6..fae1a14 100644
--- a/configurator/org.eclipse.rtp.configurator.console/RT Configurator Console.launch
+++ b/configurator/org.eclipse.rtp.configurator.console/RT Configurator Console.launch
@@ -10,16 +10,15 @@
<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"/>
+<stringAttribute key="target_bundles" value="com.google.gson@default:default,javax.servlet@default:default,org.apache.ant@default:default,org.apache.commons.io@default:default,org.easymock@default:default,org.eclipse.ant.core@default:default,org.eclipse.ant.optional.junit@default:false,org.eclipse.core.contenttype@default:default,org.eclipse.core.jobs@default:default,org.eclipse.core.net.win32.x86_64@default:default,org.eclipse.core.net@default:default,org.eclipse.core.runtime.compatibility.auth@default:default,org.eclipse.core.runtime.compatibility.registry@default:false,org.eclipse.core.runtime@default:true,org.eclipse.core.variables@default:default,org.eclipse.ecf.filetransfer@default:default,org.eclipse.ecf.identity@default:default,org.eclipse.ecf.provider.filetransfer.ssl@default:default,org.eclipse.ecf.provider.filetransfer@default:default,org.eclipse.ecf.ssl@default:default,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.p2.artifact.repository@default:default,org.eclipse.equinox.p2.core@default:default,org.eclipse.equinox.p2.director@default:default,org.eclipse.equinox.p2.engine@default:default,org.eclipse.equinox.p2.garbagecollector@default:default,org.eclipse.equinox.p2.jarprocessor@default:default,org.eclipse.equinox.p2.metadata.repository@default:default,org.eclipse.equinox.p2.metadata@default:default,org.eclipse.equinox.p2.operations@default:default,org.eclipse.equinox.p2.publisher.eclipse@default:default,org.eclipse.equinox.p2.publisher@default:default,org.eclipse.equinox.p2.ql@default:default,org.eclipse.equinox.p2.repository@default:default,org.eclipse.equinox.p2.touchpoint.eclipse@default:default,org.eclipse.equinox.p2.touchpoint.natives@default:default,org.eclipse.equinox.p2.transport.ecf@default:default,org.eclipse.equinox.preferences@default:default,org.eclipse.equinox.registry@default:default,org.eclipse.equinox.security.win32.x86_64@default:false,org.eclipse.equinox.security@default:default,org.eclipse.equinox.simpleconfigurator.manipulator@default:default,org.eclipse.equinox.simpleconfigurator@1:true,org.eclipse.equinox.util@default:default,org.eclipse.osgi.services@default:default,org.eclipse.osgi@-1:true,org.hamcrest.core@default:default,org.hamcrest.integration@default:default,org.hamcrest.library@default:default,org.hamcrest.text@default:default,org.hamcrest@default:default,org.junit*4.8.2.v4_8_2_v20110321-1705@default:default,org.mockito@default:default,org.objenesis@default:default,org.sat4j.core@default:default,org.sat4j.pb@default:default"/>
<booleanAttribute key="tracing" value="false"/>
<booleanAttribute key="useCustomFeatures" value="false"/>
<booleanAttribute key="useDefaultConfigArea" value="true"/>
-<stringAttribute key="workspace_bundles" value="org.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"/>
+<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>
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 ae61154..be2d64d 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
@@ -1,12 +1,10 @@
-/*******************************************************************************
-* 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.console;
import java.util.List;
@@ -15,19 +13,18 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.rtp.configurator.core.IConfiguratorService;
-
public class CommandDelegateImpl implements CommandDelegate {
private static IConfiguratorService configurationService;
- public static void setUp(IConfiguratorService service){
+ public static void setUp( IConfiguratorService service ) {
CommandDelegateImpl.configurationService = service;
}
-
- public static void shutDown(IConfiguratorService service){
+
+ public static void shutDown( IConfiguratorService service ) {
CommandDelegateImpl.configurationService = null;
}
-
+
@Override
public void unsupportedOperation( String operation ) {
/*
@@ -38,8 +35,8 @@ public class CommandDelegateImpl implements CommandDelegate {
@Override
public void install( List<String> parameter ) {
/*
- * Should install an iu to the latest version. The name of the iu ist the first list entry.
- * If the secodn entry is not a OSGI.version than the latest should be installed.
+ * Should install an iu to the latest version. The name of the iu ist the first list entry. If
+ * the secodn entry is not a OSGI.version than the latest should be installed.
*/
configurationService.install( parameter );
}
@@ -63,10 +60,11 @@ public class CommandDelegateImpl implements CommandDelegate {
@Override
public void search( List<String> anyListOf ) {
/*
- * Should list the available components in the rtp repos which where searched.
- * A phonetic search should be done.
+ * Should list the available components in the rtp repos which where searched. A phonetic search
+ * should be done.
*/
- configurationService.search( anyListOf );
+ List<String> search = configurationService.search( anyListOf );
+ printList( search );
}
@Override
@@ -75,7 +73,8 @@ public class CommandDelegateImpl implements CommandDelegate {
* Show details of a specific component e.g. Dependencies, available version, size and so on.
* Only one parameter = existing name of component
*/
- configurationService.show( anyListOf );
+ List<String> show = configurationService.show( anyListOf );
+ printList( show );
}
/**
@@ -85,12 +84,16 @@ public class CommandDelegateImpl implements CommandDelegate {
public void list() {
try {
List<String> list = configurationService.list();
- for( String iu : list ) {
- System.out.println(iu);
- }
+ printList( list );
} catch( CoreException e ) {
IStatus status = e.getStatus();
- System.out.println(status);
+ System.out.println( status );
+ }
+ }
+
+ private void printList( List<String> list ) {
+ for( String iu : list ) {
+ System.out.println( iu );
}
}
@@ -99,6 +102,7 @@ public class CommandDelegateImpl implements CommandDelegate {
/*
* Update the whole system to the latest version. No Parameter
*/
+ configurationService.updateWorld();
}
@Override
@@ -108,5 +112,4 @@ public class CommandDelegateImpl implements CommandDelegate {
*/
configurationService.refresh();
}
-
}
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
index 6139148..0089afc 100644
--- 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
@@ -11,6 +11,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -19,6 +20,8 @@ import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
@@ -33,6 +36,7 @@ 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;
+import org.osgi.framework.Version;
public class ConfiguratorServiceTest {
@@ -102,4 +106,91 @@ public class ConfiguratorServiceTest {
IStatus status = configuratorService.remove( parameters );
assertTrue( status.isOK() );
}
+
+ @Test
+ public void testUpdateWorldUpdateAvailable()
+ throws CoreException, FeatureInstallException, URISyntaxException
+ {
+ List<SourceVersion> sourceVersions = sourceProvider.getSources().get( 0 ).getVersions();
+ Collections.sort( sourceVersions, getSourceVersionComparator() );
+ SourceVersion latestSourceVersion = sourceVersions.get( 0 );
+ featureManager = mock( FeatureManager.class );
+ repositoryManager = mock( RepositoryManager.class );
+ when( p2UtilMock.getFeatureManager() ).thenReturn( featureManager );
+ when( p2UtilMock.getRepositoryManager() ).thenReturn( repositoryManager );
+ IStatus status = configuratorService.updateWorld();
+ verify( featureManager, atLeastOnce() ).uninstallFeature( latestSourceVersion );
+ verify( repositoryManager, atLeastOnce() ).addRepository( new URI( latestSourceVersion.getRepositoryUrl() ) );
+ assertTrue( status.isOK() );
+ }
+
+ @Test
+ public void testUpdateWorldNoUpdateAvailable()
+ throws CoreException, FeatureInstallException, URISyntaxException
+ {
+ List<SourceVersion> sourceVersions = sourceProvider.getSources().get( 0 ).getVersions();
+ Collections.sort( sourceVersions, getSourceVersionComparator() );
+ SourceVersion latestSourceVersion = sourceVersions.get( 0 );
+ featureManager = mock( FeatureManager.class );
+ repositoryManager = mock( RepositoryManager.class );
+ when( p2UtilMock.getFeatureManager() ).thenReturn( featureManager );
+ when( p2UtilMock.getRepositoryManager() ).thenReturn( repositoryManager );
+ when( featureManager.isInstalled( latestSourceVersion ) ).thenReturn( true );
+ IStatus status = configuratorService.updateWorld();
+ verify( featureManager, never() ).uninstallFeature( latestSourceVersion );
+ verify( repositoryManager, never() ).addRepository( new URI( latestSourceVersion.getRepositoryUrl() ) );
+ assertTrue( status.isOK() );
+ }
+
+ @Test
+ public void testUpdateAvailable()
+ throws CoreException, FeatureInstallException, URISyntaxException
+ {
+ List<String> iusToUpdate = new ArrayList<String>();
+ iusToUpdate.add( "rap" );
+ List<SourceVersion> sourceVersions = sourceProvider.getSources().get( 0 ).getVersions();
+ Collections.sort( sourceVersions, getSourceVersionComparator() );
+ SourceVersion latestSourceVersion = sourceVersions.get( 0 );
+ featureManager = mock( FeatureManager.class );
+ repositoryManager = mock( RepositoryManager.class );
+ when( p2UtilMock.getFeatureManager() ).thenReturn( featureManager );
+ when( p2UtilMock.getRepositoryManager() ).thenReturn( repositoryManager );
+ IStatus status = configuratorService.update( iusToUpdate );
+ verify( featureManager, atLeastOnce() ).uninstallFeature( latestSourceVersion );
+ verify( repositoryManager, atLeastOnce() ).addRepository( new URI( latestSourceVersion.getRepositoryUrl() ) );
+ assertTrue( status.isOK() );
+ }
+
+ @Test
+ public void testUpdateNoUpdateAvailable()
+ throws CoreException, FeatureInstallException, URISyntaxException
+ {
+ List<String> iusToUpdate = new ArrayList<String>();
+ iusToUpdate.add( "rap" );
+ List<SourceVersion> sourceVersions = sourceProvider.getSources().get( 0 ).getVersions();
+ Collections.sort( sourceVersions, getSourceVersionComparator() );
+ SourceVersion latestSourceVersion = sourceVersions.get( 0 );
+ featureManager = mock( FeatureManager.class );
+ repositoryManager = mock( RepositoryManager.class );
+ when( p2UtilMock.getFeatureManager() ).thenReturn( featureManager );
+ when( p2UtilMock.getRepositoryManager() ).thenReturn( repositoryManager );
+ when( featureManager.isInstalled( latestSourceVersion ) ).thenReturn( true );
+ IStatus status = configuratorService.update( iusToUpdate );
+ verify( featureManager, never() ).uninstallFeature( latestSourceVersion );
+ verify( repositoryManager, never() ).addRepository( new URI( latestSourceVersion.getRepositoryUrl() ) );
+ assertTrue( status.isOK() );
+ }
+
+ private Comparator<SourceVersion> getSourceVersionComparator() {
+ Comparator<SourceVersion> comparator = new Comparator<SourceVersion>() {
+
+ @Override
+ public int compare( SourceVersion arg0, SourceVersion arg1 ) {
+ String version = arg0.getVersion();
+ String version2 = arg1.getVersion();
+ return new Version( version2 ).compareTo( new Version( version ) );
+ }
+ };
+ return comparator;
+ }
}
diff --git a/core/org.eclipes.rtp.core/META-INF/MANIFEST.MF b/core/org.eclipes.rtp.core/META-INF/MANIFEST.MF
index 4a269f3..3da4ab7 100644
--- a/core/org.eclipes.rtp.core/META-INF/MANIFEST.MF
+++ b/core/org.eclipes.rtp.core/META-INF/MANIFEST.MF
@@ -5,6 +5,5 @@ Bundle-SymbolicName: org.eclipes.rtp.core
Bundle-Version: 1.0.0.qualifier
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/core/org.eclipse.rtp.core.service.provider/OSGI-INF/rtpConfiguratorServiceProvider.xml b/core/org.eclipse.rtp.core.service.provider/OSGI-INF/rtpConfiguratorServiceProvider.xml
index 281af20..f72610f 100644
--- a/core/org.eclipse.rtp.core.service.provider/OSGI-INF/rtpConfiguratorServiceProvider.xml
+++ b/core/org.eclipse.rtp.core.service.provider/OSGI-INF/rtpConfiguratorServiceProvider.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.rtp.core.service.provider">
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="setUp" name="org.eclipse.rtp.core.service.provider">
<implementation class="org.eclipse.rtp.configurator.service.provider.internal.DefaultConfiguratorService"/>
<service>
<provide interface="org.eclipse.rtp.configurator.core.IConfiguratorService"/>
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 7e3c925..4bda33c 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
@@ -11,6 +11,7 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import org.eclipse.core.runtime.CoreException;
@@ -25,6 +26,7 @@ import org.eclipse.rtp.configurator.service.provider.internal.deploy.FeatureMana
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;
+import org.osgi.framework.Version;
public class DefaultConfiguratorService implements IConfiguratorService {
@@ -98,12 +100,6 @@ public class DefaultConfiguratorService implements IConfiguratorService {
}
@Override
- public IStatus update( List<String> anyListOf ) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
public IStatus remove( List<String> anyListOf ) {
FeatureManager featureManager = p2Util.getFeatureManager();
List<SourceVersion> sourceVersionsToUnisntall = getSourceVersionsToUninstall( anyListOf,
@@ -174,6 +170,68 @@ public class DefaultConfiguratorService implements IConfiguratorService {
return sourcesAsString;
}
+ @Override
+ public IStatus update( List<String> anyListOf ) {
+ List<Source> sources = ConfiguratorModelUtil.getSourceProvider().getSources();
+ List<Source> sourceToUpdate = searchSources( anyListOf, sources );
+ IStatus result = updateSources( sourceToUpdate );
+ return result;
+ }
+
+ @Override
+ public IStatus updateWorld() {
+ List<Source> sources = ConfiguratorModelUtil.getSourceProvider().getSources();
+ IStatus result = updateSources( sources );
+ return result;
+ }
+
+ private IStatus updateSources( List<Source> sources ) {
+ List<IStatus> updateStatusList = new ArrayList<IStatus>();
+ FeatureManager featureManager = p2Util.getFeatureManager();
+ for( Source source : sources ) {
+ List<SourceVersion> versions = source.getVersions();
+ Collections.sort( versions, getSourceVersionComparator() );
+ SourceVersion latestSourceVersion = versions.get( 0 );
+ if( !featureManager.isInstalled( latestSourceVersion ) ) {
+ updateStatusList.addAll( uninstall( featureManager, versions ) );
+ List<String> parameters = getInstallParameters( source, latestSourceVersion );
+ updateStatusList.add( install( parameters ) );
+ }
+ }
+ IStatus result = new MultiStatus( ProviderActivator.BUNDLE_ID,
+ 0,
+ updateStatusList.toArray( new IStatus[ 0 ] ),
+ "Update status",
+ null );
+ return result;
+ }
+
+ private List<String> getInstallParameters( Source source, SourceVersion latestSourceVersion ) {
+ List<String> parameters = new ArrayList<String>();
+ parameters.add( source.getName() );
+ parameters.add( latestSourceVersion.getVersion() );
+ return parameters;
+ }
+
+ private Comparator<SourceVersion> getSourceVersionComparator() {
+ Comparator<SourceVersion> comparator = new Comparator<SourceVersion>() {
+
+ @Override
+ public int compare( SourceVersion arg0, SourceVersion arg1 ) {
+ String version = arg0.getVersion();
+ String version2 = arg1.getVersion();
+ return new Version( version2 ).compareTo( new Version( version ) );
+ }
+ };
+ return comparator;
+ }
+
+ @Override
+ public IStatus refresh() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
private List<Source> searchSources( List<String> anyListOf, List<Source> sources ) {
List<Source> result = new ArrayList<Source>();
for( Source source : sources ) {
@@ -195,16 +253,4 @@ public class DefaultConfiguratorService implements IConfiguratorService {
Collections.sort( sourcesAsString );
return sourcesAsString;
}
-
- @Override
- public IStatus updateWorld() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public IStatus refresh() {
- // TODO Auto-generated method stub
- return null;
- }
}
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 aa335de..5b26935 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
@@ -26,6 +26,7 @@ import org.eclipse.equinox.p2.operations.ProfileChangeOperation;
import org.eclipse.equinox.p2.operations.ProvisioningJob;
import org.eclipse.equinox.p2.operations.ProvisioningSession;
import org.eclipse.equinox.p2.operations.UninstallOperation;
+import org.eclipse.equinox.p2.query.IQueryResult;
import org.eclipse.equinox.p2.query.IQueryable;
import org.eclipse.equinox.p2.query.QueryUtil;
import org.eclipse.rtp.configurator.model.Feature;
@@ -151,7 +152,7 @@ public class FeatureManager {
Action action )
{
IQueryable<IInstallableUnit> queryable = action == Action.INSTALL
- ? context.getMetadata( null )
+ ? context.getMetadata( new NullProgressMonitor() )
: getProfile();
Collection<IInstallableUnit> toInstall = queryable.query( QueryUtil.createIUQuery( id,
Version.create( version ) ),
@@ -164,4 +165,16 @@ public class FeatureManager {
IProfileRegistry profileRegistry = ( IProfileRegistry )provisioningAgent.getService( IProfileRegistry.SERVICE_NAME );
return profileRegistry.getProfile( IProfileRegistry.SELF );
}
+
+ public boolean isInstalled( SourceVersion sourceVersion ) {
+ List<IInstallableUnit> result = new ArrayList<IInstallableUnit>();
+ IProfile profile = getProfile();
+ for( Feature feature : sourceVersion.getFeatures() ) {
+ IQueryResult<IInstallableUnit> query = profile.query( QueryUtil.createIUQuery( feature.getId(),
+ Version.create( feature.getVersion() ) ),
+ new NullProgressMonitor() );
+ result.addAll( query.toSet() );
+ }
+ return result.size() > 0;
+ }
}
diff --git a/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/RepositoryManager.java b/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/RepositoryManager.java
index 004b259..0692ae4 100644
--- a/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/RepositoryManager.java
+++ b/core/org.eclipse.rtp.core.service.provider/src/org/eclipse/rtp/configurator/service/provider/internal/deploy/RepositoryManager.java
@@ -1,12 +1,10 @@
-/*******************************************************************************
-* 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.BufferedOutputStream;
@@ -25,152 +23,149 @@ import org.apache.commons.io.FileUtils;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
-import org.eclipse.equinox.p2.repository.IRepository;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
public class RepositoryManager {
- private static final String LOCAL_REPOSITORY_PREFIX = "repo_"; //$NON-NLS-N$
- private static final String FILENAME_CONTENT = "content.jar"; //$NON-NLS-N$
- private static final String FILENAME_ARTIFACTS = "artifacts.jar"; //$NON-NLS-N$
- private static final int FILE_BUFFER = 8192;
- private final IProvisioningAgent provisioningAgent;
-
- public RepositoryManager(IProvisioningAgent provisioningAgent) {
- this.provisioningAgent = provisioningAgent;
- }
-
- public URI[] getRepositories() {
- IMetadataRepositoryManager metaRepoManager = getMetadataRepositoryManager();
-
- return metaRepoManager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL);
- }
-
- public List<IMetadataRepository> getMetadataRepositories() throws ProvisionException, OperationCanceledException {
- List<IMetadataRepository> result = new ArrayList<IMetadataRepository>();
- IMetadataRepositoryManager metaRepoManager = getMetadataRepositoryManager();
- URI[] knownRepositories = metaRepoManager.getKnownRepositories(IMetadataRepositoryManager.REPOSITORIES_ALL);
- for (URI uri : knownRepositories) {
- IMetadataRepository repository = metaRepoManager.loadRepository(uri, null);
- result.add(repository);
- }
- return result;
- }
-
-
- public void addRepository(URI repository) {
- IMetadataRepositoryManager metaRepoManager = getMetadataRepositoryManager();
- IArtifactRepositoryManager artiRepoManager = getArtifactRepositoryManager();
-
- metaRepoManager.addRepository(repository);
- artiRepoManager.addRepository(repository);
- }
-
- public URI addRepository(InputStream inputStream) throws InvalidRepositoryException, FileNotFoundException, IOException {
- ZipInputStream zis = new ZipInputStream(inputStream);
- File repository = createLocalRepository(zis);
- URI repositoryURI = repository.toURI();
- addRepository(repositoryURI);
-
- return repositoryURI;
- }
-
- private File createLocalRepository(ZipInputStream zis) throws InvalidRepositoryException, IOException, FileNotFoundException {
- File repository = new File(System.getProperty("java.io.tmpdir") + File.separator + LOCAL_REPOSITORY_PREFIX
- + Long.toString(System.nanoTime()));
- repository.mkdirs();
- createLocalRepositoryStructure(zis, repository);
-
- try {
- validateLocalRepository(repository);
- } catch (InvalidRepositoryException e) {
- FileUtils.deleteDirectory(repository);
- throw e;
- }
-
- return repository;
- }
-
- public void removeRepository(URI repository) {
- IMetadataRepositoryManager metaRepoManager = getMetadataRepositoryManager();
- IArtifactRepositoryManager artiRepoManager = getArtifactRepositoryManager();
-
- metaRepoManager.removeRepository(repository);
- artiRepoManager.removeRepository(repository);
- }
-
- private void createLocalRepositoryStructure(ZipInputStream zis, File repository) throws IOException, FileNotFoundException {
- ZipEntry currentFile;
- while ((currentFile = zis.getNextEntry()) != null) {
- if (currentFile.isDirectory()) {
- createLocalDirectory(repository, currentFile);
- } else {
- createLocalFile(zis, repository, currentFile);
- }
- }
- }
-
- private void createLocalDirectory(File repository, ZipEntry currentFile) {
- File file = new File(repository.getAbsolutePath() + File.separator + currentFile.getName());
- file.mkdirs();
- }
-
- private void createLocalFile(ZipInputStream zis, File repository, ZipEntry currentFile) throws IOException,
- FileNotFoundException {
- File file = new File(repository.getAbsolutePath() + File.separator + currentFile.getName());
- file.getParentFile().mkdirs();
- file.createNewFile();
- FileOutputStream fos = new FileOutputStream(file);
- BufferedOutputStream bfos = new BufferedOutputStream(fos, FILE_BUFFER);
- saveFileData(zis, bfos);
- }
-
- private void saveFileData(ZipInputStream zis, BufferedOutputStream bfos) throws IOException {
- int resultLength;
- byte[] data = new byte[FILE_BUFFER];
- while ((resultLength = zis.read(data, 0, FILE_BUFFER)) != -1) {
- bfos.write(data, 0, resultLength);
- }
- bfos.flush();
- bfos.close();
- }
-
- public void validateLocalRepository(File repository) throws InvalidRepositoryException {
- File[] files = repository.listFiles();
- boolean artifactsFound = false;
- boolean contentFound = false;
-
- for (File file : files) {
- if (file.getName().equals(FILENAME_ARTIFACTS)) {
- artifactsFound = true;
- } else if (file.getName().equals(FILENAME_CONTENT)) {
- contentFound = true;
- }
- }
-
- if (!artifactsFound || !contentFound) {
- throw new InvalidRepositoryException("invalid repository: required files not found");
- }
- }
-
- public IMetadataRepositoryManager getMetadataRepositoryManager() {
- IMetadataRepositoryManager service = (IMetadataRepositoryManager) provisioningAgent
- .getService(IMetadataRepositoryManager.SERVICE_NAME);
-
- return service;
- }
-
- public IArtifactRepositoryManager getArtifactRepositoryManager() {
- IArtifactRepositoryManager service = (IArtifactRepositoryManager) provisioningAgent
- .getService(IArtifactRepositoryManager.SERVICE_NAME);
-
- return service;
- }
-
- public void removeLocalRepository(URI repository) throws IOException {
- FileUtils.deleteDirectory(new File(repository));
- removeRepository(repository);
- }
-} \ No newline at end of file
+ private static final String LOCAL_REPOSITORY_PREFIX = "repo_"; //$NON-NLS-N$
+ private static final String FILENAME_CONTENT = "content.jar"; //$NON-NLS-N$
+ private static final String FILENAME_ARTIFACTS = "artifacts.jar"; //$NON-NLS-N$
+ private static final int FILE_BUFFER = 8192;
+ private final IProvisioningAgent provisioningAgent;
+
+ public RepositoryManager( IProvisioningAgent provisioningAgent ) {
+ this.provisioningAgent = provisioningAgent;
+ }
+
+ public URI[] getRepositories() {
+ IMetadataRepositoryManager metaRepoManager = getMetadataRepositoryManager();
+ return metaRepoManager.getKnownRepositories( IMetadataRepositoryManager.REPOSITORIES_ALL );
+ }
+
+ public List<IMetadataRepository> getMetadataRepositories()
+ throws ProvisionException, OperationCanceledException
+ {
+ List<IMetadataRepository> result = new ArrayList<IMetadataRepository>();
+ IMetadataRepositoryManager metaRepoManager = getMetadataRepositoryManager();
+ URI[] knownRepositories = metaRepoManager.getKnownRepositories( IMetadataRepositoryManager.REPOSITORIES_ALL );
+ for( URI uri : knownRepositories ) {
+ IMetadataRepository repository = metaRepoManager.loadRepository( uri, null );
+ result.add( repository );
+ }
+ return result;
+ }
+
+ public void addRepository( URI repository ) {
+ IMetadataRepositoryManager metaRepoManager = getMetadataRepositoryManager();
+ IArtifactRepositoryManager artiRepoManager = getArtifactRepositoryManager();
+ metaRepoManager.addRepository( repository );
+ artiRepoManager.addRepository( repository );
+ }
+
+ public URI addRepository( InputStream inputStream )
+ throws InvalidRepositoryException, FileNotFoundException, IOException
+ {
+ ZipInputStream zis = new ZipInputStream( inputStream );
+ File repository = createLocalRepository( zis );
+ URI repositoryURI = repository.toURI();
+ addRepository( repositoryURI );
+ return repositoryURI;
+ }
+
+ private File createLocalRepository( ZipInputStream zis )
+ throws InvalidRepositoryException, IOException, FileNotFoundException
+ {
+ File repository = new File( System.getProperty( "java.io.tmpdir" )
+ + File.separator
+ + LOCAL_REPOSITORY_PREFIX
+ + Long.toString( System.nanoTime() ) );
+ repository.mkdirs();
+ createLocalRepositoryStructure( zis, repository );
+ try {
+ validateLocalRepository( repository );
+ } catch( InvalidRepositoryException e ) {
+ FileUtils.deleteDirectory( repository );
+ throw e;
+ }
+ return repository;
+ }
+
+ public void removeRepository( URI repository ) {
+ IMetadataRepositoryManager metaRepoManager = getMetadataRepositoryManager();
+ IArtifactRepositoryManager artiRepoManager = getArtifactRepositoryManager();
+ metaRepoManager.removeRepository( repository );
+ artiRepoManager.removeRepository( repository );
+ }
+
+ private void createLocalRepositoryStructure( ZipInputStream zis, File repository )
+ throws IOException, FileNotFoundException
+ {
+ ZipEntry currentFile;
+ while( ( currentFile = zis.getNextEntry() ) != null ) {
+ if( currentFile.isDirectory() ) {
+ createLocalDirectory( repository, currentFile );
+ } else {
+ createLocalFile( zis, repository, currentFile );
+ }
+ }
+ }
+
+ private void createLocalDirectory( File repository, ZipEntry currentFile ) {
+ File file = new File( repository.getAbsolutePath() + File.separator + currentFile.getName() );
+ file.mkdirs();
+ }
+
+ private void createLocalFile( ZipInputStream zis, File repository, ZipEntry currentFile )
+ throws IOException, FileNotFoundException
+ {
+ File file = new File( repository.getAbsolutePath() + File.separator + currentFile.getName() );
+ file.getParentFile().mkdirs();
+ file.createNewFile();
+ FileOutputStream fos = new FileOutputStream( file );
+ BufferedOutputStream bfos = new BufferedOutputStream( fos, FILE_BUFFER );
+ saveFileData( zis, bfos );
+ }
+
+ private void saveFileData( ZipInputStream zis, BufferedOutputStream bfos ) throws IOException {
+ int resultLength;
+ byte[] data = new byte[ FILE_BUFFER ];
+ while( ( resultLength = zis.read( data, 0, FILE_BUFFER ) ) != -1 ) {
+ bfos.write( data, 0, resultLength );
+ }
+ bfos.flush();
+ bfos.close();
+ }
+
+ public void validateLocalRepository( File repository ) throws InvalidRepositoryException {
+ File[] files = repository.listFiles();
+ boolean artifactsFound = false;
+ boolean contentFound = false;
+ for( File file : files ) {
+ if( file.getName().equals( FILENAME_ARTIFACTS ) ) {
+ artifactsFound = true;
+ } else if( file.getName().equals( FILENAME_CONTENT ) ) {
+ contentFound = true;
+ }
+ }
+ if( !artifactsFound || !contentFound ) {
+ throw new InvalidRepositoryException( "invalid repository: required files not found" );
+ }
+ }
+
+ public IMetadataRepositoryManager getMetadataRepositoryManager() {
+ IMetadataRepositoryManager service = ( IMetadataRepositoryManager )provisioningAgent.getService( IMetadataRepositoryManager.SERVICE_NAME );
+ return service;
+ }
+
+ public IArtifactRepositoryManager getArtifactRepositoryManager() {
+ IArtifactRepositoryManager service = ( IArtifactRepositoryManager )provisioningAgent.getService( IArtifactRepositoryManager.SERVICE_NAME );
+ return service;
+ }
+
+ public void removeLocalRepository( URI repository ) throws IOException {
+ FileUtils.deleteDirectory( new File( repository ) );
+ removeRepository( repository );
+ }
+}
diff --git a/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 5fc4532..3e874ac 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
@@ -9,7 +9,7 @@ public class ConfiguratorModelUtil {
private static SourceUnMarshaller sourceUnMarshaller;
private static SourceProvider sourceProvider;
- private static String defaultModeURL = "http://foo";
+ private static String defaultModeURL = "file:///C:/Users/bveliev/org.eclipse.rtp/core/org.eclipse.rtp.core.service.provider/data/real-sources.json";
public static void setUnMarshaller( SourceUnMarshaller sourceUnMarshaller ) {
ConfiguratorModelUtil.sourceUnMarshaller = sourceUnMarshaller;
@@ -22,13 +22,13 @@ public class ConfiguratorModelUtil {
public static SourceUnMarshaller getSourceUnMarshaller() {
return sourceUnMarshaller;
}
-
- public static void setSourceProvider(SourceProvider sourceProvider){
+
+ public static void setSourceProvider( SourceProvider sourceProvider ) {
ConfiguratorModelUtil.sourceProvider = sourceProvider;
}
-
- public static SourceProvider getSourceProvider(){
- if(sourceProvider == null){
+
+ public static SourceProvider getSourceProvider() {
+ if( sourceProvider == null ) {
sourceProvider = getDefaultModel();
}
return ConfiguratorModelUtil.sourceProvider;
@@ -38,13 +38,11 @@ public class ConfiguratorModelUtil {
SourceProvider result = null;
try {
URL url = new URL( defaultModeURL );
- result = sourceUnMarshaller.marshal( url.openStream( ) );
+ result = sourceUnMarshaller.marshal( url.openStream() );
} catch( Exception e ) {
- System.out.println("Failed to load model");
+ System.out.println( "Failed to load model" );
e.printStackTrace();
}
return result;
}
-
-
}