diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2014-02-02 11:47:55 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2014-02-02 11:47:55 +0100 |
commit | 7f280114fc26b402e33fb36cedad1659196cab4b (patch) | |
tree | 13a59e9edd3d3a3f62358048ea8f77bb440c3e4d /sonar-server | |
parent | 8ee22cbabf8142c29b510bc82bfb726b3b215520 (diff) | |
download | sonarqube-7f280114fc26b402e33fb36cedad1659196cab4b.tar.gz sonarqube-7f280114fc26b402e33fb36cedad1659196cab4b.zip |
Fix some quality flaws
Diffstat (limited to 'sonar-server')
6 files changed, 38 insertions, 35 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java b/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java index 41178cb097b..3e970f10733 100644 --- a/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java +++ b/sonar-server/src/main/java/org/sonar/server/permission/InternalPermissionTemplateService.java @@ -22,8 +22,6 @@ package org.sonar.server.permission; import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.sonar.api.ServerComponent; import org.sonar.core.permission.PermissionTemplateDao; import org.sonar.core.permission.PermissionTemplateDto; @@ -32,7 +30,6 @@ import org.sonar.server.exceptions.BadRequestException; import javax.annotation.CheckForNull; import javax.annotation.Nullable; - import java.util.List; import java.util.Map; import java.util.regex.Pattern; diff --git a/sonar-server/src/main/java/org/sonar/server/plugins/MimeTypes.java b/sonar-server/src/main/java/org/sonar/server/plugins/MimeTypes.java index 7ad624f820a..8bbdcb1e6d4 100644 --- a/sonar-server/src/main/java/org/sonar/server/plugins/MimeTypes.java +++ b/sonar-server/src/main/java/org/sonar/server/plugins/MimeTypes.java @@ -30,9 +30,6 @@ import java.util.Map; * @since 3.1 */ public final class MimeTypes { - private MimeTypes() { - // only static methods - } public static final String JSON = "application/json"; public static final String XML = "application/xml"; @@ -68,6 +65,10 @@ public final class MimeTypes { .put("tsv", "text/tab-separated-values") .build(); + private MimeTypes() { + // only static methods + } + public static String getByFilename(String filename) { String extension = FilenameUtils.getExtension(filename); String mime = null; diff --git a/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleTagsWs.java b/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleTagsWs.java index de1dc6047d7..cea8acd55ab 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleTagsWs.java +++ b/sonar-server/src/main/java/org/sonar/server/rule/ws/RuleTagsWs.java @@ -38,7 +38,7 @@ public class RuleTagsWs implements WebService { @Override public void define(Context context) { NewController controller = context.newController("api/rule_tags") - .setDescription("Rule tags"); + .setDescription("Rule tags"); controller.newAction("list") .setDescription("List all available rule tags") @@ -46,7 +46,7 @@ public class RuleTagsWs implements WebService { .setHandler(new RequestHandler() { @Override public void handle(Request request, Response response) { - list(request, response); + list(response); } }); @@ -65,10 +65,10 @@ public class RuleTagsWs implements WebService { controller.done(); } - private void list(Request request, Response response) { + private void list(Response response) { JsonWriter writer = response.newJsonWriter(); writer.beginArray(); - for (String tag: ruleTags.listAllTags()) { + for (String tag : ruleTags.listAllTags()) { writer.value(tag); } writer.endArray().close(); diff --git a/sonar-server/src/main/java/org/sonar/server/user/GroupMembershipService.java b/sonar-server/src/main/java/org/sonar/server/user/GroupMembershipService.java index ec32e47249f..77f0184f26d 100644 --- a/sonar-server/src/main/java/org/sonar/server/user/GroupMembershipService.java +++ b/sonar-server/src/main/java/org/sonar/server/user/GroupMembershipService.java @@ -58,10 +58,10 @@ public class GroupMembershipService implements ServerComponent { String selected = (String) params.get("selected"); if (SELECTED_MEMBERSHIP.equals(selected)) { return GroupMembershipQuery.IN; - } else if (DESELECTED_MEMBERSHIP.equals(selected)) { + } + if (DESELECTED_MEMBERSHIP.equals(selected)) { return GroupMembershipQuery.OUT; - } else { - return GroupMembershipQuery.ANY; } + return GroupMembershipQuery.ANY; } } diff --git a/sonar-server/src/main/java/org/sonar/server/user/SecurityRealmFactory.java b/sonar-server/src/main/java/org/sonar/server/user/SecurityRealmFactory.java index 7b048cdcb4d..99a175f31d1 100644 --- a/sonar-server/src/main/java/org/sonar/server/user/SecurityRealmFactory.java +++ b/sonar-server/src/main/java/org/sonar/server/user/SecurityRealmFactory.java @@ -20,6 +20,7 @@ package org.sonar.server.user; import org.apache.commons.lang.StringUtils; +import org.picocontainer.Startable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.CoreProperties; @@ -32,9 +33,7 @@ import org.sonar.api.utils.SonarException; /** * @since 2.14 */ -public class SecurityRealmFactory implements ServerComponent { - - private static final Logger INFO = LoggerFactory.getLogger("org.sonar.INFO"); +public class SecurityRealmFactory implements ServerComponent, Startable { private final boolean ignoreStartupFailure; private final SecurityRealm realm; @@ -47,14 +46,15 @@ public class SecurityRealmFactory implements ServerComponent { if (!StringUtils.isEmpty(realmName)) { selectedRealm = selectRealm(realms, realmName); if (selectedRealm == null) { - throw new SonarException("Realm '" + realmName + "' not found. Please check the property '" + CoreProperties.CORE_AUTHENTICATOR_REALM + "' in conf/sonar.properties"); + throw new SonarException(String.format( + "Realm '%s' not found. Please check the property '%s' in conf/sonar.properties", realmName, CoreProperties.CORE_AUTHENTICATOR_REALM)); } } if (selectedRealm == null && !StringUtils.isEmpty(className)) { LoginPasswordAuthenticator authenticator = selectAuthenticator(authenticators, className); if (authenticator == null) { - throw new SonarException("Authenticator '" + className + "' not found. Please check the property '" + CoreProperties.CORE_AUTHENTICATOR_CLASS - + "' in conf/sonar.properties"); + throw new SonarException(String.format( + "Authenticator '%s' not found. Please check the property '%s' in conf/sonar.properties", className, CoreProperties.CORE_AUTHENTICATOR_CLASS)); } selectedRealm = new CompatibilityRealm(authenticator); } @@ -62,26 +62,28 @@ public class SecurityRealmFactory implements ServerComponent { } public SecurityRealmFactory(Settings settings, LoginPasswordAuthenticator[] authenticators) { - this(settings, null, authenticators); + this(settings, new SecurityRealm[0], authenticators); } public SecurityRealmFactory(Settings settings, SecurityRealm[] realms) { - this(settings, realms, null); + this(settings, realms, new LoginPasswordAuthenticator[0]); } public SecurityRealmFactory(Settings settings) { - this(settings, null, null); + this(settings, new SecurityRealm[0], new LoginPasswordAuthenticator[0]); } + @Override public void start() { if (realm != null) { + Logger logger = LoggerFactory.getLogger("org.sonar.INFO"); try { - INFO.info("Security realm: " + realm.getName()); + logger.info("Security realm: " + realm.getName()); realm.init(); - INFO.info("Security realm started"); + logger.info("Security realm started"); } catch (RuntimeException e) { if (ignoreStartupFailure) { - INFO.error("IGNORED - Security realm fails to start: " + e.getMessage()); + logger.error("IGNORED - Security realm fails to start: " + e.getMessage()); } else { throw new SonarException("Security realm fails to start: " + e.getMessage(), e); } @@ -89,27 +91,28 @@ public class SecurityRealmFactory implements ServerComponent { } } + @Override + public void stop() { + // nothing + } + public SecurityRealm getRealm() { return realm; } private static SecurityRealm selectRealm(SecurityRealm[] realms, String realmName) { - if (realms != null) { - for (SecurityRealm realm : realms) { - if (StringUtils.equals(realmName, realm.getName())) { - return realm; - } + for (SecurityRealm realm : realms) { + if (StringUtils.equals(realmName, realm.getName())) { + return realm; } } return null; } private static LoginPasswordAuthenticator selectAuthenticator(LoginPasswordAuthenticator[] authenticators, String className) { - if (authenticators != null) { - for (LoginPasswordAuthenticator lpa : authenticators) { - if (lpa.getClass().getName().equals(className)) { - return lpa; - } + for (LoginPasswordAuthenticator lpa : authenticators) { + if (lpa.getClass().getName().equals(className)) { + return lpa; } } return null; diff --git a/sonar-server/src/test/java/org/sonar/server/user/SecurityRealmFactoryTest.java b/sonar-server/src/test/java/org/sonar/server/user/SecurityRealmFactoryTest.java index 70bd0be1b7f..d571d2f9ac5 100644 --- a/sonar-server/src/test/java/org/sonar/server/user/SecurityRealmFactoryTest.java +++ b/sonar-server/src/test/java/org/sonar/server/user/SecurityRealmFactoryTest.java @@ -47,6 +47,8 @@ public class SecurityRealmFactoryTest { factory.start(); assertThat(factory.getRealm()).isSameAs(realm); verify(realm).init(); + + factory.stop(); } @Test |