accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [42/50] [abbrv] git commit: ACCUMULO-1030 First attempt at a working accumulo-maven-plugin
Date Wed, 17 Jul 2013 02:33:44 GMT
ACCUMULO-1030 First attempt at a working accumulo-maven-plugin

git-svn-id: https://svn.apache.org/repos/asf/accumulo/trunk@1502702 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/ACCUMULO-1496
Commit: db39c354eb0a393d504c3454b65bf6f2969d54bf
Parents: 6c4bfc7
Author: Christopher Tubbs <ctubbsii@apache.org>
Authored: Fri Jul 12 21:50:41 2013 +0000
Committer: Christopher Tubbs <ctubbsii@apache.org>
Committed: Fri Jul 12 21:50:41 2013 +0000

----------------------------------------------------------------------
 maven-plugin/pom.xml                            | 163 +++++++++++++++++++
 maven-plugin/src/it/plugin-test/pom.xml         | 117 +++++++++++++
 .../src/it/plugin-test/postbuild.groovy         |  24 +++
 .../org/apache/accumulo/plugin/PluginIT.java    |  98 +++++++++++
 maven-plugin/src/it/settings.xml                |  55 +++++++
 .../maven/plugin/AbstractAccumuloMojo.java      |  42 +++++
 .../org/accumulo/maven/plugin/StartMojo.java    |  67 ++++++++
 .../org/accumulo/maven/plugin/StopMojo.java     |  45 +++++
 .../minicluster/MiniAccumuloCluster.java        | 132 +++++++--------
 .../minicluster/MiniAccumuloInstance.java       |  51 ++++++
 pom.xml                                         |  43 +++--
 11 files changed, 753 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/db39c354/maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/maven-plugin/pom.xml b/maven-plugin/pom.xml
new file mode 100644
index 0000000..9060498
--- /dev/null
+++ b/maven-plugin/pom.xml
@@ -0,0 +1,163 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.accumulo</groupId>
+    <artifactId>accumulo-project</artifactId>
+    <version>1.6.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>accumulo-maven-plugin</artifactId>
+  <packaging>maven-plugin</packaging>
+  <name>Accumulo Maven Plugin</name>
+  <dependencies>
+    <dependency>
+      <groupId>commons-cli</groupId>
+      <artifactId>commons-cli</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-configuration</groupId>
+      <artifactId>commons-configuration</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-httpclient</groupId>
+      <artifactId>commons-httpclient</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.accumulo</groupId>
+      <artifactId>accumulo-minicluster</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-client</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugin-tools</groupId>
+      <artifactId>maven-plugin-annotations</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.zookeeper</groupId>
+      <artifactId>zookeeper</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-utils</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-plugin-plugin</artifactId>
+        <configuration>
+          <skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
+        </configuration>
+        <executions>
+          <execution>
+            <id>mojo-descriptor</id>
+            <goals>
+              <goal>descriptor</goal>
+            </goals>
+          </execution>
+          <execution>
+            <id>help-goal</id>
+            <goals>
+              <goal>helpmojo</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  <profiles>
+    <profile>
+      <id>test-accumulo-maven-plugin</id>
+      <activation>
+        <property>
+          <name>!skipITs</name>
+        </property>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-invoker-plugin</artifactId>
+            <configuration>
+              <debug>true</debug>
+              <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
+              <pomIncludes>
+                <pomInclude>*/pom.xml</pomInclude>
+              </pomIncludes>
+              <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
+              <settingsFile>src/it/settings.xml</settingsFile>
+              <goals>
+                <goal>clean</goal>
+                <goal>post-integration-test</goal>
+              </goals>
+            </configuration>
+            <executions>
+              <execution>
+                <id>integration-test</id>
+                <goals>
+                  <goal>install</goal>
+                  <goal>run</goal>
+                </goals>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+</project>

