Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hammer2019-09-25 19:54:25 +0000
committerAlexander Kurtakov2019-10-14 12:20:49 +0000
commit14f4c89602076e92050a11bf8d9e3ed9b9c08e14 (patch)
tree21f3ff893ba070d4675186f419481ef04e489754
parent680b7ea1ff9dd2dfc8248f3d9d1c92023bd746d4 (diff)
downloadrt.equinox.p2-14f4c89602076e92050a11bf8d9e3ed9b9c08e14.tar.gz
rt.equinox.p2-14f4c89602076e92050a11bf8d9e3ed9b9c08e14.tar.xz
rt.equinox.p2-14f4c89602076e92050a11bf8d9e3ed9b9c08e14.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: I17efcb7827adbf5a4f2424d3bb51a5cb0e56a66a Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/FileUtils.java41
-rw-r--r--bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/LogHelper.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.director/.settings/org.eclipse.jdt.core.prefs3
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Projector.java26
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Slicer.java7
-rw-r--r--bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/UserDefinedOptimizationFunction.java32
6 files changed, 58 insertions, 55 deletions
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/FileUtils.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/FileUtils.java
index 0e1d86cb2..f97d822e7 100644
--- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/FileUtils.java
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/FileUtils.java
@@ -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
*******************************************************************************/
@@ -145,8 +145,8 @@ public class FileUtils {
public static void deleteEmptyDirs(File dir) throws IOException {
File[] files = dir.listFiles();
if (files != null) {
- for (int i = 0; i < files.length; i += 1) {
- deleteEmptyDirs(files[i]);
+ for (File file : files) {
+ deleteEmptyDirs(file);
}
dir.getCanonicalFile().delete();
}
@@ -159,8 +159,9 @@ public class FileUtils {
if (file.isDirectory()) {
File[] files = file.listFiles();
if (files != null)
- for (int i = 0; i < files.length; i++)
- deleteAll(files[i]);
+ for (File f : files) {
+ deleteAll(f);
+ }
}
file.delete();
}
@@ -208,8 +209,9 @@ public class FileUtils {
if (sourceFile.isDirectory()) {
destinationFile.mkdirs();
File[] list = sourceFile.listFiles();
- for (int i = 0; i < list.length; i++)
- copy(source, destination, new File(root, list[i].getName()), false);
+ for (File file : list) {
+ copy(source, destination, new File(root, file.getName()), false);
+ }
} else {
destinationFile.getParentFile().mkdirs();
try (InputStream in = new BufferedInputStream(new FileInputStream(sourceFile)); OutputStream out = new BufferedOutputStream(new FileOutputStream(destinationFile));) {
@@ -221,7 +223,7 @@ public class FileUtils {
/**
* Creates a zip archive at the given destination that contains all of the given inclusions
* except for the given exclusions. Inclusions and exclusions can be phrased as files or folders.
- * Including a folder implies that all files and folders under the folder
+ * Including a folder implies that all files and folders under the folder
* should be considered for inclusion. Excluding a folder implies that all files and folders
* under that folder will be excluded. Inclusions with paths deeper than an exclusion folder
* are filtered out and do not end up in the resultant archive.
@@ -239,9 +241,9 @@ public class FileUtils {
try (FileOutputStream fileOutput = new FileOutputStream(destinationArchive); ZipOutputStream output = new ZipOutputStream(fileOutput)) {
HashSet<File> exclusionSet = exclusions == null ? new HashSet<>() : new HashSet<>(Arrays.asList(exclusions));
HashSet<IPath> directoryEntries = new HashSet<>();
- for (int i = 0; i < inclusions.length; i++) {
+ for (File inclusion : inclusions) {
pathComputer.reset();
- zip(output, inclusions[i], exclusionSet, pathComputer, directoryEntries);
+ zip(output, inclusion, exclusionSet, pathComputer, directoryEntries);
}
}
}
@@ -323,8 +325,9 @@ public class FileUtils {
return a.segmentCount() - b.segmentCount();
});
- for (int i = 0; i < files.length; i++)
- zip(output, files[i], exclusions, pathComputer, directoryEntries);
+ for (File file : files) {
+ zip(output, file, exclusions, pathComputer, directoryEntries);
+ }
}
/*
@@ -371,14 +374,14 @@ public class FileUtils {
* Path computers are used to transform a given File path into a path suitable for use
* as the to identify that file in an archive file or copy.
*/
- public static interface IPathComputer {
+ public interface IPathComputer {
/**
* Returns the path representing the given file. Often this trims or otherwise
* transforms the segments of the source file path.
* @param source the file path to be transformed
* @return the transformed path
*/
- public IPath computePath(File source);
+ IPath computePath(File source);
/**
* Resets this path computer. Path computers can accumulate state or other information
@@ -386,7 +389,7 @@ public class FileUtils {
* state and start afresh. The exact semantics of resetting depends on the nature of the
* computer itself.
*/
- public void reset();
+ void reset();
}
/**
@@ -415,13 +418,13 @@ public class FileUtils {
/**
* Creates a path computer that is a cross between the root and parent computers.
* When this computer is reset, the first path seen is considered a new root. That path
- * is trimmed by the given number of segments and then used as in the same way as the
+ * is trimmed by the given number of segments and then used as in the same way as the
* root path computer. Every time this computer is reset, a new root is computed.
* <p>
* This is useful when handling several sets of disjoint files but for each set you want
- * to have a common root. Rather than having to compute the roots ahead of time and
+ * to have a common root. Rather than having to compute the roots ahead of time and
* then manage their relationships, you can simply reset the computer between groups.
- * </p><p>
+ * </p><p>
* For example, say you have the a list of folders { /a/b/c/eclipse/plugins/, /x/y/eclipse/features/}
* and want to end up with a zip containing plugins and features folders. Using a dynamic
* path computer and keeping 1 segment allows this to be done simply by resetting the computer
@@ -429,7 +432,7 @@ public class FileUtils {
* </p>
* @param segmentsToKeep the number of segments of encountered paths to keep
* relative to the dynamically computed roots.
- * @return a path computer that trims but keeps the given number of segments relative
+ * @return a path computer that trims but keeps the given number of segments relative
* to the dynamically computed roots.
*/
public static IPathComputer createDynamicPathComputer(final int segmentsToKeep) {
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/LogHelper.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/LogHelper.java
index 33c9697a0..eb23efb7a 100644
--- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/LogHelper.java
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/helpers/LogHelper.java
@@ -55,8 +55,8 @@ public class LogHelper {
if (status.isMultiStatus()) {
IStatus[] children = status.getChildren();
- for (int i = 0; i < children.length; i++) {
- childlist.add(getLog(children[i]));
+ for (IStatus child : children) {
+ childlist.add(getLog(child));
}
}
diff --git a/bundles/org.eclipse.equinox.p2.director/.settings/org.eclipse.jdt.core.prefs b/bundles/org.eclipse.equinox.p2.director/.settings/org.eclipse.jdt.core.prefs
index a01c791c7..3bb5d9f8c 100644
--- a/bundles/org.eclipse.equinox.p2.director/.settings/org.eclipse.jdt.core.prefs
+++ b/bundles/org.eclipse.equinox.p2.director/.settings/org.eclipse.jdt.core.prefs
@@ -69,7 +69,7 @@ org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
-org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=error
org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
@@ -108,6 +108,7 @@ org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=warning
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=warning
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Projector.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Projector.java
index b52d41216..978debf7f 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Projector.java
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Projector.java
@@ -526,29 +526,28 @@ public class Projector {
// noop(IU)-> ~ABS
// IU -> (noop(IU) or ABS)
// Therefore we only need one optional requirement statement per IU
- for (int i = 0; i < reqs.length; i++) {
+ for (IRequirement[] requirement : reqs) {
//The requirement is unchanged
- if (reqs[i][0] == reqs[i][1]) {
- if (reqs[i][0].getMax() == 0) {
- expandNegatedRequirement(reqs[i][0], iu, optionalAbstractRequirements, isRootIu);
+ if (requirement[0] == requirement[1]) {
+ if (requirement[0].getMax() == 0) {
+ expandNegatedRequirement(requirement[0], iu, optionalAbstractRequirements, isRootIu);
return;
}
- if (!isApplicable(reqs[i][0]))
+ if (!isApplicable(requirement[0])) {
continue;
-
- List<IInstallableUnitPatch> patchesAppliedElseWhere = unchangedRequirements.get(reqs[i][0]);
+ }
+ List<IInstallableUnitPatch> patchesAppliedElseWhere = unchangedRequirements.get(requirement[0]);
if (patchesAppliedElseWhere == null) {
patchesAppliedElseWhere = new ArrayList<>();
- unchangedRequirements.put(reqs[i][0], patchesAppliedElseWhere);
+ unchangedRequirements.put(requirement[0], patchesAppliedElseWhere);
}
patchesAppliedElseWhere.add(patch);
continue;
}
-
//Generate dependency when the patch is applied
//P1 -> (A -> D) equiv. (P1 & A) -> D
- if (isApplicable(reqs[i][1])) {
- IRequirement req = reqs[i][1];
+ if (isApplicable(requirement[1])) {
+ IRequirement req = requirement[1];
List<IInstallableUnit> matches = getApplicableMatches(req);
determinePotentialHostsForFragment(iu);
if (req.getMin() > 0) {
@@ -606,9 +605,8 @@ public class Projector {
}
//Generate dependency when the patch is not applied
//-P1 -> (A -> B) ( equiv. A -> (P1 or B) )
- if (isApplicable(reqs[i][0])) {
- IRequirement req = reqs[i][0];
-
+ if (isApplicable(requirement[0])) {
+ IRequirement req = requirement[0];
// Fix: if multiple patches apply to the same IU-req, we need to make sure we list each
// patch as an optional match
Pending pending = nonPatchedRequirements.get(req);
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Slicer.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Slicer.java
index 8453e9121..8de45dcbb 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Slicer.java
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/Slicer.java
@@ -104,9 +104,10 @@ public class Slicer {
//This is a shortcut to simplify the error reporting when the filter of the ius we are being asked to install does not pass
private void validateInput(IInstallableUnit[] ius) {
- for (int i = 0; i < ius.length; i++) {
- if (!isApplicable(ius[i]))
- throw new IllegalStateException(NLS.bind(Messages.Explanation_missingRootFilter, ius[i]));
+ for (IInstallableUnit iu : ius) {
+ if (!isApplicable(iu)) {
+ throw new IllegalStateException(NLS.bind(Messages.Explanation_missingRootFilter, iu));
+ }
}
}
diff --git a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/UserDefinedOptimizationFunction.java b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/UserDefinedOptimizationFunction.java
index 83f506e54..4f699cf25 100644
--- a/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/UserDefinedOptimizationFunction.java
+++ b/bundles/org.eclipse.equinox.p2.director/src/org/eclipse/equinox/internal/p2/director/UserDefinedOptimizationFunction.java
@@ -9,7 +9,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*
- * Contributors:
+ * Contributors:
* Daniel Le Berre - initial API and implementation
* Red Hat, Inc. - support for remediation page
******************************************************************************/
@@ -41,32 +41,32 @@ public class UserDefinedOptimizationFunction extends OptimizationFunction {
List<WeightedObject<?>> weightedObjects = new ArrayList<>();
List<Object> objects = new ArrayList<>();
BigInteger weight = BigInteger.valueOf(slice.size() + 1);
- String[] criteria = new String[] {"+new", "-notuptodate", "-changed", "-removed"}; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
- BigInteger currentWeight = weight.pow(criteria.length - 1);
+ String[] criterias = new String[] {"+new", "-notuptodate", "-changed", "-removed"}; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
+ BigInteger currentWeight = weight.pow(criterias.length - 1);
boolean maximizes;
Object thing;
- for (int i = 0; i < criteria.length; i++) {
- if (criteria[i].endsWith("new")) { //$NON-NLS-1$
+ for (String criteria : criterias) {
+ if (criteria.endsWith("new")) { //$NON-NLS-1$
weightedObjects.clear();
- newRoots(weightedObjects, criteria[i].startsWith("+") ? currentWeight.negate() : currentWeight, metaIu); //$NON-NLS-1$
+ newRoots(weightedObjects, criteria.startsWith("+") ? currentWeight.negate() : currentWeight, metaIu); //$NON-NLS-1$
currentWeight = currentWeight.divide(weight);
- } else if (criteria[i].endsWith("removed")) { //$NON-NLS-1$
+ } else if (criteria.endsWith("removed")) { //$NON-NLS-1$
weightedObjects.clear();
- removedRoots(weightedObjects, criteria[i].startsWith("+") ? currentWeight.negate() : currentWeight, metaIu); //$NON-NLS-1$
+ removedRoots(weightedObjects, criteria.startsWith("+") ? currentWeight.negate() : currentWeight, metaIu); //$NON-NLS-1$
currentWeight = currentWeight.divide(weight);
- } else if (criteria[i].endsWith("notuptodate")) { //$NON-NLS-1$
+ } else if (criteria.endsWith("notuptodate")) { //$NON-NLS-1$
weightedObjects.clear();
- notuptodate(weightedObjects, criteria[i].startsWith("+") ? currentWeight.negate() : currentWeight, metaIu); //$NON-NLS-1$
+ notuptodate(weightedObjects, criteria.startsWith("+") ? currentWeight.negate() : currentWeight, metaIu); //$NON-NLS-1$
currentWeight = currentWeight.divide(weight);
- } else if (criteria[i].endsWith("changed")) { //$NON-NLS-1$
+ } else if (criteria.endsWith("changed")) { //$NON-NLS-1$
weightedObjects.clear();
- changedRoots(weightedObjects, criteria[i].startsWith("+") ? currentWeight.negate() : currentWeight, metaIu); //$NON-NLS-1$
+ changedRoots(weightedObjects, criteria.startsWith("+") ? currentWeight.negate() : currentWeight, metaIu); //$NON-NLS-1$
currentWeight = currentWeight.divide(weight);
}
objects.clear();
- maximizes = criteria[i].startsWith("+"); //$NON-NLS-1$
- for (Iterator<WeightedObject<?>> it = weightedObjects.iterator(); it.hasNext();) {
- thing = it.next().thing;
+ maximizes = criteria.startsWith("+"); //$NON-NLS-1$
+ for (WeightedObject<?> weightedObject : weightedObjects) {
+ thing = weightedObject.thing;
if (maximizes) {
thing = dependencyHelper.not(thing);
}
@@ -159,7 +159,7 @@ public class UserDefinedOptimizationFunction extends OptimizationFunction {
Projector.AbstractVariable abs = new Projector.AbstractVariable();
Object notlatest = dependencyHelper.not(toSort.get(0));
try {
- // notuptodate <=> not iuvn and (iuv1 or iuv2 or ... iuvn-1)
+ // notuptodate <=> not iuvn and (iuv1 or iuv2 or ... iuvn-1)
dependencyHelper.implication(new Object[] {abs}).implies(notlatest).named(FakeExplanation.getInstance());
Object[] clause = new Object[toSort.size()];
toSort.toArray(clause);

Back to the top