Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
<name>Julien Henry</name>
<timezone>+1</timezone>
</developer>
<developer>
<id>fabdouglas</id>
<name>Fabrice Daugan</name>
<timezone>+1</timezone>
</developer>
</developers>

<scm>
Expand All @@ -57,9 +62,9 @@
<properties>
<sonar.pluginName>Build Stability</sonar.pluginName>
<sonar.pluginClass>org.sonar.plugins.buildstability.BuildStabilityPlugin</sonar.pluginClass>
<sonar.version>4.5.2</sonar.version>
<sonar.version>4.5.4</sonar.version>
</properties>

<dependencies>
<dependency>
<groupId>org.codehaus.sonar</groupId>
Expand Down Expand Up @@ -90,6 +95,10 @@
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
</exclusions>
</dependency>

Expand Down
103 changes: 103 additions & 0 deletions src/main/java/org/sonar/plugins/buildstability/BuildAsString.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Sonar Build Stability Plugin
* Copyright (C) 2010 SonarSource
* [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.plugins.buildstability;

import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.sonar.plugins.buildstability.ci.api.Build;
import org.sonar.plugins.buildstability.ci.api.Status;

/**
* Building or serializing {@link Build} as raw String.
*
* @author Fabrice Daugan
*/
public class BuildAsString {

public static final char BUILD_SEPARATOR = ';';
public static final char PROPERTY_SEPARATOR = ',';

/**
* Return a map where {@link Build} ordered by build number from the input string. Using {@value #BUILD_SEPARATOR} as
* build separator, and {@value #PROPERTY_SEPARATOR} as property separator.
*
* @param buildsAsData
* String representation of a list of builds.
* @return the list of {@link Build} objects from a string.
*/
public Map<Integer, Build> toBuilds(final String buildsAsData) {
final Map<Integer, Build> result = new TreeMap<Integer, Build>();
for (final String buildAsString : StringUtils.split(buildsAsData, BUILD_SEPARATOR)) {
final Build build = toBuild(buildAsString);
result.put(build.getNumber(), build);
}
return result;
}

/**
* Return {@link Build} from the input string. Using {@value #PROPERTY_SEPARATOR} as property separator. Timestamp and
* duration are truncated to save memory.
*
* @param buildAsString
* String representation of a a build.
* @return the {@link Build} object from a string.
*/
public Build toBuild(String buildAsString) {
final Build build = new Build();
final String[] properties = StringUtils.split(buildAsString, PROPERTY_SEPARATOR);
build.setNumber(Integer.parseInt(properties[0]));
build.setTimestamp(Long.parseLong(properties[1]) * DateUtils.MILLIS_PER_SECOND);
build.setStatus(Status.values()[Integer.parseInt(properties[2])]);
build.setDuration(Long.parseLong(properties[3]) * DateUtils.MILLIS_PER_SECOND);
return build;
}

/**
* Return the {@link String} representation of given builds. Corresponds to the opposite of {@link #toBuilds(String)}.
*
* @param builds
* the builds to serialize as String.
* @return the {@link String} representation of builds.
*/
public String toString(final Collection<Build> builds) {
final StringBuilder result = new StringBuilder();
for (final Build build : builds) {
append(build, result).append(BUILD_SEPARATOR);
}

// Remove the trailing separator
result.setLength(Math.max(0, result.length() - 1));
return result.toString();
}

/**
* Append the given build's properties.
*/
protected StringBuilder append(final Build build, final StringBuilder result) {
result.append(build.getNumber()).append(PROPERTY_SEPARATOR);
result.append(build.getTimestamp() / DateUtils.MILLIS_PER_SECOND).append(PROPERTY_SEPARATOR);
result.append(build.getStatus().ordinal()).append(PROPERTY_SEPARATOR);
return result.append(build.getDuration() / DateUtils.MILLIS_PER_SECOND);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,15 @@ public class BuildStabilityMetrics implements Metrics {
.setDomain(DOMAIN_BUILD)
.create();

public static final Metric<String> DURATIONS = new Metric.Builder("build_durations", "Durations", Metric.ValueType.DATA)
.setDescription("Durations")
.setDirection(Metric.DIRECTION_NONE)
.setQualitative(false)
.setDomain(DOMAIN_BUILD)
.create();

public static final Metric<String> RESULTS = new Metric.Builder("build_results", "Results", Metric.ValueType.DATA)
.setDescription("Results")
public static final Metric<String> BUILDS_DETAILS = new Metric.Builder("build_details", "Builds", Metric.ValueType.DATA)
.setDescription("Builds details used to computes indicators")
.setDirection(Metric.DIRECTION_NONE)
.setQualitative(false)
.setDomain(DOMAIN_BUILD)
.setHidden(true)
.create();

@SuppressWarnings("rawtypes")
@Override
public List<Metric> getMetrics() {
return Arrays.<Metric>asList(
Expand All @@ -160,7 +155,6 @@ public List<Metric> getMetrics() {
LONGEST_TIME_TO_FIX,
AVG_BUILDS_TO_FIX,

DURATIONS,
RESULTS);
BUILDS_DETAILS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
*/
package org.sonar.plugins.buildstability;

import org.sonar.api.Extension;
import org.sonar.api.Properties;
import org.sonar.api.Property;
import org.sonar.api.SonarPlugin;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -34,7 +35,7 @@
key = BuildStabilitySensor.DAYS_PROPERTY,
defaultValue = BuildStabilitySensor.DAYS_DEFAULT_VALUE + "",
name = "Days",
description = "Number of days to analyze.",
description = "Number of days to keep results.",
global = true,
project = true,
module = false
Expand Down Expand Up @@ -79,12 +80,13 @@
)
})
public class BuildStabilityPlugin extends SonarPlugin {

@Override
public List getExtensions() {
return Arrays.asList(
BuildStabilityMetrics.class,
BuildStabilitySensor.class,
BuildStabilityWidget.class,
BuildStabilityChart.class);
public List<Class<? extends Extension>> getExtensions() {
final List<Class<? extends Extension>> extensions = new ArrayList<Class<? extends Extension>>();
extensions.add(BuildStabilityMetrics.class);
extensions.add(BuildStabilitySensor.class);
extensions.add(BuildStabilityWidget.class);
return extensions;
}
}
Loading