Fixing stylecheck problems with storm-maven-plugins

Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/84084ab0
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/84084ab0
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/84084ab0

Branch: refs/heads/master
Commit: 84084ab0ac16390f24e7f24a1d9d1693062cb023
Parents: 4fe4f04
Author: Kishor Patil <[email protected]>
Authored: Sun Apr 22 23:03:52 2018 -0400
Committer: Kishor Patil <[email protected]>
Committed: Mon Apr 23 00:22:37 2018 -0400

----------------------------------------------------------------------
 storm-buildtools/storm-maven-plugins/pom.xml    |   2 +-
 .../storm/maven/plugin/util/CommandExec.java    | 118 +++--
 .../plugin/versioninfo/VersionInfoMojo.java     | 457 +++++++++----------
 3 files changed, 282 insertions(+), 295 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/84084ab0/storm-buildtools/storm-maven-plugins/pom.xml
----------------------------------------------------------------------
diff --git a/storm-buildtools/storm-maven-plugins/pom.xml 
b/storm-buildtools/storm-maven-plugins/pom.xml
index 3f0a27d..b850f21 100644
--- a/storm-buildtools/storm-maven-plugins/pom.xml
+++ b/storm-buildtools/storm-maven-plugins/pom.xml
@@ -81,7 +81,7 @@
         <artifactId>maven-checkstyle-plugin</artifactId>
         <!--Note - the version would be inherited-->
         <configuration>
-          <maxAllowedViolations>269</maxAllowedViolations>
+          <maxAllowedViolations>11</maxAllowedViolations>
         </configuration>
       </plugin>
     </plugins>

http://git-wip-us.apache.org/repos/asf/storm/blob/84084ab0/storm-buildtools/storm-maven-plugins/src/main/java/org/apache/storm/maven/plugin/util/CommandExec.java
----------------------------------------------------------------------
diff --git 
a/storm-buildtools/storm-maven-plugins/src/main/java/org/apache/storm/maven/plugin/util/CommandExec.java
 
b/storm-buildtools/storm-maven-plugins/src/main/java/org/apache/storm/maven/plugin/util/CommandExec.java
index c289f51..8bad082 100644
--- 
a/storm-buildtools/storm-maven-plugins/src/main/java/org/apache/storm/maven/plugin/util/CommandExec.java
+++ 
b/storm-buildtools/storm-maven-plugins/src/main/java/org/apache/storm/maven/plugin/util/CommandExec.java
@@ -1,20 +1,15 @@
 /**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The 
ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance with 
the License.  You may obtain a copy of the License at
  *
  * http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions
+ * and limitations under the License.
  */
+
 package org.apache.storm.maven.plugin.util;
 
 import java.io.BufferedReader;
@@ -23,67 +18,66 @@ import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.ArrayList;
 import java.util.List;
