Package org.codehaus.plexus.util.xml

Examples of org.codehaus.plexus.util.xml.PrettyPrintXMLWriter


    public void write()
        throws Exception
    {
        final File projectFile = this.getFile(".project");
        final FileWriter fileWriter = new FileWriter(projectFile);
        final XMLWriter writer = new PrettyPrintXMLWriter(fileWriter);
        writer.startElement("projectDescription");
        writer.startElement("name");
        writer.writeText(this.project.getArtifactId());
        writer.endElement();
        writer.startElement("comment");
        writer.endElement();
        writer.startElement("projects");
        writer.endElement();
        writer.startElement("buildSpec");
        writer.startElement("buildCommand");
        writer.startElement("name");
        writer.writeText("org.eclipse.jdt.core.javabuilder");
        writer.endElement();
        writer.startElement("arguments");
        writer.endElement();
        writer.endElement();
        writer.endElement();
        writer.startElement("natures");
        writer.startElement("nature");
        writer.writeText("org.eclipse.jdt.core.javanature");
        writer.endElement();
        writer.endElement();
        writer.endElement();
        IOUtil.close(fileWriter);
        this.logger.info("Project file written --> '" + projectFile + "'");
    }
View Full Code Here


        throws Exception
    {
        final String rootDirectory = ResourceUtils.normalizePath(this.project.getBasedir().toString());
        final File classpathFile = new File(rootDirectory, ".classpath");
        final FileWriter fileWriter = new FileWriter(classpathFile);
        final XMLWriter writer = new PrettyPrintXMLWriter(fileWriter);

        writer.startElement("classpath");

        final Set projectArtifactIds = new LinkedHashSet();
        for (final Iterator iterator = projects.iterator(); iterator.hasNext();)
        {
            final MavenProject project = (MavenProject)iterator.next();
            final Artifact projectArtifact =
                artifactFactory.createArtifact(
                    project.getGroupId(),
                    project.getArtifactId(),
                    project.getVersion(),
                    null,
                    project.getPackaging());
            projectArtifactIds.add(projectArtifact.getId());
        }

        // - write the source roots for the root project (if they are any)
        this.writeSourceRoots(this.project, rootDirectory, writer);

        final Set allArtifacts = new LinkedHashSet(this.project.createArtifacts(
            artifactFactory,
            null,
            null));
        for (final Iterator iterator = projects.iterator(); iterator.hasNext();)
        {
            final MavenProject project = (MavenProject)iterator.next();
            this.writeSourceRoots(project, rootDirectory, writer);
            final Set artifacts = project.createArtifacts(
                    artifactFactory,
                    null,
                    null);

            // - get the direct dependencies
            for (final Iterator artifactIterator = artifacts.iterator(); artifactIterator.hasNext();)
            {
                final Artifact artifact = (Artifact)artifactIterator.next();

                // - don't attempt to resolve the artifact if its part of the project (we
                //   infer this if it has the same id has one of the projects or is in
                //   the same groupId).
                if (!projectArtifactIds.contains(artifact.getId()) &&
                    !project.getGroupId().equals(artifact.getGroupId()))
                {
                    artifactResolver.resolve(
                        artifact,
                        project.getRemoteArtifactRepositories(),
                        localRepository);
                    allArtifacts.add(artifact);
                }
                else
                {
                    allArtifacts.add(artifact);
                }
            }
        }

        // - remove the project artifacts
        for (final Iterator iterator = projects.iterator(); iterator.hasNext();)
        {
            final MavenProject project = (MavenProject)iterator.next();
            final Artifact projectArtifact = project.getArtifact();
            if (projectArtifact != null)
            {
                for (final Iterator artifactIterator = allArtifacts.iterator(); artifactIterator.hasNext();)
                {
                    final Artifact artifact = (Artifact)artifactIterator.next();
                    final String projectId = projectArtifact.getArtifactId();
                    final String projectGroupId = projectArtifact.getGroupId();
                    final String artifactId = artifact.getArtifactId();
                    final String groupId = artifact.getGroupId();
                    if (artifactId.equals(projectId) && groupId.equals(projectGroupId))
                    {
                        artifactIterator.remove();
                    }
                }
            }
        }

        // - now we resolve transitively, if we have the flag on
        if (resolveTransitiveDependencies)
        {
            final Artifact rootProjectArtifact =
                artifactFactory.createArtifact(
                    this.project.getGroupId(),
                    this.project.getArtifactId(),
                    this.project.getVersion(),
                    null,
                    this.project.getPackaging());

            final OrArtifactFilter filter = new OrArtifactFilter();
            filter.add(new ScopeArtifactFilter(Artifact.SCOPE_COMPILE));
            filter.add(new ScopeArtifactFilter(Artifact.SCOPE_PROVIDED));
            filter.add(new ScopeArtifactFilter(Artifact.SCOPE_TEST));
            final ArtifactResolutionResult result =
                artifactResolver.resolveTransitively(
                    allArtifacts,
                    rootProjectArtifact,
                    localRepository,
                    remoteRepositories,
                    artifactMetadataSource,
                    filter);

            allArtifacts.clear();
            allArtifacts.addAll(result.getArtifacts());
        }

        final List allArtifactPaths = new ArrayList(allArtifacts);
        for (final ListIterator iterator = allArtifactPaths.listIterator(); iterator.hasNext();)
        {
            final Artifact artifact = (Artifact)iterator.next();
            if (classpathArtifactTypes.contains(artifact.getType()))
            {
                final File artifactFile = artifact.getFile();
                final String path =
                    StringUtils.replace(
                        ResourceUtils.normalizePath(artifactFile.toString()),
                        ResourceUtils.normalizePath(localRepository.getBasedir()),
                        repositoryVariableName);
                iterator.set(path);
            }
            else
            {
                iterator.remove();
            }
        }

        // - sort the paths
        Collections.sort(allArtifactPaths);

        for (final Iterator iterator = allArtifactPaths.iterator(); iterator.hasNext();)
        {
            String path = (String)iterator.next();
            if (path.startsWith(repositoryVariableName))
            {
                this.writeClasspathEntry(
                    writer,
                    "var",
                    path);
            }
            else
            {
                if (path.startsWith(rootDirectory))
                {
                    path = StringUtils.replace(path, rootDirectory + '/', "");
                }
                this.writeClasspathEntry(
                    writer,
                    "lib",
                    path);
            }
        }

        this.writeClasspathEntry(
            writer,
            "con",
            "org.eclipse.jdt.launching.JRE_CONTAINER");

        String outputPath =
            StringUtils.replace(
                ResourceUtils.normalizePath(this.project.getBuild().getOutputDirectory()),
                rootDirectory,
                "");
        if (outputPath.startsWith("/"))
        {
            outputPath = outputPath.substring(
                    1,
                    outputPath.length());
        }
        this.writeClasspathEntry(
            writer,
            "output",
            outputPath);

        if (StringUtils.isNotBlank(merge))
        {
            writer.writeMarkup(merge);
        }
        writer.endElement();

        logger.info("Classpath file written --> '" + classpathFile + "'");
        IOUtil.close(fileWriter);
    }
