1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.pkg;
21
22 import java.util.Iterator;
23
24 /***
25 * Defines lists of packages that need to be installed or removed.
26 */
27 public class PackageCommit {
28
29
30
31
32
33 private PackageInfo[] pendingInstall;
34
35
36
37 public PackageCommit(PackageManager manager)
38 throws ParseException, UnsatisfiedDependenciesException
39 {
40 DependencyGraph graph = new DependencyGraph(manager);
41
42 for (Iterator it = manager.packages(); it.hasNext();) {
43 PackageInfo info = (PackageInfo)it.next();
44 if (PackageInfo.ACTION_INSTALL.equals(info.getAction())
45 && !PackageInfo.PACKAGE_STATUS_INSTALLED.equals
46 (info.getPackageStatus())) {
47
48 graph.add(info);
49 }
50 }
51
52 graph.buildDependencies(new DefaultDependencyParser());
53 DefaultResolver r = new DefaultResolver(graph, false);
54 r.resolve();
55 pendingInstall = r.getRequiredUninstalled();
56 }
57
58
59
60 public PackageInfo[] getInstall()
61 {
62 return pendingInstall;
63 }
64
65 public PackageInfo[] getRemove()
66 {
67 return null;
68 }
69
70 /***
71 * Returns true, if the commit would not modify any packages.
72 */
73 public boolean isEmpty()
74 {
75 return pendingInstall.length == 0;
76 }
77
78
79
80
81 }