Package org.codehaus.plexus.util.xml

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


        }
        catch ( IOException ex )
        {
            throw new MojoExecutionException( "Rad6Plugin.erroropeningfile", ex ); //$NON-NLS-1$
        }
        XMLWriter writer = new PrettyPrintXMLWriter( w, "UTF-8", null );
        Xpp3DomWriter.write( writer, xmlDomTree );
        IOUtil.close( w );
    }
View Full Code Here


        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 classpath for: " + dir.toString() + "; 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() );
            }

            String includes = dir.getIncludeAsString();
            if ( StringUtils.isNotEmpty( includes ) )
            {
                writer.addAttribute( ATTR_INCLUDING, includes );
            }

            String excludes = dir.getExcludeAsString();
            if ( StringUtils.isNotEmpty( excludes ) )
            {
                writer.addAttribute( ATTR_EXCLUDING, excludes );
            }

            writer.endElement();

        }

        // 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.getIncludeAsString() != null )
                    {
                        buildXmlPrinter.addAttribute( "includes", dir.getIncludeAsString() );
                    }
                    if ( dir.getExcludeAsString() != null )
                    {
                        buildXmlPrinter.addAttribute( "excludes", dir.getExcludeAsString() );
                    }
                    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();

        Set addedDependencies = new HashSet();
        // TODO if (..magic property equals orderDependencies..)

        // ----------------------------------------------------------------------
        // Java API dependencies that may complete the classpath container so must
        // be declared BEFORE so that container access rules don't fail
        // ----------------------------------------------------------------------
        IdeDependency[] depsToWrite = config.getDepsOrdered();
        for ( int j = 0; j < depsToWrite.length; j++ )
        {
            IdeDependency dep = depsToWrite[j];
            if ( dep.isJavaApi() )
            {
                String depId = getDependencyId( dep );
                if ( !addedDependencies.contains( depId ) )
                {
                    addDependency( writer, dep );
                    addedDependencies.add( depId );
                }
            }
        }

        // ----------------------------------------------------------------------
        // The dependencies
        // ----------------------------------------------------------------------
        for ( int j = 0; j < depsToWrite.length; j++ )
        {
            IdeDependency dep = depsToWrite[j];

            if ( dep.isAddedToClasspath() )
            {
                String depId = getDependencyId( dep );
                /* avoid duplicates in the classpath for artifacts with different types (like ejbs or test-jars) */
                if ( !addedDependencies.contains( depId ) )
                {
                    addDependency( writer, dep );
                    addedDependencies.add( depId );
                }
            }
        }

        // ----------------------------------------------------------------------
        // 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
        }

        writer.endElement();

        IOUtil.close( w );

    }
View Full Code Here

        }
        catch ( IOException ex )
        {
            throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); //$NON-NLS-1$
        }
        XMLWriter writer = new PrettyPrintXMLWriter( w );
        writeModuleTypeFacetCore( writer, packaging );
        IOUtil.close( w );
    }
View Full Code Here

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

        // create a .component file and write out to it
        XMLWriter writer = new PrettyPrintXMLWriter( w );

        writeModuleTypeComponent( writer, config.getPackaging(), config.getBuildOutputDirectory(),
                                  config.getSourceDirs(), config.getLocalRepository() );

        IOUtil.close( w );
