use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project maven-plugins by apache.
the class DefaultAssemblyReader method mergeComponentsWithMainAssembly.
/**
* Add the contents of all included components to main assembly
*
* @param assembly The assembly
* @param assemblyDir The assembly directory
* @param transformer The component interpolator
* @throws AssemblyReadException .
*/
protected void mergeComponentsWithMainAssembly(final Assembly assembly, final File assemblyDir, final AssemblerConfigurationSource configSource, ComponentXpp3Reader.ContentTransformer transformer) throws AssemblyReadException {
final Locator locator = new Locator();
if (assemblyDir != null && assemblyDir.exists() && assemblyDir.isDirectory()) {
locator.addStrategy(new RelativeFileLocatorStrategy(assemblyDir));
}
// allow absolute paths in componentDescriptor... MASSEMBLY-486
locator.addStrategy(new RelativeFileLocatorStrategy(configSource.getBasedir()));
locator.addStrategy(new FileLocatorStrategy());
locator.addStrategy(new ClasspathResourceLocatorStrategy());
final AssemblyExpressionEvaluator aee = new AssemblyExpressionEvaluator(configSource);
final List<String> componentLocations = assembly.getComponentDescriptors();
for (String location : componentLocations) {
// allow expressions in path to component descriptor... MASSEMBLY-486
try {
location = aee.evaluate(location).toString();
} catch (final Exception eee) {
getLogger().error("Error interpolating componentDescriptor: " + location, eee);
}
final Location resolvedLocation = locator.resolve(location);
if (resolvedLocation == null) {
throw new AssemblyReadException("Failed to locate component descriptor: " + location);
}
Component component = null;
Reader reader = null;
try {
reader = new InputStreamReader(resolvedLocation.getInputStream());
component = new ComponentXpp3Reader(transformer).read(reader);
} catch (final IOException e) {
throw new AssemblyReadException("Error reading component descriptor: " + location + " (resolved to: " + resolvedLocation.getSpecification() + ")", e);
} catch (final XmlPullParserException e) {
throw new AssemblyReadException("Error reading component descriptor: " + location + " (resolved to: " + resolvedLocation.getSpecification() + ")", e);
} finally {
IOUtil.close(reader);
}
mergeComponentWithAssembly(component, assembly);
}
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project maven-plugins by apache.
the class ComponentsXmlArchiverFileFilter method isSelected.
@Override
public boolean isSelected(@Nonnull final FileInfo fileInfo) throws IOException {
if (fileInfo.isFile()) {
if (excludeOverride) {
return true;
}
String entry = fileInfo.getName().replace('\\', '/');
if (entry.startsWith("/")) {
entry = entry.substring(1);
}
if (ComponentsXmlArchiverFileFilter.COMPONENTS_XML_PATH.equals(entry)) {
Reader reader = null;
try {
reader = new BufferedReader(ReaderFactory.newXmlReader(fileInfo.getContents()));
addComponentsXml(reader);
reader.close();
reader = null;
} catch (final XmlPullParserException e) {
final IOException error = new IOException("Error finalizing component-set for archive. Reason: " + e.getMessage());
error.initCause(e);
throw error;
} finally {
IOUtil.close(reader);
}
return false;
} else {
return true;
}
} else {
return true;
}
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project maven-plugins by apache.
the class DefaultAssemblyArchiver method configureArchiver.
private void configureArchiver(final Archiver archiver, final AssemblerConfigurationSource configSource) {
Xpp3Dom config;
try {
config = Xpp3DomBuilder.build(new StringReader(configSource.getArchiverConfig()));
} catch (final XmlPullParserException e) {
throw new ArchiverException("Failed to parse archiver configuration for: " + archiver.getClass().getName(), e);
} catch (final IOException e) {
throw new ArchiverException("Failed to parse archiver configuration for: " + archiver.getClass().getName(), e);
}
getLogger().debug("Configuring archiver: '" + archiver.getClass().getName() + "' -->");
try {
configureComponent(archiver, config, configSource);
} catch (final ComponentConfigurationException e) {
throw new ArchiverException("Failed to configure archiver: " + archiver.getClass().getName(), e);
} catch (final ComponentLookupException e) {
throw new ArchiverException("Failed to lookup configurator for setup of archiver: " + archiver.getClass().getName(), e);
}
getLogger().debug("-- end configuration --");
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project drools by kiegroup.
the class StaticMethodTestHelper method getProjectVersion.
static String getProjectVersion() {
URL codeLocUrl = StaticMethodTestHelper.class.getProtectionDomain().getCodeSource().getLocation();
String projVersionStr = null;
String codeLocStr = null;
try {
codeLocStr = codeLocUrl.toURI().toString();
if (codeLocStr.endsWith(".jar")) {
Matcher jarLocMatcher = jarLocRegex.matcher(codeLocStr);
assertTrue("Regex for code (jar) location did not match location!", jarLocMatcher.matches() && jarLocMatcher.groupCount() >= 2);
projVersionStr = jarLocMatcher.group(1);
} else {
codeLocStr = codeLocStr.replace("target/classes/", "pom.xml");
File pomFile = new File(new URI(codeLocStr));
assertTrue(codeLocStr + " does not exist!", pomFile.exists());
Reader reader = null;
try {
reader = new FileReader(pomFile);
MavenXpp3Reader xpp3Reader = new MavenXpp3Reader();
Model model = xpp3Reader.read(reader);
projVersionStr = model.getVersion();
if (projVersionStr == null) {
projVersionStr = model.getParent().getVersion();
}
String projectName = model.getGroupId() + ":" + model.getArtifactId();
assertNotNull("Unable to resolve project version for " + projectName, projVersionStr);
} catch (FileNotFoundException fnfe) {
throw new RuntimeException("Unable to open " + pomFile.getAbsolutePath(), fnfe);
} catch (IOException ioe) {
throw new RuntimeException("Unable to read " + codeLocStr, ioe);
} catch (XmlPullParserException xppe) {
throw new RuntimeException("Unable to parse " + codeLocStr, xppe);
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
// no-op
}
}
}
} catch (URISyntaxException urise) {
throw new RuntimeException("Invalid URL: " + codeLocStr, urise);
}
return projVersionStr;
}
Aggregations