Browse Source

Fix quality flaws

tags/5.2-RC1
Simon Brandhof 9 years ago
parent
commit
47bad47ae0

+ 2
- 2
server/sonar-server/src/main/java/org/sonar/server/notification/email/EmailNotificationChannel.java View File

@@ -95,8 +95,8 @@ public class EmailNotificationChannel extends NotificationChannel {
@Override
public void deliver(Notification notification, String username) {
User user = userFinder.findByLogin(username);
if (StringUtils.isBlank(user.email())) {
LOG.debug("Email not defined for user: " + username);
if (user == null || StringUtils.isBlank(user.email())) {
LOG.debug("User does not exist or has no email: {}", username);
return;
}
EmailMessage emailMessage = format(notification);

+ 7
- 4
sonar-application/src/main/java/org/sonar/application/JdbcSettings.java View File

@@ -22,6 +22,7 @@ package org.sonar.application;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory;
import org.sonar.api.utils.log.Loggers;
import org.sonar.process.MessageException;
import org.sonar.process.ProcessProperties;
import org.sonar.process.Props;
@@ -32,6 +33,8 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static java.lang.String.format;

public class JdbcSettings {

enum Provider {
@@ -73,13 +76,13 @@ public class JdbcSettings {
Pattern pattern = Pattern.compile("jdbc:(\\w+):.+");
Matcher matcher = pattern.matcher(url);
if (!matcher.find()) {
throw new MessageException(String.format("Bad format of JDBC URL: " + url));
throw new MessageException(format("Bad format of JDBC URL: %s", url));
}
String key = matcher.group(1);
try {
return Provider.valueOf(StringUtils.upperCase(key));
} catch (IllegalArgumentException e) {
throw new MessageException(String.format(String.format("Unsupported JDBC driver provider: %s", key)));
throw new MessageException(format("Unsupported JDBC driver provider: %s", key));
}
}

@@ -94,13 +97,13 @@ public class JdbcSettings {

private static void checkRequiredParameter(String url, String val) {
if (!url.contains(val)) {
throw new MessageException(String.format("JDBC URL must have the property '%s'", val));
throw new MessageException(format("JDBC URL must have the property '%s'", val));
}
}

private void checkRecommendedParameter(String url, String val) {
if (!url.contains(val)) {
LoggerFactory.getLogger(getClass()).warn(String.format("JDBC URL is recommended to have the property '%s'", val));
Loggers.get(getClass()).warn("JDBC URL is recommended to have the property '{}'", val);
}
}
}

+ 0
- 23
sonar-core/src/main/java/org/sonar/core/notification/package-info.java View File

@@ -1,23 +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.
*/
@ParametersAreNonnullByDefault
package org.sonar.core.notification;

import javax.annotation.ParametersAreNonnullByDefault;

+ 0
- 23
sonar-core/src/main/java/org/sonar/core/qualityprofile/package-info.java View File

@@ -1,23 +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.
*/
@ParametersAreNonnullByDefault
package org.sonar.core.qualityprofile;

import javax.annotation.ParametersAreNonnullByDefault;

+ 1
- 1
sonar-home/src/main/java/org/sonar/home/cache/FileCache.java View File

@@ -106,7 +106,7 @@ public class FileCache {
// Check if the file was cached by another process during download
if (!rename && !targetFile.exists()) {
log.warn(String.format("Unable to rename %s to %s", sourceFile.getAbsolutePath(), targetFile.getAbsolutePath()));
log.warn(String.format("A copy/delete will be tempted but with no garantee of atomicity"));
log.warn("A copy/delete will be tempted but with no guarantee of atomicity");
try {
Files.move(sourceFile.toPath(), targetFile.toPath());
} catch (IOException e) {

+ 9
- 6
sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java View File

@@ -65,15 +65,18 @@ public final class ZipUtils {
}

public static File unzip(InputStream zip, File toDir) throws IOException {
unzip(zip, toDir, new ZipEntryFilter() {
@Override
public boolean accept(ZipEntry entry) {
return true;
}
});
unzip(zip, toDir, TrueZipEntryFilter.INSTANCE);
return toDir;
}

private enum TrueZipEntryFilter implements ZipEntryFilter {
INSTANCE;
@Override
public boolean accept(ZipEntry entry) {
return true;
}
}

public static File unzip(InputStream stream, File toDir, ZipEntryFilter filter) throws IOException {
if (!toDir.exists()) {
FileUtils.forceMkdir(toDir);

Loading…
Cancel
Save