ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jaiki...@apache.org
Subject [1/2] ant-ivy git commit: refactor System.getProperty() and loops
Date Thu, 27 Jul 2017 15:42:21 GMT
Repository: ant-ivy
Updated Branches:
  refs/heads/master 366fb741f -> 1a283ab1b


http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/1a283ab1/src/java/org/apache/ivy/plugins/resolver/AbstractWorkspaceResolver.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/resolver/AbstractWorkspaceResolver.java b/src/java/org/apache/ivy/plugins/resolver/AbstractWorkspaceResolver.java
index 91991f4..466784a 100644
--- a/src/java/org/apache/ivy/plugins/resolver/AbstractWorkspaceResolver.java
+++ b/src/java/org/apache/ivy/plugins/resolver/AbstractWorkspaceResolver.java
@@ -196,10 +196,8 @@ public abstract class AbstractWorkspaceResolver extends AbstractResolver
{
         newMd.setResolvedPublicationDate(md.getResolvedPublicationDate());
         newMd.setStatus(md.getStatus());
 
-        List<Artifact> artifacts = createWorkspaceArtifacts(md);
-
         Configuration[] allConfs = md.getConfigurations();
-        for (Artifact af : artifacts) {
+        for (Artifact af : createWorkspaceArtifacts(md)) {
             if (allConfs.length == 0) {
                 newMd.addArtifact(ModuleDescriptor.DEFAULT_CONFIGURATION, af);
             } else {

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/1a283ab1/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java b/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
index e759764..9eb4eb5 100644
--- a/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
+++ b/src/java/org/apache/ivy/plugins/resolver/BasicResolver.java
@@ -917,12 +917,11 @@ public abstract class BasicResolver extends AbstractResolver {
     public OrganisationEntry[] listOrganisations() {
         Collection<String> names = findNames(Collections.<String, String> emptyMap(),
             IvyPatternHelper.ORGANISATION_KEY);
-        OrganisationEntry[] ret = new OrganisationEntry[names.size()];
-        int i = 0;
+        List<OrganisationEntry> ret = new ArrayList<>(names.size());
         for (String org : names) {
-            ret[i++] = new OrganisationEntry(this, org);
+            ret.add(new OrganisationEntry(this, org));
         }
-        return ret;
+        return ret.toArray(new OrganisationEntry[names.size()]);
     }
 
     @Override
@@ -930,12 +929,11 @@ public abstract class BasicResolver extends AbstractResolver {
         Map<String, String> tokenValues = new HashMap<>();
         tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, org.getOrganisation());
         Collection<String> names = findNames(tokenValues, IvyPatternHelper.MODULE_KEY);
-        ModuleEntry[] ret = new ModuleEntry[names.size()];
-        int i = 0;
+        List<ModuleEntry> ret = new ArrayList<>(names.size());
         for (String name : names) {
-            ret[i++] = new ModuleEntry(org, name);
+            ret.add(new ModuleEntry(org, name));
         }
-        return ret;
+        return ret.toArray(new ModuleEntry[names.size()]);
     }
 
     @Override
@@ -944,12 +942,11 @@ public abstract class BasicResolver extends AbstractResolver {
         tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, mod.getOrganisation());
         tokenValues.put(IvyPatternHelper.MODULE_KEY, mod.getModule());
         Collection<String> names = findNames(tokenValues, IvyPatternHelper.REVISION_KEY);
-        RevisionEntry[] ret = new RevisionEntry[names.size()];
-        int i = 0;
+        List<RevisionEntry> ret = new ArrayList<>(names.size());
         for (String name : names) {
-            ret[i++] = new RevisionEntry(mod, name);
+            ret.add(new RevisionEntry(mod, name));
         }
-        return ret;
+        return ret.toArray(new RevisionEntry[names.size()]);
     }
 
     protected abstract Collection<String> findNames(Map<String, String> tokenValues,
String token);

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/1a283ab1/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java b/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java
index 337afb9..2102b90 100644
--- a/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java
+++ b/src/java/org/apache/ivy/plugins/resolver/CacheResolver.java
@@ -172,8 +172,7 @@ public class CacheResolver extends FileSystemResolver {
         if (getIvyPatterns().isEmpty()) {
             setIvyPatterns(new ArrayList<String>());
             setArtifactPatterns(new ArrayList<String>());
-            RepositoryCacheManager[] caches = getSettings().getRepositoryCacheManagers();
-            for (RepositoryCacheManager cache : caches) {
+            for (RepositoryCacheManager cache : getSettings().getRepositoryCacheManagers())
{
                 if (cache instanceof DefaultRepositoryCacheManager) {
                     DefaultRepositoryCacheManager c = (DefaultRepositoryCacheManager) cache;
                     addIvyPattern(c.getBasedir().getAbsolutePath() + "/" + c.getIvyPattern());

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/1a283ab1/src/java/org/apache/ivy/plugins/resolver/IvyRepResolver.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/resolver/IvyRepResolver.java b/src/java/org/apache/ivy/plugins/resolver/IvyRepResolver.java
index 51a7d7f..bf527a0 100644
--- a/src/java/org/apache/ivy/plugins/resolver/IvyRepResolver.java
+++ b/src/java/org/apache/ivy/plugins/resolver/IvyRepResolver.java
@@ -254,12 +254,11 @@ public class IvyRepResolver extends URLResolver {
         Map<String, String> tokenValues = new HashMap<>();
         tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, org.getOrganisation());
         Collection<String> names = findIvyNames(tokenValues, IvyPatternHelper.MODULE_KEY);
-        ModuleEntry[] ret = new ModuleEntry[names.size()];
-        int i = 0;
+        List<ModuleEntry> ret = new ArrayList<>(names.size());
         for (String name : names) {
-            ret[i] = new ModuleEntry(org, name);
+            ret.add(new ModuleEntry(org, name));
         }
-        return ret;
+        return ret.toArray(new ModuleEntry[names.size()]);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/1a283ab1/src/java/org/apache/ivy/plugins/trigger/LogTrigger.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/plugins/trigger/LogTrigger.java b/src/java/org/apache/ivy/plugins/trigger/LogTrigger.java
index b66f1a3..96c8924 100644
--- a/src/java/org/apache/ivy/plugins/trigger/LogTrigger.java
+++ b/src/java/org/apache/ivy/plugins/trigger/LogTrigger.java
@@ -37,7 +37,7 @@ import org.apache.ivy.util.Message;
  * </p>
  */
 public class LogTrigger extends AbstractTrigger {
-    private static final String LINE_SEPARATOR = System.getProperty("line.separator");
+    private static final String LINE_SEPARATOR = System.lineSeparator();
 
     private String message = "";
 

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/1a283ab1/src/java/org/apache/ivy/util/ChecksumHelper.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/util/ChecksumHelper.java b/src/java/org/apache/ivy/util/ChecksumHelper.java
index 6bc1369..a859fc62 100644
--- a/src/java/org/apache/ivy/util/ChecksumHelper.java
+++ b/src/java/org/apache/ivy/util/ChecksumHelper.java
@@ -95,8 +95,7 @@ public final class ChecksumHelper {
                 // https://repo1.maven.org/maven2/org/apache/pdfbox/fontbox/0.8.0-incubator/fontbox-0.8.0-incubator.jar.md5
                 if (expected.endsWith(":")) {
                     StringBuilder result = new StringBuilder();
-                    char[] chars = csFileContent.substring(spaceIndex + 1).toCharArray();
-                    for (char ch : chars) {
+                    for (char ch : csFileContent.substring(spaceIndex + 1).toCharArray())
{
                         if (!Character.isWhitespace(ch)) {
                             result.append(ch);
                         }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/1a283ab1/src/java/org/apache/ivy/util/ConfigurationUtils.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/util/ConfigurationUtils.java b/src/java/org/apache/ivy/util/ConfigurationUtils.java
index 4bbb17c..ccb50ba 100644
--- a/src/java/org/apache/ivy/util/ConfigurationUtils.java
+++ b/src/java/org/apache/ivy/util/ConfigurationUtils.java
@@ -66,15 +66,13 @@ public final class ConfigurationUtils {
             if ("*".equals(conf)) {
                 result.addAll(Arrays.asList(md.getConfigurationsNames()));
             } else if ("*(public)".equals(conf)) {
-                Configuration[] all = md.getConfigurations();
-                for (Configuration cf : all) {
+                for (Configuration cf : md.getConfigurations()) {
                     if (cf.getVisibility().equals(Visibility.PUBLIC)) {
                         result.add(cf.getName());
                     }
                 }
             } else if ("*(private)".equals(conf)) {
-                Configuration[] all = md.getConfigurations();
-                for (Configuration cf : all) {
+                for (Configuration cf : md.getConfigurations()) {
                     if (cf.getVisibility().equals(Visibility.PRIVATE)) {
                         result.add(cf.getName());
                     }

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/1a283ab1/src/java/org/apache/ivy/util/Configurator.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/util/Configurator.java b/src/java/org/apache/ivy/util/Configurator.java
index deac6c8..c6b4082 100644
--- a/src/java/org/apache/ivy/util/Configurator.java
+++ b/src/java/org/apache/ivy/util/Configurator.java
@@ -311,8 +311,7 @@ public class Configurator {
         public ObjectDescriptor(Object object, String objName) {
             obj = object;
             this.objName = objName;
-            Method[] methods = object.getClass().getMethods();
-            for (Method m : methods) {
+            for (Method m : object.getClass().getMethods()) {
                 if (m.getName().startsWith("create") && m.getParameterTypes().length
== 0
                         && !Void.TYPE.equals(m.getReturnType())) {
                     String name = StringUtils
@@ -636,8 +635,7 @@ public class Configurator {
                 convertedValue = fileResolver.resolveFile(value, od.getObjectName() + "."
                         + attributeName);
             } else {
-                convertedValue = paramClass.getConstructor(new Class[] {String.class}).newInstance(
-                        value);
+                convertedValue = paramClass.getConstructor(String.class).newInstance(value);
             }
         } catch (Exception ex) {
             throw new IllegalArgumentException("impossible to convert "
@@ -658,7 +656,7 @@ public class Configurator {
         }
         ObjectDescriptor od = objectStack.peek();
         try {
-            od.getObject().getClass().getMethod("addText", new Class[] {String.class})
+            od.getObject().getClass().getMethod("addText", String.class)
                     .invoke(od.getObject(), text);
         } catch (Exception ex) {
             throw new IllegalArgumentException("impossible to add text on "

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/1a283ab1/src/java/org/apache/ivy/util/XMLHelper.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/ivy/util/XMLHelper.java b/src/java/org/apache/ivy/util/XMLHelper.java
index a62f34a..7112f45 100644
--- a/src/java/org/apache/ivy/util/XMLHelper.java
+++ b/src/java/org/apache/ivy/util/XMLHelper.java
@@ -197,8 +197,7 @@ public abstract class XMLHelper {
 
         StringBuilder result = new StringBuilder(text.length());
 
-        char[] chars = text.toCharArray();
-        for (char ch : chars) {
+        for (char ch : text.toCharArray()) {
             switch (ch) {
                 case '&':
                     result.append("&amp;");

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/1a283ab1/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java b/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java
index ad3de6a..bb582d0 100644
--- a/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java
+++ b/test/java/org/apache/ivy/plugins/parser/xml/XmlModuleUpdaterTest.java
@@ -54,7 +54,7 @@ public class XmlModuleUpdaterTest {
 
     @After
     public void tearDown() {
-        XmlModuleDescriptorUpdater.LINE_SEPARATOR = System.getProperty("line.separator");
+        XmlModuleDescriptorUpdater.LINE_SEPARATOR = System.lineSeparator();
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/1a283ab1/test/java/org/apache/ivy/plugins/resolver/FileSystemResolverTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/plugins/resolver/FileSystemResolverTest.java b/test/java/org/apache/ivy/plugins/resolver/FileSystemResolverTest.java
index d93b4c5..a0cbd71 100644
--- a/test/java/org/apache/ivy/plugins/resolver/FileSystemResolverTest.java
+++ b/test/java/org/apache/ivy/plugins/resolver/FileSystemResolverTest.java
@@ -63,7 +63,7 @@ import static org.junit.Assert.*;
 public class FileSystemResolverTest extends AbstractDependencyResolverTest {
     // CheckStyle:MagicNumberCheck OFF
 
-    private static final String FS = System.getProperty("file.separator");
+    private static final String FS = File.separator;
 
     private static final String REL_IVY_PATTERN = "test" + FS + "repositories" + FS + "1"
+ FS
             + "[organisation]" + FS + "[module]" + FS + "ivys" + FS + "ivy-[revision].xml";

http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/1a283ab1/test/java/org/apache/ivy/plugins/trigger/LogTriggerTest.java
----------------------------------------------------------------------
diff --git a/test/java/org/apache/ivy/plugins/trigger/LogTriggerTest.java b/test/java/org/apache/ivy/plugins/trigger/LogTriggerTest.java
index a10191b..4956a95 100644
--- a/test/java/org/apache/ivy/plugins/trigger/LogTriggerTest.java
+++ b/test/java/org/apache/ivy/plugins/trigger/LogTriggerTest.java
@@ -34,7 +34,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 public class LogTriggerTest {
-    private static final String LINE_SEPARATOR = System.getProperty("line.separator");
+    private static final String LINE_SEPARATOR = System.lineSeparator();
 
     private StartResolveEvent ev;
 


Mime
View raw message