提交 c297d681 编写于 作者: K kohsuke

improved error diagnosis.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3982 71c3de6d-444a-0410-be80-ed276b4c234a
上级 efd2416f
...@@ -292,8 +292,18 @@ public class MavenBuild extends AbstractBuild<MavenModule,MavenBuild> { ...@@ -292,8 +292,18 @@ public class MavenBuild extends AbstractBuild<MavenModule,MavenBuild> {
Map<String, String> vars = getEnvVars(); Map<String, String> vars = getEnvVars();
if(debug) if(debug)
listener.getLogger().println("Using env variables: "+vars); listener.getLogger().println("Using env variables: "+vars);
return launcher.launchChannel(buildMavenCmdLine(listener).toCommandArray(), try {
out, null, vars); return launcher.launchChannel(buildMavenCmdLine(listener).toCommandArray(),
out, null, vars);
} catch (IOException e) {
if(e.getMessage().contains("java: not found")) {
// diagnose issue #659
JDK jdk = getParent().getParent().getJDK();
if(jdk==null)
throw new IOException2(getParent().getParent().getDisplayName()+" is not configured with a JDK, but your PATH doesn't include Java",e);
}
throw e;
}
} }
/** /**
......
...@@ -1625,6 +1625,30 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node ...@@ -1625,6 +1625,30 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node
}.process(); }.process();
} }
/**
* If the user chose the default JDK, make sure we got 'java' in PATH.
*/
public void doDefaultJDKCheck( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
new FormFieldValidator(req,rsp,true) {
public void check() throws IOException, ServletException {
String v = request.getParameter("value");
if(!v.equals("(Default)"))
// assume the user configured named ones properly in system config ---
// or else system config should have reported form field validation errors.
ok();
else {
// default JDK selected. Does such java really exist?
if(JDK.isDefaultJDKValid(Hudson.this))
ok();
else
errorWithMarkup(
"java is not in your PATH. Maybe you need to" +
"<a href='"+request.getContextPath()+"/configure'>configure JDKs</a>?");
}
}
}.process();
}
/** /**
* Checks if the top-level item with the given name exists. * Checks if the top-level item with the given name exists.
*/ */
......
package hudson.model; package hudson.model;
import hudson.util.StreamTaskListener;
import hudson.util.NullStream;
import hudson.Launcher;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.Map; import java.util.Map;
/** /**
...@@ -68,4 +73,23 @@ public final class JDK { ...@@ -68,4 +73,23 @@ public final class JDK {
if(!env.containsKey("HUDSON_HOME")) if(!env.containsKey("HUDSON_HOME"))
env.put("HUDSON_HOME", Hudson.getInstance().getRootDir().getPath() ); env.put("HUDSON_HOME", Hudson.getInstance().getRootDir().getPath() );
} }
/**
* Checks if "java" is in PATH on the given node.
*
* <p>
* If it's not, then the user must specify a configured JDK,
* so this is often useful for form field validation.
*/
public static boolean isDefaultJDKValid(Node n) {
try {
TaskListener listener = new StreamTaskListener(new NullStream());
Launcher launcher = n.createLauncher(listener);
return launcher.launch("java -fullversion",new String[0],listener.getLogger(),null).join()==0;
} catch (IOException e) {
return false;
} catch (InterruptedException e) {
return false;
}
}
} }
...@@ -5,17 +5,24 @@ ...@@ -5,17 +5,24 @@
<p:config-disableBuild/> <p:config-disableBuild/>
<j:set var="jdks" value="${app.JDKs}" /> <j:set var="jdks" value="${app.JDKs}" />
<j:if test="${!empty(jdks)}"> <j:choose>
<f:entry title="JDK" <j:when test="${!empty(jdks)}">
description="JDK to be used for this project"> <f:entry title="JDK"
<select class="setting-input" name="jdk"> description="JDK to be used for this project">
<option>(Default)</option> <select class="setting-input validated" name="jdk" checkUrl="'${rootURL}/defaultJDKCheck?value='+this.value">
<j:forEach var="inst" items="${jdks}"> <option>(Default)</option>
<f:option selected="${inst.name==it.JDK.name}">${inst.name}</f:option> <j:forEach var="inst" items="${jdks}">
</j:forEach> <f:option selected="${inst.name==it.JDK.name}">${inst.name}</f:option>
</select> </j:forEach>
</f:entry> </select>
</j:if> </f:entry>
</j:when>
<j:otherwise>
<f:entry>
<input type="hidden" value="(Default)" class="validated" checkUrl="'${rootURL}/defaultJDKCheck?value='+this.value" />
</f:entry>
</j:otherwise>
</j:choose>
<!-- master/slave --> <!-- master/slave -->
<j:if test="${!empty(app.slaves)}"> <j:if test="${!empty(app.slaves)}">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册