--- /dev/null
+/*
+ * 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.
+ */
+package org.sonar.batch.bootstrap;
+
+import java.util.Map;
+import org.sonar.api.config.Settings;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+
+import static java.util.Objects.requireNonNull;
+
+public class DroppedPropertyChecker {
+ private final Settings settings;
+ private final Logger logger;
+ private final Map<String, String> properties;
+
+ public DroppedPropertyChecker(Settings settings, Map<String, String> properties) {
+ this.settings = requireNonNull(settings);
+ this.logger = Loggers.get(settings.getClass());
+ this.properties = requireNonNull(properties);
+ }
+
+ public void checkDroppedProperties() {
+ for (Map.Entry<String, String> entry : properties.entrySet()) {
+ if (settings.hasKey(entry.getKey())) {
+ logger.warn(
+ "Property '{}' (which value is '{}') is not supported any more. {}",
+ entry.getKey(), settings.getString(entry.getKey()), entry.getValue()
+ );
+ }
+ }
+ }
+
+}
*/
package org.sonar.batch.bootstrap;
+import com.google.common.collect.ImmutableMap;
+import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
private static final Logger LOG = LoggerFactory.getLogger(GlobalSettings.class);
+ private static final String JDBC_SPECIFIC_MESSAGE = "There is no more DB connection to the SQ database. It will be ignored.";
+ /**
+ * A map of dropped properties as key and specific message to display for that property
+ * (what will happen, what should the user do, ...) as a value
+ */
+ private static final Map<String, String> DROPPED_PROPERTIES = ImmutableMap.of(
+ "sonar.jdbc.url", JDBC_SPECIFIC_MESSAGE,
+ "sonar.jdbc.username", JDBC_SPECIFIC_MESSAGE,
+ "sonar.jdbc.password", JDBC_SPECIFIC_MESSAGE
+ );
+
private final BootstrapProperties bootstrapProps;
private final GlobalRepositories globalReferentials;
private final DefaultAnalysisMode mode;
this.bootstrapProps = bootstrapProps;
this.globalReferentials = globalReferentials;
init();
+ new DroppedPropertyChecker(this, DROPPED_PROPERTIES).checkDroppedProperties();
}
private void init() {
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.MessageException;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
import org.sonar.batch.bootstrap.DefaultAnalysisMode;
+import org.sonar.batch.bootstrap.DroppedPropertyChecker;
import org.sonar.batch.bootstrap.GlobalSettings;
import org.sonar.batch.protocol.input.ProjectRepositories;
public class ProjectSettings extends Settings {
- private static final Logger LOGGER = Loggers.get(ProjectSettings.class);
/**
* A map of dropped properties as key and specific message to display for that property
this.globalSettings = globalSettings;
this.projectRepositories = projectRepositories;
init(reactor);
- checkDroppedProperties();
+ new DroppedPropertyChecker(this, DROPPED_PROPERTIES).checkDroppedProperties();
}
private void init(ProjectReactor reactor) {
addProperties(reactor.getRoot().properties());
}
- private void checkDroppedProperties() {
- for (Map.Entry<String, String> entry : DROPPED_PROPERTIES.entrySet()) {
- if (hasKey(entry.getKey())) {
- LOGGER.warn("Property '{}' is not supported any more. {}", entry.getKey(), entry.getValue());
- }
- }
- }
-
@Override
protected void doOnGetProperties(String key) {
if (mode.isPreview() && key.endsWith(".secured") && !key.contains(".license")) {
--- /dev/null
+/*
+ * 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.
+ */
+package org.sonar.batch.bootstrap;
+
+import com.google.common.collect.ImmutableMap;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.api.config.Settings;
+import org.sonar.api.utils.log.LogTester;
+import org.sonar.api.utils.log.LoggerLevel;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DroppedPropertyCheckerTest {
+ private static final String SOME_VALUE = "some value";
+ private static final String DROPPED_PROPERTY_1 = "I'm dropped";
+ private static final String DROPPED_PROPERTY_MSG_1 = "blablabla!";
+
+ @Rule
+ public LogTester logTester = new LogTester();
+
+ @Test
+ public void no_log_if_no_dropped_property() {
+ Settings settings = new Settings();
+ settings.setProperty(DROPPED_PROPERTY_1, SOME_VALUE);
+
+ new DroppedPropertyChecker(settings, ImmutableMap.<String, String>of()).checkDroppedProperties();
+
+ assertThat(logTester.logs()).isEmpty();
+ }
+
+ @Test
+ public void no_log_if_settings_does_not_contain_any_dropped_property() {
+ new DroppedPropertyChecker(new Settings(), ImmutableMap.of(DROPPED_PROPERTY_1, DROPPED_PROPERTY_MSG_1)).checkDroppedProperties();
+
+ assertThat(logTester.logs()).isEmpty();
+ }
+
+ @Test
+ public void warn_log_if_settings_contains_any_dropped_property() {
+ Settings settings = new Settings();
+ settings.setProperty(DROPPED_PROPERTY_1, SOME_VALUE);
+
+ new DroppedPropertyChecker(settings, ImmutableMap.of(DROPPED_PROPERTY_1, DROPPED_PROPERTY_MSG_1)).checkDroppedProperties();
+
+ assertThat(logTester.logs(LoggerLevel.ERROR)).isEmpty();
+ assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly("Property '" + DROPPED_PROPERTY_1 + "' (which value is '" + SOME_VALUE +"') is not supported any more. " + DROPPED_PROPERTY_MSG_1);
+ assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
+ assertThat(logTester.logs(LoggerLevel.DEBUG)).isEmpty();
+ assertThat(logTester.logs(LoggerLevel.TRACE)).isEmpty();
+ }
+}
*/
package org.sonar.batch.bootstrap;
+import java.util.Collections;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.config.PropertyDefinitions;
+import org.sonar.api.utils.log.LogTester;
+import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.batch.protocol.input.GlobalRepositories;
-import java.util.Collections;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
public class GlobalSettingsTest {
+ public static final String SOME_VALUE = "some_value";
@Rule
public ExpectedException thrown = ExpectedException.none();
+ @Rule
+ public LogTester logTester = new LogTester();
GlobalRepositories globalRef;
- ProjectDefinition project = ProjectDefinition.create().setKey("struts");
BootstrapProperties bootstrapProps;
private DefaultAnalysisMode mode;
assertThat(batchSettings.getBoolean("sonar.cpd.cross")).isTrue();
}
+
+ @Test
+ public void should_log_warn_msg_for_each_jdbc_property_if_present() {
+ globalRef.globalSettings().put("sonar.jdbc.url", SOME_VALUE);
+ globalRef.globalSettings().put("sonar.jdbc.username", SOME_VALUE);
+ globalRef.globalSettings().put("sonar.jdbc.password", SOME_VALUE);
+
+ new GlobalSettings(bootstrapProps, new PropertyDefinitions(), globalRef, mode);
+
+ assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly(
+ "Property 'sonar.jdbc.url' (which value is '" + SOME_VALUE + "') is not supported any more. There is no more DB connection to the SQ database. It will be ignored.",
+ "Property 'sonar.jdbc.username' (which value is '" + SOME_VALUE + "') is not supported any more. There is no more DB connection to the SQ database. It will be ignored.",
+ "Property 'sonar.jdbc.password' (which value is '" + SOME_VALUE + "') is not supported any more. There is no more DB connection to the SQ database. It will be ignored."
+ );
+ }
}
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.log.LogTester;
+import org.sonar.api.utils.log.LoggerLevel;
import org.sonar.batch.bootstrap.BootstrapProperties;
import org.sonar.batch.bootstrap.DefaultAnalysisMode;
import org.sonar.batch.bootstrap.GlobalSettings;
GlobalSettings settings = new GlobalSettings(new BootstrapProperties(ImmutableMap.of("sonar.qualitygate", "somevalue")), new PropertyDefinitions(), new GlobalRepositories(), mode);
new ProjectSettings(new ProjectReactor(project), settings, new PropertyDefinitions(), projectRef, mode);
- logTester.logs().contains("Property 'sonar.qualitygate' is not supported any more. It will be ignored.");
+ assertThat(logTester.logs(LoggerLevel.WARN)).containsOnly("Property 'sonar.qualitygate' (which value is 'somevalue') is not supported any more. It will be ignored.");
}
}