http://git-wip-us.apache.org/repos/asf/accumulo/blob/db39c354/maven-plugin/src/it/plugin-test/pom.xml
----------------------------------------------------------------------
diff --git a/maven-plugin/src/it/plugin-test/pom.xml b/maven-plugin/src/it/plugin-test/pom.xml
new file mode 100644
index 0000000..7c430ca
--- /dev/null
+++ b/maven-plugin/src/it/plugin-test/pom.xml
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>@project.groupId@</groupId>
+    <artifactId>accumulo-project</artifactId>
+    <version>@project.version@</version>
+  </parent>
+
+  <groupId>@project.groupId@</groupId>
+  <artifactId>@project.artifactId@-test</artifactId>
+  <version>@project.version@</version>
+
+  <description>A simple IT verifying the basic use case.</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>commons-cli</groupId>
+      <artifactId>commons-cli</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-codec</groupId>
+      <artifactId>commons-codec</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-configuration</groupId>
+      <artifactId>commons-configuration</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-httpclient</groupId>
+      <artifactId>commons-httpclient</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-lang</groupId>
+      <artifactId>commons-lang</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>commons-logging</groupId>
+      <artifactId>commons-logging</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>log4j</groupId>
+      <artifactId>log4j</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.accumulo</groupId>
+      <artifactId>accumulo-minicluster</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.hadoop</groupId>
+      <artifactId>hadoop-client</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.zookeeper</groupId>
+      <artifactId>zookeeper</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>@project.groupId@</groupId>
+        <artifactId>@project.artifactId@</artifactId>
+        <version>@project.version@</version>
+        <configuration>
+          <instanceName>plugin-it-instance</instanceName>
+          <rootPassword>ITSecret</rootPassword>
+        </configuration>
+        <executions>
+          <execution>
+            <id>run-plugin</id>
+            <goals>
+              <goal>start</goal>
+              <goal>stop</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

http://git-wip-us.apache.org/repos/asf/accumulo/blob/db39c354/maven-plugin/src/it/plugin-test/postbuild.groovy
----------------------------------------------------------------------
diff --git a/maven-plugin/src/it/plugin-test/postbuild.groovy b/maven-plugin/src/it/plugin-test/postbuild.groovy
new file mode 100644
index 0000000..404961a
--- /dev/null
+++ b/maven-plugin/src/it/plugin-test/postbuild.groovy
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+File outputDirectory = new File(basedir, "target/accumulo-maven-plugin/plugin-it-instance");
+assert outputDirectory.isDirectory()
+
+File testCreateTable = new File(basedir, "target/accumulo-maven-plugin/plugin-it-instance/testCreateTablePassed");
+assert testCreateTable.isFile()
+
+File testWriteToTable = new File(basedir, "target/accumulo-maven-plugin/plugin-it-instance/testWriteToTablePassed");
+assert testWriteToTable.isFile()

