Example usage for org.eclipse.jdt.core JavaCore newProjectEntry

List of usage examples for org.eclipse.jdt.core JavaCore newProjectEntry

Introduction

In this page you can find the example usage for org.eclipse.jdt.core JavaCore newProjectEntry.

Prototype

public static IClasspathEntry newProjectEntry(IPath path, IAccessRule[] accessRules, boolean combineAccessRules,
        IClasspathAttribute[] extraAttributes, boolean isExported) 

Source Link

Document

Creates and returns a new classpath entry of kind CPE_PROJECT for the project identified by the given absolute path.

Usage

From source file:at.bestsolution.javafx.ide.jdt.internal.jdt.CPListElement.java

License:Open Source License

private IClasspathEntry newClasspathEntry() {

    IClasspathAttribute[] extraAttributes = getClasspathAttributes();
    switch (fEntryKind) {
    case IClasspathEntry.CPE_SOURCE:
        IPath[] inclusionPattern = (IPath[]) getAttribute(INCLUSION);
        IPath[] exclusionPattern = (IPath[]) getAttribute(EXCLUSION);
        IPath outputLocation = (IPath) getAttribute(OUTPUT);
        return JavaCore.newSourceEntry(fPath, inclusionPattern, exclusionPattern, outputLocation,
                extraAttributes);/*from   w w w.j  a v a2 s  .  c o m*/
    case IClasspathEntry.CPE_LIBRARY: {
        IPath attach = (IPath) getAttribute(SOURCEATTACHMENT);
        IAccessRule[] accesRules = (IAccessRule[]) getAttribute(ACCESSRULES);
        return JavaCore.newLibraryEntry(fPath, attach, null, accesRules, extraAttributes, isExported());
    }
    case IClasspathEntry.CPE_PROJECT: {
        IAccessRule[] accesRules = (IAccessRule[]) getAttribute(ACCESSRULES);
        boolean combineAccessRules = ((Boolean) getAttribute(COMBINE_ACCESSRULES)).booleanValue();
        return JavaCore.newProjectEntry(fPath, accesRules, combineAccessRules, extraAttributes, isExported());
    }
    case IClasspathEntry.CPE_CONTAINER: {
        IAccessRule[] accesRules = (IAccessRule[]) getAttribute(ACCESSRULES);
        return JavaCore.newContainerEntry(fPath, accesRules, extraAttributes, isExported());
    }
    case IClasspathEntry.CPE_VARIABLE: {
        IPath varAttach = (IPath) getAttribute(SOURCEATTACHMENT);
        IAccessRule[] accesRules = (IAccessRule[]) getAttribute(ACCESSRULES);
        return JavaCore.newVariableEntry(fPath, varAttach, null, accesRules, extraAttributes, isExported());
    }
    default:
        return null;
    }
}

From source file:com.android.ide.eclipse.adt.internal.wizards.newproject.NewProjectCreator.java

License:Open Source License

/**
 * Creates the actual project, sets its nature and adds the required folders
 * and files to it. This is run asynchronously in a different thread.
 *
 * @param monitor An existing monitor./*from w  w w .  ja v a  2 s. co m*/
 * @param project The project to create.
 * @param description A description of the project.
 * @param parameters Template parameters.
 * @param dictionary String definition.
 * @param isAndroidProject true if the project is to be set up as a full Android project; false
 * for a plain Java project.
 * @return The project newly created
 * @throws StreamException
 */
