package org.sonar.batch.scan;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.filefilter.AndFileFilter;
private static final String PROPERTY_BINARIES = "sonar.binaries";
private static final String PROPERTY_LIBRARIES = "sonar.libraries";
- /**
- * Old deprecated properties, replaced by the same ones preceded by "sonar."
- */
- private static final String PROPERTY_OLD_SOURCES = "sources";
- private static final String PROPERTY_OLD_TESTS = "tests";
- private static final String PROPERTY_OLD_BINARIES = "binaries";
- private static final String PROPERTY_OLD_LIBRARIES = "libraries";
- private static final Map<String, String> DEPRECATED_PROPS_TO_NEW_PROPS = ImmutableMap.of(
- PROPERTY_OLD_SOURCES, PROPERTY_SOURCES,
- PROPERTY_OLD_TESTS, PROPERTY_TESTS,
- PROPERTY_OLD_BINARIES, PROPERTY_BINARIES,
- PROPERTY_OLD_LIBRARIES, PROPERTY_LIBRARIES
- );
-
/**
* Array of all mandatory properties required for a project without child.
*/
@VisibleForTesting
protected static void checkMandatoryProperties(Properties props, String[] mandatoryProps) {
- replaceDeprecatedProperties(props);
StringBuilder missing = new StringBuilder();
for (String mandatoryProperty : mandatoryProps) {
if (!props.containsKey(mandatoryProperty)) {
}
}
- /**
- * Replaces the deprecated properties by the new ones, and logs a message to warn the users.
- */
- @VisibleForTesting
- protected static void replaceDeprecatedProperties(Properties props) {
- for (Entry<String, String> entry : DEPRECATED_PROPS_TO_NEW_PROPS.entrySet()) {
- String key = entry.getKey();
- if (props.containsKey(key)) {
- String newKey = entry.getValue();
- LOG.warn("/!\\ The '{}' property is deprecated and is replaced by '{}'. Don't forget to update your files.", key, newKey);
- String value = props.getProperty(key);
- props.remove(key);
- props.put(newKey, value);
- }
- }
-
- }
-
@VisibleForTesting
protected static void mergeParentProperties(Properties childProps, Properties parentProps) {
List<String> moduleIds = Lists.newArrayList(getListFromProperty(parentProps, PROPERTY_MODULES));
TestUtils.getResource(this.getClass(), "simple-project/libs/lib2.txt").getAbsolutePath());
}
- @Test
- public void shouldDefineSimpleProjectWithDeprecatedProperties() throws IOException {
- ProjectDefinition projectDefinition = loadProjectDefinition("simple-project-with-deprecated-props");
-
- assertThat(projectDefinition.getSourceDirs()).contains("sources");
- assertThat(projectDefinition.getLibraries()).contains(
- TestUtils.getResource(this.getClass(), "simple-project-with-deprecated-props/libs/lib2.txt").getAbsolutePath(),
- TestUtils.getResource(this.getClass(), "simple-project-with-deprecated-props/libs/lib2.txt").getAbsolutePath());
- }
-
@Test
public void shouldFailOnInvalidProjectKey() throws IOException {
thrown.expect(IllegalStateException.class);