Skip to content

Commit 742066b

Browse files
eclipse-platform-botlaeubi
authored andcommitted
Perform clean code of update/org.eclipse.update.configurator
1 parent 731e745 commit 742066b

21 files changed

+678
-432
lines changed

update/org.eclipse.update.configurator/src/org/eclipse/update/configurator/ConfiguratorUtils.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ public static IPlatformConfiguration getCurrentPlatformConfiguration() {
4848
// acquire factory service first
4949
BundleContext context = ConfigurationActivator.getBundleContext();
5050
ServiceReference<IPlatformConfigurationFactory> configFactorySR = context.getServiceReference(IPlatformConfigurationFactory.class);
51-
if (configFactorySR == null)
51+
if (configFactorySR == null) {
5252
throw new IllegalStateException();
53+
}
5354
IPlatformConfigurationFactory configFactory = context.getService(configFactorySR);
54-
if (configFactory == null)
55+
if (configFactory == null) {
5556
throw new IllegalStateException();
57+
}
5658
// get the configuration using the factory
5759
IPlatformConfiguration currentConfig = configFactory.getCurrentPlatformConfiguration();
5860
context.ungetService(configFactorySR);
@@ -71,11 +73,13 @@ public static IPlatformConfiguration getPlatformConfiguration(URL url) throws IO
7173
// acquire factory service first
7274
BundleContext context = ConfigurationActivator.getBundleContext();
7375
ServiceReference<IPlatformConfigurationFactory> configFactorySR = context.getServiceReference(IPlatformConfigurationFactory.class);
74-
if (configFactorySR == null)
76+
if (configFactorySR == null) {
7577
throw new IllegalStateException();
78+
}
7679
IPlatformConfigurationFactory configFactory = context.getService(configFactorySR);
77-
if (configFactory == null)
80+
if (configFactory == null) {
7881
throw new IllegalStateException();
82+
}
7983
// get the configuration using the factory
8084
IPlatformConfiguration config = configFactory.getPlatformConfiguration(url);
8185
context.ungetService(configFactorySR);
@@ -95,11 +99,13 @@ public static IPlatformConfiguration getPlatformConfiguration(URL url, URL loc)
9599
// acquire factory service first
96100
BundleContext context = ConfigurationActivator.getBundleContext();
97101
ServiceReference<IPlatformConfigurationFactory> configFactorySR = context.getServiceReference(IPlatformConfigurationFactory.class);
98-
if (configFactorySR == null)
102+
if (configFactorySR == null) {
99103
throw new IllegalStateException();
104+
}
100105
IPlatformConfigurationFactory configFactory = context.getService(configFactorySR);
101-
if (configFactory == null)
106+
if (configFactory == null) {
102107
throw new IllegalStateException();
108+
}
103109
// get the configuration using the factory
104110
IPlatformConfiguration config = configFactory.getPlatformConfiguration(url, loc);
105111
context.ungetService(configFactorySR);

update/org.eclipse.update.configurator/src/org/eclipse/update/configurator/IPlatformConfigurationFactory.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* https://www.eclipse.org/legal/epl-2.0/
88
*
99
* SPDX-License-Identifier: EPL-2.0
10-
*
10+
*
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
1313
*******************************************************************************/
@@ -31,29 +31,29 @@
3131
public interface IPlatformConfigurationFactory {
3232
/**
3333
* Returns the current platform configuration.
34-
*
34+
*
3535
* @return platform configuration used in current instance of platform
36-
*/
36+
*/
3737
public IPlatformConfiguration getCurrentPlatformConfiguration();
3838
/**
3939
* Returns a platform configuration object, optionally initialized with previously saved
4040
* configuration information.
41-
*
41+
*
4242
* @param url location of previously save configuration information. If <code>null</code>
4343
* is specified, an empty configuration object is returned
4444
* @return platform configuration used in current instance of platform
45-
*/
45+
*/
4646
public IPlatformConfiguration getPlatformConfiguration(URL url) throws IOException;
47-
47+
4848
/**
4949
* Returns a platform configuration object, optionally initialized with previously saved
5050
* configuration information.
51-
*
51+
*
5252
* @param url location of previously save configuration information. If <code>null</code>
5353
* is specified, an empty configuration object is returned
5454
* @param loc location of the platform installation. Used to resolve entries in the saved
5555
* location
5656
* @return platform configuration used in current instance of platform
57-
*/
57+
*/
5858
public IPlatformConfiguration getPlatformConfiguration(URL url, URL loc) throws IOException;
5959
}

update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/BundleGroupComponent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
public class BundleGroupComponent implements IBundleGroupProvider {
3232

3333

34-
private org.eclipse.update.configurator.IPlatformConfigurationFactory factory;
34+
private final org.eclipse.update.configurator.IPlatformConfigurationFactory factory;
3535

3636
@Activate
3737
public BundleGroupComponent(@Reference org.eclipse.update.configurator.IPlatformConfigurationFactory factory) {
@@ -49,8 +49,9 @@ public IBundleGroup[] getBundleGroups() {
4949
.getConfiguredFeatureEntries();
5050
ArrayList<IBundleGroup> bundleGroups = new ArrayList<>(features.length);
5151
for (org.eclipse.update.configurator.IPlatformConfiguration.IFeatureEntry feature : features) {
52-
if (feature instanceof FeatureEntry && ((FeatureEntry) feature).hasBranding())
52+
if (feature instanceof FeatureEntry && ((FeatureEntry) feature).hasBranding()) {
5353
bundleGroups.add((IBundleGroup) feature);
54+
}
5455
}
5556
return bundleGroups.toArray(new IBundleGroup[bundleGroups.size()]);
5657
}

update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/Configuration.java

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
* Contributors:
1212
* 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
1414
*******************************************************************************/
1515
package org.eclipse.update.internal.configurator;
1616

@@ -25,7 +25,7 @@
2525
import org.w3c.dom.*;
2626

2727
public class Configuration implements IConfigurationConstants {
28-
28+
2929
private final HashMap<String, SiteEntry> sites = new HashMap<>();
3030
private final HashMap<String, URL> platformURLs = new HashMap<>();
3131
private Date date;
@@ -35,7 +35,7 @@ public class Configuration implements IConfigurationConstants {
3535
private boolean isDirty;
3636
private Configuration linkedConfig; // shared configuration
3737
private URL associatedInstallURL = Utils.getInstallURL();
38-
38+
3939
public Configuration() {
4040
this(new Date());
4141
// the config is created now or out of a platform.xml without a date
@@ -44,37 +44,38 @@ public Configuration() {
4444
public Configuration(Date date) {
4545
this.date = date;
4646
}
47-
47+
4848
public void setURL(URL url) {
4949
this.url = url;
5050
}
51-
51+
5252
public URL getURL() {
5353
return url;
5454
}
55-
55+
5656
public void setLinkedConfig(Configuration linkedConfig) {
5757
this.linkedConfig = linkedConfig;
5858
// make all the sites read-only
59-
for (SiteEntry linkedSite : linkedConfig.getSites())
59+
for (SiteEntry linkedSite : linkedConfig.getSites()) {
6060
linkedSite.setUpdateable(false);
61+
}
6162
}
62-
63+
6364
public Configuration getLinkedConfig() {
6465
return linkedConfig;
6566
}
66-
67+
6768
/**
6869
* @return true if the config needs to be saved
6970
*/
7071
public boolean isDirty() {
7172
return isDirty;
7273
}
73-
74+
7475
public void setDirty(boolean dirty) {
7576
isDirty = dirty;
7677
}
77-
78+
7879
public void addSiteEntry(String url, SiteEntry site) {
7980
url = Utils.canonicalizeURL(url);
8081
// only add the same site once
@@ -92,7 +93,7 @@ public void addSiteEntry(String url, SiteEntry site) {
9293
}else{
9394
relSite = getInstallURL();
9495
}
95-
96+
9697
pURL = new URL(url);
9798
URL rURL = PlatformConfiguration.resolvePlatformURL(pURL, relSite);
9899
String resolvedURL = rURL.toExternalForm();
@@ -103,9 +104,9 @@ public void addSiteEntry(String url, SiteEntry site) {
103104
}
104105
}
105106
}
106-
107+
107108
public void removeSiteEntry(String url) {
108-
url =Utils.canonicalizeURL(url);
109+
url =Utils.canonicalizeURL(url);
109110
sites.remove(url);
110111
if(url.startsWith("platform:")){ //$NON-NLS-1$
111112
URL pURL;
@@ -118,7 +119,7 @@ public void removeSiteEntry(String url) {
118119
}else{
119120
relSite = getInstallURL();
120121
}
121-
122+
122123
pURL = new URL(url);
123124
URL rURL = PlatformConfiguration.resolvePlatformURL(pURL, relSite);
124125
String resolvedURL = rURL.toExternalForm();
@@ -128,83 +129,88 @@ public void removeSiteEntry(String url) {
128129
}
129130
}
130131
}
131-
132+
132133
public SiteEntry getSiteEntry(String url) {
133-
url = Utils.canonicalizeURL(url);
134+
url = Utils.canonicalizeURL(url);
134135
SiteEntry site = sites.get(url);
135-
if (site == null && linkedConfig != null)
136+
if (site == null && linkedConfig != null) {
136137
site = linkedConfig.getSiteEntry(url);
138+
}
137139
return site;
138140
}
139-
141+
140142
public SiteEntry[] getSites() {
141-
if (linkedConfig == null)
143+
if (linkedConfig == null) {
142144
return sites.values().toArray(new SiteEntry[sites.size()]);
145+
}
143146
ArrayList<SiteEntry> combinedSites = new ArrayList<>(sites.values());
144147
combinedSites.addAll(linkedConfig.sites.values());
145148
return combinedSites.toArray(new SiteEntry[combinedSites.size()]);
146149
}
147-
148-
public Element toXML(Document doc) throws CoreException {
150+
151+
public Element toXML(Document doc) throws CoreException {
149152
try {
150153
Element configElement = doc.createElement(CFG);
151154

152155
configElement.setAttribute(CFG_VERSION, VERSION);
153156
configElement.setAttribute(CFG_DATE, String.valueOf(date.getTime()));
154157
String transitory = isTransient() ? "true" : "false"; //$NON-NLS-1$ //$NON-NLS-2$
155158
configElement.setAttribute(CFG_TRANSIENT, transitory);
156-
159+
157160
if (linkedConfig != null) {
158-
// make externalized URL install relative
161+
// make externalized URL install relative
159162
configElement.setAttribute(CFG_SHARED_URL, Utils.makeRelative(getInstallURL(), linkedConfig.getURL()).toExternalForm());
160163
}
161164

162165
// collect site entries
163166
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) {
165168
continue;
169+
}
166170
Element siteElement = element.toXML(doc);
167171
configElement.appendChild(siteElement);
168172
}
169-
173+
170174
return configElement;
171-
175+
172176
} catch (Exception e) {
173177
throw Utils.newCoreException("", e); //$NON-NLS-1$
174-
}
178+
}
175179
}
176-
180+
177181
public boolean isTransient() {
178182
return transientConfig;
179183
}
180-
184+
181185
public void setTransient(boolean isTransient) {
182186
this.transientConfig = isTransient;
183187
}
184-
188+
185189
public Date getDate() {
186190
return date;
187191
}
188-
192+
189193
public void setDate(Date date) {
190194
this.date = date;
191195
}
192-
196+
193197
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)) {
196200
return true;
201+
}
202+
}
197203
return false;
198204
}
199-
205+
200206
public void setLastModified(long lastModified) {
201207
this.lastModified = lastModified;
202208
}
203-
209+
204210
public long lastModified() {
205211
return (lastModified != 0) ? lastModified : date.getTime();
206212
}
207-
213+
208214
/**
209215
* Returns the url as a platform:/ url, if possible, else leaves it unchanged
210216
*/
@@ -213,20 +219,21 @@ public URL asPlatformURL(URL url) {
213219
if (url.getProtocol().equals("file")) {//$NON-NLS-1$
214220
String rUrl = url.toExternalForm();
215221
URL pUrl = platformURLs.get(rUrl);
216-
if(pUrl == null)
222+
if(pUrl == null) {
217223
return url;
224+
}
218225
return pUrl;
219226
}
220227
return url;
221228
} catch (Exception e) {
222229
return url;
223230
}
224231
}
225-
232+
226233
public URL getInstallURL() {
227234
return associatedInstallURL;
228235
}
229-
236+
230237
public void setInstallLocation(URL installURL) {
231238
associatedInstallURL = installURL;
232239
}

update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/ConfigurationActivator.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ private void loadOptions() {
5050
// all this is only to get the application args
5151
DebugOptions service = null;
5252
ServiceReference<DebugOptions> reference = context.getServiceReference(DebugOptions.class);
53-
if (reference != null)
53+
if (reference != null) {
5454
service = context.getService(reference);
55-
if (service == null)
55+
}
56+
if (service == null) {
5657
return;
58+
}
5759
try {
5860
DEBUG = service.getBooleanOption(OPTION_DEBUG, false);
5961
} finally {
@@ -68,8 +70,9 @@ public static BundleContext getBundleContext() {
6870

6971
private void acquireFrameworkLogService() {
7072
ServiceReference<FrameworkLog> logServiceReference = context.getServiceReference(FrameworkLog.class);
71-
if (logServiceReference == null)
73+
if (logServiceReference == null) {
7274
return;
75+
}
7376
Utils.log = context.getService(logServiceReference);
7477
}
7578
}

0 commit comments

Comments
 (0)