View Full Code Here

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

        XMLWriter writer = new PrettyPrintXMLWriter( w, "UTF-8", null );

        writer.startElement( MYECLIPSE_METADATA_PROJECT );
        writer.addAttribute( MYECLIPSE_METADATA_PROJECT_TYPE, getMyEclipseProjectType( packaging ) );
        writer.addAttribute( MYECLIPSE_METADATA_PROJECT_NAME, config.getEclipseProjectName() );
        writer.addAttribute( MYECLIPSE_METADATA_PROJECT_ID, config.getEclipseProjectName() );

        if ( Constants.PROJECT_PACKAGING_WAR.equalsIgnoreCase( packaging ) )
        {
            // Find web application context root from maven-war-plugin configuration.
            // ArtifactId is used as the default value
            String warContextRoot =
                IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN, "warContextRoot",//$NON-NLS-1$
                                           "/" + config.getProject().getArtifactId() );

            writer.addAttribute( MYECLIPSE_METADATA_PROJECT_CONTEXT_ROOT, warContextRoot );

            writer.addAttribute( MYECLIPSE_METADATA_PROJECT_J2EE_SPEC, getJeeVersion() );
            // TODO : use maven final name
            writer.addAttribute( MYECLIPSE_METADATA_PROJECT_ARCHIVE, config.getEclipseProjectName() + ".war" );
        }

        if ( Constants.PROJECT_PACKAGING_EAR.equalsIgnoreCase( packaging ) )
        {
            // TODO : use maven final name
            writer.addAttribute( MYECLIPSE_METADATA_PROJECT_ARCHIVE, config.getEclipseProjectName() + ".ear" );
        }

        writer.startElement( MYECLIPSE_METADATA_PROJECT_ATTRIBUTES );
        if ( Constants.PROJECT_PACKAGING_WAR.equalsIgnoreCase( packaging ) )
        {
            writer.startElement( MYECLIPSE_METADATA_PROJECT_ATTRIBUTE );
            writer.addAttribute( "name", "webrootdir" );
            // TODO : retrieve this from project configuration
            writer.addAttribute( "value", "src/main/webapp" );
            writer.endElement();
        }
        // Close <attributes>
        writer.endElement();

        // Close <project-module>
        writer.endElement();

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

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

        XMLWriter writer = new PrettyPrintXMLWriter( sprintFileWriter, "UTF-8", null );

        writer.startElement( MYECLIPSE_SPRING_BEANS_PROJECT_DESCRIPTION );
        // Configuration extension
        writer.startElement( MYECLIPSE_SPRING_CONFIG_EXTENSIONS );
        writer.startElement( MYECLIPSE_SPRING_CONFIG_EXTENSION );
        writer.writeText( "xml" );
        writer.endElement();
        writer.endElement();

        // Configuration files
        writer.startElement( MYECLIPSE_SPRING_CONFIGS );

        // maven's cwd stays at the top of hierarchical projects so we
        // do this with full path so it works as we descend through various modules (projects)
        String absolutePrefix = config.getEclipseProjectDirectory() + "/";
        // convert hem all to forward slashes
        absolutePrefix = StringUtils.replace( absolutePrefix, "\\", "/" );
        int absolutePrefixLength = absolutePrefix.length();
        Iterator onConfigFiles =
            getConfigurationFilesList( absolutePrefix + (String) springConfig.get( "basedir" ),
                                       (String) springConfig.get( "file-pattern" ) ).iterator();

        while ( onConfigFiles.hasNext() )
        {
            writer.startElement( MYECLIPSE_SPRING_CONFIG );
            // convert out any back slashes
            String processedFileName = StringUtils.replace( (String) onConfigFiles.next(), "\\", "/" );
            // write out the file name minus the absolute path to get to the top of the project
            writer.writeText( processedFileName.substring( absolutePrefixLength ) );
            writer.endElement();
        }
        writer.endElement();

        // Configuration sets
        writer.startElement( MYECLIPSE_SPRING_CONFIGSETS );
        writer.endElement();

        // Spring version
        writer.startElement( MYECLIPSE_SPRING_VERSION );
        writer.writeText( (String) springConfig.get( "version" ) );
        writer.endElement();

        writer.endElement();

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

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

            XMLWriter writer = new PrettyPrintXMLWriter( w, "UTF-8", null );

            writer.startElement( MYECLIPSE_STRUTS_PROPERTIES );

            writer.startElement( MYECLIPSE_STRUTS_VERSION );
            writer.writeText( getStrutsVersion() );
            writer.endElement();

            writer.startElement( MYECLIPSE_STRUTS_BASE_PACKAGE );
            writer.writeText( getBasePackage() );
            writer.endElement();

            writer.startElement( MYECLIPSE_STRUTS_PATTERN );
            writer.writeText( getStrutsPattern() );
            writer.endElement();

            writer.startElement( MYECLIPSE_STRUTS_SERVLET_NAME );
            writer.writeText( getStrutsServletName() );
            writer.endElement();

            // Close <MyEclipseStrutsProperties>
            writer.endElement();

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

    {
        OutputStreamWriter fileWriter = new OutputStreamWriter( new FileOutputStream( file ), "UTF-8" );

        PrintWriter printWriter = new PrintWriter( fileWriter );

        XMLWriter writer = new PrettyPrintXMLWriter( printWriter );

        Map classes = new HashMap();

        for ( Iterator it = model.getClasses( getGeneratedVersion() ).iterator(); it.hasNext(); )
        {
            ModelClass modelClass = (ModelClass) it.next();

            JPoxClassMetadata jpoxMetadata = (JPoxClassMetadata) modelClass.getMetadata( JPoxClassMetadata.ID );

            if ( !jpoxMetadata.isEnabled() )
            {
                // Skip generation of those classes that are not enabled for the jpox plugin.
                continue;
            }

            String packageName = modelClass.getPackageName( isPackageWithVersion(), getGeneratedVersion() );

            List list = (List) classes.get( packageName );

            if ( list == null )
            {
                list = new ArrayList();
            }

            list.add( modelClass );

            classes.put( packageName, list );
        }

        printWriter.println( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" );
        printWriter.println();
        printWriter.println( "<!DOCTYPE jdo PUBLIC" );
        printWriter.println( "  \"-//Sun Microsystems, Inc.//DTD Java Data Objects Metadata 2.0//EN\"" );
        printWriter.println( "  \"http://java.sun.com/dtd/jdo_2_0.dtd\">" );
        printWriter.println();

        writer.startElement( "jdo" );

        for ( Iterator it = classes.entrySet().iterator(); it.hasNext(); )
        {
            Map.Entry entry = (Map.Entry) it.next();

            List list = (List) entry.getValue();

            if ( list.size() == 0 )
            {
                continue;
            }

            String packageName = (String) entry.getKey();

            writer.startElement( "package" );

            writer.addAttribute( "name", packageName );

            for ( Iterator it2 = list.iterator(); it2.hasNext(); )
            {
                ModelClass modelClass = (ModelClass) it2.next();

                writeClass( writer, modelClass );
            }

            if ( packageName.equals( model.getDefaultPackageName( isPackageWithVersion(), getGeneratedVersion() ) ) )
            {
                writeModelloMetadataClass( writer );
            }

            writer.endElement(); // package
        }

        writer.endElement(); // jdo

        printWriter.println();

        printWriter.close();
    }
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();

                if ( helpDescriptor )
                {
                    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

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

        XMLWriter writer = new PrettyPrintXMLWriter(w, "UTF-8", null);

        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 classpath for: " + dir.toString() + "; 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());
            }

            String includes = dir.getIncludeAsString();
            if (StringUtils.isNotEmpty(includes)) {
                writer.addAttribute(ATTR_INCLUDING, includes);
            }

            String excludes = dir.getExcludeAsString();
            if (StringUtils.isNotEmpty(excludes)) {
                writer.addAttribute(ATTR_EXCLUDING, excludes);
            }

            writer.endElement();
        }

        // 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.getIncludeAsString() != null) {
                        buildXmlPrinter.addAttribute("includes", dir.getIncludeAsString());
                    }
                    if (dir.getExcludeAsString() != null) {
                        buildXmlPrinter.addAttribute("excludes", dir.getExcludeAsString());
                    }
                    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();

        Set addedDependencies = new HashSet();

        // ----------------------------------------------------------------------
        // Java API dependencies that may complete the classpath container must
        // be declared BEFORE all other dependencies so that container access rules don't fail
        // ----------------------------------------------------------------------
        IdeDependency[] depsToWrite = config.getDeps();
        for (int j = 0; j < depsToWrite.length; j++) {
            IdeDependency dep = depsToWrite[j];
            if (dep.isJavaApi()) {
                String depId = getDependencyId(dep);
                if (!addedDependencies.contains(depId)) {
                    addDependency(writer, dep);
                    addedDependencies.add(depId);
                }
            }
        }

        if (!config.isClasspathContainersLast()) {
            writeClasspathContainers(writer);
        }

        // ----------------------------------------------------------------------
        // The project's dependencies
        // ----------------------------------------------------------------------
        for (int j = 0; j < depsToWrite.length; j++) {
            IdeDependency dep = depsToWrite[j];

            if (dep.isAddedToClasspath()) {
                String depId = getDependencyId(dep);
                /* avoid duplicates in the classpath for artifacts with different types (like ejbs or test-jars) */
                if (!addedDependencies.contains(depId)) {
                    addDependency(writer, dep);
                    addedDependencies.add(depId);
                }
            }
        }

        if (config.isClasspathContainersLast()) {
            writeClasspathContainers(writer);
        }

        writer.endElement();

        IOUtil.close(w);
    }
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.