Skip to content

Commit

Permalink
fair configuration values for a new clif job
Browse files Browse the repository at this point in the history
archive is available in job workspace
  • Loading branch information
thenrio committed Mar 30, 2012
1 parent 932ab2d commit c75680b
Show file tree
Hide file tree
Showing 19 changed files with 300 additions and 135 deletions.
9 changes: 5 additions & 4 deletions src/main/java/org/ow2/clif/jenkins/ClifBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@ public ClifInstallation.DescriptorImpl getToolDescriptor() {
return ToolInstallation.all().get(ClifInstallation.DescriptorImpl.class);
}

public boolean isApplicable(Class<? extends AbstractProject> jobType) {
@Override
@SuppressWarnings("rawtypes")
public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return true;
}

Expand All @@ -338,7 +340,8 @@ public String getHelpFile() {
return "/help-clif.html";
}

public String getDisplayName() {
@Override
public String getDisplayName() {
return Messages.Clif_DisplayName();
}

Expand Down Expand Up @@ -384,6 +387,4 @@ public FormValidation doCheckTestPlanFile(@QueryParameter String value) {
return FormValidation.ok();
}
}


}
3 changes: 2 additions & 1 deletion src/main/java/org/ow2/clif/jenkins/ClifDataCleanup.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ public class ClifDataCleanup
protected double keepPercentage;

public ClifDataCleanup() {
this.keepFactor = 2;
this.keepPercentage = 95;
}