-
 import org.apache.maven.plugin.Mojo;
 
 public class CommandExec {
-  private Mojo mojo;
+    private Mojo mojo;
 
-  public CommandExec(Mojo mojo) {
-    this.mojo = mojo;
-  }
+    public CommandExec(Mojo mojo) {
+        this.mojo = mojo;
+    }
 
-  public int run(List<String> command, List<String> output) {
-    int retCode = 1;
-    ProcessBuilder pb = new ProcessBuilder(command);
-    try {
-      Process p = pb.start();
-      OutputBufferThread stdOut = new OutputBufferThread(p.getInputStream());
-      OutputBufferThread stdErr = new OutputBufferThread(p.getErrorStream());
-      stdOut.start();
-      stdErr.start();
-      retCode = p.waitFor();
-      if (retCode != 0) {
-        mojo.getLog().warn(command + " failed with error code " + retCode);
-        for (String s : stdErr.getOutput()) {
-          mojo.getLog().debug(s);
+    public int run(List<String> command, List<String> output) {
+        int retCode = 1;
+        ProcessBuilder pb = new ProcessBuilder(command);
+        try {
+            Process p = pb.start();
+            OutputBufferThread stdOut = new 
OutputBufferThread(p.getInputStream());
+            OutputBufferThread stdErr = new 
OutputBufferThread(p.getErrorStream());
+            stdOut.start();
+            stdErr.start();
+            retCode = p.waitFor();
+            if (retCode != 0) {
+                mojo.getLog().warn(command + " failed with error code " + 
retCode);
+                for (String s : stdErr.getOutput()) {
+                    mojo.getLog().debug(s);
+                }
+            }
+            stdOut.join();
+            stdErr.join();
+            output.addAll(stdOut.getOutput());
+        } catch (Exception ex) {
+            mojo.getLog().warn(command + " failed: " + ex.toString());
         }
-      }
-      stdOut.join();
-      stdErr.join();
-      output.addAll(stdOut.getOutput());
-    } catch (Exception ex) {
-      mojo.getLog().warn(command + " failed: " + ex.toString());
+        return retCode;
     }
-    return retCode;
-  }
 
-  private static class OutputBufferThread extends Thread {
-    private List<String> output;
-    private BufferedReader reader;
+    private static class OutputBufferThread extends Thread {
+        private List<String> output;
+        private BufferedReader reader;
 
-    public OutputBufferThread(InputStream is) {
-      this.setDaemon(true);
-      output = new ArrayList<String>();
-      reader = new BufferedReader(new InputStreamReader(is));
-    }
+        public OutputBufferThread(InputStream is) {
+            this.setDaemon(true);
+            output = new ArrayList<String>();
+            reader = new BufferedReader(new InputStreamReader(is));
+        }
 
-    @Override
-    public void run() {
-      try {
-        String line = reader.readLine();
-        while (line != null) {
-          output.add(line);
-          line = reader.readLine();
+        @Override
+        public void run() {
+            try {
+                String line = reader.readLine();
+                while (line != null) {
+                    output.add(line);
+                    line = reader.readLine();
+                }
+            } catch (IOException ex) {
+                throw new RuntimeException("make failed with error code "
+                                           + ex.toString());
+            }
         }
-      } catch (IOException ex) {
-        throw new RuntimeException("make failed with error code "
-            + ex.toString());
-      }
-    }
 
-    public List<String> getOutput() {
-      return output;
+        public List<String> getOutput() {
+            return output;
+        }
     }
-  }
 }

http://git-wip-us.apache.org/repos/asf/storm/blob/84084ab0/storm-buildtools/storm-maven-plugins/src/main/java/org/apache/storm/maven/plugin/versioninfo/VersionInfoMojo.java
----------------------------------------------------------------------
diff --git 
a/storm-buildtools/storm-maven-plugins/src/main/java/org/apache/storm/maven/plugin/versioninfo/VersionInfoMojo.java
 
b/storm-buildtools/storm-maven-plugins/src/main/java/org/apache/storm/maven/plugin/versioninfo/VersionInfoMojo.java
index 31354e3..9eb0298 100644
--- 
a/storm-buildtools/storm-maven-plugins/src/main/java/org/apache/storm/maven/plugin/versioninfo/VersionInfoMojo.java
+++ 
b/storm-buildtools/storm-maven-plugins/src/main/java/org/apache/storm/maven/plugin/versioninfo/VersionInfoMojo.java
@@ -1,20 +1,15 @@
 /**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The 
ASF licenses this file to you under the Apache License, Version
+ * 2.0 (the "License"); you may not use this file except in compliance with 
the License.  You may obtain a copy of the License at
  *
  * http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions
+ * and limitations under the License.
  */
+
 package org.apache.storm.maven.plugin.versioninfo;
 
 import java.io.File;
@@ -31,7 +26,6 @@ import java.util.Comparator;
 import java.util.Date;
 import java.util.List;
 import java.util.TimeZone;
-
 import org.apache.maven.model.FileSet;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -44,261 +38,260 @@ import org.codehaus.plexus.util.FileUtils;
 @Mojo(name = "version-info")
 public class VersionInfoMojo extends AbstractMojo {
 
-  @Parameter(defaultValue = "${project}")
-  private MavenProject project;
+    @Parameter(defaultValue = "${project}")
+    private MavenProject project;
 
-  @Parameter(required = true)
-  private FileSet source;
+    @Parameter(required = true)
+    private FileSet source;
 
-  @Parameter(defaultValue = "version-info.build.time")
-  private String buildTimeProperty;
+    @Parameter(defaultValue = "version-info.build.time")
+    private String buildTimeProperty;
 
-  @Parameter(defaultValue = "version-info.source.md5")
-  private String md5Property;
+    @Parameter(defaultValue = "version-info.source.md5")
+    private String md5Property;
 
-  @Parameter(defaultValue = "version-info.scm.uri")
-  private String scmUriProperty;
+    @Parameter(defaultValue = "version-info.scm.uri")
+    private String scmUriProperty;
 
-  @Parameter(defaultValue = "version-info.scm.branch")
-  private String scmBranchProperty;
+    @Parameter(defaultValue = "version-info.scm.branch")
+    private String scmBranchProperty;
 
-  @Parameter(defaultValue = "version-info.scm.commit")
-  private String scmCommitProperty;
+    @Parameter(defaultValue = "version-info.scm.commit")
+    private String scmCommitProperty;
 
-  @Parameter(defaultValue = "git")
-  private String gitCommand;
+    @Parameter(defaultValue = "git")
+    private String gitCommand;
 
-  @Parameter(defaultValue = "svn")
-  private String svnCommand;
+    @Parameter(defaultValue = "svn")
+    private String svnCommand;
+    private List<String> scmOut;
 
-  private enum SCM {
-    NONE, SVN, GIT
-  }
+    @SuppressWarnings("rawtypes")
+    private static String getCommaSeparatedList(List list) {
+        StringBuilder buffer = new StringBuilder();
+        String separator = "";
+        for (Object e : list) {
+            buffer.append(separator).append(e);
+            separator = ",";
+        }
+        return buffer.toString();
+    }
 
-  @Override
-  public void execute() throws MojoExecutionException {
-    try {
-      SCM scm = determineSCM();
-      project.getProperties().setProperty(buildTimeProperty, getBuildTime());
-      project.getProperties().setProperty(scmUriProperty, getSCMUri(scm));
-      project.getProperties().setProperty(scmBranchProperty, 
getSCMBranch(scm));
-      project.getProperties().setProperty(scmCommitProperty, 
getSCMCommit(scm));
-      project.getProperties().setProperty(md5Property, computeMD5());
-    } catch (Throwable ex) {
-      throw new MojoExecutionException(ex.toString(), ex);
+    @SuppressWarnings("unchecked")
+    public static List<File> convertFileSetToFiles(FileSet source)
+        throws IOException {
+        String includes = getCommaSeparatedList(source.getIncludes());
+        String excludes = getCommaSeparatedList(source.getExcludes());
+        return FileUtils.getFiles(new File(source.getDirectory()), includes,
+                                  excludes);
     }
-  }
 
-  private String getBuildTime() {
-    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
-    dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
-    return dateFormat.format(new Date());
-  }
+    @Override
+    public void execute() throws MojoExecutionException {
+        try {
+            SCM scm = determineSCM();
+            project.getProperties().setProperty(buildTimeProperty, 
getBuildTime());
+            project.getProperties().setProperty(scmUriProperty, 
getSCMUri(scm));
+            project.getProperties().setProperty(scmBranchProperty, 
getSCMBranch(scm));
+            project.getProperties().setProperty(scmCommitProperty, 
getSCMCommit(scm));
+            project.getProperties().setProperty(md5Property, computeMD5());
+        } catch (Throwable ex) {
+            throw new MojoExecutionException(ex.toString(), ex);
+        }
+    }
 
-  private List<String> scmOut;
+    private String getBuildTime() {
+        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'");
+        dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+        return dateFormat.format(new Date());
+    }
 
-  /**
-   * Determines which SCM is in use (Subversion, git, or none) and captures
-   * output of the SCM command for later parsing.
-   * 
-   * @return SCM in use for this build
-   * @throws Exception if any error occurs attempting to determine SCM
-   */
-  private SCM determineSCM() throws Exception {
-    CommandExec exec = new CommandExec(this);
-    SCM scm = SCM.NONE;
-    scmOut = new ArrayList<String>();
-    int ret = exec.run(Arrays.asList(svnCommand, "info"), scmOut);
-    if (ret == 0) {
-      scm = SCM.SVN;
-    } else {
-      ret = exec.run(Arrays.asList(gitCommand, "branch"), scmOut);
-      if (ret == 0) {
-        ret = exec.run(Arrays.asList(gitCommand, "remote", "-v"), scmOut);
-        if (ret != 0) {
-          scm = SCM.NONE;
-          scmOut = null;
+    /**
+     * Determines which SCM is in use (Subversion, git, or none) and captures
+     * output of the SCM command for later parsing.
+     *
+     * @return SCM in use for this build
+     * @throws Exception if any error occurs attempting to determine SCM
+     */
+    private SCM determineSCM() throws Exception {
+        CommandExec exec = new CommandExec(this);
+        SCM scm = SCM.NONE;
+        scmOut = new ArrayList<String>();
+        int ret = exec.run(Arrays.asList(svnCommand, "info"), scmOut);
+        if (ret == 0) {
+            scm = SCM.SVN;
         } else {
-          ret = exec.run(Arrays.asList(gitCommand, "log", "-n", "1"), scmOut);
-          if (ret != 0) {
-            scm = SCM.NONE;
-            scmOut = null;
-          } else {
-            scm = SCM.GIT;
-          }
+            ret = exec.run(Arrays.asList(gitCommand, "branch"), scmOut);
+            if (ret == 0) {
+                ret = exec.run(Arrays.asList(gitCommand, "remote", "-v"), 
scmOut);
+                if (ret != 0) {
+                    scm = SCM.NONE;
+                    scmOut = null;
+                } else {
+                    ret = exec.run(Arrays.asList(gitCommand, "log", "-n", 
"1"), scmOut);
+                    if (ret != 0) {
+                        scm = SCM.NONE;
+                        scmOut = null;
+                    } else {
+                        scm = SCM.GIT;
+                    }
+                }
+            }
         }
-      }
-    }
-    if (scmOut != null) {
-      getLog().debug(scmOut.toString());
+        if (scmOut != null) {
+            getLog().debug(scmOut.toString());
+        }
+        getLog().info("SCM: " + scm);
+        return scm;
     }
-    getLog().info("SCM: " + scm);
-    return scm;
-  }
 
-  private String[] getSvnUriInfo(String str) {
-    String[] res = new String[] { "Unknown", "Unknown" };
-    try {
-      String path = str;
-      int index = path.indexOf("trunk");
-      if (index > -1) {
-        res[0] = path.substring(0, index - 1);
-        res[1] = "trunk";
-      } else {
-        index = path.indexOf("branches");
-        if (index > -1) {
-          res[0] = path.substring(0, index - 1);
-          int branchIndex = index + "branches".length() + 1;
-          index = path.indexOf("/", branchIndex);
-          if (index > -1) {
-            res[1] = path.substring(branchIndex, index);
-          } else {
-            res[1] = path.substring(branchIndex);
-          }
+    private String[] getSvnUriInfo(String str) {
+        String[] res = new String[]{ "Unknown", "Unknown" };
+        try {
+            String path = str;
+            int index = path.indexOf("trunk");
+            if (index > -1) {
+                res[0] = path.substring(0, index - 1);
+                res[1] = "trunk";
+            } else {
+                index = path.indexOf("branches");
+                if (index > -1) {
+                    res[0] = path.substring(0, index - 1);
+                    int branchIndex = index + "branches".length() + 1;
+                    index = path.indexOf("/", branchIndex);
+                    if (index > -1) {
+                        res[1] = path.substring(branchIndex, index);
+                    } else {
+                        res[1] = path.substring(branchIndex);
+                    }
+                }
+            }
+        } catch (Exception ex) {
+            getLog().warn("Could not determine URI & branch from SVN URI: " + 
str);
         }
-      }
-    } catch (Exception ex) {
-      getLog().warn("Could not determine URI & branch from SVN URI: " + str);
+        return res;
     }
-    return res;
-  }
 
-  private String getSCMUri(SCM scm) {
-    String uri = "Unknown";
-    switch (scm) {
-    case SVN:
-      for (String s : scmOut) {
-        if (s.startsWith("URL:")) {
-          uri = s.substring(4).trim();
-          uri = getSvnUriInfo(uri)[0];
-          break;
+    private String getSCMUri(SCM scm) {
+        String uri = "Unknown";
+        switch (scm) {
+            case SVN:
+                for (String s : scmOut) {
+                    if (s.startsWith("URL:")) {
+                        uri = s.substring(4).trim();
+                        uri = getSvnUriInfo(uri)[0];
+                        break;
+                    }
+                }
+                break;
+            case GIT:
+                for (String s : scmOut) {
+                    if (s.startsWith("origin") && s.endsWith("(fetch)")) {
+                        uri = s.substring("origin".length());
+                        uri = uri.substring(0, uri.length() - 
"(fetch)".length());
+                        break;
+                    }
+                }
+                break;
         }
-      }
-      break;
-    case GIT:
-      for (String s : scmOut) {
-        if (s.startsWith("origin") && s.endsWith("(fetch)")) {
-          uri = s.substring("origin".length());
-          uri = uri.substring(0, uri.length() - "(fetch)".length());
-          break;
-        }
-      }
-      break;
+        return uri.trim();
     }
-    return uri.trim();
-  }
 
-  private String getSCMCommit(SCM scm) {
-    String commit = "Unknown";
-    switch (scm) {
-    case SVN:
-      for (String s : scmOut) {
-        if (s.startsWith("Revision:")) {
-          commit = s.substring("Revision:".length());
-          break;
-        }
-      }
-      break;
-    case GIT:
-      for (String s : scmOut) {
-        if (s.startsWith("commit")) {
-          commit = s.substring("commit".length());
-          break;
+    private String getSCMCommit(SCM scm) {
+        String commit = "Unknown";
+        switch (scm) {
+            case SVN:
+                for (String s : scmOut) {
+                    if (s.startsWith("Revision:")) {
+                        commit = s.substring("Revision:".length());
+                        break;
+                    }
+                }
+                break;
+            case GIT:
+                for (String s : scmOut) {
+                    if (s.startsWith("commit")) {
+                        commit = s.substring("commit".length());
+                        break;
+                    }
+                }
+                break;
         }
-      }
-      break;
+        return commit.trim();
     }
-    return commit.trim();
-  }
 
-  private String getSCMBranch(SCM scm) {
-    String branch = "Unknown";
-    switch (scm) {
-    case SVN:
-      for (String s : scmOut) {
-        if (s.startsWith("URL:")) {
-          branch = s.substring(4).trim();
-          branch = getSvnUriInfo(branch)[1];
-          break;
+    private String getSCMBranch(SCM scm) {
+        String branch = "Unknown";
+        switch (scm) {
+            case SVN:
+                for (String s : scmOut) {
+                    if (s.startsWith("URL:")) {
+                        branch = s.substring(4).trim();
+                        branch = getSvnUriInfo(branch)[1];
+                        break;
+                    }
+                }
+                break;
+            case GIT:
+                for (String s : scmOut) {
+                    if (s.startsWith("*")) {
+                        branch = s.substring("*".length());
+                        break;
+                    }
+                }
+                break;
         }
-      }
-      break;
-    case GIT:
-      for (String s : scmOut) {
-        if (s.startsWith("*")) {
-          branch = s.substring("*".length());
-          break;
-        }
-      }
-      break;
+        return branch.trim();
     }
-    return branch.trim();
-  }
-
-  private byte[] readFile(File file) throws IOException {
-    RandomAccessFile raf = new RandomAccessFile(file, "r");
-    byte[] buffer = new byte[(int) raf.length()];
-    raf.readFully(buffer);
-    raf.close();
-    return buffer;
-  }
 
-  private byte[] computeMD5(List<File> files) throws IOException,
-      NoSuchAlgorithmException {
-    MessageDigest md5 = MessageDigest.getInstance("MD5");
-    for (File file : files) {
-      getLog().debug("Computing MD5 for: " + file);
-      md5.update(readFile(file));
+    private byte[] readFile(File file) throws IOException {
+        RandomAccessFile raf = new RandomAccessFile(file, "r");
+        byte[] buffer = new byte[(int) raf.length()];
+        raf.readFully(buffer);
+        raf.close();
+        return buffer;
     }
-    return md5.digest();
-  }
 
-  private String byteArrayToString(byte[] array) {
-    StringBuilder sb = new StringBuilder();
-    for (byte b : array) {
-      sb.append(Integer.toHexString(0xff & b));
+    private byte[] computeMD5(List<File> files) throws IOException,
+        NoSuchAlgorithmException {
+        MessageDigest md5 = MessageDigest.getInstance("MD5");
+        for (File file : files) {
+            getLog().debug("Computing MD5 for: " + file);
+            md5.update(readFile(file));
+        }
+        return md5.digest();
     }
-    return sb.toString();
-  }
 
-  private String computeMD5() throws Exception {
-    List<File> files = convertFileSetToFiles(source);
-    // File order of MD5 calculation is significant. Sorting is done on
-    // unix-format names, case-folded, in order to get a platform-independent
-    // sort and calculate the same MD5 on all platforms.
-    Collections.sort(files, new Comparator<File>() {
-      @Override
-      public int compare(File lhs, File rhs) {
-        return normalizePath(lhs).compareTo(normalizePath(rhs));
-      }
+    private String byteArrayToString(byte[] array) {
+        StringBuilder sb = new StringBuilder();
+        for (byte b : array) {
+            sb.append(Integer.toHexString(0xff & b));
+        }
+        return sb.toString();
+    }
 
-      private String normalizePath(File file) {
-        return file.getPath().toUpperCase().replaceAll("\\\\", "/");
-      }
-    });
-    byte[] md5 = computeMD5(files);
-    String md5str = byteArrayToString(md5);
-    getLog().info("Computed MD5: " + md5str);
-    return md5str;
-  }
+    private String computeMD5() throws Exception {
+        List<File> files = convertFileSetToFiles(source);
+        // File order of MD5 calculation is significant. Sorting is done on
+        // unix-format names, case-folded, in order to get a 
platform-independent
+        // sort and calculate the same MD5 on all platforms.
+        Collections.sort(files, new Comparator<File>() {
+            @Override
+            public int compare(File lhs, File rhs) {
+                return normalizePath(lhs).compareTo(normalizePath(rhs));
+            }
 
-  @SuppressWarnings("rawtypes")
-  private static String getCommaSeparatedList(List list) {
-    StringBuilder buffer = new StringBuilder();
-    String separator = "";
-    for (Object e : list) {
-      buffer.append(separator).append(e);
-      separator = ",";
+            private String normalizePath(File file) {
+                return file.getPath().toUpperCase().replaceAll("\\\\", "/");
+            }
+        });
+        byte[] md5 = computeMD5(files);
+        String md5str = byteArrayToString(md5);
+        getLog().info("Computed MD5: " + md5str);
+        return md5str;
     }
-    return buffer.toString();
-  }
 
-  @SuppressWarnings("unchecked")
-  public static List<File> convertFileSetToFiles(FileSet source)
-      throws IOException {
-    String includes = getCommaSeparatedList(source.getIncludes());
-    String excludes = getCommaSeparatedList(source.getExcludes());
-    return FileUtils.getFiles(new File(source.getDirectory()), includes,
-        excludes);
-  }
+    private enum SCM {
+        NONE, SVN, GIT
+    }
 }

Reply via email to