All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hudson.maven.MavenTestDataPublisher Maven / Gradle / Ivy

Go to download

This plug-in provides deep integration of Hudson and Maven. This functionality used to be part of the Hudson core. Now it is a plug-in that is installed by default, but can be disabled.

There is a newer version: 2.2.0
Show newest version
/*
 * The MIT License
 * 
 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Tom Huybrechts
 * 
 * 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.maven;

import hudson.Extension;
import hudson.Launcher;
import hudson.maven.reporters.SurefireReport;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.Descriptor;
import hudson.model.Saveable;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
import hudson.tasks.Recorder;
import hudson.tasks.junit.TestDataPublisher;
import hudson.tasks.junit.TestResultAction.Data;
import hudson.util.DescribableList;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import net.sf.json.JSONObject;

import org.kohsuke.stapler.StaplerRequest;

/**
 * Augments {@link SurefireReport} by executing {@link TestDataPublisher}s.
 * @since 1.320
 */
public class MavenTestDataPublisher extends Recorder {

	private final DescribableList> testDataPublishers;

	public MavenTestDataPublisher(
			DescribableList> testDataPublishers) {
		super();
		this.testDataPublishers = testDataPublishers;
	}

	public BuildStepMonitor getRequiredMonitorService() {
		return BuildStepMonitor.STEP;
	}

	public boolean perform(AbstractBuild build, Launcher launcher,
			BuildListener listener) throws InterruptedException, IOException {

		SurefireReport report = build.getAction(SurefireReport.class);
		if (report == null) {
			return true;
		}
		
		List data = new ArrayList();
		if (testDataPublishers != null) {
			for (TestDataPublisher tdp : testDataPublishers) {
				Data d = tdp.getTestData(build, launcher, listener, report.getResult());
				if (d != null) {
					data.add(d);
				}
			}
		}
		
		report.setData(data);

		return true;
	}

	public DescribableList> getTestDataPublishers() {
		return testDataPublishers;
	}
	
	@Extension
	public static class DescriptorImpl extends BuildStepDescriptor {

		@Override
		public String getDisplayName() {
			return "Additional test report features";
		}

		@Override
		public boolean isApplicable(Class jobType) {
			return MavenModuleSet.class.isAssignableFrom(jobType) && !TestDataPublisher.all().isEmpty();
		}
		
		@Override
		public Publisher newInstance(StaplerRequest req, JSONObject formData) throws FormException {
			DescribableList> testDataPublishers
                    = new DescribableList>(Saveable.NOOP);
            try {
                testDataPublishers.rebuild(req, formData, TestDataPublisher.all());
            } catch (IOException e) {
                throw new FormException(e,null);
            }

            return new MavenTestDataPublisher(testDataPublishers);
		}
		
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy