Search in sources :

Example 1 with MavenDependencyCollector

use of org.sonar.java.checks.xml.maven.helpers.MavenDependencyCollector in project sonar-java by SonarSource.

the class DependencyWithSystemScopeCheck method scanFile.

@Override
public void scanFile(PomCheckContext context) {
    List<Dependency> dependencies = new MavenDependencyCollector(context.getMavenProject()).allDependencies();
    for (Dependency dependency : dependencies) {
        LocatedAttribute scope = dependency.getScope();
        if (scope != null && "system".equalsIgnoreCase(scope.getValue())) {
            String message = "Update this scope.";
            LocatedAttribute systemPath = dependency.getSystemPath();
            List<PomCheckContext.Location> secondaries = getSecondary(systemPath);
            if (systemPath != null) {
                message = "Update this scope and remove the \"systemPath\".";
            }
            context.reportIssue(this, scope.startLocation().line(), message, secondaries);
        }
    }
}
Also used : MavenDependencyCollector(org.sonar.java.checks.xml.maven.helpers.MavenDependencyCollector) LocatedAttribute(org.sonar.maven.model.LocatedAttribute) Dependency(org.sonar.maven.model.maven2.Dependency)

Aggregations

MavenDependencyCollector (org.sonar.java.checks.xml.maven.helpers.MavenDependencyCollector)1 LocatedAttribute (org.sonar.maven.model.LocatedAttribute)1 Dependency (org.sonar.maven.model.maven2.Dependency)1