提交 5ede2ec4 编写于 作者: K kohsuke

tab -> WS

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@21262 71c3de6d-444a-0410-be80-ed276b4c234a
上级 5bcdc23d
...@@ -25,32 +25,19 @@ package org.jvnet.hudson.test; ...@@ -25,32 +25,19 @@ package org.jvnet.hudson.test;
import hudson.FilePath; import hudson.FilePath;
import hudson.Launcher; import hudson.Launcher;
import hudson.model.User;
import hudson.model.AbstractBuild; import hudson.model.AbstractBuild;
import hudson.model.BuildListener; import hudson.model.BuildListener;
import hudson.scm.ChangeLogParser;
import hudson.scm.NullSCM; import hudson.scm.NullSCM;
import hudson.scm.SCM; import hudson.scm.SCM;
import hudson.scm.ChangeLogSet;
import hudson.scm.ChangeLogParser;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.PrintStream;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream;
import java.net.URL; import java.net.URL;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.List; import java.util.zip.ZipInputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import org.apache.commons.digester.Digester;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.export.Exported;
import org.xml.sax.SAXException;
/** /**
* {@link SCM} useful for testing that extracts the given resource as a zip file. * {@link SCM} useful for testing that extracts the given resource as a zip file.
...@@ -60,49 +47,49 @@ import org.xml.sax.SAXException; ...@@ -60,49 +47,49 @@ import org.xml.sax.SAXException;
public class ExtractResourceWithChangesSCM extends NullSCM { public class ExtractResourceWithChangesSCM extends NullSCM {
private final URL firstZip; private final URL firstZip;
private final URL secondZip; private final URL secondZip;
public ExtractResourceWithChangesSCM(URL firstZip, URL secondZip) { public ExtractResourceWithChangesSCM(URL firstZip, URL secondZip) {
if ((firstZip==null) || (secondZip==null)) if ((firstZip == null) || (secondZip == null))
throw new IllegalArgumentException(); throw new IllegalArgumentException();
this.firstZip = firstZip; this.firstZip = firstZip;
this.secondZip = secondZip; this.secondZip = secondZip;
} }
@Override @Override
public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspace, BuildListener listener, File changeLogFile) throws IOException, InterruptedException { public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspace, BuildListener listener, File changeLogFile) throws IOException, InterruptedException {
if (workspace.exists()) { if (workspace.exists()) {
listener.getLogger().println("Deleting existing workspace " + workspace.getRemote()); listener.getLogger().println("Deleting existing workspace " + workspace.getRemote());
workspace.deleteRecursive(); workspace.deleteRecursive();
} }
listener.getLogger().println("Staging first zip: "+firstZip); listener.getLogger().println("Staging first zip: " + firstZip);
workspace.unzipFrom(firstZip.openStream()); workspace.unzipFrom(firstZip.openStream());
listener.getLogger().println("Staging second zip: "+secondZip); listener.getLogger().println("Staging second zip: " + secondZip);
workspace.unzipFrom(secondZip.openStream()); workspace.unzipFrom(secondZip.openStream());
// Get list of files changed in secondZip. // Get list of files changed in secondZip.
ZipInputStream zip = new ZipInputStream(secondZip.openStream()); ZipInputStream zip = new ZipInputStream(secondZip.openStream());
ZipEntry e; ZipEntry e;
ExtractChangeLogParser.ExtractChangeLogEntry changeLog = new ExtractChangeLogParser.ExtractChangeLogEntry(secondZip.toString()); ExtractChangeLogParser.ExtractChangeLogEntry changeLog = new ExtractChangeLogParser.ExtractChangeLogEntry(secondZip.toString());
try { try {
while ((e=zip.getNextEntry())!=null) { while ((e = zip.getNextEntry()) != null) {
if (!e.isDirectory()) if (!e.isDirectory())
changeLog.addFile(new ExtractChangeLogParser.FileInZip(e.getName())); changeLog.addFile(new ExtractChangeLogParser.FileInZip(e.getName()));
} }
} }
finally { finally {
zip.close(); zip.close();
} }
saveToChangeLog(changeLogFile, changeLog); saveToChangeLog(changeLogFile, changeLog);
return true; return true;
} }
@Override @Override
public ChangeLogParser createChangeLogParser() { public ChangeLogParser createChangeLogParser() {
return new ExtractChangeLogParser(); return new ExtractChangeLogParser();
} }
public static String escapeForXml(String string) { public static String escapeForXml(String string) {
if (string == null) { if (string == null) {
return ""; return "";
...@@ -138,29 +125,26 @@ public class ExtractResourceWithChangesSCM extends NullSCM { ...@@ -138,29 +125,26 @@ public class ExtractResourceWithChangesSCM extends NullSCM {
return escapedString.toString().trim(); return escapedString.toString().trim();
} }
public void saveToChangeLog(File changeLogFile, ExtractChangeLogParser.ExtractChangeLogEntry changeLog) throws IOException { public void saveToChangeLog(File changeLogFile, ExtractChangeLogParser.ExtractChangeLogEntry changeLog) throws IOException {
FileOutputStream outputStream = new FileOutputStream(changeLogFile); FileOutputStream outputStream = new FileOutputStream(changeLogFile);
PrintStream stream = new PrintStream(outputStream, false, "UTF-8");
stream.println("<?xml version='1.0' encoding='UTF-8'?>");
stream.println("<extractChanges>");
stream.println("<entry>");
stream.println("<zipFile>" + escapeForXml(changeLog.getZipFile()) + "</zipFile>");
stream.println("<file>");
for (String fileName : changeLog.getAffectedPaths()) {
stream.println("<fileName>" + escapeForXml(fileName) + "</fileName>");
}
stream.println("</file>");
stream.println("</entry>");
stream.println("</extractChanges>");
stream.close();
}
PrintStream stream = new PrintStream(outputStream, false, "UTF-8");
stream.println("<?xml version='1.0' encoding='UTF-8'?>");
stream.println("<extractChanges>");
stream.println("<entry>");
stream.println("<zipFile>" + escapeForXml(changeLog.getZipFile()) + "</zipFile>");
stream.println("<file>");
for (String fileName : changeLog.getAffectedPaths()) {
stream.println("<fileName>" + escapeForXml(fileName) + "</fileName>");
}
stream.println("</file>");
stream.println("</entry>");
stream.println("</extractChanges>");
stream.close();
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册