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

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

Introduction

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

Prototype

public static IClasspathEntry newSourceEntry(IPath path, IPath[] inclusionPatterns, IPath[] exclusionPatterns,
        IPath specificOutputLocation, IClasspathAttribute[] extraAttributes) 

Source Link

Document

Creates and returns a new classpath entry of kind CPE_SOURCE for the project's source folder identified by the given absolute workspace-relative path using the given inclusion and exclusion patterns to determine which source files are included, and the given output path to control the output location of generated files.

Usage

From source file:at.bestsolution.fxide.jdt.maven.MavenModuleTypeService.java

License:Open Source License

@Override
public Status createModule(IProject project, IResource resource) {
    IProjectDescription description = project.getWorkspace().newProjectDescription(project.getName());
    description.setNatureIds(new String[] { JavaCore.NATURE_ID, "org.eclipse.m2e.core.maven2Nature" });

    ICommand[] commands = new ICommand[2];

    {/*w ww  . j av a2  s . c  om*/
        ICommand cmd = description.newCommand();
        cmd.setBuilderName(JavaCore.BUILDER_ID);
        commands[0] = cmd;
    }

    {
        ICommand cmd = description.newCommand();
        cmd.setBuilderName("org.eclipse.m2e.core.maven2Builder");
        commands[1] = cmd;
    }

    if (resource != null) {
        // If we get a parent path we create a nested project
        try {
            if (resource.getProject().getNature("org.eclipse.m2e.core.maven2Nature") != null) {
                IFolder folder = resource.getProject().getFolder(project.getName());
                if (folder.exists()) {
                    return Status.status(State.ERROR, -1, "Folder already exists", null);
                }
                folder.create(true, true, null);

                description.setLocation(folder.getLocation());
            }
        } catch (CoreException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
            return Status.status(State.ERROR, -1, "Could not create parent relation", e1);
        }
    }

    description.setBuildSpec(commands);

    try {
        project.create(description, null);
        project.open(null);

        project.getFolder(new Path("target")).create(true, true, null);
        project.getFolder(new Path("target").append("classes")).create(true, true, null);

        project.getFolder(new Path("target")).setDerived(true, null);
        project.getFolder(new Path("target").append("classes")).setDerived(true, null);

        project.getFolder(new Path("src")).create(true, true, null);

        project.getFolder(new Path("src").append("main")).create(true, true, null);
        project.getFolder(new Path("src").append("main").append("java")).create(true, true, null);
        project.getFolder(new Path("src").append("main").append("resources")).create(true, true, null);

        project.getFolder(new Path("src").append("test")).create(true, true, null);
        project.getFolder(new Path("src").append("test").append("java")).create(true, true, null);
        project.getFolder(new Path("src").append("test").append("resources")).create(true, true, null);

        {
            IFile file = project.getFile(new Path("pom.xml"));
            try (InputStream templateStream = getClass().getResourceAsStream("template-pom.xml")) {
                String pomContent = IOUtils.readToString(templateStream, Charset.forName("UTF-8"));
                Map<String, String> map = new HashMap<>();
                map.put("groupId", project.getName());
                map.put("artifactId", project.getName());
                map.put("version", "1.0.0");

                file.create(new ByteArrayInputStream(StrSubstitutor.replace(pomContent, map).getBytes()), true,
                        null);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        IJavaProject jProject = JavaCore.create(project);
        jProject.setOutputLocation(project.getFolder(new Path("target").append("classes")).getFullPath(), null);

        List<IClasspathEntry> entries = new ArrayList<>();

        {
            IClasspathAttribute[] attributes = new IClasspathAttribute[2];
            attributes[0] = JavaCore.newClasspathAttribute("optional", "true");
            attributes[1] = JavaCore.newClasspathAttribute("maven.pomderived", "true");
            IPath path = new Path("src").append("main").append("java");
            IPath output = new Path("target").append("classes");
            IClasspathEntry sourceEntry = JavaCore.newSourceEntry(
                    project.getProject().getFullPath().append(path), null, null,
                    project.getProject().getFullPath().append(output), attributes);
            entries.add(sourceEntry);
        }

        {
            IClasspathAttribute[] attributes = new IClasspathAttribute[1];
            attributes[0] = JavaCore.newClasspathAttribute("maven.pomderived", "true");
            IPath path = new Path("src").append("main").append("resources");
            IPath output = new Path("target").append("classes");
            IPath[] exclusions = new IPath[] { new Path("**") };
            entries.add(JavaCore.newSourceEntry(project.getProject().getFullPath().append(path), null,
                    exclusions, project.getProject().getFullPath().append(output), attributes));
        }

        {
            IClasspathAttribute[] attributes = new IClasspathAttribute[2];
            attributes[0] = JavaCore.newClasspathAttribute("optional", "true");
            attributes[1] = JavaCore.newClasspathAttribute("maven.pomderived", "true");
            IPath path = new Path("src").append("test").append("java");
            IPath output = new Path("target").append("test-classes");
            IClasspathEntry sourceEntry = JavaCore.newSourceEntry(
                    project.getProject().getFullPath().append(path), null, null,
                    project.getProject().getFullPath().append(output), attributes);
            entries.add(sourceEntry);
        }

        {
            IClasspathAttribute[] attributes = new IClasspathAttribute[1];
            attributes[0] = JavaCore.newClasspathAttribute("maven.pomderived", "true");
            IPath path = new Path("src").append("test").append("resources");
            IPath output = new Path("target").append("test-classes");
            IPath[] exclusions = new IPath[] { new Path("**") };
            entries.add(JavaCore.newSourceEntry(project.getProject().getFullPath().append(path), null,
                    exclusions, project.getProject().getFullPath().append(output), attributes));
        }

        {
            IClasspathAttribute[] attributes = new IClasspathAttribute[1];
            attributes[0] = JavaCore.newClasspathAttribute("maven.pomderived", "true");

            IPath path = JavaRuntime.newDefaultJREContainerPath();
            entries.add(JavaCore.newContainerEntry(path, null, attributes, false));
        }

        {
            IClasspathAttribute[] attributes = new IClasspathAttribute[1];
            attributes[0] = JavaCore.newClasspathAttribute("maven.pomderived", "true");

            IPath path = new Path("org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER");
            entries.add(JavaCore.newContainerEntry(path, null, attributes, false));
        }

        jProject.setRawClasspath(entries.toArray(new IClasspathEntry[0]), null);
        project.getWorkspace().save(true, null);
        return Status.ok();
    } catch (CoreException ex) {
        //TODO
        ex.printStackTrace();
        return Status.status(State.ERROR, -1, "Failed to create project", ex);
    }
}

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);/* ww  w .  j av a  2  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.google.gdt.eclipse.appengine.rpc.wizards.helpers.RpcServiceLayerCreator.java

License:Open Source License

private void addAptSourceFolder(IProject project, IProgressMonitor monitor) throws JavaModelException {
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] entries = javaProject.getRawClasspath();

    // add .apt_generated to classpath
    IClasspathAttribute[] attributes = new IClasspathAttribute[] {
            JavaCore.newClasspathAttribute("optional", "true") }; //$NON-NLS-N$
    IFolder aptFolder = project.getFolder(APT_FOLDER);
    IClasspathEntry entry = JavaCore.newSourceEntry(aptFolder.getFullPath(), ClasspathEntry.INCLUDE_ALL,
            ClasspathEntry.EXCLUDE_NONE, null, attributes);
    entries = CodegenUtils.addEntryToClasspath(entries, entry);

    javaProject.setRawClasspath(entries, new SubProgressMonitor(monitor, 10));
}

From source file:com.liferay.ide.gradle.core.LiferayGradleProject.java

License:Open Source License

private IFolder createResorcesFolder(IProject project) {
    try {//from   w ww  . j  av a 2  s.co m
        IJavaProject javaProject = JavaCore.create(project);

        List<IClasspathEntry> existingRawClasspath;

        existingRawClasspath = Arrays.asList(javaProject.getRawClasspath());

        List<IClasspathEntry> newRawClasspath = new ArrayList<IClasspathEntry>();

        IClasspathAttribute[] attributes = new IClasspathAttribute[] {
                JavaCore.newClasspathAttribute("FROM_GRADLE_MODEL", "true") }; //$NON-NLS-1$ //$NON-NLS-2$

        IClasspathEntry resourcesEntry = JavaCore.newSourceEntry(
                project.getFullPath().append("src/main/resources"), new IPath[0], new IPath[0], null,
                attributes);

        for (IClasspathEntry entry : existingRawClasspath) {
            newRawClasspath.add(entry);
        }

        if (!existingRawClasspath.contains(resourcesEntry)) {
            newRawClasspath.add(resourcesEntry);
        }

        javaProject.setRawClasspath(newRawClasspath.toArray(new IClasspathEntry[0]), new NullProgressMonitor());

        project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());

        IFolder[] sourceFolders = getSourceFolders();

        for (IFolder folder : sourceFolders) {
            if (folder.getName().equals("resources")) {
                return folder;
            }
        }
    } catch (CoreException e) {
        GradleCore.logError(e);
    }

    return null;
}

From source file:com.liferay.ide.project.core.facet.ExtPluginFacetInstall.java

License:Open Source License

@Override
public void execute(IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor)
        throws CoreException {
    super.execute(project, fv, config, monitor);

    IDataModel model = (IDataModel) config;
    IDataModel masterModel = (IDataModel) model.getProperty(FacetInstallDataModelProvider.MASTER_PROJECT_DM);

    if (masterModel != null && masterModel.getBooleanProperty(CREATE_PROJECT_OPERATION)) {
        /*/*from   www  .  jav a  2s  .c  o  m*/
        // get the template zip for portlets and extract into the project
        SDK sdk = getSDK();
                
        String extName = this.masterModel.getStringProperty( EXT_NAME );
                
        // FIX IDE-450
        if( extName.endsWith( ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX ) )
        {
        extName = extName.substring( 0, extName.indexOf( ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX ) );
        }
        // END FIX IDE-450
                
        String displayName = this.masterModel.getStringProperty( DISPLAY_NAME );
                
        Map<String, String> appServerProperties = ServerUtil.configureAppServerProperties( project );
                
        IPath newExtPath = sdk.createNewExtProject( extName, displayName, appServerProperties );
                
        IPath tempInstallPath = newExtPath.append( extName + ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX );
                
        processNewFiles( tempInstallPath );
        // cleanup ext temp files
        FileUtil.deleteDir( installPath.toFile(), true );
        */

        // IDE-1122 SDK creating project has been moved to Class NewPluginProjectWizard
        String extName = this.masterModel.getStringProperty(EXT_NAME);

        IPath projectTempPath = (IPath) masterModel.getProperty(PROJECT_TEMP_PATH);

        processNewFiles(projectTempPath.append(extName + ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX));

        FileUtil.deleteDir(projectTempPath.toFile(), true);
        // End IDE-1122

        try {
            this.project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
        } catch (Exception e) {
            ProjectCore.logError(e);
        }

        IFolder webappRoot = this.project.getFolder(ISDKConstants.DEFAULT_DOCROOT_FOLDER);

        deleteFolder(webappRoot.getFolder("WEB-INF/src")); //$NON-NLS-1$
        deleteFolder(webappRoot.getFolder("WEB-INF/classes")); //$NON-NLS-1$
    }

    if (shouldSetupExtClasspath()) {
        IJavaProject javaProject = JavaCore.create(project);

        List<IClasspathEntry> existingRawClasspath = Arrays.asList(javaProject.getRawClasspath());

        List<IClasspathEntry> newRawClasspath = new ArrayList<IClasspathEntry>();

        // first lets add all new source folders
        for (int i = 0; i < IPluginFacetConstants.EXT_PLUGIN_SDK_SOURCE_FOLDERS.length; i++) {
            IPath sourcePath = this.project.getFolder(IPluginFacetConstants.EXT_PLUGIN_SDK_SOURCE_FOLDERS[i])
                    .getFullPath();

            IPath outputPath = this.project.getFolder(IPluginFacetConstants.EXT_PLUGIN_SDK_OUTPUT_FOLDERS[i])
                    .getFullPath();

            IClasspathAttribute[] attributes = new IClasspathAttribute[] {
                    JavaCore.newClasspathAttribute("owner.project.facets", "liferay.ext") }; //$NON-NLS-1$ //$NON-NLS-2$

            IClasspathEntry sourceEntry = JavaCore.newSourceEntry(sourcePath, new IPath[0], new IPath[0],
                    outputPath, attributes);

            newRawClasspath.add(sourceEntry);
        }

        // next add all previous classpath entries except for source folders
        for (IClasspathEntry entry : existingRawClasspath) {
            if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) {
                newRawClasspath.add(entry);
            }
        }

        javaProject.setRawClasspath(newRawClasspath.toArray(new IClasspathEntry[0]),
                this.project.getFolder(IPluginFacetConstants.EXT_PLUGIN_DEFAULT_OUTPUT_FOLDER).getFullPath(),
                null);

        ProjectUtil.fixExtProjectSrcFolderLinks(this.project);
        // fixTilesDefExtFile();
    }

    //IDE-1239 need to make sure and delete docroot/WEB-INF/ext-web/docroot/WEB-INF/lib
    removeUnneededFolders(this.project);
}

