Skip to content

Commit

Permalink
merged 'ready-to-merge' from huybrechts
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Nov 25, 2010
2 parents 494ac30 + 55b7d25 commit 768abac
Show file tree
Hide file tree
Showing 16 changed files with 226 additions and 54 deletions.
6 changes: 3 additions & 3 deletions core/src/main/java/hudson/TcpSlaveAgentListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private void runJnlpConnect(DataInputStream in, PrintWriter out) throws IOExcept
return;
}

String nodeName = in.readUTF();
final String nodeName = in.readUTF();
SlaveComputer computer = (SlaveComputer) Hudson.getInstance().getComputer(nodeName);
if(computer==null) {
error(out, "No such slave: "+nodeName);
Expand Down Expand Up @@ -241,7 +241,7 @@ public void onClosed(Channel channel, IOException cause) {
e.printStackTrace();
}
if(cause!=null)
LOGGER.log(Level.WARNING, "Connection #"+id+" terminated",cause);
LOGGER.log(Level.WARNING, "Connection #"+id+" for + " + nodeName + " terminated",cause);
try {
ConnectionHandler.this.s.close();
} catch (IOException e) {
Expand All @@ -254,7 +254,7 @@ public void onClosed(Channel channel, IOException cause) {
logw.println("Failed to establish the connection with the slave");
throw e;
} catch (IOException e) {
logw.println("Failed to establish the connection with the slave");
logw.println("Failed to establish the connection with the slave " + nodeName);
e.printStackTrace(logw);
throw e;
}
Expand Down
48 changes: 48 additions & 0 deletions core/src/main/java/hudson/cli/SetBuildDescriptionCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package hudson.cli;

import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.Run;
import hudson.remoting.Callable;

import java.io.IOException;
import java.io.Serializable;

import org.apache.commons.io.IOUtils;
import org.kohsuke.args4j.Argument;

@Extension
public class SetBuildDescriptionCommand extends CLICommand implements Serializable {

@Override
public String getShortDescription() {
return "Sets the description of a build";
}

@Argument(metaVar="JOB",usage="Name of the job to build",required=true,index=0)
public transient AbstractProject<?,?> job;

@Argument(metaVar="BUILD#",usage="Number of the build",required=true,index=1)
public int number;

@Argument(metaVar="DESCRIPTION",required=true,usage="Description to be set. '=' to read from stdin.", index=2)
public String description;

protected int run() throws Exception {
Run run = job.getBuildByNumber(number);
run.checkPermission(Run.UPDATE);

if ("=".equals(description)) {
description = channel.call(new Callable<String,IOException>() {
public String call() throws IOException {
return IOUtils.toString(System.in);
}
});
}

run.setDescription(description);

return 0;
}

}
3 changes: 2 additions & 1 deletion core/src/main/java/hudson/model/Cause.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ public UserCause() {

@Exported(visibility=3)
public String getUserName() {
return authenticationName;
User u = User.get(authenticationName, false);
return u != null ? u.getDisplayName() : authenticationName;
}

@Override
Expand Down
12 changes: 2 additions & 10 deletions core/src/main/java/hudson/model/ListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,25 +166,17 @@ protected void initJobFilters() {
jobFilters = new DescribableList<ViewJobFilter, Descriptor<ViewJobFilter>>(this,r);
}

/**
* Returns the transient {@link Action}s associated with the top page.
*
* @see Hudson#getActions()
*/
@Override
public List<Action> getActions() {
return Hudson.getInstance().getActions();
}

/**
* Used to determine if we want to display the Add button.
*/
public boolean hasJobFilterExtensions() {
return !ViewJobFilter.all().isEmpty();
}

public Iterable<ViewJobFilter> getJobFilters() {
return jobFilters;
}

public Iterable<ListViewColumn> getColumns() {
return columns;
}
Expand Down
20 changes: 17 additions & 3 deletions core/src/main/java/hudson/model/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -94,6 +96,7 @@
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.input.NullInputStream;
import org.apache.commons.io.IOUtils;
import org.apache.commons.jelly.XMLOutput;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
Expand Down Expand Up @@ -1072,8 +1075,19 @@ public Reader getLogReader() throws IOException {
* @since 1.349
*/
public void writeLogTo(long offset, XMLOutput out) throws IOException {
// TODO: resurrect compressed log file support
getLogText().writeHtmlTo(offset,out.asWriter());
try {
getLogText().writeHtmlTo(offset,out.asWriter());
} catch (IOException e) {
// try to fall back to the old getLogInputStream()
// mainly to support .gz compressed files
// In this case, console annotation handling will be turned off.
InputStream input = getLogInputStream();
try {
IOUtils.copy(input, out.asWriter());
} finally {
IOUtils.closeQuietly(input);
}
}
}

/**
Expand Down Expand Up @@ -1909,4 +1923,4 @@ public void doDynamic(StaplerResponse rsp) throws IOException {
out.flush();
}
}
}
}
40 changes: 40 additions & 0 deletions core/src/main/java/hudson/model/TransientViewActionFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package hudson.model;

import hudson.ExtensionList;

import java.util.ArrayList;
import java.util.List;

/**
* Extension point for adding transient {@link Action}s to {@link View}s.
*
*/
public abstract class TransientViewActionFactory {

/**
* returns a list of (transient) actions never null, may be empty
*
* @param v
* @return
*/
public abstract List<Action> createFor(View v);

/**
* Returns all the registered {@link TransientViewActionFactory}s.
*/
public static ExtensionList<TransientViewActionFactory> all() {
return Hudson.getInstance().getExtensionList(TransientViewActionFactory.class);
}

/**
* Creates {@link Action)s for a view, using all registered {@link TransientViewActionFactory}s.
*/
public static List<Action> createAllFor(View v) {
List<Action> result = new ArrayList<Action>();
for (TransientViewActionFactory f: all()) {
result.addAll(f.createFor(v));
}
return result;
}

}
19 changes: 18 additions & 1 deletion core/src/main/java/hudson/model/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ public abstract class View extends AbstractModelObject implements AccessControll
* If true, only show relevant queue items
*/
protected boolean filterQueue;

protected transient List<Action> transientActions;

protected View(String name) {
this.name = name;
Expand Down Expand Up @@ -313,7 +315,22 @@ public String getSearchUrl() {
* @see Hudson#getActions()
*/
public List<Action> getActions() {
return Hudson.getInstance().getActions();
List<Action> result = new ArrayList<Action>();
result.addAll(Hudson.getInstance().getActions());
synchronized (this) {
if (transientActions == null) {
transientActions = TransientViewActionFactory.createAllFor(this);
}
result.addAll(transientActions);
}
return result;
}

public Object getDynamic(String token) {
for (Action a : getActions())
if(a.getUrlName().equals(token))
return a;
return null;
}

/**
Expand Down
71 changes: 53 additions & 18 deletions core/src/main/java/hudson/tasks/junit/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,20 @@

import hudson.model.AbstractBuild;
import hudson.model.Hudson;
import hudson.tasks.test.TestResult;
import hudson.tasks.test.TestObject;
import hudson.util.*;
import hudson.tasks.test.TestResult;
import hudson.util.ChartUtil;
import hudson.util.ColorPalette;
import hudson.util.DataSetBuilder;
import hudson.util.Graph;
import hudson.util.ShiftedCategoryAxis;
import hudson.util.StackedAreaRenderer2;

import java.awt.Color;
import java.awt.Paint;
import java.util.ArrayList;
import java.util.List;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
Expand All @@ -38,10 +49,8 @@
import org.jfree.chart.renderer.category.StackedAreaRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.ui.RectangleInsets;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;

/**
* History of {@link hudson.tasks.test.TestObject} over time.
Expand All @@ -66,26 +75,42 @@ public boolean historyAvailable() {
return false;
}

public List<TestResult> getList(int start, int end) {
List<TestResult> list = new ArrayList<TestResult>();
end = Math.min(end, testObject.getOwner().getParent().getBuilds().size());
for (AbstractBuild<?,?> b: testObject.getOwner().getParent().getBuilds().subList(start, end)) {
if (b.isBuilding()) continue;
TestResult o = testObject.getResultInBuild(b);
if (o != null) {
list.add(o);
}
}
return list;
}

public List<TestResult> getList() {
List<TestResult> list = new ArrayList<TestResult>();
for (AbstractBuild<?,?> b: testObject.getOwner().getParent().getBuilds()) {
if (b.isBuilding()) continue;
TestResult o = testObject.getResultInBuild(b);
if (o != null) {
list.add(o);
}
}
return list;
return getList(0, testObject.getOwner().getParent().getBuilds().size());
}

/**
* Graph of duration of tests over time.
*/
public Graph getDurationGraph() {
return new GraphImpl("seconds") {

protected DataSetBuilder<String, ChartLabel> createDataSet() {
DataSetBuilder<String, ChartLabel> data = new DataSetBuilder<String, ChartLabel>();
for (hudson.tasks.test.TestResult o: getList()) {

List<TestResult> list;
try {
list = getList(
Integer.parseInt(Stapler.getCurrentRequest().getParameter("start")),
Integer.parseInt(Stapler.getCurrentRequest().getParameter("end")));
} catch (NumberFormatException e) {
list = getList();
}

for (hudson.tasks.test.TestResult o: list) {
data.add(((double) o.getDuration()) / (1000), "", new ChartLabel(o) {
@Override
public Color getColor() {
Expand All @@ -100,6 +125,7 @@ else if (o.getSkipCount() > 0)
}
return data;
}

};
}

Expand All @@ -111,7 +137,16 @@ public Graph getCountGraph() {
protected DataSetBuilder<String, ChartLabel> createDataSet() {
DataSetBuilder<String, ChartLabel> data = new DataSetBuilder<String, ChartLabel>();

for (TestResult o: getList()) {
List<TestResult> list;
try {
list = getList(
Integer.parseInt(Stapler.getCurrentRequest().getParameter("start")),
Integer.parseInt(Stapler.getCurrentRequest().getParameter("end")));
} catch (NumberFormatException e) {
list = getList();
}

for (TestResult o: list) {
data.add(o.getPassCount(), "2Passed", new ChartLabel(o));
data.add(o.getFailCount(), "1Failed", new ChartLabel(o));
data.add(o.getSkipCount(), "0Skipped", new ChartLabel(o));
Expand All @@ -125,7 +160,7 @@ private abstract class GraphImpl extends Graph {
private final String yLabel;

protected GraphImpl(String yLabel) {
super(testObject.getOwner().getTimestamp(),600,300);
super(-1,600,300); // cannot use timestamp, since ranges may change
this.yLabel = yLabel;
}

Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/hudson/tasks/test/TestObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.kohsuke.stapler.*;
import org.kohsuke.stapler.export.ExportedBean;

import com.google.common.collect.MapMaker;

import javax.servlet.ServletException;
import java.io.IOException;
import java.util.*;
Expand Down Expand Up @@ -339,7 +341,7 @@ protected final synchronized String uniquifyName(
UNIQUIFIED_NAMES.put(this, uniquified);
return uniquified;
}
private static final Map<TestObject, String> UNIQUIFIED_NAMES = new WeakHashMap<TestObject, String>();
private static final Map<TestObject, String> UNIQUIFIED_NAMES = new MapMaker().weakKeys().makeMap();

/**
* Replaces URL-unsafe characters.
Expand Down
Loading

0 comments on commit 768abac

Please sign in to comment.