Issue 126: renamed to scriptbuilder

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2346 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-11-30 00:59:52 +00:00
parent 13d37f554d
commit 0823f73c0d
21 changed files with 76 additions and 71 deletions

View File

@ -1,27 +0,0 @@
@echo off
goto END_FUNCTIONS
:ABORT_SUB
echo Aborting: %EXCEPTION%.
exit /b 1
:SOURCE_ENV
set ENV_FILE=%1
shift
if not defined ENV_FILE (
set EXCEPTION=Internal error. Called SOURCE_ENV with no file param
exit /b 1
)
call %SETTINGS_FILE%
if errorlevel 1 (
set EXCEPTION=Please end your '%SETTINGS_FILE%' file with the command 'exit /b 0' to enable this script to detect syntax errors.
exit /b 1
)
exit /b 0
:END_FUNCTIONS
if exist "%APPENV_SETTINGS_FILE%" (
call :SOURCE_SF "%APPENV_SETTINGS_FILE%"
if errorlevel 1 goto ABORT_SUB
)

View File

@ -49,7 +49,7 @@
<module>vcloud</module> <module>vcloud</module>
<module>twitter</module> <module>twitter</module>
<module>rimuhosting</module> <module>rimuhosting</module>
<module>initbuilder</module> <module>scriptbuilder</module>
</modules> </modules>
<build> <build>
<plugins> <plugins>

View File

@ -29,10 +29,10 @@
<relativePath>../project/pom.xml</relativePath> <relativePath>../project/pom.xml</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>jclouds-initbuilder</artifactId> <artifactId>jclouds-scriptbuilder</artifactId>
<name>jclouds init builder</name> <name>jclouds script builder</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<description>creates init scripts that can be used to manage services</description> <description>creates scripts that can be used to manage services</description>
<properties> <properties>
<jclouds.test.listener></jclouds.test.listener> <jclouds.test.listener></jclouds.test.listener>
</properties> </properties>

View File

@ -21,15 +21,15 @@
* under the License. * under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.initbuilder; package org.jclouds.scriptbuilder;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map; import java.util.Map;
import org.jclouds.initbuilder.domain.OsFamily; import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.initbuilder.domain.ShellToken; import org.jclouds.scriptbuilder.domain.ShellToken;
import org.jclouds.initbuilder.util.Utils; import org.jclouds.scriptbuilder.util.Utils;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;

View File

