Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix using global gemset's Rake gem #4

Merged
merged 4 commits into from
Mar 25, 2011
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/hudson/plugins/rake/Rake.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,15 @@ public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListene
try {
EnvVars env = build.getEnvironment(listener);
if (rake != null) {
System.out.println("Rake GEM HOME: "+ rake.getGemHome());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ben could you remove all these logging lines?

if (rake.getGemHome() != null) {
env.put("GEM_HOME", rake.getGemHome());
}
System.out.println("Rake GEM PATH: "+ rake.getGemPath());
if (rake.getGemPath() != null) {
env.put("GEM_PATH", rake.getGemPath());
}
System.err.println("Rake Bin PATH: "+ rake.getBinPath());
if (rake.getBinPath() != null) {
StringBuilder builder = new StringBuilder();
String path = env.get("PATH");
Expand Down
59 changes: 44 additions & 15 deletions src/main/java/hudson/plugins/rake/RvmUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,51 @@ public static RubyInstallation[] getRvmRubies(Rvm rvm) {
FilePath global = getGlobal(name, gemsPath);

for (FilePath gemCandidate : gems) {
FilePath specifications = getSpecifications(gemCandidate, global);
String newpath = "";
FilePath specifications = getSpecifications(gemCandidate);
if (specifications != null) {
Collection<FilePath> specs = specifications.list(rakeFilter);
if (specs == null || specs.size() == 0) {
// We did not find the rake gem in this gemset's bin directory; check in global
specifications = getSpecifications(global);
if (specifications != null) {
specs = specifications.list(rakeFilter);
if (specs == null || specs.size() == 0) {
// Rake not found in global either; this gemset is unusable
continue;
} else {
// Rake was found in the global gemset; include it in the path
newpath = global.getRemote().concat(File.separator).concat("bin");
}
}
}
}

if (specs != null && specs.size() > 0) {
String path = new File(candidate.toURI()).getCanonicalPath();
RubyInstallation ruby = new RubyInstallation(gemCandidate.getName(), path);
String path = new File(candidate.toURI()).getCanonicalPath();
RubyInstallation ruby = new RubyInstallation(gemCandidate.getName(), path);

ruby.setGemHome(new File(gemCandidate.toURI()).getCanonicalPath());
ruby.setGemPath(buildGemPath(ruby.getGemHome(), global, gems));
ruby.setBinPath(new File(ruby.getGemHome(), "bin").getCanonicalPath());
ruby.setGemHome(new File(gemCandidate.toURI()).getCanonicalPath());
ruby.setGemPath(buildGemPath(ruby.getGemHome(), global, gems));

rubies.add(ruby);
}
// Add RVM Ruby path
if (newpath.length() > 0) {
newpath = newpath.concat(File.pathSeparator);
}
newpath = newpath.concat(rubiesPath.getRemote() + File.separator + name + File.separator + "bin");

// Add GEM bin directory to path
newpath = newpath.concat(File.pathSeparator).concat(new File(ruby.getGemHome(), "bin").getCanonicalPath());

// Create or append the calculated path for this Ruby install
path = ruby.getBinPath();
if (path == null || path.length() == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this condition is not actually needed because you never set the bin path before.

path = newpath;
} else {
path = path.concat(File.pathSeparator).concat(newpath);
}
ruby.setBinPath(path);

rubies.add(ruby);
}

}
Expand Down Expand Up @@ -93,9 +123,11 @@ private static String buildGemPath(String currentGem, FilePath global, Collectio
}

for (String canonical : paths) {
path.append(File.pathSeparator).append(canonical);
if (path.length() > 0) {
path.append(File.pathSeparator);
}
path.append(canonical);
}

return path.toString();
}

Expand All @@ -110,14 +142,11 @@ private static FilePath getGlobal(String name, FilePath gemsPath)
return global;
}

private static FilePath getSpecifications(FilePath candidate, FilePath global)
private static FilePath getSpecifications(FilePath candidate)
throws InterruptedException, IOException {
FilePath specification = candidate.child("specifications");
if (specification.exists()) {
return specification;
} else if (global != null && global.exists() &&
global.child("specifications").exists()) {
return global.child("specifications");
}
return null;
}
Expand Down