Example usage for org.eclipse.jdt.internal.core ClasspathEntry K_OUTPUT

List of usage examples for org.eclipse.jdt.internal.core ClasspathEntry K_OUTPUT

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core ClasspathEntry K_OUTPUT.

Prototype

int K_OUTPUT

To view the source code for org.eclipse.jdt.internal.core ClasspathEntry K_OUTPUT.

Click Source Link

Document

A constant indicating an output location.

Usage

From source file:io.sarl.eclipse.util.JavaClasspathParser.java

License:Apache License

/**
 * Reads and decode an XML classpath string. Returns a two-dimensional array, where the number of elements in the row is fixed to 2. The first
 * element is an array of raw classpath entries and the second element is an array of referenced entries that may have been stored by the client
 * earlier. See {@link IJavaProject#getReferencedClasspathEntries()} for more details.
 *
 * @param projectName//from   w  w w .j  a  v a  2  s . c om
 *            - the name of project containing the .classpath file
 * @param projectRootAbsoluteFullPath
 *            - the path to project containing the .classpath file
 * @param xmlClasspath
 *            - path to the XML
 * @param unknownElements
 *            - map of unknow elements
 * @return the set of CLasspath ENtries extracted from the .classpath
 * @throws IOException
 *             - exception during parsing of .classpath
 * @throws ClasspathEntry.AssertionFailedException
 *             - exception during parsing of .classpath
 */
@SuppressWarnings("checkstyle:npathcomplexity")
public static IClasspathEntry[][] decodeClasspath(String projectName, IPath projectRootAbsoluteFullPath,
        String xmlClasspath, Map<IPath, UnknownXmlElements> unknownElements)
        throws IOException, ClasspathEntry.AssertionFailedException {

    final List<IClasspathEntry> paths = new ArrayList<>();
    IClasspathEntry defaultOutput = null;
    final Element cpElement;

    try (StringReader reader = new StringReader(xmlClasspath);) {
        final DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        cpElement = parser.parse(new InputSource(reader)).getDocumentElement();
    } catch (SAXException e) {
        throw new IOException(Messages.file_badFormat);
    } catch (ParserConfigurationException e) {
        throw new IOException(Messages.file_badFormat);
    }

    if (!cpElement.getNodeName().equalsIgnoreCase("classpath")) { //$NON-NLS-1$
        throw new IOException(Messages.file_badFormat);
    }
    NodeList list = cpElement.getElementsByTagName(ClasspathEntry.TAG_CLASSPATHENTRY);
    int length = list.getLength();

    for (int i = 0; i < length; ++i) {
        final Node node = list.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            final IClasspathEntry entry = elementDecode((Element) node, projectName,
                    projectRootAbsoluteFullPath, unknownElements);
            if (entry != null) {
                if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) {
                    // separate output
                    defaultOutput = entry;
                } else {
                    paths.add(entry);
                }
            }
        }
    }
    final int pathSize = paths.size();
    final IClasspathEntry[][] entries = new IClasspathEntry[2][];
    entries[0] = new IClasspathEntry[pathSize + (defaultOutput == null ? 0 : 1)];
    paths.toArray(entries[0]);
    if (defaultOutput != null) {
        // ensure output is last item
        entries[0][pathSize] = defaultOutput;
    }
    paths.clear();
    list = cpElement.getElementsByTagName(ClasspathEntry.TAG_REFERENCED_ENTRY);
    length = list.getLength();

    for (int i = 0; i < length; ++i) {
        final Node node = list.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            final IClasspathEntry entry = elementDecode((Element) node, projectName,
                    projectRootAbsoluteFullPath, unknownElements);
            if (entry != null) {
                paths.add(entry);
            }
        }
    }
    entries[1] = new IClasspathEntry[paths.size()];
    paths.toArray(entries[1]);

    return entries;
}

From source file:io.sarl.eclipse.util.JavaClasspathParser.java

License:Apache License