private IProject createEclipseProject(@NonNull IProgressMonitor monitor, @NonNull IProject project,
        @NonNull IProjectDescription description, @NonNull Map<String, Object> parameters,
        @Nullable Map<String, String> dictionary, @Nullable ProjectPopulator projectPopulator,
        boolean isAndroidProject) throws CoreException, IOException, StreamException {

    // get the project target
    IAndroidTarget target = (IAndroidTarget) parameters.get(PARAM_SDK_TARGET);
    boolean legacy = isAndroidProject && target.getVersion().getApiLevel() < 4;

    // Create project and open it
    project.create(description, new SubProgressMonitor(monitor, 10));
    if (monitor.isCanceled())
        throw new OperationCanceledException();

    project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 10));

    // Add the Java and android nature to the project
    AndroidNature.setupProjectNatures(project, monitor, isAndroidProject);

    // Create folders in the project if they don't already exist
    addDefaultDirectories(project, AdtConstants.WS_ROOT, DEFAULT_DIRECTORIES, monitor);
    String[] sourceFolders;
    if (isAndroidProject) {
        sourceFolders = new String[] { (String) parameters.get(PARAM_SRC_FOLDER), GEN_SRC_DIRECTORY };
    } else {
        sourceFolders = new String[] { (String) parameters.get(PARAM_SRC_FOLDER) };
    }
    addDefaultDirectories(project, AdtConstants.WS_ROOT, sourceFolders, monitor);

    // Create the resource folders in the project if they don't already exist.
    if (legacy) {
        addDefaultDirectories(project, RES_DIRECTORY, RES_DIRECTORIES, monitor);
    } else {
        addDefaultDirectories(project, RES_DIRECTORY, RES_DENSITY_ENABLED_DIRECTORIES, monitor);
    }

    if (projectPopulator != null) {
        try {
            projectPopulator.populate(project);
        } catch (InvocationTargetException ite) {
            AdtPlugin.log(ite, null);
        }
    }

    // Setup class path: mark folders as source folders
    IJavaProject javaProject = JavaCore.create(project);
    setupSourceFolders(javaProject, sourceFolders, monitor);

    if (((Boolean) parameters.get(PARAM_IS_NEW_PROJECT)).booleanValue()) {
        // Create files in the project if they don't already exist
        addManifest(project, parameters, dictionary, monitor);

        // add the default app icon
        addIcon(project, legacy, monitor);

        // Create the default package components
        addSampleCode(project, sourceFolders[0], parameters, dictionary, monitor);

        // add the string definition file if needed
        if (dictionary != null && dictionary.size() > 0) {
            addStringDictionaryFile(project, dictionary, monitor);
        }

        // add the default proguard config
        File libFolder = new File((String) parameters.get(PARAM_SDK_TOOLS_DIR), SdkConstants.FD_LIB);
        addLocalFile(project, new File(libFolder, SdkConstants.FN_PROJECT_PROGUARD_FILE),
                // Write ProGuard config files with the extension .pro which
                // is what is used in the ProGuard documentation and samples
                SdkConstants.FN_PROJECT_PROGUARD_FILE, monitor);

        // Set output location
        javaProject.setOutputLocation(project.getFolder(BIN_CLASSES_DIRECTORY).getFullPath(), monitor);
    }

    File sampleDir = (File) parameters.get(PARAM_SAMPLE_LOCATION);
    if (sampleDir != null) {
        // Copy project
        copySampleCode(project, sampleDir, parameters, dictionary, monitor);
    }

    // Create the reference to the target project
    if (parameters.containsKey(PARAM_REFERENCE_PROJECT)) {
        IProject refProject = (IProject) parameters.get(PARAM_REFERENCE_PROJECT);
        if (refProject != null) {
            IProjectDescription desc = project.getDescription();

            // Add out reference to the existing project reference.
            // We just created a project with no references so we don't need to expand
            // the currently-empty current list.
            desc.setReferencedProjects(new IProject[] { refProject });

            project.setDescription(desc, IResource.KEEP_HISTORY, new SubProgressMonitor(monitor, 10));

            IClasspathEntry entry = JavaCore.newProjectEntry(refProject.getFullPath(), //path
                    new IAccessRule[0], //accessRules
                    false, //combineAccessRules
                    new IClasspathAttribute[0], //extraAttributes
                    false //isExported

            );
            ProjectHelper.addEntryToClasspath(javaProject, entry);
        }
    }

    if (isAndroidProject) {
        Sdk.getCurrent().initProject(project, target);
    }

    // Fix the project to make sure all properties are as expected.
    // Necessary for existing projects and good for new ones to.
    ProjectHelper.fixProject(project);

    Boolean isLibraryProject = (Boolean) parameters.get(PARAM_IS_LIBRARY);
    if (isLibraryProject != null && isLibraryProject.booleanValue() && Sdk.getCurrent() != null
            && project.isOpen()) {
        ProjectState state = Sdk.getProjectState(project);
        if (state != null) {
            // make a working copy of the properties
            ProjectPropertiesWorkingCopy properties = state.getProperties().makeWorkingCopy();

            properties.setProperty(PROPERTY_LIBRARY, Boolean.TRUE.toString());
            try {
                properties.save();
                IResource projectProp = project.findMember(FN_PROJECT_PROPERTIES);
                if (projectProp != null) {
                    projectProp.refreshLocal(DEPTH_ZERO, new NullProgressMonitor());
                }
            } catch (Exception e) {
                String msg = String.format("Failed to save %1$s for project %2$s",
                        SdkConstants.FN_PROJECT_PROPERTIES, project.getName());
                AdtPlugin.log(e, msg);
            }
        }
    }

    return project;
}

