started implementing layouter.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3531 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2007-06-23 22:27:59 +00:00
1 parent f2ccaf33a8
commit 2efb071a95
4 files changed
+138

No files matched your search

@@ -0,0 +1,90 @@
package hudson.matrix;
import java.util.List;
import java.util.ArrayList;
/**
* Used to assist thegeneration of config table.
*
* <p>
* {@link Axis Axes} are split into four groups.
* {@link #x Ones that are displayed as columns},
* {@link #x Ones that are displayed as rows},
* {@link #z Ones that are listed as bullet items inside table cell},
* and those which only have one value, and therefore doesn't show up
* in the table.
*
* @author Kohsuke Kawaguchi
*/
public final class Layouter {
public final List<Axis> x,y,z;
public Layouter(List<Axis> x, List<Axis> y, List<Axis> z) {
this.x = x;
this.y = y;
this.z = z;
}
/**
* Automatically split axes to x,y, and z.
*/
public Layouter(AxisList axisList) {
x = new ArrayList<Axis>();
y = new ArrayList<Axis>();
z = new ArrayList<Axis>();
List<Axis> nonTrivialAxes = new ArrayList<Axis>();
for (Axis a : axisList) {
if(a.size()>1)
nonTrivialAxes.add(a);
}
switch(nonTrivialAxes.size()) {
case 0:
return;
case 1:
z.add(nonTrivialAxes.get(0));
return;
case 2:
x.add(nonTrivialAxes.get(0));
y.add(nonTrivialAxes.get(1));
break;
}
// for size > 3,
int i;
for( i=0; i<nonTrivialAxes.size(); i+=3 ) {
x.add(nonTrivialAxes.get(0));
y.add(nonTrivialAxes.get(1));
z.add(nonTrivialAxes.get(2));
}
switch(i-nonTrivialAxes.size()) {
case 1:
y.add(nonTrivialAxes.get(i-2));
// fall through
case 2:
x.add(nonTrivialAxes.get(i-3));
}
}
/**
* Computes the width of n-th X-axis.
*/
public int width(int n) {
return calc(x,n);
}
/**
* Computes the width of n-th X-axis.
*/
public int height(int n) {
return calc(y,n);
}
private int calc(List<Axis> l, int n) {
int w = 1;
for( n++ ; n<l.size(); n++ )
w *= l.get(n).size();
return w;
}
}
@@ -43,6 +43,13 @@ public class MatrixConfiguration extends Project<MatrixConfiguration,MatrixRun>
return (MatrixProject)super.getParent();
}
/**
* Get the actual combination of the axes values for this {@link MatrixConfiguration}
*/
public Combination getCombination() {
return combination;
}
@Override
public FilePath getWorkspace() {
Node node = getLastBuiltOn();
@@ -1,6 +1,7 @@
package hudson.matrix;
import hudson.FilePath;
import hudson.maven.ModuleName;
import hudson.tasks.Builder;
import hudson.tasks.Publisher;
import hudson.tasks.BuildWrapper;
@@ -77,6 +78,14 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im
super(Hudson.getInstance(), name);
}
public AxisList getAxes() {
return axes;
}
public Layouter getLayouter() {
return new Layouter(axes);
}
public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOException {
super.onLoad(parent,name);
Collections.sort(axes); // perhaps the file was edited on disk and the sort order might have been broken
@@ -219,6 +228,12 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im
return this;
}
public Object getDynamic(String token, StaplerRequest req, StaplerResponse rsp) {
MatrixConfiguration item = getItem(token);
if(item!=null)
return item;
return super.getDynamic(token,req,rsp);
}
protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException {
super.submit(req, rsp);