Skip to main content
summaryrefslogtreecommitdiffstats
blob: 020be859b950d10b19cceeb8eee59ce03fd17d49 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*******************************************************************************
 * Copyright (c) 2008 IBM Corporation and others.
 * 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.internal.p2.update;

import org.eclipse.equinox.p2.core.ProvisionException;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
import org.eclipse.equinox.internal.p2.core.helpers.URLUtil;
import org.eclipse.equinox.internal.p2.touchpoint.eclipse.Activator;
import org.eclipse.equinox.internal.p2.touchpoint.eclipse.Util;

/**
 * @since 1.0
 */
public class Configuration {

	private List<Site> sites = new ArrayList<Site>();
	String date;
	boolean transientProperty;
	String version;
	String shared_ur;

	public static Configuration load(File location, URL osgiInstallArea) throws ProvisionException {
		return ConfigurationIO.read(location, osgiInstallArea);
	}

	public Configuration() {
		super();
	}

	public void save(File location, URL osgiInstallArea) throws ProvisionException {
		ConfigurationIO.write(location, this, osgiInstallArea);
	}

	public String getSharedUR() {
		return shared_ur;
	}

	public void setSharedUR(String value) {
		shared_ur = value;
	}

	public List<Site> getSites() {
		return internalGetSites(true);
	}

	List<Site> internalGetSites(boolean includeParent) {
		if (!includeParent)
			return sites;
		String shared = getSharedUR();
		if (shared == null)
			return sites;
		List<Site> result = new ArrayList<Site>(sites);
		try {
			URL url = new URL(shared);
			File location = URLUtil.toFile(url);
			if (location == null)
				return result;

			if (!location.isAbsolute()) {
				File eclipseHome = Util.getEclipseHome();
				if (eclipseHome == null)
					return null;

				location = new File(eclipseHome, location.getPath());
			}
			Configuration parent = Configuration.load(location, Util.getOSGiInstallArea());
			if (parent == null)
				LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Unable to load parent configuration from: " + location)); //$NON-NLS-1$
			else
				result.addAll(parent.getSites());
		} catch (MalformedURLException e) {
			LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Error occurred while getting parent configuration location.", e)); //$NON-NLS-1$
		} catch (ProvisionException e) {
			LogHelper.log(new Status(IStatus.ERROR, Activator.ID, "Error occurred while loading parent configuratin from: " + shared, e)); //$NON-NLS-1$
		}
		return result;
	}

	public void add(Site site) {
		sites.add(site);
	}

	public boolean removeSite(Site site) {
		return sites.remove(site);
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public void setVersion(String value) {
		version = value;
	}

	public String getVersion() {
		return version;
	}

	public void setTransient(boolean value) {
		transientProperty = value;
	}

	public boolean isTransient() {
		return transientProperty;
	}
}

Back to the top