use of org.sonar.maven.model.maven2.Dependency 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);
}
}
}
use of org.sonar.maven.model.maven2.Dependency in project sonar-java by SonarSource.
the class PomParserTest method should_retrieve_dependencies_from_dependency_management.
@Test
public void should_retrieve_dependencies_from_dependency_management() {
MavenProject project = PomParser.parseXML(SIMPLE_POM_FILE);
DependencyManagement dependencyManagement = project.getDependencyManagement();
checkPosition(dependencyManagement, 26, 3, 36, 3);
Dependency dependency = dependencyManagement.getDependencies().getDependencies().get(0);
checkAttribute(dependency.getGroupId(), "fake", 29, 18, 29, 22);
checkAttribute(dependency.getArtifactId(), "mock", 30, 21, 30, 25);
checkAttribute(dependency.getVersion(), "4.0", 31, 18, 31, 21);
checkAttribute(dependency.getScope(), "system", 32, 16, 32, 22);
checkAttribute(dependency.getSystemPath(), "hello", 33, 21, 33, 26);
}
use of org.sonar.maven.model.maven2.Dependency in project sonar-java by SonarSource.
the class MavenDependencyCollector method fromProfiles.
private static List<Dependency> fromProfiles(@Nullable Profiles profiles) {
if (profiles != null) {
List<Dependency> results = new LinkedList<>();
for (Profile profile : profiles.getProfiles()) {
results.addAll(fromDependencyManagement(profile.getDependencyManagement()));
results.addAll(profile.getDependencies() != null ? profile.getDependencies().getDependencies() : Collections.<Dependency>emptyList());
results.addAll(fromBuild(profile.getBuild()));
}
return results;
}
return Collections.<Dependency>emptyList();
}
use of org.sonar.maven.model.maven2.Dependency 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;
}
use of org.sonar.maven.model.maven2.Dependency in project sonar-java by SonarSource.
the class MavenDependencyMatcherTest method empty_dependencies_never_match.
@Test
public void empty_dependencies_never_match() {
matcher = new MavenDependencyMatcher("*:log", "");
assertNotMatch(new Dependency());
}
Aggregations