You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2013/10/11 21:29:02 UTC
git commit: ACCUMULO-1030 Fix classpath issues
Updated Branches:
refs/heads/master 3976e0a35 -> 57afd7e28
ACCUMULO-1030 Fix classpath issues
Fixed classpath issues introduced by ACCUMULO-1368 changes
(741daecfde80e19ceaeb11f89124883f53effd59). MiniAccumuloConfig now has
the ability to explicitly set classpath elements to be used when
spawning processes.
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/57afd7e2
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/57afd7e2
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/57afd7e2
Branch: refs/heads/master
Commit: 57afd7e2834173619840e18817983d4d1d500f5e
Parents: 3976e0a
Author: Christopher Tubbs <ct...@apache.org>
Authored: Fri Oct 11 15:25:14 2013 -0400
Committer: Christopher Tubbs <ct...@apache.org>
Committed: Fri Oct 11 15:25:14 2013 -0400
----------------------------------------------------------------------
.../maven/plugin/AbstractAccumuloMojo.java | 31 ++++-----
.../apache/accumulo/maven/plugin/StartMojo.java | 20 +++---
.../minicluster/MiniAccumuloCluster.java | 70 ++++++++++----------
.../minicluster/MiniAccumuloConfig.java | 23 +++++++
4 files changed, 82 insertions(+), 62 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/57afd7e2/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/AbstractAccumuloMojo.java
----------------------------------------------------------------------
diff --git a/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/AbstractAccumuloMojo.java b/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/AbstractAccumuloMojo.java
index 65174ed..cc34511 100644
--- a/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/AbstractAccumuloMojo.java
+++ b/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/AbstractAccumuloMojo.java
@@ -18,35 +18,30 @@ package org.apache.accumulo.maven.plugin;
import java.io.File;
import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import org.apache.accumulo.minicluster.MiniAccumuloConfig;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.project.MavenProject;
public abstract class AbstractAccumuloMojo extends AbstractMojo {
-
+
@Component
private MavenProject project;
-
- void configureMiniClasspath(String miniClasspath) throws MalformedURLException {
- String classpath = "";
- StringBuilder sb = new StringBuilder();
+
+ void configureMiniClasspath(MiniAccumuloConfig macConfig, String miniClasspath) throws MalformedURLException {
+ ArrayList<String> classpathItems = new ArrayList<String>();
if (miniClasspath == null && project != null) {
- sb.append(project.getBuild().getOutputDirectory());
- String sep = File.pathSeparator;
- sb.append(sep).append(project.getBuild().getTestOutputDirectory());
- for (Artifact artifact : project.getArtifacts()) {
- addArtifact(sb, sep, artifact);
- }
- classpath = sb.toString();
+ classpathItems.add(project.getBuild().getOutputDirectory());
+ classpathItems.add(project.getBuild().getTestOutputDirectory());
+ for (Artifact artifact : project.getArtifacts())
+ classpathItems.add(artifact.getFile().toURI().toURL().toString());
} else if (miniClasspath != null && !miniClasspath.isEmpty()) {
- classpath = miniClasspath;
+ classpathItems.addAll(Arrays.asList(miniClasspath.split(File.pathSeparator)));
}
- System.setProperty("java.class.path", System.getProperty("java.class.path", "") + File.pathSeparator + classpath);
- }
-
- private void addArtifact(StringBuilder classpath, String separator, Artifact artifact) throws MalformedURLException {
- classpath.append(separator).append(artifact.getFile().toURI().toURL());
+ macConfig.setClasspathItems(classpathItems.toArray(new String[classpathItems.size()]));
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/57afd7e2/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/StartMojo.java
----------------------------------------------------------------------
diff --git a/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/StartMojo.java b/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/StartMojo.java
index 9579952..a210c79 100644
--- a/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/StartMojo.java
+++ b/maven-plugin/src/main/java/org/apache/accumulo/maven/plugin/StartMojo.java
@@ -37,32 +37,32 @@ import org.codehaus.plexus.util.FileUtils;
@ThreadSafe
@Mojo(name = "start", defaultPhase = LifecyclePhase.PRE_INTEGRATION_TEST, requiresDependencyResolution = ResolutionScope.TEST)
public class StartMojo extends AbstractAccumuloMojo {
-
+
@Parameter(defaultValue = "${project.build.directory}", property = "outputDir", required = true)
private File outputDirectory;
-
+
@Parameter(defaultValue = "testInstance", property = "instanceName", required = true)
private String instanceName;
-
+
@Parameter(defaultValue = "secret", property = "rootPassword", required = true)
private String rootPassword;
-
+
private String miniClasspath;
-
+
static Set<MiniAccumuloCluster> runningClusters = Collections.synchronizedSet(new HashSet<MiniAccumuloCluster>());
-
+
@Override
public void execute() throws MojoExecutionException {
File subdir = new File(new File(outputDirectory, "accumulo-maven-plugin"), instanceName);
-
+
try {
subdir = subdir.getCanonicalFile();
if (subdir.exists())
FileUtils.forceDelete(subdir);
subdir.mkdirs();
- configureMiniClasspath(miniClasspath);
MiniAccumuloConfig cfg = new MiniAccumuloConfig(subdir, rootPassword);
cfg.setInstanceName(instanceName);
+ configureMiniClasspath(cfg, miniClasspath);
MiniAccumuloCluster mac = new MiniAccumuloCluster(cfg);
System.out.println("Starting MiniAccumuloCluster: " + mac.getInstanceName() + " in " + mac.getConfig().getDir());
mac.start();
@@ -70,9 +70,9 @@ public class StartMojo extends AbstractAccumuloMojo {
} catch (Exception e) {
throw new MojoExecutionException("Unable to start " + MiniAccumuloCluster.class.getSimpleName(), e);
}
-
+
}
-
+
public static void main(String[] args) throws MojoExecutionException {
int a = 0;
for (String arg : args) {
http://git-wip-us.apache.org/repos/asf/accumulo/blob/57afd7e2/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
----------------------------------------------------------------------
diff --git a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
index 165acad..dd230dd 100644
--- a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
+++ b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
@@ -153,7 +153,7 @@ public class MiniAccumuloCluster {
private boolean containsSiteFile(File f) {
return f.isDirectory() && f.listFiles(new FileFilter() {
-
+
@Override
public boolean accept(File pathname) {
return pathname.getName().endsWith("site.xml");
@@ -161,59 +161,61 @@ public class MiniAccumuloCluster {
}).length > 0;
}
- private void append(StringBuilder classpathBuilder, String sep, URL url) throws URISyntaxException {
+ private void append(StringBuilder classpathBuilder, URL url) throws URISyntaxException {
File file = new File(url.toURI());
// do not include dirs containing hadoop or accumulo site files
- if (!containsSiteFile(file)) {
- classpathBuilder.append(sep);
- classpathBuilder.append(file.getAbsolutePath());
- }
+ if (!containsSiteFile(file))
+ classpathBuilder.append(File.pathSeparator).append(file.getAbsolutePath());
}
private String getClasspath() throws IOException {
-
+
try {
ArrayList<ClassLoader> classloaders = new ArrayList<ClassLoader>();
-
+
ClassLoader cl = this.getClass().getClassLoader();
-
+
while (cl != null) {
classloaders.add(cl);
cl = cl.getParent();
}
-
+
Collections.reverse(classloaders);
-
+
StringBuilder classpathBuilder = new StringBuilder();
classpathBuilder.append(config.getConfDir().getAbsolutePath());
- String sep = File.pathSeparator;
-
- // assume 0 is the system classloader and skip it
- for (int i = 1; i < classloaders.size(); i++) {
- ClassLoader classLoader = classloaders.get(i);
-
- if (classLoader instanceof URLClassLoader) {
-
- URLClassLoader ucl = (URLClassLoader) classLoader;
-
- for (URL u : ucl.getURLs()) {
- append(classpathBuilder, sep, u);
- }
-
- } else if (classLoader instanceof VFSClassLoader) {
-
- VFSClassLoader vcl = (VFSClassLoader) classLoader;
- for (FileObject f : vcl.getFileObjects()) {
- append(classpathBuilder, sep, f.getURL());
+ if (config.getClasspathItems() == null) {
+
+ // assume 0 is the system classloader and skip it
+ for (int i = 1; i < classloaders.size(); i++) {
+ ClassLoader classLoader = classloaders.get(i);
+
+ if (classLoader instanceof URLClassLoader) {
+
+ URLClassLoader ucl = (URLClassLoader) classLoader;
+
+ for (URL u : ucl.getURLs()) {
+ append(classpathBuilder, u);
+ }
+
+ } else if (classLoader instanceof VFSClassLoader) {
+
+ VFSClassLoader vcl = (VFSClassLoader) classLoader;
+ for (FileObject f : vcl.getFileObjects()) {
+ append(classpathBuilder, f.getURL());
+ }
+ } else {
+ throw new IllegalArgumentException("Unknown classloader type : " + classLoader.getClass().getName());
}
- } else {
- throw new IllegalArgumentException("Unknown classloader type : " + classLoader.getClass().getName());
}
+ } else {
+ for (String s : config.getClasspathItems())
+ classpathBuilder.append(File.pathSeparator).append(s);
}
-
+
return classpathBuilder.toString();
-
+
} catch (URISyntaxException e) {
throw new IOException(e);
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/57afd7e2/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java
----------------------------------------------------------------------
diff --git a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java
index 0b6c42c..2ae6d0f 100644
--- a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java
+++ b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloConfig.java
@@ -59,6 +59,8 @@ public class MiniAccumuloConfig {
private boolean useMiniDFS = false;
private boolean runGC = false;
+ private String[] classpathItems = null;
+
/**
* @param dir
* An empty or nonexistant directory that Accumulo and Zookeeper can store data in. Creating the directory is left to the user. Java 7, Guava, and
@@ -372,4 +374,25 @@ public class MiniAccumuloConfig {
public void runGC(boolean shouldRunGC) {
runGC = shouldRunGC;
}
+
+ /**
+ * Gets the classpath elements to use when spawning processes.
+ *
+ * @return the classpathItems, if set
+ * @since 1.6.0
+ */
+ public String[] getClasspathItems() {
+ return classpathItems;
+ }
+
+ /**
+ * Sets the classpath elements to use when spawning processes.
+ *
+ * @param classpathItems
+ * the classpathItems to set
+ * @since 1.6.0
+ */
+ public void setClasspathItems(String... classpathItems) {
+ this.classpathItems = classpathItems;
+ }
}