@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); |
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); | |||||
} | } | ||||
} | } | ||||
} | } |
/* | |||||
* 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; |
/* | |||||
* 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; |
// 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) { |
} | } | ||||
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); |