提交 b560509f 编写于 作者: K kohsuke

added a few basic set of Maven console annotations.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@34834 71c3de6d-444a-0410-be80-ed276b4c234a
上级 20e4d0bd
......@@ -95,5 +95,19 @@ public abstract class LineTransformationOutputStream extends OutputStream {
}
}
protected String trimEOL(String line) {
int slen = line.length();
while (slen>0) {
char ch = line.charAt(slen-1);
if (ch=='\r' || ch=='\n') {
slen--;
continue;
}
break;
}
line = line.substring(0,slen);
return line;
}
private static final int LF = 0x0A;
}
......@@ -42,6 +42,8 @@ import hudson.model.TaskListener;
import hudson.remoting.Callable;
import hudson.remoting.VirtualChannel;
import hudson.slaves.NodeSpecific;
import hudson.tasks._ant.AntConsoleAnnotator;
import hudson.tasks._maven.MavenConsoleAnnotator;
import hudson.tools.ToolDescriptor;
import hudson.tools.ToolInstallation;
import hudson.tools.DownloadFromUrlInstaller;
......@@ -250,7 +252,8 @@ public class Maven extends Builder {
buildEnvVars(env, mi);
try {
int r = launcher.launch().cmds(args).envs(env).stdout(listener).pwd(build.getModuleRoot()).join();
MavenConsoleAnnotator mca = new MavenConsoleAnnotator(listener.getLogger(),build.getCharset());
int r = launcher.launch().cmds(args).envs(env).stdout(mca).pwd(build.getModuleRoot()).join();
if (0 != r) {
return false;
}
......
......@@ -70,20 +70,6 @@ public class AntConsoleAnnotator extends LineTransformationOutputStream {
return len>0 && line.charAt(len-1)==c;
}
private String trimEOL(String line) {
int slen = line.length();
while (slen>0) {
char ch = line.charAt(slen-1);
if (ch=='\r' || ch=='\n') {
slen--;
continue;
}
break;
}
line = line.substring(0,slen);
return line;
}
@Override
public void close() throws IOException {
super.close();
......
/*
* The MIT License
*
* Copyright (c) 2010, InfraDNA, Inc.
*
* 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.
*/
package hudson.tasks._maven;
import hudson.console.LineTransformationOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.regex.Matcher;
/**
* Filter {@link OutputStream} that places annotations that marks various Maven outputs.
*
* @author Kohsuke Kawaguchi
*/
public class MavenConsoleAnnotator extends LineTransformationOutputStream {
private final OutputStream out;
private final Charset charset;
public MavenConsoleAnnotator(OutputStream out, Charset charset) {
this.out = out;
this.charset = charset;
}
@Override
protected void eol(byte[] b, int len) throws IOException {
String line = charset.decode(ByteBuffer.wrap(b, 0, len)).toString();
// trim off CR/LF from the end
line = trimEOL(line);
// TODO:
// we need more support for conveniently putting annotations in the middle of the line, not just at the beginning
// we also need the ability for an extension point to have notes hook into the processing
Matcher m = MavenMojoNote.PATTERN.matcher(line);
if (m.matches())
new MavenMojoNote().encodeTo(out);
m = MavenWarningNote.PATTERN.matcher(line);
if (m.matches())
new MavenWarningNote().encodeTo(out);
m = MavenErrorNote.PATTERN.matcher(line);
if (m.matches())
new MavenErrorNote().encodeTo(out);
out.write(b,0,len);
}
@Override
public void close() throws IOException {
super.close();
out.close();
}
}
/*
* The MIT License
*
* Copyright (c) 2010, InfraDNA, Inc.
*
* 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.
*/
package hudson.tasks._maven;
import hudson.Extension;
import hudson.MarkupText;
import hudson.console.ConsoleAnnotationDescriptor;
import hudson.console.ConsoleAnnotator;
import hudson.console.ConsoleNote;
import java.util.regex.Pattern;
/**
* @author Kohsuke Kawaguchi
*/
public class MavenErrorNote extends ConsoleNote {
public MavenErrorNote() {
}
@Override
public ConsoleAnnotator annotate(Object context, MarkupText text, int charPos) {
MarkupText.SubText t = text.findToken(Pattern.compile("^[^:]+(?=:)"));
if (t!=null)
t.addMarkup(0,t.length(),"<span class=error-inline>","</span>");
return null;
}
@Extension
public static final class DescriptorImpl extends ConsoleAnnotationDescriptor {
public String getDisplayName() {
return "Maven Errors";
}
}
public static Pattern PATTERN = Pattern.compile("^\\[ERROR\\]");
}
/*
* The MIT License
*
* Copyright (c) 2010, InfraDNA, Inc.
*
* 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.
*/
package hudson.tasks._maven;
import hudson.Extension;
import hudson.MarkupText;
import hudson.console.ConsoleAnnotationDescriptor;
import hudson.console.ConsoleAnnotator;
import hudson.console.ConsoleNote;
import java.util.regex.Pattern;
/**
* Marks the log line that reports that Maven is executing a mojo.
* It'll look something like this:
*
* <pre>[INFO] [pmd:pmd {execution: default}]</pre>
*
* @author Kohsuke Kawaguchi
*/
public class MavenMojoNote extends ConsoleNote {
public MavenMojoNote() {
}
@Override
public ConsoleAnnotator annotate(Object context, MarkupText text, int charPos) {
MarkupText.SubText t = text.findToken(Pattern.compile("^[^:]+(?=:)"));
if (t!=null)
t.addMarkup(7,t.length(),"<b class=maven-mojo>","</b>");
return null;
}
@Extension
public static final class DescriptorImpl extends ConsoleAnnotationDescriptor {
public String getDisplayName() {
return "Maven Mojos";
}
}
public static Pattern PATTERN = Pattern.compile("\\[INFO\\] \\[\\w+:\\w+ \\{execution: \\w+\\}\\]");
}
/*
* The MIT License
*
* Copyright (c) 2010, InfraDNA, Inc.
*
* 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.
*/
package hudson.tasks._maven;
import hudson.Extension;
import hudson.MarkupText;
import hudson.console.ConsoleAnnotationDescriptor;
import hudson.console.ConsoleAnnotator;
import hudson.console.ConsoleNote;
import java.util.regex.Pattern;
/**
* Marks the warning messages from Maven.
*
* @author Kohsuke Kawaguchi
*/
public class MavenWarningNote extends ConsoleNote {
public MavenWarningNote() {
}
@Override
public ConsoleAnnotator annotate(Object context, MarkupText text, int charPos) {
MarkupText.SubText t = text.findToken(Pattern.compile("^[^:]+(?=:)"));
if (t!=null)
t.addMarkup(0,t.length(),"<span class=warning-inline>","</span>");
return null;
}
@Extension
public static final class DescriptorImpl extends ConsoleAnnotationDescriptor {
public String getDisplayName() {
return "Maven Warnings";
}
}
public static Pattern PATTERN = Pattern.compile("^\\[WARNING\\]");
}
......@@ -452,6 +452,11 @@ div.behavior-loading {
background-repeat: no-repeat;
}
.error-inline {
color: #CC0000;
font-weight: bold;
}
.warning {
color: #C4A000;
font-weight: bold;
......@@ -462,6 +467,11 @@ div.behavior-loading {
background-repeat: no-repeat;
}
.warning-inline {
color: #C4A000;
font-weight: bold;
}
.info {
color: black;
font-weight: bold;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册