View Full Code Here

        {
            xmlOutputFile.getParentFile().mkdirs();
            try
            {
                xmlFileWriter = new FileWriter( xmlOutputFile );
                xmlWriter = new PrettyPrintXMLWriter( xmlFileWriter );
            }
            catch ( IOException e )
            {
                getLog().warn( "No XML report will be produced, cannot write data to " + xmlOutputFile, e );
            }
View Full Code Here

            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(reportFile), "UTF-8")));

            writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + NL);

            Xpp3DomWriter.write(new PrettyPrintXMLWriter(writer), testSuite);
        } catch (UnsupportedEncodingException e) {
            throw new Exception("Unable to use UTF-8 encoding", e);
        } catch (FileNotFoundException e) {
            throw new Exception("Unable to create file: " + e.getMessage(), e);
        } finally {
View Full Code Here

            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
                    new FileOutputStream(reportFile), "UTF-8")));

            writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + NL);

            Xpp3DomWriter.write(new PrettyPrintXMLWriter(writer), testSuite);
        } catch (UnsupportedEncodingException e) {
            throw new Exception("Unable to use UTF-8 encoding", e);
        } catch (FileNotFoundException e) {
            throw new Exception("Unable to create file: " + e.getMessage(), e);
        } finally {
View Full Code Here

    private Reader writeComponentsXml( final List<ComponentDef> componentDefs )
        throws IOException
    {
        final StringWriter writer = new StringWriter();

        final PrettyPrintXMLWriter xmlWriter = new PrettyPrintXMLWriter( writer );

        xmlWriter.startElement( "component-set" );
        xmlWriter.startElement( "components" );

        for ( final ComponentDef def : componentDefs )
        {
            xmlWriter.startElement( "component" );

            xmlWriter.startElement( "role" );
            xmlWriter.writeText( def.role );
            xmlWriter.endElement();

            final String roleHint = def.roleHint;
            if ( roleHint != null )
            {
                xmlWriter.startElement( "role-hint" );
                xmlWriter.writeText( roleHint );
                xmlWriter.endElement();
            }

            xmlWriter.startElement( "implementation" );
            xmlWriter.writeText( def.implementation );
            xmlWriter.endElement();

            xmlWriter.endElement();
        }

        xmlWriter.endElement();
        xmlWriter.endElement();

        return new StringReader( writer.toString() );
    }
View Full Code Here

public class AntrunXmlPlexusConfigurationWriter {

  public void write(PlexusConfiguration configuration, Writer writer) throws IOException {
    int depth = 0;

    PrettyPrintXMLWriter xmlWriter = new PrettyPrintXMLWriter(writer);
    write(configuration, xmlWriter, depth);
  }
View Full Code Here

    /** {@inheritDoc} */
    public void tableCaption( SinkEventAttributes attributes )
    {
        StringWriter sw = new StringWriter();
        this.tableCaptionWriterStack.addLast( sw );
        this.tableCaptionXMLWriterStack.addLast( new PrettyPrintXMLWriter( sw ) );

        // <fo:table-caption> is XSL-FO 1.0 standard but not implemented in FOP 0.95
        //writeStartTag( TABLE_CAPTION_TAG );

        // TODO: how to implement this otherwise?
View Full Code Here

    private static final String DEFAULT_INDENT = StringUtils.repeat( " ", XmlUtil.DEFAULT_INDENTATION_SIZE );

    /** {@inheritDoc} */
    protected Sink createSink( Writer writer )
    {
        return new XmlWriterXdocSink( new PrettyPrintXMLWriter( writer ) );
    }
View Full Code Here

    /** {@inheritDoc} */
    public void tableCaption()
    {
        tableCaptionWriter = new StringWriter();
        tableCaptionXMLWriter = new PrettyPrintXMLWriter( tableCaptionWriter );
        actionContext.setAction( SinkActionContext.TABLE_CAPTION );
    }
View Full Code Here

TOP

Related Classes of org.codehaus.plexus.util.xml.PrettyPrintXMLWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.