/**
 * Decodes one XML element with the XML stream.
 *
 * @param element//  ww  w  .  j  a va  2s  .c o m
 *            - the considered element
 * @param projectName
 *            - the name of project containing the .classpath file
 * @param projectRootAbsoluteFullPath
 *            - he path to project containing the .classpath file
 * @param unknownElements
 *            - map of unknown elements
 * @return the set of CLasspath ENtries extracted from the considered element
 */
@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" })
public static IClasspathEntry elementDecode(Element element, String projectName,
        IPath projectRootAbsoluteFullPath, Map<IPath, UnknownXmlElements> unknownElements) {
    final IPath projectPath = projectRootAbsoluteFullPath;
    final NamedNodeMap attributes = element.getAttributes();
    final NodeList children = element.getChildNodes();
    final boolean[] foundChildren = new boolean[children.getLength()];
    final String kindAttr = removeAttribute(ClasspathEntry.TAG_KIND, attributes);
    final String pathAttr = removeAttribute(ClasspathEntry.TAG_PATH, attributes);

    // ensure path is absolute
    IPath path = new Path(pathAttr);
    final int kind = kindFromString(kindAttr);
    if (kind != IClasspathEntry.CPE_VARIABLE && kind != IClasspathEntry.CPE_CONTAINER && !path.isAbsolute()) {
        if (!(path.segmentCount() > 0 && path.segment(0).equals(ClasspathEntry.DOT_DOT))) {
            path = projectPath.append(path);
        }
    }
    // source attachment info (optional)
    IPath sourceAttachmentPath = element.hasAttribute(ClasspathEntry.TAG_SOURCEPATH)
            ? new Path(removeAttribute(ClasspathEntry.TAG_SOURCEPATH, attributes))
            : null;
    if (kind != IClasspathEntry.CPE_VARIABLE && sourceAttachmentPath != null
            && !sourceAttachmentPath.isAbsolute()) {
        sourceAttachmentPath = projectPath.append(sourceAttachmentPath);
    }
    final IPath sourceAttachmentRootPath = element.hasAttribute(ClasspathEntry.TAG_ROOTPATH)
            ? new Path(removeAttribute(ClasspathEntry.TAG_ROOTPATH, attributes))
            : null;

    // exported flag (optional)
    final boolean isExported = removeAttribute(ClasspathEntry.TAG_EXPORTED, attributes).equals("true"); //$NON-NLS-1$

    // inclusion patterns (optional)
    IPath[] inclusionPatterns = decodePatterns(attributes, ClasspathEntry.TAG_INCLUDING);
    if (inclusionPatterns == null) {
        inclusionPatterns = ClasspathEntry.INCLUDE_ALL;
    }

    // exclusion patterns (optional)
    IPath[] exclusionPatterns = decodePatterns(attributes, ClasspathEntry.TAG_EXCLUDING);
    if (exclusionPatterns == null) {
        exclusionPatterns = ClasspathEntry.EXCLUDE_NONE;
    }

    // access rules (optional)
    NodeList attributeList = getChildAttributes(ClasspathEntry.TAG_ACCESS_RULES, children, foundChildren);
    IAccessRule[] accessRules = decodeAccessRules(attributeList);

    // backward compatibility
    if (accessRules == null) {
        accessRules = getAccessRules(inclusionPatterns, exclusionPatterns);
    }

    // combine access rules (optional)
    final boolean combineAccessRestrictions = !removeAttribute(ClasspathEntry.TAG_COMBINE_ACCESS_RULES,
            attributes).equals("false"); //$NON-NLS-1$

    // extra attributes (optional)
    attributeList = getChildAttributes(ClasspathEntry.TAG_ATTRIBUTES, children, foundChildren);
    final IClasspathAttribute[] extraAttributes = decodeExtraAttributes(attributeList);

    // custom output location
    final IPath outputLocation = element.hasAttribute(ClasspathEntry.TAG_OUTPUT)
            ? projectPath.append(removeAttribute(ClasspathEntry.TAG_OUTPUT, attributes))
            : null;

    String[] unknownAttributes = null;
    ArrayList<String> unknownChildren = null;

    if (unknownElements != null) {
        // unknown attributes
        final int unknownAttributeLength = attributes.getLength();
        if (unknownAttributeLength != 0) {
            unknownAttributes = new String[unknownAttributeLength * 2];
            for (int i = 0; i < unknownAttributeLength; i++) {
                final Node attribute = attributes.item(i);
                unknownAttributes[i * 2] = attribute.getNodeName();
                unknownAttributes[i * 2 + 1] = attribute.getNodeValue();
            }
        }

        // unknown children
        for (int i = 0, length = foundChildren.length; i < length; i++) {
            if (!foundChildren[i]) {
                final Node node = children.item(i);
                if (node.getNodeType() != Node.ELEMENT_NODE) {
                    continue;
                }
                if (unknownChildren == null) {
                    unknownChildren = new ArrayList<>();
                }
                final StringBuffer buffer = new StringBuffer();
                decodeUnknownNode(node, buffer);
                unknownChildren.add(buffer.toString());
            }
        }
    }

    // recreate the CP entry
    IClasspathEntry entry = null;
    switch (kind) {

    case IClasspathEntry.CPE_PROJECT:
        /*
         * IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_PROJECT, path, ClasspathEntry.INCLUDE_ALL, // inclusion patterns
         * ClasspathEntry.EXCLUDE_NONE, // exclusion patterns null, // source attachment null, // source attachment root null, // specific output
         * folder
         */
        entry = new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_PROJECT, path,
                ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, null, null, isExported,
                accessRules, combineAccessRestrictions, extraAttributes);
        break;
    case IClasspathEntry.CPE_LIBRARY:
        entry = JavaCore.newLibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, accessRules,
                extraAttributes, isExported);
        break;
    case IClasspathEntry.CPE_SOURCE:
        // must be an entry in this project or specify another project
        final String projSegment = path.segment(0);
        if (projSegment != null && projSegment.equals(projectName)) {
            // this project
            entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation,
                    extraAttributes);
        } else {
            if (path.segmentCount() == 1) {
                // another project
                entry = JavaCore.newProjectEntry(path, accessRules, combineAccessRestrictions, extraAttributes,
                        isExported);
            } else {
                // an invalid source folder
                entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation,
                        extraAttributes);
            }
        }
        break;
    case IClasspathEntry.CPE_VARIABLE:
        entry = JavaCore.newVariableEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, accessRules,
                extraAttributes, isExported);
        break;
    case IClasspathEntry.CPE_CONTAINER:
        entry = JavaCore.newContainerEntry(path, accessRules, extraAttributes, isExported);
        break;
    case ClasspathEntry.K_OUTPUT:
        if (!path.isAbsolute()) {
            return null;
        }
        /*
         * ClasspathEntry.EXCLUDE_NONE, null, // source attachment null, // source attachment root null, // custom output location false, null, //
         * no access rules false, // no accessible files to combine
         */
        entry = new ClasspathEntry(ClasspathEntry.K_OUTPUT, IClasspathEntry.CPE_LIBRARY, path,
                ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, null, null, false, null, false,
                ClasspathEntry.NO_EXTRA_ATTRIBUTES);
        break;
    default:
        throw new AssertionFailedException(Messages.bind(Messages.classpath_unknownKind, kindAttr));
    }

    if (unknownAttributes != null || unknownChildren != null) {
        final UnknownXmlElements unknownXmlElements = new UnknownXmlElements();
        unknownXmlElements.attributes = unknownAttributes;
        unknownXmlElements.children = unknownChildren;
        if (unknownElements != null) {
            unknownElements.put(path, unknownXmlElements);
        }
    }

    return entry;
}

