HADOOP-13602. Fix some warnings by findbugs in hadoop-maven-plugin. (ozawa)
(cherry picked from commit 8d619b4896
)
This commit is contained in:
parent
a0b0767856
commit
d73359382e
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
package org.apache.hadoop.maven.plugin.cmakebuilder;
|
package org.apache.hadoop.maven.plugin.cmakebuilder;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
import org.apache.hadoop.maven.plugin.util.Exec.OutputBufferThread;
|
import org.apache.hadoop.maven.plugin.util.Exec.OutputBufferThread;
|
||||||
import org.apache.hadoop.maven.plugin.util.Exec;
|
import org.apache.hadoop.maven.plugin.util.Exec;
|
||||||
import org.apache.maven.plugin.AbstractMojo;
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
|
@ -83,7 +84,8 @@ public class CompileMojo extends AbstractMojo {
|
||||||
|
|
||||||
// TODO: support Windows
|
// TODO: support Windows
|
||||||
private static void validatePlatform() throws MojoExecutionException {
|
private static void validatePlatform() throws MojoExecutionException {
|
||||||
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
|
if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH)
|
||||||
|
.startsWith("windows")) {
|
||||||
throw new MojoExecutionException("CMakeBuilder does not yet support " +
|
throw new MojoExecutionException("CMakeBuilder does not yet support " +
|
||||||
"the Windows platform.");
|
"the Windows platform.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
package org.apache.hadoop.maven.plugin.cmakebuilder;
|
package org.apache.hadoop.maven.plugin.cmakebuilder;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
import org.apache.hadoop.maven.plugin.util.Exec;
|
import org.apache.hadoop.maven.plugin.util.Exec;
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.plugin.AbstractMojo;
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
|
@ -111,7 +112,8 @@ public class TestMojo extends AbstractMojo {
|
||||||
|
|
||||||
// TODO: support Windows
|
// TODO: support Windows
|
||||||
private static void validatePlatform() throws MojoExecutionException {
|
private static void validatePlatform() throws MojoExecutionException {
|
||||||
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
|
if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH)
|
||||||
|
.startsWith("windows")) {
|
||||||
throw new MojoExecutionException("CMakeBuilder does not yet support " +
|
throw new MojoExecutionException("CMakeBuilder does not yet support " +
|
||||||
"the Windows platform.");
|
"the Windows platform.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,6 +105,10 @@ public class ProtocMojo extends AbstractMojo {
|
||||||
private boolean hasDirectoryChanged(File directory) throws IOException {
|
private boolean hasDirectoryChanged(File directory) throws IOException {
|
||||||
File[] listing = directory.listFiles();
|
File[] listing = directory.listFiles();
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
|
if (listing == null) {
|
||||||
|
// not changed.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// Do not exit early, since we need to compute and save checksums
|
// Do not exit early, since we need to compute and save checksums
|
||||||
// for each file within the directory.
|
// for each file within the directory.
|
||||||
for (File f : listing) {
|
for (File f : listing) {
|
||||||
|
|
|
@ -84,8 +84,10 @@ public class Exec {
|
||||||
if (errors != null) {
|
if (errors != null) {
|
||||||
errors.addAll(stdErr.getOutput());
|
errors.addAll(stdErr.getOutput());
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (IOException ioe) {
|
||||||
mojo.getLog().warn(command + " failed: " + ex.toString());
|
mojo.getLog().warn(command + " failed: " + ioe.toString());
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
mojo.getLog().warn(command + " failed: " + ie.toString());
|
||||||
}
|
}
|
||||||
return retCode;
|
return retCode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.maven.plugin.versioninfo;
|
package org.apache.hadoop.maven.plugin.versioninfo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import org.apache.hadoop.maven.plugin.util.Exec;
|
import org.apache.hadoop.maven.plugin.util.Exec;
|
||||||
import org.apache.hadoop.maven.plugin.util.FileSetUtils;
|
import org.apache.hadoop.maven.plugin.util.FileSetUtils;
|
||||||
|
@ -149,27 +150,23 @@ public class VersionInfoMojo extends AbstractMojo {
|
||||||
*/
|
*/
|
||||||
private String[] getSvnUriInfo(String str) {
|
private String[] getSvnUriInfo(String str) {
|
||||||
String[] res = new String[]{"Unknown", "Unknown"};
|
String[] res = new String[]{"Unknown", "Unknown"};
|
||||||
try {
|
String path = str;
|
||||||
String path = str;
|
int index = path.indexOf("trunk");
|
||||||
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) {
|
if (index > -1) {
|
||||||
res[0] = path.substring(0, index - 1);
|
res[0] = path.substring(0, index - 1);
|
||||||
res[1] = "trunk";
|
int branchIndex = index + "branches".length() + 1;
|
||||||
} else {
|
index = path.indexOf("/", branchIndex);
|
||||||
index = path.indexOf("branches");
|
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
res[0] = path.substring(0, index - 1);
|
res[1] = path.substring(branchIndex, index);
|
||||||
int branchIndex = index + "branches".length() + 1;
|
} else {
|
||||||
index = path.indexOf("/", branchIndex);
|
res[1] = path.substring(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);
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -311,6 +308,20 @@ public class VersionInfoMojo extends AbstractMojo {
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class MD5Comparator implements Comparator<File>, Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(File lhs, File rhs) {
|
||||||
|
return normalizePath(lhs).compareTo(normalizePath(rhs));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String normalizePath(File file) {
|
||||||
|
return file.getPath().toUpperCase(Locale.ENGLISH)
|
||||||
|
.replaceAll("\\\\", "/");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes and returns an MD5 checksum of the contents of all files in the
|
* Computes and returns an MD5 checksum of the contents of all files in the
|
||||||
* input Maven FileSet.
|
* input Maven FileSet.
|
||||||
|
@ -323,17 +334,7 @@ public class VersionInfoMojo extends AbstractMojo {
|
||||||
// File order of MD5 calculation is significant. Sorting is done on
|
// File order of MD5 calculation is significant. Sorting is done on
|
||||||
// unix-format names, case-folded, in order to get a platform-independent
|
// unix-format names, case-folded, in order to get a platform-independent
|
||||||
// sort and calculate the same MD5 on all platforms.
|
// sort and calculate the same MD5 on all platforms.
|
||||||
Collections.sort(files, new Comparator<File>() {
|
Collections.sort(files, new MD5Comparator());
|
||||||
@Override
|
|
||||||
public int compare(File lhs, File rhs) {
|
|
||||||
return normalizePath(lhs).compareTo(normalizePath(rhs));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String normalizePath(File file) {
|
|
||||||
return file.getPath().toUpperCase(Locale.ENGLISH)
|
|
||||||
.replaceAll("\\\\", "/");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
byte[] md5 = computeMD5(files);
|
byte[] md5 = computeMD5(files);
|
||||||
String md5str = byteArrayToString(md5);
|
String md5str = byteArrayToString(md5);
|
||||||
getLog().info("Computed MD5: " + md5str);
|
getLog().info("Computed MD5: " + md5str);
|
||||||
|
|
Loading…
Reference in New Issue