From source file:com.liferay.ide.project.core.modules.templates.AbstractLiferayComponentTemplate.java

License:Open Source License

protected void createResorcesFolder(IProject project) throws CoreException {
    IFolder resourceFolder = liferayProject.getSourceFolder("resources");

    if (resourceFolder == null || !resourceFolder.exists()) {
        IJavaProject javaProject = JavaCore.create(project);

        List<IClasspathEntry> existingRawClasspath = Arrays.asList(javaProject.getRawClasspath());
        List<IClasspathEntry> newRawClasspath = new ArrayList<IClasspathEntry>();

        IClasspathAttribute[] attributes = new IClasspathAttribute[] {
                JavaCore.newClasspathAttribute("FROM_GRADLE_MODEL", "true") }; //$NON-NLS-1$ //$NON-NLS-2$

        IClasspathEntry resourcesEntry = JavaCore.newSourceEntry(
                project.getFullPath().append("src/main/resources"), new IPath[0], new IPath[0], null,
                attributes);//w ww.j  a va  2  s  . c o m

        newRawClasspath.add(resourcesEntry);

        for (IClasspathEntry entry : existingRawClasspath) {
            newRawClasspath.add(entry);
        }

        javaProject.setRawClasspath(newRawClasspath.toArray(new IClasspathEntry[0]), new NullProgressMonitor());

        project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    }
}

