10
10
*
11
11
* Contributors:
12
12
* IBM Corporation - initial API and implementation
13
- * James D Miles (IBM Corp.) - bug 176250, Configurator needs to handle more platform urls
13
+ * James D Miles (IBM Corp.) - bug 176250, Configurator needs to handle more platform urls
14
14
*******************************************************************************/
15
15
package org .eclipse .update .internal .configurator ;
16
16
25
25
import org .w3c .dom .*;
26
26
27
27
public class Configuration implements IConfigurationConstants {
28
-
28
+
29
29
private final HashMap <String , SiteEntry > sites = new HashMap <>();
30
30
private final HashMap <String , URL > platformURLs = new HashMap <>();
31
31
private Date date ;
@@ -35,7 +35,7 @@ public class Configuration implements IConfigurationConstants {
35
35
private boolean isDirty ;
36
36
private Configuration linkedConfig ; // shared configuration
37
37
private URL associatedInstallURL = Utils .getInstallURL ();
38
-
38
+
39
39
public Configuration () {
40
40
this (new Date ());
41
41
// the config is created now or out of a platform.xml without a date
@@ -44,37 +44,38 @@ public Configuration() {
44
44
public Configuration (Date date ) {
45
45
this .date = date ;
46
46
}
47
-
47
+
48
48
public void setURL (URL url ) {
49
49
this .url = url ;
50
50
}
51
-
51
+
52
52
public URL getURL () {
53
53
return url ;
54
54
}
55
-
55
+
56
56
public void setLinkedConfig (Configuration linkedConfig ) {
57
57
this .linkedConfig = linkedConfig ;
58
58
// make all the sites read-only
59
- for (SiteEntry linkedSite : linkedConfig .getSites ())
59
+ for (SiteEntry linkedSite : linkedConfig .getSites ()) {
60
60
linkedSite .setUpdateable (false );
61
+ }
61
62
}
62
-
63
+
63
64
public Configuration getLinkedConfig () {
64
65
return linkedConfig ;
65
66
}
66
-
67
+
67
68
/**
68
69
* @return true if the config needs to be saved
69
70
*/
70
71
public boolean isDirty () {
71
72
return isDirty ;
72
73
}
73
-
74
+
74
75
public void setDirty (boolean dirty ) {
75
76
isDirty = dirty ;
76
77
}
77
-
78
+
78
79
public void addSiteEntry (String url , SiteEntry site ) {
79
80
url = Utils .canonicalizeURL (url );
80
81
// only add the same site once
@@ -92,7 +93,7 @@ public void addSiteEntry(String url, SiteEntry site) {
92
93
}else {
93
94
relSite = getInstallURL ();
94
95
}
95
-
96
+
96
97
pURL = new URL (url );
97
98
URL rURL = PlatformConfiguration .resolvePlatformURL (pURL , relSite );
98
99
String resolvedURL = rURL .toExternalForm ();
@@ -103,9 +104,9 @@ public void addSiteEntry(String url, SiteEntry site) {
103
104
}
104
105
}
105
106
}
106
-
107
+
107
108
public void removeSiteEntry (String url ) {
108
- url =Utils .canonicalizeURL (url );
109
+ url =Utils .canonicalizeURL (url );
109
110
sites .remove (url );
110
111
if (url .startsWith ("platform:" )){ //$NON-NLS-1$
111
112
URL pURL ;
@@ -118,7 +119,7 @@ public void removeSiteEntry(String url) {
118
119
}else {
119
120
relSite = getInstallURL ();
120
121
}
121
-
122
+
122
123
pURL = new URL (url );
123
124
URL rURL = PlatformConfiguration .resolvePlatformURL (pURL , relSite );
124
125
String resolvedURL = rURL .toExternalForm ();
@@ -128,83 +129,88 @@ public void removeSiteEntry(String url) {
128
129
}
129
130
}
130
131
}
131
-
132
+
132
133
public SiteEntry getSiteEntry (String url ) {
133
- url = Utils .canonicalizeURL (url );
134
+ url = Utils .canonicalizeURL (url );
134
135
SiteEntry site = sites .get (url );
135
- if (site == null && linkedConfig != null )
136
+ if (site == null && linkedConfig != null ) {
136
137
site = linkedConfig .getSiteEntry (url );
138
+ }
137
139
return site ;
138
140
}
139
-
141
+
140
142
public SiteEntry [] getSites () {
141
- if (linkedConfig == null )
143
+ if (linkedConfig == null ) {
142
144
return sites .values ().toArray (new SiteEntry [sites .size ()]);
145
+ }
143
146
ArrayList <SiteEntry > combinedSites = new ArrayList <>(sites .values ());
144
147
combinedSites .addAll (linkedConfig .sites .values ());
145
148
return combinedSites .toArray (new SiteEntry [combinedSites .size ()]);
146
149
}
147
-
148
- public Element toXML (Document doc ) throws CoreException {
150
+
151
+ public Element toXML (Document doc ) throws CoreException {
149
152
try {
150
153
Element configElement = doc .createElement (CFG );
151
154
152
155
configElement .setAttribute (CFG_VERSION , VERSION );
153
156
configElement .setAttribute (CFG_DATE , String .valueOf (date .getTime ()));
154
157
String transitory = isTransient () ? "true" : "false" ; //$NON-NLS-1$ //$NON-NLS-2$
155
158
configElement .setAttribute (CFG_TRANSIENT , transitory );
156
-
159
+
157
160
if (linkedConfig != null ) {
158
- // make externalized URL install relative
161
+ // make externalized URL install relative
159
162
configElement .setAttribute (CFG_SHARED_URL , Utils .makeRelative (getInstallURL (), linkedConfig .getURL ()).toExternalForm ());
160
163
}
161
164
162
165
// collect site entries
163
166
for (SiteEntry element : sites .values ()) {
164
- if (linkedConfig != null && linkedConfig .getSiteEntry (element .getURL ().toExternalForm ()) != null )
167
+ if (linkedConfig != null && linkedConfig .getSiteEntry (element .getURL ().toExternalForm ()) != null ) {
165
168
continue ;
169
+ }
166
170
Element siteElement = element .toXML (doc );
167
171
configElement .appendChild (siteElement );
168
172
}
169
-
173
+
170
174
return configElement ;
171
-
175
+
172
176
} catch (Exception e ) {
173
177
throw Utils .newCoreException ("" , e ); //$NON-NLS-1$
174
- }
178
+ }
175
179
}
176
-
180
+
177
181
public boolean isTransient () {
178
182
return transientConfig ;
179
183
}
180
-
184
+
181
185
public void setTransient (boolean isTransient ) {
182
186
this .transientConfig = isTransient ;
183
187
}
184
-
188
+
185
189
public Date getDate () {
186
190
return date ;
187
191
}
188
-
192
+
189
193
public void setDate (Date date ) {
190
194
this .date = date ;
191
195
}
192
-
196
+
193
197
public boolean unconfigureFeatureEntry (IPlatformConfiguration .IFeatureEntry feature ) {
194
- for (SiteEntry site : getSites ())
195
- if (site .unconfigureFeatureEntry (feature ))
198
+ for (SiteEntry site : getSites ()) {
199
+ if (site .unconfigureFeatureEntry (feature )) {
196
200
return true ;
201
+ }
202
+ }
197
203
return false ;
198
204
}
199
-
205
+
200
206
public void setLastModified (long lastModified ) {
201
207
this .lastModified = lastModified ;
202
208
}
203
-
209
+
204
210
public long lastModified () {
205
211
return (lastModified != 0 ) ? lastModified : date .getTime ();
206
212
}
207
-
213
+
208
214
/**
209
215
* Returns the url as a platform:/ url, if possible, else leaves it unchanged
210
216
*/
@@ -213,20 +219,21 @@ public URL asPlatformURL(URL url) {
213
219
if (url .getProtocol ().equals ("file" )) {//$NON-NLS-1$
214
220
String rUrl = url .toExternalForm ();
215
221
URL pUrl = platformURLs .get (rUrl );
216
- if (pUrl == null )
222
+ if (pUrl == null ) {
217
223
return url ;
224
+ }
218
225
return pUrl ;
219
226
}
220
227
return url ;
221
228
} catch (Exception e ) {
222
229
return url ;
223
230
}
224
231
}
225
-
232
+
226
233
public URL getInstallURL () {
227
234
return associatedInstallURL ;
228
235
}
229
-
236
+
230
237
public void setInstallLocation (URL installURL ) {
231
238
associatedInstallURL = installURL ;
232
239
}
0 commit comments