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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ void mapping() {
assertThat(repository(Slf4jLoggerShouldBePrivate.class)).isEqualTo(ERRORPRONE_SLF4J_REPOSITORY);
assertThat(repository(JUnitValueSource.class)).isEqualTo(PICNIC_REPOSITORY);
}

@Test
void unknownRepository() {
assertThrows(ErrorAwayException.class, () -> ErrorAwayRulesMapping.repository(UnknownBugChecker.class));
}

@Test
void pluginChecker() {
assertDoesNotThrow(() -> ErrorAwayRulesMapping.pluginCheckers());
assertDoesNotThrow(ErrorAwayRulesMapping::pluginCheckers);
}

@BugPattern(summary = "", severity = SeverityLevel.ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public ErrorAwayDependencyManager(TempFolder tempFolder, Configuration configura
this.tempFolder = tempFolder;
this.configuration = configuration;

workOffline = configuration.getBoolean(ErrorAwayPlugin.MAVEN_WORK_OFFLINE).orElse(false);
workOffline = configuration.getBoolean(ErrorAwayPluginConstants.MAVEN_WORK_OFFLINE).orElse(false);

DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
Expand Down Expand Up @@ -120,7 +120,7 @@ private Settings settings(Configuration configuration) {
SettingsBuildingRequest request = new DefaultSettingsBuildingRequest();

File userSettingsFile;
Optional<String> userSettingsFileValue = configuration.get(ErrorAwayPlugin.MAVEN_USER_SETTINGS_FILE);
Optional<String> userSettingsFileValue = configuration.get(ErrorAwayPluginConstants.MAVEN_USER_SETTINGS_FILE);
if (userSettingsFileValue.isPresent()) {
userSettingsFile = new File(userSettingsFileValue.get());
} else {
Expand All @@ -139,8 +139,8 @@ private Settings settings(Configuration configuration) {

private LocalRepository localRepository(Settings settings) {
File localRepositoryDir;
Optional<String> localRepositoryValue = configuration.get(ErrorAwayPlugin.MAVEN_LOCAL_REPOSITORY);
Optional<Boolean> useTemporaryLocalRepositoryValue = configuration.getBoolean(ErrorAwayPlugin.MAVEN_USE_TEMP_LOCAL_REPOSITORY);
Optional<String> localRepositoryValue = configuration.get(ErrorAwayPluginConstants.MAVEN_LOCAL_REPOSITORY);
Optional<Boolean> useTemporaryLocalRepositoryValue = configuration.getBoolean(ErrorAwayPluginConstants.MAVEN_USE_TEMP_LOCAL_REPOSITORY);

if (localRepositoryValue.isPresent()) {
localRepositoryDir = new File(localRepositoryValue.get());
Expand All @@ -157,7 +157,7 @@ private LocalRepository localRepository(Settings settings) {
}

private List<RemoteRepository> remoteRepositories() {
String[] configurationRepositories = configuration.getStringArray(ErrorAwayPlugin.MAVEN_REPOSITORIES);
String[] configurationRepositories = configuration.getStringArray(ErrorAwayPluginConstants.MAVEN_REPOSITORIES);
List<RemoteRepository> repositories = new ArrayList<>();
int i = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
*/
package com.github.erroraway.sonarqube;

import static com.github.erroraway.sonarqube.ErrorAwayPluginConstants.ANNOTATION_PROCESSORS_MAVEN_COORDINATES;
import static com.github.erroraway.sonarqube.ErrorAwayPluginConstants.CLASS_PATH_MAVEN_COORDINATES;
import static com.github.erroraway.sonarqube.ErrorAwayPluginConstants.MAVEN_LOCAL_REPOSITORY;
import static com.github.erroraway.sonarqube.ErrorAwayPluginConstants.MAVEN_REPOSITORIES;
import static com.github.erroraway.sonarqube.ErrorAwayPluginConstants.MAVEN_USER_SETTINGS_FILE;
import static com.github.erroraway.sonarqube.ErrorAwayPluginConstants.MAVEN_USE_TEMP_LOCAL_REPOSITORY;
import static com.github.erroraway.sonarqube.ErrorAwayPluginConstants.MAVEN_WORK_OFFLINE;

import org.sonar.api.Plugin;
import org.sonar.api.PropertyType;
import org.sonar.api.config.PropertyDefinition;
Expand All @@ -29,14 +37,6 @@ public class ErrorAwayPlugin implements Plugin {
private static final String PROPERTY_ERRORAWAY_CATEGORY = "ErrorAway";
private static final String PROPERTY_MAVEN_SUBCATEGORY = "Maven";

public static final String MAVEN_WORK_OFFLINE = "erroraway.maven.work.offline";
public static final String MAVEN_USER_SETTINGS_FILE = "erroraway.maven.user.settings.file";
public static final String MAVEN_LOCAL_REPOSITORY = "erroraway.maven.local.repository";
public static final String MAVEN_USE_TEMP_LOCAL_REPOSITORY = "erroraway.maven.use.temp.local.repository";
public static final String MAVEN_REPOSITORIES = "erroraway.maven.repositories";
public static final String CLASS_PATH_MAVEN_COORDINATES = "erroraway.classpath.maven.coordinates";
public static final String ANNOTATION_PROCESSORS_MAVEN_COORDINATES = "erroraway.annotation.processors.maven.coordinates";

@Override
public void define(Context context) {
context.addExtension(PropertyDefinition
Expand All @@ -48,7 +48,7 @@ public void define(Context context) {
.onQualifiers(Qualifiers.PROJECT)
.type(PropertyType.BOOLEAN)
.build());

context.addExtension(PropertyDefinition
.builder(MAVEN_USER_SETTINGS_FILE)
.name("Maven user settings file")
Expand All @@ -57,7 +57,7 @@ public void define(Context context) {
.subCategory(PROPERTY_MAVEN_SUBCATEGORY)
.onQualifiers(Qualifiers.PROJECT)
.build());

context.addExtension(PropertyDefinition
.builder(MAVEN_LOCAL_REPOSITORY)
.name("Maven local repository")
Expand All @@ -66,7 +66,7 @@ public void define(Context context) {
.subCategory(PROPERTY_MAVEN_SUBCATEGORY)
.onQualifiers(Qualifiers.PROJECT)
.build());

context.addExtension(PropertyDefinition
.builder(MAVEN_USE_TEMP_LOCAL_REPOSITORY)
.name("Use Maven temporary local repository")
Expand All @@ -76,7 +76,7 @@ public void define(Context context) {
.onQualifiers(Qualifiers.PROJECT)
.type(PropertyType.BOOLEAN)
.build());

context.addExtension(PropertyDefinition
.builder(MAVEN_REPOSITORIES)
.name("Maven repositories")
Expand All @@ -86,7 +86,7 @@ public void define(Context context) {
.onQualifiers(Qualifiers.PROJECT)
.multiValues(true)
.build());

context.addExtension(PropertyDefinition
.builder(CLASS_PATH_MAVEN_COORDINATES)
.name("Classpath Maven coordinates")
Expand All @@ -96,7 +96,7 @@ public void define(Context context) {
.onQualifiers(Qualifiers.PROJECT)
.multiValues(true)
.build());

context.addExtension(PropertyDefinition
.builder(ANNOTATION_PROCESSORS_MAVEN_COORDINATES)
.name("Annotation processors Maven coordinates")
Expand All @@ -106,7 +106,7 @@ public void define(Context context) {
.onQualifiers(Qualifiers.PROJECT)
.multiValues(true)
.build());

for (NullAwayOption option : NullAwayOption.values()) {
context.addExtension(PropertyDefinition
.builder(option.getKey())
Expand All @@ -117,7 +117,7 @@ public void define(Context context) {
.multiValues(true)
.build());
}

context.addExtension(ErrorAwayRulesDefinition.class);
context.addExtension(ErrorAwayQualityProfile.class);
context.addExtension(ErrorAwaySensor.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
*
*/
package com.github.erroraway.sonarqube;

/**
* @author gtoison
*/
public final class ErrorAwayPluginConstants {

public static final String MAVEN_WORK_OFFLINE = "erroraway.maven.work.offline";
public static final String MAVEN_USER_SETTINGS_FILE = "erroraway.maven.user.settings.file";
public static final String MAVEN_LOCAL_REPOSITORY = "erroraway.maven.local.repository";
public static final String MAVEN_USE_TEMP_LOCAL_REPOSITORY = "erroraway.maven.use.temp.local.repository";
public static final String MAVEN_REPOSITORIES = "erroraway.maven.repositories";
public static final String CLASS_PATH_MAVEN_COORDINATES = "erroraway.classpath.maven.coordinates";
public static final String ANNOTATION_PROCESSORS_MAVEN_COORDINATES = "erroraway.annotation.processors.maven.coordinates";

private ErrorAwayPluginConstants() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private ErrorProneOptions buildErrorProneOptions(SensorContext context) {

// When some annotation processors are enabled com.google.errorprone.ErrorPronePlugins turns on plugin
// scanning and tries to instanciate NullAway
if (configuration.hasKey(ErrorAwayPlugin.ANNOTATION_PROCESSORS_MAVEN_COORDINATES)) {
if (configuration.hasKey(ErrorAwayPluginConstants.ANNOTATION_PROCESSORS_MAVEN_COORDINATES)) {
options.add("-XepOpt:NullAway:" + NullAwayOption.ANNOTATED_PACKAGES.getErrorproneOption() + "=foo.bar");
}
}
Expand Down Expand Up @@ -188,17 +188,17 @@ private Iterable<? extends JavaFileObject> buildCompilationUnits(SensorContext c
private void configureClasspath(StandardJavaFileManager fileManager, Configuration configuration, FileSystem fs) throws IOException {
ClasspathForMain classpathForMain = new ClasspathForMain(configuration, fs);
Collection<File> classpath = new ArrayList<>(classpathForMain.getElements());
if (configuration.hasKey(ErrorAwayPlugin.CLASS_PATH_MAVEN_COORDINATES)) {
String[] coordinates = configuration.getStringArray(ErrorAwayPlugin.CLASS_PATH_MAVEN_COORDINATES);
if (configuration.hasKey(ErrorAwayPluginConstants.CLASS_PATH_MAVEN_COORDINATES)) {
String[] coordinates = configuration.getStringArray(ErrorAwayPluginConstants.CLASS_PATH_MAVEN_COORDINATES);
classpath.addAll(dependencyManager.downloadDependencies(coordinates));
}

fileManager.setLocation(StandardLocation.CLASS_PATH, classpath);
}

private void configureAnnotationProcessors(StandardJavaFileManager fileManager, Configuration configuration) throws IOException {
if (configuration.hasKey(ErrorAwayPlugin.ANNOTATION_PROCESSORS_MAVEN_COORDINATES)) {
String[] coordinates = configuration.getStringArray(ErrorAwayPlugin.ANNOTATION_PROCESSORS_MAVEN_COORDINATES);
if (configuration.hasKey(ErrorAwayPluginConstants.ANNOTATION_PROCESSORS_MAVEN_COORDINATES)) {
String[] coordinates = configuration.getStringArray(ErrorAwayPluginConstants.ANNOTATION_PROCESSORS_MAVEN_COORDINATES);
Collection<File> annotationProcessors = dependencyManager.downloadDependencies(coordinates);

fileManager.setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, annotationProcessors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ void setup() {

@Test
void invalidSettings() {
ErrorAwayTestUtil.setConfiguration(configuration, ErrorAwayPlugin.MAVEN_USER_SETTINGS_FILE,
ErrorAwayTestUtil.setConfiguration(configuration, ErrorAwayPluginConstants.MAVEN_USER_SETTINGS_FILE,
"src/test/resources/samples/invalid-settings.xml");

assertThrows(ErrorAwayException.class, () -> new ErrorAwayDependencyManager(tempFolder, configuration));
}

@Test
void invalidArtifactCoordinates() {
when(configuration.getBoolean(ErrorAwayPlugin.MAVEN_WORK_OFFLINE)).thenReturn(Optional.of(true));
when(configuration.getBoolean(ErrorAwayPluginConstants.MAVEN_WORK_OFFLINE)).thenReturn(Optional.of(true));
ErrorAwayDependencyManager dependencyManager = new ErrorAwayDependencyManager(tempFolder, configuration);

assertThrows(ErrorAwayException.class, () -> dependencyManager.downloadDependencies("x:y:1.2.3"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ void analyzeWithErrorProneRule() {

@Test
void analyzeWithAnnotationProcessor() {
setConfigurationStringArray(ErrorAwayPlugin.CLASS_PATH_MAVEN_COORDINATES, new String[]{"com.google.auto.value:auto-value-annotations:1.9"});
setConfigurationStringArray(ErrorAwayPlugin.ANNOTATION_PROCESSORS_MAVEN_COORDINATES, new String[]{"com.google.auto.value:auto-value:1.9"});
setConfigurationBoolean(ErrorAwayPlugin.MAVEN_USE_TEMP_LOCAL_REPOSITORY, true);
setConfigurationStringArray(ErrorAwayPlugin.MAVEN_REPOSITORIES, new String[]{"https://repo1.maven.org/maven2/"});
setConfigurationStringArray(ErrorAwayPluginConstants.CLASS_PATH_MAVEN_COORDINATES, new String[] { "com.google.auto.value:auto-value-annotations:1.9" });
setConfigurationStringArray(ErrorAwayPluginConstants.ANNOTATION_PROCESSORS_MAVEN_COORDINATES, new String[] { "com.google.auto.value:auto-value:1.9" });
setConfigurationBoolean(ErrorAwayPluginConstants.MAVEN_USE_TEMP_LOCAL_REPOSITORY, true);
setConfigurationStringArray(ErrorAwayPluginConstants.MAVEN_REPOSITORIES, new String[] { "https://repo1.maven.org/maven2/" });

setup(Path.of("com/bug/AutoValueSamples.java"));
enableRule(RuleKey.of("errorprone", "DurationTemporalUnit"));
Expand Down Expand Up @@ -230,12 +230,12 @@ void analyzeWithNullAwayWithoutAnnotatedPackageOption() {

@Test
void analyzeWithErrorProneSlf4j() {
setConfigurationStringArray(ErrorAwayPlugin.MAVEN_REPOSITORIES, new String[] {"https://repo1.maven.org/maven2/"});
setConfigurationStringArray(ErrorAwayPluginConstants.MAVEN_REPOSITORIES, new String[] { "https://repo1.maven.org/maven2/" });
setup(Path.of("com/bug/Slf4jSamples.java"));

RuleKey ruleKey = RuleKey.of("errorprone-slf4j", "Slf4jPlaceholderMismatch");
enableRule(ruleKey);
setConfigurationStringArray(ErrorAwayPlugin.CLASS_PATH_MAVEN_COORDINATES, new String[]{"org.slf4j:slf4j-api:1.7.36"});
setConfigurationStringArray(ErrorAwayPluginConstants.CLASS_PATH_MAVEN_COORDINATES, new String[] { "org.slf4j:slf4j-api:1.7.36" });

// Call the sensor
ErrorAwaySensor sensor = new ErrorAwaySensor(dependencyManager, tempFolder);
Expand All @@ -247,13 +247,13 @@ void analyzeWithErrorProneSlf4j() {

@Test
void analyzeWithPicnicErrorProneSupport() {
setConfigurationStringArray(ErrorAwayPlugin.MAVEN_REPOSITORIES, new String[]{"https://repo1.maven.org/maven2/"});
setConfigurationStringArray(ErrorAwayPluginConstants.MAVEN_REPOSITORIES, new String[] { "https://repo1.maven.org/maven2/" });
setup(Path.of("com/bug/PicnicErrorProneSupportSample.java"));

RuleKey ruleKey = RuleKey.of(ErrorAwayRulesMapping.PICNIC_REPOSITORY, "IdentityConversion");
enableRule(ruleKey);
setConfigurationStringArray(
ErrorAwayPlugin.CLASS_PATH_MAVEN_COORDINATES,
ErrorAwayPluginConstants.CLASS_PATH_MAVEN_COORDINATES,
new String[]{"com.google.guava:guava:31.1-jre"});

// Call the sensor
Expand Down
Loading