Examples of PrettyPrintXMLWriter


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

        } catch (IOException ex) {
            throw new JbiPluginException("Exception while opening file["
                    + descriptor.getAbsolutePath() + "]", ex);
        }

        XMLWriter writer = new PrettyPrintXMLWriter(w, encoding, null);
        writer.startElement("jbi");
        writer.addAttribute("xmlns", "http://java.sun.com/xml/ns/jbi");
        writer.addAttribute("version", "1.0");

        writer.startElement("service-assembly");

        writer.startElement("identification");
        writer.startElement("name");
        writer.writeText(name);
        writer.endElement();
        writer.startElement("description");
        writer.writeText(description);
        writer.endElement();
        writer.endElement();

        for (Iterator it = uris.iterator(); it.hasNext();) {
            DependencyInformation serviceUnitInfo = (DependencyInformation) it
                    .next();
            writeServiceUnit(writer, serviceUnitInfo);

        }

        if (!connections.isEmpty()) {
            writer.startElement("connections");

            Map namespaceMap = buildNamespaceMap(connections);
            for (Iterator it = connections.iterator(); it.hasNext();) {
                GenerateServiceAssemblyDescriptorMojo.Connection connection = (GenerateServiceAssemblyDescriptorMojo.Connection) it
                        .next();
                writeConnection(namespaceMap, writer, connection);

            }
            writer.endElement();
        }

        writer.endElement();
        writer.endElement();

        close(w);
    }