From source file:com.liferay.ide.project.core.util.ProjectUtil.java

License:Open Source License

private static void fixExtProjectClasspathEntries(IProject project) {
    try {/*  ww  w.j  av  a 2 s.c o  m*/
        boolean fixedAttr = false;

        IJavaProject javaProject = JavaCore.create(project);

        List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();

        IClasspathEntry[] entries = javaProject.getRawClasspath();

        for (IClasspathEntry entry : entries) {
            IClasspathEntry newEntry = null;

            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                List<IClasspathAttribute> newAttrs = new ArrayList<IClasspathAttribute>();

                IClasspathAttribute[] attrs = entry.getExtraAttributes();

                if (!CoreUtil.isNullOrEmpty(attrs)) {
                    for (IClasspathAttribute attr : attrs) {
                        IClasspathAttribute newAttr = null;

                        if ("owner.project.facets".equals(attr.getName()) && //$NON-NLS-1$
                                "liferay.plugin".equals(attr.getValue())) //$NON-NLS-1$
                        {
                            newAttr = JavaCore.newClasspathAttribute(attr.getName(), "liferay.ext"); //$NON-NLS-1$
                            fixedAttr = true;
                        } else {
                            newAttr = attr;
                        }

                        newAttrs.add(newAttr);
                    }

                    newEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(),
                            entry.getExclusionPatterns(), entry.getOutputLocation(),
                            newAttrs.toArray(new IClasspathAttribute[0]));
                }
            }

            if (newEntry == null) {
                newEntry = entry;
            }

            newEntries.add(newEntry);
        }

        if (fixedAttr) {
            IProgressMonitor monitor = new NullProgressMonitor();

            javaProject.setRawClasspath(newEntries.toArray(new IClasspathEntry[0]), monitor);

            try {
                javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
            } catch (Exception e) {
                ProjectCore.logError(e);
            }
        }

        fixExtProjectSrcFolderLinks(project);
    } catch (Exception ex) {
        ProjectCore.logError("Exception trying to fix Ext project classpath entries.", ex); //$NON-NLS-1$
    }
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockProject.java

