From b34de6cbb17ae0f15c5ddc19573e0c8704ac564c Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 1 Jul 2014 17:45:56 +0200 Subject: [PATCH] Fix quality flaws --- .../java/org/sonar/application/StartServer.java | 3 +-- .../filesystem/ProjectFileSystemAdapter.java | 1 - .../org/sonar/core/rule/CacheRuleFinder.java | 16 +++------------- .../java/org/sonar/api/utils/PathUtilsTest.java | 2 +- .../org/sonar/server/issue/IssueService.java | 1 - .../org/sonar/server/rule/DefaultRuleFinder.java | 5 ++--- 6 files changed, 7 insertions(+), 21 deletions(-) diff --git a/sonar-application/src/main/java/org/sonar/application/StartServer.java b/sonar-application/src/main/java/org/sonar/application/StartServer.java index 0d1c8ef5093..dd51a5247c4 100644 --- a/sonar-application/src/main/java/org/sonar/application/StartServer.java +++ b/sonar-application/src/main/java/org/sonar/application/StartServer.java @@ -22,7 +22,6 @@ package org.sonar.application; import org.apache.catalina.LifecycleException; import java.io.IOException; -import java.net.URISyntaxException; public final class StartServer { @@ -46,7 +45,7 @@ public final class StartServer { tomcat.stop(); } - public static void main(String[] args) throws URISyntaxException, IOException, LifecycleException { + public static void main(String[] args) throws Exception { new StartServer(new Env()).start(); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ProjectFileSystemAdapter.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ProjectFileSystemAdapter.java index c42c1d75fac..ba0fe388bca 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ProjectFileSystemAdapter.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ProjectFileSystemAdapter.java @@ -56,7 +56,6 @@ public class ProjectFileSystemAdapter implements ProjectFileSystem { this.target = target; this.pom = pom; - // TODO See http://jira.codehaus.org/browse/SONAR-2126 // previously MavenProjectBuilder was responsible for creation of ProjectFileSystem project.setFileSystem(this); } diff --git a/sonar-core/src/main/java/org/sonar/core/rule/CacheRuleFinder.java b/sonar-core/src/main/java/org/sonar/core/rule/CacheRuleFinder.java index 8747055a4ee..76a59f8ea80 100644 --- a/sonar-core/src/main/java/org/sonar/core/rule/CacheRuleFinder.java +++ b/sonar-core/src/main/java/org/sonar/core/rule/CacheRuleFinder.java @@ -90,29 +90,19 @@ public final class CacheRuleFinder implements RuleFinder { } + @Override @CheckForNull public Rule findByKey(RuleKey key) { return findByKey(key.repository(), key.rule()); } - - @CheckForNull - protected final Rule doFindByKey(String repositoryKey, String key) { - DatabaseSession session = sessionFactory.getSession(); - return session.getSingleResult( - session.createQuery("FROM " + Rule.class.getSimpleName() + " r WHERE r.key=:key and r.pluginName=:pluginName and r.status<>:status") - .setParameter("key", key) - .setParameter("pluginName", repositoryKey) - .setParameter("status", Rule.STATUS_REMOVED - ), - null); - } - + @Override public final Rule find(RuleQuery query) { DatabaseSession session = sessionFactory.getSession(); return session.getSingleResult(createHqlQuery(session, query), null); } + @Override public final Collection findAll(RuleQuery query) { DatabaseSession session = sessionFactory.getSession(); return createHqlQuery(session, query).getResultList(); diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/PathUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/PathUtilsTest.java index 4ffd592d5ac..57a75e2437e 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/PathUtilsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/PathUtilsTest.java @@ -26,7 +26,6 @@ import org.junit.rules.TemporaryFolder; import java.io.File; import java.io.IOException; -import java.lang.reflect.Method; import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Fail.fail; @@ -65,6 +64,7 @@ public class PathUtilsTest { File file = temp.newFile(); String path = PathUtils.canonicalPath(file); assertThat(path).isEqualTo(FilenameUtils.separatorsToUnix(file.getCanonicalPath())); + assertThat(PathUtils.canonicalPath(null)).isNull(); } @Test diff --git a/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java b/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java index 3d2dded5fbf..f1bba567579 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java @@ -121,7 +121,6 @@ public class IssueService implements ServerComponent { * Never return null, but an empty list if the issue does not exist. * No security check is done since it should already have been done to get the issue */ - // TODO remove userSession parameter ? public List listTransitions(@Nullable Issue issue, UserSession userSession) { if (issue == null) { return Collections.emptyList(); diff --git a/sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java b/sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java index 4939964bf25..ddcd033de8d 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/DefaultRuleFinder.java @@ -53,11 +53,10 @@ public class DefaultRuleFinder implements RuleFinder { @CheckForNull public org.sonar.api.rules.Rule findById(int ruleId) { Rule rule = index.getById(ruleId); - if (rule.status() != RuleStatus.REMOVED) { + if (rule != null && rule.status() != RuleStatus.REMOVED) { return toRule(rule); - } else { - return null; } + return null; } @CheckForNull -- 2.39.5