From source file:io.sarl.eclipse.util.JavaClasspathParser.java

License:Apache License

/**
 * Returns the kind of a <code>PackageFragmentRoot</code> from its <code>String</code> form.
 *
 * @param kindStr/*from  w ww.j a  va2 s  .co  m*/
 *            - string to test
 * @return the integer identifier of the type of the specified string: CPE_PROJECT, CPE_VARIABLE, CPE_CONTAINER, etc.
 */
@SuppressWarnings("checkstyle:equalsavoidnull")
private static int kindFromString(String kindStr) {

    if (kindStr.equalsIgnoreCase("prj")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_PROJECT;
    }
    if (kindStr.equalsIgnoreCase("var")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_VARIABLE;
    }
    if (kindStr.equalsIgnoreCase("con")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_CONTAINER;
    }
    if (kindStr.equalsIgnoreCase("src")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_SOURCE;
    }
    if (kindStr.equalsIgnoreCase("lib")) { //$NON-NLS-1$
        return IClasspathEntry.CPE_LIBRARY;
    }
    if (kindStr.equalsIgnoreCase("output")) { //$NON-NLS-1$
        return ClasspathEntry.K_OUTPUT;
    }
    return -1;
}

From source file:io.sarl.eclipse.util.Utilities.java

License:Apache License

