use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project maven-plugins by apache.
the class ResourceResolver method resolveBundleFromProject.
private static List<JavadocBundle> resolveBundleFromProject(SourceResolverConfig config, MavenProject project, Artifact artifact) throws IOException {
List<JavadocBundle> bundles = new ArrayList<JavadocBundle>();
List<String> classifiers = new ArrayList<String>();
if (config.includeCompileSources()) {
classifiers.add(AbstractJavadocMojo.JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER);
}
if (config.includeTestSources()) {
classifiers.add(AbstractJavadocMojo.TEST_JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER);
}
for (String classifier : classifiers) {
File optionsFile = new File(project.getBuild().getDirectory(), "javadoc-bundle-options/javadoc-options-" + classifier + ".xml");
if (!optionsFile.exists()) {
continue;
}
FileInputStream stream = null;
try {
stream = new FileInputStream(optionsFile);
JavadocOptions options = new JavadocOptionsXpp3Reader().read(stream);
stream.close();
stream = null;
bundles.add(new JavadocBundle(options, new File(project.getBasedir(), options.getJavadocResourcesDirectory())));
} catch (XmlPullParserException e) {
IOException error = new IOException("Failed to read javadoc options from: " + optionsFile + "\nReason: " + e.getMessage());
error.initCause(e);
throw error;
} finally {
close(stream);
}
}
return bundles;
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project asterixdb by apache.
the class SupplementalModelHelper method getSupplement.
protected static Model getSupplement(Log log, Xpp3Dom supplementModelXml) throws MojoExecutionException {
MavenXpp3Reader modelReader = new MavenXpp3Reader();
Model model = null;
try {
model = modelReader.read(new StringReader(supplementModelXml.toString()));
String groupId = model.getGroupId();
String artifactId = model.getArtifactId();
if (groupId == null || "".equals(groupId.trim())) {
throw new MojoExecutionException("Supplemental project XML requires that a <groupId> element be present.");
}
if (artifactId == null || "".equals(artifactId.trim())) {
throw new MojoExecutionException("Supplemental project XML requires that a <artifactId> element be present.");
}
} catch (IOException e) {
log.warn("Unable to read supplemental XML: " + e.getMessage(), e);
} catch (XmlPullParserException e) {
log.warn("Unable to parse supplemental XML: " + e.getMessage(), e);
}
return model;
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project maven-plugins by apache.
the class AbstractPmdViolationCheckMojo method executeCheck.
protected void executeCheck(final String filename, final String tagName, final String key, final int failurePriority) throws MojoFailureException, MojoExecutionException {
if (aggregate && !project.isExecutionRoot()) {
return;
}
if ("pom".equals(project.getPackaging()) && !aggregate) {
return;
}
excludeFromFile.loadExcludeFromFailuresData(excludeFromFailureFile);
final File outputFile = new File(targetDirectory, filename);
if (outputFile.exists()) {
try {
final ViolationDetails<D> violations = getViolations(outputFile, failurePriority);
final List<D> failures = violations.getFailureDetails();
final List<D> warnings = violations.getWarningDetails();
if (verbose) {
printErrors(failures, warnings);
}
final int failureCount = failures.size();
final int warningCount = warnings.size();
final String message = getMessage(failureCount, warningCount, key, outputFile);
getLog().debug("PMD failureCount: " + failureCount + ", warningCount: " + warningCount);
if (failureCount > 0 && isFailOnViolation()) {
throw new MojoFailureException(message);
}
this.getLog().info(message);
} catch (final IOException e) {
throw new MojoExecutionException("Unable to read PMD results xml: " + outputFile.getAbsolutePath(), e);
} catch (final XmlPullParserException e) {
throw new MojoExecutionException("Unable to read PMD results xml: " + outputFile.getAbsolutePath(), e);
}
} else {
throw new MojoFailureException("Unable to perform check, " + "unable to find " + outputFile);
}
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project BIMserver by opensourceBIM.
the class PluginManager method loadPluginsFromEclipseProject.
public PluginBundle loadPluginsFromEclipseProject(Path projectRoot) throws PluginException {
try {
if (!Files.isDirectory(projectRoot)) {
throw new PluginException("No directory: " + projectRoot.toString());
}
final Path pluginFolder = projectRoot.resolve("plugin");
if (!Files.isDirectory(pluginFolder)) {
throw new PluginException("No 'plugin' directory found in " + projectRoot.toString());
}
Path pluginFile = pluginFolder.resolve("plugin.xml");
if (!Files.exists(pluginFile)) {
throw new PluginException("No 'plugin.xml' found in " + pluginFolder.toString());
}
PluginDescriptor pluginDescriptor = getPluginDescriptor(Files.newInputStream(pluginFile));
Path pomFile = projectRoot.resolve("pom.xml");
if (!Files.exists(pomFile)) {
throw new PluginException("No pom.xml found in " + projectRoot);
}
// Path packageFile = projectRoot.resolve("package.json");
// if (Files.exists(packageFile)) {
// return loadJavaScriptProject(projectRoot, packageFile,
// pluginFolder, pluginDescriptor);
// } else if (Files.exists(pomFile)) {
PluginBundle pluginBundle = loadJavaProject(projectRoot, pomFile, pluginFolder, pluginDescriptor);
// } else {
// throw new PluginException("No pom.xml or package.json found in "
// + projectRoot.toString());
// }
List<SPluginInformation> plugins = new ArrayList<>();
processPluginDescriptor(pluginDescriptor, plugins);
for (SPluginInformation sPluginInformation : plugins) {
if (sPluginInformation.isEnabled()) {
// For local plugins, we assume to install for all users
sPluginInformation.setInstallForAllUsers(true);
sPluginInformation.setInstallForNewUsers(true);
PluginContext pluginContext = pluginBundle.getPluginContext(sPluginInformation.getIdentifier());
if (pluginContext == null) {
throw new PluginException("No plugin context found for " + sPluginInformation.getIdentifier());
}
pluginContext.getPlugin().init(pluginContext);
}
}
try {
long pluginBundleVersionId = pluginChangeListener.pluginBundleInstalled(pluginBundle);
for (SPluginInformation sPluginInformation : plugins) {
if (sPluginInformation.isEnabled()) {
PluginContext pluginContext = pluginBundle.getPluginContext(sPluginInformation.getIdentifier());
pluginChangeListener.pluginInstalled(pluginBundleVersionId, pluginContext, sPluginInformation);
}
}
} catch (Exception e) {
LOGGER.error("", e);
throw new PluginException(e);
}
return pluginBundle;
} catch (JAXBException e) {
throw new PluginException(e);
} catch (FileNotFoundException e) {
throw new PluginException(e);
} 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 BIMserver by opensourceBIM.
the class PluginManager method extractPluginBundleFromJar.
// public void loadAllPluginsFromDirectoryOfJars(Path directory) throws
// PluginException, IOException {
// LOGGER.debug("Loading all plugins from " + directory.toString());
// if (!Files.isDirectory(directory)) {
// throw new PluginException("No directory: " + directory.toString());
// }
// for (Path file : PathUtils.list(directory)) {
// if (file.getFileName().toString().toLowerCase().endsWith(".jar")) {
// try {
// PluginBundleVersionIdentifier pluginBundleVersionIdentifier =
// PluginBundleVersionIdentifier.fromFileName(file.getFileName().toString());
//
// loadPluginsFromJar(pluginBundleVersionIdentifier, file,
// extractPluginBundleFromJar(file),
// extractPluginBundleVersionFromJar(file));
// } catch (PluginException e) {
// LOGGER.error("", e);
// }
// }
// }
// }
public SPluginBundle extractPluginBundleFromJar(Path jarFilePath) throws PluginException {
String filename = jarFilePath.getFileName().toString();
PluginBundleVersionIdentifier pluginBundleVersionIdentifier = PluginBundleVersionIdentifier.fromFileName(filename);
try (JarFile jarFile = new JarFile(jarFilePath.toFile())) {
String pomLocation = "META-INF/maven/" + pluginBundleVersionIdentifier.getPluginBundleIdentifier().getGroupId() + "/" + pluginBundleVersionIdentifier.getPluginBundleIdentifier().getArtifactId() + "/" + "pom.xml";
ZipEntry pomEntry = jarFile.getEntry(pomLocation);
if (pomEntry == null) {
throw new PluginException("No pom.xml found in JAR file " + jarFilePath.toString() + ", " + pomLocation);
}
MavenXpp3Reader mavenreader = new MavenXpp3Reader();
Model model = mavenreader.read(jarFile.getInputStream(pomEntry));
SPluginBundle sPluginBundle = new SPluginBundle();
sPluginBundle.setOrganization(model.getOrganization().getName());
sPluginBundle.setName(model.getName());
return sPluginBundle;
} catch (IOException e) {
throw new PluginException(e);
} catch (XmlPullParserException e) {
throw new PluginException(e);
}
}
Aggregations