use of org.sonar.maven.model.LocatedAttributeAdapter in project sonar-java by SonarSource.
the class PomParser method parseXML.
@CheckForNull
public static MavenProject parseXML(File file) {
try (FileInputStream is = new FileInputStream(file)) {
// it is necessary to provide classloader explicitly, otherwise Thread.contextClassLoader will be used,
// which doesn't include jar of plugin
JAXBContext context = JAXBContext.newInstance("org.sonar.maven.model.maven2", PomParser.class.getClassLoader());
XMLInputFactory factory = XMLInputFactory.newInstance();
enableLocationPropertyForIBM(factory);
XMLStreamReader reader = factory.createXMLStreamReader(is);
StreamListener streamListener = new StreamListener(reader);
Unmarshaller unmarshaller = context.createUnmarshaller();
unmarshaller.setListener(streamListener);
unmarshaller.setAdapter(new LocatedAttributeAdapter(reader));
JAXBElement<MavenProject> unmarshalledObject = unmarshaller.unmarshal(reader, MavenProject.class);
if (!"project".equalsIgnoreCase(unmarshalledObject.getName().getLocalPart())) {
return null;
}
return unmarshalledObject.getValue();
} catch (JAXBException | XMLStreamException | IOException e) {
LOG.error("Unable to parse pom file " + file.getPath(), e);
}
return null;
}
Aggregations