/** Create the classpath output location.
 *
 * @param bundle the bundle to point to. Never <code>null</code>.
 * @param precomputedBundlePath the path to the bundle that is already available. If <code>null</code>,
 *      the path is computed from the bundle with {@link BundleUtil}.
 * @param javadocURLs the mappings from the bundle to the javadoc URL. It is used for linking the javadoc to the bundle if
 *      the bundle platform does not know the Javadoc file. If <code>null</code>, no mapping is defined.
 * @return the classpath entry./* w  ww.  ja va  2s.  c  o m*/
 */
public static IClasspathEntry newOutputClasspathEntry(Bundle bundle, IPath precomputedBundlePath,
        BundleURLMappings javadocURLs) {
    assert bundle != null;
    final IPath bundlePath;
    if (precomputedBundlePath == null) {
        bundlePath = BundleUtil.getBundlePath(bundle);
    } else {
        bundlePath = precomputedBundlePath;
    }
    final IPath sourceBundlePath = BundleUtil.getSourceBundlePath(bundle, bundlePath);
    final IPath javadocPath = BundleUtil.getJavadocBundlePath(bundle, bundlePath);

    final IClasspathAttribute[] extraAttributes;
    if (javadocPath == null) {
        if (javadocURLs != null) {
            final String url = javadocURLs.getURLForBundle(bundle);
            if (!Strings.isNullOrEmpty(url)) {
                final IClasspathAttribute attr = JavaCore
                        .newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, url);
                extraAttributes = new IClasspathAttribute[] { attr };
            } else {
                extraAttributes = ClasspathEntry.NO_EXTRA_ATTRIBUTES;
            }
        } else {
            extraAttributes = ClasspathEntry.NO_EXTRA_ATTRIBUTES;
        }
    } else {
        final IClasspathAttribute attr = JavaCore.newClasspathAttribute(
                IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, javadocPath.makeAbsolute().toOSString());
        extraAttributes = new IClasspathAttribute[] { attr };
    }

    return new ClasspathEntry(ClasspathEntry.K_OUTPUT, IClasspathEntry.CPE_LIBRARY, bundlePath,
            ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, sourceBundlePath, null, null, false, null,
            false, extraAttributes);
}

From source file:org.eclipse.ajdt.core.CoreUtils.java

License:Open Source License

/**
 * Get the output locations for the project
 * /* w ww .  ja v  a  2s.  c  om*/
 * @param project
 * @return list of IPath objects
 */
public static List<IPath> getOutputLocationPaths(IProject project) {
    List<IPath> outputLocations = new ArrayList<IPath>();
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject == null)
        return outputLocations;

    try {
        // Have been unable to create a user scenario where the following
        // for
        // loop adds something to outputLocations, therefore always
        // fall through to the following if loop. However, if a project has
        // more than one output folder, then this for loop should pick them
        // up.
        // Needs testing.......
        IClasspathEntry[] cpEntry = javaProject.getRawClasspath();
        for (int j = 0; j < cpEntry.length; j++) {
            IClasspathEntry entry = cpEntry[j];
            int contentKind = entry.getContentKind();
            if (contentKind == ClasspathEntry.K_OUTPUT) {
                if (entry.getOutputLocation() != null) {
                    outputLocations.add(entry.getOutputLocation());
                }
            }
        }
        // If we haven't added anything from reading the .classpath
        // file, then use the default output location
        if (outputLocations.size() == 0) {
            outputLocations.add(javaProject.getOutputLocation());
        }
    } catch (JavaModelException e) {
    }
    return outputLocations;
}

