use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project maven-plugins by apache.
the class ProcessRemoteResourcesMojo method getSupplement.
protected Model getSupplement(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 || groupId.trim().equals("")) {
throw new MojoExecutionException("Supplemental project XML " + "requires that a <groupId> element be present.");
}
if (artifactId == null || artifactId.trim().equals("")) {
throw new MojoExecutionException("Supplemental project XML " + "requires that a <artifactId> element be present.");
}
} catch (IOException e) {
getLog().warn("Unable to read supplemental XML: " + e.getMessage(), e);
} catch (XmlPullParserException e) {
getLog().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 ProcessRemoteResourcesMojo method processResourceBundles.
protected void processResourceBundles(RemoteResourcesClassLoader classLoader, VelocityContext context) throws MojoExecutionException {
try {
// CHECKSTYLE_OFF: LineLength
for (Enumeration<URL> e = classLoader.getResources(BundleRemoteResourcesMojo.RESOURCES_MANIFEST); e.hasMoreElements(); ) {
URL url = e.nextElement();
InputStream in = null;
OutputStream out = null;
Reader reader = null;
Writer writer = null;
try {
reader = new InputStreamReader(url.openStream());
RemoteResourcesBundleXpp3Reader bundleReader = new RemoteResourcesBundleXpp3Reader();
RemoteResourcesBundle bundle = bundleReader.read(reader);
reader.close();
reader = null;
for (String bundleResource : bundle.getRemoteResources()) {
String projectResource = bundleResource;
boolean doVelocity = false;
if (projectResource.endsWith(TEMPLATE_SUFFIX)) {
projectResource = projectResource.substring(0, projectResource.length() - 3);
doVelocity = true;
}
// Don't overwrite resource that are already being provided.
File f = new File(outputDirectory, projectResource);
FileUtils.mkdir(f.getParentFile().getAbsolutePath());
if (!copyResourceIfExists(f, projectResource, context)) {
if (doVelocity) {
DeferredFileOutputStream os = new DeferredFileOutputStream(velocityFilterInMemoryThreshold, f);
writer = bundle.getSourceEncoding() == null ? new OutputStreamWriter(os) : new OutputStreamWriter(os, bundle.getSourceEncoding());
if (bundle.getSourceEncoding() == null) {
// TODO: Is this correct? Shouldn't we behave like the rest of maven and fail
// down to JVM default instead ISO-8859-1 ?
velocity.mergeTemplate(bundleResource, "ISO-8859-1", context, writer);
} else {
velocity.mergeTemplate(bundleResource, bundle.getSourceEncoding(), context, writer);
}
writer.close();
writer = null;
fileWriteIfDiffers(os);
} else {
URL resUrl = classLoader.getResource(bundleResource);
if (resUrl != null) {
FileUtils.copyURLToFile(resUrl, f);
}
}
File appendedResourceFile = new File(appendedResourcesDirectory, projectResource);
File appendedVmResourceFile = new File(appendedResourcesDirectory, projectResource + ".vm");
if (appendedResourceFile.exists()) {
in = new FileInputStream(appendedResourceFile);
out = new FileOutputStream(f, true);
IOUtil.copy(in, out);
out.close();
out = null;
in.close();
in = null;
} else if (appendedVmResourceFile.exists()) {
reader = new FileReader(appendedVmResourceFile);
if (bundle.getSourceEncoding() == null) {
writer = new PrintWriter(new FileWriter(f, true));
} else {
writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(f, true), bundle.getSourceEncoding()));
}
Velocity.init();
Velocity.evaluate(context, writer, "remote-resources", reader);
writer.close();
writer = null;
reader.close();
reader = null;
}
}
}
} finally {
IOUtil.close(out);
IOUtil.close(in);
IOUtil.close(writer);
IOUtil.close(reader);
}
// CHECKSTYLE_ON: LineLength
}
} catch (IOException e) {
throw new MojoExecutionException("Error finding remote resources manifests", e);
} catch (XmlPullParserException e) {
throw new MojoExecutionException("Error parsing remote resource bundle descriptor.", e);
} catch (Exception e) {
throw new MojoExecutionException("Error rendering velocity resource.", e);
}
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project maven-plugins by apache.
the class DefaultRepositoryCopier method copy.
public void copy(Repository sourceRepository, Repository targetRepository, String version) throws WagonException, IOException {
String prefix = "staging-plugin";
String fileName = prefix + "-" + version + ".zip";
String tempdir = System.getProperty("java.io.tmpdir");
logger.debug("Writing all output to " + tempdir);
// Create the renameScript script
String renameScriptName = prefix + "-" + version + "-rename.sh";
File renameScript = new File(tempdir, renameScriptName);
// Work directory
File basedir = new File(tempdir, prefix + "-" + version);
FileUtils.deleteDirectory(basedir);
basedir.mkdirs();
Wagon sourceWagon = wagonManager.getWagon(sourceRepository);
AuthenticationInfo sourceAuth = wagonManager.getAuthenticationInfo(sourceRepository.getId());
sourceWagon.connect(sourceRepository, sourceAuth);
logger.info("Looking for files in the source repository.");
List<String> files = new ArrayList<String>();
scan(sourceWagon, "", files);
logger.info("Downloading files from the source repository to: " + basedir);
for (String s : files) {
if (s.contains(".svn")) {
continue;
}
File f = new File(basedir, s);
FileUtils.mkdir(f.getParentFile().getAbsolutePath());
logger.info("Downloading file from the source repository: " + s);
sourceWagon.get(s, f);
}
// ----------------------------------------------------------------------------
// Now all the files are present locally and now we are going to grab the
// metadata files from the targetRepositoryUrl and pull those down locally
// so that we can merge the metadata.
// ----------------------------------------------------------------------------
logger.info("Downloading metadata from the target repository.");
Wagon targetWagon = wagonManager.getWagon(targetRepository);
if (!(targetWagon instanceof CommandExecutor)) {
throw new CommandExecutionException("Wagon class '" + targetWagon.getClass().getName() + "' in use for target repository is not a CommandExecutor");
}
AuthenticationInfo targetAuth = wagonManager.getAuthenticationInfo(targetRepository.getId());
targetWagon.connect(targetRepository, targetAuth);
PrintWriter rw = new PrintWriter(new FileWriter(renameScript));
File archive = new File(tempdir, fileName);
for (String s : files) {
if (s.startsWith("/")) {
s = s.substring(1);
}
if (s.endsWith(MAVEN_METADATA)) {
File emf = new File(basedir, s + IN_PROCESS_MARKER);
try {
targetWagon.get(s, emf);
} catch (ResourceDoesNotExistException e) {
continue;
}
try {
mergeMetadata(emf);
} catch (XmlPullParserException e) {
throw new IOException("Metadata file is corrupt " + s + " Reason: " + e.getMessage());
}
}
}
Set moveCommands = new TreeSet();
// ----------------------------------------------------------------------------
// Create the Zip file that we will deploy to the targetRepositoryUrl stage
// ----------------------------------------------------------------------------
logger.info("Creating zip file.");
OutputStream os = new FileOutputStream(archive);
ZipOutputStream zos = new ZipOutputStream(os);
scanDirectory(basedir, basedir, zos, version, moveCommands);
// ----------------------------------------------------------------------------
// Create the renameScript script. This is as atomic as we can
// ----------------------------------------------------------------------------
logger.info("Creating rename script.");
for (Object moveCommand : moveCommands) {
String s = (String) moveCommand;
// We use an explicit unix '\n' line-ending here instead of using the println() method.
// Using println() will cause files and folders to have a '\r' at the end if the plugin is run on Windows.
rw.print(s + "\n");
}
rw.close();
ZipEntry e = new ZipEntry(renameScript.getName());
zos.putNextEntry(e);
InputStream is = new FileInputStream(renameScript);
IOUtil.copy(is, zos);
zos.close();
is.close();
sourceWagon.disconnect();
// Push the Zip to the target system
logger.info("Uploading zip file to the target repository.");
targetWagon.put(archive, fileName);
logger.info("Unpacking zip file on the target machine.");
String targetRepoBaseDirectory = targetRepository.getBasedir();
// We use the super quiet option here as all the noise seems to kill/stall the connection
String command = "unzip -o -qq -d " + targetRepoBaseDirectory + " " + targetRepoBaseDirectory + "/" + fileName;
((CommandExecutor) targetWagon).executeCommand(command);
logger.info("Deleting zip file from the target repository.");
command = "rm -f " + targetRepoBaseDirectory + "/" + fileName;
((CommandExecutor) targetWagon).executeCommand(command);
logger.info("Running rename script on the target machine.");
command = "cd " + targetRepoBaseDirectory + "; sh " + renameScriptName;
((CommandExecutor) targetWagon).executeCommand(command);
logger.info("Deleting rename script from the target repository.");
command = "rm -f " + targetRepoBaseDirectory + "/" + renameScriptName;
((CommandExecutor) targetWagon).executeCommand(command);
targetWagon.disconnect();
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project sling by apache.
the class AttachPartialBundleListMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
final BundleList initializedBundleList;
if (bundleListFile.exists()) {
try {
initializedBundleList = readBundleList(bundleListFile);
} catch (IOException e) {
throw new MojoExecutionException("Unable to read bundle list file", e);
} catch (XmlPullParserException e) {
throw new MojoExecutionException("Unable to read bundle list file", e);
}
} else {
throw new MojoFailureException(String.format("Bundle list file %s does not exist.", bundleListFile.getAbsolutePath()));
}
interpolateProperties(initializedBundleList, this.project, this.mavenSession);
final BundleListXpp3Writer writer = new BundleListXpp3Writer();
try {
this.bundleListOutput.getParentFile().mkdirs();
writer.write(new FileWriter(bundleListOutput), initializedBundleList);
} catch (IOException e) {
throw new MojoExecutionException("Unable to write bundle list", e);
}
// if this project is a partial bundle list, it's the main artifact
if (project.getPackaging().equals(PARTIAL)) {
project.getArtifact().setFile(bundleListOutput);
} else {
// otherwise attach it as an additional artifact
projectHelper.attachArtifact(project, TYPE, CLASSIFIER, bundleListOutput);
}
this.getLog().info("Attaching bundle list configuration");
try {
this.attachConfigurations();
} catch (final IOException ioe) {
throw new MojoExecutionException("Unable to attach configuration.", ioe);
} catch (final ArchiverException ioe) {
throw new MojoExecutionException("Unable to attach configuration.", ioe);
}
}
use of org.codehaus.plexus.util.xml.pull.XmlPullParserException in project intellij-community by JetBrains.
the class MavenEmbedder method buildSettings.
public static Settings buildSettings(PlexusContainer container, MavenEmbedderSettings embedderSettings) {
File file = embedderSettings.getGlobalSettingsFile();
if (file != null) {
System.setProperty(MavenSettingsBuilder.ALT_GLOBAL_SETTINGS_XML_LOCATION, file.getPath());
}
Settings settings = null;
try {
MavenSettingsBuilder builder = (MavenSettingsBuilder) container.lookup(MavenSettingsBuilder.ROLE);
File userSettingsFile = embedderSettings.getUserSettingsFile();
if (userSettingsFile != null && userSettingsFile.exists() && !userSettingsFile.isDirectory()) {
settings = builder.buildSettings(userSettingsFile, false);
}
if (settings == null) {
settings = builder.buildSettings();
}
} catch (ComponentLookupException e) {
MavenEmbedderLog.LOG.error(e);
} catch (IOException e) {
MavenEmbedderLog.LOG.warn(e);
} catch (XmlPullParserException e) {
MavenEmbedderLog.LOG.warn(e);
}
if (settings == null) {
settings = new Settings();
}
if (embedderSettings.getLocalRepository() != null) {
settings.setLocalRepository(embedderSettings.getLocalRepository().getPath());
}
if (settings.getLocalRepository() == null) {
settings.setLocalRepository(System.getProperty("user.home") + "/.m2/repository");
}
settings.setOffline(embedderSettings.isWorkOffline());
settings.setInteractiveMode(false);
settings.setUsePluginRegistry(embedderSettings.isUsePluginRegistry());
RuntimeInfo runtimeInfo = new RuntimeInfo(settings);
runtimeInfo.setPluginUpdateOverride(embedderSettings.getPluginUpdatePolicy() == MavenEmbedderSettings.UpdatePolicy.ALWAYS_UPDATE);
settings.setRuntimeInfo(runtimeInfo);
return settings;
}
Aggregations