From source file:com.android.ide.eclipse.auidt.internal.wizards.newproject.NewProjectCreator.java

License:Open Source License

/**
 * Creates the actual project, sets its nature and adds the required folders
 * and files to it. This is run asynchronously in a different thread.
 *
 * @param monitor An existing monitor./*from  w w  w .  java 2s  . c om*/
 * @param project The project to create.
 * @param description A description of the project.
 * @param parameters Template parameters.
 * @param dictionary String definition.
 * @return The project newly created
 * @throws StreamException
 */
private IProject createEclipseProject(IProgressMonitor monitor, IProject project,
        IProjectDescription description, Map<String, Object> parameters, Map<String, String> dictionary,
        ProjectPopulator projectPopulator) throws CoreException, IOException, StreamException {

    // get the project target
    IAndroidTarget target = (IAndroidTarget) parameters.get(PARAM_SDK_TARGET);
    boolean legacy = target.getVersion().getApiLevel() < 4;

    // Create project and open it
    project.create(description, new SubProgressMonitor(monitor, 10));
    if (monitor.isCanceled())
        throw new OperationCanceledException();

    project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 10));

    // Add the Java and android nature to the project
    AndroidNature.setupProjectNatures(project, monitor);

    // Create folders in the project if they don't already exist
    addDefaultDirectories(project, AdtConstants.WS_ROOT, DEFAULT_DIRECTORIES, monitor);
    String[] sourceFolders = new String[] { (String) parameters.get(PARAM_SRC_FOLDER), GEN_SRC_DIRECTORY };
    addDefaultDirectories(project, AdtConstants.WS_ROOT, sourceFolders, monitor);

    // Create the resource folders in the project if they don't already exist.
    if (legacy) {
        addDefaultDirectories(project, RES_DIRECTORY, RES_DIRECTORIES, monitor);
    } else {
        addDefaultDirectories(project, RES_DIRECTORY, RES_DENSITY_ENABLED_DIRECTORIES, monitor);
    }

    if (projectPopulator != null) {
        try {
            projectPopulator.populate(project);
        } catch (InvocationTargetException ite) {
            AdtPlugin.log(ite, null);
        }
    }

    // Setup class path: mark folders as source folders
    IJavaProject javaProject = JavaCore.create(project);
    setupSourceFolders(javaProject, sourceFolders, monitor);

    if (((Boolean) parameters.get(PARAM_IS_NEW_PROJECT)).booleanValue()) {
        // Create files in the project if they don't already exist
        addManifest(project, parameters, dictionary, monitor);

        // add the default app icon
        addIcon(project, legacy, monitor);

        // Create the default package components
        addSampleCode(project, sourceFolders[0], parameters, dictionary, monitor);

        // add the string definition file if needed
        if (dictionary.size() > 0) {
            addStringDictionaryFile(project, dictionary, monitor);
        }

        // add the default proguard config
        File libFolder = new File((String) parameters.get(PARAM_SDK_TOOLS_DIR), SdkConstants.FD_LIB);
        addLocalFile(project, new File(libFolder, SdkConstants.FN_PROJECT_PROGUARD_FILE),
                // Write ProGuard config files with the extension .pro which
                // is what is used in the ProGuard documentation and samples
                SdkConstants.FN_PROJECT_PROGUARD_FILE, monitor);

        // Set output location
        javaProject.setOutputLocation(project.getFolder(BIN_CLASSES_DIRECTORY).getFullPath(), monitor);
    }

    File sampleDir = (File) parameters.get(PARAM_SAMPLE_LOCATION);
    if (sampleDir != null) {
        // Copy project
        copySampleCode(project, sampleDir, parameters, dictionary, monitor);
    }

    // Create the reference to the target project
    if (parameters.containsKey(PARAM_REFERENCE_PROJECT)) {
        IProject refProject = (IProject) parameters.get(PARAM_REFERENCE_PROJECT);
        if (refProject != null) {
            IProjectDescription desc = project.getDescription();

            // Add out reference to the existing project reference.
            // We just created a project with no references so we don't need to expand
            // the currently-empty current list.
            desc.setReferencedProjects(new IProject[] { refProject });

            project.setDescription(desc, IResource.KEEP_HISTORY, new SubProgressMonitor(monitor, 10));

            IClasspathEntry entry = JavaCore.newProjectEntry(refProject.getFullPath(), //path
                    new IAccessRule[0], //accessRules
                    false, //combineAccessRules
                    new IClasspathAttribute[0], //extraAttributes
                    false //isExported

            );
            ProjectHelper.addEntryToClasspath(javaProject, entry);
        }
    }

    Sdk.getCurrent().initProject(project, target);

    // Fix the project to make sure all properties are as expected.
    // Necessary for existing projects and good for new ones to.
    ProjectHelper.fixProject(project);

    Boolean isLibraryProject = (Boolean) parameters.get(PARAM_IS_LIBRARY);
    if (isLibraryProject != null && isLibraryProject.booleanValue() && Sdk.getCurrent() != null
            && project.isOpen()) {
        ProjectState state = Sdk.getProjectState(project);
        if (state != null) {
            // make a working copy of the properties
            ProjectPropertiesWorkingCopy properties = state.getProperties().makeWorkingCopy();

            properties.setProperty(PROPERTY_LIBRARY, Boolean.TRUE.toString());
            try {
                properties.save();
                IResource projectProp = project.findMember(FN_PROJECT_PROPERTIES);
                if (projectProp != null) {
                    projectProp.refreshLocal(DEPTH_ZERO, new NullProgressMonitor());
                }
            } catch (Exception e) {
                String msg = String.format("Failed to save %1$s for project %2$s",
                        SdkConstants.FN_PROJECT_PROPERTIES, project.getName());
                AdtPlugin.log(e, msg);
            }
        }
    }

    return project;
}

