提交 64442252 编写于 作者: K kohsuke

shouldn't escape & and < for .../consoleText

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@20927 71c3de6d-444a-0410-be80-ed276b4c234a
上级 1a3ad411
......@@ -91,6 +91,7 @@ import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.framework.io.LargeText;
import org.apache.commons.io.IOUtils;
import com.thoughtworks.xstream.XStream;
......@@ -1388,6 +1389,14 @@ public abstract class Run <JobT extends Job<JobT,RunT>,RunT extends Run<JobT,Run
rsp.getWriter().print(df.format(getTimestamp().getTime()));
}
/**
* Sends out the raw console output.
*/
public void doConsoleText(StaplerRequest req, StaplerResponse rsp) throws IOException {
rsp.setContentType("text/plain;charset=UTF-8");
IOUtils.copy(getLogReader(),rsp.getCompressedOutputStream(req));
}
/**
* Handles incremental log output.
*/
......
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<!--
Displays the console output as plain/text
-->
<st:compress xmlns:j="jelly:core" xmlns:st="jelly:stapler">
<st:contentType value="text/plain;charset=UTF-8" />
<st:copyStream reader="${it.getLogReader()}"/></st:compress>
\ No newline at end of file
package hudson.model
import com.gargoylesoftware.htmlunit.Page
import hudson.model.BuildListener
import hudson.slaves.EnvironmentVariablesNodeProperty
import hudson.slaves.EnvironmentVariablesNodeProperty.Entry
import junit.framework.Assert
import org.jvnet.hudson.test.CaptureEnvironmentBuilder
import org.jvnet.hudson.test.GroovyHudsonTestCase
public class AbstractBuildTest extends GroovyHudsonTestCase {
void testVariablesResolved() {
def project = createFreeStyleProject();
hudson.getNodeProperties().replaceBy([
new EnvironmentVariablesNodeProperty(new Entry("KEY1", "value"), new Entry("KEY2",'$KEY1'))]);
def builder = new CaptureEnvironmentBuilder();
project.getBuildersList().add(builder);
assertBuildStatusSuccess(project.scheduleBuild2(0).get());
def envVars = builder.getEnvVars();
Assert.assertEquals("value", envVars.get("KEY1"));
Assert.assertEquals("value", envVars.get("KEY2"));
}
/**
* Makes sure that raw console output doesn't get affected by XML escapes.
*/
void testRawConsoleOutput() {
def out = "<test>&</test>";
def p = createFreeStyleProject();
p.buildersList.add(builder { builder,launcher,BuildListener listener ->
listener.logger.println(out);
})
def b = assertBuildStatusSuccess(p.scheduleBuild2(0).get());
Page rsp = createWebClient().goTo("${b.url}/consoleText", "text/plain");
println "Output:\n"+rsp.webResponse.contentAsString
assertTrue(rsp.webResponse.contentAsString.contains(out));
}
}
package hudson.model;
import hudson.slaves.EnvironmentVariablesNodeProperty;
import hudson.slaves.NodeProperty;
import hudson.slaves.EnvironmentVariablesNodeProperty.Entry;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import junit.framework.Assert;
import org.jvnet.hudson.test.CaptureEnvironmentBuilder;
import org.jvnet.hudson.test.HudsonTestCase;
public class AbstractBuildTest extends HudsonTestCase {
public void testVariablesResolved() throws Exception {
FreeStyleProject project = createFreeStyleProject();
Hudson.getInstance().getNodeProperties().replaceBy(
Collections.singleton(new EnvironmentVariablesNodeProperty(
new Entry("KEY1", "value"), new Entry("KEY2",
"$KEY1"))));
CaptureEnvironmentBuilder builder = new CaptureEnvironmentBuilder();
project.getBuildersList().add(builder);
AbstractBuild build = project.scheduleBuild2(0).get(10, TimeUnit.SECONDS);
Map<String, String> envVars = builder.getEnvVars();
Assert.assertEquals("value", envVars.get("KEY1"));
Assert.assertEquals("value", envVars.get("KEY2"));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册