From source file:org.eclipse.ajdt.ui.tests.builder.ProjectDependenciesUtils.java

License:Open Source License

public static boolean projectHasClassFolderDependency(IProject project, IProject projectDependedOn)
        throws JavaModelException {
    IJavaProject javaProject = JavaCore.create(project);
    IJavaProject depProject = JavaCore.create(projectDependedOn);
    if (javaProject == null || depProject == null)
        return false;

    // first get the output location for projectDependedOn
    IPath outputLocation = null;/* w  w w .  ja v  a2  s . c  om*/
    IClasspathEntry[] cp = depProject.getRawClasspath();
    for (int j = 0; j < cp.length; j++) {
        IClasspathEntry entry = cp[j];
        int contentKind = entry.getContentKind();
        if (contentKind == ClasspathEntry.K_OUTPUT) {
            outputLocation = entry.getOutputLocation();
        }
        if (entry.getEntryKind() == ClasspathEntry.K_OUTPUT) {
            outputLocation = entry.getOutputLocation();
        }
    }
    if (outputLocation == null) {
        outputLocation = depProject.getOutputLocation();
    }
    // now check the classpath entries of project for the output
    // location just calculated
    IClasspathEntry[] cpEntry = javaProject.getRawClasspath();
    for (int j = 0; j < cpEntry.length; j++) {
        IClasspathEntry entry = cpEntry[j];
        int entryKind = entry.getEntryKind();
        IPath entryPath = entry.getPath();
        if (entryKind == IClasspathEntry.CPE_LIBRARY && entryPath.equals(outputLocation)) {
            return true;
        }
    }
    return false;
}

From source file:org.eclipse.buckminster.pde.cspecgen.bundle.CSpecFromSource.java

License:Open Source License

private IPath getDefaultOutputLocation(IClasspathEntry[] classPath, IPath[] projectRootReplacement) {
    for (IClasspathEntry cpe : classPath) {
        if (cpe.getContentKind() == ClasspathEntry.K_OUTPUT)
            return asProjectRelativeFolder(cpe.getPath(), projectRootReplacement);
    }/*  w ww . ja  v  a2  s . c  om*/
    return null;
}

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

/**
 * Compare current classpath with given one to see if any different.
 * Note that the argument classpath contains its binary output.
 * @param newClasspath IClasspathEntry[]
 * @param newOutputLocation IPath//from www. j av a2s .  com
 * @param otherClasspathWithOutput IClasspathEntry[]
 * @return boolean
 */
private static boolean areClasspathsEqual(IClasspathEntry[] newClasspath, IPath newOutputLocation,
        IClasspathEntry[] otherClasspathWithOutput) {

    if (otherClasspathWithOutput == null || otherClasspathWithOutput.length == 0)
        return false;

    int length = otherClasspathWithOutput.length;
    if (length != newClasspath.length + 1)
        // output is amongst file entries (last one)
        return false;

    // compare classpath entries
    for (int i = 0; i < length - 1; i++) {
        if (!otherClasspathWithOutput[i].equals(newClasspath[i]))
            return false;
    }
    // compare binary outputs
    IClasspathEntry output = otherClasspathWithOutput[length - 1];
    if (output.getContentKind() != ClasspathEntry.K_OUTPUT || !output.getPath().equals(newOutputLocation))
        return false;
    return true;
}

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

/**
 * Reads and decode an XML classpath string. Returns a two-dimensional array, where the number of elements in the row is fixed to 2.
 * The first element is an array of raw classpath entries and the second element is an array of referenced entries that may have been stored
 * by the client earlier. See {@link IJavaProject#getReferencedClasspathEntries()} for more details. 
 * //from w  w w  .  ja v  a2 s  .c o m
 */
