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

com.marvelution.bamboo.plugins.sonar.SonarPluginHelper Maven / Gradle / Ivy

There is a newer version: 4.0.0
Show newest version
/*
 * Licensed to Marvelution under one or more contributor license 
 * agreements.  See the NOTICE file distributed with this work 
 * for additional information regarding copyright ownership.
 * Marvelution licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package com.marvelution.bamboo.plugins.sonar;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Writer;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.maven.model.Build;
import org.apache.maven.model.CiManagement;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.Scm;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.jetbrains.annotations.NotNull;

import com.atlassian.bamboo.build.Artifact;
import com.atlassian.bamboo.build.DefaultArtifact;
import com.atlassian.bamboo.builder.Maven2Builder;
import com.atlassian.bamboo.repository.RepositoryException;
import com.atlassian.bamboo.resultsummary.ExtendedBuildResultsSummary;
import com.atlassian.bamboo.v2.build.BuildContext;
import com.atlassian.bamboo.v2.build.BuildPlanDefinition;

/**
 * Helper class for Sonar specific requirements, like:
 * 
    *
  • generating a sonar pom file
  • *
  • generating sonar {@link Maven2Builder} command
  • *
* * @author Mark Rekveld */ public final class SonarPluginHelper { /** * The property prefix used for all Sonar properties saved in bamboo */ public static final String PROPERTY_PREFIX = "custom."; /** * The Sonar project key build meta data key */ public static final String SONAR_PROJECT_KEY = PROPERTY_PREFIX + "sonar.project.key"; /** * The Sonar Analysis execution state build meta data key */ public static final String SONAR_BUILD_STATE_KEY = PROPERTY_PREFIX + "sonar.build.state"; /** * Sonar log artifact name */ public static final String SONAR_ARTIFACT_LABEL = "Sonar Analysis Log (System)"; /** * Sonar log artifact copy pattern used by the ArtifactManager */ public static final String SONAR_ARTIFACT_COPY_PATTERN = "sonar-log.log"; /** * Sonar log artifact source directory used by the ArtifactManager */ public static final String SONAR_ARTIFACT_SRC_DIRECTORY = ""; /** * The Sonar Analysis Log artifact */ public static final Artifact SONAR_LOG_ARTIFACT = new DefaultArtifact(SONAR_ARTIFACT_LABEL, SONAR_ARTIFACT_COPY_PATTERN, SONAR_ARTIFACT_SRC_DIRECTORY); /** * Sonar Server Build Plan property */ public static final String SONAR_SERVER = PROPERTY_PREFIX + "sonar.server"; /** * Build Specific Sonar server property value */ public static final String BUILD_PLAN_SPECIFIC = "buildPlanSpecific"; /** * Property used to store the generated CI URL */ public static final String SONAR_CI_URL = PROPERTY_PREFIX + "sonar.ci.url"; /** * Sonar Run Build Plan property */ public static final String SONAR_RUN = PROPERTY_PREFIX + "sonar.run"; /** * Sonar Host URL Build Plan property */ public static final String SONAR_HOST_URL = PROPERTY_PREFIX + "sonar.host.url"; /** * Sonar Host Username Build Plan property */ public static final String SONAR_HOST_USERNAME = PROPERTY_PREFIX + "sonar.host.username"; /** * Sonar Host Password Build Plan property */ public static final String SONAR_HOST_PASSWORD = PROPERTY_PREFIX + "sonar.host.password"; /** * Sonar JDBC URL Build Plan property */ public static final String SONAR_JDBC_URL = PROPERTY_PREFIX + "sonar.jdbc.url"; /** * Sonar JDBC Driver Build Plan property */ public static final String SONAR_JDBC_DRIVER = PROPERTY_PREFIX + "sonar.jdbc.driver"; /** * Sonar JDBC Username Build Plan property */ public static final String SONAR_JDBC_USERNAME = PROPERTY_PREFIX + "sonar.jdbc.username"; /** * Sonar JDBC Password Build Plan property */ public static final String SONAR_JDBC_PASSWORD = PROPERTY_PREFIX + "sonar.jdbc.password"; /** * Sonar goal property, lists the properties used in the Maven execution command */ public static final Map SONAR_GOAL_PROPERTIES = new HashMap(); /** * Sonar Hidden properties, an array of Sonar properties of which the value needs to be hidden in the Maven command */ public static final String[] SONAR_HIDDEN_PROPERTIES = new String[] { SONAR_JDBC_USERNAME.substring(PROPERTY_PREFIX.length()), SONAR_JDBC_PASSWORD.substring(PROPERTY_PREFIX.length()) }; /** * Sonar property used for source hidding feature of Sonar * * @see http://docs.codehaus.org/display/SONAR/Advanced+parameters#Advancedparameters-Hidesources */ public static final String SONAR_IMPORT_SOURCES = PROPERTY_PREFIX + "sonar.import.sources"; /** * Sonar property used for branch support * * @see http://docs.codehaus.org/display/SONAR/Advanced+parameters#Advancedparameters-ManageSCMBranches */ public static final String SONAR_BRANCH = PROPERTY_PREFIX + "sonar.branch"; /** * Sonar property used for skipping modules * * @see http://docs.codehaus.org/display/SONAR/Advanced+parameters#Advancedparameters-Excludemodules */ public static final String SONAR_SKIPPED_MODULES = PROPERTY_PREFIX + "sonar.skipped.modules"; /** * Sonar property used for excluding resources * * @see http://docs.codehaus.org/display/SONAR/Advanced+parameters#Advancedparameters-Excluderesources */ public static final String SONAR_EXCLUSIONS = PROPERTY_PREFIX + "sonar.exclusions"; /** * Sonar property used for Quality Profile * * @see http://docs.codehaus.org/display/SONAR/Advanced+parameters#Advancedparameters-Definethequalityprofiletobeused */ public static final String SONAR_PROFILE = PROPERTY_PREFIX + "sonar.profile"; /** * Sonar property used for reusing already generated reports of Clover, Cobertura, Surefire, etc. */ public static final String SONAR_REUSE_REPORTS = PROPERTY_PREFIX + "sonar.reusereports"; /** * Sonar property used for to deactivate bytecode analysis * * @see http://docs.codehaus.org/display/SONAR/Advanced+parameters#Advancedparameters-Advancedparameters-Deactivatingbytecodeanalysis */ public static final String SONAR_SKIP_BYTECODE_ANALYSIS = PROPERTY_PREFIX + "sonar.skip.bytecode.analysis"; /** * Property used to define the JDK version to use for the analysis */ public static final String SONAR_BUILD_JDK = PROPERTY_PREFIX + "sonar.build.jdk"; /** * Property used as value for the SONAR_BUILD_JDK property to define that the build JDK must be used. */ public static final String SONAR_BUILD_JDK_DEFAULT = "Reuse Build Defined JDK"; /** * Property used to specify extra MAVEN_OPTS value */ public static final String SONAR_MAVEN_OPTS = PROPERTY_PREFIX + "sonar.maven.opts"; /** * Property used to specify extra Sonar arguments */ public static final String SONAR_ADD_ARGS = PROPERTY_PREFIX + "sonar.add.args"; /** * Property used to indicate if the Sonar globals need to be overridden */ public static final String SONAR_OVERRIDE_GLOBALS = PROPERTY_PREFIX + "sonar.override.globals"; /** * Property to indicate if a the analysis needs to be skipped if the main build had failed */ public static final String SONAR_SKIP_ON_BUILD_FAILURE = PROPERTY_PREFIX + "sonar.skip.build.failure"; /** * Property to indicate if a the analysis needs to be skipped if the main build was triggered manually */ public static final String SONAR_SKIP_ON_MANUAL_BUILD = PROPERTY_PREFIX + "sonar.skip.manual.build"; /** * Property to indicate if a the analysis needs to be skipped if the main build has no code changes */ public static final String SONAR_SKIP_ON_NO_CODE_CHANGES = PROPERTY_PREFIX + "sonar.skip.no.code.changes"; /** * Property to specify the failure behavior of the Sonar Analysis build */ public static final String SONAR_FAILURE_BEHAVIOR = PROPERTY_PREFIX + "sonar.failure.behavior"; /** * The IGNORE failure behavior, no action will be taken by the plugin if the analysis build fails */ public static final String SONAR_IGNORE_BEHAVIOR = "ignore"; /** * The FAIL failure behavior, in case the Sonar Analysis fails the main build will be set to status FAILED */ public static final String SONAR_FAIL_BEHAVIOR = "fail"; /** * The LABEL failure behavior, in case the Sonar Analysis fails the main build will be labeled to indicate that * the Sonar Analysis has failed. */ public static final String SONAR_LABEL_BEHAVIOR = "label"; /** * Array containing all the Failure behavior values */ public static final String[] SONAR_FAILURE_BEHAVIORS = { SONAR_IGNORE_BEHAVIOR, SONAR_FAIL_BEHAVIOR, SONAR_LABEL_BEHAVIOR }; /** * Property to indicate if Sonar Light feature needs to be used for the Analysis */ public static final String SONAR_LIGHT = PROPERTY_PREFIX + "sonar.light.run"; /** * The Maven Project GroupdId property key to use when using Sonar Light */ public static final String SONAR_LIGHT_GROUPID = PROPERTY_PREFIX + "sonar.light.groupId"; /** * The Maven Project ArtifactId property key to use when using Sonar Light */ public static final String SONAR_LIGHT_ARTIFACTID = PROPERTY_PREFIX + "sonar.light.artifactId"; /** * The Maven Project Version property key to use when using Sonar Light */ public static final String SONAR_LIGHT_VERSION = PROPERTY_PREFIX + "sonar.light.version"; /** * The Maven Project Name property key to use when using Sonar Light */ public static final String SONAR_LIGHT_NAME = PROPERTY_PREFIX + "sonar.light.name"; /** * The Maven Project Description property key to use when using Sonar Light */ public static final String SONAR_LIGHT_DESCRIPTION = PROPERTY_PREFIX + "sonar.light.description"; /** * The Maven Project Sources property key to use when using Sonar Light, may be a comma separated list of source * directories */ public static final String SONAR_LIGHT_SOURCES = PROPERTY_PREFIX + "sonar.light.sources"; /** * The Maven Project build directory property key to use when using Sonar Light */ public static final String SONAR_LIGHT_TARGET = PROPERTY_PREFIX + "sonar.light.target"; /** * The JDK Version of the sources property key to use when using Sonar Light */ public static final String SONAR_LIGHT_JDK = PROPERTY_PREFIX + "sonar.light.jdk"; /** * The Sonar Light POM filename */ public static final String SONAR_LIGHT_POM = "sonar-pom.xml"; /** * Common Key used by Bamboo builders to indicate if tests are executed */ public static final String BUILDER_HAS_TESTS = "testChecked"; /** * Common Key used by Bamboo builders to indicate the directory where the test results are located */ public static final String BUILDER_TESTS_PATH = "testResultsDirectory"; /** * Bamboo Key used to indicate if Clover is running in the build */ public static final String CLOVER_EXISTS = PROPERTY_PREFIX + "clover.exists"; /** * Bamboo Key used to indicate the path where the Clover artifacts are located */ public static final String CLOVER_PATH = PROPERTY_PREFIX + "clover.path"; /** * Bamboo Key used to indicate if Cobertura is running in the build */ public static final String COBERTURA_EXISTS = PROPERTY_PREFIX + "cobertura.exists"; /** * Bamboo Key used to indicate the path where the Coberture artifacts are located */ public static final String COBERTURA_PATH = PROPERTY_PREFIX + "cobertura.path"; /** * {@link Map} of SCM systems that are supported by the plugin to generate the SCM URL used for the SCM Activity * Plugin * * @see http://docs.codehaus.org/display/SONAR/SCM+Activity+Plugin */ public static final Map SUPPORTED_SCM_SYSTEMS = new HashMap(); private static final Logger LOGGER = Logger.getLogger(SonarPluginHelper.class); private static final Pattern ALTERNATE_POM_PATTERN = Pattern.compile("\\s*(-f|--file)\\s+"); static { SONAR_GOAL_PROPERTIES.put(SONAR_HOST_URL, "http://localhost:9000/"); SONAR_GOAL_PROPERTIES.put(SONAR_JDBC_URL, ""); SONAR_GOAL_PROPERTIES.put(SONAR_JDBC_DRIVER, ""); SONAR_GOAL_PROPERTIES.put(SONAR_JDBC_USERNAME, "sonar"); SONAR_GOAL_PROPERTIES.put(SONAR_JDBC_PASSWORD, "sonar"); SUPPORTED_SCM_SYSTEMS.put("repository.svn.repositoryUrl", "svn"); SUPPORTED_SCM_SYSTEMS.put("repository.cvs.cvsRoot", "cvs"); } /** * Generate the Sonar Light pom.xml and write it to the given repository directory * * @param repositoryDirectory the source repository {@link File} directory * @param customConfiguration the custom configuration of the Build * @throws IOException in case the generated sonar-pom.xml file cannot be written to the repository directory */ @SuppressWarnings("unchecked") public void generateSonarLightPom(@NotNull File repositoryDirectory, @NotNull Map customConfiguration) throws IOException { final Model model = new Model(); model.setModelVersion("4.0.0"); model.setGroupId(customConfiguration.get(SONAR_LIGHT_GROUPID)); model.setArtifactId(customConfiguration.get(SONAR_LIGHT_ARTIFACTID)); if (StringUtils.isNotBlank(customConfiguration.get(SONAR_LIGHT_VERSION))) { model.setVersion(customConfiguration.get(SONAR_LIGHT_VERSION)); } else { model.setVersion("1.0"); } model.setName(customConfiguration.get(SONAR_LIGHT_NAME)); if (StringUtils.isNotBlank(customConfiguration.get(SONAR_LIGHT_DESCRIPTION))) { model.setDescription(customConfiguration.get(SONAR_LIGHT_DESCRIPTION)); } for (Entry scmSystem : SUPPORTED_SCM_SYSTEMS.entrySet()) { if (customConfiguration.containsKey(scmSystem.getKey())) { model.setScm(new Scm()); model.getScm().setUrl(customConfiguration.get(scmSystem.getKey())); model.getScm().setConnection( "scm:" + scmSystem.getValue() + ":" + customConfiguration.get(scmSystem.getKey())); model.getScm().setDeveloperConnection(model.getScm().getConnection()); break; } } if (customConfiguration.containsKey(SONAR_CI_URL) && StringUtils.isNotBlank(customConfiguration.get(SONAR_CI_URL))) { model.setCiManagement(new CiManagement()); model.getCiManagement().setSystem("Bamboo"); model.getCiManagement().setUrl(customConfiguration.get(SONAR_CI_URL)); } model.setBuild(new Build()); final List sourceDirectories = Arrays.asList(customConfiguration.get(SONAR_LIGHT_SOURCES).split(", ")); model.getBuild().setSourceDirectory(sourceDirectories.get(0)); model.getBuild().setOutputDirectory(customConfiguration.get(SONAR_LIGHT_TARGET)); if (sourceDirectories.size() > 1) { final Plugin sourcesPlugin = new Plugin(); sourcesPlugin.setGroupId("org.codehaus.mojo"); sourcesPlugin.setArtifactId("build-helper-maven-plugin"); sourcesPlugin.setVersion("1.1"); final PluginExecution execution = new PluginExecution(); execution.setId("add-source"); execution.setPhase("generate-sources"); execution.setGoals(Collections.singletonList("add-source")); final Xpp3Dom configuration = new Xpp3Dom("configuration"); final Xpp3Dom sources = new Xpp3Dom("sources"); for (int i = 1; i < sourceDirectories.size(); i++) { final Xpp3Dom source = new Xpp3Dom("source"); source.setValue(sourceDirectories.get(i)); sources.addChild(source); } configuration.addChild(sources); execution.setConfiguration(configuration); sourcesPlugin.getExecutions().add(execution); model.getBuild().getPlugins().add(sourcesPlugin); } String jdkVersion = "1.5"; if (StringUtils.isNotBlank(customConfiguration.get(SONAR_LIGHT_JDK))) { jdkVersion = customConfiguration.get(SONAR_LIGHT_JDK); } final Plugin compiler = new Plugin(); compiler.setArtifactId("maven-compiler-plugin"); final Xpp3Dom configuration = new Xpp3Dom("configuration"); final Xpp3Dom source = new Xpp3Dom("source"); source.setValue(jdkVersion); configuration.addChild(source); final Xpp3Dom target = new Xpp3Dom("target"); target.setValue(jdkVersion); configuration.addChild(target); compiler.setConfiguration(configuration); model.getBuild().getPlugins().add(compiler); final MavenXpp3Writer pomWriter = new MavenXpp3Writer(); Writer fileWriter = null; try { fileWriter = WriterFactory.newXmlWriter(new File(repositoryDirectory, SONAR_LIGHT_POM)); pomWriter.write(fileWriter, model); } finally { IOUtil.close(fileWriter); } } /** * Generate the Sonar goals and arguments for the {@link Maven2Builder} * * @param configuration the {@link Map} containing the custom configuration of the current Build Plan * @return the Sonar goals and arguments for the {@link Maven2Builder} */ @NotNull public String generateSonarGoals(@NotNull Map configuration) { final StringBuilder goalsBuilder = new StringBuilder(); goalsBuilder.append("-B"); if (Boolean.parseBoolean((String) configuration.get(SONAR_LIGHT))) { goalsBuilder.append(" --file " + SONAR_LIGHT_POM); } for (Entry property : SONAR_GOAL_PROPERTIES.entrySet()) { final String propertyName = property.getKey().substring(PROPERTY_PREFIX.length()); if (StringUtils.isNotBlank(configuration.get(property.getKey()))) { goalsBuilder.append(" -D" + propertyName + "=" + configuration.get(property.getKey())); } else if (StringUtils.isNotBlank(property.getValue())) { goalsBuilder.append(" -D" + propertyName + "=" + property.getValue()); } } if (Boolean.parseBoolean((String) configuration.get(SONAR_REUSE_REPORTS))) { goalsBuilder.append(" -Dsonar.dynamicAnalysis=reuseReports"); } for (Entry entry : configuration.entrySet()) { if (entry.getKey().endsWith(BUILDER_HAS_TESTS) && Boolean.parseBoolean(entry.getValue())) { final String pathKey = entry.getKey().replace(BUILDER_HAS_TESTS, BUILDER_TESTS_PATH); goalsBuilder.append(" -Dsonar.surefire.reportsPath=\"" + configuration.get(pathKey) + "\""); break; } } if (Boolean.parseBoolean((String) configuration.get(COBERTURA_EXISTS))) { goalsBuilder.append(" -Dsonar.cobertura.reportPath=\"" + configuration.get(COBERTURA_PATH) + "\""); } if (Boolean.parseBoolean((String) configuration.get(CLOVER_EXISTS))) { goalsBuilder.append(" -Dsonar.clover.reportPath=\"" + configuration.get(CLOVER_PATH) + "\""); } if (Boolean.parseBoolean((String) configuration.get(SONAR_IMPORT_SOURCES))) { goalsBuilder.append(" -Dsonar.importSources=false"); } if (StringUtils.isNotBlank((String) configuration.get(SONAR_BRANCH))) { goalsBuilder.append(" -Dsonar.branch=\"" + configuration.get(SONAR_BRANCH) + "\""); } if (StringUtils.isNotBlank((String) configuration.get(SONAR_SKIPPED_MODULES))) { goalsBuilder.append(" -Dsonar.skippedModules=\"" + configuration.get(SONAR_SKIPPED_MODULES) + "\""); } if (StringUtils.isNotBlank((String) configuration.get(SONAR_EXCLUSIONS))) { goalsBuilder.append(" -Dsonar.exclusions=\"" + configuration.get(SONAR_EXCLUSIONS) + "\""); } if (Boolean.parseBoolean((String) configuration.get(SONAR_SKIP_BYTECODE_ANALYSIS))) { goalsBuilder.append(" -Dsonar.skipDesign=true"); } if (StringUtils.isNotBlank((String) configuration.get(SONAR_PROFILE))) { goalsBuilder.append(" -Dsonar.profile=\"" + configuration.get(SONAR_PROFILE) + "\""); } if (StringUtils.isNotBlank(configuration.get(SONAR_ADD_ARGS))) { goalsBuilder.append(" " + configuration.get(SONAR_ADD_ARGS)); } goalsBuilder.append(" sonar:sonar"); LOGGER.debug("Generated provided configuration to Sonar goals: " + goalsBuilder.toString()); return goalsBuilder.toString(); } /** * Copy the {@link BambooSonarServer} configuration to the given {@link BuildPlanDefinition} * * @param server the {@link BambooSonarServer} configuration to copy * @param buildDefinition the {@link BuildPlanDefinition} to copy the configuration to */ public void copySonarServerToBuildPlanDefinition(BambooSonarServer server, BuildPlanDefinition buildDefinition) { buildDefinition.getCustomConfiguration().put(SONAR_HOST_URL, server.getHost()); buildDefinition.getCustomConfiguration().put(SONAR_JDBC_URL, server.getDatabaseUrl()); buildDefinition.getCustomConfiguration().put(SONAR_JDBC_DRIVER, server.getDatabaseDriver()); buildDefinition.getCustomConfiguration().put(SONAR_JDBC_USERNAME, server.getDatabaseUsername()); buildDefinition.getCustomConfiguration().put(SONAR_JDBC_PASSWORD, server.getDatabasePassword()); String planAddArgs = buildDefinition.getCustomConfiguration().get(SONAR_ADD_ARGS); // Fix for Issue MARVBAMBOOSONAR-15: the server additional arguments should only be added if they are not in // the plan additional arguments if (StringUtils.isBlank(planAddArgs)) { planAddArgs = ""; } if (!planAddArgs.contains(server.getAdditionalArguments())) { buildDefinition.getCustomConfiguration().put(SONAR_ADD_ARGS, (planAddArgs + " " + server.getAdditionalArguments()).trim()); } } /** * Get the Sonar project key from the {@link BuildContext} * * @param buildContext the {@link BuildContext} to get the project key from * @return the Sonar project key */ public String getSonarProjectKeyFromBuildContext(BuildContext buildContext) { final MavenXpp3Reader reader = new MavenXpp3Reader(); String filename = null; if (buildContext.getBuildPlanDefinition().getBuilderV2() instanceof Maven2Builder) { final Maven2Builder builder = (Maven2Builder) buildContext.getBuildPlanDefinition().getBuilderV2(); if ("".equals(builder.getProjectFile())) { filename = builder.getProjectFile(); } else { filename = getPomFilenameFromGoals(builder.getGoal()); } } else { filename = SONAR_LIGHT_POM; } FileReader fileInput = null; try { if (StringUtils.isBlank(filename)) { filename = "pom.xml"; } fileInput = new FileReader(new File(buildContext.getBuildPlanDefinition() .getRepositoryV2().getSourceCodeDirectory(buildContext.getPlanKey()), filename)); final Model model = reader.read(fileInput); return model.getGroupId() + ":" + model.getArtifactId(); } catch (FileNotFoundException e) { LOGGER.error("Could not find POM file: " + filename, e); } catch (IOException e) { LOGGER.error("Failed to read POM file: " + filename, e); } catch (XmlPullParserException e) { LOGGER.error("Failed to parse POM file: " + filename, e); } catch (RepositoryException e) { LOGGER.error("Failed to get the Source repository for the Build Plan", e); } finally { IOUtils.closeQuietly(fileInput); } return ""; } /** * Get the SonarProject key from the {@link com.atlassian.bamboo.build.Build} results data * * @param build the {@link com.atlassian.bamboo.build.Build} to get the Sonar Project key from * @return the Sonar Project key, may be blank */ @SuppressWarnings("unchecked") public String getSonarProjectFromBuildResultsData(com.atlassian.bamboo.build.Build build) { String sonarProject = ""; for (final ExtendedBuildResultsSummary result : (List) build.getBuildResultSummaries()) { if (StringUtils.isNotBlank(result.getCustomBuildData().get(SonarPluginHelper.SONAR_PROJECT_KEY))) { sonarProject = result.getCustomBuildData().get(SonarPluginHelper.SONAR_PROJECT_KEY); } } return sonarProject; } /** * Get the POM filename from the goals given * * @param goals the Maven 2 goals to get the POM filename from * @return the POM filename, may be null in which case the default pom.xml is used */ public String getPomFilenameFromGoals(String goals) { if (goals == null) { return null; } final Matcher matcher = ALTERNATE_POM_PATTERN.matcher(goals); if (matcher.find()) { final String[] options = goals.split("\\s"); for (int i = 0; i < options.length; i++) { if ("-f".equals(options[i]) || "--file".equals(options[i])) { return options[i + 1]; } } } return null; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy