Skip to content

Commit

Permalink
Merge pull request #17 from sanelson2000/master
Browse files Browse the repository at this point in the history
Add option to use bundle exec
  • Loading branch information
olivierdagenais committed Mar 13, 2014
2 parents f5c57ee + dfcbb88 commit 247f3ea
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/main/java/hudson/plugins/rake/Rake.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ public class Rake extends Builder {
private final String rakeWorkingDir;
private final String tasks;
private final boolean silent;
private final boolean bundleExec;

@DataBoundConstructor
public Rake(String rakeInstallation, String rakeFile, String tasks, String rakeLibDir, String rakeWorkingDir, boolean silent) {
public Rake(String rakeInstallation, String rakeFile, String tasks, String rakeLibDir, String rakeWorkingDir, boolean silent, boolean bundleExec) {
this.rakeInstallation = rakeInstallation;
this.rakeFile = rakeFile;
this.tasks = tasks;
this.rakeLibDir = rakeLibDir;
this.rakeWorkingDir = rakeWorkingDir;
this.silent = silent;
this.bundleExec = bundleExec;
}

private RubyInstallation getRake() {
Expand Down Expand Up @@ -100,14 +102,21 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
}

if (rake != null) {
File exec = rake.getExecutable();
File exec;
if (bundleExec) {
exec = rake.getBundleExecutable();
} else {
exec = rake.getExecutable();
}
if(!exec.exists()) {
listener.fatalError(exec + " doesn't exist");
return false;
}
args.add(exec.getPath());
} else {
String executable = lastBuiltLauncher.isUnix()?"rake":"rake.bat";
String fileExtension = lastBuiltLauncher.isUnix()?"":".bat";
String executable = bundleExec?"bundle":"rake";
executable += fileExtension;
// search PATH to build an absolute path to the executable,
// to work around a bug in Java 7u21 - 7u25
// "JDK-8016721 : (process) Behavior of %~dp0 in .cmd and .bat scripts has changed"
Expand All @@ -125,6 +134,9 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
args.add(executable);
}

if (bundleExec) {
args.add("exec", "rake");
}
if (rakeFile != null && rakeFile.length() > 0) {
args.add("--rakefile", rakeFile);
}
Expand Down Expand Up @@ -201,6 +213,10 @@ public boolean isSilent() {
return silent;
}

public boolean isBundleExec() {
return bundleExec;
}

public String getRakeWorkingDir() {
return rakeWorkingDir;
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/hudson/plugins/rake/RubyInstallation.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public File getExecutable() {
Util.getExecutable(getPath());
}

public File getBundleExecutable() {
return getGemHome() != null ? Util.getBundleExecutable(getPath(), getGemHome(), getGemPath()) :
Util.getBundleExecutable(getPath());
}

public File getCanonicalExecutable() throws IOException {
return Util.getExecutable(getPath()).getCanonicalFile();
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/hudson/plugins/rake/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,29 @@ public static File getExecutable(String path, String gemHome, String gemPath) {
return new File(gemHome, "bin/" + execName());
}

public static File getBundleExecutable(String path) {
File parent = isJruby(path) || isCustom(path, execName())? new File(path) : new File(path).getParentFile().getParentFile();
return new File(parent, "bin/" + bundleExecName());
}

public static File getBundleExecutable(String path, String gemHome, String gemPath) {
for (String candidate : gemPath.split(File.pathSeparator)) {
File bin = new File(candidate, "bin/" + bundleExecName());
if (bin.exists()) {
return bin;
}
}
return new File(gemHome, "bin/" + bundleExecName());
}

public static String execName() {
return isWindows() ? "rake.bat" : "rake";
}

public static String bundleExecName() {
return isWindows() ? "bundle.bat" : "bundle";
}

public static boolean isWindows() {
String name = System.getProperty("os.name");
return name != null?name.contains("Windows") : File.separatorChar == '\\';
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/hudson/plugins/rake/Rake/config.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<f:entry title="Tasks" description=" Specify Rake task(s) to run.">
<f:expandableTextbox name="rake.tasks" value="${instance.tasks}" />
</f:entry>
<f:entry title="bundle exec" description="If your project uses Bundler gem requirements manager, this option will allow you to launch rake tasks using 'bundle exec' command.">
<f:checkbox name="rake.bundleExec" checked="${instance.bundleExec}"/>
</f:entry>
<f:advanced>
<f:entry title="Rake file" description="Specify the rake file path, by default it's './Rakefile'">
<f:textbox name="rake.rakeFile" value="${instance.rakeFile}"/>
Expand Down

0 comments on commit 247f3ea

Please sign in to comment.