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

@Override @Override
public void deliver(Notification notification, String username) { public void deliver(Notification notification, String username) {
User user = userFinder.findByLogin(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; return;
} }
EmailMessage emailMessage = format(notification); EmailMessage emailMessage = format(notification);

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

import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.sonar.api.utils.log.Loggers;
import org.sonar.process.MessageException; import org.sonar.process.MessageException;
import org.sonar.process.ProcessProperties; import org.sonar.process.ProcessProperties;
import org.sonar.process.Props; import org.sonar.process.Props;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;


import static java.lang.String.format;

public class JdbcSettings { public class JdbcSettings {


enum Provider { enum Provider {
Pattern pattern = Pattern.compile("jdbc:(\\w+):.+"); Pattern pattern = Pattern.compile("jdbc:(\\w+):.+");
Matcher matcher = pattern.matcher(url); Matcher matcher = pattern.matcher(url);
if (!matcher.find()) { 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); String key = matcher.group(1);
try { try {
return Provider.valueOf(StringUtils.upperCase(key)); return Provider.valueOf(StringUtils.upperCase(key));
} catch (IllegalArgumentException e) { } 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));
} }
} }




private static void checkRequiredParameter(String url, String val) { private static void checkRequiredParameter(String url, String val) {
if (!url.contains(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) { private void checkRecommendedParameter(String url, String val) {
if (!url.contains(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

/*
* 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

/*
* 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

// Check if the file was cached by another process during download // Check if the file was cached by another process during download
if (!rename && !targetFile.exists()) { if (!rename && !targetFile.exists()) {
log.warn(String.format("Unable to rename %s to %s", sourceFile.getAbsolutePath(), targetFile.getAbsolutePath())); 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 { try {
Files.move(sourceFile.toPath(), targetFile.toPath()); Files.move(sourceFile.toPath(), targetFile.toPath());
} catch (IOException e) { } catch (IOException e) {

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

} }


public static File unzip(InputStream zip, File toDir) throws IOException { 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; 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 { public static File unzip(InputStream stream, File toDir, ZipEntryFilter filter) throws IOException {
if (!toDir.exists()) { if (!toDir.exists()) {
FileUtils.forceMkdir(toDir); FileUtils.forceMkdir(toDir);

Loading…
Cancel
Save