Search in sources :

Example 6 with MavenProject

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

the class MavenDependencyCollectorTest method parse.

private static MavenProject parse(String testCase) {
    File file = new File("src/test/files/checks/xml/maven/dependencyCollector/" + testCase + "-pom.xml");
    MavenProject project = PomParser.parseXML(file);
    if (project == null) {
        Fail.fail("unable to parse test case: " + file.getAbsolutePath());
    }
    return project;
}
Also used : MavenProject(org.sonar.maven.model.maven2.MavenProject) File(java.io.File)

Example 7 with MavenProject

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

the class PomParserTest method should_retrieve_attributes.

@Test
public void should_retrieve_attributes() throws Exception {
    MavenProject project = PomParser.parseXML(SIMPLE_POM_FILE);
    checkAttribute(project.getModelVersion(), "4.0.0", 3, 17, 3, 22);
    checkAttribute(project.getGroupId(), "org.sonarsource.java", 5, 12, 5, 32);
    checkAttribute(project.getArtifactId(), "simple-project", 6, 15, 6, 29);
    checkAttribute(project.getPackaging(), "jar", 10, 14, 10, 17);
    checkAttribute(project.getName(), "simple-project", 12, 9, 12, 23);
    checkAttribute(project.getUrl(), "http://maven.apache.org", 13, 8, 13, 31);
    // starting column is unknown
    checkAttribute(project.getVersion(), "1.0-SNAPSHOT", 7, -1, 9, 10);
    // empty property
    checkAttribute(project.getDescription(), "", 14, 16, 14, 16);
}
Also used : MavenProject(org.sonar.maven.model.maven2.MavenProject) Test(org.junit.Test)

Example 8 with MavenProject

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

the class PomParserTest method should_not_parse.

@Test
public void should_not_parse() {
    MavenProject project = PomParser.parseXML(new File("."));
    assertThat(project).isNull();
}
Also used : MavenProject(org.sonar.maven.model.maven2.MavenProject) File(java.io.File) Test(org.junit.Test)

Example 9 with MavenProject

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

the class PomParserTest method should_parse_incompletly_pom_with_complex_elements.

@Test
public void should_parse_incompletly_pom_with_complex_elements() throws Exception {
    MavenProject project = PomParser.parseXML(COMPLEX_ELEMENT_POM_FILE);
    Configuration config = project.getBuild().getPlugins().getPlugins().get(0).getExecutions().getExecutions().get(0).getConfiguration();
    checkPosition(config, 16, 13, 24, 13);
    assertThat(config).isNotNull();
    List<Element> values = config.getElements();
    assertThat(values).hasSize(2);
}
Also used : MavenProject(org.sonar.maven.model.maven2.MavenProject) Configuration(org.sonar.maven.model.maven2.PluginExecution.Configuration) Element(org.w3c.dom.Element) Test(org.junit.Test)

Example 10 with MavenProject

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

the class PomParserTest method should_fail_parsing.

@Test
public void should_fail_parsing() {
    MavenProject project = PomParser.parseXML(PARSE_ISSUE_POM_FILE);
    assertThat(project).isNull();
}
Also used : MavenProject(org.sonar.maven.model.maven2.MavenProject) Test(org.junit.Test)

Aggregations

MavenProject (org.sonar.maven.model.maven2.MavenProject)12 Test (org.junit.Test)8 File (java.io.File)3 Element (org.w3c.dom.Element)3 Configuration (org.sonar.maven.model.maven2.PluginExecution.Configuration)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 CheckForNull (javax.annotation.CheckForNull)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 Location (org.sonar.java.xml.maven.PomCheckContext.Location)1 LocatedAttributeAdapter (org.sonar.maven.model.LocatedAttributeAdapter)1 Dependency (org.sonar.maven.model.maven2.Dependency)1 DependencyManagement (org.sonar.maven.model.maven2.DependencyManagement)1 Properties (org.sonar.maven.model.maven2.MavenProject.Properties)1 Plugin (org.sonar.maven.model.maven2.Plugin)1