Skip to content

Commit

Permalink
[JENKINS-11877] Improve error message when hg cannot be found
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmc24 committed Dec 4, 2011
1 parent f06a86a commit 2fff702
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions src/main/java/hudson/plugins/mercurial/MercurialSCM.java
@@ -1,6 +1,7 @@
package hudson.plugins.mercurial;

import static java.util.logging.Level.FINE;
import hudson.AbortException;
import hudson.EnvVars;
import hudson.Extension;
import hudson.FilePath;
Expand Down Expand Up @@ -264,6 +265,13 @@ protected PollingResult compareRemoteRevisionWith(AbstractProject<?, ?> project,

MercurialTagAction cur = parsePollingLogOutput(baos, baseline, changedFileNames);
return new PollingResult(baseline,cur,computeDegreeOfChanges(changedFileNames,output));
} catch(IOException e) {
if (causedByMissingHg(e)) {
listener.error("Failed to compare with remote repository because hg could not be found;" +
" check that you've properly configured your Mercurial installation");
throw new AbortException("Failed to compare with remote repository");
}
throw new IOException("Failed to compare with remote repository", e);
} finally {
tmpFile.delete();
}
Expand Down Expand Up @@ -375,8 +383,18 @@ public boolean checkout(AbstractBuild<?,?> build, Launcher launcher, FilePath wo
final boolean jobShouldUseSharing = mercurialInstallation != null && mercurialInstallation.isUseSharing();

FilePath repository = workspace2Repo(workspace);
boolean canReuseExistingWorkspace =
canReuseWorkspace(repository, jobShouldUseSharing, build, launcher, listener);
boolean canReuseExistingWorkspace;
try {
canReuseExistingWorkspace = canReuseWorkspace(repository, jobShouldUseSharing, build, launcher, listener);
} catch(IOException e) {
if (causedByMissingHg(e)) {
listener.error("Failed to determine whether workspace can be reused because hg could not be found;" +
" check that you've properly configured your Mercurial installation");
} else {
e.printStackTrace(listener.error("Failed to determine whether workspace can be reused"));
}
return false;
}

boolean success;
if (canReuseExistingWorkspace) {
Expand Down Expand Up @@ -502,8 +520,12 @@ private boolean update(AbstractBuild<?, ?> build, Launcher launcher, FilePath re
try {
pull(launcher, repository, listener, new PrintStream(new NullOutputStream()), Computer.currentComputer().getNode(), getBranch(env));
} catch (IOException e) {
listener.error("Failed to pull");
e.printStackTrace(listener.getLogger());
if (causedByMissingHg(e)) {
listener.error("Failed to pull because hg could not be found;" +
" check that you've properly configured your Mercurial installation");
} else {
e.printStackTrace(listener.error("Failed to pull"));
}
return false;
}

Expand Down Expand Up @@ -575,7 +597,12 @@ private boolean clone(AbstractBuild<?,?> build, Launcher launcher, FilePath repo
return false;
}
} catch (IOException e) {
e.printStackTrace(listener.error("Failed to clone "+source));
if (causedByMissingHg(e)) {
listener.error("Failed to clone " + source + " because hg could not be found;" +
" check that you've properly configured your Mercurial installation");
} else {
e.printStackTrace(listener.error("Failed to clone "+source));
}
return false;
}

Expand Down Expand Up @@ -629,6 +656,11 @@ public String getModules() {
return modules;
}

private boolean causedByMissingHg(IOException e) {
String message = e.getMessage();
return message.startsWith("Cannot run program") && message.endsWith("No such file or directory");
}

static boolean CACHE_LOCAL_REPOS = false;
private @CheckForNull PossiblyCachedRepo cachedSource(Node node, Launcher launcher, TaskListener listener, boolean fromPolling) {
if (!CACHE_LOCAL_REPOS && source.matches("(file:|[/\\\\]).+")) {
Expand Down

0 comments on commit 2fff702

Please sign in to comment.