Skip to content

Clean Code for update/org.eclipse.update.configurator #1954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ public static IPlatformConfiguration getCurrentPlatformConfiguration() {
// acquire factory service first
BundleContext context = ConfigurationActivator.getBundleContext();
ServiceReference<IPlatformConfigurationFactory> configFactorySR = context.getServiceReference(IPlatformConfigurationFactory.class);
if (configFactorySR == null)
if (configFactorySR == null) {
throw new IllegalStateException();
}
IPlatformConfigurationFactory configFactory = context.getService(configFactorySR);
if (configFactory == null)
if (configFactory == null) {
throw new IllegalStateException();
}
// get the configuration using the factory
IPlatformConfiguration currentConfig = configFactory.getCurrentPlatformConfiguration();
context.ungetService(configFactorySR);
Expand All @@ -71,11 +73,13 @@ public static IPlatformConfiguration getPlatformConfiguration(URL url) throws IO
// acquire factory service first
BundleContext context = ConfigurationActivator.getBundleContext();
ServiceReference<IPlatformConfigurationFactory> configFactorySR = context.getServiceReference(IPlatformConfigurationFactory.class);
if (configFactorySR == null)
if (configFactorySR == null) {
throw new IllegalStateException();
}
IPlatformConfigurationFactory configFactory = context.getService(configFactorySR);
if (configFactory == null)
if (configFactory == null) {
throw new IllegalStateException();
}
// get the configuration using the factory
IPlatformConfiguration config = configFactory.getPlatformConfiguration(url);
context.ungetService(configFactorySR);
Expand All @@ -95,11 +99,13 @@ public static IPlatformConfiguration getPlatformConfiguration(URL url, URL loc)
// acquire factory service first
BundleContext context = ConfigurationActivator.getBundleContext();
ServiceReference<IPlatformConfigurationFactory> configFactorySR = context.getServiceReference(IPlatformConfigurationFactory.class);
if (configFactorySR == null)
if (configFactorySR == null) {
throw new IllegalStateException();
}
IPlatformConfigurationFactory configFactory = context.getService(configFactorySR);
if (configFactory == null)
if (configFactory == null) {
throw new IllegalStateException();
}
// get the configuration using the factory
IPlatformConfiguration config = configFactory.getPlatformConfiguration(url, loc);
context.ungetService(configFactorySR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
Expand All @@ -31,29 +31,29 @@
public interface IPlatformConfigurationFactory {
/**
* Returns the current platform configuration.
*
*
* @return platform configuration used in current instance of platform
*/
*/
public IPlatformConfiguration getCurrentPlatformConfiguration();
/**
* Returns a platform configuration object, optionally initialized with previously saved
* configuration information.
*
*
* @param url location of previously save configuration information. If <code>null</code>
* is specified, an empty configuration object is returned
* @return platform configuration used in current instance of platform
*/
*/
public IPlatformConfiguration getPlatformConfiguration(URL url) throws IOException;

/**
* Returns a platform configuration object, optionally initialized with previously saved
* configuration information.
*
*
* @param url location of previously save configuration information. If <code>null</code>
* is specified, an empty configuration object is returned
* @param loc location of the platform installation. Used to resolve entries in the saved
* location
* @return platform configuration used in current instance of platform
*/
*/
public IPlatformConfiguration getPlatformConfiguration(URL url, URL loc) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class BundleGroupComponent implements IBundleGroupProvider {


private org.eclipse.update.configurator.IPlatformConfigurationFactory factory;
private final org.eclipse.update.configurator.IPlatformConfigurationFactory factory;

@Activate
public BundleGroupComponent(@Reference org.eclipse.update.configurator.IPlatformConfigurationFactory factory) {
Expand All @@ -49,8 +49,9 @@ public IBundleGroup[] getBundleGroups() {
.getConfiguredFeatureEntries();
ArrayList<IBundleGroup> bundleGroups = new ArrayList<>(features.length);
for (org.eclipse.update.configurator.IPlatformConfiguration.IFeatureEntry feature : features) {
if (feature instanceof FeatureEntry && ((FeatureEntry) feature).hasBranding())
if (feature instanceof FeatureEntry && ((FeatureEntry) feature).hasBranding()) {
bundleGroups.add((IBundleGroup) feature);
}
}
return bundleGroups.toArray(new IBundleGroup[bundleGroups.size()]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
* James D Miles (IBM Corp.) - bug 176250, Configurator needs to handle more platform urls
* James D Miles (IBM Corp.) - bug 176250, Configurator needs to handle more platform urls
*******************************************************************************/
package org.eclipse.update.internal.configurator;

Expand All @@ -25,7 +25,7 @@
import org.w3c.dom.*;

public class Configuration implements IConfigurationConstants {

private final HashMap<String, SiteEntry> sites = new HashMap<>();
private final HashMap<String, URL> platformURLs = new HashMap<>();
private Date date;
Expand All @@ -35,7 +35,7 @@
private boolean isDirty;
private Configuration linkedConfig; // shared configuration
private URL associatedInstallURL = Utils.getInstallURL();

public Configuration() {
this(new Date());
// the config is created now or out of a platform.xml without a date
Expand All @@ -44,37 +44,38 @@
public Configuration(Date date) {
this.date = date;
}

public void setURL(URL url) {
this.url = url;
}

public URL getURL() {
return url;
}

public void setLinkedConfig(Configuration linkedConfig) {
this.linkedConfig = linkedConfig;
// make all the sites read-only
for (SiteEntry linkedSite : linkedConfig.getSites())
for (SiteEntry linkedSite : linkedConfig.getSites()) {
linkedSite.setUpdateable(false);
}
}

public Configuration getLinkedConfig() {
return linkedConfig;
}

/**
* @return true if the config needs to be saved
*/
public boolean isDirty() {
return isDirty;
}

public void setDirty(boolean dirty) {
isDirty = dirty;
}

public void addSiteEntry(String url, SiteEntry site) {
url = Utils.canonicalizeURL(url);
// only add the same site once
Expand All @@ -92,7 +93,7 @@
}else{
relSite = getInstallURL();
}

pURL = new URL(url);
URL rURL = PlatformConfiguration.resolvePlatformURL(pURL, relSite);
String resolvedURL = rURL.toExternalForm();
Expand All @@ -103,9 +104,9 @@
}
}
}

public void removeSiteEntry(String url) {
url =Utils.canonicalizeURL(url);
url =Utils.canonicalizeURL(url);
sites.remove(url);
if(url.startsWith("platform:")){ //$NON-NLS-1$
URL pURL;
Expand All @@ -118,7 +119,7 @@
}else{
relSite = getInstallURL();
}

pURL = new URL(url);
URL rURL = PlatformConfiguration.resolvePlatformURL(pURL, relSite);
String resolvedURL = rURL.toExternalForm();
Expand All @@ -128,83 +129,88 @@
}
}
}

public SiteEntry getSiteEntry(String url) {
url = Utils.canonicalizeURL(url);
url = Utils.canonicalizeURL(url);
SiteEntry site = sites.get(url);
if (site == null && linkedConfig != null)
if (site == null && linkedConfig != null) {
site = linkedConfig.getSiteEntry(url);
}
return site;
}

public SiteEntry[] getSites() {
if (linkedConfig == null)
if (linkedConfig == null) {
return sites.values().toArray(new SiteEntry[sites.size()]);
}
ArrayList<SiteEntry> combinedSites = new ArrayList<>(sites.values());
combinedSites.addAll(linkedConfig.sites.values());
return combinedSites.toArray(new SiteEntry[combinedSites.size()]);
}
public Element toXML(Document doc) throws CoreException {

public Element toXML(Document doc) throws CoreException {
try {
Element configElement = doc.createElement(CFG);

configElement.setAttribute(CFG_VERSION, VERSION);
configElement.setAttribute(CFG_DATE, String.valueOf(date.getTime()));
String transitory = isTransient() ? "true" : "false"; //$NON-NLS-1$ //$NON-NLS-2$
configElement.setAttribute(CFG_TRANSIENT, transitory);

if (linkedConfig != null) {
// make externalized URL install relative
// make externalized URL install relative
configElement.setAttribute(CFG_SHARED_URL, Utils.makeRelative(getInstallURL(), linkedConfig.getURL()).toExternalForm());
}

// collect site entries
for (SiteEntry element : sites.values()) {
if (linkedConfig != null && linkedConfig.getSiteEntry(element.getURL().toExternalForm()) != null)
if (linkedConfig != null && linkedConfig.getSiteEntry(element.getURL().toExternalForm()) != null) {
continue;
}
Element siteElement = element.toXML(doc);
configElement.appendChild(siteElement);
}

return configElement;

} catch (Exception e) {
throw Utils.newCoreException("", e); //$NON-NLS-1$
}
}
}

public boolean isTransient() {
return transientConfig;
}

public void setTransient(boolean isTransient) {
this.transientConfig = isTransient;
}

public Date getDate() {
return date;
}

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

public boolean unconfigureFeatureEntry(IPlatformConfiguration.IFeatureEntry feature) {

Check warning on line 197 in update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/Configuration.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

Deprecation

NORMAL: The type IPlatformConfiguration has been deprecated since version 2025-06 (removal in 2027-06 or later) and marked for removal

Check warning on line 197 in update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/Configuration.java

View check run for this annotation

Jenkins - Eclipse Platform / Compiler

Deprecation

NORMAL: The type IPlatformConfiguration.IFeatureEntry has been deprecated and marked for removal
for (SiteEntry site : getSites())
if (site.unconfigureFeatureEntry(feature))
for (SiteEntry site : getSites()) {
if (site.unconfigureFeatureEntry(feature)) {
return true;
}
}
return false;
}

public void setLastModified(long lastModified) {
this.lastModified = lastModified;
}

public long lastModified() {
return (lastModified != 0) ? lastModified : date.getTime();
}

/**
* Returns the url as a platform:/ url, if possible, else leaves it unchanged
*/
Expand All @@ -213,20 +219,21 @@
if (url.getProtocol().equals("file")) {//$NON-NLS-1$
String rUrl = url.toExternalForm();
URL pUrl = platformURLs.get(rUrl);
if(pUrl == null)
if(pUrl == null) {
return url;
}
return pUrl;
}
return url;
} catch (Exception e) {
return url;
}
}

public URL getInstallURL() {
return associatedInstallURL;
}

public void setInstallLocation(URL installURL) {
associatedInstallURL = installURL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ private void loadOptions() {
// all this is only to get the application args
DebugOptions service = null;
ServiceReference<DebugOptions> reference = context.getServiceReference(DebugOptions.class);
if (reference != null)
if (reference != null) {
service = context.getService(reference);
if (service == null)
}
if (service == null) {
return;
}
try {
DEBUG = service.getBooleanOption(OPTION_DEBUG, false);
} finally {
Expand All @@ -68,8 +70,9 @@ public static BundleContext getBundleContext() {

private void acquireFrameworkLogService() {
ServiceReference<FrameworkLog> logServiceReference = context.getServiceReference(FrameworkLog.class);
if (logServiceReference == null)
if (logServiceReference == null) {
return;
}
Utils.log = context.getService(logServiceReference);
}
}
Loading
Loading