@DataBoundConstructor
public ClifDataCleanup(boolean enabled, double keepFactor, double keepPercentage) {
super();
this.enabled = enabled;
this.keepFactor = keepFactor;
this.keepPercentage = keepPercentage;
Expand Down
27 changes: 17 additions & 10 deletions src/main/java/org/ow2/clif/jenkins/ClifPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,37 @@
public class ClifPublisher
extends Recorder {

private String clifReportDirectory;
private final String clifReportDirectory;

private boolean dateFiltering;
private final boolean dateFiltering;

private String minTimestamp;
private final String minTimestamp;

private String maxTimestamp;
private final String maxTimestamp;

private List<ClifAlias> alias;

private List<ClifResultConfig> successPatterns;

private ClifDataCleanup dataCleanupConfig;

private int chartWidth;
private final int chartWidth;

private int chartHeight;
private final int chartHeight;

private int distributionSliceNumber;

private int distributionSliceSize;
private final int distributionSliceNumber;

private final int distributionSliceSize;

private int statisticalPeriod;

public ClifPublisher(String clifReportDirectory) {
// duplication of default values of
// src/main/resources/org/ow2/clif/jenkins/ClifPublisher/config.jelly
this(clifReportDirectory, false, "", "", 1200, 600, 50, 15, 5);
this.dataCleanupConfig = new ClifDataCleanup();
}

@DataBoundConstructor
public ClifPublisher(String clifReportDirectory, boolean dateFiltering, String minTimestamp,
String maxTimestamp, int chartWidth, int chartHeight, int distributionSliceSize,
Expand Down Expand Up @@ -202,7 +208,8 @@ public DescriptorImpl() {
super(ClifPublisher.class);
}

public String getDisplayName() {
@Override
public String getDisplayName() {
return Messages.Publisher_DisplayName();
}

Expand Down
24 changes: 11 additions & 13 deletions src/main/java/org/ow2/clif/jenkins/ImportZipAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.ow2.clif.jenkins.helper.Configurer;
import org.ow2.clif.jenkins.zip.Zip;
import org.ow2.clif.jenkins.jobs.Configurer;
import org.ow2.clif.jenkins.jobs.Workspaces;
import org.ow2.clif.jenkins.jobs.Zip;

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -54,26 +55,23 @@ public void doImport(StaplerRequest req, StaplerResponse res)
List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory())
.parseRequest(req);

for (FileItem item : items) {
Zip zip = new Zip(item.getInputStream());
List<FreeStyleProject> projects =
newProjectForEachFileInZipMatchingFilter(zip, whiteList);
for (FreeStyleProject project : projects) {
jenkins.putItem(project);
}
}
Zip zip = new Zip(items.get(0));
List<FreeStyleProject> projects =
newProjectForEachFileInZipMatchingFilter(zip, whiteList);
for (FreeStyleProject project : projects) {
jenkins.putItem(project);
}

zip.extractTo(Workspaces.DEFAULT_LOCATION);
res.sendRedirect2("/");
}


/**
*
* @param name
* @param zip
* @param filter regular expression as a string
* @return
* @throws IOException wish I could use a list comprehension!
* @throws IOException
*/
List<FreeStyleProject>
newProjectForEachFileInZipMatchingFilter(Zip zip, String filter)
Expand Down
34 changes: 0 additions & 34 deletions src/main/java/org/ow2/clif/jenkins/helper/Configurer.java

This file was deleted.

39 changes: 39 additions & 0 deletions src/main/java/org/ow2/clif/jenkins/jobs/Configurer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.ow2.clif.jenkins.jobs;

import hudson.model.FreeStyleProject;

import java.io.IOException;

import org.ow2.clif.jenkins.ClifBuilder;
import org.ow2.clif.jenkins.ClifPublisher;

public class Configurer {
Installations installations = new Installations();

public FreeStyleProject
configure(FreeStyleProject project, String testPlan) throws IOException {
String dir = Workspaces.DEFAULT_LOCATION, plan = null;
if (testPlan != null) {
String[] strings = testPlan.split("/");
dir += "/" + strings[0];
plan = strings[1];
}
project.getBuildersList().add(newClifBuilder(plan));
project.getPublishersList().add(newClifPublisher(dir));
project.setCustomWorkspace(dir);
return project;
}

ClifPublisher newClifPublisher(String dir) {
return new ClifPublisher(dir + "/report");
}

ClifBuilder newClifBuilder(String plan) {
String clifName = installations.getFirstClifName();
String antName = installations.getFirstAntName();
ClifBuilder builder = new ClifBuilder(
clifName, antName, null, null, plan, null
);
return builder;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.ow2.clif.jenkins.helper;
package org.ow2.clif.jenkins.jobs;

import hudson.tasks.Ant.AntInstallation;
import hudson.tools.ToolDescriptor;
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/ow2/clif/jenkins/jobs/Workspaces.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.ow2.clif.jenkins.jobs;

public class Workspaces {

public static final String DEFAULT_LOCATION = System.getProperty("user.home") + "/clif";

}
118 changes: 118 additions & 0 deletions src/main/java/org/ow2/clif/jenkins/jobs/Zip.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package org.ow2.clif.jenkins.jobs;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.io.FileUtils;

import com.google.common.collect.Lists;

public class Zip {
private Reader reader;

static interface Reader {
ZipInputStream newStream() throws IOException;
}

public Zip(final String file) throws IOException {
this.reader = new Reader() {
public ZipInputStream newStream() throws IOException {
return new ZipInputStream(new FileInputStream(file));
}
};
}

public Zip(final FileItem fileItem) {
this.reader = new Reader() {
public ZipInputStream newStream() throws IOException {
return new ZipInputStream(fileItem.getInputStream());
}
};
}

/**
* returns entry names of zip, matching given white pattern
*
* @param white, a regular expression as a string
* @return
* @throws IOException
*/
public List<String> names(String white) throws IOException {
ZipInputStream zip = reader.newStream();

List<String> list = Lists.newArrayList();
Pattern pattern = Pattern.compile(white);
ZipEntry entry;
while ((entry = zip.getNextEntry()) != null) {
String entryName = entry.getName();
if (pattern.matcher(entryName).matches()) {
list.add(entryName);
}
}
return list;
}

/**
* unzips to directory
*
* @param toDir the directory
* @throws IOException
*
*/
public void extractTo(String toDir) throws IOException {
FileUtils.forceMkdir(new File(toDir));
// many options to do that
// 1- apache commons compress
// is not a dependency of jenkins
// does not provide such a method
// 2- ant
// unzips a file (string)
// browser does have an InputStream ...
// 3- hand made :(
// inspired from http://stackoverflow.com/questions/4597821/what-is-the-jodatime-apache-commons-of-zip-unzip-java-utilities
byte[] buf = new byte[1024];
ZipEntry zipentry;
ZipInputStream zip = reader.newStream();
try {
for (zipentry = zip.getNextEntry(); zipentry != null; zipentry = zip.getNextEntry()) {
String entryName = zipentry.getName();

File dest = new File(toDir, entryName);
if (zipentry.isDirectory()) {
dest.mkdirs();
}
else {
dest.getParentFile().mkdirs();
dest.createNewFile();
writeCurrentFile(zip, buf, dest);
}
zip.closeEntry();
}
}
finally {
zip.close();
}
}

void writeCurrentFile(ZipInputStream zip, byte[] buf, File dest) throws IOException {
int n;
OutputStream fos = new BufferedOutputStream(new FileOutputStream(dest));
try {
while ((n = zip.read(buf, 0, buf.length)) > -1) {
fos.write(buf, 0, n);
}
}
finally {
fos.close();
}
}
}
43 changes: 0 additions & 43 deletions src/main/java/org/ow2/clif/jenkins/zip/Zip.java

This file was deleted.

Loading

0 comments on commit c75680b

Please sign in to comment.