提交 b72b7af3 编写于 作者: K kohsuke

something terrible must have happend between 1.78 and 1.79, as a lot of...

something terrible must have happend between 1.78 and 1.79, as a lot of changes have been apparently lost.
I'm resurrecting them.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3855 71c3de6d-444a-0410-be80-ed276b4c234a
上级 bf918224
...@@ -4,6 +4,7 @@ import hudson.FilePath; ...@@ -4,6 +4,7 @@ import hudson.FilePath;
import hudson.FilePath.FileCallable; import hudson.FilePath.FileCallable;
import hudson.Launcher; import hudson.Launcher;
import hudson.Util; import hudson.Util;
import hudson.triggers.SCMTrigger;
import hudson.model.AbstractBuild; import hudson.model.AbstractBuild;
import hudson.model.AbstractProject; import hudson.model.AbstractProject;
import hudson.model.BuildListener; import hudson.model.BuildListener;
...@@ -32,6 +33,7 @@ import org.tmatesoft.svn.core.auth.SVNAuthentication; ...@@ -32,6 +33,7 @@ import org.tmatesoft.svn.core.auth.SVNAuthentication;
import org.tmatesoft.svn.core.auth.SVNPasswordAuthentication; import org.tmatesoft.svn.core.auth.SVNPasswordAuthentication;
import org.tmatesoft.svn.core.auth.SVNSSHAuthentication; import org.tmatesoft.svn.core.auth.SVNSSHAuthentication;
import org.tmatesoft.svn.core.auth.SVNSSLAuthentication; import org.tmatesoft.svn.core.auth.SVNSSLAuthentication;
import org.tmatesoft.svn.core.auth.SVNUserNameAuthentication;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory; import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory; import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl; import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
...@@ -162,10 +164,35 @@ public class SubversionSCM extends SCM implements Serializable { ...@@ -162,10 +164,35 @@ public class SubversionSCM extends SCM implements Serializable {
return username; return username;
} }
@Override
public SubversionRepositoryBrowser getBrowser() { public SubversionRepositoryBrowser getBrowser() {
return browser; return browser;
} }
/**
* Sets the <tt>SVN_REVISION</tt> environment variable during the build.
*/
@Override
public void buildEnvVars(AbstractBuild build, Map<String, String> env) {
super.buildEnvVars(build, env);
try {
Map<String,Long> revisions = parseRevisionFile(build);
if(locations.length==1) {
Long rev = revisions.get(locations[0].remote);
if(rev!=null)
env.put("SVN_REVISION",rev.toString());
}
// it's not clear what to do if there are more than one modules.
// if we always return locations[0].remote, it'll be difficult
// to change this later (to something more sensible, such as
// choosing the "root module" or whatever), so let's not set
// anything for now.
} catch (IOException e) {
// ignore this error
}
}
/** /**
* Called after checkout/update has finished to compute the changelog. * Called after checkout/update has finished to compute the changelog.
*/ */
...@@ -192,6 +219,12 @@ public class SubversionSCM extends SCM implements Serializable { ...@@ -192,6 +219,12 @@ public class SubversionSCM extends SCM implements Serializable {
} }
/**
* Reads the revision file of the specified build.
*
* @return
* map from {@link SvnInfo#url Subversion URL} to its revision.
*/
/*package*/ static Map<String,Long> parseRevisionFile(AbstractBuild build) throws IOException { /*package*/ static Map<String,Long> parseRevisionFile(AbstractBuild build) throws IOException {
Map<String,Long> revisions = new HashMap<String,Long>(); // module -> revision Map<String,Long> revisions = new HashMap<String,Long>(); // module -> revision
{// read the revision file of the last build {// read the revision file of the last build
...@@ -201,17 +234,21 @@ public class SubversionSCM extends SCM implements Serializable { ...@@ -201,17 +234,21 @@ public class SubversionSCM extends SCM implements Serializable {
return revisions; return revisions;
BufferedReader br = new BufferedReader(new FileReader(file)); BufferedReader br = new BufferedReader(new FileReader(file));
String line; try {
while((line=br.readLine())!=null) { String line;
int index = line.lastIndexOf('/'); while((line=br.readLine())!=null) {
if(index<0) { int index = line.lastIndexOf('/');
continue; // invalid line? if(index<0) {
} continue; // invalid line?
try { }
revisions.put(line.substring(0,index), Long.parseLong(line.substring(index+1))); try {
} catch (NumberFormatException e) { revisions.put(line.substring(0,index), Long.parseLong(line.substring(index+1)));
// perhaps a corrupted line. ignore } catch (NumberFormatException e) {
// perhaps a corrupted line. ignore
}
} }
} finally {
br.close();
} }
} }
...@@ -305,6 +342,10 @@ public class SubversionSCM extends SCM implements Serializable { ...@@ -305,6 +342,10 @@ public class SubversionSCM extends SCM implements Serializable {
} catch (SVNException e) { } catch (SVNException e) {
e.printStackTrace(listener.error("Failed to update "+l.remote)); e.printStackTrace(listener.error("Failed to update "+l.remote));
// trouble-shooting probe for #591
if(e.getErrorMessage().getErrorCode()==SVNErrorCode.WC_NOT_LOCKED) {
listener.getLogger().println("Polled jobs are "+SCMTrigger.DESCRIPTOR.getItemsBeingPolled());
}
return null; return null;
} }
} }
...@@ -351,8 +392,8 @@ public class SubversionSCM extends SCM implements Serializable { ...@@ -351,8 +392,8 @@ public class SubversionSCM extends SCM implements Serializable {
/** /**
* Decoded repository URL. * Decoded repository URL.
*/ */
final String url; public final String url;
final long revision; public final long revision;
public SvnInfo(String url, long revision) { public SvnInfo(String url, long revision) {
this.url = url; this.url = url;
...@@ -368,16 +409,35 @@ public class SubversionSCM extends SCM implements Serializable { ...@@ -368,16 +409,35 @@ public class SubversionSCM extends SCM implements Serializable {
} }
public int compareTo(SvnInfo that) { public int compareTo(SvnInfo that) {
int d = this.url.compareTo(that.url); int r = this.url.compareTo(that.url);
if(d!=0) return d; if(r!=0) return r;
long e = this.revision-that.revision;
if(e<0) return -1; if(this.revision<that.revision) return -1;
if(e>0) return 1; if(this.revision>that.revision) return +1;
return 0; return 0;
} }
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SvnInfo svnInfo = (SvnInfo) o;
if (revision != svnInfo.revision) return false;
if (!url.equals(svnInfo.url)) return false;
return true;
}
public int hashCode() {
int result;
result = url.hashCode();
result = 31 * result + (int) (revision ^ (revision >>> 32));
return result;
}
public String toString() { public String toString() {
return url+" rev."+revision; return String.format("%s (rev.%s)",url,revision);
} }
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -721,7 +781,14 @@ public class SubversionSCM extends SCM implements Serializable { ...@@ -721,7 +781,14 @@ public class SubversionSCM extends SCM implements Serializable {
public SVNAuthentication requestClientAuthentication(String kind, SVNURL url, String realm, SVNErrorMessage errorMessage, SVNAuthentication previousAuth, boolean authMayBeStored) { public SVNAuthentication requestClientAuthentication(String kind, SVNURL url, String realm, SVNErrorMessage errorMessage, SVNAuthentication previousAuth, boolean authMayBeStored) {
Credential cred = source.getCredential(realm); Credential cred = source.getCredential(realm);
LOGGER.fine(String.format("requestClientAuthentication(%s,%s,%s)=>%s",kind,url,realm,cred)); LOGGER.fine(String.format("requestClientAuthentication(%s,%s,%s)=>%s",kind,url,realm,cred));
if(cred==null) return null; if(cred==null) {
// this happens with file:// URL. The base class does this, too.
if (ISVNAuthenticationManager.USERNAME.equals(kind))
// user auth shouldn't be null.
return new SVNUserNameAuthentication("",false);
return null;
}
try { try {
return cred.createSVNAuthentication(kind); return cred.createSVNAuthentication(kind);
} catch (SVNException e) { } catch (SVNException e) {
...@@ -888,7 +955,7 @@ public class SubversionSCM extends SCM implements Serializable { ...@@ -888,7 +955,7 @@ public class SubversionSCM extends SCM implements Serializable {
e.printStackTrace(new PrintWriter(sw)); e.printStackTrace(new PrintWriter(sw));
String message=""; String message="";
message += "Unable to access "+url+" : "+Util.escape( e.getErrorMessage().getFullMessage()); message += "Unable to access "+Util.escape(url)+" : "+Util.escape( e.getErrorMessage().getFullMessage());
message += " <a href='#' id=svnerrorlink onclick='javascript:" + message += " <a href='#' id=svnerrorlink onclick='javascript:" +
"document.getElementById(\"svnerror\").style.display=\"block\";" + "document.getElementById(\"svnerror\").style.display=\"block\";" +
"document.getElementById(\"svnerrorlink\").style.display=\"none\";" + "document.getElementById(\"svnerrorlink\").style.display=\"none\";" +
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册