@@ -14,7 +14,6 @@ | |||
<modules> | |||
<module>sonar-application</module> | |||
<module>sonar-batch</module> | |||
<module>sonar-batch-plugin-api</module> | |||
<module>sonar-batch-maven-compat</module> | |||
<module>sonar-check-api</module> | |||
<module>sonar-colorizer</module> | |||
@@ -575,11 +574,6 @@ | |||
<artifactId>sonar-plugin-api</artifactId> | |||
<version>${project.version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.codehaus.sonar</groupId> | |||
<artifactId>sonar-batch-plugin-api</artifactId> | |||
<version>${project.version}</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.codehaus.sonar</groupId> | |||
<artifactId>sonar-update-center-common</artifactId> |
@@ -1,34 +0,0 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |||
<modelVersion>4.0.0</modelVersion> | |||
<parent> | |||
<groupId>org.codehaus.sonar</groupId> | |||
<artifactId>sonar</artifactId> | |||
<version>4.4-SNAPSHOT</version> | |||
</parent> | |||
<artifactId>sonar-batch-plugin-api</artifactId> | |||
<packaging>jar</packaging> | |||
<name>SonarQube :: Batch Plugin API</name> | |||
<dependencies> | |||
<dependency> | |||
<groupId>com.google.code.findbugs</groupId> | |||
<artifactId>jsr305</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>junit</groupId> | |||
<artifactId>junit</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.easytesting</groupId> | |||
<artifactId>fest-assert</artifactId> | |||
</dependency> | |||
</dependencies> | |||
</project> |
@@ -1,107 +0,0 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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 02110-1301, USA. | |||
*/ | |||
package org.sonar.batch.api.analyzer; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.batch.api.measures.Metric; | |||
import java.util.Arrays; | |||
import java.util.Collection; | |||
public class AnalyzerDescriptor { | |||
private final String name; | |||
private final Metric<?>[] dependsOn; | |||
private final Metric<?>[] provides; | |||
private final String[] languages; | |||
private final InputFile.Type[] types; | |||
private AnalyzerDescriptor(Builder builder) { | |||
this.name = builder.name; | |||
this.dependsOn = builder.dependsOn != null ? builder.dependsOn : new Metric<?>[0]; | |||
this.provides = builder.provides != null ? builder.provides : new Metric<?>[0]; | |||
this.languages = builder.languages != null ? builder.languages : new String[0]; | |||
this.types = builder.types; | |||
} | |||
public String name() { | |||
return name; | |||
} | |||
public Metric<?>[] dependsOn() { | |||
return dependsOn; | |||
} | |||
public Metric<?>[] provides() { | |||
return provides; | |||
} | |||
public Collection<String> languages() { | |||
return Arrays.asList(languages); | |||
} | |||
public InputFile.Type[] types() { | |||
return types; | |||
} | |||
public static Builder builder() { | |||
return new Builder(); | |||
} | |||
public static class Builder { | |||
private String name; | |||
private Metric<?>[] dependsOn; | |||
private Metric<?>[] provides; | |||
private String[] languages; | |||
private InputFile.Type[] types; | |||
public Builder name(String name) { | |||
this.name = name; | |||
return this; | |||
} | |||
public Builder dependsOn(Metric<?>... metrics) { | |||
this.dependsOn = metrics; | |||
return this; | |||
} | |||
public Builder provides(Metric<?>... metrics) { | |||
this.provides = metrics; | |||
return this; | |||
} | |||
public Builder runOnLanguages(String... languageKeys) { | |||
this.languages = languageKeys; | |||
return this; | |||
} | |||
public Builder runOnTypes(InputFile.Type... types) { | |||
this.types = types; | |||
return this; | |||
} | |||
public AnalyzerDescriptor build() { | |||
return new AnalyzerDescriptor(this); | |||
} | |||
} | |||
} |
@@ -1,244 +0,0 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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 02110-1301, USA. | |||
*/ | |||
package org.sonar.batch.api.internal; | |||
import java.io.File; | |||
/** | |||
* Copied from commons io | |||
* | |||
*/ | |||
public class FilenameUtils { | |||
public static final char EXTENSION_SEPARATOR = '.'; | |||
private static final char UNIX_SEPARATOR = '/'; | |||
/** | |||
* The Windows separator character. | |||
*/ | |||
private static final char WINDOWS_SEPARATOR = '\\'; | |||
/** | |||
* The system separator character. | |||
*/ | |||
private static final char SYSTEM_SEPARATOR = File.separatorChar; | |||
/** | |||
* The separator character that is the opposite of the system separator. | |||
*/ | |||
private static final char OTHER_SEPARATOR; | |||
static { | |||
if (isSystemWindows()) { | |||
OTHER_SEPARATOR = UNIX_SEPARATOR; | |||
} else { | |||
OTHER_SEPARATOR = WINDOWS_SEPARATOR; | |||
} | |||
} | |||
static boolean isSystemWindows() { | |||
return SYSTEM_SEPARATOR == WINDOWS_SEPARATOR; | |||
} | |||
public static String normalize(String filename) { | |||
return doNormalize(filename, UNIX_SEPARATOR, true); | |||
} | |||
private static String doNormalize(String filename, char separator, boolean keepSeparator) { | |||
if (filename == null) { | |||
return null; | |||
} | |||
int size = filename.length(); | |||
if (size == 0) { | |||
return filename; | |||
} | |||
int prefix = getPrefixLength(filename); | |||
if (prefix < 0) { | |||
return null; | |||
} | |||
char[] array = new char[size + 2]; // +1 for possible extra slash, +2 for arraycopy | |||
filename.getChars(0, filename.length(), array, 0); | |||
// fix separators throughout | |||
char otherSeparator = separator == SYSTEM_SEPARATOR ? OTHER_SEPARATOR : SYSTEM_SEPARATOR; | |||
for (int i = 0; i < array.length; i++) { | |||
if (array[i] == otherSeparator) { | |||
array[i] = separator; | |||
} | |||
} | |||
// add extra separator on the end to simplify code below | |||
boolean lastIsDirectory = true; | |||
if (array[size - 1] != separator) { | |||
array[size++] = separator; | |||
lastIsDirectory = false; | |||
} | |||
// adjoining slashes | |||
for (int i = prefix + 1; i < size; i++) { | |||
if (array[i] == separator && array[i - 1] == separator) { | |||
System.arraycopy(array, i, array, i - 1, size - i); | |||
size--; | |||
i--; | |||
} | |||
} | |||
// dot slash | |||
for (int i = prefix + 1; i < size; i++) { | |||
if (array[i] == separator && array[i - 1] == '.' && | |||
(i == prefix + 1 || array[i - 2] == separator)) { | |||
if (i == size - 1) { | |||
lastIsDirectory = true; | |||
} | |||
System.arraycopy(array, i + 1, array, i - 1, size - i); | |||
size -= 2; | |||
i--; | |||
} | |||
} | |||
// double dot slash | |||
outer: for (int i = prefix + 2; i < size; i++) { | |||
if (array[i] == separator && array[i - 1] == '.' && array[i - 2] == '.' && | |||
(i == prefix + 2 || array[i - 3] == separator)) { | |||
if (i == prefix + 2) { | |||
return null; | |||
} | |||
if (i == size - 1) { | |||
lastIsDirectory = true; | |||
} | |||
int j; | |||
for (j = i - 4; j >= prefix; j--) { | |||
if (array[j] == separator) { | |||
// remove b/../ from a/b/../c | |||
System.arraycopy(array, i + 1, array, j + 1, size - i); | |||
size -= i - j; | |||
i = j + 1; | |||
continue outer; | |||
} | |||
} | |||
// remove a/../ from a/../c | |||
System.arraycopy(array, i + 1, array, prefix, size - i); | |||
size -= i + 1 - prefix; | |||
i = prefix + 1; | |||
} | |||
} | |||
if (size <= 0) { // should never be less than 0 | |||
return ""; | |||
} | |||
if (size <= prefix) { // should never be less than prefix | |||
return new String(array, 0, size); | |||
} | |||
if (lastIsDirectory && keepSeparator) { | |||
return new String(array, 0, size); // keep trailing separator | |||
} | |||
return new String(array, 0, size - 1); // lose trailing separator | |||
} | |||
public static int getPrefixLength(String filename) { | |||
if (filename == null) { | |||
return -1; | |||
} | |||
int len = filename.length(); | |||
if (len == 0) { | |||
return 0; | |||
} | |||
char ch0 = filename.charAt(0); | |||
if (ch0 == ':') { | |||
return -1; | |||
} | |||
if (len == 1) { | |||
if (ch0 == '~') { | |||
return 2; // return a length greater than the input | |||
} | |||
return isSeparator(ch0) ? 1 : 0; | |||
} else { | |||
if (ch0 == '~') { | |||
int posUnix = filename.indexOf(UNIX_SEPARATOR, 1); | |||
int posWin = filename.indexOf(WINDOWS_SEPARATOR, 1); | |||
if (posUnix == -1 && posWin == -1) { | |||
return len + 1; // return a length greater than the input | |||
} | |||
posUnix = posUnix == -1 ? posWin : posUnix; | |||
posWin = posWin == -1 ? posUnix : posWin; | |||
return Math.min(posUnix, posWin) + 1; | |||
} | |||
char ch1 = filename.charAt(1); | |||
if (ch1 == ':') { | |||
ch0 = Character.toUpperCase(ch0); | |||
if (ch0 >= 'A' && ch0 <= 'Z') { | |||
if (len == 2 || isSeparator(filename.charAt(2)) == false) { | |||
return 2; | |||
} | |||
return 3; | |||
} | |||
return -1; | |||
} else if (isSeparator(ch0) && isSeparator(ch1)) { | |||
int posUnix = filename.indexOf(UNIX_SEPARATOR, 2); | |||
int posWin = filename.indexOf(WINDOWS_SEPARATOR, 2); | |||
if (posUnix == -1 && posWin == -1 || posUnix == 2 || posWin == 2) { | |||
return -1; | |||
} | |||
posUnix = posUnix == -1 ? posWin : posUnix; | |||
posWin = posWin == -1 ? posUnix : posWin; | |||
return Math.min(posUnix, posWin) + 1; | |||
} else { | |||
return isSeparator(ch0) ? 1 : 0; | |||
} | |||
} | |||
} | |||
private static boolean isSeparator(char ch) { | |||
return ch == UNIX_SEPARATOR || ch == WINDOWS_SEPARATOR; | |||
} | |||
public static String getExtension(String filename) { | |||
if (filename == null) { | |||
return null; | |||
} | |||
int index = indexOfExtension(filename); | |||
if (index == -1) { | |||
return ""; | |||
} else { | |||
return filename.substring(index + 1); | |||
} | |||
} | |||
public static int indexOfExtension(String filename) { | |||
if (filename == null) { | |||
return -1; | |||
} | |||
int extensionPos = filename.lastIndexOf(EXTENSION_SEPARATOR); | |||
int lastSeparator = indexOfLastSeparator(filename); | |||
return lastSeparator > extensionPos ? -1 : extensionPos; | |||
} | |||
public static int indexOfLastSeparator(String filename) { | |||
if (filename == null) { | |||
return -1; | |||
} | |||
int lastUnixPos = filename.lastIndexOf(UNIX_SEPARATOR); | |||
int lastWindowsPos = filename.lastIndexOf(WINDOWS_SEPARATOR); | |||
return Math.max(lastUnixPos, lastWindowsPos); | |||
} | |||
} |
@@ -1,413 +0,0 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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 02110-1301, USA. | |||
*/ | |||
package org.sonar.batch.api.internal; | |||
import javax.annotation.Nullable; | |||
/** | |||
* Copied from Guava | |||
*/ | |||
public final class Preconditions { | |||
private Preconditions() { | |||
} | |||
/** | |||
* Ensures the truth of an expression involving one or more parameters to the | |||
* calling method. | |||
* | |||
* @param expression a boolean expression | |||
* @throws IllegalArgumentException if {@code expression} is false | |||
*/ | |||
public static void checkArgument(boolean expression) { | |||
if (!expression) { | |||
throw new IllegalArgumentException(); | |||
} | |||
} | |||
/** | |||
* Ensures the truth of an expression involving one or more parameters to the | |||
* calling method. | |||
* | |||
* @param expression a boolean expression | |||
* @param errorMessage the exception message to use if the check fails; will | |||
* be converted to a string using {@link String#valueOf(Object)} | |||
* @throws IllegalArgumentException if {@code expression} is false | |||
*/ | |||
public static void checkArgument( | |||
boolean expression, @Nullable Object errorMessage) { | |||
if (!expression) { | |||
throw new IllegalArgumentException(String.valueOf(errorMessage)); | |||
} | |||
} | |||
/** | |||
* Ensures the truth of an expression involving one or more parameters to the | |||
* calling method. | |||
* | |||
* @param expression a boolean expression | |||
* @param errorMessageTemplate a template for the exception message should the | |||
* check fail. The message is formed by replacing each {@code %s} | |||
* placeholder in the template with an argument. These are matched by | |||
* position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc. | |||
* Unmatched arguments will be appended to the formatted message in square | |||
* braces. Unmatched placeholders will be left as-is. | |||
* @param errorMessageArgs the arguments to be substituted into the message | |||
* template. Arguments are converted to strings using | |||
* {@link String#valueOf(Object)}. | |||
* @throws IllegalArgumentException if {@code expression} is false | |||
* @throws NullPointerException if the check fails and either {@code | |||
* errorMessageTemplate} or {@code errorMessageArgs} is null (don't let | |||
* this happen) | |||
*/ | |||
public static void checkArgument(boolean expression, | |||
@Nullable String errorMessageTemplate, | |||
@Nullable Object... errorMessageArgs) { | |||
if (!expression) { | |||
throw new IllegalArgumentException( | |||
format(errorMessageTemplate, errorMessageArgs)); | |||
} | |||
} | |||
/** | |||
* Ensures the truth of an expression involving the state of the calling | |||
* instance, but not involving any parameters to the calling method. | |||
* | |||
* @param expression a boolean expression | |||
* @throws IllegalStateException if {@code expression} is false | |||
*/ | |||
public static void checkState(boolean expression) { | |||
if (!expression) { | |||
throw new IllegalStateException(); | |||
} | |||
} | |||
/** | |||
* Ensures the truth of an expression involving the state of the calling | |||
* instance, but not involving any parameters to the calling method. | |||
* | |||
* @param expression a boolean expression | |||
* @param errorMessage the exception message to use if the check fails; will | |||
* be converted to a string using {@link String#valueOf(Object)} | |||
* @throws IllegalStateException if {@code expression} is false | |||
*/ | |||
public static void checkState( | |||
boolean expression, @Nullable Object errorMessage) { | |||
if (!expression) { | |||
throw new IllegalStateException(String.valueOf(errorMessage)); | |||
} | |||
} | |||
/** | |||
* Ensures the truth of an expression involving the state of the calling | |||
* instance, but not involving any parameters to the calling method. | |||
* | |||
* @param expression a boolean expression | |||
* @param errorMessageTemplate a template for the exception message should the | |||
* check fail. The message is formed by replacing each {@code %s} | |||
* placeholder in the template with an argument. These are matched by | |||
* position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc. | |||
* Unmatched arguments will be appended to the formatted message in square | |||
* braces. Unmatched placeholders will be left as-is. | |||
* @param errorMessageArgs the arguments to be substituted into the message | |||
* template. Arguments are converted to strings using | |||
* {@link String#valueOf(Object)}. | |||
* @throws IllegalStateException if {@code expression} is false | |||
* @throws NullPointerException if the check fails and either {@code | |||
* errorMessageTemplate} or {@code errorMessageArgs} is null (don't let | |||
* this happen) | |||
*/ | |||
public static void checkState(boolean expression, | |||
@Nullable String errorMessageTemplate, | |||
@Nullable Object... errorMessageArgs) { | |||
if (!expression) { | |||
throw new IllegalStateException( | |||
format(errorMessageTemplate, errorMessageArgs)); | |||
} | |||
} | |||
/** | |||
* Ensures that an object reference passed as a parameter to the calling | |||
* method is not null. | |||
* | |||
* @param reference an object reference | |||
* @return the non-null reference that was validated | |||
* @throws NullPointerException if {@code reference} is null | |||
*/ | |||
public static <T> T checkNotNull(T reference) { | |||
if (reference == null) { | |||
throw new NullPointerException(); | |||
} | |||
return reference; | |||
} | |||
/** | |||
* Ensures that an object reference passed as a parameter to the calling | |||
* method is not null. | |||
* | |||
* @param reference an object reference | |||
* @param errorMessage the exception message to use if the check fails; will | |||
* be converted to a string using {@link String#valueOf(Object)} | |||
* @return the non-null reference that was validated | |||
* @throws NullPointerException if {@code reference} is null | |||
*/ | |||
public static <T> T checkNotNull(T reference, @Nullable Object errorMessage) { | |||
if (reference == null) { | |||
throw new NullPointerException(String.valueOf(errorMessage)); | |||
} | |||
return reference; | |||
} | |||
/** | |||
* Ensures that an object reference passed as a parameter to the calling | |||
* method is not null. | |||
* | |||
* @param reference an object reference | |||
* @param errorMessageTemplate a template for the exception message should the | |||
* check fail. The message is formed by replacing each {@code %s} | |||
* placeholder in the template with an argument. These are matched by | |||
* position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc. | |||
* Unmatched arguments will be appended to the formatted message in square | |||
* braces. Unmatched placeholders will be left as-is. | |||
* @param errorMessageArgs the arguments to be substituted into the message | |||
* template. Arguments are converted to strings using | |||
* {@link String#valueOf(Object)}. | |||
* @return the non-null reference that was validated | |||
* @throws NullPointerException if {@code reference} is null | |||
*/ | |||
public static <T> T checkNotNull(T reference, | |||
@Nullable String errorMessageTemplate, | |||
@Nullable Object... errorMessageArgs) { | |||
if (reference == null) { | |||
// If either of these parameters is null, the right thing happens anyway | |||
throw new NullPointerException( | |||
format(errorMessageTemplate, errorMessageArgs)); | |||
} | |||
return reference; | |||
} | |||
/* | |||
* All recent hotspots (as of 2009) *really* like to have the natural code | |||
* | |||
* if (guardExpression) { | |||
* throw new BadException(messageExpression); | |||
* } | |||
* | |||
* refactored so that messageExpression is moved to a separate | |||
* String-returning method. | |||
* | |||
* if (guardExpression) { | |||
* throw new BadException(badMsg(...)); | |||
* } | |||
* | |||
* The alternative natural refactorings into void or Exception-returning | |||
* methods are much slower. This is a big deal - we're talking factors of | |||
* 2-8 in microbenchmarks, not just 10-20%. (This is a hotspot optimizer | |||
* bug, which should be fixed, but that's a separate, big project). | |||
* | |||
* The coding pattern above is heavily used in java.util, e.g. in ArrayList. | |||
* There is a RangeCheckMicroBenchmark in the JDK that was used to test this. | |||
* | |||
* But the methods in this class want to throw different exceptions, | |||
* depending on the args, so it appears that this pattern is not directly | |||
* applicable. But we can use the ridiculous, devious trick of throwing an | |||
* exception in the middle of the construction of another exception. | |||
* Hotspot is fine with that. | |||
*/ | |||
/** | |||
* Ensures that {@code index} specifies a valid <i>element</i> in an array, | |||
* list or string of size {@code size}. An element index may range from zero, | |||
* inclusive, to {@code size}, exclusive. | |||
* | |||
* @param index a user-supplied index identifying an element of an array, list | |||
* or string | |||
* @param size the size of that array, list or string | |||
* @return the value of {@code index} | |||
* @throws IndexOutOfBoundsException if {@code index} is negative or is not | |||
* less than {@code size} | |||
* @throws IllegalArgumentException if {@code size} is negative | |||
*/ | |||
public static int checkElementIndex(int index, int size) { | |||
return checkElementIndex(index, size, "index"); | |||
} | |||
/** | |||
* Ensures that {@code index} specifies a valid <i>element</i> in an array, | |||
* list or string of size {@code size}. An element index may range from zero, | |||
* inclusive, to {@code size}, exclusive. | |||
* | |||
* @param index a user-supplied index identifying an element of an array, list | |||
* or string | |||
* @param size the size of that array, list or string | |||
* @param desc the text to use to describe this index in an error message | |||
* @return the value of {@code index} | |||
* @throws IndexOutOfBoundsException if {@code index} is negative or is not | |||
* less than {@code size} | |||
* @throws IllegalArgumentException if {@code size} is negative | |||
*/ | |||
public static int checkElementIndex( | |||
int index, int size, @Nullable String desc) { | |||
// Carefully optimized for execution by hotspot (explanatory comment above) | |||
if (index < 0 || index >= size) { | |||
throw new IndexOutOfBoundsException(badElementIndex(index, size, desc)); | |||
} | |||
return index; | |||
} | |||
private static String badElementIndex(int index, int size, String desc) { | |||
if (index < 0) { | |||
return format("%s (%s) must not be negative", desc, index); | |||
} else if (size < 0) { | |||
throw new IllegalArgumentException("negative size: " + size); | |||
} else { // index >= size | |||
return format("%s (%s) must be less than size (%s)", desc, index, size); | |||
} | |||
} | |||
/** | |||
* Ensures that {@code index} specifies a valid <i>position</i> in an array, | |||
* list or string of size {@code size}. A position index may range from zero | |||
* to {@code size}, inclusive. | |||
* | |||
* @param index a user-supplied index identifying a position in an array, list | |||
* or string | |||
* @param size the size of that array, list or string | |||
* @return the value of {@code index} | |||
* @throws IndexOutOfBoundsException if {@code index} is negative or is | |||
* greater than {@code size} | |||
* @throws IllegalArgumentException if {@code size} is negative | |||
*/ | |||
public static int checkPositionIndex(int index, int size) { | |||
return checkPositionIndex(index, size, "index"); | |||
} | |||
/** | |||
* Ensures that {@code index} specifies a valid <i>position</i> in an array, | |||
* list or string of size {@code size}. A position index may range from zero | |||
* to {@code size}, inclusive. | |||
* | |||
* @param index a user-supplied index identifying a position in an array, list | |||
* or string | |||
* @param size the size of that array, list or string | |||
* @param desc the text to use to describe this index in an error message | |||
* @return the value of {@code index} | |||
* @throws IndexOutOfBoundsException if {@code index} is negative or is | |||
* greater than {@code size} | |||
* @throws IllegalArgumentException if {@code size} is negative | |||
*/ | |||
public static int checkPositionIndex( | |||
int index, int size, @Nullable String desc) { | |||
// Carefully optimized for execution by hotspot (explanatory comment above) | |||
if (index < 0 || index > size) { | |||
throw new IndexOutOfBoundsException(badPositionIndex(index, size, desc)); | |||
} | |||
return index; | |||
} | |||
private static String badPositionIndex(int index, int size, String desc) { | |||
if (index < 0) { | |||
return format("%s (%s) must not be negative", desc, index); | |||
} else if (size < 0) { | |||
throw new IllegalArgumentException("negative size: " + size); | |||
} else { // index > size | |||
return format("%s (%s) must not be greater than size (%s)", | |||
desc, index, size); | |||
} | |||
} | |||
/** | |||
* Ensures that {@code start} and {@code end} specify a valid <i>positions</i> | |||
* in an array, list or string of size {@code size}, and are in order. A | |||
* position index may range from zero to {@code size}, inclusive. | |||
* | |||
* @param start a user-supplied index identifying a starting position in an | |||
* array, list or string | |||
* @param end a user-supplied index identifying a ending position in an array, | |||
* list or string | |||
* @param size the size of that array, list or string | |||
* @throws IndexOutOfBoundsException if either index is negative or is | |||
* greater than {@code size}, or if {@code end} is less than {@code start} | |||
* @throws IllegalArgumentException if {@code size} is negative | |||
*/ | |||
public static void checkPositionIndexes(int start, int end, int size) { | |||
// Carefully optimized for execution by hotspot (explanatory comment above) | |||
if (start < 0 || end < start || end > size) { | |||
throw new IndexOutOfBoundsException(badPositionIndexes(start, end, size)); | |||
} | |||
} | |||
private static String badPositionIndexes(int start, int end, int size) { | |||
if (start < 0 || start > size) { | |||
return badPositionIndex(start, size, "start index"); | |||
} | |||
if (end < 0 || end > size) { | |||
return badPositionIndex(end, size, "end index"); | |||
} | |||
// end < start | |||
return format("end index (%s) must not be less than start index (%s)", | |||
end, start); | |||
} | |||
/** | |||
* Substitutes each {@code %s} in {@code template} with an argument. These | |||
* are matched by position - the first {@code %s} gets {@code args[0]}, etc. | |||
* If there are more arguments than placeholders, the unmatched arguments will | |||
* be appended to the end of the formatted message in square braces. | |||
* | |||
* @param template a non-null string containing 0 or more {@code %s} | |||
* placeholders. | |||
* @param args the arguments to be substituted into the message | |||
* template. Arguments are converted to strings using | |||
* {@link String#valueOf(Object)}. Arguments can be null. | |||
*/ | |||
static String format(String template, | |||
@Nullable Object... args) { | |||
template = String.valueOf(template); // null -> "null" | |||
// start substituting the arguments into the '%s' placeholders | |||
StringBuilder builder = new StringBuilder( | |||
template.length() + 16 * args.length); | |||
int templateStart = 0; | |||
int i = 0; | |||
while (i < args.length) { | |||
int placeholderStart = template.indexOf("%s", templateStart); | |||
if (placeholderStart == -1) { | |||
break; | |||
} | |||
builder.append(template.substring(templateStart, placeholderStart)); | |||
builder.append(args[i++]); | |||
templateStart = placeholderStart + 2; | |||
} | |||
builder.append(template.substring(templateStart)); | |||
// if we run out of placeholders, append the extra args in square braces | |||
if (i < args.length) { | |||
builder.append(" ["); | |||
builder.append(args[i++]); | |||
while (i < args.length) { | |||
builder.append(", "); | |||
builder.append(args[i++]); | |||
} | |||
builder.append(']'); | |||
} | |||
return builder.toString(); | |||
} | |||
} |
@@ -1,140 +0,0 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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 02110-1301, USA. | |||
*/ | |||
package org.sonar.batch.api.internal; | |||
/** | |||
* Copied from commons lang | |||
*/ | |||
public class StringUtils { | |||
public static final String EMPTY = ""; | |||
public static String trim(String str) { | |||
return str == null ? null : str.trim(); | |||
} | |||
public static String removeStart(String str, String remove) { | |||
if (isEmpty(str) || isEmpty(remove)) { | |||
return str; | |||
} | |||
if (str.startsWith(remove)) { | |||
return str.substring(remove.length()); | |||
} | |||
return str; | |||
} | |||
public static String removeEnd(String str, String remove) { | |||
if (isEmpty(str) || isEmpty(remove)) { | |||
return str; | |||
} | |||
if (str.endsWith(remove)) { | |||
return str.substring(0, str.length() - remove.length()); | |||
} | |||
return str; | |||
} | |||
public static boolean isEmpty(String str) { | |||
return str == null || str.length() == 0; | |||
} | |||
public static boolean startsWithIgnoreCase(String str, String prefix) { | |||
return startsWith(str, prefix, true); | |||
} | |||
private static boolean startsWith(String str, String prefix, boolean ignoreCase) { | |||
if (str == null || prefix == null) { | |||
return (str == null && prefix == null); | |||
} | |||
if (prefix.length() > str.length()) { | |||
return false; | |||
} | |||
return str.regionMatches(ignoreCase, 0, prefix, 0, prefix.length()); | |||
} | |||
public static String substring(String str, int start) { | |||
if (str == null) { | |||
return null; | |||
} | |||
// handle negatives, which means last n characters | |||
if (start < 0) { | |||
start = str.length() + start; // remember start is negative | |||
} | |||
if (start < 0) { | |||
start = 0; | |||
} | |||
if (start > str.length()) { | |||
return EMPTY; | |||
} | |||
return str.substring(start); | |||
} | |||
public static boolean isBlank(String str) { | |||
int strLen; | |||
if (str == null || (strLen = str.length()) == 0) { | |||
return true; | |||
} | |||
for (int i = 0; i < strLen; i++) { | |||
if ((Character.isWhitespace(str.charAt(i)) == false)) { | |||
return false; | |||
} | |||
} | |||
return true; | |||
} | |||
public static boolean isNotBlank(String str) { | |||
return !StringUtils.isBlank(str); | |||
} | |||
public static String removeEndIgnoreCase(String str, String remove) { | |||
if (isEmpty(str) || isEmpty(remove)) { | |||
return str; | |||
} | |||
if (endsWithIgnoreCase(str, remove)) { | |||
return str.substring(0, str.length() - remove.length()); | |||
} | |||
return str; | |||
} | |||
public static boolean endsWithIgnoreCase(String str, String suffix) { | |||
return endsWith(str, suffix, true); | |||
} | |||
private static boolean endsWith(String str, String suffix, boolean ignoreCase) { | |||
if (str == null || suffix == null) { | |||
return (str == null && suffix == null); | |||
} | |||
if (suffix.length() > str.length()) { | |||
return false; | |||
} | |||
int strOffset = str.length() - suffix.length(); | |||
return str.regionMatches(ignoreCase, strOffset, suffix, 0, suffix.length()); | |||
} | |||
public static String lowerCase(String str) { | |||
if (str == null) { | |||
return null; | |||
} | |||
return str.toLowerCase(); | |||
} | |||
} |
@@ -1,205 +0,0 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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 02110-1301, USA. | |||
*/ | |||
package org.sonar.batch.api.internal; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
import java.util.regex.Pattern; | |||
/** | |||
* Implementation of Ant-style matching patterns. | |||
* Contrary to other implementations (like AntPathMatcher from Spring Framework) it is based on {@link Pattern Java Regular Expressions}. | |||
* To increase performance it holds an internal cache of all processed patterns. | |||
* <p> | |||
* Following rules are applied: | |||
* <ul> | |||
* <li>? matches single character</li> | |||
* <li>* matches zero or more characters</li> | |||
* <li>** matches zero or more 'directories'</li> | |||
* </ul> | |||
* </p> | |||
* <p> | |||
* Some examples of patterns: | |||
* <ul> | |||
* <li><code>org/T?st.java</code> - matches <code>org/Test.java</code> and also <code>org/Tost.java</code></li> | |||
* <li><code>org/*.java</code> - matches all <code>.java</code> files in the <code>org</code> directory, | |||
* e.g. <code>org/Foo.java</code> or <code>org/Bar.java</code></li> | |||
* <li><code>org/**</code> - matches all files underneath the <code>org</code> directory, | |||
* e.g. <code>org/Foo.java</code> or <code>org/foo/bar.jsp</code></li> | |||
* <li><code>org/**/Test.java</code> - matches all <code>Test.java</code> files underneath the <code>org</code> directory, | |||
* e.g. <code>org/Test.java</code> or <code>org/foo/Test.java</code> or <code>org/foo/bar/Test.java</code></li> | |||
* <li><code>org/**/*.java</code> - matches all <code>.java</code> files underneath the <code>org</code> directory, | |||
* e.g. <code>org/Foo.java</code> or <code>org/foo/Bar.java</code> or <code>org/foo/bar/Baz.java</code></li> | |||
* </ul> | |||
* </p> | |||
* <p> | |||
* Another implementation, which is also based on Java Regular Expressions, can be found in | |||
* <a href="https://github.com/JetBrains/intellij-community/blob/idea/107.743/platform/util/src/com/intellij/openapi/util/io/FileUtil.java#L847">FileUtil</a> | |||
* from IntelliJ OpenAPI. | |||
* </p> | |||
* | |||
*/ | |||
public class WildcardPattern { | |||
private static final Map<String, WildcardPattern> CACHE = new HashMap<String, WildcardPattern>(); | |||
private static final String SPECIAL_CHARS = "()[]^$.{}+|"; | |||
private Pattern pattern; | |||
private String stringRepresentation; | |||
protected WildcardPattern(String pattern, String directorySeparator) { | |||
this.stringRepresentation = pattern; | |||
this.pattern = Pattern.compile(toRegexp(pattern, directorySeparator)); | |||
} | |||
private static String toRegexp(String antPattern, String directorySeparator) { | |||
final String escapedDirectorySeparator = '\\' + directorySeparator; | |||
final StringBuilder sb = new StringBuilder(antPattern.length()); | |||
sb.append('^'); | |||
int i = antPattern.startsWith("/") || antPattern.startsWith("\\") ? 1 : 0; | |||
while (i < antPattern.length()) { | |||
final char ch = antPattern.charAt(i); | |||
if (SPECIAL_CHARS.indexOf(ch) != -1) { | |||
// Escape regexp-specific characters | |||
sb.append('\\').append(ch); | |||
} else if (ch == '*') { | |||
if (i + 1 < antPattern.length() && antPattern.charAt(i + 1) == '*') { | |||
// Double asterisk | |||
// Zero or more directories | |||
if (i + 2 < antPattern.length() && isSlash(antPattern.charAt(i + 2))) { | |||
sb.append("(?:.*").append(escapedDirectorySeparator).append("|)"); | |||
i += 2; | |||
} else { | |||
sb.append(".*"); | |||
i += 1; | |||
} | |||
} else { | |||
// Single asterisk | |||
// Zero or more characters excluding directory separator | |||
sb.append("[^").append(escapedDirectorySeparator).append("]*?"); | |||
} | |||
} else if (ch == '?') { | |||
// Any single character excluding directory separator | |||
sb.append("[^").append(escapedDirectorySeparator).append("]"); | |||
} else if (isSlash(ch)) { | |||
// Directory separator | |||
sb.append(escapedDirectorySeparator); | |||
} else { | |||
// Single character | |||
sb.append(ch); | |||
} | |||
i++; | |||
} | |||
sb.append('$'); | |||
return sb.toString(); | |||
} | |||
private static boolean isSlash(char ch) { | |||
return ch == '/' || ch == '\\'; | |||
} | |||
/** | |||
* Returns string representation of this pattern. | |||
* | |||
* @since 2.5 | |||
*/ | |||
@Override | |||
public String toString() { | |||
return stringRepresentation; | |||
} | |||
/** | |||
* Returns true if specified value matches this pattern. | |||
*/ | |||
public boolean match(String value) { | |||
value = StringUtils.removeStart(value, "/"); | |||
value = StringUtils.removeEnd(value, "/"); | |||
return pattern.matcher(value).matches(); | |||
} | |||
/** | |||
* Returns true if specified value matches one of specified patterns. | |||
* | |||
* @since 2.4 | |||
*/ | |||
public static boolean match(WildcardPattern[] patterns, String value) { | |||
for (WildcardPattern pattern : patterns) { | |||
if (pattern.match(value)) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
/** | |||
* Creates pattern with "/" as a directory separator. | |||
* | |||
* @see #create(String, String) | |||
*/ | |||
public static WildcardPattern create(String pattern) { | |||
return create(pattern, "/"); | |||
} | |||
/** | |||
* Creates array of patterns with "/" as a directory separator. | |||
* | |||
* @see #create(String, String) | |||
*/ | |||
public static WildcardPattern[] create(String[] patterns) { | |||
if (patterns == null) { | |||
return new WildcardPattern[0]; | |||
} | |||
WildcardPattern[] exclusionPAtterns = new WildcardPattern[patterns.length]; | |||
for (int i = 0; i < patterns.length; i++) { | |||
exclusionPAtterns[i] = create(patterns[i]); | |||
} | |||
return exclusionPAtterns; | |||
} | |||
/** | |||
* Creates pattern with specified separator for directories. | |||
* <p> | |||
* This is used to match Java-classes, i.e. <code>org.foo.Bar</code> against <code>org/**</code>. | |||
* <b>However usage of character other than "/" as a directory separator is misleading and should be avoided, | |||
* so method {@link #create(String)} is preferred over this one.</b> | |||
* </p> | |||
* <p> | |||
* Also note that no matter whether forward or backward slashes were used in the <code>antPattern</code> | |||
* the returned pattern will use <code>directorySeparator</code>. | |||
* Thus to match Windows-style path "dir\file.ext" against pattern "dir/file.ext" normalization should be performed. | |||
* </p> | |||
*/ | |||
public static WildcardPattern create(String pattern, String directorySeparator) { | |||
String key = pattern + directorySeparator; | |||
WildcardPattern wildcardPattern = CACHE.get(key); | |||
if (wildcardPattern == null) { | |||
wildcardPattern = new WildcardPattern(pattern, directorySeparator); | |||
CACHE.put(key, wildcardPattern); | |||
} | |||
return wildcardPattern; | |||
} | |||
} |
@@ -1,21 +0,0 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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 02110-1301, USA. | |||
*/ | |||
@javax.annotation.ParametersAreNonnullByDefault | |||
package org.sonar.batch.api.measures; |
@@ -1,90 +0,0 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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 02110-1301, USA. | |||
*/ | |||
package org.sonar.batch.api.rules; | |||
import java.io.Serializable; | |||
/** | |||
* Key of a rule. Unique among all the rule repositories. | |||
* | |||
* @since 3.6 | |||
*/ | |||
public class RuleKey implements Serializable { | |||
private final String repository, rule; | |||
protected RuleKey(String repositoryKey, String ruleKey) { | |||
this.repository = repositoryKey; | |||
this.rule = ruleKey; | |||
} | |||
/** | |||
* Create a key. Parameters are NOT null. | |||
*/ | |||
public static RuleKey of(String repository, String rule) { | |||
return new RuleKey(repository, rule); | |||
} | |||
/** | |||
* Never null | |||
*/ | |||
public String repository() { | |||
return repository; | |||
} | |||
/** | |||
* Never null | |||
*/ | |||
public String rule() { | |||
return rule; | |||
} | |||
@Override | |||
public boolean equals(Object o) { | |||
if (this == o) { | |||
return true; | |||
} | |||
if (o == null || getClass() != o.getClass()) { | |||
return false; | |||
} | |||
RuleKey ruleKey = (RuleKey) o; | |||
if (!repository.equals(ruleKey.repository)) { | |||
return false; | |||
} | |||
if (!rule.equals(ruleKey.rule)) { | |||
return false; | |||
} | |||
return true; | |||
} | |||
@Override | |||
public int hashCode() { | |||
int result = repository.hashCode(); | |||
result = 31 * result + rule.hashCode(); | |||
return result; | |||
} | |||
/** | |||
* Format is "repository:rule", for example "squid:AvoidCycle" | |||
*/ | |||
@Override | |||
public String toString() { | |||
return String.format("%s:%s", repository, rule); | |||
} | |||
} |
@@ -40,10 +40,6 @@ | |||
<groupId>org.codehaus.sonar</groupId> | |||
<artifactId>sonar-java-api</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.codehaus.sonar</groupId> | |||
<artifactId>sonar-batch-plugin-api</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.codehaus.sonar</groupId> | |||
<artifactId>sonar-plugin-api</artifactId> |
@@ -19,6 +19,9 @@ | |||
*/ | |||
package org.sonar.batch.bootstrap; | |||
import org.sonar.api.batch.analyzer.Analyzer; | |||
import org.sonar.api.batch.analyzer.AnalyzerContext; | |||
import com.google.common.collect.Lists; | |||
import org.apache.commons.lang.ClassUtils; | |||
import org.sonar.api.batch.CheckProject; | |||
@@ -26,8 +29,6 @@ import org.sonar.api.batch.Sensor; | |||
import org.sonar.api.batch.fs.FileSystem; | |||
import org.sonar.api.platform.ComponentContainer; | |||
import org.sonar.api.resources.Project; | |||
import org.sonar.batch.api.analyzer.Analyzer; | |||
import org.sonar.batch.api.analyzer.AnalyzerContext; | |||
import org.sonar.batch.scan.SensorWrapper; | |||
import java.util.Collection; |
@@ -178,7 +178,7 @@ public class DefaultIndex extends SonarIndex { | |||
} | |||
@Override | |||
public Measure getMeasure(Resource resource, org.sonar.batch.api.measures.Metric<?> metric) { | |||
public Measure getMeasure(Resource resource, org.sonar.api.batch.measures.Metric<?> metric) { | |||
return getMeasures(resource, MeasuresFilters.metric(metric)); | |||
} | |||
@@ -19,8 +19,9 @@ | |||
*/ | |||
package org.sonar.batch.languages; | |||
import org.sonar.api.batch.languages.Language; | |||
import org.sonar.api.resources.Languages; | |||
import org.sonar.batch.api.languages.Language; | |||
import javax.annotation.CheckForNull; | |||
@@ -19,8 +19,9 @@ | |||
*/ | |||
package org.sonar.batch.languages; | |||
import org.sonar.api.batch.languages.Language; | |||
import org.sonar.api.BatchComponent; | |||
import org.sonar.batch.api.languages.Language; | |||
import javax.annotation.CheckForNull; | |||
@@ -19,11 +19,12 @@ | |||
*/ | |||
package org.sonar.batch.phases; | |||
import org.sonar.api.batch.analyzer.Analyzer; | |||
import org.apache.commons.lang.ClassUtils; | |||
import org.sonar.api.BatchExtension; | |||
import org.sonar.api.batch.InstantiationStrategy; | |||
import org.sonar.api.batch.Sensor; | |||
import org.sonar.batch.api.analyzer.Analyzer; | |||
import org.sonar.batch.bootstrap.ExtensionMatcher; | |||
/** |
@@ -19,6 +19,8 @@ | |||
*/ | |||
package org.sonar.batch.rule; | |||
import org.sonar.api.batch.rules.QProfile; | |||
import com.google.common.collect.ArrayListMultimap; | |||
import com.google.common.collect.ListMultimap; | |||
import org.picocontainer.injectors.ProviderAdapter; | |||
@@ -28,7 +30,6 @@ import org.sonar.api.batch.rule.internal.NewActiveRule; | |||
import org.sonar.api.rules.Rule; | |||
import org.sonar.api.rules.RuleFinder; | |||
import org.sonar.api.rules.RuleParam; | |||
import org.sonar.batch.api.rules.QProfile; | |||
import org.sonar.batch.rules.QProfileWithId; | |||
import org.sonar.core.qualityprofile.db.ActiveRuleDao; | |||
import org.sonar.core.qualityprofile.db.ActiveRuleDto; |
@@ -19,13 +19,14 @@ | |||
*/ | |||
package org.sonar.batch.rule; | |||
import org.sonar.api.batch.languages.Language; | |||
import org.sonar.api.batch.rules.QProfile; | |||
import com.google.common.collect.ImmutableMap; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.BatchComponent; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.utils.MessageException; | |||
import org.sonar.batch.api.languages.Language; | |||
import org.sonar.batch.api.rules.QProfile; | |||
import org.sonar.batch.languages.LanguagesReferential; | |||
import org.sonar.batch.rules.QProfilesReferential; | |||
@@ -19,6 +19,8 @@ | |||
*/ | |||
package org.sonar.batch.rule; | |||
import org.sonar.api.batch.rules.QProfile; | |||
import com.google.common.annotations.VisibleForTesting; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.slf4j.Logger; | |||
@@ -27,7 +29,6 @@ import org.sonar.api.BatchComponent; | |||
import org.sonar.api.batch.fs.FileSystem; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.utils.MessageException; | |||
import org.sonar.batch.api.rules.QProfile; | |||
public class QProfileVerifier implements BatchComponent { | |||
@@ -19,6 +19,8 @@ | |||
*/ | |||
package org.sonar.batch.rule; | |||
import org.sonar.api.batch.rules.QProfile; | |||
import com.google.common.collect.Lists; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.picocontainer.injectors.ProviderAdapter; | |||
@@ -30,7 +32,6 @@ import org.sonar.api.rules.ActiveRule; | |||
import org.sonar.api.rules.Rule; | |||
import org.sonar.api.rules.RuleFinder; | |||
import org.sonar.api.rules.RulePriority; | |||
import org.sonar.batch.api.rules.QProfile; | |||
import java.util.Collection; | |||
import java.util.Map; |
@@ -19,7 +19,8 @@ | |||
*/ | |||
package org.sonar.batch.rules; | |||
import org.sonar.batch.api.rules.QProfile; | |||
import org.sonar.api.batch.rules.QProfile; | |||
import org.sonar.core.qualityprofile.db.QualityProfileDao; | |||
import org.sonar.core.qualityprofile.db.QualityProfileDto; | |||
@@ -19,7 +19,7 @@ | |||
*/ | |||
package org.sonar.batch.rules; | |||
import org.sonar.batch.api.rules.QProfile; | |||
import org.sonar.api.batch.rules.QProfile; | |||
public class QProfileWithId extends QProfile { | |||
private final int id; |
@@ -19,8 +19,9 @@ | |||
*/ | |||
package org.sonar.batch.rules; | |||
import org.sonar.api.batch.rules.QProfile; | |||
import org.sonar.api.BatchComponent; | |||
import org.sonar.batch.api.rules.QProfile; | |||
import javax.annotation.CheckForNull; | |||
@@ -20,7 +20,13 @@ | |||
package org.sonar.batch.scan; | |||
import org.sonar.api.batch.SensorContext; | |||
import org.sonar.api.batch.analyzer.AnalyzerContext; | |||
import org.sonar.api.batch.analyzer.issue.AnalyzerIssue; | |||
import org.sonar.api.batch.analyzer.measure.AnalyzerMeasure; | |||
import org.sonar.api.batch.analyzer.measure.AnalyzerMeasureBuilder; | |||
import org.sonar.api.batch.analyzer.measure.internal.DefaultAnalyzerMeasureBuilder; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.api.batch.measures.Metric; | |||
import org.sonar.api.component.ResourcePerspectives; | |||
import org.sonar.api.issue.Issuable; | |||
import org.sonar.api.measures.Measure; | |||
@@ -29,10 +35,6 @@ import org.sonar.api.resources.File; | |||
import org.sonar.api.resources.Project; | |||
import org.sonar.api.resources.Resource; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.batch.api.analyzer.AnalyzerContext; | |||
import org.sonar.batch.api.analyzer.issue.AnalyzerIssue; | |||
import org.sonar.batch.api.analyzer.measure.AnalyzerMeasure; | |||
import org.sonar.batch.api.measures.Metric; | |||
import java.io.Serializable; | |||
import java.util.Collection; | |||
@@ -51,6 +53,11 @@ public class AnalyzerContextAdaptor implements AnalyzerContext { | |||
this.perspectives = perspectives; | |||
} | |||
@Override | |||
public <G extends Serializable> AnalyzerMeasureBuilder<G> measureBuilder() { | |||
return new DefaultAnalyzerMeasureBuilder<G>(); | |||
} | |||
@Override | |||
public AnalyzerMeasure<?> getMeasure(String metricKey) { | |||
Metric<?> m = metricFinder.findByKey(metricKey); | |||
@@ -67,7 +74,7 @@ public class AnalyzerContextAdaptor implements AnalyzerContext { | |||
if (measure == null) { | |||
return null; | |||
} | |||
return AnalyzerMeasure.<G>builder() | |||
return this.<G>measureBuilder() | |||
.onProject() | |||
.forMetric(metric) | |||
.withValue(measure.value()) | |||
@@ -91,7 +98,7 @@ public class AnalyzerContextAdaptor implements AnalyzerContext { | |||
if (measure == null) { | |||
return null; | |||
} | |||
return AnalyzerMeasure.<G>builder() | |||
return this.<G>measureBuilder() | |||
.onFile(file) | |||
.forMetric(metric) | |||
.withValue(measure.value()) |
@@ -19,6 +19,8 @@ | |||
*/ | |||
package org.sonar.batch.scan; | |||
import org.sonar.api.batch.languages.Language; | |||
import org.picocontainer.Startable; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
@@ -26,7 +28,6 @@ import org.sonar.api.CoreProperties; | |||
import org.sonar.api.batch.fs.internal.DefaultFileSystem; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.utils.MessageException; | |||
import org.sonar.batch.api.languages.Language; | |||
import org.sonar.batch.languages.LanguagesReferential; | |||
/** |
@@ -200,8 +200,7 @@ public class ModuleScanContainer extends ComponentContainer { | |||
// Example : C# plugin adds sub-projects at runtime, even if they are not defined in root pom. | |||
return !ExtensionUtils.isMavenExtensionOnly(extension) || module.getPom() != null; | |||
} | |||
return ExtensionUtils.isType(extension, org.sonar.batch.api.BatchComponent.class) | |||
&& ExtensionUtils.isInstantiationStrategy(extension, org.sonar.batch.api.InstantiationStrategy.PER_PROJECT); | |||
return false; | |||
} | |||
}); | |||
} |
@@ -100,23 +100,26 @@ public class ProjectScanContainer extends ComponentContainer { | |||
} | |||
private void projectBootstrap() { | |||
ProjectReactor reactor; | |||
// OK, not present, so look for a custom ProjectBootstrapper | |||
ProjectBootstrapper bootstrapper = getComponentByType(ProjectBootstrapper.class); | |||
Settings settings = getComponentByType(Settings.class); | |||
if (bootstrapper == null | |||
// Starting from Maven plugin 2.3 then only DefaultProjectBootstrapper should be used. | |||
|| "true".equals(settings.getString("sonar.mojoUseRunner"))) { | |||
// Use default SonarRunner project bootstrapper | |||
ProjectReactorBuilder builder = getComponentByType(ProjectReactorBuilder.class); | |||
reactor = builder.execute(); | |||
} else { | |||
reactor = bootstrapper.bootstrap(); | |||
} | |||
// Views pass a custom ProjectReactor | |||
ProjectReactor reactor = getComponentByType(ProjectReactor.class); | |||
if (reactor == null) { | |||
throw new SonarException(bootstrapper + " has returned null as ProjectReactor"); | |||
// OK, not present, so look for a deprecated custom ProjectBootstrapper for old versions of SQ Runner | |||
ProjectBootstrapper bootstrapper = getComponentByType(ProjectBootstrapper.class); | |||
Settings settings = getComponentByType(Settings.class); | |||
if (bootstrapper == null | |||
// Starting from Maven plugin 2.3 then only DefaultProjectBootstrapper should be used. | |||
|| "true".equals(settings.getString("sonar.mojoUseRunner"))) { | |||
// Use default SonarRunner project bootstrapper | |||
ProjectReactorBuilder builder = getComponentByType(ProjectReactorBuilder.class); | |||
reactor = builder.execute(); | |||
} else { | |||
reactor = bootstrapper.bootstrap(); | |||
} | |||
if (reactor == null) { | |||
throw new SonarException(bootstrapper + " has returned null as ProjectReactor"); | |||
} | |||
add(reactor); | |||
} | |||
add(reactor); | |||
} | |||
private void addBatchComponents() { |
@@ -19,6 +19,8 @@ | |||
*/ | |||
package org.sonar.batch.scan; | |||
import org.sonar.batch.scan2.ProjectScanContainer; | |||
import org.sonar.api.CoreProperties; | |||
import org.sonar.api.platform.ComponentContainer; | |||
import org.sonar.api.task.Task; | |||
@@ -27,7 +29,6 @@ import org.sonar.batch.DefaultProjectTree; | |||
import org.sonar.batch.bootstrap.BootstrapProperties; | |||
import org.sonar.batch.bootstrap.TaskContainer; | |||
import org.sonar.batch.phases.Phases; | |||
import org.sonar.batch.scan2.ProjectScanContainer; | |||
public class ScanTask implements Task { | |||
public static final TaskDefinition DEFINITION = TaskDefinition.builder() |
@@ -23,11 +23,12 @@ import org.sonar.api.batch.DependedUpon; | |||
import org.sonar.api.batch.DependsUpon; | |||
import org.sonar.api.batch.Sensor; | |||
import org.sonar.api.batch.SensorContext; | |||
import org.sonar.api.batch.analyzer.Analyzer; | |||
import org.sonar.api.batch.analyzer.AnalyzerContext; | |||
import org.sonar.api.batch.analyzer.internal.DefaultAnalyzerDescriptor; | |||
import org.sonar.api.batch.fs.FileSystem; | |||
import org.sonar.api.batch.measures.Metric; | |||
import org.sonar.api.resources.Project; | |||
import org.sonar.batch.api.analyzer.Analyzer; | |||
import org.sonar.batch.api.analyzer.AnalyzerContext; | |||
import org.sonar.batch.api.measures.Metric; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
@@ -37,31 +38,34 @@ public class SensorWrapper implements Sensor { | |||
private Analyzer analyzer; | |||
private AnalyzerContext adaptor; | |||
private FileSystem fs; | |||
private DefaultAnalyzerDescriptor descriptor; | |||
public SensorWrapper(Analyzer analyzer, AnalyzerContext adaptor, FileSystem fs) { | |||
this.analyzer = analyzer; | |||
descriptor = new DefaultAnalyzerDescriptor(); | |||
analyzer.describe(descriptor); | |||
this.adaptor = adaptor; | |||
this.fs = fs; | |||
} | |||
@DependedUpon | |||
public List<Metric<?>> provides() { | |||
return Arrays.asList(analyzer.describe().provides()); | |||
return Arrays.asList(descriptor.provides()); | |||
} | |||
@DependsUpon | |||
public List<Metric<?>> depends() { | |||
return Arrays.asList(analyzer.describe().dependsOn()); | |||
return Arrays.asList(descriptor.dependsOn()); | |||
} | |||
@Override | |||
public boolean shouldExecuteOnProject(Project project) { | |||
if (!analyzer.describe().languages().isEmpty()) { | |||
if (project.getLanguageKey() != null && !analyzer.describe().languages().contains(project.getLanguageKey())) { | |||
if (!descriptor.languages().isEmpty()) { | |||
if (project.getLanguageKey() != null && !descriptor.languages().contains(project.getLanguageKey())) { | |||
return false; | |||
} | |||
boolean hasFile = false; | |||
for (String languageKey : analyzer.describe().languages()) { | |||
for (String languageKey : descriptor.languages()) { | |||
hasFile |= fs.hasFiles(fs.predicates().hasLanguage(languageKey)); | |||
} | |||
if (!hasFile) { |
@@ -19,6 +19,8 @@ | |||
*/ | |||
package org.sonar.batch.scan.filesystem; | |||
import org.sonar.api.batch.languages.Language; | |||
import com.google.common.base.Joiner; | |||
import com.google.common.collect.Lists; | |||
import com.google.common.collect.Maps; | |||
@@ -30,7 +32,6 @@ import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.api.batch.fs.internal.PathPattern; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.utils.MessageException; | |||
import org.sonar.batch.api.languages.Language; | |||
import org.sonar.batch.languages.LanguagesReferential; | |||
import javax.annotation.CheckForNull; |
@@ -21,7 +21,7 @@ package org.sonar.batch.scan2; | |||
import com.google.common.base.Preconditions; | |||
import org.sonar.api.BatchComponent; | |||
import org.sonar.batch.api.analyzer.measure.AnalyzerMeasure; | |||
import org.sonar.api.batch.analyzer.measure.internal.DefaultAnalyzerMeasure; | |||
import org.sonar.batch.index.Cache; | |||
import org.sonar.batch.index.Cache.Entry; | |||
import org.sonar.batch.index.Caches; | |||
@@ -29,36 +29,36 @@ import org.sonar.batch.index.Caches; | |||
/** | |||
* Cache of all measures. This cache is shared amongst all project modules. | |||
*/ | |||
public class MeasureCache implements BatchComponent { | |||
public class AnalyzerMeasureCache implements BatchComponent { | |||
private final Cache<AnalyzerMeasure<?>> cache; | |||
private final Cache<DefaultAnalyzerMeasure> cache; | |||
public MeasureCache(Caches caches) { | |||
public AnalyzerMeasureCache(Caches caches) { | |||
cache = caches.createCache("measures"); | |||
} | |||
public Iterable<Entry<AnalyzerMeasure<?>>> entries() { | |||
public Iterable<Entry<DefaultAnalyzerMeasure>> entries() { | |||
return cache.entries(); | |||
} | |||
public AnalyzerMeasure<?> byMetric(String resourceKey, String metricKey) { | |||
public DefaultAnalyzerMeasure<?> byMetric(String resourceKey, String metricKey) { | |||
return cache.get(resourceKey, metricKey); | |||
} | |||
public MeasureCache put(String resourceKey, AnalyzerMeasure<?> measure) { | |||
public AnalyzerMeasureCache put(String resourceKey, DefaultAnalyzerMeasure<?> measure) { | |||
Preconditions.checkNotNull(resourceKey); | |||
Preconditions.checkNotNull(measure.metricKey()); | |||
cache.put(resourceKey, measure.metricKey(), measure); | |||
return this; | |||
} | |||
public boolean contains(String resourceKey, AnalyzerMeasure<?> measure) { | |||
public boolean contains(String resourceKey, DefaultAnalyzerMeasure<?> measure) { | |||
Preconditions.checkNotNull(resourceKey); | |||
Preconditions.checkNotNull(measure); | |||
return cache.containsKey(resourceKey, measure.metricKey()); | |||
} | |||
public Iterable<AnalyzerMeasure<?>> all() { | |||
public Iterable<DefaultAnalyzerMeasure> all() { | |||
return cache.values(); | |||
} | |||
@@ -22,10 +22,10 @@ package org.sonar.batch.scan2; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.sonar.api.BatchComponent; | |||
import org.sonar.api.batch.analyzer.Analyzer; | |||
import org.sonar.api.batch.analyzer.AnalyzerContext; | |||
import org.sonar.api.batch.analyzer.internal.DefaultAnalyzerDescriptor; | |||
import org.sonar.api.platform.ComponentContainer; | |||
import org.sonar.batch.api.analyzer.Analyzer; | |||
import org.sonar.batch.api.analyzer.AnalyzerContext; | |||
import org.sonar.batch.api.analyzer.AnalyzerDescriptor; | |||
import java.util.Collection; | |||
@@ -44,7 +44,8 @@ public class AnalyzersExecutor implements BatchComponent { | |||
for (Analyzer analyzer : analyzers) { | |||
AnalyzerDescriptor descriptor = analyzer.describe(); | |||
DefaultAnalyzerDescriptor descriptor = new DefaultAnalyzerDescriptor(); | |||
analyzer.describe(descriptor); | |||
LOG.info("Execute analyzer: " + descriptor.name()); | |||
@@ -19,14 +19,17 @@ | |||
*/ | |||
package org.sonar.batch.scan2; | |||
import org.sonar.api.batch.analyzer.AnalyzerContext; | |||
import org.sonar.api.batch.analyzer.issue.AnalyzerIssue; | |||
import org.sonar.api.batch.analyzer.measure.AnalyzerMeasure; | |||
import org.sonar.api.batch.analyzer.measure.AnalyzerMeasureBuilder; | |||
import org.sonar.api.batch.analyzer.measure.internal.DefaultAnalyzerMeasure; | |||
import org.sonar.api.batch.analyzer.measure.internal.DefaultAnalyzerMeasureBuilder; | |||
import org.sonar.api.batch.bootstrap.ProjectDefinition; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.api.batch.measures.Metric; | |||
import org.sonar.api.issue.internal.DefaultIssue; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.batch.api.analyzer.AnalyzerContext; | |||
import org.sonar.batch.api.analyzer.issue.AnalyzerIssue; | |||
import org.sonar.batch.api.analyzer.measure.AnalyzerMeasure; | |||
import org.sonar.batch.api.measures.Metric; | |||
import org.sonar.batch.issue.ModuleIssues; | |||
import org.sonar.core.component.ComponentKeys; | |||
import org.sonar.core.issue.DefaultIssueBuilder; | |||
@@ -36,16 +39,21 @@ import java.util.Collection; | |||
public class DefaultAnalyzerContext implements AnalyzerContext { | |||
private final MeasureCache measureCache; | |||
private final AnalyzerMeasureCache measureCache; | |||
private ProjectDefinition def; | |||
private ModuleIssues moduleIssues; | |||
public DefaultAnalyzerContext(ProjectDefinition def, MeasureCache measureCache, ModuleIssues moduleIssues) { | |||
public DefaultAnalyzerContext(ProjectDefinition def, AnalyzerMeasureCache measureCache, ModuleIssues moduleIssues) { | |||
this.def = def; | |||
this.measureCache = measureCache; | |||
this.moduleIssues = moduleIssues; | |||
} | |||
@Override | |||
public <G extends Serializable> AnalyzerMeasureBuilder<G> measureBuilder() { | |||
return new DefaultAnalyzerMeasureBuilder<G>(); | |||
} | |||
@Override | |||
public AnalyzerMeasure getMeasure(String metricKey) { | |||
return measureCache.byMetric(def.getKey(), metricKey); | |||
@@ -67,11 +75,11 @@ public class DefaultAnalyzerContext implements AnalyzerContext { | |||
} | |||
@Override | |||
public void addMeasure(org.sonar.batch.api.analyzer.measure.AnalyzerMeasure<?> measure) { | |||
public void addMeasure(AnalyzerMeasure<?> measure) { | |||
if (measure.inputFile() != null) { | |||
measureCache.put(ComponentKeys.createEffectiveKey(def.getKey(), measure.inputFile()), measure); | |||
measureCache.put(ComponentKeys.createEffectiveKey(def.getKey(), measure.inputFile()), (DefaultAnalyzerMeasure) measure); | |||
} else { | |||
measureCache.put(def.getKey(), measure); | |||
measureCache.put(def.getKey(), (DefaultAnalyzerMeasure) measure); | |||
} | |||
} | |||
@@ -21,12 +21,12 @@ package org.sonar.batch.scan2; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.sonar.api.BatchComponent; | |||
import org.sonar.api.batch.InstantiationStrategy; | |||
import org.sonar.api.batch.bootstrap.ProjectDefinition; | |||
import org.sonar.api.batch.rule.CheckFactory; | |||
import org.sonar.api.platform.ComponentContainer; | |||
import org.sonar.api.scan.filesystem.FileExclusions; | |||
import org.sonar.batch.api.BatchComponent; | |||
import org.sonar.batch.api.InstantiationStrategy; | |||
import org.sonar.batch.bootstrap.BatchExtensionDictionnary; | |||
import org.sonar.batch.bootstrap.ExtensionInstaller; | |||
import org.sonar.batch.bootstrap.ExtensionMatcher; |
@@ -19,11 +19,12 @@ | |||
*/ | |||
package org.sonar.batch.scan2; | |||
import org.sonar.api.batch.analyzer.AnalyzerContext; | |||
import com.google.common.collect.Lists; | |||
import org.slf4j.Logger; | |||
import org.slf4j.LoggerFactory; | |||
import org.sonar.api.batch.bootstrap.ProjectDefinition; | |||
import org.sonar.batch.api.analyzer.AnalyzerContext; | |||
import org.sonar.batch.issue.ignore.scanner.IssueExclusionsLoader; | |||
import org.sonar.batch.phases.SensorsExecutor; | |||
import org.sonar.batch.rule.QProfileVerifier; |
@@ -20,7 +20,9 @@ | |||
package org.sonar.batch.scan2; | |||
import com.google.common.annotations.VisibleForTesting; | |||
import org.sonar.api.BatchComponent; | |||
import org.sonar.api.CoreProperties; | |||
import org.sonar.api.batch.InstantiationStrategy; | |||
import org.sonar.api.batch.bootstrap.ProjectBootstrapper; | |||
import org.sonar.api.batch.bootstrap.ProjectDefinition; | |||
import org.sonar.api.batch.bootstrap.ProjectReactor; | |||
@@ -28,8 +30,6 @@ import org.sonar.api.config.Settings; | |||
import org.sonar.api.platform.ComponentContainer; | |||
import org.sonar.api.scan.filesystem.PathResolver; | |||
import org.sonar.api.utils.SonarException; | |||
import org.sonar.batch.api.BatchComponent; | |||
import org.sonar.batch.api.InstantiationStrategy; | |||
import org.sonar.batch.bootstrap.ExtensionInstaller; | |||
import org.sonar.batch.bootstrap.ExtensionMatcher; | |||
import org.sonar.batch.bootstrap.ExtensionUtils; | |||
@@ -105,7 +105,7 @@ public class ProjectScanContainer extends ComponentContainer { | |||
ResourceCache.class, | |||
ComponentDataCache.class, | |||
ComponentDataPersister.class, | |||
MeasureCache.class, | |||
AnalyzerMeasureCache.class, | |||
// file system | |||
InputFileCache.class, |
@@ -19,7 +19,7 @@ | |||
*/ | |||
package org.sonar.batch.scan2; | |||
import org.sonar.batch.api.BatchExtension; | |||
import org.sonar.api.BatchExtension; | |||
public interface ScanTaskObserver extends BatchExtension { | |||
@@ -19,6 +19,8 @@ | |||
*/ | |||
package org.sonar.batch.bootstrap; | |||
import org.sonar.api.batch.analyzer.AnalyzerContext; | |||
import org.junit.Test; | |||
import org.sonar.api.BatchExtension; | |||
import org.sonar.api.batch.Sensor; | |||
@@ -26,7 +28,6 @@ import org.sonar.api.batch.SensorContext; | |||
import org.sonar.api.batch.fs.FileSystem; | |||
import org.sonar.api.platform.ComponentContainer; | |||
import org.sonar.api.resources.Project; | |||
import org.sonar.batch.api.analyzer.AnalyzerContext; | |||
import java.util.Collection; | |||
@@ -19,6 +19,8 @@ | |||
*/ | |||
package org.sonar.batch.rule; | |||
import org.sonar.api.batch.rules.QProfile; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import org.sonar.api.batch.rule.ActiveRule; | |||
@@ -27,7 +29,6 @@ import org.sonar.api.rule.RuleKey; | |||
import org.sonar.api.rule.Severity; | |||
import org.sonar.api.rules.Rule; | |||
import org.sonar.api.rules.RuleFinder; | |||
import org.sonar.batch.api.rules.QProfile; | |||
import org.sonar.batch.rules.QProfileWithId; | |||
import org.sonar.core.persistence.AbstractDaoTestCase; | |||
import org.sonar.core.qualityprofile.db.ActiveRuleDao; |
@@ -19,13 +19,14 @@ | |||
*/ | |||
package org.sonar.batch.rule; | |||
import org.sonar.api.batch.rules.QProfile; | |||
import com.google.common.collect.Lists; | |||
import org.junit.Test; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.resources.Language; | |||
import org.sonar.api.resources.Languages; | |||
import org.sonar.api.utils.MessageException; | |||
import org.sonar.batch.api.rules.QProfile; | |||
import org.sonar.batch.languages.DeprecatedLanguagesReferential; | |||
import org.sonar.batch.languages.LanguagesReferential; | |||
import org.sonar.batch.rules.DefaultQProfileReferential; |
@@ -19,13 +19,14 @@ | |||
*/ | |||
package org.sonar.batch.rule; | |||
import org.sonar.api.batch.rules.QProfile; | |||
import org.junit.Test; | |||
import org.sonar.api.batch.SensorContext; | |||
import org.sonar.api.batch.fs.internal.DefaultFileSystem; | |||
import org.sonar.api.measures.CoreMetrics; | |||
import org.sonar.api.resources.Project; | |||
import org.sonar.api.test.IsMeasure; | |||
import org.sonar.batch.api.rules.QProfile; | |||
import org.sonar.batch.rules.QProfileWithId; | |||
import org.sonar.core.persistence.AbstractDaoTestCase; | |||
import org.sonar.core.qualityprofile.db.QualityProfileDao; |
@@ -19,12 +19,13 @@ | |||
*/ | |||
package org.sonar.batch.rule; | |||
import org.sonar.api.batch.rules.QProfile; | |||
import org.junit.Test; | |||
import org.sonar.api.batch.rule.ActiveRules; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.profiles.RulesProfile; | |||
import org.sonar.api.rules.RuleFinder; | |||
import org.sonar.batch.api.rules.QProfile; | |||
import org.sonar.batch.rules.QProfileWithId; | |||
import java.util.Arrays; |
@@ -24,13 +24,14 @@ import com.google.common.collect.Collections2; | |||
import com.google.common.collect.Lists; | |||
import org.apache.commons.lang.ClassUtils; | |||
import org.sonar.api.BatchExtension; | |||
import org.sonar.api.batch.analyzer.Analyzer; | |||
import org.sonar.api.batch.analyzer.internal.DefaultAnalyzerDescriptor; | |||
import org.sonar.api.batch.maven.DependsUponMavenPlugin; | |||
import org.sonar.api.batch.maven.MavenPluginHandler; | |||
import org.sonar.api.platform.ComponentContainer; | |||
import org.sonar.api.resources.Project; | |||
import org.sonar.api.utils.AnnotationUtils; | |||
import org.sonar.api.utils.dag.DirectAcyclicGraph; | |||
import org.sonar.batch.api.analyzer.Analyzer; | |||
import java.lang.annotation.Annotation; | |||
import java.lang.reflect.Array; | |||
@@ -99,7 +100,6 @@ public class BatchExtensionDictionnary { | |||
private static void completeBatchExtensions(ComponentContainer container, List<Object> extensions) { | |||
if (container != null) { | |||
extensions.addAll(container.getComponentsByType(BatchExtension.class)); | |||
extensions.addAll(container.getComponentsByType(org.sonar.batch.api.BatchExtension.class)); | |||
completeBatchExtensions(container.getParent(), extensions); | |||
} | |||
} | |||
@@ -147,7 +147,9 @@ public class BatchExtensionDictionnary { | |||
List<Object> result = new ArrayList<Object>(); | |||
result.addAll(evaluateAnnotatedClasses(extension, DependsUpon.class)); | |||
if (ClassUtils.isAssignable(extension.getClass(), Analyzer.class)) { | |||
result.addAll(Arrays.asList(((Analyzer) extension).describe().dependsOn())); | |||
DefaultAnalyzerDescriptor descriptor = new DefaultAnalyzerDescriptor(); | |||
((Analyzer) extension).describe(descriptor); | |||
result.addAll(Arrays.asList(descriptor.dependsOn())); | |||
} | |||
return result; | |||
} | |||
@@ -159,7 +161,9 @@ public class BatchExtensionDictionnary { | |||
List<Object> result = new ArrayList<Object>(); | |||
result.addAll(evaluateAnnotatedClasses(extension, DependedUpon.class)); | |||
if (ClassUtils.isAssignable(extension.getClass(), Analyzer.class)) { | |||
result.addAll(Arrays.asList(((Analyzer) extension).describe().provides())); | |||
DefaultAnalyzerDescriptor descriptor = new DefaultAnalyzerDescriptor(); | |||
((Analyzer) extension).describe(descriptor); | |||
result.addAll(Arrays.asList(descriptor.provides())); | |||
} | |||
return result; | |||
} |
@@ -27,10 +27,6 @@ | |||
<groupId>org.codehaus.sonar</groupId> | |||
<artifactId>sonar-check-api</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.codehaus.sonar</groupId> | |||
<artifactId>sonar-batch-plugin-api</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.codehaus.sonar</groupId> | |||
<artifactId>sonar-colorizer</artifactId> |
@@ -120,7 +120,7 @@ public abstract class SonarIndex implements DirectedGraphAccessor<Resource, Depe | |||
public abstract Resource addResource(Resource resource); | |||
@CheckForNull | |||
public abstract Measure getMeasure(Resource resource, org.sonar.batch.api.measures.Metric<?> metric); | |||
public abstract Measure getMeasure(Resource resource, org.sonar.api.batch.measures.Metric<?> metric); | |||
@CheckForNull | |||
public abstract <M> M getMeasures(Resource resource, MeasuresFilter<M> filter); |
@@ -17,9 +17,9 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.batch.api.analyzer; | |||
package org.sonar.api.batch.analyzer; | |||
import org.sonar.batch.api.BatchExtension; | |||
import org.sonar.api.BatchExtension; | |||
/** | |||
* <p> | |||
@@ -36,15 +36,12 @@ import org.sonar.batch.api.BatchExtension; | |||
public interface Analyzer extends BatchExtension { | |||
/** | |||
* Describe what this analyzer is doing. | |||
* @return | |||
* Populate {@link AnalyzerDescriptor} of this analyzer. | |||
*/ | |||
AnalyzerDescriptor describe(); | |||
void describe(AnalyzerDescriptor descriptor); | |||
/** | |||
* The method that is going to be run when the analyzer is called | |||
* | |||
* @param context the context | |||
* The actual analyzer code. | |||
*/ | |||
void analyse(AnalyzerContext context); | |||
@@ -17,12 +17,13 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.batch.api.analyzer; | |||
package org.sonar.api.batch.analyzer; | |||
import org.sonar.api.batch.analyzer.issue.AnalyzerIssue; | |||
import org.sonar.api.batch.analyzer.measure.AnalyzerMeasure; | |||
import org.sonar.api.batch.analyzer.measure.AnalyzerMeasureBuilder; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.batch.api.analyzer.issue.AnalyzerIssue; | |||
import org.sonar.batch.api.analyzer.measure.AnalyzerMeasure; | |||
import org.sonar.batch.api.measures.Metric; | |||
import org.sonar.api.batch.measures.Metric; | |||
import javax.annotation.CheckForNull; | |||
@@ -36,11 +37,16 @@ public interface AnalyzerContext { | |||
// ----------- MEASURES -------------- | |||
/** | |||
* Builder to create a new {@link AnalyzerMeasure}. | |||
*/ | |||
<G extends Serializable> AnalyzerMeasureBuilder<G> measureBuilder(); | |||
/** | |||
* Find a project measure. | |||
*/ | |||
@CheckForNull | |||
AnalyzerMeasure<?> getMeasure(String metricKey); | |||
AnalyzerMeasure getMeasure(String metricKey); | |||
/** | |||
* Find a project measure. | |||
@@ -52,7 +58,7 @@ public interface AnalyzerContext { | |||
* Find a file measure. | |||
*/ | |||
@CheckForNull | |||
AnalyzerMeasure<?> getMeasure(InputFile file, String metricKey); | |||
AnalyzerMeasure getMeasure(InputFile file, String metricKey); | |||
/** | |||
* Find a file measure. | |||
@@ -61,7 +67,7 @@ public interface AnalyzerContext { | |||
<G extends Serializable> AnalyzerMeasure<G> getMeasure(InputFile file, Metric<G> metric); | |||
/** | |||
* Add a measure. | |||
* Add a measure. Use {@link #measureBuilder()} to create the new measure. | |||
*/ | |||
void addMeasure(AnalyzerMeasure<?> measure); | |||
@@ -0,0 +1,40 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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 02110-1301, USA. | |||
*/ | |||
package org.sonar.api.batch.analyzer; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.api.batch.measures.Metric; | |||
/** | |||
* @since 4.4 | |||
*/ | |||
public interface AnalyzerDescriptor { | |||
AnalyzerDescriptor name(String name); | |||
AnalyzerDescriptor dependsOn(Metric<?>... metrics); | |||
AnalyzerDescriptor provides(Metric<?>... metrics); | |||
AnalyzerDescriptor runOnLanguages(String... languageKeys); | |||
AnalyzerDescriptor runOnTypes(InputFile.Type... types); | |||
} |
@@ -0,0 +1,87 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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 02110-1301, USA. | |||
*/ | |||
package org.sonar.api.batch.analyzer.internal; | |||
import org.sonar.api.batch.analyzer.AnalyzerDescriptor; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.api.batch.measures.Metric; | |||
import java.util.Arrays; | |||
import java.util.Collection; | |||
public class DefaultAnalyzerDescriptor implements AnalyzerDescriptor { | |||
private String name; | |||
private Metric<?>[] dependsOn; | |||
private Metric<?>[] provides; | |||
private String[] languages; | |||
private InputFile.Type[] types; | |||
public String name() { | |||
return name; | |||
} | |||
public Metric<?>[] dependsOn() { | |||
return dependsOn; | |||
} | |||
public Metric<?>[] provides() { | |||
return provides; | |||
} | |||
public Collection<String> languages() { | |||
return Arrays.asList(languages); | |||
} | |||
public InputFile.Type[] types() { | |||
return types; | |||
} | |||
@Override | |||
public DefaultAnalyzerDescriptor name(String name) { | |||
this.name = name; | |||
return this; | |||
} | |||
@Override | |||
public DefaultAnalyzerDescriptor dependsOn(Metric<?>... metrics) { | |||
this.dependsOn = metrics; | |||
return this; | |||
} | |||
@Override | |||
public DefaultAnalyzerDescriptor provides(Metric<?>... metrics) { | |||
this.provides = metrics; | |||
return this; | |||
} | |||
@Override | |||
public DefaultAnalyzerDescriptor runOnLanguages(String... languageKeys) { | |||
this.languages = languageKeys; | |||
return this; | |||
} | |||
@Override | |||
public DefaultAnalyzerDescriptor runOnTypes(InputFile.Type... types) { | |||
this.types = types; | |||
return this; | |||
} | |||
} |
@@ -0,0 +1,21 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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 02110-1301, USA. | |||
*/ | |||
@javax.annotation.ParametersAreNonnullByDefault | |||
package org.sonar.api.batch.analyzer.internal; |
@@ -17,12 +17,12 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.batch.api.analyzer.issue; | |||
package org.sonar.api.batch.analyzer.issue; | |||
import com.google.common.base.Preconditions; | |||
import org.sonar.api.batch.analyzer.Analyzer; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.batch.api.analyzer.Analyzer; | |||
import org.sonar.batch.api.internal.Preconditions; | |||
import org.sonar.batch.api.rules.RuleKey; | |||
import org.sonar.api.rule.RuleKey; | |||
import javax.annotation.Nullable; | |||
@@ -0,0 +1,27 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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 02110-1301, USA. | |||
*/ | |||
/** | |||
* | |||
*/ | |||
/** | |||
* @author julien | |||
* | |||
*/ | |||
package org.sonar.api.batch.analyzer.issue.internal; |
@@ -18,4 +18,4 @@ | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@javax.annotation.ParametersAreNonnullByDefault | |||
package org.sonar.batch.api.analyzer.issue; | |||
package org.sonar.api.batch.analyzer.issue; |
@@ -0,0 +1,45 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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 02110-1301, USA. | |||
*/ | |||
package org.sonar.api.batch.analyzer.measure; | |||
import org.sonar.api.batch.analyzer.Analyzer; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import javax.annotation.Nullable; | |||
import java.io.Serializable; | |||
/** | |||
* A measure produced by {@link Analyzer}. | |||
* @since 4.4 | |||
*/ | |||
public interface AnalyzerMeasure<G extends Serializable> { | |||
/** | |||
* The {@link InputFile} this measure belongs to. Returns null if measure is global to the project. | |||
*/ | |||
@Nullable | |||
InputFile inputFile(); | |||
String metricKey(); | |||
G value(); | |||
} |
@@ -0,0 +1,57 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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 02110-1301, USA. | |||
*/ | |||
package org.sonar.api.batch.analyzer.measure; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.api.batch.measures.Metric; | |||
import java.io.Serializable; | |||
/** | |||
* Builder to create new {@link AnalyzerMeasure} | |||
* @since 4.4 | |||
*/ | |||
public interface AnalyzerMeasureBuilder<G extends Serializable> { | |||
/** | |||
* The file the measure belongs to. | |||
*/ | |||
AnalyzerMeasureBuilder<G> onFile(InputFile file); | |||
/** | |||
* Tell that the measure is global to the project. | |||
*/ | |||
AnalyzerMeasureBuilder<G> onProject(); | |||
/** | |||
* The metric this measure belong to. | |||
*/ | |||
AnalyzerMeasureBuilder<G> forMetric(Metric<G> metric); | |||
/** | |||
* Value of the measure. | |||
*/ | |||
AnalyzerMeasureBuilder<G> withValue(G value); | |||
/** | |||
* Build the measure. | |||
*/ | |||
AnalyzerMeasure<G> build(); | |||
} |
@@ -17,23 +17,23 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.batch.api.analyzer.measure; | |||
package org.sonar.api.batch.analyzer.measure.internal; | |||
import com.google.common.base.Preconditions; | |||
import org.sonar.api.batch.analyzer.measure.AnalyzerMeasure; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.batch.api.internal.Preconditions; | |||
import org.sonar.batch.api.measures.Metric; | |||
import javax.annotation.Nullable; | |||
import java.io.Serializable; | |||
public class AnalyzerMeasure<G extends Serializable> implements Serializable { | |||
public class DefaultAnalyzerMeasure<G extends Serializable> implements AnalyzerMeasure<G>, Serializable { | |||
private final InputFile inputFile; | |||
private final String metricKey; | |||
private final G value; | |||
private AnalyzerMeasure(Builder<G> builder) { | |||
DefaultAnalyzerMeasure(DefaultAnalyzerMeasureBuilder<G> builder) { | |||
Preconditions.checkNotNull(builder.value, "Measure value can't be null"); | |||
Preconditions.checkNotNull(builder.metricKey, "Measure metricKey can't be null"); | |||
this.inputFile = builder.file; | |||
@@ -42,72 +42,27 @@ public class AnalyzerMeasure<G extends Serializable> implements Serializable { | |||
} | |||
@Nullable | |||
@Override | |||
public InputFile inputFile() { | |||
return inputFile; | |||
} | |||
@Override | |||
public String metricKey() { | |||
return metricKey; | |||
} | |||
public Serializable value() { | |||
@Override | |||
public G value() { | |||
return value; | |||
} | |||
public static <G extends Serializable> Builder<G> builder() { | |||
return new Builder<G>(); | |||
} | |||
public static class Builder<G extends Serializable> { | |||
private Boolean onProject = null; | |||
private InputFile file; | |||
private String metricKey; | |||
private G value; | |||
public Builder<G> onFile(InputFile file) { | |||
Preconditions.checkState(onProject == null, "onFile or onProject can be called only once"); | |||
Preconditions.checkNotNull(file, "InputFile should be non null"); | |||
this.file = file; | |||
this.onProject = false; | |||
return this; | |||
} | |||
public Builder<G> onProject() { | |||
Preconditions.checkState(onProject == null, "onFile or onProject can be called only once"); | |||
this.file = null; | |||
this.onProject = true; | |||
return this; | |||
} | |||
private Builder<G> metricKey(String metricKey) { | |||
Preconditions.checkState(metricKey != null, "Metric already defined"); | |||
this.metricKey = metricKey; | |||
return this; | |||
} | |||
public Builder<G> forMetric(Metric<G> metric) { | |||
return metricKey(metric.key()); | |||
} | |||
public Builder<G> withValue(G value) { | |||
Preconditions.checkState(value != null, "Measure value already defined"); | |||
Preconditions.checkNotNull(value, "Measure value can't be null"); | |||
this.value = value; | |||
return this; | |||
} | |||
public AnalyzerMeasure<G> build() { | |||
return new AnalyzerMeasure<G>(this); | |||
} | |||
} | |||
@Override | |||
public boolean equals(Object obj) { | |||
if (!(obj instanceof AnalyzerMeasure)) { | |||
if (!(obj instanceof DefaultAnalyzerMeasure)) { | |||
return false; | |||
} | |||
AnalyzerMeasure<?> other = (AnalyzerMeasure<?>) obj; | |||
DefaultAnalyzerMeasure<?> other = (DefaultAnalyzerMeasure<?>) obj; | |||
return metricKey.equals(other.metricKey) | |||
&& value.equals(other.value) | |||
&& (inputFile == null ? other.inputFile == null : inputFile.equals(other.inputFile)); |
@@ -0,0 +1,77 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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 02110-1301, USA. | |||
*/ | |||
package org.sonar.api.batch.analyzer.measure.internal; | |||
import com.google.common.base.Preconditions; | |||
import org.sonar.api.batch.analyzer.measure.AnalyzerMeasure; | |||
import org.sonar.api.batch.analyzer.measure.AnalyzerMeasureBuilder; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.api.batch.measures.Metric; | |||
import java.io.Serializable; | |||
public class DefaultAnalyzerMeasureBuilder<G extends Serializable> implements AnalyzerMeasureBuilder<G> { | |||
Boolean onProject = null; | |||
InputFile file; | |||
String metricKey; | |||
G value; | |||
@Override | |||
public AnalyzerMeasureBuilder<G> onFile(InputFile file) { | |||
Preconditions.checkState(onProject == null, "onFile or onProject can be called only once"); | |||
Preconditions.checkNotNull(file, "InputFile should be non null"); | |||
this.file = file; | |||
this.onProject = false; | |||
return this; | |||
} | |||
@Override | |||
public AnalyzerMeasureBuilder<G> onProject() { | |||
Preconditions.checkState(onProject == null, "onFile or onProject can be called only once"); | |||
this.file = null; | |||
this.onProject = true; | |||
return this; | |||
} | |||
private AnalyzerMeasureBuilder<G> metricKey(String metricKey) { | |||
Preconditions.checkState(metricKey != null, "Metric already defined"); | |||
this.metricKey = metricKey; | |||
return this; | |||
} | |||
@Override | |||
public AnalyzerMeasureBuilder<G> forMetric(Metric<G> metric) { | |||
return metricKey(metric.key()); | |||
} | |||
@Override | |||
public AnalyzerMeasureBuilder<G> withValue(G value) { | |||
Preconditions.checkState(value != null, "Measure value already defined"); | |||
Preconditions.checkNotNull(value, "Measure value can't be null"); | |||
this.value = value; | |||
return this; | |||
} | |||
@Override | |||
public AnalyzerMeasure<G> build() { | |||
return new DefaultAnalyzerMeasure<G>(this); | |||
} | |||
} |
@@ -0,0 +1,21 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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 02110-1301, USA. | |||
*/ | |||
@javax.annotation.ParametersAreNonnullByDefault | |||
package org.sonar.api.batch.analyzer.measure.internal; |
@@ -18,4 +18,4 @@ | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@javax.annotation.ParametersAreNonnullByDefault | |||
package org.sonar.batch.api.analyzer.measure; | |||
package org.sonar.api.batch.analyzer.measure; |
@@ -18,4 +18,4 @@ | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@javax.annotation.ParametersAreNonnullByDefault | |||
package org.sonar.batch.api.analyzer; | |||
package org.sonar.api.batch.analyzer; |
@@ -19,7 +19,7 @@ | |||
*/ | |||
package org.sonar.api.batch.fs; | |||
import org.sonar.batch.api.BatchComponent; | |||
import org.sonar.api.BatchComponent; | |||
import javax.annotation.CheckForNull; | |||
@@ -19,7 +19,7 @@ | |||
*/ | |||
package org.sonar.api.batch.fs; | |||
import org.sonar.batch.api.BatchExtension; | |||
import org.sonar.api.BatchExtension; | |||
/** | |||
* Extension point to exclude some files from inspection |
@@ -21,7 +21,7 @@ package org.sonar.api.batch.fs.internal; | |||
import org.sonar.api.batch.fs.FilePredicate; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.batch.api.internal.FilenameUtils; | |||
import org.sonar.api.utils.PathUtils; | |||
/** | |||
* @since 4.2 | |||
@@ -31,7 +31,7 @@ class AbsolutePathPredicate implements FilePredicate { | |||
private final String path; | |||
AbsolutePathPredicate(String path) { | |||
this.path = FilenameUtils.normalize(path); | |||
this.path = PathUtils.sanitize(path); | |||
} | |||
@Override |
@@ -19,11 +19,11 @@ | |||
*/ | |||
package org.sonar.api.batch.fs.internal; | |||
import com.google.common.base.Preconditions; | |||
import org.sonar.api.batch.fs.FilePredicate; | |||
import org.sonar.api.batch.fs.FilePredicates; | |||
import org.sonar.api.batch.fs.FileSystem; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.batch.api.internal.Preconditions; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; |
@@ -20,7 +20,7 @@ | |||
package org.sonar.api.batch.fs.internal; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.batch.api.internal.FilenameUtils; | |||
import org.sonar.api.utils.PathUtils; | |||
import javax.annotation.CheckForNull; | |||
@@ -42,7 +42,7 @@ public class DefaultInputFile implements InputFile, Serializable { | |||
private String key; | |||
public DefaultInputFile(String relativePath) { | |||
this.relativePath = FilenameUtils.normalize(relativePath); | |||
this.relativePath = PathUtils.sanitize(relativePath); | |||
} | |||
@Override | |||
@@ -117,7 +117,7 @@ public class DefaultInputFile implements InputFile, Serializable { | |||
} | |||
public DefaultInputFile setAbsolutePath(String s) { | |||
this.absolutePath = FilenameUtils.normalize(s); | |||
this.absolutePath = PathUtils.sanitize(s); | |||
return this; | |||
} | |||
@@ -19,7 +19,7 @@ | |||
*/ | |||
package org.sonar.api.batch.fs.internal; | |||
import org.sonar.batch.api.internal.FilenameUtils; | |||
import org.sonar.api.utils.PathUtils; | |||
import java.io.BufferedInputStream; | |||
import java.io.File; | |||
@@ -51,7 +51,7 @@ public class DeprecatedDefaultInputFile extends DefaultInputFile implements org. | |||
} | |||
public void setBasedir(File basedir) { | |||
this.basedir = FilenameUtils.normalize(basedir.getAbsolutePath()); | |||
this.basedir = PathUtils.sanitize(basedir.getAbsolutePath()); | |||
} | |||
/** | |||
@@ -92,7 +92,7 @@ public class DeprecatedDefaultInputFile extends DefaultInputFile implements org. | |||
} | |||
public DeprecatedDefaultInputFile setSourceDirAbsolutePath(String s) { | |||
this.sourceDirAbsolutePath = FilenameUtils.normalize(s); | |||
this.sourceDirAbsolutePath = PathUtils.sanitize(s); | |||
return this; | |||
} | |||
@@ -105,7 +105,7 @@ public class DeprecatedDefaultInputFile extends DefaultInputFile implements org. | |||
} | |||
public DeprecatedDefaultInputFile setPathRelativeToSourceDir(String s) { | |||
this.pathRelativeToSourceDir = FilenameUtils.normalize(s); | |||
this.pathRelativeToSourceDir = PathUtils.sanitize(s); | |||
return this; | |||
} | |||
@@ -19,10 +19,10 @@ | |||
*/ | |||
package org.sonar.api.batch.fs.internal; | |||
import org.apache.commons.io.FilenameUtils; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.batch.api.internal.FilenameUtils; | |||
import org.sonar.batch.api.internal.StringUtils; | |||
import org.sonar.batch.api.internal.WildcardPattern; | |||
import org.sonar.api.utils.WildcardPattern; | |||
public abstract class PathPattern { | |||
@@ -21,7 +21,7 @@ package org.sonar.api.batch.fs.internal; | |||
import org.sonar.api.batch.fs.FilePredicate; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.batch.api.internal.FilenameUtils; | |||
import org.sonar.api.utils.PathUtils; | |||
/** | |||
* @since 4.2 | |||
@@ -31,7 +31,7 @@ public class RelativePathPredicate implements FilePredicate { | |||
private final String path; | |||
RelativePathPredicate(String path) { | |||
this.path = FilenameUtils.normalize(path); | |||
this.path = PathUtils.sanitize(path); | |||
} | |||
public String path() { |
@@ -17,7 +17,7 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.batch.api.languages; | |||
package org.sonar.api.batch.languages; | |||
import java.util.Arrays; | |||
import java.util.Collection; |
@@ -18,4 +18,4 @@ | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@javax.annotation.ParametersAreNonnullByDefault | |||
package org.sonar.batch.api.languages; | |||
package org.sonar.api.batch.languages; |
@@ -17,7 +17,7 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.batch.api.measures; | |||
package org.sonar.api.batch.measures; | |||
import java.io.Serializable; | |||
@@ -18,4 +18,4 @@ | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@javax.annotation.ParametersAreNonnullByDefault | |||
package org.sonar.batch.api.internal; | |||
package org.sonar.api.batch.measures; |
@@ -17,7 +17,7 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.batch.api.rules; | |||
package org.sonar.api.batch.rules; | |||
public class QProfile { | |||
private final String name, language; |
@@ -18,4 +18,4 @@ | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@javax.annotation.ParametersAreNonnullByDefault | |||
package org.sonar.batch.api.rules; | |||
package org.sonar.api.batch.rules; |
@@ -51,7 +51,7 @@ public final class MeasuresFilters { | |||
}; | |||
} | |||
public static MeasuresFilter<Measure> metric(final org.sonar.batch.api.measures.Metric<?> metric) { | |||
public static MeasuresFilter<Measure> metric(final org.sonar.api.batch.measures.Metric<?> metric) { | |||
return metric(metric.key()); | |||
} | |||
@@ -46,7 +46,7 @@ import java.io.Serializable; | |||
@Table(name = "metrics") | |||
@Entity(name = "Metric") | |||
@InstantiationStrategy(InstantiationStrategy.PER_BATCH) | |||
public class Metric<G extends Serializable> implements ServerExtension, BatchExtension, Serializable, org.sonar.batch.api.measures.Metric<G> { | |||
public class Metric<G extends Serializable> implements ServerExtension, BatchExtension, Serializable, org.sonar.api.batch.measures.Metric<G> { | |||
/** | |||
* A metric bigger value means a degradation |