Skip to main content
summaryrefslogtreecommitdiffstats
blob: af8f73138624102dfbd9157c8ec4cb457c4bdd2a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*******************************************************************************
 * Copyright (c) 2007 Innoopract Informationssysteme GmbH
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Innoopract - initial API and implementation
 *******************************************************************************/
package org.eclipse.epp.packaging.core.download;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.epp.packaging.core.io.FileUtils;
import org.eclipse.update.configuration.IConfiguredSite;
import org.eclipse.update.configuration.IInstallConfiguration;
import org.eclipse.update.configuration.ILocalSite;
import org.eclipse.update.core.SiteManager;

/**
 * Responsible for creating and deleting extension sites.
 */
public class SiteCreator {

  /**
   * Adds a new extension site to the system and configures it to be able to
   * update.
   */
  public static IConfiguredSite createInstallationSite( final File folder )
    throws IOException, CoreException
  {
    if( !folder.exists() ) {
      folder.mkdir();
    }
    IInstallConfiguration config = SiteManager.getLocalSite()
      .getCurrentConfiguration();
    IConfiguredSite site = config.createConfiguredSite( folder );
    site.verifyUpdatableStatus();
    config.addConfiguredSite( site );
    return site;
  }

  /**
   * Removes an extension site from the system, deleting its content.
   */
  public static void removeInstallationSite( final String siteString )
    throws CoreException, MalformedURLException
  {
    ILocalSite localSite = SiteManager.getLocalSite();
    IInstallConfiguration configuration = localSite.getCurrentConfiguration();
    IConfiguredSite[] sites = configuration.getConfiguredSites();
    File file = new File( siteString );
    String fileUrl = file.toURL().toExternalForm() + "eclipse/";//$NON-NLS-1$
    for( IConfiguredSite site : sites ) {
      if( site.getSite().getURL().toExternalForm().equals( fileUrl ) ) {
        configuration.removeConfiguredSite( site );
        FileUtils.deleteFile( file );
      }
    }
  }
}

Back to the top