@ -21,7 +21,7 @@
* under the License. * under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.initbuilder; package org.jclouds.scriptbuilder;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
@ -29,9 +29,9 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.jclouds.initbuilder.domain.OsFamily; import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.initbuilder.domain.ShellToken; import org.jclouds.scriptbuilder.domain.ShellToken;
import org.jclouds.initbuilder.util.Utils; import org.jclouds.scriptbuilder.util.Utils;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function; import com.google.common.base.Function;
@ -40,11 +40,11 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
/** /**
* Creates a start script. * Creates a shell script.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class InitBuilder { public class ScriptBuilder {
@VisibleForTesting @VisibleForTesting
Map<String, Map<String, String>> switchExec = Maps.newHashMap(); Map<String, Map<String, String>> switchExec = Maps.newHashMap();
@ -74,7 +74,7 @@ public class InitBuilder {
* - case statements, if the value of the variable matches a key, the corresponding * - case statements, if the value of the variable matches a key, the corresponding
* value will be invoked. * value will be invoked.
*/ */
public InitBuilder switchOn(String variable, Map<String, String> valueToActions) { public ScriptBuilder switchOn(String variable, Map<String, String> valueToActions) {
switchExec.put(checkNotNull(variable, "variable"), checkNotNull(valueToActions, switchExec.put(checkNotNull(variable, "variable"), checkNotNull(valueToActions,
"valueToActions")); "valueToActions"));
return this; return this;
@ -83,7 +83,7 @@ public class InitBuilder {
/** /**
* Unsets a variable to ensure it is set within the script. * Unsets a variable to ensure it is set within the script.
*/ */
public InitBuilder unsetEnvironmentVariable(String name) { public ScriptBuilder unsetEnvironmentVariable(String name) {
variablesToUnset.add(checkNotNull(name, "name")); variablesToUnset.add(checkNotNull(name, "name"));
return this; return this;
} }
@ -91,7 +91,7 @@ public class InitBuilder {
/** /**
* Exports a variable inside the script * Exports a variable inside the script
*/ */
public InitBuilder export(String name, String value) { public ScriptBuilder export(String name, String value) {
variables.put(checkNotNull(name, "name"), checkNotNull(value, "value")); variables.put(checkNotNull(name, "name"), checkNotNull(value, "value"));
return this; return this;
} }

View File

@ -21,7 +21,7 @@
* under the License. * under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.initbuilder.domain; package org.jclouds.scriptbuilder.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -21,7 +21,7 @@
* under the License. * under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.initbuilder.domain; package org.jclouds.scriptbuilder.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -21,7 +21,7 @@
* under the License. * under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.initbuilder.domain; package org.jclouds.scriptbuilder.domain;
/** /**
* Type of an Operating System. * Type of an Operating System.

View File

@ -21,7 +21,7 @@
* under the License. * under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.initbuilder.domain; package org.jclouds.scriptbuilder.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -21,7 +21,7 @@
* under the License. * under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.initbuilder.domain; package org.jclouds.scriptbuilder.domain;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;

View File

@ -21,7 +21,7 @@
* under the License. * under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.initbuilder.util; package org.jclouds.scriptbuilder.util;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -29,8 +29,8 @@ import java.util.Map.Entry;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.jclouds.initbuilder.domain.OsFamily; import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.initbuilder.domain.ShellToken; import org.jclouds.scriptbuilder.domain.ShellToken;
import com.google.common.base.CaseFormat; import com.google.common.base.CaseFormat;
import com.google.common.base.Function; import com.google.common.base.Function;

View File

@ -1,12 +1,13 @@
package org.jclouds.initbuilder; package org.jclouds.scriptbuilder;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import org.jclouds.initbuilder.domain.OsFamily; import org.jclouds.scriptbuilder.EnvBuilder;
import org.jclouds.initbuilder.domain.ShellToken; import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.scriptbuilder.domain.ShellToken;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;

View File

@ -1,12 +1,13 @@
package org.jclouds.initbuilder; package org.jclouds.scriptbuilder;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import org.jclouds.initbuilder.domain.OsFamily; import org.jclouds.scriptbuilder.ScriptBuilder;
import org.jclouds.initbuilder.domain.ShellToken; import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.scriptbuilder.domain.ShellToken;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
@ -15,13 +16,13 @@ import com.google.common.io.CharStreams;
import com.google.common.io.Resources; import com.google.common.io.Resources;
/** /**
* Tests possible uses of InitBuilder * Tests possible uses of ScriptBuilder
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class InitBuilderTest { public class ScriptBuilderTest {
InitBuilder testScriptBuilder = new InitBuilder().switchOn("1", ScriptBuilder testScriptBuilder = new ScriptBuilder().switchOn("1",
ImmutableMap.of("start", "echo started", "stop", "echo stopped")).export("javaHome", ImmutableMap.of("start", "echo started", "stop", "echo stopped")).export("javaHome",
"/apps/jdk1.6"); "/apps/jdk1.6");
@ -41,7 +42,7 @@ public class InitBuilderTest {
@Test @Test
public void testSwitchOn() { public void testSwitchOn() {
InitBuilder builder = new InitBuilder(); ScriptBuilder builder = new ScriptBuilder();
builder.switchOn("1", ImmutableMap.of("start", "echo started", "stop", "echo stopped")); builder.switchOn("1", ImmutableMap.of("start", "echo started", "stop", "echo stopped"));
assertEquals(builder.switchExec, ImmutableMap.of("1", ImmutableMap.of("start", assertEquals(builder.switchExec, ImmutableMap.of("1", ImmutableMap.of("start",
"echo started", "stop", "echo stopped"))); "echo started", "stop", "echo stopped")));
@ -49,13 +50,13 @@ public class InitBuilderTest {
@Test @Test
public void testNoSwitchOn() { public void testNoSwitchOn() {
InitBuilder builder = new InitBuilder(); ScriptBuilder builder = new ScriptBuilder();
assertEquals(builder.switchExec.size(), 0); assertEquals(builder.switchExec.size(), 0);
} }
@Test @Test
public void testExport() { public void testExport() {
InitBuilder builder = new InitBuilder(); ScriptBuilder builder = new ScriptBuilder();
builder.export("javaHome", "/apps/jdk1.6"); builder.export("javaHome", "/apps/jdk1.6");
assertEquals(builder.variables, ImmutableMap.of("javaHome", "/apps/jdk1.6")); assertEquals(builder.variables, ImmutableMap.of("javaHome", "/apps/jdk1.6"));
@ -63,13 +64,13 @@ public class InitBuilderTest {
@Test @Test
public void testNoExport() { public void testNoExport() {
InitBuilder builder = new InitBuilder(); ScriptBuilder builder = new ScriptBuilder();
assertEquals(builder.variables.size(), 0); assertEquals(builder.variables.size(), 0);
} }
@Test(expectedExceptions = NullPointerException.class) @Test(expectedExceptions = NullPointerException.class)
public void testExportNPE() { public void testExportNPE() {
new InitBuilder().export(null, null); new ScriptBuilder().export(null, null);
} }
} }

View File

@ -21,12 +21,14 @@
* under the License. * under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.initbuilder.domain; package org.jclouds.scriptbuilder.domain;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.util.Map; import java.util.Map;
import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.scriptbuilder.domain.ShellToken;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -34,7 +36,7 @@ import com.google.common.collect.ImmutableMap;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "initbuilder.ShellTokenTest") @Test(groups = "unit", testName = "scriptbuilder.ShellTokenTest")
public class ShellTokenTest { public class ShellTokenTest {
public void testTokenValueMapUNIX() { public void testTokenValueMapUNIX() {

View File

@ -21,13 +21,14 @@
* under the License. * under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.initbuilder.util; package org.jclouds.scriptbuilder.util;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import org.jclouds.initbuilder.domain.OsFamily; import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.scriptbuilder.util.Utils;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -36,7 +37,7 @@ import com.google.common.collect.ImmutableMap;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "initbuilder.UtilsTest") @Test(groups = "unit", testName = "scriptbuilder.UtilsTest")
public class UtilsTest { public class UtilsTest {
public void testReplaceTokens() throws UnsupportedEncodingException { public void testReplaceTokens() throws UnsupportedEncodingException {

View File

@ -0,0 +1,27 @@
@echo off
goto END_FUNCTIONS
:abortFunction
echo Aborting: %EXCEPTION%.
exit /b 1
:sourceEnv
set ENV_FILE=%1
shift
if not defined ENV_FILE (
set EXCEPTION=Internal error. Called sourceEnv with no file param
exit /b 1
)
call %ENV_FILE%
if errorlevel 1 (
set EXCEPTION=Please end your '%ENV_FILE%' file with the command 'exit /b 0' to enable this script to detect syntax errors.
exit /b 1
)
exit /b 0
:END_FUNCTIONS
if exist "%APPENV_SETTINGS_FILE%" (
call :sourceEnv "%APPENV_SETTINGS_FILE%"
if errorlevel 1 goto abortFunction
)