Search in sources :

Example 1 with LocatedAttribute

use of org.sonar.maven.model.LocatedAttribute 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)

Example 2 with LocatedAttribute

use of org.sonar.maven.model.LocatedAttribute in project sonar-java by SonarSource.

the class PatternMatcherTest method should_match_patterns.

@Test
public void should_match_patterns() {
    matcher = new PatternMatcher("[a-z]*");
    assertThat(matcher.test(null)).isFalse();
    assertThat(matcher.test(new LocatedAttribute("test"))).isTrue();
    assertThat(matcher.test(new LocatedAttribute("012"))).isFalse();
}
Also used : LocatedAttribute(org.sonar.maven.model.LocatedAttribute) Test(org.junit.Test)

Example 3 with LocatedAttribute

use of org.sonar.maven.model.LocatedAttribute in project sonar-java by SonarSource.

the class LocatedAttributeMatcherTest method matcher_always_matching_always_match.

@Test
public void matcher_always_matching_always_match() {
    LocatedAttributeMatcher matcher = LocatedAttributeMatcher.any();
    assertThat(matcher.test(null)).isTrue();
    assertThat(matcher.test(new LocatedAttribute("test"))).isTrue();
}
Also used : LocatedAttribute(org.sonar.maven.model.LocatedAttribute) Test(org.junit.Test)

Example 4 with LocatedAttribute

use of org.sonar.maven.model.LocatedAttribute in project sonar-java by SonarSource.

the class MavenDependencyMatcherTest method newDependency.

private static Dependency newDependency(String groupId, String artifactId, @Nullable String version) {
    Dependency dependency = new Dependency();
    dependency.setGroupId(new LocatedAttribute(groupId));
    dependency.setArtifactId(new LocatedAttribute(artifactId));
    if (version != null) {
        dependency.setVersion(new LocatedAttribute(version));
    }
    return dependency;
}
Also used : LocatedAttribute(org.sonar.maven.model.LocatedAttribute) Dependency(org.sonar.maven.model.maven2.Dependency)

Aggregations

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