KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > standalone > ListFeaturesCommand


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation 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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.update.standalone;
12 import java.io.*;
13 import java.net.*;
14
15 import org.eclipse.core.runtime.*;
16 import org.eclipse.update.configuration.*;
17 import org.eclipse.update.core.*;
18 import org.eclipse.update.internal.core.*;
19
20
21 /**
22  * Command to list all installed features.
23  * <p>
24  * <b>Note:</b> This class/interface is part of an interim API that is still under development and expected to
25  * change significantly before reaching stability. It is being made available at this early stage to solicit feedback
26  * from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken
27  * (repeatedly) as the API evolves.
28  * </p>
29  * @since 3.0
30  */

31 public class ListFeaturesCommand extends ScriptedCommand {
32     private IConfiguredSite[] sites = getConfiguration().getConfiguredSites();
33     
34     /**
35      * @param fromSite if specified, list only the features from the specified local install site
36      */

37     public ListFeaturesCommand(String JavaDoc fromSite) throws Exception JavaDoc {
38         try {
39             if (fromSite != null) {
40                 File sitePath = new File(fromSite);
41                 if (!sitePath.exists())
42                     throw new Exception JavaDoc(Messages.Standalone_noSite + fromSite);
43                     
44                 URL fromSiteURL = sitePath.toURL();
45                 ISite site = SiteManager.getSite(fromSiteURL, null);
46                 if (site == null) {
47                     throw new Exception JavaDoc(Messages.Standalone_noSite + fromSite);
48                 }
49                 IConfiguredSite csite = site.getCurrentConfiguredSite();
50                 if (csite == null)
51                     throw new Exception JavaDoc(Messages.Standalone_noConfiguredSite + fromSite);
52                 sites = new IConfiguredSite[] { csite };
53             }
54         
55         } catch (Exception JavaDoc e) {
56             throw e;
57         }
58     }
59
60     /**
61      */

62     public boolean run(IProgressMonitor monitor) {
63         try {
64             if (sites != null) {
65                 for (int i = 0; i < sites.length; i++) {
66                     System.out.println("Site: " + sites[i].getSite().getURL()); //$NON-NLS-1$
67
IFeatureReference[] features = sites[i]
68                             .getFeatureReferences();
69                     for (int f = 0; f < features.length; f++) {
70                         boolean configured = sites[i].isConfigured(features[f]
71                                 .getFeature(null));
72                         System.out.println(" Feature: " //$NON-NLS-1$
73
+ features[f].getVersionedIdentifier()
74                                         .getIdentifier()
75                                 + " " //$NON-NLS-1$
76
+ features[f].getVersionedIdentifier()
77                                         .getVersion() + " " //$NON-NLS-1$
78
+ (configured ? "enabled" : "disabled")); //$NON-NLS-1$ //$NON-NLS-2$
79
}
80                 }
81             }
82             return true;
83         } catch (CoreException e) {
84             StandaloneUpdateApplication.exceptionLogged();
85             UpdateCore.log(e);
86             return false;
87         }
88     }
89 }
90
Popular Tags