--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.project.management;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.net.URI;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.Collections;\r
+import java.util.HashMap;\r
+import java.util.HashSet;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
+import java.util.jar.Manifest;\r
+\r
+import org.eclipse.core.runtime.IPath;\r
+import org.eclipse.core.runtime.IProgressMonitor;\r
+import org.eclipse.core.runtime.IStatus;\r
+import org.eclipse.core.runtime.Path;\r
+import org.eclipse.core.runtime.Platform;\r
+import org.eclipse.core.runtime.Status;\r
+import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;\r
+import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository;\r
+import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepositoryFactory;\r
+import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository;\r
+import org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository;\r
+import org.eclipse.equinox.internal.p2.metadata.repository.SimpleMetadataRepositoryFactory;\r
+import org.eclipse.equinox.p2.core.IProvisioningAgent;\r
+import org.eclipse.equinox.p2.core.ProvisionException;\r
+import org.eclipse.equinox.p2.internal.repository.mirroring.Mirroring;\r
+import org.eclipse.equinox.p2.metadata.IArtifactKey;\r
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;\r
+import org.eclipse.equinox.p2.metadata.IVersionedId;\r
+import org.eclipse.equinox.p2.metadata.VersionedId;\r
+import org.eclipse.equinox.p2.query.IQuery;\r
+import org.eclipse.equinox.p2.query.IQueryResult;\r
+import org.eclipse.equinox.p2.query.QueryUtil;\r
+import org.eclipse.equinox.p2.repository.artifact.ArtifactKeyQuery;\r
+import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;\r
+import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;\r
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;\r
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;\r
+import org.simantics.graph.db.TransferableGraphException;\r
+import org.simantics.graph.query.Graphs;\r
+import org.simantics.graph.query.IGraph;\r
+import org.simantics.graph.query.Paths;\r
+import org.simantics.graph.query.Res;\r
+import org.simantics.graph.query.UriUtils;\r
+import org.simantics.graph.representation.TransferableGraph1;\r
+import org.simantics.scl.reflection.OntologyVersions;\r
+import org.simantics.utils.FileUtils;\r
+\r
+/**\r
+ * Bundlepool is a repository of artifacts and installable units. \r
+ *\r
+ * @author Toni Kalajainen <toni.kalajainen@vtt.fi>\r
+ */\r
+@SuppressWarnings("restriction")\r
+public class BundlePool {\r
+\r
+ /** Application default pool. It is located at "workspace/bundlepool" */\r
+ static BundlePool DEFAULT; \r
+\r
+ IMetadataRepository metadataRepository; \r
+ IArtifactRepository artifactRepository;\r
+ IProvisioningAgent metadataAgent;\r
+ IProvisioningAgent artifactAgent;\r
+ URI metadataAgentLocation;\r
+ URI artifactAgentLocation;\r
+ \r
+ List<BundleInfo> userInstallables;\r
+\r
+ /** All features that were discovered in the repository */\r
+ Set<FeatureInfo> projectFeatures = new HashSet<FeatureInfo>(); \r
+ \r
+ /**\r
+ * Get SPM Bundle Pool\r
+ * \r
+ * @return SPM Bundle Pool\r
+ */\r
+ public synchronized static BundlePool getDefault() {\r
+ if (DEFAULT == null) {\r
+ try {\r
+ IPath path = Platform.getLocation().append("bundlepool");\r
+ URI metadataRepositoryLocation = path.toFile().toURI();\r
+ URI artifactRepositoryLocation = path.toFile().toURI();\r
+ IProvisioningAgent agent = P2Util.createAgent( path ); \r
+ DEFAULT = new BundlePool(metadataRepositoryLocation, artifactRepositoryLocation, agent);\r
+ } catch (ProvisionException e) {\r
+ // Not expected\r
+ throw new RuntimeException(e);\r
+ }\r
+ }\r
+ return DEFAULT;\r
+ }\r
+\r
+ /**\r
+ * Create bundle pool in a directory on a local hard drive. \r
+ * This location will contain metadata repository, artifact repository and \r
+ * P2 workarea (Agent).\r
+ * \r
+ * @param location\r
+ * @return bundle pool\r
+ */\r
+ public static BundlePool createAt(File location) { \r
+ try {\r
+ File canonicalLocation = location.getCanonicalFile();\r
+ URI metadataRepositoryLocation = canonicalLocation.toURI();\r
+ URI artifactRepositoryLocation = canonicalLocation.toURI();\r
+ IPath agentLocation = new Path( canonicalLocation.toString() );\r
+ IProvisioningAgent agent = P2Util.createAgent( agentLocation ); \r
+ return new BundlePool(metadataRepositoryLocation, artifactRepositoryLocation, agent); \r
+ } catch (IOException e) {\r
+ throw new RuntimeException(e);\r
+ } catch (org.eclipse.equinox.p2.core.ProvisionException e) {\r
+ throw new RuntimeException(e);\r
+ }\r
+ \r
+ }\r
+ \r
+ public BundlePool(URI metadataRepositoryLocation, URI artifactRepositoryLocation, IProvisioningAgent agent) throws ProvisionException {\r
+ \r
+ this.metadataAgent = agent;\r
+ this.artifactAgent = agent;\r
+ \r
+ SimpleMetadataRepositoryFactory metRepFactory = new SimpleMetadataRepositoryFactory();\r
+ metRepFactory.setAgent( metadataAgent ); \r
+ try {\r
+ metadataRepository = metRepFactory.load(metadataRepositoryLocation, 0, null);\r
+ } catch (org.eclipse.equinox.p2.core.ProvisionException pe) {\r
+ new File(metadataRepositoryLocation).mkdirs();\r
+ Map<String, String> repoProperties = new HashMap<String, String>();\r
+ metadataRepository = metRepFactory.create(metadataRepositoryLocation, "SPM Bundle Pool", "file", repoProperties);\r
+ }\r
+ \r
+ // IMetadataRepository metadataRepository = new LocalMetadataRepository( agent, repositoryLocation, "My Metadata Repository", Collections.EMPTY_MAP );\r
+ // IMetadataRepository metadataRepository = getMetadataRepository(agent, repositoryLocation);\r
+ \r
+// IArtifactRepository artifactRepository = new SimpleArtifactRepositoryFactory().create(repositoryLocation, "Sample Artifact Repository", ArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, Collections.EMPTY_MAP);\r
+// SimpleArtifactRepository artifactRepository = new SimpleArtifactRepository( agent, "My Simple Artifact Repository", repositoryLocation, Collections.EMPTY_MAP);\r
+ SimpleArtifactRepositoryFactory artRepFactory = new SimpleArtifactRepositoryFactory();\r
+ artRepFactory.setAgent( artifactAgent );\r
+ \r
+ try {\r
+ artifactRepository = artRepFactory.load(artifactRepositoryLocation, 0, null);\r
+ } catch (org.eclipse.equinox.p2.core.ProvisionException pe) {\r
+ new File(artifactRepositoryLocation).mkdirs();\r
+ Map<String, String> repoProperties = new HashMap<String, String>();\r
+ artifactRepository = artRepFactory.create(artifactRepositoryLocation, "SPM Bundle Pool", "file", repoProperties);\r
+ }\r
+ \r
+ init();\r
+ }\r
+ \r
+ public BundlePool(IMetadataRepository metadataRepository, IArtifactRepository artifactRepository) throws ProvisionException {\r
+ this.metadataRepository = metadataRepository;\r
+ this.artifactRepository = artifactRepository;\r
+ this.metadataAgent = metadataRepository.getProvisioningAgent();\r
+ this.artifactAgent = artifactRepository.getProvisioningAgent();\r
+ init();\r
+ }\r
+ \r
+ /**\r
+ * Init prepares with the following actions:\r
+ * o loads transferable graphs\r
+ * o discovers Features and collects Feature URIs, Artifacts and Installable Units\r
+ * \r
+ * @throws ProvisionException \r
+ */\r
+ protected void init() throws ProvisionException {\r
+ try {\r
+ projectFeatures.clear();\r
+ \r
+ ArrayList<TransferableGraph1> platformTGs = new ArrayList<TransferableGraph1>();\r
+ \r
+ for (IArtifactKey key : getAllArtifactKeys()) {\r
+ boolean hasGraph = ProvisioningUtil.hasFile(artifactRepository, key, "graph.tg");\r
+ if (!hasGraph) continue;\r
+ \r
+ // Read Graph\r
+ TransferableGraph1 graph = ProvisioningUtil.getTransferableGraph(artifactRepository, key);\r
+ platformTGs.add(graph);\r
+ }\r
+ \r
+ // Create new project, use all features available in Platform\r
+ final List<String> poolFeatures = new ArrayList<String>();\r
+ \r
+ // Convert graph instances\r
+ GraphBundleEx l0 = getLayer0();\r
+ String l0v = l0.getMajor() + "." + l0.getMinor();\r
+ IGraph graph = Graphs.createGraph(new Paths(l0v), platformTGs);\r
+ \r
+ for(Res feature : graph.getInstances(UriUtils.uriToPath(OntologyVersions.getInstance().currentVersion("http://www.simantics.org/Project-0.0/Feature" )))) {\r
+ poolFeatures.add( feature.toString() );\r
+ } \r
+ \r
+ } catch (TransferableGraphException e) {\r
+ throw new ProvisionException("Problem", e);\r
+ } catch (IOException e) {\r
+ throw new ProvisionException("Failed to read graph.tg", e);\r
+ }\r
+ }\r
+ \r
+ public IMetadataRepository getMetadataRepository() {\r
+ return metadataRepository;\r
+ }\r
+ \r
+ public IArtifactRepository getArtifactRepository() {\r
+ return artifactRepository;\r
+ }\r
+ \r
+ public IArtifactKey[] getAllArtifactKeys() {\r
+ return artifactRepository.query( ArtifactKeyQuery.ALL_KEYS, null ).toArray( IArtifactKey.class );\r
+ }\r
+ \r
+ public GraphBundleEx getLayer0() throws ProvisionException, TransferableGraphException {\r
+ IVersionedId vid = VersionedId.parse("org.simantics.layer0");\r
+ Set<IInstallableUnit> result = metadataRepository.query( QueryUtil.createLatestQuery( QueryUtil.createIUQuery(vid) ), null).toSet();\r
+ if (result.isEmpty()) throw new RuntimeException("Unexpectedly got no IU for "+vid);\r
+ if (result.size()>1) throw new RuntimeException("Unexpectedly got more than one latest IU for "+vid);\r
+ IInstallableUnit iu = result.iterator().next();\r
+ IArtifactKey key = toSingleArtifact(iu);\r
+ TransferableGraph1 graph = getTransferableGraph( key );\r
+ return new GraphBundleEx( "Layer0", graph, key);\r
+ } \r
+ \r
+ public TransferableGraph1 getTransferableGraph(IArtifactKey artifactKey) throws ProvisionException, TransferableGraphException {\r
+ return ProvisioningUtil.getTransferableGraph( artifactRepository, artifactKey);\r
+ }\r
+\r
+ \r
+ \r
+ /**\r
+ * Get all features.\r
+ * \r
+ * @param a list of features\r
+ * @throws ProvisionException \r
+ */\r
+ public void getFeatures(List<BundleInfo> features) throws ProvisionException {\r
+ IMetadataRepository metadataRepository = getMetadataRepository();\r
+ \r
+ Collection<IInstallableUnit> ius = ProvisioningUtil.getInstallableUnits(metadataRepository); \r
+ for (IInstallableUnit iu : ius) { \r
+ if (ProvisioningUtil.isGroup(iu)) {\r
+// if (P2Util.isFeature(iu)) {\r
+ BundleInfo b = BundleInfo.read(iu);\r
+ features.add( b );\r
+ }\r
+ } \r
+ }\r
+ \r
+ /**\r
+ * Get bundle info\r
+ * \r
+ * @param id bundle id\r
+ * @return bundle info\r
+ */\r
+ public BundleInfo getBundleInfo(String id) {\r
+ IQuery<IInstallableUnit> query = QueryUtil.createLatestQuery( QueryUtil.createIUQuery(id) );\r
+ IQueryResult<IInstallableUnit> queryResult = metadataRepository.query(query, null);\r
+ IInstallableUnit[] array = queryResult.toArray( IInstallableUnit.class );\r
+ for (IInstallableUnit iu : array) {\r
+ BundleInfo bi = BundleInfo.read(iu);\r
+ return bi;\r
+ }\r
+ return null;\r
+ }\r
+ \r
+ /**\r
+ * Get the features that visible for the end-user.\r
+ * User installable features are configured in Simantics manifest files\r
+ * (META-INF/SIMANTICS.MF as Simantics-Features-Bundle -property)\r
+ * \r
+ * @param result\r
+ * @throws IOException \r
+ */\r
+// public void getUserInstallableFeatures(Collection<BundleInfo> result) throws IOException {\r
+// ArrayList<String> ids = new ArrayList<String>();\r
+// ProvisioningUtil.getUserInstallables(artifactRepository, ids);\r
+// for (String id : ids) {\r
+// BundleInfo bi = getBundleInfo(id);\r
+// if (bi != null) result.add( bi );\r
+// }\r
+// // Add workspace bundle\r
+// BundleInfo bi = getBundleInfo( "org.simantics.workbench.product" );\r
+// if (bi != null) result.add( bi );\r
+// }\r
+ \r
+ /**\r
+ * Get all groups.\r
+ * \r
+ * @param a list of features\r
+ * @throws ProvisionException \r
+ */\r
+// public void getInstallableFeatures(List<BundleInfo> features) throws ProvisionException {\r
+// IMetadataRepository metadataRepository = getMetadataRepository();\r
+// \r
+// Collection<IInstallableUnit> ius = ProvisioningUtil.getInstallableUnits(metadataRepository); \r
+// for (IInstallableUnit iu : ius) { \r
+// if (ProvisioningUtil.isGroup(iu)) {\r
+//// if (P2Util.isFeature(iu)) {\r
+// BundleInfo b = BundleInfo.read(iu);\r
+// features.add( b );\r
+// }\r
+// } \r
+// }\r
+\r
+ /**\r
+ * Mirror source locations to the bundle pool.\r
+ * \r
+ * @param monitor\r
+ * @param sourceLocations\r
+ * @return\r
+ * @throws ProvisionException\r
+ */\r
+ public IStatus download(IProgressMonitor monitor, URI[] sourceLocations) throws ProvisionException {\r
+ try {\r
+ monitor.beginTask("Synchronizing Local repository with web repositories", 10); \r
+ \r
+ @SuppressWarnings("unused")\r
+ IMetadataRepositoryManager metaRepoMgr = (IMetadataRepositoryManager) metadataAgent.getService(IMetadataRepositoryManager.SERVICE_NAME);\r
+ @SuppressWarnings("unused")\r
+ IArtifactRepositoryManager artsRepoMgr = (IArtifactRepositoryManager) artifactAgent.getService(IArtifactRepositoryManager.SERVICE_NAME);\r
+ \r
+ \r
+ // Create dest repos\r
+ monitor.setTaskName("Setting up local metadata repository");\r
+ LocalMetadataRepository dstMetaRepo = (LocalMetadataRepository) metadataRepository;\r
+ monitor.worked(1);\r
+ \r
+ monitor.setTaskName("Setting up local artifact repository");\r
+ SimpleArtifactRepository dstArtsRepo = (SimpleArtifactRepository) artifactRepository;\r
+ monitor.worked(1);\r
+ \r
+ // Create a source repos\r
+ monitor.setTaskName("Setting up remote artifact repository");\r
+ CompositeArtifactRepository srcArtsRepo = CompositeArtifactRepository.createMemoryComposite( metadataAgent /* ? */ );\r
+ for (URI uri : sourceLocations) srcArtsRepo.addChild(uri);\r
+ monitor.worked(1);\r
+ \r
+ monitor.setTaskName("Setting up remote metadata repository"); \r
+ CompositeMetadataRepository srcMetaRepo = CompositeMetadataRepository.createMemoryComposite( artifactAgent /* ? */ );\r
+ for (URI uri : sourceLocations) srcMetaRepo.addChild(uri);\r
+ monitor.worked(1);\r
+ \r
+ monitor.setTaskName("Retrieving Installable Units");\r
+ @SuppressWarnings("unused")\r
+ Collection<IInstallableUnit> ius = ProvisioningUtil.getInstallableUnits(srcMetaRepo);\r
+ monitor.worked(1);\r
+ \r
+ monitor.setTaskName("Mirroring Metadata");\r
+ // Get all IUs from source\r
+ IQueryResult<IInstallableUnit> allIUs = srcMetaRepo.query(QueryUtil.createIUAnyQuery(), monitor);\r
+ // Put the IUs to dst\r
+ dstMetaRepo.addInstallableUnits(allIUs.toUnmodifiableSet());\r
+ dstMetaRepo.addReferences(srcMetaRepo.getReferences());\r
+ monitor.worked(1);\r
+ \r
+ monitor.setTaskName("Mirroring Artifacts");\r
+ \r
+ boolean compare = false;\r
+ boolean failOnError = true;\r
+ //boolean raw = true;\r
+ boolean verbose = false;\r
+ boolean validate = false;\r
+ //boolean mirrorReferences = false;\r
+ String comparatorID = "";\r
+ \r
+ Mirroring mirror = new Mirroring(srcArtsRepo, dstArtsRepo, false);\r
+ mirror.setCompare(compare);\r
+ mirror.setComparatorId(comparatorID);\r
+ // mirror.setBaseline(null);\r
+ mirror.setValidate(validate);\r
+ // mirror.setCompareExclusions();\r
+ \r
+ IStatus result = mirror.run(failOnError, verbose);\r
+ if (result.getException()!=null)\r
+ throw new ProvisionException(result);\r
+ \r
+ init();\r
+ \r
+ return result;\r
+ } catch (IllegalArgumentException iae) {\r
+ return new Status(IStatus.ERROR, "org.simantics.project", iae.getMessage(), iae);\r
+ }\r
+ }\r
+\r
+ public IInstallableUnit toSingleInstallableUnit(IVersionedId id) throws ProvisionException {\r
+ Set<IInstallableUnit> result = metadataRepository.query( QueryUtil.createIUQuery(id), null).toSet();\r
+ if (result.size() != 1) throw new RuntimeException("Unexpectedly got more than one latest IU for "+id); \r
+ return result.iterator().next(); \r
+ }\r
+\r
+ public IArtifactKey toSingleArtifact(IVersionedId id) throws ProvisionException {\r
+ IInstallableUnit iu = toSingleInstallableUnit(id);\r
+ if (iu.getArtifacts().size() != 1) throw new RuntimeException("Unexpectedly got more than one artifact for ");\r
+ return iu.getArtifacts().iterator().next();\r
+ }\r
+\r
+ /**\r
+ * Get file from an artifact.\r
+ * \r
+ * @param key\r
+ * @param filename\r
+ * @return inputstream or <tt>null</tt>. Inputstream must be closed.\r
+ * @throws IOException \r
+ */\r
+ public InputStream getFile(IArtifactKey key, String filename) throws IOException {\r
+ return ProvisioningUtil.getFile(artifactRepository, key, filename);\r
+ }\r
+ \r
+ /**\r
+ * Checks whether there exists a file in an artifact\r
+ * \r
+ * @param key\r
+ * @param filename\r
+ * @return true file exists in the artifact\r
+ * @throws IOException\r
+ */\r
+ public boolean hasFile(IArtifactKey key, String filename) throws IOException {\r
+ return ProvisioningUtil.hasFile(artifactRepository, key, filename);\r
+ }\r
+ \r
+ /**\r
+ * Get META-INF/MANIFEST.MF\r
+ * \r
+ * @param repo artifact repo\r
+ * @param key key to artifact\r
+ * @return manifest or null\r
+ * @throws IOException \r
+ */\r
+ public Manifest getManifest(IArtifactKey key) throws IOException {\r
+ return ProvisioningUtil.getManifest(artifactRepository, key);\r
+ }\r
+ \r
+ /**\r
+ * Get META-INF/SIMANTICS.MF \r
+ * \r
+ * @param repo artifact repo\r
+ * @param key key to artifact\r
+ * @return manifest or null\r
+ * @throws IOException \r
+ */\r
+ public Manifest getSimanticsManifest(IArtifactKey key) throws IOException {\r
+ return ProvisioningUtil.getManifest(artifactRepository, key);\r
+ }\r
+ \r
+ /**\r
+ * Get list of user installable bundles\r
+ * \r
+ * @param result\r
+ * @throws IOException\r
+ */\r
+ public void getUserInstallables(List<BundleInfo> result) throws IOException {\r
+ if (userInstallables==null) {\r
+ userInstallables = new ArrayList<BundleInfo>();\r
+ \r
+ List<String> topLevelBundles = new ArrayList<String>();\r
+ ProvisioningUtil.getUserInstallables(artifactRepository, topLevelBundles);\r
+ \r
+ for (String bundleId : topLevelBundles) {\r
+ IInstallableUnit ius[] = metadataRepository.query( QueryUtil.createIUQuery(bundleId) , null).toArray( IInstallableUnit.class );\r
+ for (IInstallableUnit iu : ius) {\r
+ userInstallables.add( BundleInfo.read(iu) );\r
+ }\r
+ } \r
+ \r
+ }\r
+ result.addAll(userInstallables);\r
+ }\r
+ \r
+ \r
+ \r
+ /////////// \r
+ /////////// GRAPHS\r
+ ///////////\r
+ \r
+\r
+ \r
+// /**\r
+// * Get graph bundles\r
+// * \r
+// * @param list to be populated with graph bundle ids\r
+// * @throws ProvisionException \r
+// * @throws IOException \r
+// */\r
+// public void getGraphs(List<BundleInfo> graphs) throws ProvisionException, IOException {\r
+// Collection<IInstallableUnit> ius = ProvisioningUtil.getInstallableUnits(metadataRepository); \r
+// for (IInstallableUnit iu : ius) {\r
+// if (isGraph(iu)) {\r
+// BundleInfo b = BundleInfo.read(iu);\r
+// graphs.add( b );\r
+// }\r
+// } \r
+// }\r
+\r
+ /**\r
+ * Get graph bundles\r
+ * \r
+ * @param list to be populated with graph bundle ids\r
+ * @throws ProvisionException \r
+ * @throws IOException \r
+ * @throws TransferableGraphException \r
+ */\r
+ public void getGraphBundles(List<GraphBundleEx> graphs) throws ProvisionException, IOException, TransferableGraphException {\r
+ Collection<IInstallableUnit> ius = ProvisioningUtil.getInstallableUnits(metadataRepository); \r
+ for (IInstallableUnit iu : ius) {\r
+ for (IArtifactKey key : iu.getArtifacts()) {\r
+ if (!ProvisioningUtil.isGraphArtifact(artifactRepository, key)) continue;\r
+ TransferableGraph1 tg = ProvisioningUtil.getTransferableGraph( artifactRepository, key );\r
+ GraphBundleEx b = new GraphBundleEx(iu.getId(), tg, key);\r
+ graphs.add( b );\r
+ }\r
+ } \r
+ }\r
+ \r
+ /**\r
+ * Get a list of all features. Features are uris, they are versionless. \r
+ * @return fetures\r
+ * @throws TransferableGraphException \r
+ * @throws IOException \r
+ */\r
+ public Set<FeatureInfo> getFeatures() throws IOException, TransferableGraphException {\r
+ /*\r
+ HashSet<FeatureInfo> result = new HashSet<FeatureInfo>();\r
+ Collection<IInstallableUnit> ius = ProvisioningUtil.getInstallableUnits(metadataRepository); \r
+ for (IInstallableUnit iu : ius) {\r
+ for (IArtifactKey key : iu.getArtifacts()) {\r
+ if (!ProvisioningUtil.isGraphArtifact(artifactRepository, key)) continue;\r
+ TransferableGraph1 tg = ProvisioningUtil.getTransferableGraph( artifactRepository, key );\r
+ IGraph g = Graphs.createGraph(tg);\r
+ \r
+ Res PublishedProjectFeatures = UriUtils.uriToPath( ProjectResource.URIs.PublishedProjectFeatures );\r
+ Path HasFeature = UriUtils.uriToPath( ProjectResource.URIs.HasFeature );\r
+ for(Res feature : g.getObjects(PublishedProjectFeatures, HasFeature)) {\r
+ String uri = feature.toString();\r
+ String name = feature instanceof PathChild ? ((PathChild)feature).name : uri;\r
+ \r
+ FeatureInfo fi = new FeatureInfo(name, uri, null, null);\r
+ result.add( fi );\r
+ }\r
+ }\r
+ }\r
+ \r
+ return result;\r
+ */\r
+ return Collections.emptySet();\r
+ }\r
+ \r
+ /**\r
+ * For a set of extact feature ids (id_version), find the set of graph bundles \r
+ * required in the database.\r
+ * \r
+ * @param featureIds feature\r
+ * @return graph bundles\r
+ */\r
+ public Set<IVersionedId> getRequiredGraphBundles(Collection<IVersionedId> featureIds) {\r
+ \r
+ return null;\r
+ }\r
+ \r
+ /**\r
+ * Checks whether artifact is a graph bundle. \r
+ * \r
+ * @param key key to artifact\r
+ * @return <code>true</code> if is a graph bundle\r
+ * @throws IOException \r
+ */\r
+ public boolean isGraphArtifact(IArtifactKey key) throws IOException {\r
+ return ProvisioningUtil.isGraphArtifact(artifactRepository, key);\r
+ }\r
+\r
+ /**\r
+ * Checks wheter iu is graph\r
+ * \r
+ * @param iu\r
+ * @return\r
+ * @throws IOException\r
+ */\r
+ public boolean isGraph(IInstallableUnit iu) throws IOException {\r
+ return ProvisioningUtil.isGraph(iu, metadataRepository, artifactRepository);\r
+ }\r
+\r
+ /**\r
+ * Delete default repositories located in /P2 folder\r
+ * @throws IOException\r
+ */\r
+ public void delete() throws IOException {\r
+ File location1 = new File(metadataAgentLocation);\r
+ File location2 = new File(artifactAgentLocation);\r
+ File location3 = new File(metadataRepository.getLocation());\r
+ File location4 = new File(artifactRepository.getLocation());\r
+ FileUtils.deleteDir(location1);\r
+ FileUtils.deleteDir(location2);\r
+ FileUtils.deleteDir(location3);\r
+ FileUtils.deleteDir(location4);\r
+ location1.mkdirs();\r
+ location2.mkdirs();\r
+ location3.mkdirs();\r
+ location4.mkdirs();\r
+ } \r
+ \r
+ \r
+}\r
+\r