Search in sources :

Example 11 with XmlPullParserException

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;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Model(org.apache.maven.model.Model) StringReader(java.io.StringReader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 12 with XmlPullParserException

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);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) DeferredFileOutputStream(org.apache.commons.io.output.DeferredFileOutputStream) FileOutputStream(java.io.FileOutputStream) FileWriter(java.io.FileWriter) RemoteResourcesBundleXpp3Reader(org.apache.maven.plugin.resources.remote.io.xpp3.RemoteResourcesBundleXpp3Reader) Reader(java.io.Reader) MavenXpp3Reader(org.apache.maven.model.io.xpp3.MavenXpp3Reader) SupplementalDataModelXpp3Reader(org.apache.maven.plugin.resources.remote.io.xpp3.SupplementalDataModelXpp3Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) FileReader(java.io.FileReader) IOException(java.io.IOException) URL(java.net.URL) FileInputStream(java.io.FileInputStream) ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) ArtifactFilterException(org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException) MethodInvocationException(org.apache.velocity.exception.MethodInvocationException) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) InvalidDependencyVersionException(org.apache.maven.project.artifact.InvalidDependencyVersionException) InvalidProjectModelException(org.apache.maven.project.InvalidProjectModelException) MalformedURLException(java.net.MalformedURLException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) ParseErrorException(org.apache.velocity.exception.ParseErrorException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ResourceNotFoundException(org.apache.velocity.exception.ResourceNotFoundException) RemoteResourcesBundleXpp3Reader(org.apache.maven.plugin.resources.remote.io.xpp3.RemoteResourcesBundleXpp3Reader) DeferredFileOutputStream(org.apache.commons.io.output.DeferredFileOutputStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) FileReader(java.io.FileReader) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) DeferredFileOutputStream(org.apache.commons.io.output.DeferredFileOutputStream) File(java.io.File) PrintWriter(java.io.PrintWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) FileWriter(java.io.FileWriter) PrintWriter(java.io.PrintWriter)

Example 13 with XmlPullParserException

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();
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileWriter(java.io.FileWriter) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) CommandExecutor(org.apache.maven.wagon.CommandExecutor) Wagon(org.apache.maven.wagon.Wagon) IOException(java.io.IOException) AuthenticationInfo(org.apache.maven.wagon.authentication.AuthenticationInfo) FileInputStream(java.io.FileInputStream) TreeSet(java.util.TreeSet) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) CommandExecutionException(org.apache.maven.wagon.CommandExecutionException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) File(java.io.File) ResourceDoesNotExistException(org.apache.maven.wagon.ResourceDoesNotExistException) PrintWriter(java.io.PrintWriter)

Example 14 with XmlPullParserException

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);
    }
}
Also used : BundleListXpp3Writer(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.io.xpp3.BundleListXpp3Writer) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) BundleListUtils.readBundleList(org.apache.sling.maven.projectsupport.BundleListUtils.readBundleList) BundleList(org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) FileWriter(java.io.FileWriter) MojoFailureException(org.apache.maven.plugin.MojoFailureException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException)

Example 15 with XmlPullParserException

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;
}
Also used : ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) File(java.io.File)

Aggregations

IOException (java.io.IOException)28 XmlPullParserException (org.codehaus.plexus.util.xml.pull.XmlPullParserException)28 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)13 Reader (java.io.Reader)11 File (java.io.File)10 Model (org.apache.maven.model.Model)8 MavenXpp3Reader (org.apache.maven.model.io.xpp3.MavenXpp3Reader)8 StringReader (java.io.StringReader)7 FileInputStream (java.io.FileInputStream)4 FileNotFoundException (java.io.FileNotFoundException)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 MojoFailureException (org.apache.maven.plugin.MojoFailureException)4 FileReader (java.io.FileReader)3 FileWriter (java.io.FileWriter)3 InputStreamReader (java.io.InputStreamReader)3 BufferedReader (java.io.BufferedReader)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2