License:Open Source License

private void updatePathElement(List<IClasspathEntry> ents, Element xml) {
    IClasspathEntry oent = null;//from  w w  w.j  a  v  a  2 s  .c om
    int id = IvyXml.getAttrInt(xml, "ID", 0);
    if (id != 0) {
        for (IClasspathEntry ent : ents) {
            if (ent.hashCode() == id) {
                oent = ent;
                break;
            }
        }
    }

    BedrockPlugin.logD("UPDATE PATH ELEMENT " + oent + " " + IvyXml.convertXmlToString(xml));

    if (IvyXml.getAttrString(xml, "TYPE").equals("LIBRARY")) {
        if (IvyXml.getAttrBool(xml, "DELETE")) {
            ents.remove(oent);
        } else if (IvyXml.getAttrBool(xml, "MODIFIED") || IvyXml.getAttrBool(xml, "NEW")) {
            String f = IvyXml.getTextElement(xml, "BINARY");
            IPath bin = (f == null ? null : Path.fromOSString(f));
            f = IvyXml.getTextElement(xml, "SOURCE");
            IPath src = (f == null ? null : Path.fromOSString(f));
            boolean optfg = IvyXml.getAttrBool(xml, "OPTIONAL");
            boolean export = IvyXml.getAttrBool(xml, "EXPORTED");
            IAccessRule[] rls = null;
            URL docu = null;
            String doc = IvyXml.getTextElement(xml, "JAVADOC");
            if (doc != null) {
                try {
                    docu = new URL(doc);
                } catch (MalformedURLException e) {
                }
                if (docu == null) {
                    try {
                        docu = new URL("file://" + doc);
                    } catch (MalformedURLException e) {
                    }
                }
            }
            if (oent != null) {
                rls = oent.getAccessRules();
            }

            IClasspathAttribute[] xatts = null;
            List<IClasspathAttribute> els = new ArrayList<IClasspathAttribute>();
            if (optfg)
                els.add(JavaCore.newClasspathAttribute(IClasspathAttribute.OPTIONAL, "true"));
            if (docu != null) {
                els.add(JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
                        docu.toString()));
            }
            if (!els.isEmpty()) {
                xatts = new IClasspathAttribute[els.size()];
                xatts = els.toArray(xatts);
            }

            IClasspathEntry nent = null;
            if (bin != null)
                nent = JavaCore.newLibraryEntry(bin, src, null, rls, xatts, export);
            else
                nent = JavaCore.newSourceEntry(src, null, null, null, xatts);

            if (IvyXml.getAttrBool(xml, "MODIFIED") && oent != null) {
                int idx = ents.indexOf(oent);
                ents.set(idx, nent);
            } else {
                ents.add(nent);
            }
        }
    }
}

