KickJava   Java API By Example, From Geeks To Geeks.

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


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
14 import org.eclipse.core.runtime.*;
15 import org.eclipse.update.configuration.*;
16 import org.eclipse.update.core.*;
17 import org.eclipse.update.internal.core.*;
18 import org.eclipse.update.operations.*;
19
20
21 /**
22  * Command to remove a product extension site.
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 RemoveSiteCommand extends ScriptedCommand {
32     private IConfiguredSite csite;
33     private File sitePath;
34     
35     /**
36      * @param toSite if specified, list only the features from the specified local install site
37      */

38     public RemoveSiteCommand(String JavaDoc toSite) throws Exception JavaDoc {
39         try {
40             if (toSite != null) {
41                 sitePath = new File(toSite);
42                 if (!sitePath.getName().equals("eclipse")) //$NON-NLS-1$
43
sitePath = new File(sitePath, "eclipse"); //$NON-NLS-1$
44
if (!sitePath.exists())
45                     throw new Exception JavaDoc(Messages.Standalone_noSite + toSite);
46                     
47                 IConfiguredSite[] csites = SiteManager.getLocalSite().getCurrentConfiguration().getConfiguredSites();
48                 for (int i=0; i<csites.length; i++) {
49                     File f = new File(csites[i].getSite().getURL().getFile());
50                     if (f.equals(sitePath)) {
51                         csite = csites[i];
52                         break;
53                     }
54                 }
55                 
56                 if (csite == null)
57                     throw new Exception JavaDoc(Messages.Standalone_noConfiguredSite + toSite);
58             } else {
59                 throw new Exception JavaDoc(Messages.Standalone_noSite3);
60             }
61         
62         } catch (Exception JavaDoc e) {
63             throw e;
64         }
65     }
66
67     /**
68      */

69     public boolean run(IProgressMonitor monitor) {
70         // check if the config file has been modifed while we were running
71
IStatus status = OperationsManager.getValidator().validatePlatformConfigValid();
72         if (status != null) {
73             UpdateCore.log(status);
74             return false;
75         }
76         try {
77             getConfiguration().removeConfiguredSite(csite);
78             // update the sites array
79
getConfiguration().getConfiguredSites();
80             SiteManager.getLocalSite().save();
81             return true;
82         } catch (CoreException e) {
83             UpdateCore.log(e);
84             return false;
85         }
86     }
87 }
88
Popular Tags