diff options
author | Carsten Hammer | 2019-09-25 20:02:50 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2019-10-16 05:15:19 +0000 |
commit | 79098619b63c156419bfc0adfb62c728e446f1c5 (patch) | |
tree | b75f5ed8f43dd4fef1640ae659f127e2d783c344 | |
parent | 55af3c84c9551c91b30db58af3d71aa03ca2b033 (diff) | |
download | rt.equinox.p2-79098619b63c156419bfc0adfb62c728e446f1c5.tar.gz rt.equinox.p2-79098619b63c156419bfc0adfb62c728e446f1c5.tar.xz rt.equinox.p2-79098619b63c156419bfc0adfb62c728e446f1c5.zip |
Use jdk 5 for-each loop
Replace simple uses of Iterator with a corresponding for-loop. Also add
missing braces on loops as necessary.
Change-Id: I88bd9ca5cd161ef4977afc12c36b28ad1517a5de
Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
6 files changed, 130 insertions, 113 deletions
diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/LocalUpdateSiteAction.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/LocalUpdateSiteAction.java index 6b6647813..59062c50a 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/LocalUpdateSiteAction.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/LocalUpdateSiteAction.java @@ -70,10 +70,10 @@ public class LocalUpdateSiteAction implements IPublisherAction { public IStatus perform(IPublisherInfo info, IPublisherResult results, IProgressMonitor monitor) { IPublisherAction[] actions = createActions(); MultiStatus finalStatus = new MultiStatus(LocalUpdateSiteAction.class.getName(), 0, NLS.bind(Messages.Error_Generation, source != null ? source : (updateSite != null ? updateSite.getLocation().toString() : "Unknown")), null); //$NON-NLS-1$ - for (int i = 0; i < actions.length; i++) { + for (IPublisherAction action : actions) { if (monitor.isCanceled()) return Status.CANCEL_STATUS; - finalStatus.merge(actions[i].perform(info, results, monitor)); + finalStatus.merge(action.perform(info, results, monitor)); } if (!finalStatus.isOK()) return finalStatus; diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/RemoteFeaturesAction.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/RemoteFeaturesAction.java index 5bd710202..70197d9f7 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/RemoteFeaturesAction.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/RemoteFeaturesAction.java @@ -56,11 +56,9 @@ public class RemoteFeaturesAction extends FeaturesAction { protected void generateFeatureIUs(Feature[] featureList, IPublisherResult result) { Map<String, String> extraProperties = new HashMap<>(); extraProperties.put(IInstallableUnit.PROP_PARTIAL_IU, Boolean.TRUE.toString()); - for (int i = 0; i < featureList.length; i++) { - Feature feature = featureList[i]; + for (Feature feature : featureList) { FeatureEntry[] featureEntries = feature.getEntries(); - for (int j = 0; j < featureEntries.length; j++) { - FeatureEntry entry = featureEntries[j]; + for (FeatureEntry entry : featureEntries) { if (entry.isPlugin() && !entry.isRequires()) { Dictionary<String, String> mockManifest = new Hashtable<>(); mockManifest.put("Manifest-Version", "1.0"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -70,8 +68,9 @@ public class RemoteFeaturesAction extends FeaturesAction { BundleDescription bundleDescription = BundlesAction.createBundleDescription(mockManifest, null); IArtifactKey key = BundlesAction.createBundleArtifactKey(entry.getId(), entry.getVersion()); IInstallableUnit[] bundleIUs = EclipsePublisherHelper.createEclipseIU(bundleDescription, entry.isUnpack(), key, extraProperties); - for (int n = 0; n < bundleIUs.length; n++) - result.addIU(bundleIUs[n], IPublisherResult.ROOT); + for (IInstallableUnit bundleIU : bundleIUs) { + result.addIU(bundleIU, IPublisherResult.ROOT); + } } } IInstallableUnit featureIU = createFeatureJarIU(feature, new PublisherInfo()); diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/RemoteUpdateSiteAction.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/RemoteUpdateSiteAction.java index cb0fd5ca5..53fb8b936 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/RemoteUpdateSiteAction.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/RemoteUpdateSiteAction.java @@ -48,10 +48,10 @@ public class RemoteUpdateSiteAction implements IPublisherAction { Tracing.debug("Generating metadata for update site: " + updateSite.getLocation()); //$NON-NLS-1$ IPublisherAction[] actions = createActions(); MultiStatus finalStatus = new MultiStatus(this.getClass().getName(), 0, NLS.bind(Messages.Error_Generation, updateSite != null ? updateSite.getLocation().toString() : "Unknown"), null); //$NON-NLS-1$ - for (int i = 0; i < actions.length; i++) { + for (IPublisherAction action : actions) { if (monitor.isCanceled()) return Status.CANCEL_STATUS; - finalStatus.merge(actions[i].perform(info, results, monitor)); + finalStatus.merge(action.perform(info, results, monitor)); } if (Tracing.DEBUG_PUBLISHING) Tracing.debug("Generation for update site complete: " + updateSite.getLocation()); //$NON-NLS-1$ diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java index 97e5c8ee3..5b443c686 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java @@ -272,13 +272,13 @@ public class SiteXMLAction extends AbstractPublisherAction { return mappings; SiteIU[] ius = site.getIUs(); - for (int i = 0; i < ius.length; i++) { + for (SiteIU iu : ius) { // add a mapping for each category this feature belongs to - String[] categoryNames = ius[i].getCategoryNames(); + String[] categoryNames = iu.getCategoryNames(); Set<SiteCategory> categories = new HashSet<>(); - mappings.put(ius[i], categories); - for (int j = 0; j < categoryNames.length; j++) { - SiteCategory category = site.getCategory(categoryNames[j]); + mappings.put(iu, categories); + for (String categoryName : categoryNames) { + SiteCategory category = site.getCategory(categoryName); if (category != null) categories.add(category); } @@ -433,16 +433,16 @@ public class SiteXMLAction extends AbstractPublisherAction { return mappings; SiteFeature[] features = site.getFeatures(); - for (int i = 0; i < features.length; i++) { + for (SiteFeature feature : features) { // add a mapping for each category this feature belongs to - String[] categoryNames = features[i].getCategoryNames(); - Set<SiteCategory> categories = mappings.get(features[i]); + String[] categoryNames = feature.getCategoryNames(); + Set<SiteCategory> categories = mappings.get(feature); if (categories == null) { categories = new HashSet<>(); - mappings.put(features[i], categories); + mappings.put(feature, categories); } - for (int j = 0; j < categoryNames.length; j++) { - SiteCategory category = site.getCategory(categoryNames[j]); + for (String categoryName : categoryNames) { + SiteCategory category = site.getCategory(categoryName); if (category != null) categories.add(category); } @@ -465,13 +465,13 @@ public class SiteXMLAction extends AbstractPublisherAction { return mappings; SiteBundle[] bundles = site.getBundles(); - for (int i = 0; i < bundles.length; i++) { + for (SiteBundle bundle : bundles) { // add a mapping for each category this feature belongs to - String[] categoryNames = bundles[i].getCategoryNames(); + String[] categoryNames = bundle.getCategoryNames(); Set<SiteCategory> categories = new HashSet<>(); - mappings.put(bundles[i], categories); - for (int j = 0; j < categoryNames.length; j++) { - SiteCategory category = site.getCategory(categoryNames[j]); + mappings.put(bundle, categories); + for (String categoryName : categoryNames) { + SiteCategory category = site.getCategory(categoryName); if (category != null) categories.add(category); } @@ -505,16 +505,15 @@ public class SiteXMLAction extends AbstractPublisherAction { URLEntry[] associatedSites = site.getAssociatedSites(); if (associatedSites != null) { ArrayList<IRepositoryReference> refs = new ArrayList<>(associatedSites.length * 2); - for (int i = 0; i < associatedSites.length; i++) { - URLEntry associatedSite = associatedSites[i]; + for (URLEntry associatedSite : associatedSites) { String siteLocation = associatedSite.getURL(); try { URI associateLocation = new URI(siteLocation); String label = associatedSite.getAnnotation(); refs.add(new RepositoryReference(associateLocation, label, IRepository.TYPE_METADATA, - IRepository.ENABLED)); + IRepository.ENABLED)); refs.add(new RepositoryReference(associateLocation, label, IRepository.TYPE_ARTIFACT, - IRepository.ENABLED)); + IRepository.ENABLED)); } catch (URISyntaxException e) { String message = "Invalid site reference: " + siteLocation; //$NON-NLS-1$ LogHelper.log(new Status(IStatus.ERROR, Activator.ID, message)); diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/UpdateSite.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/UpdateSite.java index d3398d4b0..7634cf5ea 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/UpdateSite.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/UpdateSite.java @@ -82,12 +82,14 @@ public class UpdateSite { /** * Loads and returns a category file + * * @param location * @param monitor * @return A CategoryFile * @throws ProvisionException */ - public static synchronized UpdateSite loadCategoryFile(URI location, Transport transport, IProgressMonitor monitor) throws ProvisionException { + public static synchronized UpdateSite loadCategoryFile(URI location, Transport transport, IProgressMonitor monitor) + throws ProvisionException { if (location == null) return null; UpdateSite result = null; @@ -95,7 +97,7 @@ public class UpdateSite { result = categoryCache.get(location.toString()).get(); if (result != null) return result; - //else soft reference has been cleared, take it out of the cache + // else soft reference has been cleared, take it out of the cache categoryCache.remove(location.toString()); } @@ -113,10 +115,12 @@ public class UpdateSite { return result; } catch (SAXException e) { String msg = NLS.bind(Messages.ErrorReadingSite, location); - throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, msg, e)); + throw new ProvisionException( + new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, msg, e)); } catch (IOException e) { String msg = NLS.bind(Messages.ErrorReadingSite, location); - throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, msg, e)); + throw new ProvisionException( + new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, msg, e)); } finally { try { if (input != null) @@ -132,17 +136,18 @@ public class UpdateSite { /* * Load and return an update site object from the given location. */ - public static synchronized UpdateSite load(URI location, Transport transport, IProgressMonitor monitor) throws ProvisionException { + public static synchronized UpdateSite load(URI location, Transport transport, IProgressMonitor monitor) + throws ProvisionException { if (location == null) return null; UpdateSite result = null; - //only caching remote sites + // only caching remote sites if (!PROTOCOL_FILE.equals(location.getScheme()) && siteCache.containsKey(location.toString())) { result = siteCache.get(location.toString()).get(); if (result != null) return result; - //else soft reference has been cleared, take it out of the cache + // else soft reference has been cleared, take it out of the cache siteCache.remove(location.toString()); } @@ -160,10 +165,12 @@ public class UpdateSite { return result; } catch (SAXException e) { String msg = NLS.bind(Messages.ErrorReadingSite, location); - throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, msg, e)); + throw new ProvisionException( + new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, msg, e)); } catch (IOException e) { String msg = NLS.bind(Messages.ErrorReadingSite, location); - throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, msg, e)); + throw new ProvisionException( + new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, msg, e)); } finally { try { if (input != null) @@ -177,9 +184,11 @@ public class UpdateSite { } /** - * Returns a local file containing the contents of the update site at the given location. + * Returns a local file containing the contents of the update site at the given + * location. */ - private static File loadActualSiteFile(URI location, URI actualLocation, Transport transport, IProgressMonitor monitor) throws ProvisionException { + private static File loadActualSiteFile(URI location, URI actualLocation, Transport transport, + IProgressMonitor monitor) throws ProvisionException { SubMonitor submonitor = SubMonitor.convert(monitor, 1000); try { File siteFile = null; @@ -192,7 +201,8 @@ public class UpdateSite { transferResult = Status.OK_STATUS; else { String msg = NLS.bind(Messages.ErrorReadingSite, location); - transferResult = new Status(IStatus.ERROR, Activator.ID, ProvisionException.ARTIFACT_NOT_FOUND, msg, new FileNotFoundException(siteFile.getAbsolutePath())); + transferResult = new Status(IStatus.ERROR, Activator.ID, ProvisionException.ARTIFACT_NOT_FOUND, + msg, new FileNotFoundException(siteFile.getAbsolutePath())); } } else { // creating a temp file. In the event of an error we want to delete it. @@ -202,7 +212,8 @@ public class UpdateSite { siteFile = File.createTempFile("site", ".xml"); //$NON-NLS-1$//$NON-NLS-2$ destination = new BufferedOutputStream(new FileOutputStream(siteFile)); } catch (IOException e) { - throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.INTERNAL_ERROR, "Can not create tempfile for site.xml", e)); //$NON-NLS-1$ + throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, + ProvisionException.INTERNAL_ERROR, "Can not create tempfile for site.xml", e)); //$NON-NLS-1$ } try { transferResult = transport.download(actualLocation, destination, submonitor.newChild(999)); @@ -210,14 +221,16 @@ public class UpdateSite { try { destination.close(); } catch (IOException e) { - throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.INTERNAL_ERROR, "Failing to close tempfile for site.xml", e)); //$NON-NLS-1$ + throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, + ProvisionException.INTERNAL_ERROR, "Failing to close tempfile for site.xml", e)); //$NON-NLS-1$ } } } if (monitor.isCanceled()) throw new OperationCanceledException(); if (transferResult.isOK()) { - // successful. If the siteFile is the download of a remote site.xml it will get cleaned up later + // successful. If the siteFile is the download of a remote site.xml it will get + // cleaned up later deleteSiteFile = false; return siteFile; } @@ -231,8 +244,11 @@ public class UpdateSite { if (transferResult.getException() instanceof FileNotFoundException) ms = new MultiStatus(Activator.ID, // ProvisionException.REPOSITORY_NOT_FOUND, - // (code == ProvisionException.ARTIFACT_NOT_FOUND || code == ProvisionException.REPOSITORY_NOT_FOUND ? ProvisionException.REPOSITORY_NOT_FOUND : ProvisionException.REPOSITORY_FAILED_READ), // - new IStatus[] {transferResult}, // + // (code == ProvisionException.ARTIFACT_NOT_FOUND || code == + // ProvisionException.REPOSITORY_NOT_FOUND ? + // ProvisionException.REPOSITORY_NOT_FOUND : + // ProvisionException.REPOSITORY_FAILED_READ), // + new IStatus[] { transferResult }, // NLS.bind(Messages.ErrorReadingSite, location), null); else ms = transferResult; @@ -249,8 +265,9 @@ public class UpdateSite { } /* - * Parse the feature.xml specified by the given input stream and return the feature object. - * In case of failure, the failure is logged and null is returned + * Parse the feature.xml specified by the given input stream and return the + * feature object. In case of failure, the failure is logged and null is + * returned */ private Feature parseFeature(FeatureParser featureParser, URI featureURI, IProgressMonitor monitor) { File featureFile = null; @@ -261,7 +278,7 @@ public class UpdateSite { try { featureFile = File.createTempFile(FEATURE_TEMP_FILE, JAR_EXTENSION); IStatus transferResult = null; - //try the download twice in case of transient network problems + // try the download twice in case of transient network problems for (int i = 0; i < RETRY_COUNT; i++) { if (monitor.isCanceled()) throw new OperationCanceledException(); @@ -272,7 +289,8 @@ public class UpdateSite { try { destination.close(); } catch (IOException e) { - LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingFeature, featureURI), e)); + LogHelper.log(new Status(IStatus.ERROR, Activator.ID, + NLS.bind(Messages.ErrorReadingFeature, featureURI), e)); return null; } } @@ -287,7 +305,8 @@ public class UpdateSite { } return featureParser.parse(featureFile); } catch (IOException e) { - LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingFeature, featureURI), e)); + LogHelper.log( + new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingFeature, featureURI), e)); } finally { if (featureFile != null) featureFile.delete(); @@ -317,8 +336,8 @@ public class UpdateSite { } /* - * Iterate over the archive entries in this site and return the matching URI string for - * the given identifier, if there is one. + * Iterate over the archive entries in this site and return the matching URI + * string for the given identifier, if there is one. */ private URI getArchiveURI(URI base, String identifier) { URLEntry[] archives = site.getArchives(); @@ -346,7 +365,7 @@ public class UpdateSite { if (url != null) return URIUtil.toURI(url); } catch (URISyntaxException e) { - //fall through and resolve the URI ourselves + // fall through and resolve the URI ourselves } URI base = getBaseURI(); String featureURIString = siteFeature.getURLString(); @@ -362,7 +381,7 @@ public class UpdateSite { if (url != null) return URIUtil.toURI(url); } catch (URISyntaxException e) { - //fall through and resolve the URI ourselves + // fall through and resolve the URI ourselves } URI base = getBaseURI(); String bundleURIString = siteBundle.getURLString(); @@ -374,9 +393,9 @@ public class UpdateSite { */ public URI getFeatureURI(String id, String version) { SiteFeature[] entries = site.getFeatures(); - for (int i = 0; i < entries.length; i++) { - if (id.equals(entries[i].getFeatureIdentifier()) && version.equals(entries[i].getFeatureVersion())) { - return getSiteFeatureURI(entries[i]); + for (SiteFeature entry : entries) { + if (id.equals(entry.getFeatureIdentifier()) && version.equals(entry.getFeatureVersion())) { + return getSiteFeatureURI(entry); } } @@ -392,9 +411,9 @@ public class UpdateSite { */ public URI getBundleURI(String id, String version) { SiteBundle[] entries = site.getBundles(); - for (int i = 0; i < entries.length; i++) { - if (id.equals(entries[i].getBundleIdentifier()) && version.equals(entries[i].getBundleVersion())) { - return getSiteBundleURI(entries[i]); + for (SiteBundle entry : entries) { + if (id.equals(entry.getBundleIdentifier()) && version.equals(entry.getBundleVersion())) { + return getSiteBundleURI(entry); } } @@ -413,11 +432,11 @@ public class UpdateSite { } public String getMirrorsURI() { - //copy mirror information from update site to p2 repositories + // copy mirror information from update site to p2 repositories String mirrors = site.getMirrorsURI(); if (mirrors == null) return null; - //remove site.xml file reference + // remove site.xml file reference int index = mirrors.indexOf("site.xml"); //$NON-NLS-1$ if (index != -1) mirrors = mirrors.substring(0, index) + mirrors.substring(index + "site.xml".length()); //$NON-NLS-1$ @@ -457,9 +476,9 @@ public class UpdateSite { } /* - * The trailing parameter can be either null, relative or absolute. If it is null, - * then return null. If it is absolute, then create a new url and return it. If it is - * relative, then make it relative to the given base url. + * The trailing parameter can be either null, relative or absolute. If it is + * null, then return null. If it is absolute, then create a new url and return + * it. If it is relative, then make it relative to the given base url. */ private URI internalGetURI(URI base, String trailing) { if (trailing == null) @@ -488,8 +507,8 @@ public class UpdateSite { } /* - * Try and load the feature information from the update site's - * digest file, if it exists. + * Try and load the feature information from the update site's digest file, if + * it exists. */ private Feature[] loadFeaturesFromDigest(IProgressMonitor monitor) { File digestFile = null; @@ -511,7 +530,8 @@ public class UpdateSite { try { destination.close(); } catch (IOException e) { - LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingFeature, location), e)); + LogHelper.log(new Status(IStatus.ERROR, Activator.ID, + NLS.bind(Messages.ErrorReadingFeature, location), e)); return null; } } @@ -524,14 +544,14 @@ public class UpdateSite { if (features == null) return null; Map<String, Feature> tmpFeatureCache = new HashMap<>(features.length); - for (int i = 0; i < features.length; i++) { - String key = features[i].getId() + VERSION_SEPARATOR + features[i].getVersion(); - tmpFeatureCache.put(key, features[i]); + for (Feature feature : features) { + String key = feature.getId() + VERSION_SEPARATOR + feature.getVersion(); + tmpFeatureCache.put(key, feature); } featureCache = tmpFeatureCache; return features; } catch (FileNotFoundException fnfe) { - // we do not track FNF exceptions as we will fall back to the + // we do not track FNF exceptions as we will fall back to the // standard feature parsing from the site itself, see bug 225587. } catch (IOException e) { LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingDigest, location), e)); @@ -558,19 +578,19 @@ public class UpdateSite { } /* - * Load and return the features that are referenced by this update site. Note this - * requires downloading and parsing the feature manifest locally. + * Load and return the features that are referenced by this update site. Note + * this requires downloading and parsing the feature manifest locally. */ private Feature[] loadFeaturesFromSite(IProgressMonitor monitor) throws ProvisionException { SiteFeature[] siteFeatures = site.getFeatures(); FeatureParser featureParser = new FeatureParser(); Map<String, Feature> tmpFeatureCache = new HashMap<>(siteFeatures.length); - for (int i = 0; i < siteFeatures.length; i++) { + for (SiteFeature siteFeature1 : siteFeatures) { if (monitor.isCanceled()) { throw new OperationCanceledException(); } - SiteFeature siteFeature = siteFeatures[i]; + SiteFeature siteFeature = siteFeature1; String key = null; if (siteFeature.getFeatureIdentifier() != null && siteFeature.getFeatureVersion() != null) { key = siteFeature.getFeatureIdentifier() + VERSION_SEPARATOR + siteFeature.getFeatureVersion(); @@ -580,7 +600,8 @@ public class UpdateSite { URI featureURI = getSiteFeatureURI(siteFeature); Feature feature = parseFeature(featureParser, featureURI, new NullProgressMonitor()); if (feature == null) { - LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingFeature, featureURI))); + LogHelper.log( + new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingFeature, featureURI))); } else { if (key == null) { siteFeature.setFeatureIdentifier(feature.getId()); @@ -598,22 +619,23 @@ public class UpdateSite { /* * Load the features that are included by the given feature. */ - private void loadIncludedFeatures(Feature feature, FeatureParser featureParser, Map<String, Feature> features, IProgressMonitor monitor) throws ProvisionException { + private void loadIncludedFeatures(Feature feature, FeatureParser featureParser, Map<String, Feature> features, + IProgressMonitor monitor) throws ProvisionException { FeatureEntry[] featureEntries = feature.getEntries(); - for (int i = 0; i < featureEntries.length; i++) { + for (FeatureEntry featureEntry : featureEntries) { if (monitor.isCanceled()) throw new OperationCanceledException(); - FeatureEntry entry = featureEntries[i]; + FeatureEntry entry = featureEntry; if (entry.isRequires() || entry.isPlugin()) continue; String key = entry.getId() + VERSION_SEPARATOR + entry.getVersion(); if (features.containsKey(key)) continue; - URI includedFeatureURI = getFeatureURI(entry.getId(), entry.getVersion()); Feature includedFeature = parseFeature(featureParser, includedFeatureURI, monitor); if (includedFeature == null) { - LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingFeature, includedFeatureURI))); + LogHelper.log(new Status(IStatus.ERROR, Activator.ID, + NLS.bind(Messages.ErrorReadingFeature, includedFeatureURI))); } else { features.put(key, includedFeature); loadIncludedFeatures(includedFeature, featureParser, features, monitor); @@ -622,18 +644,17 @@ public class UpdateSite { } /* - * Load and return the bundles that are referenced by this update site. Note this - * requires downloading and parsing the feature manifest locally. + * Load and return the bundles that are referenced by this update site. Note + * this requires downloading and parsing the feature manifest locally. */ private BundleDescription[] loadBundlesFromSite(IProgressMonitor monitor) { SiteBundle[] siteBundles = site.getBundles(); Map<String, BundleDescription> tmpBundleCache = new HashMap<>(siteBundles.length); - for (int i = 0; i < siteBundles.length; i++) { + for (SiteBundle siteBundle : siteBundles) { if (monitor.isCanceled()) { throw new OperationCanceledException(); } - SiteBundle siteBundle = siteBundles[i]; String key = null; if (siteBundle.getBundleIdentifier() != null && siteBundle.getBundleVersion() != null) { key = siteBundle.getBundleIdentifier() + VERSION_SEPARATOR + siteBundle.getBundleVersion(); @@ -643,12 +664,14 @@ public class UpdateSite { URI bundleURI = getSiteBundleURI(siteBundle); BundleDescription bundle = parseBundleDescription(bundleURI, monitor); if (bundle == null) { - LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingBundle, bundleURI))); + LogHelper + .log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingBundle, bundleURI))); } else { if (key == null) { siteBundle.setBundleIdentifier(bundle.getSymbolicName()); siteBundle.setBundleVersion(bundle.getVersion().toString()); - key = siteBundle.getBundleIdentifier() + VERSION_SEPARATOR + siteBundle.getBundleVersion().toString(); + key = siteBundle.getBundleIdentifier() + VERSION_SEPARATOR + + siteBundle.getBundleVersion().toString(); } tmpBundleCache.put(key, bundle); } @@ -658,8 +681,8 @@ public class UpdateSite { } /* - * Reads a bundle and extract its BundleDescription - * In case of failure, the failure is logged and null is returned + * Reads a bundle and extract its BundleDescription In case of failure, the + * failure is logged and null is returned */ private BundleDescription parseBundleDescription(URI bundleURI, IProgressMonitor monitor) { File bundleFile = null; @@ -669,7 +692,7 @@ public class UpdateSite { try { bundleFile = File.createTempFile("bundle", JAR_EXTENSION); //$NON-NLS-1$ IStatus transferResult = null; - //try the download twice in case of transient network problems + // try the download twice in case of transient network problems for (int i = 0; i < RETRY_COUNT; i++) { if (monitor.isCanceled()) throw new OperationCanceledException(); @@ -680,7 +703,8 @@ public class UpdateSite { try { destination.close(); } catch (IOException e) { - LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingFeature, bundleURI), e)); + LogHelper.log(new Status(IStatus.ERROR, Activator.ID, + NLS.bind(Messages.ErrorReadingFeature, bundleURI), e)); return null; } } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/artifact/UpdateSiteArtifactRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/artifact/UpdateSiteArtifactRepositoryFactory.java index 3879f9ffa..9e5eacb11 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/artifact/UpdateSiteArtifactRepositoryFactory.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/artifact/UpdateSiteArtifactRepositoryFactory.java @@ -121,32 +121,28 @@ public class UpdateSiteArtifactRepositoryFactory extends ArtifactRepositoryFacto boolean packSupported = updateSite.getSite().isPack200Supported(); { Feature[] features = updateSite.loadFeatures(monitor); - for (int i = 0; i < features.length; i++) { - Feature feature = features[i]; + for (Feature feature : features) { IArtifactKey featureKey = FeaturesAction.createFeatureArtifactKey(feature.getId(), - feature.getVersion()); + feature.getVersion()); SimpleArtifactDescriptor featureArtifactDescriptor = new SimpleArtifactDescriptor(featureKey); URI featureURL = updateSite.getFeatureURI(feature.getId(), feature.getVersion()); featureArtifactDescriptor.setRepositoryProperty(PROP_ARTIFACT_REFERENCE, featureURL.toString()); allSiteArtifacts.add(featureArtifactDescriptor); - if (packSupported) { // Update site supports pack200, create a packed descriptor featureArtifactDescriptor = new SimpleArtifactDescriptor(featureKey); featureURL = updateSite.getFeatureURI(feature.getId(), feature.getVersion()); featureArtifactDescriptor.setRepositoryProperty(PROP_ARTIFACT_REFERENCE, - featureURL.toString() + PACK_EXT); + featureURL.toString() + PACK_EXT); IProcessingStepDescriptor[] steps = new IProcessingStepDescriptor[] { new ProcessingStepDescriptor( - "org.eclipse.equinox.p2.processing.Pack200Unpacker", null, true) }; //$NON-NLS-1$ + "org.eclipse.equinox.p2.processing.Pack200Unpacker", null, true) }; //$NON-NLS-1$ featureArtifactDescriptor.setProcessingSteps(steps); featureArtifactDescriptor.setProperty(IArtifactDescriptor.FORMAT, - IArtifactDescriptor.FORMAT_PACKED); + IArtifactDescriptor.FORMAT_PACKED); allSiteArtifacts.add(featureArtifactDescriptor); } - FeatureEntry[] featureEntries = feature.getEntries(); - for (int j = 0; j < featureEntries.length; j++) { - FeatureEntry entry = featureEntries[j]; + for (FeatureEntry entry : featureEntries) { if (entry.isPlugin() && !entry.isRequires()) { IArtifactKey key = BundlesAction.createBundleArtifactKey(entry.getId(), entry.getVersion()); SimpleArtifactDescriptor artifactDescriptor = new SimpleArtifactDescriptor(key); @@ -160,13 +156,13 @@ public class UpdateSiteArtifactRepositoryFactory extends ArtifactRepositoryFacto artifactDescriptor = new SimpleArtifactDescriptor(key); pluginURL = updateSite.getPluginURI(entry); artifactDescriptor.setRepositoryProperty(PROP_ARTIFACT_REFERENCE, - pluginURL.toString() + PACK_EXT); + pluginURL.toString() + PACK_EXT); IProcessingStepDescriptor[] steps = new IProcessingStepDescriptor[] { - new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Pack200Unpacker", //$NON-NLS-1$ - null, true) }; + new ProcessingStepDescriptor("org.eclipse.equinox.p2.processing.Pack200Unpacker", //$NON-NLS-1$ + null, true) }; artifactDescriptor.setProcessingSteps(steps); artifactDescriptor.setProperty(IArtifactDescriptor.FORMAT, - IArtifactDescriptor.FORMAT_PACKED); + IArtifactDescriptor.FORMAT_PACKED); allSiteArtifacts.add(artifactDescriptor); } } @@ -175,10 +171,9 @@ public class UpdateSiteArtifactRepositoryFactory extends ArtifactRepositoryFacto } { BundleDescription[] bundles = updateSite.loadBundles(monitor); - for (int i = 0; i < bundles.length; i++) { - BundleDescription bundle = bundles[i]; + for (BundleDescription bundle : bundles) { IArtifactKey bundleKey = BundlesAction.createBundleArtifactKey(bundle.getSymbolicName(), - bundle.getVersion().toString()); + bundle.getVersion().toString()); SimpleArtifactDescriptor bundleArtifactDescriptor = new SimpleArtifactDescriptor(bundleKey); URI bundleURI = updateSite.getBundleURI(bundle.getSymbolicName(), bundle.getVersion().toString()); bundleArtifactDescriptor.setRepositoryProperty(PROP_ARTIFACT_REFERENCE, bundleURI.toString()); @@ -189,9 +184,9 @@ public class UpdateSiteArtifactRepositoryFactory extends ArtifactRepositoryFacto bundleArtifactDescriptor = new SimpleArtifactDescriptor(bundleKey); bundleURI = updateSite.getBundleURI(bundle.getSymbolicName(), bundle.getVersion().toString()); bundleArtifactDescriptor.setRepositoryProperty(PROP_ARTIFACT_REFERENCE, - bundleURI.toString() + PACK_EXT); + bundleURI.toString() + PACK_EXT); IProcessingStepDescriptor[] steps = new IProcessingStepDescriptor[] { new ProcessingStepDescriptor( - "org.eclipse.equinox.p2.processing.Pack200Unpacker", null, true) }; //$NON-NLS-1$ + "org.eclipse.equinox.p2.processing.Pack200Unpacker", null, true) }; //$NON-NLS-1$ bundleArtifactDescriptor.setProcessingSteps(steps); bundleArtifactDescriptor.setProperty(IArtifactDescriptor.FORMAT, IArtifactDescriptor.FORMAT_PACKED); allSiteArtifacts.add(bundleArtifactDescriptor); |