From source file:io.sarl.eclipse.natures.SARLProjectConfigurator.java

License:Apache License

private static List<CPListElement> buildClassPathEntries(IJavaProject project, IFolder[] sourcePaths,
        IFolder[] generationPaths) {/*from   w  ww. j a  v a2s . c o  m*/
    final List<CPListElement> list = new ArrayList<>();

    for (final IFolder sourcePath : sourcePaths) {
        if (sourcePath != null) {
            list.add(new CPListElement(project, IClasspathEntry.CPE_SOURCE,
                    sourcePath.getFullPath().makeAbsolute(), sourcePath));
        }
    }

    for (final IFolder sourcePath : generationPaths) {
        if (sourcePath != null) {
            final IClasspathAttribute attr = JavaCore.newClasspathAttribute(
                    IClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS, Boolean.TRUE.toString());
            final IClasspathEntry entry = JavaCore.newSourceEntry(sourcePath.getFullPath().makeAbsolute(),
                    ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null /*output location*/,
                    new IClasspathAttribute[] { attr });
            list.add(CPListElement.create(entry, false, project));
        }
    }

    for (final IClasspathEntry current : PreferenceConstants.getDefaultJRELibrary()) {
        if (current != null) {
            list.add(CPListElement.create(current, true, project));
            break;
        }
    }

    list.add(CPListElement.create(JavaCore.newContainerEntry(SARLClasspathContainerInitializer.CONTAINER_ID),
            true, project));

    return list;
}

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

License:Apache License

/**
 * Decodes one XML element with the XML stream.
 *
 * @param element/*from ww w . j  av  a  2s  . co 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;
}