From f26a726db792bae0e5be8a6964530eacc9daa259 Mon Sep 17 00:00:00 2001 From: Ignasi Barrera Date: Wed, 3 Apr 2013 10:27:46 +0200 Subject: [PATCH] Enforce the use of builders in Ruby and Chef statements --- .../scriptbuilder/statements/chef/ChefSolo.java | 2 +- .../statements/chef/InstallChefGems.java | 2 +- .../scriptbuilder/statements/ruby/InstallRuby.java | 12 +++++++++++- .../statements/ruby/InstallRubyGems.java | 2 +- .../statements/ruby/InstallRubyTest.java | 10 +++++----- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/chef/ChefSolo.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/chef/ChefSolo.java index bcdc270bd8..d7ed950ec5 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/chef/ChefSolo.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/chef/ChefSolo.java @@ -271,7 +271,7 @@ public class ChefSolo implements Statement { private RunList runlist; private final InstallChefGems installChefGems; - public ChefSolo(Optional fileCachePath, Optional rolePath, Optional databagPath, + protected ChefSolo(Optional fileCachePath, Optional rolePath, Optional databagPath, Optional> cookbookPath, Optional cookbooksArchiveLocation, Optional jsonAttributes, Optional group, Optional interval, Optional logLevel, Optional logFile, Optional nodeName, Optional splay, diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/chef/InstallChefGems.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/chef/InstallChefGems.java index 5d259572d5..5daa907afc 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/chef/InstallChefGems.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/chef/InstallChefGems.java @@ -58,7 +58,7 @@ public class InstallChefGems implements Statement { private Optional version; - public InstallChefGems(Optional version) { + protected InstallChefGems(Optional version) { this.version = version; } diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/ruby/InstallRuby.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/ruby/InstallRuby.java index 896512601f..9b684f8acf 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/ruby/InstallRuby.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/ruby/InstallRuby.java @@ -30,7 +30,17 @@ import org.jclouds.scriptbuilder.domain.StatementList; */ public class InstallRuby extends StatementList { - public InstallRuby() { + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + public InstallRuby build() { + return new InstallRuby(); + } + } + + protected InstallRuby() { super(call("setupPublicCurl"), call("installRuby")); } diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/ruby/InstallRubyGems.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/ruby/InstallRubyGems.java index 1b4e14a62f..a36f1171ed 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/ruby/InstallRubyGems.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/ruby/InstallRubyGems.java @@ -99,7 +99,7 @@ public class InstallRubyGems implements Statement { private Optional updateSystemVersion; private boolean updateExistingGems; - public InstallRubyGems(Optional version, boolean updateSystem, Optional updateSystemVersion, + protected InstallRubyGems(Optional version, boolean updateSystem, Optional updateSystemVersion, boolean updateExistingGems) { this.version = checkNotNull(version, "version must be set"); this.updateSystem = updateSystem; diff --git a/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/ruby/InstallRubyTest.java b/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/ruby/InstallRubyTest.java index dc9407855b..a99eee0243 100644 --- a/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/ruby/InstallRubyTest.java +++ b/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/ruby/InstallRubyTest.java @@ -38,19 +38,19 @@ import com.google.common.io.Resources; @Test(groups = "unit", testName = "InstallRubyTest") public class InstallRubyTest { - @Test(expectedExceptions = UnsupportedOperationException.class, - expectedExceptionsMessageRegExp = "windows not yet implemented") + @Test(expectedExceptions = UnsupportedOperationException.class, expectedExceptionsMessageRegExp = "windows not yet implemented") public void installRubyInWindows() { - new InstallRuby().render(OsFamily.WINDOWS); + InstallRuby.builder().build().render(OsFamily.WINDOWS); } public void installRubyUnix() throws IOException { - assertEquals(new InstallRuby().render(OsFamily.UNIX), Resources.toString( + assertEquals(InstallRuby.builder().build().render(OsFamily.UNIX), Resources.toString( Resources.getResource("test_install_ruby." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8)); } public void installRubyUnixInScriptBuilderSourcesSetupPublicCurl() throws IOException { - assertEquals(InitScript.builder().name("install_ruby").run(new InstallRuby()).build().render(OsFamily.UNIX), + assertEquals( + InitScript.builder().name("install_ruby").run(InstallRuby.builder().build()).build().render(OsFamily.UNIX), Resources.toString( Resources.getResource("test_install_ruby_scriptbuilder." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8));