}
File report = project.getFileSystem().resolvePath(path);
if (!report.exists() || !report.isFile()) {
- Logs.INFO.warn("Cobertura report not found at {}", report);
+ LoggerFactory.getLogger(getClass()).warn("Cobertura report not found at {}", report);
return;
}
parseReport(report, context);
protected void parseReport(File xmlFile, final SensorContext context) {
LoggerFactory.getLogger(CoberturaSensor.class).info("parsing {}", xmlFile);
- new AbstractCoberturaParser() {
- @Override
- protected Resource<?> getResource(String fileName) {
- return new JavaFile(fileName);
- }
- }.parseReport(xmlFile, context);
+ new JavaCoberturaParser().parseReport(xmlFile, context);
}
@Override
return getClass().getSimpleName();
}
+ private static final class JavaCoberturaParser extends AbstractCoberturaParser {
+ @Override
+ protected Resource<?> getResource(String fileName) {
+ return new JavaFile(fileName);
+ }
+ }
}
.setFieldValue("assignee", getAssignee(review));
}
- private @Nullable String getCreator(ReviewDto review) {
+ private String getCreator(ReviewDto review) {
if (review.getUserId() == null) { // no creator and in fact this should never happen in real-life, however happens during unit tests
return null;
}
return user != null ? user.getLogin() : null;
}
- private @Nullable String getAssignee(ReviewDto review) {
+ private String getAssignee(ReviewDto review) {
if (review.getAssigneeId() == null) { // not assigned
return null;
}
for (ReviewDto review : openReviews) {
Violation violation = violationsByPermanentId.get(review.getViolationPermanentId());
- if (violation != null) {
- if (!hasUpToDateInformation(review, violation)) {
- review.setLine(violation.getLineId());
- review.setTitle(violation.getMessage());
- updated.add(review);
- }
+ if (violation != null && !hasUpToDateInformation(review, violation)) {
+ review.setLine(violation.getLineId());
+ review.setTitle(violation.getMessage());
+ updated.add(review);
}
}
}
}
private void closeResolvedStandardViolations(Collection<ReviewDto> openReviews, List<Violation> violations, Project project, Resource resource, Set<ReviewDto> updated) {
- Set<Integer> violationIds = Sets.newHashSet(Collections2.transform(violations, new Function<Violation, Integer>() {
- public Integer apply(Violation violation) {
- return violation.getPermanentId();
- }
- }));
+ Set<Integer> violationIds = Sets.newHashSet(Collections2.transform(violations, new ViolationToPermanentIdFunction()));
for (ReviewDto openReview : openReviews) {
if (!openReview.isManualViolation() && !violationIds.contains(openReview.getViolationPermanentId())) {
review.setResolution(null);
review.setUpdatedAt(new Date());
}
+
+ private static final class ViolationToPermanentIdFunction implements Function<Violation, Integer> {
+ public Integer apply(Violation violation) {
+ return violation.getPermanentId();
+ }
+ }
}
public DefaultPluginMetadata install(DefaultPluginMetadata metadata, File toDir) {
try {
File pluginFile = metadata.getFile();
- File pluginBasedir;
- if (toDir != null) {
- pluginBasedir = toDir;
- FileUtils.forceMkdir(pluginBasedir);
- File targetFile = new File(pluginBasedir, pluginFile.getName());
- FileUtils.copyFile(pluginFile, targetFile);
- metadata.addDeployedFile(targetFile);
- } else {
- pluginBasedir = pluginFile.getParentFile();
- metadata.addDeployedFile(pluginFile);
- }
-
- if (metadata.getPathsToInternalDeps().length > 0) {
- // needs to unzip the jar
- ZipUtils.unzip(pluginFile, pluginBasedir, new LibFilter());
- for (String depPath : metadata.getPathsToInternalDeps()) {
- File dependency = new File(pluginBasedir, depPath);
- if (!dependency.isFile() || !dependency.exists()) {
- throw new IllegalArgumentException("Dependency " + depPath + " can not be found in " + pluginFile.getName());
- }
- metadata.addDeployedFile(dependency);
- }
- }
-
- for (File extension : metadata.getDeprecatedExtensions()) {
- File toFile = new File(pluginBasedir, extension.getName());
- if (!toFile.equals(extension)) {
- FileUtils.copyFile(extension, toFile);
- }
- metadata.addDeployedFile(toFile);
- }
+ File pluginBasedir = copyPlugin(metadata, toDir, pluginFile);
+ copyDependencies(metadata, pluginFile, pluginBasedir);
+ copyDeprecatedExtensions(metadata, pluginBasedir);
return metadata;
}
}
- private static class LibFilter implements ZipUtils.ZipEntryFilter {
+ private File copyPlugin(DefaultPluginMetadata metadata, File toDir, File pluginFile) throws IOException {
+ File pluginBasedir;
+ if (toDir != null) {
+ pluginBasedir = toDir;
+ FileUtils.forceMkdir(pluginBasedir);
+ File targetFile = new File(pluginBasedir, pluginFile.getName());
+ FileUtils.copyFile(pluginFile, targetFile);
+ metadata.addDeployedFile(targetFile);
+ } else {
+ pluginBasedir = pluginFile.getParentFile();
+ metadata.addDeployedFile(pluginFile);
+ }
+ return pluginBasedir;
+ }
+
+ private void copyDependencies(DefaultPluginMetadata metadata, File pluginFile, File pluginBasedir) throws IOException {
+ if (metadata.getPathsToInternalDeps().length > 0) {
+ // needs to unzip the jar
+ ZipUtils.unzip(pluginFile, pluginBasedir, new LibFilter());
+ for (String depPath : metadata.getPathsToInternalDeps()) {
+ File dependency = new File(pluginBasedir, depPath);
+ if (!dependency.isFile() || !dependency.exists()) {
+ throw new IllegalArgumentException("Dependency " + depPath + " can not be found in " + pluginFile.getName());
+ }
+ metadata.addDeployedFile(dependency);
+ }
+ }
+ }
+
+ private void copyDeprecatedExtensions(DefaultPluginMetadata metadata, File pluginBasedir) throws IOException {
+ for (File extension : metadata.getDeprecatedExtensions()) {
+ File toFile = new File(pluginBasedir, extension.getName());
+ if (!toFile.equals(extension)) {
+ FileUtils.copyFile(extension, toFile);
+ }
+ metadata.addDeployedFile(toFile);
+ }
+ }
+
+ private static final class LibFilter implements ZipUtils.ZipEntryFilter {
public boolean accept(ZipEntry entry) {
return entry.getName().startsWith("META-INF/lib");
}
}
}
- private void completeDeprecatedMetadata(DefaultPluginMetadata metadata) throws IOException {
+ private void completeDeprecatedMetadata(DefaultPluginMetadata metadata) {
String mainClass = metadata.getMainClass();
File pluginFile = metadata.getFile();
try {
private String errorKey = null;
- private static Result newError(@Nullable String key) {
+ private static Result newError(String key) {
return new Result(key);
}
@Nullable
- private Result(String errorKey) {
+ private Result(@Nullable String errorKey) {
this.errorKey = errorKey;
}
rootPath = StringUtils.removeStart(rootPath, "/");
URL root = classLoader.getResource(rootPath);
- if (root == null) {
- return paths;
- }
- if (!"jar".equals(root.getProtocol())) {
- throw new IllegalStateException("Unsupported protocol: " + root.getProtocol());
- }
+ if (root != null) {
+ if (!"jar".equals(root.getProtocol())) {
+ throw new IllegalStateException("Unsupported protocol: " + root.getProtocol());
+ }
- // Path of the root directory
- // Examples :
- // org/sonar/sqale/index.txt -> rootDirectory is org/sonar/sqale
- // org/sonar/sqale/ -> rootDirectory is org/sonar/sqale
- // org/sonar/sqale -> rootDirectory is org/sonar/sqale
- String rootDirectory = rootPath;
- if (StringUtils.substringAfterLast(rootPath, "/").indexOf('.') >= 0) {
- rootDirectory = StringUtils.substringBeforeLast(rootPath, "/");
- }
- String jarPath = root.getPath().substring(5, root.getPath().indexOf("!")); //strip out only the JAR file
- JarFile jar = new JarFile(URLDecoder.decode(jarPath, CharEncoding.UTF_8));
- Enumeration<JarEntry> entries = jar.entries();
- while (entries.hasMoreElements()) {
- String name = entries.nextElement().getName();
- if (name.startsWith(rootDirectory) && predicate.apply(name)) {
- paths.add(name);
+ // Path of the root directory
+ // Examples :
+ // org/sonar/sqale/index.txt -> rootDirectory is org/sonar/sqale
+ // org/sonar/sqale/ -> rootDirectory is org/sonar/sqale
+ // org/sonar/sqale -> rootDirectory is org/sonar/sqale
+ String rootDirectory = rootPath;
+ if (StringUtils.substringAfterLast(rootPath, "/").indexOf('.') >= 0) {
+ rootDirectory = StringUtils.substringBeforeLast(rootPath, "/");
+ }
+ String jarPath = root.getPath().substring(5, root.getPath().indexOf("!")); //strip out only the JAR file
+ JarFile jar = new JarFile(URLDecoder.decode(jarPath, CharEncoding.UTF_8));
+ Enumeration<JarEntry> entries = jar.entries();
+ while (entries.hasMoreElements()) {
+ String name = entries.nextElement().getName();
+ if (name.startsWith(rootDirectory) && predicate.apply(name)) {
+ paths.add(name);
+ }
}
}
return paths;