private boolean createTag( String tagName, TaskListener listener, File destdir, String moduleLocalDir, String module, boolean isFlatten) throws IOException, InterruptedException { FilePath path = (isFlatten ? new FilePath(destdir).child(module) : new FilePath(destdir).child(moduleLocalDir).child(module)); boolean isDir = path.isDirectory(); ArgumentListBuilder cmd = new ArgumentListBuilder(); cmd.add(scmInstance.getDescriptor().getCvsExeOrDefault(), "tag"); if (isDir) { cmd.add("-R"); } cmd.add(tagName); if (!isDir) { cmd.add(path.getName()); path = path.getParent(); } if (!scmInstance.run(new Launcher.LocalLauncher(listener), cmd, listener, path)) { listener.getLogger().println(Messages.CVSSCM_TaggingFailed()); return false; } return true; }
public static void generateFile(String mavenSettingsPath, FilePath outputPath) { try { // create directories if needed outputPath.getParent().mkdirs(); StringBuilder sb = new StringBuilder("eclipse.m2.userSettingsFile="); sb.append(OSPathHacks.escapePathForEclipseConf(mavenSettingsPath)); sb.append("\neclipse.preferences.version=1"); outputPath.write(sb.toString(), null); } catch (IOException e) { throw new RuntimeException("Error generating xCP Designer m2e preferences file.", e); } catch (InterruptedException e) { throw new RuntimeException("Error generating xCP Designer m2e preferences file.", e); } }
/** {@inheritDoc} */ @Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { Result threshold = onlyStable ? Result.SUCCESS : Result.UNSTABLE; if (build.getResult().isWorseThan(threshold)) { listener .getLogger() .println( "Skipping Cobertura coverage report as build was not " + threshold.toString() + " or better ..."); return true; } listener.getLogger().println("[Cobertura] Publishing Cobertura coverage report..."); final FilePath[] moduleRoots = build.getModuleRoots(); final boolean multipleModuleRoots = moduleRoots != null && moduleRoots.length > 1; final FilePath moduleRoot = multipleModuleRoots ? build.getWorkspace() : build.getModuleRoot(); final File buildCoberturaDir = build.getRootDir(); FilePath buildTarget = new FilePath(buildCoberturaDir); FilePath[] reports = new FilePath[0]; try { reports = moduleRoot.act(new ParseReportCallable(coberturaReportFile)); // if the build has failed, then there's not // much point in reporting an error if (build.getResult().isWorseOrEqualTo(Result.FAILURE) && reports.length == 0) { return true; } } catch (IOException e) { Util.displayIOException(e, listener); e.printStackTrace(listener.fatalError("Unable to find coverage results")); build.setResult(Result.FAILURE); } if (reports.length == 0) { String msg = "[Cobertura] No coverage results were found using the pattern '" + coberturaReportFile + "' relative to '" + moduleRoot.getRemote() + "'." + " Did you enter a pattern relative to the correct directory?" + " Did you generate the XML report(s) for Cobertura?"; listener.getLogger().println(msg); if (failNoReports) { build.setResult(Result.FAILURE); } else { listener.getLogger().println("[Cobertura] Skipped cobertura reports."); } return true; } for (int i = 0; i < reports.length; i++) { final FilePath targetPath = new FilePath(buildTarget, "coverage" + (i == 0 ? "" : i) + ".xml"); try { reports[i].copyTo(targetPath); } catch (IOException e) { Util.displayIOException(e, listener); e.printStackTrace( listener.fatalError( "Unable to copy coverage from " + reports[i] + " to " + buildTarget)); build.setResult(Result.FAILURE); } } listener.getLogger().println("Publishing Cobertura coverage results..."); Set<String> sourcePaths = new HashSet<String>(); CoverageResult result = null; for (File coberturaXmlReport : getCoberturaReports(build)) { try { result = CoberturaCoverageParser.parse(coberturaXmlReport, result, sourcePaths); } catch (IOException e) { Util.displayIOException(e, listener); e.printStackTrace(listener.fatalError("Unable to parse " + coberturaXmlReport)); build.setResult(Result.FAILURE); } } if (result != null) { listener.getLogger().println("Cobertura coverage report found."); result.setOwner(build); final FilePath paintedSourcesPath = new FilePath(new File(build.getProject().getRootDir(), "cobertura")); paintedSourcesPath.mkdirs(); if (sourcePaths.contains(".")) { sourcePaths.remove("."); for (FilePath f : reports) { FilePath p = f.getParent(); if (p != null && p.isDirectory()) { sourcePaths.add(p.getRemote()); } } } SourceCodePainter painter = new SourceCodePainter( paintedSourcesPath, sourcePaths, result.getPaintedSources(), listener, getSourceEncoding()); moduleRoot.act(painter); final CoberturaBuildAction action = CoberturaBuildAction.load( build, result, healthyTarget, unhealthyTarget, getOnlyStable(), getFailUnhealthy(), getFailUnstable(), getAutoUpdateHealth(), getAutoUpdateStability()); build.getActions().add(action); Set<CoverageMetric> failingMetrics = failingTarget.getFailingMetrics(result); if (!failingMetrics.isEmpty()) { listener.getLogger().println("Code coverage enforcement failed for the following metrics:"); float oldStabilityPercent; float setStabilityPercent; for (CoverageMetric metric : failingMetrics) { oldStabilityPercent = failingTarget.getObservedPercent(result, metric); setStabilityPercent = failingTarget.getSetPercent(result, metric); listener .getLogger() .println( " " + metric.getName() + "'s stability is " + roundDecimalFloat(oldStabilityPercent * 100f) + " and set mininum stability is " + roundDecimalFloat(setStabilityPercent * 100f) + "."); } if (!getFailUnstable()) { listener.getLogger().println("Setting Build to unstable."); build.setResult(Result.UNSTABLE); } else { listener.getLogger().println("Failing build due to unstability."); build.setResult(Result.FAILURE); } } if (getFailUnhealthy()) { Set<CoverageMetric> unhealthyMetrics = unhealthyTarget.getFailingMetrics(result); if (!unhealthyMetrics.isEmpty()) { listener.getLogger().println("Unhealthy for the following metrics:"); float oldHealthyPercent; float setHealthyPercent; for (CoverageMetric metric : unhealthyMetrics) { oldHealthyPercent = unhealthyTarget.getObservedPercent(result, metric); setHealthyPercent = unhealthyTarget.getSetPercent(result, metric); listener .getLogger() .println( " " + metric.getName() + "'s health is " + roundDecimalFloat(oldHealthyPercent * 100f) + " and set minimum health is " + roundDecimalFloat(setHealthyPercent * 100f) + "."); } listener.getLogger().println("Failing build because it is unhealthy."); build.setResult(Result.FAILURE); } } if (build.getResult() == Result.SUCCESS) { if (getAutoUpdateHealth()) { setNewPercentages(result, true, listener); } if (getAutoUpdateStability()) { setNewPercentages(result, false, listener); } } } else { listener .getLogger() .println( "No coverage results were successfully parsed. Did you generate " + "the XML report(s) for Cobertura?"); build.setResult(Result.FAILURE); } return true; }