Promoted hyracks maven plugin to be a top level project
git-svn-id: https://hyracks.googlecode.com/svn/trunk@483 123451ca-8445-de46-9d55-352943316053
diff --git a/hyracks-maven-plugin/.classpath b/hyracks-maven-plugin/.classpath
new file mode 100644
index 0000000..1f3c1ff
--- /dev/null
+++ b/hyracks-maven-plugin/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/hyracks-maven-plugin/.project b/hyracks-maven-plugin/.project
new file mode 100644
index 0000000..0e5add5
--- /dev/null
+++ b/hyracks-maven-plugin/.project
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>hyracks-maven-plugin</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
diff --git a/hyracks-maven-plugin/.settings/org.eclipse.jdt.core.prefs b/hyracks-maven-plugin/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..52cdab7
--- /dev/null
+++ b/hyracks-maven-plugin/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,6 @@
+#Thu May 19 11:57:56 PDT 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/hyracks-maven-plugin/.settings/org.maven.ide.eclipse.prefs b/hyracks-maven-plugin/.settings/org.maven.ide.eclipse.prefs
new file mode 100644
index 0000000..bcc93a5
--- /dev/null
+++ b/hyracks-maven-plugin/.settings/org.maven.ide.eclipse.prefs
@@ -0,0 +1,9 @@
+#Thu May 19 11:57:56 PDT 2011
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1
diff --git a/hyracks-maven-plugin/pom.xml b/hyracks-maven-plugin/pom.xml
new file mode 100644
index 0000000..0972bca
--- /dev/null
+++ b/hyracks-maven-plugin/pom.xml
@@ -0,0 +1,36 @@
+<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>
+ <groupId>edu.uci.ics.hyracks</groupId>
+ <artifactId>hyracks-maven-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+ <version>0.1.6-SNAPSHOT</version>
+
+ <parent>
+ <groupId>edu.uci.ics.hyracks</groupId>
+ <artifactId>hyracks</artifactId>
+ <version>0.1.6-SNAPSHOT</version>
+ </parent>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.2.1</version>
+ <type>jar</type>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/AbstractHyracksCLIMojo.java b/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/AbstractHyracksCLIMojo.java
new file mode 100644
index 0000000..7f3faef
--- /dev/null
+++ b/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/AbstractHyracksCLIMojo.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2009-2010 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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 edu.uci.ics.hyracks.maven.plugin;
+
+import java.io.File;
+import java.io.PrintWriter;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+public abstract class AbstractHyracksCLIMojo extends AbstractHyracksMojo {
+ private static final String HYRACKS_CLI_SCRIPT = "bin" + File.separator + "hyrackscli";
+
+ /**
+ * @parameter
+ * @required
+ */
+ protected File hyracksCLIHome;
+
+ /**
+ * @parameter
+ * @required
+ */
+ private String ccHost;
+
+ /**
+ * @parameter
+ */
+ private int ccPort;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(createConnectCommand());
+ buffer.append('\n');
+ buffer.append(getCommands());
+ final Process proc = launch(new File(hyracksCLIHome, makeScriptName(HYRACKS_CLI_SCRIPT)), null, null);
+ try {
+ PrintWriter out = new PrintWriter(proc.getOutputStream());
+ out.println(buffer.toString());
+ out.close();
+ proc.waitFor();
+ } catch (Exception e) {
+ throw new MojoExecutionException(e.getMessage());
+ }
+ }
+
+ private String createConnectCommand() {
+ return "connect to \"" + ccHost + (ccPort == 0 ? "" : (":" + ccPort)) + "\";";
+ }
+
+ protected abstract String getCommands();
+}
\ No newline at end of file
diff --git a/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/AbstractHyracksMojo.java b/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/AbstractHyracksMojo.java
new file mode 100644
index 0000000..972f584
--- /dev/null
+++ b/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/AbstractHyracksMojo.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2009-2010 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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 edu.uci.ics.hyracks.maven.plugin;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+public abstract class AbstractHyracksMojo extends AbstractMojo {
+ protected Process launch(File command, String options, File workingDir) throws MojoExecutionException {
+ if (!command.isFile()) {
+ throw new MojoExecutionException(command.getAbsolutePath() + " is not an executable program");
+ }
+
+ getLog().info("Executing Hyracks command: " + command + " with args [" + options + "]");
+ String osName = System.getProperty("os.name");
+ try {
+ if (osName.startsWith("Windows")) {
+ return launchWindowsBatch(command, options);
+ } else {
+ return launchUnixScript(command, options, workingDir);
+ }
+ } catch (IOException e) {
+ throw new MojoExecutionException("Error executing command: " + command.getAbsolutePath(), e);
+ }
+ }
+
+ protected Process launchWindowsBatch(File command, String options) throws IOException {
+ String[] commandWithOptions = new String[] { "cmd.exe", "/C", command.getAbsolutePath() + " " + options };
+
+ Process proc = Runtime.getRuntime().exec(commandWithOptions);
+ dump(proc.getInputStream());
+ dump(proc.getErrorStream());
+ return proc;
+ }
+
+ protected Process launchUnixScript(File command, String options, File workingDir) throws IOException {
+ String[] optionsArray = new String[0];
+ if (options != null && !options.trim().isEmpty()) {
+ optionsArray = options.trim().split("\\s+");
+ }
+ String[] commandWithOptions = new String[optionsArray.length + 1];
+ commandWithOptions[0] = command.getAbsolutePath();
+ for (int i = 0; i < optionsArray.length; ++i) {
+ commandWithOptions[i + 1] = optionsArray[i];
+ }
+ Process proc = Runtime.getRuntime().exec(commandWithOptions, null,
+ workingDir == null ? new File(".") : workingDir);
+ dump(proc.getInputStream());
+ dump(proc.getErrorStream());
+ return proc;
+ }
+
+ protected void dump(final InputStream input) {
+ final int streamBufferSize = 1000;
+ final Reader in = new InputStreamReader(input);
+ new Thread(new Runnable() {
+ public void run() {
+ try {
+ char[] chars = new char[streamBufferSize];
+ int c;
+ while ((c = in.read(chars)) != -1) {
+ if (c > 0) {
+ System.out.print(String.valueOf(chars, 0, c));
+ }
+ }
+ } catch (IOException e) {
+ }
+ }
+ }).start();
+ }
+
+ protected String makeScriptName(String scriptName) {
+ String osName = System.getProperty("os.name");
+ String commandExt = osName.startsWith("Windows") ? ".bat" : "";
+ return scriptName + commandExt;
+ }
+}
\ No newline at end of file
diff --git a/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/AbstractHyracksServerMojo.java b/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/AbstractHyracksServerMojo.java
new file mode 100644
index 0000000..448ca22
--- /dev/null
+++ b/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/AbstractHyracksServerMojo.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2009-2010 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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 edu.uci.ics.hyracks.maven.plugin;
+
+import java.io.File;
+
+public abstract class AbstractHyracksServerMojo extends AbstractHyracksMojo {
+ /**
+ * @parameter
+ * @required
+ */
+ protected File hyracksServerHome;
+
+ /**
+ * @parameter
+ */
+ protected File workingDir;
+}
\ No newline at end of file
diff --git a/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/HyracksAppDeploymentMojo.java b/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/HyracksAppDeploymentMojo.java
new file mode 100644
index 0000000..76bbb5a
--- /dev/null
+++ b/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/HyracksAppDeploymentMojo.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2009-2010 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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 edu.uci.ics.hyracks.maven.plugin;
+
+import java.io.File;
+
+/**
+ * @goal deploy-app
+ */
+public class HyracksAppDeploymentMojo extends AbstractHyracksCLIMojo {
+ /**
+ * @parameter
+ * @required
+ */
+ private String appName;
+
+ /**
+ * @parameter
+ * @required
+ */
+ private File harFile;
+
+ @Override
+ protected String getCommands() {
+ return "create application " + appName + " \"" + harFile.getAbsolutePath() + "\";";
+ }
+}
\ No newline at end of file
diff --git a/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/HyracksCCStartMojo.java b/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/HyracksCCStartMojo.java
new file mode 100644
index 0000000..942b055
--- /dev/null
+++ b/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/HyracksCCStartMojo.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2009-2010 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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 edu.uci.ics.hyracks.maven.plugin;
+
+import java.io.File;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * @goal start-cc
+ */
+public class HyracksCCStartMojo extends AbstractHyracksServerMojo {
+ private static final String HYRACKS_CC_SCRIPT = "bin" + File.separator + "hyrackscc";
+
+ /**
+ * @parameter property = "port"
+ */
+ private int port;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ StringBuilder cmdLineBuffer = new StringBuilder();
+ if (port != 0) {
+ cmdLineBuffer.append("-port ").append(port);
+ }
+ String args = cmdLineBuffer.toString();
+ final Process proc = launch(new File(hyracksServerHome, makeScriptName(HYRACKS_CC_SCRIPT)), args, workingDir);
+ HyracksServiceRegistry.INSTANCE.addServiceProcess(proc);
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
diff --git a/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/HyracksNCStartMojo.java b/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/HyracksNCStartMojo.java
new file mode 100644
index 0000000..1206e08
--- /dev/null
+++ b/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/HyracksNCStartMojo.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2009-2010 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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 edu.uci.ics.hyracks.maven.plugin;
+
+import java.io.File;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * @goal start-nc
+ */
+public class HyracksNCStartMojo extends AbstractHyracksServerMojo {
+ private static final String HYRACKS_NC_SCRIPT = "bin" + File.separator + "hyracksnc";
+
+ /**
+ * @parameter
+ * @required
+ */
+ private String nodeId;
+
+ /**
+ * @parameter
+ * @required
+ */
+ private String ccHost;
+
+ /**
+ * @parameter
+ */
+ private int ccPort;
+
+ /**
+ * @parameter
+ * @required
+ */
+ private String dataIpAddress;
+
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ StringBuilder cmdLineBuffer = new StringBuilder();
+ cmdLineBuffer.append(" -cc-host ").append(ccHost);
+ cmdLineBuffer.append(" -data-ip-address ").append(dataIpAddress);
+ cmdLineBuffer.append(" -node-id ").append(nodeId);
+ if (ccPort != 0) {
+ cmdLineBuffer.append(" -cc-port ").append(ccPort);
+ }
+ String args = cmdLineBuffer.toString();
+ final Process proc = launch(new File(hyracksServerHome, makeScriptName(HYRACKS_NC_SCRIPT)), args, workingDir);
+ HyracksServiceRegistry.INSTANCE.addServiceProcess(proc);
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
diff --git a/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/HyracksServiceRegistry.java b/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/HyracksServiceRegistry.java
new file mode 100644
index 0000000..6ea5a64
--- /dev/null
+++ b/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/HyracksServiceRegistry.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2009-2010 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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 edu.uci.ics.hyracks.maven.plugin;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class HyracksServiceRegistry {
+ public static HyracksServiceRegistry INSTANCE = new HyracksServiceRegistry();
+
+ private final List<Process> serviceProcesses;
+
+ private HyracksServiceRegistry() {
+ serviceProcesses = new ArrayList<Process>();
+ Runtime.getRuntime().addShutdownHook(new Thread() {
+ @Override
+ public void run() {
+ destroyAll();
+ }
+ });
+ }
+
+ public synchronized void addServiceProcess(Process process) {
+ serviceProcesses.add(process);
+ }
+
+ public synchronized void destroyAll() {
+ for (Process p : serviceProcesses) {
+ try {
+ p.destroy();
+ } catch (Exception e) {
+ }
+ }
+ serviceProcesses.clear();
+ }
+}
\ No newline at end of file
diff --git a/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/HyracksStopServicesMojo.java b/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/HyracksStopServicesMojo.java
new file mode 100644
index 0000000..eaf40fc
--- /dev/null
+++ b/hyracks-maven-plugin/src/main/java/edu/uci/ics/hyracks/maven/plugin/HyracksStopServicesMojo.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2009-2010 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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 edu.uci.ics.hyracks.maven.plugin;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+/**
+ * @goal stop-services
+ */
+public class HyracksStopServicesMojo extends AbstractHyracksMojo {
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getLog().info("Stopping Hyracks Services");
+ HyracksServiceRegistry.INSTANCE.destroyAll();
+ }
+}
\ No newline at end of file