]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.project/src/org/simantics/project/management/BundlePool.java
Support ontology install option trueWhenDeployed also during development
[simantics/platform.git] / bundles / org.simantics.project / src / org / simantics / project / management / BundlePool.java
1 /*******************************************************************************
2  * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     VTT Technical Research Centre of Finland - initial API and implementation
10  *******************************************************************************/
11 package org.simantics.project.management;
12
13 import java.io.File;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.net.URI;
17 import java.util.ArrayList;
18 import java.util.Collection;
19 import java.util.Collections;
20 import java.util.HashMap;
21 import java.util.HashSet;
22 import java.util.List;
23 import java.util.Map;
24 import java.util.Set;
25 import java.util.jar.Manifest;
26
27 import org.eclipse.core.runtime.IPath;
28 import org.eclipse.core.runtime.IProgressMonitor;
29 import org.eclipse.core.runtime.IStatus;
30 import org.eclipse.core.runtime.Path;
31 import org.eclipse.core.runtime.Platform;
32 import org.eclipse.core.runtime.Status;
33 import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
34 import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository;
35 import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepositoryFactory;
36 import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository;
37 import org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository;
38 import org.eclipse.equinox.internal.p2.metadata.repository.SimpleMetadataRepositoryFactory;
39 import org.eclipse.equinox.p2.core.IProvisioningAgent;
40 import org.eclipse.equinox.p2.core.ProvisionException;
41 import org.eclipse.equinox.p2.internal.repository.mirroring.Mirroring;
42 import org.eclipse.equinox.p2.metadata.IArtifactKey;
43 import org.eclipse.equinox.p2.metadata.IInstallableUnit;
44 import org.eclipse.equinox.p2.metadata.IVersionedId;
45 import org.eclipse.equinox.p2.metadata.VersionedId;
46 import org.eclipse.equinox.p2.query.IQuery;
47 import org.eclipse.equinox.p2.query.IQueryResult;
48 import org.eclipse.equinox.p2.query.QueryUtil;
49 import org.eclipse.equinox.p2.repository.artifact.ArtifactKeyQuery;
50 import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
51 import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
52 import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
53 import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
54 import org.simantics.graph.db.TransferableGraphException;
55 import org.simantics.graph.query.Graphs;
56 import org.simantics.graph.query.IGraph;
57 import org.simantics.graph.query.Paths;
58 import org.simantics.graph.query.Res;
59 import org.simantics.graph.query.UriUtils;
60 import org.simantics.graph.representation.TransferableGraph1;
61 import org.simantics.scl.reflection.OntologyVersions;
62 import org.simantics.utils.FileUtils;
63
64 /**
65  * Bundlepool is a repository of artifacts and installable units. 
66  *
67  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
68  */
69 @SuppressWarnings("restriction")
70 public class BundlePool {
71
72         /** Application default pool. It is located at "workspace/bundlepool" */
73         static BundlePool DEFAULT;      
74
75         IMetadataRepository metadataRepository; 
76         IArtifactRepository artifactRepository;
77         IProvisioningAgent metadataAgent;
78         IProvisioningAgent artifactAgent;
79         URI metadataAgentLocation;
80         URI artifactAgentLocation;
81         
82         List<BundleInfo> userInstallables;
83
84         /** All features that were discovered in the repository */
85         Set<FeatureInfo> projectFeatures = new HashSet<FeatureInfo>(); 
86         
87         /**
88          * Get SPM Bundle Pool
89          * 
90          * @return SPM Bundle Pool
91          */
92         public synchronized static BundlePool getDefault() {
93                 if (DEFAULT == null) {
94                         try {
95                                 IPath path = Platform.getLocation().append("bundlepool");
96                                 URI metadataRepositoryLocation = path.toFile().toURI();
97                                 URI artifactRepositoryLocation = path.toFile().toURI();
98                                 IProvisioningAgent agent = P2Util.createAgent( path );                          
99                                 DEFAULT = new BundlePool(metadataRepositoryLocation, artifactRepositoryLocation, agent);
100                         } catch (ProvisionException e) {
101                                 // Not expected
102                                 throw new RuntimeException(e);
103                         }
104                 }
105                 return DEFAULT;
106         }
107
108         /**
109          * Create bundle pool in a directory on a local hard drive.  
110          * This location will contain metadata repository, artifact repository and 
111          * P2 workarea (Agent).
112          * 
113          * @param location
114          * @return bundle pool
115          */
116         public static BundlePool createAt(File location) {              
117                 try {
118                         File canonicalLocation = location.getCanonicalFile();
119                         URI metadataRepositoryLocation = canonicalLocation.toURI();
120                         URI artifactRepositoryLocation = canonicalLocation.toURI();
121                         IPath agentLocation = new Path( canonicalLocation.toString() );
122                         IProvisioningAgent agent = P2Util.createAgent( agentLocation );                         
123                         return new BundlePool(metadataRepositoryLocation, artifactRepositoryLocation, agent); 
124                 } catch (IOException e) {
125                         throw new RuntimeException(e);
126                 } catch (org.eclipse.equinox.p2.core.ProvisionException e) {
127                         throw new RuntimeException(e);
128                 }
129                 
130         }
131         
132         public BundlePool(URI metadataRepositoryLocation, URI artifactRepositoryLocation, IProvisioningAgent agent) throws ProvisionException {
133                 
134                 this.metadataAgent = agent;
135                 this.artifactAgent = agent;
136                 
137             SimpleMetadataRepositoryFactory metRepFactory = new SimpleMetadataRepositoryFactory();
138             metRepFactory.setAgent( metadataAgent );        
139             try {
140                 metadataRepository = metRepFactory.load(metadataRepositoryLocation, 0, null);
141                 } catch (org.eclipse.equinox.p2.core.ProvisionException pe) {
142                         new File(metadataRepositoryLocation).mkdirs();
143                 Map<String, String> repoProperties = new HashMap<String, String>();
144                 metadataRepository = metRepFactory.create(metadataRepositoryLocation, "SPM Bundle Pool", "file", repoProperties);
145                 }
146         
147         //          IMetadataRepository metadataRepository = new LocalMetadataRepository( agent, repositoryLocation, "My Metadata Repository", Collections.EMPTY_MAP );
148         //          IMetadataRepository metadataRepository = getMetadataRepository(agent, repositoryLocation);
149             
150 //              IArtifactRepository artifactRepository = new SimpleArtifactRepositoryFactory().create(repositoryLocation, "Sample Artifact Repository", ArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, Collections.EMPTY_MAP);
151 //          SimpleArtifactRepository artifactRepository = new SimpleArtifactRepository( agent, "My Simple Artifact Repository", repositoryLocation, Collections.EMPTY_MAP);
152                 SimpleArtifactRepositoryFactory artRepFactory = new SimpleArtifactRepositoryFactory();
153                 artRepFactory.setAgent( artifactAgent );
154                         
155                 try {
156                         artifactRepository = artRepFactory.load(artifactRepositoryLocation, 0, null);
157                 } catch (org.eclipse.equinox.p2.core.ProvisionException pe) {
158                         new File(artifactRepositoryLocation).mkdirs();
159                 Map<String, String> repoProperties = new HashMap<String, String>();
160                 artifactRepository = artRepFactory.create(artifactRepositoryLocation, "SPM Bundle Pool", "file", repoProperties);
161                 }
162                 
163                 init();
164         }
165         
166         public BundlePool(IMetadataRepository metadataRepository, IArtifactRepository artifactRepository) throws ProvisionException {
167                 this.metadataRepository = metadataRepository;
168                 this.artifactRepository = artifactRepository;
169                 this.metadataAgent = metadataRepository.getProvisioningAgent();
170                 this.artifactAgent = artifactRepository.getProvisioningAgent();
171                 init();
172         }
173         
174         /**
175          * Init prepares with the following actions:
176          *  o loads transferable graphs
177          *  o discovers Features and collects Feature URIs, Artifacts and Installable Units
178          * 
179          * @throws ProvisionException 
180          */
181         protected void init() throws ProvisionException {
182                 try {
183                         projectFeatures.clear();
184                         
185                         ArrayList<TransferableGraph1> platformTGs = new ArrayList<TransferableGraph1>();
186                         
187                         for (IArtifactKey key : getAllArtifactKeys()) {
188                                 boolean hasGraph = ProvisioningUtil.hasFile(artifactRepository, key, "graph.tg");
189                                 if (!hasGraph) continue;
190                                 
191                                 // Read Graph
192                                 TransferableGraph1 graph = ProvisioningUtil.getTransferableGraph(artifactRepository, key);
193                                 platformTGs.add(graph);
194                         }
195                         
196                         // Create new project, use all features available in Platform
197                         final List<String> poolFeatures = new ArrayList<String>();
198                         
199                         // Convert graph instances
200                         GraphBundleEx l0 = getLayer0();
201                         String l0v = l0.getMajor() + "." + l0.getMinor();
202                         IGraph graph = Graphs.createGraph(new Paths(l0v), platformTGs);
203                 
204                         for(Res feature : graph.getInstances(UriUtils.uriToPath(OntologyVersions.getInstance().currentVersion("http://www.simantics.org/Project-0.0/Feature" )))) {
205                                 poolFeatures.add( feature.toString() );
206                         }                               
207                 
208                 } catch (TransferableGraphException e) {
209                         throw new ProvisionException("Problem", e);
210                 } catch (IOException e) {
211                         throw new ProvisionException("Failed to read graph.tg", e);
212                 }
213         }
214         
215         public IMetadataRepository getMetadataRepository() {
216                 return metadataRepository;
217         }
218         
219         public IArtifactRepository getArtifactRepository() {
220                 return artifactRepository;
221         }
222         
223         public IArtifactKey[] getAllArtifactKeys() {
224                 return artifactRepository.query( ArtifactKeyQuery.ALL_KEYS, null ).toArray( IArtifactKey.class );
225         }
226                         
227         public GraphBundleEx getLayer0() throws ProvisionException, TransferableGraphException {
228                 IVersionedId vid = VersionedId.parse("org.simantics.layer0");
229                 Set<IInstallableUnit> result = metadataRepository.query( QueryUtil.createLatestQuery( QueryUtil.createIUQuery(vid) ), null).toSet();
230                 if (result.isEmpty()) throw new RuntimeException("Unexpectedly got no IU for "+vid);
231                 if (result.size()>1) throw new RuntimeException("Unexpectedly got more than one latest IU for "+vid);
232                 IInstallableUnit iu = result.iterator().next();
233                 IArtifactKey key = toSingleArtifact(iu);
234                 TransferableGraph1 graph = getTransferableGraph( key );
235                 return new GraphBundleEx( "Layer0", graph, key);
236         }       
237         
238         public TransferableGraph1 getTransferableGraph(IArtifactKey artifactKey) throws ProvisionException, TransferableGraphException  {
239                 return ProvisioningUtil.getTransferableGraph( artifactRepository, artifactKey);
240         }
241
242         
243         
244         /**
245          * Get all features.
246          * 
247          * @param a list of features
248          * @throws ProvisionException 
249          */
250         public void getFeatures(List<BundleInfo> features) throws ProvisionException {
251                 IMetadataRepository metadataRepository = getMetadataRepository();
252                 
253                 Collection<IInstallableUnit> ius = ProvisioningUtil.getInstallableUnits(metadataRepository); 
254                 for (IInstallableUnit iu : ius) {               
255                 if (ProvisioningUtil.isGroup(iu)) {
256 //              if (P2Util.isFeature(iu)) {
257                         BundleInfo b = BundleInfo.read(iu);
258                         features.add( b );
259                 }
260                 }               
261         }
262         
263         /**
264          * Get bundle info
265          * 
266          * @param id bundle id
267          * @return bundle info
268          */
269         public BundleInfo getBundleInfo(String id) {
270                 IQuery<IInstallableUnit> query =  QueryUtil.createLatestQuery( QueryUtil.createIUQuery(id) );
271                 IQueryResult<IInstallableUnit> queryResult = metadataRepository.query(query, null);
272                 IInstallableUnit[] array = queryResult.toArray( IInstallableUnit.class );
273                 for (IInstallableUnit iu : array) {
274                         BundleInfo bi = BundleInfo.read(iu);
275                         return bi;
276                 }
277                 return null;
278         }
279         
280         /**
281          * Get the features that visible for the end-user.
282          * User installable features are configured in Simantics manifest files
283          * (META-INF/SIMANTICS.MF as Simantics-Features-Bundle -property)
284          * 
285          * @param result
286          * @throws IOException 
287          */
288 //      public void getUserInstallableFeatures(Collection<BundleInfo> result) throws IOException {
289 //              ArrayList<String> ids = new ArrayList<String>();
290 //              ProvisioningUtil.getUserInstallables(artifactRepository, ids);
291 //              for (String id : ids) {
292 //                      BundleInfo bi = getBundleInfo(id);
293 //                      if (bi != null) result.add( bi );
294 //              }
295 //              // Add workspace bundle
296 //              BundleInfo bi = getBundleInfo( "org.simantics.workbench.product" );
297 //              if (bi != null) result.add( bi );
298 //      }
299         
300         /**
301          * Get all groups.
302          * 
303          * @param a list of features
304          * @throws ProvisionException 
305          */
306 //      public void getInstallableFeatures(List<BundleInfo> features) throws ProvisionException {
307 //              IMetadataRepository metadataRepository = getMetadataRepository();
308 //              
309 //              Collection<IInstallableUnit> ius = ProvisioningUtil.getInstallableUnits(metadataRepository); 
310 //              for (IInstallableUnit iu : ius) {               
311 //              if (ProvisioningUtil.isGroup(iu)) {
312 ////            if (P2Util.isFeature(iu)) {
313 //                      BundleInfo b = BundleInfo.read(iu);
314 //                      features.add( b );
315 //              }
316 //              }               
317 //      }
318
319         /**
320          * Mirror source locations to the bundle pool.
321          * 
322          * @param monitor
323          * @param sourceLocations
324          * @return
325          * @throws ProvisionException
326          */
327         public IStatus download(IProgressMonitor monitor, URI[] sourceLocations) throws ProvisionException {
328                 try {
329                         monitor.beginTask("Synchronizing Local repository with web repositories", 10);          
330         
331                         @SuppressWarnings("unused")
332                         IMetadataRepositoryManager metaRepoMgr = (IMetadataRepositoryManager) metadataAgent.getService(IMetadataRepositoryManager.SERVICE_NAME);
333                         @SuppressWarnings("unused")
334                         IArtifactRepositoryManager artsRepoMgr = (IArtifactRepositoryManager) artifactAgent.getService(IArtifactRepositoryManager.SERVICE_NAME);
335         
336                         
337                         // Create dest repos
338                         monitor.setTaskName("Setting up local metadata repository");
339                         LocalMetadataRepository dstMetaRepo = (LocalMetadataRepository) metadataRepository;
340                         monitor.worked(1);
341                         
342                         monitor.setTaskName("Setting up local artifact repository");
343                         SimpleArtifactRepository dstArtsRepo = (SimpleArtifactRepository) artifactRepository;
344                         monitor.worked(1);
345                         
346                         // Create a source repos
347                         monitor.setTaskName("Setting up remote artifact repository");
348                         CompositeArtifactRepository srcArtsRepo = CompositeArtifactRepository.createMemoryComposite( metadataAgent /* ? */ );
349                         for (URI uri : sourceLocations) srcArtsRepo.addChild(uri);
350                         monitor.worked(1);
351                         
352                         monitor.setTaskName("Setting up remote metadata repository");           
353                         CompositeMetadataRepository srcMetaRepo = CompositeMetadataRepository.createMemoryComposite( artifactAgent /* ? */ );
354                         for (URI uri : sourceLocations) srcMetaRepo.addChild(uri);
355                         monitor.worked(1);
356                         
357                         monitor.setTaskName("Retrieving Installable Units");
358                         @SuppressWarnings("unused")
359                         Collection<IInstallableUnit> ius = ProvisioningUtil.getInstallableUnits(srcMetaRepo);
360                         monitor.worked(1);
361         
362                         monitor.setTaskName("Mirroring Metadata");
363                         // Get all IUs from source
364                         IQueryResult<IInstallableUnit> allIUs = srcMetaRepo.query(QueryUtil.createIUAnyQuery(), monitor);
365                         // Put the IUs to dst
366                         dstMetaRepo.addInstallableUnits(allIUs.toUnmodifiableSet());
367                         dstMetaRepo.addReferences(srcMetaRepo.getReferences());
368                         monitor.worked(1);
369                         
370                         monitor.setTaskName("Mirroring Artifacts");
371                         
372                         boolean compare = false;
373                         boolean failOnError = true;
374                         //boolean raw = true;
375                         boolean verbose = false;
376                         boolean validate = false;
377                         //boolean mirrorReferences = false;
378                         String comparatorID = "";
379                         
380                         Mirroring mirror = new Mirroring(srcArtsRepo, dstArtsRepo, false);
381                         mirror.setCompare(compare);
382                         mirror.setComparatorId(comparatorID);
383         //              mirror.setBaseline(null);
384                         mirror.setValidate(validate);
385         //              mirror.setCompareExclusions();
386         
387                         IStatus result = mirror.run(failOnError, verbose);
388                         if (result.getException()!=null)
389                                 throw new ProvisionException(result);
390                         
391                         init();
392                         
393                         return result;
394                 } catch (IllegalArgumentException iae) {
395                         return new Status(IStatus.ERROR, "org.simantics.project", iae.getMessage(), iae);
396                 }
397         }
398
399         public IInstallableUnit toSingleInstallableUnit(IVersionedId id) throws ProvisionException {
400                 Set<IInstallableUnit> result = metadataRepository.query( QueryUtil.createIUQuery(id), null).toSet();
401                 if (result.size() != 1) throw new RuntimeException("Unexpectedly got more than one latest IU for "+id);         
402                 return result.iterator().next();                
403         }
404
405         public IArtifactKey toSingleArtifact(IVersionedId id) throws ProvisionException {
406                 IInstallableUnit iu = toSingleInstallableUnit(id);
407                 if (iu.getArtifacts().size() != 1) throw new RuntimeException("Unexpectedly got more than one artifact for ");
408                 return iu.getArtifacts().iterator().next();
409         }
410
411         /**
412          * Get file from an artifact.
413          * 
414          * @param key
415          * @param filename
416          * @return inputstream or <tt>null</tt>. Inputstream must be closed.
417          * @throws IOException 
418          */
419         public InputStream getFile(IArtifactKey key, String filename) throws IOException {
420                 return ProvisioningUtil.getFile(artifactRepository, key, filename);
421         }
422         
423         /**
424          * Checks whether there exists a file in an artifact
425          * 
426          * @param key
427          * @param filename
428          * @return true file exists in the artifact
429          * @throws IOException
430          */
431         public boolean hasFile(IArtifactKey key, String filename) throws IOException {
432                 return ProvisioningUtil.hasFile(artifactRepository, key, filename);
433         }
434         
435         /**
436          * Get META-INF/MANIFEST.MF
437          * 
438          * @param repo artifact repo
439          * @param key key to artifact
440          * @return manifest or null
441          * @throws IOException 
442          */
443         public Manifest getManifest(IArtifactKey key) throws IOException {
444                 return ProvisioningUtil.getManifest(artifactRepository, key);
445         }
446         
447         /**
448          * Get META-INF/SIMANTICS.MF 
449          * 
450          * @param repo artifact repo
451          * @param key key to artifact
452          * @return manifest or null
453          * @throws IOException 
454          */
455         public Manifest getSimanticsManifest(IArtifactKey key) throws IOException {
456                 return ProvisioningUtil.getManifest(artifactRepository, key);
457         }
458         
459         /**
460          * Get list of user installable bundles
461          * 
462          * @param result
463          * @throws IOException
464          */
465         public void getUserInstallables(List<BundleInfo> result) throws IOException {
466                 if (userInstallables==null) {
467                         userInstallables = new ArrayList<BundleInfo>();
468                         
469                         List<String> topLevelBundles = new ArrayList<String>();
470                         ProvisioningUtil.getUserInstallables(artifactRepository, topLevelBundles);
471                         
472                         for (String bundleId : topLevelBundles) {
473                                 IInstallableUnit ius[] = metadataRepository.query( QueryUtil.createIUQuery(bundleId) , null).toArray( IInstallableUnit.class );
474                                 for (IInstallableUnit iu : ius) {
475                                         userInstallables.add( BundleInfo.read(iu) );
476                                 }
477                         }                       
478                         
479                 }
480                 result.addAll(userInstallables);
481         }
482         
483         
484         
485         /////////// 
486         /////////// GRAPHS
487         ///////////
488         
489
490         
491 //      /**
492 //       * Get graph bundles
493 //       * 
494 //       * @param list to be populated with graph bundle ids
495 //       * @throws ProvisionException 
496 //       * @throws IOException 
497 //       */
498 //      public void getGraphs(List<BundleInfo> graphs) throws ProvisionException, IOException {
499 //              Collection<IInstallableUnit> ius = ProvisioningUtil.getInstallableUnits(metadataRepository); 
500 //              for (IInstallableUnit iu : ius) {
501 //              if (isGraph(iu)) {
502 //                      BundleInfo b = BundleInfo.read(iu);
503 //                      graphs.add( b );
504 //              }
505 //              }               
506 //      }
507
508         /**
509          * Get graph bundles
510          * 
511          * @param list to be populated with graph bundle ids
512          * @throws ProvisionException 
513          * @throws IOException 
514          * @throws TransferableGraphException 
515          */
516         public void getGraphBundles(List<GraphBundleEx> graphs) throws ProvisionException, IOException, TransferableGraphException {
517                 Collection<IInstallableUnit> ius = ProvisioningUtil.getInstallableUnits(metadataRepository); 
518                 for (IInstallableUnit iu : ius) {
519                         for (IArtifactKey key : iu.getArtifacts()) {
520                         if (!ProvisioningUtil.isGraphArtifact(artifactRepository, key)) continue;
521                         TransferableGraph1 tg = ProvisioningUtil.getTransferableGraph( artifactRepository, key );
522                         GraphBundleEx b = new GraphBundleEx(iu.getId(), tg, key);
523                         graphs.add( b );
524                         }
525                 }               
526         }
527         
528         /**
529          * Get a list of all features. Features are uris, they are versionless. 
530          * @return fetures
531          * @throws TransferableGraphException 
532          * @throws IOException 
533          */
534         public Set<FeatureInfo> getFeatures() throws IOException, TransferableGraphException {
535                 /*
536                 HashSet<FeatureInfo> result = new HashSet<FeatureInfo>();
537                 Collection<IInstallableUnit> ius = ProvisioningUtil.getInstallableUnits(metadataRepository); 
538                 for (IInstallableUnit iu : ius) {
539                         for (IArtifactKey key : iu.getArtifacts()) {
540                         if (!ProvisioningUtil.isGraphArtifact(artifactRepository, key)) continue;
541                         TransferableGraph1 tg = ProvisioningUtil.getTransferableGraph( artifactRepository, key );
542                         IGraph g = Graphs.createGraph(tg);
543                                 
544                                 Res    PublishedProjectFeatures = UriUtils.uriToPath( ProjectResource.URIs.PublishedProjectFeatures );
545                                 Path   HasFeature = UriUtils.uriToPath( ProjectResource.URIs.HasFeature );
546                                 for(Res feature : g.getObjects(PublishedProjectFeatures, HasFeature)) {
547                                         String uri = feature.toString();
548                                         String name = feature instanceof PathChild ? ((PathChild)feature).name : uri;
549                                         
550                                         FeatureInfo fi = new FeatureInfo(name, uri, null, null);
551                                         result.add( fi );
552                                 }
553                         }
554                 }
555                 
556                 return result;
557                 */
558                 return Collections.emptySet();
559         }
560         
561         /**
562          * For a set of extact feature ids (id_version), find the set of graph bundles 
563          * required in the database.
564          * 
565          * @param featureIds feature
566          * @return graph bundles
567          */
568         public Set<IVersionedId> getRequiredGraphBundles(Collection<IVersionedId> featureIds) {
569                 
570                 return null;
571         }
572         
573         /**
574          * Checks whether artifact is a graph bundle. 
575          * 
576          * @param key key to artifact
577          * @return <code>true</code> if is a graph bundle
578          * @throws IOException 
579          */
580         public boolean isGraphArtifact(IArtifactKey key) throws IOException {
581                 return ProvisioningUtil.isGraphArtifact(artifactRepository, key);
582         }
583
584         /**
585          * Checks wheter iu is graph
586          *  
587          * @param iu
588          * @return
589          * @throws IOException
590          */
591         public boolean isGraph(IInstallableUnit iu) throws IOException {
592                 return ProvisioningUtil.isGraph(iu, metadataRepository, artifactRepository);
593         }
594
595         /**
596          * Delete default repositories located in /P2 folder
597          * @throws IOException
598          */
599         public void delete() throws IOException {
600                 File location1 = new File(metadataAgentLocation);
601                 File location2 = new File(artifactAgentLocation);
602                 File location3 = new File(metadataRepository.getLocation());
603                 File location4 = new File(artifactRepository.getLocation());
604                 FileUtils.deleteDir(location1);
605                 FileUtils.deleteDir(location2);
606                 FileUtils.deleteDir(location3);
607                 FileUtils.deleteDir(location4);
608                 location1.mkdirs();
609                 location2.mkdirs();
610                 location3.mkdirs();
611                 location4.mkdirs();
612         }       
613         
614         
615 }
616