Package org.codehaus.plexus.util.xml

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


    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

        } 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("services");
        writer.addAttribute("binding-component", bc ? "true" : "false");

        // We need to get all the namespaces into a hashmap so we
        // can get the QName output correctly
        Map namespaceMap = getNamespaceMap(provides, consumes);

        // Set-up the namespaces
        for (Iterator iterator = namespaceMap.keySet().iterator(); iterator
                .hasNext();) {
            String key = (String) iterator.next();
            StringBuffer namespaceDecl = new StringBuffer();
            namespaceDecl.append("xmlns:");
            namespaceDecl.append(namespaceMap.get(key));
            writer.addAttribute(namespaceDecl.toString(), key);
        }

        // Put in the provides
        for (Iterator iterator = provides.iterator(); iterator.hasNext();) {
            Provides providesEntry = (Provides) iterator.next();
            writer.startElement("provides");
            addQNameAttribute(writer, "interface-name", providesEntry
                    .getInterfaceName(), namespaceMap);
            addQNameAttribute(writer, "service-name", providesEntry
                    .getServiceName(), namespaceMap);
            addStringAttribute(writer, "endpoint-name", providesEntry
                    .getEndpointName());
            writer.endElement();
        }

        // Put in the consumes
        for (Iterator iterator = consumes.iterator(); iterator.hasNext();) {
            Consumes consumesEntry = (Consumes) iterator.next();
            writer.startElement("consumes");
            addQNameAttribute(writer, "interface-name", consumesEntry
                    .getInterfaceName(), namespaceMap);
            addQNameAttribute(writer, "service-name", consumesEntry
                    .getServiceName(), namespaceMap);
            addStringAttribute(writer, "endpoint-name", consumesEntry
                    .getEndpointName());

            // TODO Handling of LinkType?

            writer.endElement();
        }

        writer.endElement();

        writer.endElement();

        close(w);
    }
View Full Code Here

        } 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("shared-library");
        writer.addAttribute("class-loader-delegation", classLoaderDelegation);
        writer.addAttribute("version", version);

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

        writer.startElement("shared-library-class-path");
        for (Iterator it = uris.iterator(); it.hasNext();) {
            DependencyInformation dependency = (DependencyInformation) it
                    .next();
            writer.startElement("path-element");
            writer.writeText(dependency.getFilename());
            writer.endElement();
        }
        writer.endElement();

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

        close(w);
    }
View Full Code Here

        } 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("component");
        writer.addAttribute("type", type);
        writer.addAttribute("component-class-loader-delegation",
                componentClassLoaderDelegation);
        writer.addAttribute("bootstrap-class-loader-delegation",
                bootstrapClassLoaderDelegation);

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

        writer.startElement("component-class-name");
        writer.writeText(component);
        writer.endElement();
        writer.startElement("component-class-path");
        for (Iterator it = uris.iterator(); it.hasNext();) {
            DependencyInformation info = (DependencyInformation) it.next();
            if ("jar".equals(info.getType()) || "bundle".equals(info.getType())) {
                writer.startElement("path-element");
                writer.writeText(info.getFilename());
                writer.endElement();
            }
        }
        writer.endElement();

        writer.startElement("bootstrap-class-name");
        writer.writeText(bootstrap);
        writer.endElement();
        writer.startElement("bootstrap-class-path");
        for (Iterator it = uris.iterator(); it.hasNext();) {
            DependencyInformation info = (DependencyInformation) it.next();
            if ("jar".equals(info.getType())) {
                writer.startElement("path-element");
                writer.writeText(info.getFilename());
                writer.endElement();
            }
        }
        writer.endElement();

        for (Iterator it = uris.iterator(); it.hasNext();) {
            DependencyInformation info = (DependencyInformation) it.next();
            if ("jbi-shared-library".equals(info.getType())) {
                writer.startElement("shared-library");
                writer.addAttribute("version", info.getVersion());
                writer.writeText(info.getName());
                writer.endElement();
            }
        }

        writer.endElement();

        writer.endElement();

        close(w);
    }
View Full Code Here

        } 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

            copySettings = copySettings( settings );
            hidePasswords( copySettings );
        }

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

        writeHeader( writer );
View Full Code Here

    /** {@inheritDoc} */
    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

        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

            SiteRenderingContext context = createSiteRenderingContext( localesList.get( 0 ) );

            DecorationModel decorationModel = context.getDecoration();

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

            writeHeader( writer );
View Full Code Here

TOP

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

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.