From source file:com.google.gwt.eclipse.core.runtime.GWTRuntimeTest.java

License:Open Source License

/**
 * Tests that we find an {@link com.google.gdt.eclipse.core.sdk.Sdk} on the
 * gwt-user project./*from  w w w.  j  a va  2 s .  c om*/
 *
 * @throws Exception
 */
public void testFindSdkFor_GwtUserProject() throws Exception {
    GwtRuntimeTestUtilities.importGwtSourceProjects();
    try {
        IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
        IJavaProject javaProject = javaModel.getJavaProject("gwt-user");
        GWTRuntime sdk = GWTRuntime.findSdkFor(javaProject);
        IClasspathEntry gwtUserEntry = JavaCore.newSourceEntry(
                javaModel.getJavaProject("gwt-user").getPath().append("core/src"),
                new IPath[] { new Path("**/super/**") });
        /*
         * NOTE: Passing null for the IClasspathAttribute array tickles a bug in
         * eclipse 3.3.
         */
        IClasspathEntry gwtDevEntry = JavaCore.newProjectEntry(javaModel.getJavaProject("gwt-dev").getPath(),
                null, false, new IClasspathAttribute[0] /* */, false);
        IClasspathEntry[] expected = new IClasspathEntry[] { gwtUserEntry, gwtDevEntry };
        assertEquals(expected, sdk.getClasspathEntries());
    } finally {
        GwtRuntimeTestUtilities.removeGwtSourceProjects();
    }
}