View Full Code Here

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

            hidePasswords( copySettings );
        }

        StringWriter w = new StringWriter();
        XMLWriter writer =
            new PrettyPrintXMLWriter( w, StringUtils.repeat( " ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE ),
                                      copySettings.getModelEncoding(), null );

        writeHeader( writer );

        writeEffectiveSettings( copySettings, writer );
View Full Code Here

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

    public void execute()
        throws MojoExecutionException
    {
        StringWriter w = new StringWriter();
        XMLWriter writer =
            new PrettyPrintXMLWriter( w, StringUtils.repeat( " ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE ),
                                      project.getModel().getModelEncoding(), null );

        writeHeader( writer );

        String effectivePom;
        if ( projects.get( 0 ).equals( project ) && projects.size() > 1 )
        {
            // outer root element
            writer.startElement( "projects" );
            for ( MavenProject subProject : projects )
            {
                writeEffectivePom( subProject, writer );
            }
            writer.endElement();

            effectivePom = w.toString();
            effectivePom = prettyFormat( effectivePom );
        }
        else
View Full Code Here

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

    private XmlWriterXdocSink( StringWriter out, String encoding )
    {
        super( out, encoding );
        this.xdocWriter = out;
        this.xmlWriter = new PrettyPrintXMLWriter( out );
    }
View Full Code Here

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

        Writer writer = null;
        try
        {
            writer = new OutputStreamWriter( new FileOutputStream( destinationFile ), encoding );

            XMLWriter w = new PrettyPrintXMLWriter( writer, encoding, null );

            w.writeMarkup( "\n<!-- Generated by maven-plugin-tools " + getVersion() + " on " + new SimpleDateFormat(
                "yyyy-MM-dd" ).format( new Date() ) + " -->\n\n" );

            w.startElement( "plugin" );

            GeneratorUtils.element( w, "name", pluginDescriptor.getName() );

            GeneratorUtils.element( w, "description", pluginDescriptor.getDescription(), helpDescriptor );

            GeneratorUtils.element( w, "groupId", pluginDescriptor.getGroupId() );

            GeneratorUtils.element( w, "artifactId", pluginDescriptor.getArtifactId() );

            GeneratorUtils.element( w, "version", pluginDescriptor.getVersion() );

            GeneratorUtils.element( w, "goalPrefix", pluginDescriptor.getGoalPrefix() );

            if ( !helpDescriptor )
            {
                GeneratorUtils.element( w, "isolatedRealm", String.valueOf( pluginDescriptor.isIsolatedRealm() ) );

                GeneratorUtils.element( w, "inheritedByDefault",
                                        String.valueOf( pluginDescriptor.isInheritedByDefault() ) );
            }

            w.startElement( "mojos" );

            if ( pluginDescriptor.getMojos() != null )
            {
                @SuppressWarnings( "unchecked" ) List<MojoDescriptor> descriptors = pluginDescriptor.getMojos();

                PluginUtils.sortMojos( descriptors );

                for ( MojoDescriptor descriptor : descriptors )
                {
                    processMojoDescriptor( descriptor, w, helpDescriptor );
                }
            }

            w.endElement();

            if ( !helpDescriptor )
            {
                GeneratorUtils.writeDependencies( w, pluginDescriptor );
            }

            w.endElement();

            writer.flush();

        }
        finally
View Full Code Here

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

            DecorationModel decorationModel = context.getDecoration();

            StringWriter w = new StringWriter();
            XMLWriter writer =
                new PrettyPrintXMLWriter( w, StringUtils.repeat( " ", XmlWriterUtil.DEFAULT_INDENTATION_SIZE ),
                                          decorationModel.getModelEncoding(), null );

            writeHeader( writer );

            writeEffectiveSite( decorationModel, writer );
View Full Code Here

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

        if ( !artifacts.isEmpty() )
        {
            getLog().info( "Add the following to your pom to correct the missing dependencies: " );

            StringWriter out = new StringWriter();
            PrettyPrintXMLWriter writer = new PrettyPrintXMLWriter( out );

            for ( Artifact artifact : artifacts )
            {
                // called because artifact will set the version to -SNAPSHOT only if I do this. MNG-2961
                artifact.isSnapshot();

                writer.startElement( "dependency" );
                writer.startElement( "groupId" );
                writer.writeText( artifact.getGroupId() );
                writer.endElement();
                writer.startElement( "artifactId" );
                writer.writeText( artifact.getArtifactId() );
                writer.endElement();
                writer.startElement( "version" );
                writer.writeText( artifact.getBaseVersion() );
                if ( !StringUtils.isBlank( artifact.getClassifier() ) )
                {
                    writer.startElement( "classifier" );
                    writer.writeText( artifact.getClassifier() );
                    writer.endElement();
                }
                writer.endElement();

                if ( !Artifact.SCOPE_COMPILE.equals( artifact.getScope() ) )
                {
                    writer.startElement( "scope" );
                    writer.writeText( artifact.getScope() );
                    writer.endElement();
                }
                writer.endElement();
            }

            getLog().info( "\n" + out.getBuffer() );
        }
    }
View Full Code Here

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

        catch ( IOException ex )
        {
            throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); //$NON-NLS-1$
        }

        XMLWriter writer = new PrettyPrintXMLWriter( w );

        writer.startElement( ELT_CLASSPATH );

        String defaultOutput =
            IdeUtils.toRelativeAndFixSeparator( config.getProjectBaseDir(), config.getBuildOutputDirectory(), false );

        // ----------------------------------------------------------------------
        // Source roots and resources
        // ----------------------------------------------------------------------

        // List<EclipseSourceDir>
        List specialSources = new ArrayList();

        // Map<String,List<EclipseSourceDir>>
        Map byOutputDir = new HashMap();

        for ( int j = 0; j < config.getSourceDirs().length; j++ )
        {
            EclipseSourceDir dir = config.getSourceDirs()[j];

            // List<EclipseSourceDir>
            List byOutputDirs = (List) byOutputDir.get( dir.getOutput() );
            if ( byOutputDirs == null )
            {
                // ArrayList<EclipseSourceDir>
                byOutputDir.put( dir.getOutput() == null ? defaultOutput : dir.getOutput(), byOutputDirs =
                    new ArrayList() );
            }
            byOutputDirs.add( dir );
        }

        for ( int j = 0; j < config.getSourceDirs().length; j++ )
        {
            EclipseSourceDir dir = config.getSourceDirs()[j];

            log.debug( "Processing " + ( dir.isResource() ? "re" : "" ) + "source " + dir.getPath() + ": output=" +
                dir.getOutput() + "; default output=" + defaultOutput );

            boolean isSpecial = false;

            // handle resource with nested output folders
            if ( dir.isResource() )
            {
                // Check if the output is a subdirectory of the default output,
                // and if the default output has any sources that copy there.

                if ( dir.getOutput() != null // resource output dir is set
                    &&
                    !dir.getOutput().equals( defaultOutput ) // output dir is not default target/classes
                    && dir.getOutput().startsWith( defaultOutput ) // ... but is nested
                    && byOutputDir.get( defaultOutput ) != null // ???
                    && !( (List) byOutputDir.get( defaultOutput ) ).isEmpty() // ???
                )
                {
                    // do not specify as source since the output will be nested. Instead, mark
                    // it as a todo, and handle it with a custom build.xml file later.

                    log.debug( "Marking as special to prevent output folder nesting: " + dir.getPath() + " (output=" +
                        dir.getOutput() + ")" );

                    isSpecial = true;
                    specialSources.add( dir );
                }
            }

            writer.startElement( ELT_CLASSPATHENTRY );

            writer.addAttribute( ATTR_KIND, "src" ); //$NON-NLS-1$
            writer.addAttribute( ATTR_PATH, dir.getPath() );

            if ( !isSpecial && dir.getOutput() != null && !defaultOutput.equals( dir.getOutput() ) )
            {
                writer.addAttribute( ATTR_OUTPUT, dir.getOutput() );
            }

            if ( StringUtils.isNotEmpty( dir.getInclude() ) )
            {
                writer.addAttribute( ATTR_INCLUDING, dir.getInclude() );
            }

            String excludes = dir.getExclude();

            if ( dir.isResource() )
            {
                // automatically exclude java files: eclipse doesn't have the concept of resource directory so it will
                // try to compile any java file found in maven resource dirs
                excludes = StringUtils.isEmpty( excludes ) ? "**/*.java" : excludes + "|**/*.java";
            }

            if ( StringUtils.isNotEmpty( excludes ) )
            {
                writer.addAttribute( ATTR_EXCLUDING, excludes );
            }

            writer.endElement();

        }

        /* --------------- Commented out by rfeng
        // handle the special sources.
        if ( !specialSources.isEmpty() )
        {
            log.info( "Creating maven-eclipse.xml Ant file to handle resources" );

            try
            {
                Writer buildXmlWriter =
                    new OutputStreamWriter( new FileOutputStream( new File( config.getEclipseProjectDirectory(),
                                                                            "maven-eclipse.xml" ) ), "UTF-8" );
                PrettyPrintXMLWriter buildXmlPrinter = new PrettyPrintXMLWriter( buildXmlWriter );

                buildXmlPrinter.startElement( "project" );
                buildXmlPrinter.addAttribute( "default", "copy-resources" );

                buildXmlPrinter.startElement( "target" );
                buildXmlPrinter.addAttribute( "name", "init" );
                // initialize filtering tokens here
                buildXmlPrinter.endElement();

                buildXmlPrinter.startElement( "target" );
                buildXmlPrinter.addAttribute( "name", "copy-resources" );
                buildXmlPrinter.addAttribute( "depends", "init" );

                for ( Iterator it = specialSources.iterator(); it.hasNext(); )
                {
                    // TODO: merge source dirs on output path+filtering to reduce
                    // <copy> tags for speed.
                    EclipseSourceDir dir = (EclipseSourceDir) it.next();
                    buildXmlPrinter.startElement( "copy" );
                    buildXmlPrinter.addAttribute( "todir", dir.getOutput() );
                    buildXmlPrinter.addAttribute( "filtering", "" + dir.isFiltering() );

                    buildXmlPrinter.startElement( "fileset" );
                    buildXmlPrinter.addAttribute( "dir", dir.getPath() );
                    if ( dir.getInclude() != null )
                    {
                        buildXmlPrinter.addAttribute( "includes", dir.getInclude() );
                    }
                    if ( dir.getExclude() != null )
                    {
                        buildXmlPrinter.addAttribute( "excludes", dir.getExclude() );
                    }
                    buildXmlPrinter.endElement();

                    buildXmlPrinter.endElement();
                }

                buildXmlPrinter.endElement();

                buildXmlPrinter.endElement();

                IOUtil.close( buildXmlWriter );
            }
            catch ( IOException e )
            {
                throw new MojoExecutionException( "Cannot create " + config.getEclipseProjectDirectory() +
                    "/maven-eclipse.xml", e );
            }

            log.info( "Creating external launcher file" );
            // now create the launcher
            new EclipseAntExternalLaunchConfigurationWriter().init( log, config, "Maven_Ant_Builder.launch",
                                                                    "maven-eclipse.xml" ).write();

            // finally add it to the project writer.

            config.getBuildCommands().add(
                                           new BuildCommand(
                                                             "org.eclipse.ui.externaltools.ExternalToolBuilder",
                                                             "LaunchConfigHandle",
                                                             "<project>/" +
                                                                 EclipseLaunchConfigurationWriter.FILE_DOT_EXTERNAL_TOOL_BUILDERS +
                                                                 "Maven_Ant_Builder.launch" ) );
        }
        */

        // ----------------------------------------------------------------------
        // The default output
        // ----------------------------------------------------------------------

        writer.startElement( ELT_CLASSPATHENTRY );
        writer.addAttribute( ATTR_KIND, ATTR_OUTPUT );
        writer.addAttribute( ATTR_PATH, defaultOutput );
        writer.endElement();

        // ----------------------------------------------------------------------
        // Container classpath entries
        // ----------------------------------------------------------------------

        for ( Iterator it = config.getClasspathContainers().iterator(); it.hasNext(); )
        {
            writer.startElement( ELT_CLASSPATHENTRY );
            writer.addAttribute( ATTR_KIND, "con" ); //$NON-NLS-1$
            writer.addAttribute( ATTR_PATH, (String) it.next() );
            writer.endElement(); // name
        }

        // ----------------------------------------------------------------------
        // The dependencies
        // ----------------------------------------------------------------------
        Set addedDependencies = new HashSet();
        // TODO if (..magic property equals orderDependencies..)
        IdeDependency[] depsToWrite = config.getDepsOrdered();
        for ( int j = 0; j < depsToWrite.length; j++ )
        {
            IdeDependency dep = depsToWrite[j];

            if ( dep.isAddedToClasspath() )
            {
                String depId =
                    dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getClassifier() + ":" + dep.getVersion();
                /* avoid duplicates in the classpath for artifacts with different types (like ejbs) */
                if ( !addedDependencies.contains( depId ) )
                {
                    addDependency( writer, dep );
                    addedDependencies.add( depId );
                }
            }
        }

        writer.endElement();

        IOUtil.close( w );

    }
