You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whirr.apache.org by to...@apache.org on 2010/09/30 01:17:02 UTC
svn commit: r1002888 - in /incubator/whirr/trunk: ./ cli/
cli/src/main/java/org/apache/whirr/cli/
cli/src/main/java/org/apache/whirr/cli/command/ cli/src/main/resources/
cli/src/test/java/org/apache/whirr/cli/command/
Author: tomwhite
Date: Wed Sep 29 23:17:01 2010
New Revision: 1002888
URL: http://svn.apache.org/viewvc?rev=1002888&view=rev
Log:
WHIRR-105. Add version command to the CLI.
Added:
incubator/whirr/trunk/cli/src/main/java/org/apache/whirr/cli/command/VersionCommand.java (with props)
incubator/whirr/trunk/cli/src/main/resources/
incubator/whirr/trunk/cli/src/main/resources/version-banner.txt (with props)
incubator/whirr/trunk/cli/src/test/java/org/apache/whirr/cli/command/VersionCommandTest.java (with props)
Modified:
incubator/whirr/trunk/CHANGES.txt
incubator/whirr/trunk/cli/pom.xml
incubator/whirr/trunk/cli/src/main/java/org/apache/whirr/cli/Main.java
Modified: incubator/whirr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/CHANGES.txt?rev=1002888&r1=1002887&r2=1002888&view=diff
==============================================================================
--- incubator/whirr/trunk/CHANGES.txt (original)
+++ incubator/whirr/trunk/CHANGES.txt Wed Sep 29 23:17:01 2010
@@ -16,6 +16,8 @@ Trunk (unreleased changes)
WHIRR-103. Add more to .gitignore. (phunt via tomwhite)
+ WHIRR-105. Add version command to the CLI. (tomwhite)
+
BUG FIXES
WHIRR-93. Fail on checkstyle violation. (tomwhite)
Modified: incubator/whirr/trunk/cli/pom.xml
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/cli/pom.xml?rev=1002888&r1=1002887&r2=1002888&view=diff
==============================================================================
--- incubator/whirr/trunk/cli/pom.xml (original)
+++ incubator/whirr/trunk/cli/pom.xml Wed Sep 29 23:17:01 2010
@@ -96,6 +96,12 @@
</dependency>
</dependencies>
<build>
+ <resources>
+ <resource>
+ <directory>${project.basedir}/src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Modified: incubator/whirr/trunk/cli/src/main/java/org/apache/whirr/cli/Main.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/cli/src/main/java/org/apache/whirr/cli/Main.java?rev=1002888&r1=1002887&r2=1002888&view=diff
==============================================================================
--- incubator/whirr/trunk/cli/src/main/java/org/apache/whirr/cli/Main.java (original)
+++ incubator/whirr/trunk/cli/src/main/java/org/apache/whirr/cli/Main.java Wed Sep 29 23:17:01 2010
@@ -29,6 +29,7 @@ import java.util.Map;
import org.apache.whirr.cli.command.DestroyClusterCommand;
import org.apache.whirr.cli.command.LaunchClusterCommand;
+import org.apache.whirr.cli.command.VersionCommand;
/**
* The entry point for the Whirr CLI.
@@ -63,6 +64,7 @@ public class Main {
public static void main(String... args) throws Exception {
Main main = new Main(
+ new VersionCommand(),
new LaunchClusterCommand(),
new DestroyClusterCommand()
);
Added: incubator/whirr/trunk/cli/src/main/java/org/apache/whirr/cli/command/VersionCommand.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/cli/src/main/java/org/apache/whirr/cli/command/VersionCommand.java?rev=1002888&view=auto
==============================================================================
--- incubator/whirr/trunk/cli/src/main/java/org/apache/whirr/cli/command/VersionCommand.java (added)
+++ incubator/whirr/trunk/cli/src/main/java/org/apache/whirr/cli/command/VersionCommand.java Wed Sep 29 23:17:01 2010
@@ -0,0 +1,46 @@
+/**
+ * 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.whirr.cli.command;
+
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.util.List;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.whirr.cli.Command;
+
+public class VersionCommand extends Command {
+
+ public VersionCommand() {
+ super("version", "Print the version number and exit.");
+ }
+
+ @Override
+ public int run(InputStream in, PrintStream out, PrintStream err,
+ List<String> args) throws Exception {
+ InputStream input = getClass().getResourceAsStream("/version-banner.txt");
+ if (input == null) {
+ err.printf("Cannot determine version number\n");
+ return -1;
+ }
+ out.write(IOUtils.toByteArray(input));
+ return 0;
+ }
+
+}
Propchange: incubator/whirr/trunk/cli/src/main/java/org/apache/whirr/cli/command/VersionCommand.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/whirr/trunk/cli/src/main/resources/version-banner.txt
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/cli/src/main/resources/version-banner.txt?rev=1002888&view=auto
==============================================================================
--- incubator/whirr/trunk/cli/src/main/resources/version-banner.txt (added)
+++ incubator/whirr/trunk/cli/src/main/resources/version-banner.txt Wed Sep 29 23:17:01 2010
@@ -0,0 +1 @@
+Apache Whirr ${version}
Propchange: incubator/whirr/trunk/cli/src/main/resources/version-banner.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/whirr/trunk/cli/src/test/java/org/apache/whirr/cli/command/VersionCommandTest.java
URL: http://svn.apache.org/viewvc/incubator/whirr/trunk/cli/src/test/java/org/apache/whirr/cli/command/VersionCommandTest.java?rev=1002888&view=auto
==============================================================================
--- incubator/whirr/trunk/cli/src/test/java/org/apache/whirr/cli/command/VersionCommandTest.java (added)
+++ incubator/whirr/trunk/cli/src/test/java/org/apache/whirr/cli/command/VersionCommandTest.java Wed Sep 29 23:17:01 2010
@@ -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.whirr.cli.command;
+
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.Assert.assertThat;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+import java.util.Collections;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class VersionCommandTest {
+
+ private ByteArrayOutputStream outBytes;
+ private PrintStream out;
+
+ @Before
+ public void setUp() {
+ outBytes = new ByteArrayOutputStream();
+ out = new PrintStream(outBytes);
+ }
+
+ @Test
+ public void testOverrides() throws Exception {
+ VersionCommand command = new VersionCommand();
+ int rc = command.run(null, out, null, Collections.<String>emptyList());
+ assertThat(rc, is(0));
+ assertThat(outBytes.toString(), startsWith("Apache Whirr "));
+ }
+
+}
Propchange: incubator/whirr/trunk/cli/src/test/java/org/apache/whirr/cli/command/VersionCommandTest.java
------------------------------------------------------------------------------
svn:eol-style = native