From source file:com.siteview.mde.internal.core.MDEClasspathContainer.java

License:Open Source License

protected void addProjectEntry(IProject project, Rule[] rules, ArrayList entries) throws CoreException {
    if (project.hasNature(JavaCore.NATURE_ID)) {
        IClasspathEntry entry = null;/*from   w  ww .  j  a v a 2  s .com*/
        if (rules != null) {
            IAccessRule[] accessRules = getAccessRules(rules);
            entry = JavaCore.newProjectEntry(project.getFullPath(), accessRules, true,
                    new IClasspathAttribute[0], false);
        } else {
            entry = JavaCore.newProjectEntry(project.getFullPath());
        }
        if (!entries.contains(entry))
            entries.add(entry);
    }
}

From source file:de.plugins.eclipse.depclipse.testcommons.TestingEnvironment.java

License:Open Source License

/** Adds a project to the classpath of a project.
 *///from w ww. jav a  2 s .c  o m
public void addRequiredProject(IPath projectPath, IPath requiredProjectPath, IPath[] accessibleFiles,
        IPath[] nonAccessibleFiles, boolean isExported) throws JavaModelException {
    checkAssertion("required project must not be in project", !projectPath.isPrefixOf(requiredProjectPath)); //$NON-NLS-1$
    IAccessRule[] accessRules = ClasspathEntry.getAccessRules(accessibleFiles, nonAccessibleFiles);
    addEntry(projectPath, JavaCore.newProjectEntry(requiredProjectPath, accessRules, true,
            new IClasspathAttribute[0], isExported));
}

From source file:de.plugins.eclipse.depclipse.testcommons.TestingEnvironment.java

License:Open Source License

public void addRequiredProject(IPath projectPath, IPath requiredProjectPath, IPath rule, int ruleKind)
        throws JavaModelException {
    checkAssertion("required project must not be in project", !projectPath.isPrefixOf(requiredProjectPath)); //$NON-NLS-1$
    IAccessRule accessRule = JavaCore.newAccessRule(rule, ruleKind);
    addEntry(projectPath, JavaCore.newProjectEntry(requiredProjectPath, new IAccessRule[] { accessRule }, true,
            new IClasspathAttribute[0], false));
}

From source file:de.plugins.eclipse.depclipse.testcommons.TestingEnvironment.java

License:Open Source License

public void addRequiredProject(IPath projectPath, IPath requiredProjectPath, boolean isOptional)
        throws JavaModelException {
    checkAssertion("required project must not be in project", !projectPath.isPrefixOf(requiredProjectPath)); //$NON-NLS-1$
    IClasspathAttribute[] attributes = isOptional
            ? new IClasspathAttribute[] { JavaCore.newClasspathAttribute(IClasspathAttribute.OPTIONAL, "true") }
            : new IClasspathAttribute[0];
    addEntry(projectPath, JavaCore.newProjectEntry(requiredProjectPath, null, true, attributes, false));
}

From source file:fede.workspace.eclipse.java.JavaProjectManager.java

License:Apache License

/**
 * Creates a new non exported Project classpath entry.
 * /*from   w ww.  j  av  a  2 s.c  o m*/
 * @param fullpath
 *            the fullpath
 * 
 * @return the i classpath entry
 * 
 * @throws CoreException
 *             the core exception
 */
public static IClasspathEntry newProjectEntry(IPath fullpath) throws CoreException {
    return JavaCore.newProjectEntry(fullpath, DEFAULT_ACCESS_RULE, true, DEFAULT_PATH_ATTRIBUTES, false);
}

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

License:Apache License

/**
 * Decodes one XML element with the XML stream.
 *
 * @param element//w w w  .j a v a2  s.  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;
}