use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project BIMserver by opensourceBIM.
the class PluginManager method extractPluginBundleVersionFromJar.
public SPluginBundleVersion extractPluginBundleVersionFromJar(Path jarFilePath, boolean isLocal) throws PluginException {
String filename = jarFilePath.getFileName().toString();
PluginBundleVersionIdentifier pluginBundleVersionIdentifier = PluginBundleVersionIdentifier.fromFileName(filename);
PluginBundleIdentifier pluginBundleIdentifier = pluginBundleVersionIdentifier.getPluginBundleIdentifier();
try (JarFile jarFile = new JarFile(jarFilePath.toFile())) {
ZipEntry pomEntry = jarFile.getEntry("META-INF/maven/" + pluginBundleIdentifier.getGroupId() + "/" + pluginBundleIdentifier.getArtifactId() + "/" + "pom.xml");
if (pomEntry == null) {
throw new PluginException("No pom.xml found in JAR file " + jarFilePath.toString());
}
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
Model model = mavenreader.read(jarFile.getInputStream(pomEntry));
SPluginBundleVersion sPluginBundleVersion = createPluginBundleVersionFromMavenModel(model, isLocal);
return sPluginBundleVersion;
} catch (IOException e) {
throw new PluginException(e);
} catch (XmlPullParserException e) {
throw new PluginException(e);
}
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project pom-manipulation-ext by release-engineering.
the class PomIO method readModelsForManipulation.
/**
* Read {@link Model} instances by parsing the POM directly. This is useful to escape some post-processing that happens when the
* {@link MavenProject#getOriginalModel()} instance is set.
*
* @param executionRoot the top level pom file.
* @param peeked a collection of poms resolved from the top level file.
* @return a collection of Projects
* @throws ManipulationException if an error occurs.
*/
private List<Project> readModelsForManipulation(File executionRoot, final List<PomPeek> peeked) throws ManipulationException {
final List<Project> projects = new ArrayList<>();
final HashMap<Project, ProjectVersionRef> projectToParent = new HashMap<>();
for (final PomPeek peek : peeked) {
final File pom = peek.getPom();
// Sucks, but we have to brute-force reading in the raw model.
// The effective-model building, below, has a tantalizing getRawModel()
// method on the result, BUT this seems to return models that have
// the plugin versions set inside profiles...so they're not entirely
// raw.
Model raw = null;
InputStream in = null;
try {
in = new FileInputStream(pom);
raw = new MavenXpp3Reader().read(in);
} catch (final IOException | XmlPullParserException e) {
throw new ManipulationException("Failed to build model for POM: %s.\n--> %s", e, pom, e.getMessage());
} finally {
closeQuietly(in);
}
if (raw == null) {
continue;
}
final Project project = new Project(pom, raw);
projectToParent.put(project, peek.getParentKey());
project.setInheritanceRoot(peek.isInheritanceRoot());
if (executionRoot.equals(pom)) {
logger.debug("Setting execution root to {} with file {}" + (project.isInheritanceRoot() ? " and is the inheritance root. " : ""), project, pom);
project.setExecutionRoot();
try {
if (FileUtils.readFileToString(pom).contains(MODIFIED_BY)) {
project.setIncrementalPME(true);
}
} catch (final IOException e) {
throw new ManipulationException("Failed to read POM: %s", e, pom);
}
}
projects.add(project);
}
// Fill out inheritance info for every project we have created.
for (Project p : projects) {
ProjectVersionRef pvr = projectToParent.get(p);
p.setProjectParent(getParent(projects, pvr));
}
return projects;
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project pom-manipulation-ext by release-engineering.
the class ModelIO method resolveRawModel.
/**
* Read the raw model (equivalent to the pom file on disk) from a given GAV.
*
* @param ref the ProjectVersion to read.
* @return the Maven Model for the GAV
* @throws ManipulationException if an error occurs.
*/
public Model resolveRawModel(final ProjectVersionRef ref) throws ManipulationException {
Transfer transfer;
try {
transfer = galleyWrapper.resolveArtifact(ref.asPomArtifact());
} catch (final TransferException e) {
throw new ManipulationException("Failed to resolve POM: %s.\n--> %s", e, ref, e.getMessage());
}
if (transfer == null) {
throw new ManipulationException("Failed to resolve POM: " + ref.asPomArtifact());
}
InputStream in = null;
try {
in = transfer.openInputStream();
return new MavenXpp3Reader().read(in);
} catch (final IOException | XmlPullParserException e) {
throw new ManipulationException("Failed to build model for POM: %s.\n--> %s", e, ref, e.getMessage());
} finally {
closeQuietly(in);
}
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project fabric8 by jboss-fuse.
the class AetherResolutionSupport method getOrCreateMetadata.
private Metadata getOrCreateMetadata(File repository, String groupId, String artifactId, String version, String repoId) throws IOException {
File metadata;
if (version == null) {
metadata = new File(repository, String.format("%s/%s/maven-metadata%s.xml", groupId.replaceAll("\\.", "/"), artifactId, repoId == null ? "" : "-" + repoId));
} else {
metadata = new File(repository, String.format("%s/%s/%s/maven-metadata%s.xml", groupId.replaceAll("\\.", "/"), artifactId, version, repoId == null ? "" : "-" + repoId));
}
Metadata md;
if (metadata.isFile()) {
try {
md = new MetadataXpp3Reader().read(new FileReader(metadata));
} catch (XmlPullParserException e) {
throw new IOException(e.getMessage(), e);
}
} else {
md = new Metadata();
md.setGroupId(groupId);
md.setArtifactId(artifactId);
if (version != null) {
md.setVersion(version);
}
md.setVersioning(new Versioning());
}
return md;
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project fabric8 by jboss-fuse.
the class PomDetails method getModel.
public Model getModel() throws IOException {
try {
Model model = new MavenXpp3Reader().read(new FileInputStream(file));
model.setGroupId(properties.getProperty("groupId", model.getGroupId()));
model.setArtifactId(properties.getProperty("artifactId", model.getArtifactId()));
model.setVersion(properties.getProperty("version", model.getVersion()));
return model;
} catch (XmlPullParserException e) {
throw new IOException("Error parsing maven pom " + file, e);
}
}
Aggregations