/******************************************************************************* * Copyright (c) 2009 Thales Corporate Services SAS * * Author : Gregory Boissinot * * * * 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 com.thalesgroup.hudson.plugins.cccc; import hudson.FilePath; import hudson.Launcher; import hudson.model.*; import hudson.tasks.BuildStepMonitor; import hudson.tasks.Recorder; import org.kohsuke.stapler.DataBoundConstructor; import java.io.IOException; import java.io.PrintStream; import java.io.Serializable; public class CcccPublisher extends Recorder implements Serializable { private static final long serialVersionUID = 1L; private final String metricFilePath; @DataBoundConstructor public CcccPublisher(String metricFilePath) { this.metricFilePath = metricFilePath; } @Override public Action getProjectAction(AbstractProject<?, ?> project) { return new CcccProjectAction(project); } protected boolean canContinue(final Result result) { return result != Result.ABORTED && result != Result.FAILURE; } @Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) { if (this.canContinue(build.getResult())) { listener.getLogger().println("Parsing cccc results"); FilePath workspace = build.getWorkspace(); PrintStream logger = listener.getLogger(); CccccParser parser = new CccccParser(new FilePath(build.getWorkspace(), metricFilePath)); CcccReport report; try { report = workspace.act(parser); } catch (IOException ioe) { ioe.printStackTrace(logger); build.setResult(Result.FAILURE); return false; } catch (InterruptedException ie) { ie.printStackTrace(logger); build.setResult(Result.FAILURE); return false; } CcccResult result = new CcccResult(report, build); CcccBuildAction buildAction = new CcccBuildAction(build, result); build.addAction(buildAction); listener.getLogger().println("End Processing cccc results"); } build.setResult(Result.SUCCESS); return true; } public BuildStepMonitor getRequiredMonitorService() { return BuildStepMonitor.NONE; } @SuppressWarnings("unused") public String getMetricFilePath() { return metricFilePath; } }