| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2008, 2010 IBM Corporation and others. |
| 3 |
* |
| 4 |
* This program and the accompanying materials |
| 5 |
* are made available under the terms of the Eclipse Public License 2.0 |
| 6 |
* which accompanies this distribution, and is available at |
| 7 |
* https://www.eclipse.org/legal/epl-2.0/ |
| 8 |
* |
| 9 |
* SPDX-License-Identifier: EPL-2.0 |
| 10 |
* |
| 11 |
* Contributors: |
| 12 |
* IBM Corporation - initial API and implementation |
| 13 |
*******************************************************************************/ |
| 14 |
package org.eclipse.equinox.internal.p2.update; |
| 15 |
|
| 16 |
import java.io.File; |
| 17 |
import java.net.MalformedURLException; |
| 18 |
import java.net.URL; |
| 19 |
import java.util.ArrayList; |
| 20 |
import java.util.List; |
| 21 |
import org.eclipse.core.runtime.IStatus; |
| 22 |
import org.eclipse.core.runtime.Status; |
| 23 |
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; |
| 24 |
import org.eclipse.equinox.internal.p2.core.helpers.URLUtil; |
| 25 |
import org.eclipse.equinox.internal.p2.touchpoint.eclipse.Activator; |
| 26 |
import org.eclipse.equinox.internal.p2.touchpoint.eclipse.Util; |
| 27 |
import org.eclipse.equinox.p2.core.ProvisionException; |
| 28 |
|
| 29 |
/** |
| 30 |
* @since 1.0 |
| 31 |
*/ |
| 32 |
public class Configuration { |
| 33 |
|
| 34 |
private List<Site> sites = new ArrayList<>(); |
| 35 |
String date; |
| 36 |
boolean transientProperty; |
| 37 |
String version; |
| 38 |
String shared_ur; |
| 39 |
|
| 40 |
public static Configuration load(File location, URL osgiInstallArea) throws ProvisionException { |
| 41 |
return ConfigurationIO.read(location, osgiInstallArea); |
| 42 |
} |
| 43 |
|
| 44 |
public Configuration() { |
| 45 |
super(); |
| 46 |
} |
| 47 |
|
| 48 |
public void save(File location, URL osgiInstallArea) throws ProvisionException { |
| 49 |
ConfigurationIO.write(location, this, osgiInstallArea); |
| 50 |
} |
| 51 |
|
| 52 |
public String getSharedUR() { |
| 53 |
return shared_ur; |
| 54 |
} |
| 55 |
|
| 56 |
public void setSharedUR(String value) { |
| 57 |
shared_ur = value; |
| 58 |
} |
| 59 |
|
| 60 |
public List<Site> getSites() { |
| 61 |
return internalGetSites(true); |
| 62 |
} |
| 63 |
|
| 64 |
List<Site> internalGetSites(boolean includeParent) { |
| 65 |
if (!includeParent) |
| 66 |
return sites; |
| 67 |
String shared = getSharedUR(); |
| 68 |
if (shared == null) |
| 69 |
return sites; |
| 70 |
List<Site> result = new ArrayList<>(sites); |
| 71 |
try { |
| 72 |
URL url = new URL(shared); |
| 73 |
File location = URLUtil.toFile(url); |
| 74 |
if (location == null) |
| 75 |
return result; |
| 76 |
|
| 77 |
if (!location.isAbsolute()) { |
| 78 |
File eclipseHome = Util.getEclipseHome(); |
| 79 |
if (eclipseHome == null) |
| 80 |
return null; |
| 81 |
|
| 82 |
location = new File(eclipseHome, location.getPath()); |
| 83 |
} |
| 84 |
Configuration parent = Configuration.load(location, Util.getOSGiInstallArea()); |
| 85 |
if (parent == null) |
| 86 |
LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Unable to load parent configuration from: " + location)); //$NON-NLS-1$ |
| 87 |
else |
| 88 |
result.addAll(parent.getSites()); |
| 89 |
} catch (MalformedURLException e) { |
| 90 |
LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Error occurred while getting parent configuration location.", e)); //$NON-NLS-1$ |
| 91 |
} catch (ProvisionException e) { |
| 92 |
LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Error occurred while loading parent configuratin from: " + shared, e)); //$NON-NLS-1$ |
| 93 |
} |
| 94 |
return result; |
| 95 |
} |
| 96 |
|
| 97 |
public void add(Site site) { |
| 98 |
sites.add(site); |
| 99 |
} |
| 100 |
|
| 101 |
public boolean removeSite(Site site) { |
| 102 |
return sites.remove(site); |
| 103 |
} |
| 104 |
|
| 105 |
public String getDate() { |
| 106 |
return date; |
| 107 |
} |
| 108 |
|
| 109 |
public void setDate(String date) { |
| 110 |
this.date = date; |
| 111 |
} |
| 112 |
|
| 113 |
public void setVersion(String value) { |
| 114 |
version = value; |
| 115 |
} |
| 116 |
|
| 117 |
public String getVersion() { |
| 118 |
return version; |
| 119 |
} |
| 120 |
|
| 121 |
public void setTransient(boolean value) { |
| 122 |
transientProperty = value; |
| 123 |
} |
| 124 |
|
| 125 |
public boolean isTransient() { |
| 126 |
return transientProperty; |
| 127 |
} |
| 128 |
} |