aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-03-26 16:31:26 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2014-03-26 16:31:47 +0100
commit88823aa9297fda7aa0fcf0e3b79e55747978a0fb (patch)
treeeafb27f91d5bcf5ec1705b5ad022e4e2a7d81023
parent74255d29d42c2eca4ce0e4a89dc0b8686b9e50a3 (diff)
downloadsonarqube-88823aa9297fda7aa0fcf0e3b79e55747978a0fb.tar.gz
sonarqube-88823aa9297fda7aa0fcf0e3b79e55747978a0fb.zip
Fix some quality flaws
-rw-r--r--plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenProjectConverter.java3
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java12
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java12
-rw-r--r--sonar-deprecated/src/main/java/org/sonar/api/batch/SquidUtils.java8
-rw-r--r--sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java16
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractCpdMapping.java3
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/checks/NoSonarFilter.java6
8 files changed, 39 insertions, 25 deletions
diff --git a/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenProjectConverter.java b/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenProjectConverter.java
index fd9fa8064da..47082d40b2a 100644
--- a/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenProjectConverter.java
+++ b/plugins/sonar-maven-batch-plugin/src/main/java/org/sonar/plugins/maven/MavenProjectConverter.java
@@ -31,6 +31,7 @@ import org.apache.maven.model.IssueManagement;
import org.apache.maven.model.Scm;
import org.apache.maven.project.MavenProject;
import org.sonar.api.CoreProperties;
+import org.sonar.api.batch.SupportedEnvironment;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.maven.MavenUtils;
import org.sonar.api.task.TaskExtension;
@@ -39,6 +40,7 @@ import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem;
import org.sonar.java.api.JavaUtils;
import javax.annotation.Nullable;
+
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
@@ -46,6 +48,7 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
+@SupportedEnvironment("maven")
public class MavenProjectConverter implements TaskExtension {
private static final String UNABLE_TO_DETERMINE_PROJECT_STRUCTURE_EXCEPTION_MESSAGE = "Unable to determine structure of project." +
diff --git a/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java b/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java
index 3a5ff6f4539..460131fd5e9 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/DefaultFileLinesContextFactory.java
@@ -35,9 +35,9 @@ public class DefaultFileLinesContextFactory implements FileLinesContextFactory {
}
@Override
- public FileLinesContext createFor(Resource resource) {
+ public FileLinesContext createFor(Resource model) {
// Reload resource in case it use deprecated key
- resource = index.getResource(resource);
+ Resource resource = index.getResource(model);
return new DefaultFileLinesContext(index, resource);
}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java
index 018237eae4f..840c9ec8869 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java
@@ -43,12 +43,6 @@ public final class PhaseExecutor {
public static final Logger LOGGER = LoggerFactory.getLogger(PhaseExecutor.class);
- public static Collection<Class> getPhaseClasses() {
- return Lists.<Class>newArrayList(DecoratorsExecutor.class, MavenPhaseExecutor.class, MavenPluginsConfigurator.class,
- PostJobsExecutor.class, SensorsExecutor.class,
- InitializersExecutor.class, ProjectInitializer.class, UpdateStatusJob.class);
- }
-
private final EventBus eventBus;
private final Phases phases;
private final DecoratorsExecutor decoratorsExecutor;
@@ -107,6 +101,12 @@ public final class PhaseExecutor {
sensorsExecutor, persistenceManager, sensorContext, index, eventBus, null, pi, persisters, fsLogger, jsonReport, fs, profileVerifier, issueExclusionsLoader);
}
+ public static Collection<Class> getPhaseClasses() {
+ return Lists.<Class>newArrayList(DecoratorsExecutor.class, MavenPhaseExecutor.class, MavenPluginsConfigurator.class,
+ PostJobsExecutor.class, SensorsExecutor.class,
+ InitializersExecutor.class, ProjectInitializer.class, UpdateStatusJob.class);
+ }
+
/**
* Executed on each module
*/
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
index 2447fa0aaad..ea5692fb4b3 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/DefaultModuleFileSystem.java
@@ -37,9 +37,9 @@ import org.sonar.api.utils.SonarException;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+
import java.io.File;
import java.nio.charset.Charset;
-import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -67,7 +67,7 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module
private boolean initialized;
public DefaultModuleFileSystem(ModuleInputFileCache moduleInputFileCache, Project module, Settings settings, FileIndexer indexer, ModuleFileSystemInitializer initializer,
- ComponentIndexer componentIndexer) {
+ ComponentIndexer componentIndexer) {
super(moduleInputFileCache);
this.componentIndexer = componentIndexer;
this.moduleKey = module.getKey();
@@ -146,7 +146,7 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module
*/
@Deprecated
void addSourceDir(File dir) {
- throw new UnsupportedOperationException("Modifications of the file system are not permitted");
+ throw modificationNotPermitted();
}
/**
@@ -156,7 +156,11 @@ public class DefaultModuleFileSystem extends DefaultFileSystem implements Module
*/
@Deprecated
void addTestDir(File dir) {
- throw new UnsupportedOperationException("Modifications of the file system are not permitted");
+ throw modificationNotPermitted();
+ }
+
+ private UnsupportedOperationException modificationNotPermitted() {
+ return new UnsupportedOperationException("Modifications of the file system are not permitted");
}
/**
diff --git a/sonar-deprecated/src/main/java/org/sonar/api/batch/SquidUtils.java b/sonar-deprecated/src/main/java/org/sonar/api/batch/SquidUtils.java
index 5a7e3a1475e..b3ead5d4214 100644
--- a/sonar-deprecated/src/main/java/org/sonar/api/batch/SquidUtils.java
+++ b/sonar-deprecated/src/main/java/org/sonar/api/batch/SquidUtils.java
@@ -37,7 +37,7 @@ public final class SquidUtils {
*/
@Deprecated
public static JavaFile convertJavaFileKeyFromSquidFormat(String key) {
- throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
+ throw unsupported();
}
/**
@@ -45,7 +45,11 @@ public final class SquidUtils {
*/
@Deprecated
public static JavaPackage convertJavaPackageKeyFromSquidFormat(String key) {
- throw new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
+ throw unsupported();
+ }
+
+ private static UnsupportedOperationException unsupported() {
+ return new UnsupportedOperationException("Not supported since v4.2. See http://docs.codehaus.org/display/SONAR/API+Changes");
}
/**
diff --git a/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java b/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java
index 8cb4d94460e..0164c2e0c11 100644
--- a/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java
+++ b/sonar-maven-plugin/src/main/java/org/sonar/maven/SonarMojo.java
@@ -232,12 +232,7 @@ public final class SonarMojo extends AbstractMojo {
try {
for (String key : properties.stringPropertyNames()) {
if (key.contains(".password")) {
- try {
- String decrypted = securityDispatcher.decrypt(properties.getProperty(key));
- newProperties.setProperty(key, decrypted);
- } catch (SecDispatcherException e) {
- getLog().warn("Unable to decrypt property " + key, e);
- }
+ decrypt(properties, newProperties, key);
}
}
} catch (Exception e) {
@@ -245,4 +240,13 @@ public final class SonarMojo extends AbstractMojo {
}
return newProperties;
}
+
+ private void decrypt(Properties properties, Properties newProperties, String key) {
+ try {
+ String decrypted = securityDispatcher.decrypt(properties.getProperty(key));
+ newProperties.setProperty(key, decrypted);
+ } catch (SecDispatcherException e) {
+ getLog().warn("Unable to decrypt property " + key, e);
+ }
+ }
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractCpdMapping.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractCpdMapping.java
index 6c76e04ef23..902680daaeb 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractCpdMapping.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractCpdMapping.java
@@ -19,7 +19,6 @@
*/
package org.sonar.api.batch;
-import org.sonar.api.resources.File;
import org.sonar.api.resources.Resource;
import java.util.List;
@@ -35,6 +34,6 @@ public abstract class AbstractCpdMapping implements CpdMapping {
* {@inheritDoc}
*/
public Resource createResource(java.io.File file, List<java.io.File> sourceDirs) {
- return File.fromIOFile(file, sourceDirs);
+ throw new UnsupportedOperationException("Deprecated since 4.2");
}
}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/checks/NoSonarFilter.java b/sonar-plugin-api/src/main/java/org/sonar/api/checks/NoSonarFilter.java
index 2fc49ea74f9..05c4bd9bfaf 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/checks/NoSonarFilter.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/checks/NoSonarFilter.java
@@ -43,10 +43,10 @@ public class NoSonarFilter implements ViolationFilter {
this.context = context;
}
- public void addResource(Resource resource, Set<Integer> noSonarLines) {
- if (resource != null && noSonarLines != null) {
+ public void addResource(Resource model, Set<Integer> noSonarLines) {
+ if (model != null && noSonarLines != null) {
// Reload resource to handle backward compatibility of resource keys
- resource = context.getResource(resource);
+ Resource resource = context.getResource(model);
if (resource != null) {
noSonarLinesByResource.put(resource, noSonarLines);
}