View Full Code Here

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

        catch ( IOException ex )
        {
            throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); //$NON-NLS-1$
        }

        XMLWriter writer = new PrettyPrintXMLWriter( w );

        writer.startElement( "projectDescription" ); //$NON-NLS-1$

        writer.startElement( ELT_NAME );
        writer.writeText( config.getEclipseProjectName() );
        writer.endElement();

        // TODO: this entire element might be dropped if the comment is null.
        // but as the maven1 eclipse plugin does it, it's better to be safe than sorry
        // A eclipse developer might want to look at this.
        writer.startElement( "comment" ); //$NON-NLS-1$

        if ( config.getProject().getDescription() != null )
        {
            writer.writeText( config.getProject().getDescription() );
        }

        writer.endElement();

        writer.startElement( "projects" ); //$NON-NLS-1$

        // referenced projects should not be added for plugins
        if ( !config.isPde() )
        {
            for ( int j = 0; j < config.getDepsOrdered().length; j++ )
            {
                IdeDependency dep = config.getDepsOrdered()[j];
                if ( dep.isReferencedProject() )
                {
                    writer.startElement( "project" ); //$NON-NLS-1$
                    writer.writeText( dep.getEclipseProjectName() );
                    writer.endElement();
                }
            }
        }

        writer.endElement(); // projects

        writer.startElement( ELT_BUILD_SPEC );

        for ( Iterator it = buildCommands.iterator(); it.hasNext(); )
        {
            ( (BuildCommand) it.next() ).print( writer );
        }

        writer.endElement(); // buildSpec

        writer.startElement( ELT_NATURES );

        for ( Iterator it = projectnatures.iterator(); it.hasNext(); )
        {
            writer.startElement( ELT_NATURE );
            writer.writeText( (String) it.next() );
            writer.endElement(); // name
        }

        writer.endElement(); // natures

        /*
        boolean addLinks = !config.getProjectBaseDir().equals( config.getEclipseProjectDirectory() );

        if ( addLinks || ( config.isPde() && config.getDepsOrdered().length > 0 ) )
        {
            writer.startElement( "linkedResources" ); //$NON-NLS-1$

            if ( addLinks )
            {

                addFileLink( writer, config.getProjectBaseDir(), config.getEclipseProjectDirectory(),
                             config.getProject().getFile() );

                addSourceLinks( writer, config.getProjectBaseDir(), config.getEclipseProjectDirectory(),
                                config.getProject().getCompileSourceRoots() );
                addResourceLinks( writer, config.getProjectBaseDir(), config.getEclipseProjectDirectory(),
                                  config.getProject().getBuild().getResources() );

                addSourceLinks( writer, config.getProjectBaseDir(), config.getEclipseProjectDirectory(),
                                config.getProject().getTestCompileSourceRoots() );
                addResourceLinks( writer, config.getProjectBaseDir(), config.getEclipseProjectDirectory(),
                                  config.getProject().getBuild().getTestResources() );

            }

            if ( config.isPde() )
            {
                for ( int j = 0; j < config.getDepsOrdered().length; j++ )
                {
                    IdeDependency dep = config.getDepsOrdered()[j];

                    if ( dep.isAddedToClasspath() && !dep.isProvided() && !dep.isReferencedProject() &&
                        !dep.isTestDependency() && !dep.isOsgiBundle() )
                    {
                        String name = dep.getFile().getName();
                        addLink( writer, name, StringUtils.replace( IdeUtils.getCanonicalPath( dep.getFile() ), "\\",
                                                                    "/" ), LINK_TYPE_FILE );
                    }
                }
            }

            writer.endElement(); // linkedResources
        }
        */

        writer.endElement(); // projectDescription

        IOUtil.close( w );
    }
View Full Code Here

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

        }

        is.close();
        Writer w = new OutputStreamWriter( new FileOutputStream( new File( project.getBasedir(), ".classpath" ) ),
            "UTF-8" );
        org.codehaus.plexus.util.xml.XMLWriter writer = new PrettyPrintXMLWriter( w );
        Xpp3DomWriter.write( writer, dom );
        w.flush();
        w.close();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.