import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.xoo.Xoo;
+@SuppressWarnings("deprecation")
public class DeprecatedResourceApiSensor implements Sensor {
public static final String RULE_KEY = "DeprecatedResourceApi";
}
+ @Test
+ public void createIssueOnRootDir() throws IOException {
+
+ File baseDir = temp.getRoot();
+
+ File xooFileInRootDir = new File(baseDir, "sample.xoo");
+ FileUtils.write(xooFileInRootDir, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10");
+
+ File xooFileInAnotherDir = new File(baseDir, "package/sample.xoo");
+ FileUtils.write(xooFileInAnotherDir, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10");
+
+ TaskResult result = tester.newTask()
+ .properties(ImmutableMap.<String, String>builder()
+ .put("sonar.task", "scan")
+ .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
+ .put("sonar.projectKey", "com.foo.project")
+ .put("sonar.projectName", "Foo Project")
+ .put("sonar.projectVersion", "1.0-SNAPSHOT")
+ .put("sonar.projectDescription", "Description of Foo Project")
+ .put("sonar.sources", ".")
+ .build())
+ .start();
+
+ assertThat(result.issuesFor(result.inputFile("sample.xoo"))).extracting("msg", "line").containsOnly(
+ tuple("Issue created using deprecated API", 0),
+ tuple("Issue created using deprecated API", 1));
+ assertThat(result.issuesFor(result.inputFile("package/sample.xoo"))).extracting("msg", "line").containsOnly(
+ tuple("Issue created using deprecated API", 0),
+ tuple("Issue created using deprecated API", 1));
+ assertThat(result.issuesFor(result.inputDir(""))).extracting("msg", "line").containsOnly(
+ tuple("Issue created using deprecated API", 0));
+ assertThat(result.issuesFor(result.inputDir("package"))).extracting("msg", "line").containsOnly(
+ tuple("Issue created using deprecated API", 0));
+
+ }
+
}
assertThat(result.issuesFor(result.inputDir("src"))).hasSize(2);
}
+ @Test
+ public void issueOnRootFolder() throws IOException {
+
+ File baseDir = temp.getRoot();
+
+ File xooFile1 = new File(baseDir, "sample1.xoo");
+ FileUtils.write(xooFile1, "Sample1 xoo\ncontent");
+
+ File xooFile2 = new File(baseDir, "sample2.xoo");
+ FileUtils.write(xooFile2, "Sample2 xoo\ncontent");
+
+ TaskResult result = tester.newTask()
+ .properties(ImmutableMap.<String, String>builder()
+ .put("sonar.task", "scan")
+ .put("sonar.projectBaseDir", baseDir.getAbsolutePath())
+ .put("sonar.projectKey", "com.foo.project")
+ .put("sonar.projectName", "Foo Project")
+ .put("sonar.projectVersion", "1.0-SNAPSHOT")
+ .put("sonar.projectDescription", "Description of Foo Project")
+ .put("sonar.sources", ".")
+ .build())
+ .start();
+
+ assertThat(result.issuesFor(result.inputDir(""))).hasSize(2);
+ }
+
}
import java.io.File;
import java.nio.file.Path;
+import org.apache.commons.lang.StringUtils;
import org.sonar.api.batch.fs.InputDir;
import org.sonar.api.utils.PathUtils;
@Override
public String key() {
- return new StringBuilder().append(moduleKey).append(":").append(relativePath).toString();
+ StringBuilder sb = new StringBuilder().append(moduleKey).append(":");
+ if (StringUtils.isEmpty(relativePath)) {
+ sb.append("/");
+ } else {
+ sb.append(relativePath);
+ }
+ return sb.toString();
}
/**
*/
package org.sonar.api.resources;
+import javax.annotation.CheckForNull;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.utils.WildcardPattern;
-import javax.annotation.CheckForNull;
-
/**
* @since 1.10
*/
public static Directory create(String relativePathFromBaseDir) {
Directory d = new Directory();
String normalizedPath = normalize(relativePathFromBaseDir);
- d.setKey(normalizedPath);
- d.setPath(normalizedPath);
+ d.setKey(normalizedPath == null ? SEPARATOR : normalizedPath);
+ d.setPath(normalizedPath == null ? "" : normalizedPath);
return d;
}