http://git-wip-us.apache.org/repos/asf/accumulo/blob/db39c354/maven-plugin/src/it/plugin-test/src/test/java/org/apache/accumulo/plugin/PluginIT.java
----------------------------------------------------------------------
diff --git a/maven-plugin/src/it/plugin-test/src/test/java/org/apache/accumulo/plugin/PluginIT.java b/maven-plugin/src/it/plugin-test/src/test/java/org/apache/accumulo/plugin/PluginIT.java
new file mode 100644
index 0000000..e4dee28
--- /dev/null
+++ b/maven-plugin/src/it/plugin-test/src/test/java/org/apache/accumulo/plugin/PluginIT.java
@@ -0,0 +1,98 @@
+/*
+ * 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.
+ */
+package org.apache.accumulo.plugin;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map.Entry;
+
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.BatchWriter;
+import org.apache.accumulo.core.client.BatchWriterConfig;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.client.TableExistsException;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.minicluster.MiniAccumuloInstance;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class PluginIT {
+  
+  private static Instance instance;
+  private static Connector connector;
+  
+  @BeforeClass
+  public static void setUp() throws Exception {
+    String instanceName = "plugin-it-instance";
+    instance = new MiniAccumuloInstance(instanceName, new File("target/accumulo-maven-plugin/" + instanceName));
+    connector = instance.getConnector("root", new PasswordToken("ITSecret"));
+  }
+  
+  @Test
+  public void testInstanceConnection() {
+    assertTrue(instance != null);
+    assertTrue(instance instanceof MiniAccumuloInstance);
+    assertTrue(connector != null);
+    assertTrue(connector instanceof Connector);
+  }
+  
+  @Test
+  public void testCreateTable() throws AccumuloException, AccumuloSecurityException, TableExistsException, IOException {
+    String tableName = "testCreateTable";
+    connector.tableOperations().create(tableName);
+    assertTrue(connector.tableOperations().exists(tableName));
+    assertTrue(new File("target/accumulo-maven-plugin/" + instance.getInstanceName() + "/testCreateTablePassed").createNewFile());
+  }
+  
+  @Test
+  public void writeToTable() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, IOException {
+    String tableName = "writeToTable";
+    connector.tableOperations().create(tableName);
+    BatchWriter bw = connector.createBatchWriter(tableName, new BatchWriterConfig());
+    Mutation m = new Mutation("ROW");
+    m.put("CF", "CQ", "V");
+    bw.addMutation(m);
+    bw.close();
+    Scanner scanner = connector.createScanner(tableName, Authorizations.EMPTY);
+    int count = 0;
+    for (Entry<Key,Value> entry : scanner) {
+      count++;
+      assertEquals("ROW", entry.getKey().getRow().toString());
+      assertEquals("CF", entry.getKey().getColumnFamily().toString());
+      assertEquals("CQ", entry.getKey().getColumnQualifier().toString());
+      assertEquals("V", entry.getValue().toString());
+    }
+    assertEquals(1, count);
+    assertTrue(new File("target/accumulo-maven-plugin/" + instance.getInstanceName() + "/testWriteToTablePassed").createNewFile());
+  }
+  
+  @AfterClass
+  public static void tearDown() throws Exception {}
+  
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/db39c354/maven-plugin/src/it/settings.xml
----------------------------------------------------------------------
diff --git a/maven-plugin/src/it/settings.xml b/maven-plugin/src/it/settings.xml
new file mode 100644
index 0000000..c8f77f0
--- /dev/null
+++ b/maven-plugin/src/it/settings.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+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.
+-->
+
+<settings>
+  <profiles>
+    <profile>
+      <id>it-repo</id>
+      <activation>
+        <activeByDefault>true</activeByDefault>
+      </activation>
+      <repositories>
+        <repository>
+          <id>local.central</id>
+          <url>@localRepositoryUrl@</url>
+          <releases>
+            <enabled>true</enabled>
+          </releases>
+          <snapshots>
+            <enabled>true</enabled>
+          </snapshots>
+        </repository>
+      </repositories>
+      <pluginRepositories>
+        <pluginRepository>
+          <id>local.central</id>
+          <url>@localRepositoryUrl@</url>
+          <releases>
+            <enabled>true</enabled>
+          </releases>
+          <snapshots>
+            <enabled>true</enabled>
+          </snapshots>
+        </pluginRepository>
+      </pluginRepositories>
+    </profile>
+  </profiles>
+</settings>

http://git-wip-us.apache.org/repos/asf/accumulo/blob/db39c354/maven-plugin/src/main/java/org/accumulo/maven/plugin/AbstractAccumuloMojo.java
----------------------------------------------------------------------
diff --git a/maven-plugin/src/main/java/org/accumulo/maven/plugin/AbstractAccumuloMojo.java b/maven-plugin/src/main/java/org/accumulo/maven/plugin/AbstractAccumuloMojo.java
new file mode 100644
index 0000000..2ffcd29
--- /dev/null
+++ b/maven-plugin/src/main/java/org/accumulo/maven/plugin/AbstractAccumuloMojo.java
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+package org.accumulo.maven.plugin;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugins.annotations.Parameter;
+
+public abstract class AbstractAccumuloMojo extends AbstractMojo {
+  
+  @Parameter(defaultValue = "${plugin.artifacts}", readonly = true, required = true)
+  private List<Artifact> pluginArtifacts;
+  
+  void configureMiniClasspath() {
+    for (Artifact artifact : pluginArtifacts) {
+      try {
+        System.setProperty("java.class.path", System.getProperty("java.class.path", "") + File.pathSeparator + artifact.getFile().toURI().toURL());
+      } catch (MalformedURLException e) {
+        e.printStackTrace();
+      }
+    }
+    
+  }
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/db39c354/maven-plugin/src/main/java/org/accumulo/maven/plugin/StartMojo.java
----------------------------------------------------------------------
diff --git a/maven-plugin/src/main/java/org/accumulo/maven/plugin/StartMojo.java b/maven-plugin/src/main/java/org/accumulo/maven/plugin/StartMojo.java
new file mode 100644
index 0000000..fc0d716
--- /dev/null
+++ b/maven-plugin/src/main/java/org/accumulo/maven/plugin/StartMojo.java
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+package org.accumulo.maven.plugin;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.accumulo.minicluster.MiniAccumuloCluster;
+import org.apache.accumulo.minicluster.MiniAccumuloConfig;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+
+/**
+ * Goal which starts an instance of {@link MiniAccumuloCluster}.
+ */
+@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 = "secret";
+  
+  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);
+    subdir.mkdirs();
+    
+    try {
+      configureMiniClasspath();
+      MiniAccumuloConfig cfg = new MiniAccumuloConfig(subdir, rootPassword);
+      cfg.setInstanceName(instanceName);
+      MiniAccumuloCluster mac = new MiniAccumuloCluster(cfg);
+      System.out.println("Starting MiniAccumuloCluster: " + mac.getInstanceName());
+      mac.start();
+      runningClusters.add(mac);
+    } catch (Exception e) {
+      throw new MojoExecutionException("Unable to start " + MiniAccumuloCluster.class.getSimpleName(), e);
+    }
+    
+  }
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/db39c354/maven-plugin/src/main/java/org/accumulo/maven/plugin/StopMojo.java
----------------------------------------------------------------------
diff --git a/maven-plugin/src/main/java/org/accumulo/maven/plugin/StopMojo.java b/maven-plugin/src/main/java/org/accumulo/maven/plugin/StopMojo.java
new file mode 100644
index 0000000..84c2a6c
--- /dev/null
+++ b/maven-plugin/src/main/java/org/accumulo/maven/plugin/StopMojo.java
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+package org.accumulo.maven.plugin;
+
+import org.apache.accumulo.minicluster.MiniAccumuloCluster;
+import org.apache.accumulo.minicluster.MiniAccumuloCluster.LogWriter;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+
+/**
+ * Goal which stops all instances of {@link MiniAccumuloCluster} started with the start mojo.
+ */
+@Mojo(name = "stop", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST, requiresDependencyResolution = ResolutionScope.TEST)
+public class StopMojo extends AbstractAccumuloMojo {
+  
+  @Override
+  public void execute() throws MojoExecutionException {
+    for (MiniAccumuloCluster mac : StartMojo.runningClusters) {
+      System.out.println("Stopping MiniAccumuloCluster: " + mac.getInstanceName());
+      try {
+        mac.stop();
+        for (LogWriter log : mac.getLogWriters())
+          log.flush();
+      } catch (Exception e) {
+        throw new MojoExecutionException("Unable to start " + MiniAccumuloCluster.class.getSimpleName(), e);
+      }
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/db39c354/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 8da22e0..0418396 100644
--- a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
+++ b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloCluster.java
@@ -58,7 +58,7 @@ import org.apache.zookeeper.server.ZooKeeperServerMain;
 /**
  * A utility class that will create Zookeeper and Accumulo processes that write all of their data to a single local directory. This class makes it easy to test
  * code against a real Accumulo instance. Its much more accurate for testing than {@link org.apache.accumulo.core.client.mock.MockAccumulo}, but much slower.
- *
+ * 
  * @since 1.5.0
  */
 public class MiniAccumuloCluster {
@@ -66,14 +66,11 @@ public class MiniAccumuloCluster {
   public static class LogWriter extends Daemon {
     private BufferedReader in;
     private BufferedWriter out;
-
-    /**
-     * @throws IOException
-     */
+    
     public LogWriter(InputStream stream, File logFile) throws IOException {
       this.in = new BufferedReader(new InputStreamReader(stream));
       out = new BufferedWriter(new FileWriter(logFile));
-
+      
       SimpleTimer.getInstance().schedule(new Runnable() {
         @Override
         public void run() {
@@ -85,75 +82,74 @@ public class MiniAccumuloCluster {
         }
       }, 1000, 1000);
     }
-
+    
     public synchronized void flush() throws IOException {
       if (out != null)
         out.flush();
     }
-
+    
     @Override
     public void run() {
       String line;
-
+      
       try {
         while ((line = in.readLine()) != null) {
           out.append(line);
           out.append("\n");
         }
-
+        
         synchronized (this) {
           out.close();
           out = null;
           in.close();
         }
-
+        
       } catch (IOException e) {}
     }
   }
-
+  
   private boolean initialized = false;
   private Process zooKeeperProcess = null;
   private Process masterProcess = null;
   private List<Process> tabletServerProcesses = new ArrayList<Process>();
-
+  
   private Set<Pair<ServerType,Integer>> debugPorts = new HashSet<Pair<ServerType,Integer>>();
-
+  
   private File zooCfgFile;
-
+  
   public List<LogWriter> getLogWriters() {
     return logWriters;
   }
-
-
+  
   private List<LogWriter> logWriters = new ArrayList<MiniAccumuloCluster.LogWriter>();
-
+  
   private MiniAccumuloConfig config;
-
+  
   public Process exec(Class<? extends Object> clazz, String... args) throws IOException {
     return exec(clazz, Collections.singletonList("-Xmx" + config.getDefaultMemory()), args);
   }
-
+  
   private Process exec(Class<? extends Object> clazz, List<String> extraJvmOpts, String... args) throws IOException {
     String javaHome = System.getProperty("java.home");
     String javaBin = javaHome + File.separator + "bin" + File.separator + "java";
     String classpath = System.getProperty("java.class.path");
-
+    
     classpath = config.getConfDir().getAbsolutePath() + File.pathSeparator + classpath;
-
+    
     String className = clazz.getCanonicalName();
-
+    
     ArrayList<String> argList = new ArrayList<String>();
     argList.addAll(Arrays.asList(javaBin, "-Dproc=" + clazz.getSimpleName(), "-cp", classpath));
     argList.add("-Djava.library.path=" + config.getLibDir());
     argList.addAll(extraJvmOpts);
     argList.addAll(Arrays.asList("-XX:+UseConcMarkSweepGC", "-XX:CMSInitiatingOccupancyFraction=75", Main.class.getName(), className));
     argList.addAll(Arrays.asList(args));
-
+    
     ProcessBuilder builder = new ProcessBuilder(argList);
-
+    
     builder.environment().put("ACCUMULO_HOME", config.getDir().getAbsolutePath());
     builder.environment().put("ACCUMULO_LOG_DIR", config.getLogDir().getAbsolutePath());
-
+    
     // if we're running under accumulo.start, we forward these env vars
     String env = System.getenv("HADOOP_PREFIX");
     if (env != null)
@@ -161,9 +157,9 @@ public class MiniAccumuloCluster {
     env = System.getenv("ZOOKEEPER_HOME");
     if (env != null)
       builder.environment().put("ZOOKEEPER_HOME", env);
-
+    
     Process process = builder.start();
-
+    
     LogWriter lw;
     lw = new LogWriter(process.getErrorStream(), new File(config.getLogDir(), clazz.getSimpleName() + "_" + process.hashCode() + ".err"));
     logWriters.add(lw);
@@ -171,12 +167,12 @@ public class MiniAccumuloCluster {
     lw = new LogWriter(process.getInputStream(), new File(config.getLogDir(), clazz.getSimpleName() + "_" + process.hashCode() + ".out"));
     logWriters.add(lw);
     lw.start();
-
+    
     return process;
   }
-
+  
   private Process exec(Class<? extends Object> clazz, ServerType serverType, String... args) throws IOException {
-
+    
     List<String> jvmOpts = new ArrayList<String>();
     jvmOpts.add("-Xmx" + config.getMemory(serverType));
 
@@ -187,49 +183,47 @@ public class MiniAccumuloCluster {
     }
     return exec(clazz, jvmOpts, args);
   }
-
+  
   /**
-   *
+   * 
    * @param dir
    *          An empty or nonexistant temp directoy that Accumulo and Zookeeper can store data in. Creating the directory is left to the user. Java 7, Guava,
    *          and Junit provide methods for creating temporary directories.
    * @param rootPassword
    *          Initial root password for instance.
-   * @throws IOException
    */
   public MiniAccumuloCluster(File dir, String rootPassword) throws IOException {
     this(new MiniAccumuloConfig(dir, rootPassword));
   }
-
+  
   /**
    * @param config
    *          initial configuration
-   * @throws IOException
    */
   public MiniAccumuloCluster(MiniAccumuloConfig config) throws IOException {
-
+    
     this.config = config.initialize();
-
+    
     config.getConfDir().mkdirs();
     config.getAccumuloDir().mkdirs();
     config.getZooKeeperDir().mkdirs();
     config.getLogDir().mkdirs();
     config.getWalogDir().mkdirs();
     config.getLibDir().mkdirs();
-
+    
     File siteFile = new File(config.getConfDir(), "accumulo-site.xml");
-
+    
     FileWriter fileWriter = new FileWriter(siteFile);
     fileWriter.append("<configuration>\n");
-
+    
     for (Entry<String,String> entry : config.getSiteConfig().entrySet())
       fileWriter.append("<property><name>" + entry.getKey() + "</name><value>" + entry.getValue() + "</value></property>\n");
     fileWriter.append("</configuration>\n");
     fileWriter.close();
-
+    
     zooCfgFile = new File(config.getConfDir(), "zoo.cfg");
     fileWriter = new FileWriter(zooCfgFile);
-
+    
     // zookeeper uses Properties to read its config, so use that to write in order to properly escape things like Windows paths
     Properties zooCfg = new Properties();
     zooCfg.setProperty("tickTime", "1000");
@@ -239,9 +233,9 @@ public class MiniAccumuloCluster {
     zooCfg.setProperty("maxClientCnxns", "100");
     zooCfg.setProperty("dataDir", config.getZooKeeperDir().getAbsolutePath());
     zooCfg.store(fileWriter, null);
-
+    
     fileWriter.close();
-
+    
     File nativeMap = new File(config.getLibDir().getAbsolutePath() + "/native/map");
     nativeMap.mkdirs();
     File testRoot = new File(new File(new File(System.getProperty("user.dir")).getParent() + "/server/src/main/c++/nativeMap").getAbsolutePath());
@@ -254,17 +248,15 @@ public class MiniAccumuloCluster {
       }
     }
   }
-
+  
   /**
    * Starts Accumulo and Zookeeper processes. Can only be called once.
-   *
-   * @throws IOException
-   * @throws InterruptedException
+   * 
    * @throws IllegalStateException
    *           if already started
    */
   public void start() throws IOException, InterruptedException {
-
+    
     if (!initialized) {
       
       Runtime.getRuntime().addShutdownHook(new Thread() {
@@ -280,22 +272,22 @@ public class MiniAccumuloCluster {
         }
       });
     }
-
+    
     if (zooKeeperProcess == null) {
       zooKeeperProcess = exec(Main.class, ServerType.ZOOKEEPER, ZooKeeperServerMain.class.getName(), zooCfgFile.getAbsolutePath());
       // sleep a little bit to let zookeeper come up before calling init, seems to work better
       UtilWaitThread.sleep(250);
     }
-
+    
     if (!initialized) {
       Process initProcess = exec(Initialize.class, "--instance-name", config.getInstanceName(), "--password", config.getRootPassword(), "--username", "root");
       int ret = initProcess.waitFor();
       if (ret != 0) {
         throw new RuntimeException("Initialize process returned " + ret);
       }
-      initialized = true; 
+      initialized = true;
     }
-
+    
     for (int i = tabletServerProcesses.size(); i < config.getNumTservers(); i++) {
       tabletServerProcesses.add(exec(TabletServer.class, ServerType.TABLET_SERVER));
     }
@@ -308,14 +300,13 @@ public class MiniAccumuloCluster {
       masterProcess = exec(Master.class, ServerType.MASTER);
     }
   }
-
+  
   private List<String> buildRemoteDebugParams(int port) {
     return Arrays.asList(new String[] {"-Xdebug", String.format("-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=%d", port)});
   }
-
+  
   /**
    * @return generated remote debug ports if in debug mode.
-   *
    * @since 1.6.0
    */
   public Set<Pair<ServerType,Integer>> getDebugPorts() {
@@ -330,8 +321,8 @@ public class MiniAccumuloCluster {
     return result;
   }
   
-  public Map<ServerType, Collection<ProcessReference>> getProcesses() {
-    Map<ServerType, Collection<ProcessReference>> result = new HashMap<ServerType, Collection<ProcessReference>>();
+  public Map<ServerType,Collection<ProcessReference>> getProcesses() {
+    Map<ServerType,Collection<ProcessReference>> result = new HashMap<ServerType,Collection<ProcessReference>>();
     result.put(ServerType.MASTER, references(masterProcess));
     result.put(ServerType.TABLET_SERVER, references(tabletServerProcesses.toArray(new Process[0])));
     result.put(ServerType.ZOOKEEPER, references(zooKeeperProcess));
@@ -349,7 +340,7 @@ public class MiniAccumuloCluster {
         }
         break;
       case TABLET_SERVER:
-        for (Process tserver: tabletServerProcesses) {
+        for (Process tserver : tabletServerProcesses) {
           if (proc.equals(tserver)) {
             tabletServerProcesses.remove(tserver);
             found = true;
@@ -368,27 +359,24 @@ public class MiniAccumuloCluster {
     if (!found)
       throw new ProcessNotFoundException();
   }
-
+  
   /**
    * @return Accumulo instance name
    */
   public String getInstanceName() {
     return config.getInstanceName();
   }
-
+  
   /**
    * @return zookeeper connection string
    */
   public String getZooKeepers() {
     return config.getZooKeepers();
   }
-
+  
   /**
    * Stops Accumulo and Zookeeper processes. If stop is not called, there is a shutdown hook that is setup to kill the processes. However its probably best to
    * call stop in a finally block as soon as possible.
-   *
-   * @throws IOException
-   * @throws InterruptedException
    */
   public void stop() throws IOException, InterruptedException {
     if (zooKeeperProcess != null)
@@ -400,29 +388,25 @@ public class MiniAccumuloCluster {
         tserver.destroy();
       }
     }
-
+    
     for (LogWriter lw : logWriters)
       lw.flush();
     zooKeeperProcess = null;
     masterProcess = null;
     tabletServerProcesses.clear();
   }
-
+  
   /**
    * @since 1.6.0
    */
   public MiniAccumuloConfig getConfig() {
     return config;
   }
-
+  
   /**
    * Utility method to get a connector to the MAC.
+   * 
    * @since 1.6.0
-   * @param user
-   * @param passwd
-   * @return Connector
-   * @throws AccumuloException
-   * @throws AccumuloSecurityException
    */
   public Connector getConnector(String user, String passwd) throws AccumuloException, AccumuloSecurityException {
     Instance instance = new ZooKeeperInstance(this.getInstanceName(), this.getZooKeepers());

http://git-wip-us.apache.org/repos/asf/accumulo/blob/db39c354/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloInstance.java
----------------------------------------------------------------------
diff --git a/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloInstance.java b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloInstance.java
new file mode 100644
index 0000000..540d7ae
--- /dev/null
+++ b/minicluster/src/main/java/org/apache/accumulo/minicluster/MiniAccumuloInstance.java
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+package org.apache.accumulo.minicluster;
+
+import java.io.File;
+import java.net.MalformedURLException;
+
+import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.client.ZooKeeperInstance;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.hadoop.conf.Configuration;
+
+/**
+ * 
+ */
+public class MiniAccumuloInstance extends ZooKeeperInstance {
+  
+  /**
+   * Construct an {@link Instance} entry point to Accumulo using a {@link MiniAccumuloCluster} directory
+   */
+  public MiniAccumuloInstance(String instanceName, File directory) {
+    super(instanceName, getZooKeepersFromDir(directory));
+  }
+  
+  private static String getZooKeepersFromDir(File directory) {
+    if (!directory.isDirectory())
+      throw new IllegalArgumentException("Not a directory " + directory.getPath());
+    File configFile = new File(new File(directory, "conf"), "accumulo-site.xml");
+    Configuration conf = new Configuration(false);
+    try {
+      conf.addResource(configFile.toURI().toURL());
+    } catch (MalformedURLException e) {
+      throw new IllegalStateException("Missing file: " + configFile.getPath());
+    }
+    return conf.get(Property.INSTANCE_ZK_HOST.getKey());
+  }
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/db39c354/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 0dc56a4..905e4e7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -83,6 +83,7 @@
     <module>test</module>
     <module>minicluster</module>
     <module>docs</module>
+    <module>maven-plugin</module>
   </modules>
   <scm>
     <connection>scm:svn:http://svn.apache.org/repos/asf/accumulo/trunk</connection>
@@ -297,6 +298,16 @@
         <version>${hadoop.version}</version>
       </dependency>
       <dependency>
+        <groupId>org.apache.maven</groupId>
+        <artifactId>maven-plugin-api</artifactId>
+        <version>${maven.min-version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.maven.plugin-tools</groupId>
+        <artifactId>maven-plugin-annotations</artifactId>
+        <version>3.2</version>
+      </dependency>
+      <dependency>
         <groupId>org.apache.thrift</groupId>
         <artifactId>libthrift</artifactId>
         <version>0.9.0</version>
@@ -307,6 +318,11 @@
         <version>${zookeeper.version}</version>
       </dependency>
       <dependency>
+        <groupId>org.codehaus.plexus</groupId>
+        <artifactId>plexus-utils</artifactId>
+        <version>3.0.10</version>
+      </dependency>
+      <dependency>
         <groupId>org.easymock</groupId>
         <artifactId>easymock</artifactId>
         <version>3.1</version>
@@ -571,6 +587,19 @@
                 </pluginExecution>
                 <pluginExecution>
                   <pluginExecutionFilter>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-invoker-plugin</artifactId>
+                    <versionRange>[1.7,)</versionRange>
+                    <goals>
+                      <goal>install</goal>
+                    </goals>
+                  </pluginExecutionFilter>
+                  <action>
+                    <ignore />
+                  </action>
+                </pluginExecution>
+                <pluginExecution>
+                  <pluginExecutionFilter>
                     <groupId>com.google.code.sortpom</groupId>
                     <artifactId>maven-sortpom-plugin</artifactId>
                     <versionRange>[2.1.0,)</versionRange>
@@ -630,18 +659,11 @@
             <id>run-integration-tests</id>
             <goals>
               <goal>integration-test</goal>
-            </goals>
-            <phase>integration-test</phase>
-          	<configuration>
-              <redirectTestOutputToFile>true</redirectTestOutputToFile>
-          	</configuration>
-          </execution>
-          <execution>
-            <id>verify-integration-tests</id>
-            <goals>
               <goal>verify</goal>
             </goals>
-            <phase>verify</phase>
+            <configuration>
+              <redirectTestOutputToFile>true</redirectTestOutputToFile>
+            </configuration>
           </execution>
         </executions>
       </plugin>
@@ -839,6 +861,7 @@
       <id>seal-jars</id>
       <properties>
         <sealJars>true</sealJars>
+        <skipITs>true</skipITs>
         <skipTests>true</skipTests>
       </properties>
     </profile>


Mime
View raw message