View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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      //--- Constant(s) ---
30  
31      //--- Data field(s) ---
32  
33  	private PackageInfo[] pendingInstall;
34  
35      //--- Constructor(s) ---
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      //--- Method(s) ---
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      // --- Inner Class(es) ---
79  
80  
81  }