public IClasspathEntry[][] decodeClasspath(String xmlClasspath, Map unknownElements)
        throws IOException, ClasspathEntry.AssertionFailedException {

    ArrayList paths = new ArrayList();
    IClasspathEntry defaultOutput = null;
    StringReader reader = new StringReader(xmlClasspath);
    Element cpElement;
    try {
        DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        cpElement = parser.parse(new InputSource(reader)).getDocumentElement();
    } catch (SAXException e) {
        throw new IOException(Messages.file_badFormat);
    } catch (ParserConfigurationException e) {
        throw new IOException(Messages.file_badFormat);
    } finally {
        reader.close();
    }

    if (!cpElement.getNodeName().equalsIgnoreCase("classpath")) { //$NON-NLS-1$
        throw new IOException(Messages.file_badFormat);
    }
    NodeList list = cpElement.getElementsByTagName(ClasspathEntry.TAG_CLASSPATHENTRY);
    int length = list.getLength();

    for (int i = 0; i < length; ++i) {
        Node node = list.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            IClasspathEntry entry = ClasspathEntry.elementDecode((Element) node, this, unknownElements);
            if (entry != null) {
                if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) {
                    defaultOutput = entry; // separate output
                } else {
                    paths.add(entry);
                }
            }
        }
    }
    int pathSize = paths.size();
    IClasspathEntry[][] entries = new IClasspathEntry[2][];
    entries[0] = new IClasspathEntry[pathSize + (defaultOutput == null ? 0 : 1)];
    paths.toArray(entries[0]);
    if (defaultOutput != null)
        entries[0][pathSize] = defaultOutput; // ensure output is last item

    paths.clear();
    list = cpElement.getElementsByTagName(ClasspathEntry.TAG_REFERENCED_ENTRY);
    length = list.getLength();

    for (int i = 0; i < length; ++i) {
        Node node = list.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            IClasspathEntry entry = ClasspathEntry.elementDecode((Element) node, this, unknownElements);
            if (entry != null) {
                paths.add(entry);
            }
        }
    }
    entries[1] = new IClasspathEntry[paths.size()];
    paths.toArray(entries[1]);

    return entries;
}

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

/**
 * Returns the XML String encoding of the class path.
 *//*  ww w. j a va2 s .c  om*/
protected String encodeClasspath(IClasspathEntry[] classpath, IClasspathEntry[] referencedEntries,
        IPath outputLocation, boolean indent, Map unknownElements) throws JavaModelException {
    try {
        ByteArrayOutputStream s = new ByteArrayOutputStream();
        OutputStreamWriter writer = new OutputStreamWriter(s, "UTF8"); //$NON-NLS-1$
        XMLWriter xmlWriter = new XMLWriter(writer, this, true/*print XML version*/);

        xmlWriter.startTag(ClasspathEntry.TAG_CLASSPATH, indent);
        for (int i = 0; i < classpath.length; ++i) {
            ((ClasspathEntry) classpath[i]).elementEncode(xmlWriter, this.project.getFullPath(), indent, true,
                    unknownElements, false);
        }

        if (outputLocation != null) {
            outputLocation = outputLocation.removeFirstSegments(1);
            outputLocation = outputLocation.makeRelative();
            HashMap parameters = new HashMap();
            parameters.put(ClasspathEntry.TAG_KIND, ClasspathEntry.kindToString(ClasspathEntry.K_OUTPUT));
            parameters.put(ClasspathEntry.TAG_PATH, String.valueOf(outputLocation));
            xmlWriter.printTag(ClasspathEntry.TAG_CLASSPATHENTRY, parameters, indent, true, true);
        }

        if (referencedEntries != null) {
            for (int i = 0; i < referencedEntries.length; ++i) {
                ((ClasspathEntry) referencedEntries[i]).elementEncode(xmlWriter, this.project.getFullPath(),
                        indent, true, unknownElements, true);
            }
        }

        xmlWriter.endTag(ClasspathEntry.TAG_CLASSPATH, indent, true/*insert new line*/);
        writer.flush();
        writer.close();
        return s.toString("UTF8");//$NON-NLS-1$
    } catch (IOException e) {
        throw new JavaModelException(e, IJavaModelStatusConstants.IO_EXCEPTION);
    }
}