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

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

Introduction

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

Prototype

IClasspathAttribute[] NO_EXTRA_ATTRIBUTES

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

Click Source Link

Usage

From source file:com.google.gdt.eclipse.managedapis.impl.ClasspathEntryPrototype.java

License:Open Source License

/**
 * Produce a ClasspathEntry from this prototype.
 * //from   www .  jav a2 s .  co  m
 * @param projectRoot The project root, used to determine relative paths.
 * @return The classpath entry or null if no class archive is defined.
 */
public IClasspathEntry createClasspathEntry(IPath projectRoot) {
    IPath libRelativePath = (classArchive == null) ? null
            : makeRelative(classArchive.getFullPath(), projectRoot);
    IPath srcPath = (sourceArchive == null) ? null : makeRelative(sourceArchive.getFullPath(), projectRoot);
    IPath javadocPath = (javadocArchive == null) ? null
            : makeRelative(javadocArchive.getFullPath(), projectRoot);

    IClasspathAttribute[] extraAttributes = (null == javadocPath) ? ClasspathEntry.NO_EXTRA_ATTRIBUTES
            : new IClasspathAttribute[] {
                    new ClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
                            "jar:platform:/resource" + javadocPath.toString() + "!/") };

    // create a new CPE_LIBRARY type of cp entry with an attached source
    // archive if it exists
    return (libRelativePath == null) ? null
            : JavaCore.newLibraryEntry(libRelativePath, srcPath, srcPath == null ? null : new Path("/"),
                    ClasspathEntry.NO_ACCESS_RULES, extraAttributes, false);
}

From source file:com.windowtester.codegen.util.BuildPathUtil.java

License:Open Source License

public static IClasspathEntry getEntry(String bundleName, String jarName, boolean hasJavadoc) {

    // check if bundle is a workspace project and if it is then use the project entry 
    // from workspace or otherwise resolve path from the bundle location
    IProject wsJavaProject = ResourcesPlugin.getWorkspace().getRoot().getProject(bundleName);
    if (wsJavaProject.exists())
        return JavaCore.newProjectEntry(wsJavaProject.getFullPath());

    // get the bundle
    Bundle bundle = Platform.getBundle(bundleName);
    if (bundle == null)
        return null;
    String path;//from w  ww  . j av  a2 s. c o m
    try {
        // get the bundle location
        URL location = bundle.getEntry(jarName);
        // there is no jar in bundle location
        URL jarLocation = null;
        if (location == null) {
            // assume bundle location is jared archive
            location = bundle.getEntry("/");
            jarLocation = Platform.resolve(location);
            // test if bundle is jared
            if (!jarLocation.getFile().endsWith(".jar!/")) {
                // return null if it is not jar
                return null;
            } else {
                // remove jar: protocol from URL at this step
                jarLocation = new URL(jarLocation.getPath());
            }
        } else {
            jarLocation = Platform.resolve(location);
        }
        // normalize path
        path = jarLocation.getFile();
        if (path.endsWith(".jar!/")) {
            path = path.substring(0, path.length() - 2);
        }
    } catch (IOException e) {
        Logger.log(e);
        return null;
    }

    /* $codepro.preprocessor.if version < 3.1 $ 
    return JavaCore.newLibraryEntry(new Path(path), null, null);
            
    $codepro.preprocessor.elseif version >= 3.1 $ */
    org.eclipse.jdt.core.IClasspathAttribute[] attributes = ClasspathEntry.NO_EXTRA_ATTRIBUTES;
    if (hasJavadoc) {
        Bundle docBundle = Platform.getBundle(WINTEST_JAVADOC_PLUGIN_ID);
        if (docBundle != null) {
            URL location = bundle.getEntry(WINTEST_JAVADOC_RELATIVE_PATH);
            if (location != null) {
                attributes = new org.eclipse.jdt.core.IClasspathAttribute[] { JavaCore.newClasspathAttribute(
                        org.eclipse.jdt.core.IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
                        location.toExternalForm()) };
            }
        }
    }
    return JavaCore.newLibraryEntry(new Path(path), null, null, ClasspathEntry.NO_ACCESS_RULES, attributes,
            false);

    /* $codepro.preprocessor.endif $ */
}

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  va2 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;
}

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

License:Apache License

@SuppressWarnings("checkstyle:innerassignment")
private static IClasspathAttribute[] decodeExtraAttributes(NodeList attributes) {
    if (attributes == null) {
        return ClasspathEntry.NO_EXTRA_ATTRIBUTES;
    }//  ww  w .j a v  a  2  s . co m
    final int length = attributes.getLength();
    if (length == 0) {
        return ClasspathEntry.NO_EXTRA_ATTRIBUTES;
    }
    IClasspathAttribute[] result = new IClasspathAttribute[length];
    int index = 0;
    for (int i = 0; i < length; ++i) {
        final Node node = attributes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            final Element attribute = (Element) node;
            final String name = attribute.getAttribute(ClasspathEntry.TAG_ATTRIBUTE_NAME);
            if (name == null) {
                continue;
            }
            final String value = attribute.getAttribute(ClasspathEntry.TAG_ATTRIBUTE_VALUE);
            if (value == null) {
                continue;
            }
            result[index++] = new ClasspathAttribute(name, value);
        }
    }
    if (index != length) {
        System.arraycopy(result, 0, result = new IClasspathAttribute[index], 0, index);
    }
    return result;
}

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

License:Apache License

/** Create the classpath library linked to the bundle with the given name.
 *
 * @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./*from ww  w  .j a v a 2  s .  c  o  m*/
 */
public static IClasspathEntry newLibraryEntry(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 JavaCore.newLibraryEntry(bundlePath, sourceBundlePath, null, null, extraAttributes, false);
}

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.//from   w w w . j av a 2  s  .c  om
 */
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.codehaus.groovy.eclipse.core.model.GroovyRuntime.java

License:Apache License

/**
 * Adds a library/folder that already exists in the project to the
 * classpath. Only added if it is not already on the classpath.
 *
 * @param javaProject//  w  w w .  j  a v  a 2s . co m
 *            The project to add add the classpath entry to.
 * @param libraryPath
 *            The path to add to the classpath.
 * @param isExported TODO
 * @throws JavaModelException
 */
public static void addLibraryToClasspath(final IJavaProject javaProject, final IPath libraryPath,
        boolean isExported) throws JavaModelException {

    boolean alreadyExists = includesClasspathEntry(javaProject, libraryPath.lastSegment());
    if (alreadyExists) {
        return;
    }
    addClassPathEntry(javaProject,
            new ClasspathEntry(IPackageFragmentRoot.K_BINARY, IClasspathEntry.CPE_CONTAINER, libraryPath,
                    ClasspathEntry.INCLUDE_ALL, // inclusion patterns
                    ClasspathEntry.EXCLUDE_NONE, // exclusion patterns
                    null, null, null, // specific output folder
                    true, // exported
                    ClasspathEntry.NO_ACCESS_RULES, false, // no access rules to
                    // combine
                    ClasspathEntry.NO_EXTRA_ATTRIBUTES));
}

From source file:org.drools.eclipse.util.DroolsClasspathContainer.java

License:Apache License

private IClasspathEntry[] createDroolsLibraryEntries(IJavaProject project) {
    int internalAPI = DroolsEclipsePlugin.getDefault().getPluginPreferences()
            .getInt(IDroolsConstants.INTERNAL_API);
    String[] jarNames = getJarNames(project);
    List<IClasspathEntry> list = new ArrayList<IClasspathEntry>();
    if (jarNames != null) {
        for (int i = 0; i < jarNames.length; i++) {
            Path path = new Path(jarNames[i]);
            if (internalAPI != 0) {
                if (jarNames[i].contains("knowledge-api")) {
                    list.add(JavaCore.newLibraryEntry(path, path, null));
                } else {
                    IAccessRule[] accessRules = new IAccessRule[1];
                    accessRules[0] = new ClasspathAccessRule(new Path("**"), internalAPI);
                    list.add(JavaCore.newLibraryEntry(path, path, null, accessRules,
                            ClasspathEntry.NO_EXTRA_ATTRIBUTES, false));
                }// ww w  .  ja  v  a 2 s  .  c  o  m
            }
        }
    }
    return (IClasspathEntry[]) list.toArray(new IClasspathEntry[list.size()]);
}

From source file:org.eclipse.dirigible.ide.workspace.dual.ProjectCreatorEnhancer.java

License:Open Source License

public static void enhance(IProject project) throws CoreException {
    //      project.refreshLocal(1, null);
    ////      createProjectFile(project);
    //      createClasspathFile(project);

    try {//w  ww .  ja v a 2s .  com
        //set the Java nature
        IProjectDescription description = project.getDescription();
        description.setNatureIds(new String[] { JavaCore.NATURE_ID }); // ModuleCoreNature?

        //create the project
        project.setDescription(description, null);
        IJavaProject javaProject = JavaCore.create(project);

        ClasspathEntry cpWeb = new ClasspathEntry(IPackageFragmentRoot.K_BINARY, IClasspathEntry.CPE_CONTAINER,
                new Path("org.eclipse.jst.j2ee.internal.web.container"), ClasspathEntry.INCLUDE_ALL,
                ClasspathEntry.EXCLUDE_NONE, null, null, null, false, (IAccessRule[]) null, false,
                ClasspathEntry.NO_EXTRA_ATTRIBUTES);

        ClasspathEntry cpModule = new ClasspathEntry(IPackageFragmentRoot.K_BINARY,
                IClasspathEntry.CPE_CONTAINER, new Path("org.eclipse.jst.j2ee.internal.module.container"),
                ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, null, null, false,
                (IAccessRule[]) null, false, ClasspathEntry.NO_EXTRA_ATTRIBUTES);

        ClasspathEntry cpTomcat = new ClasspathEntry(IPackageFragmentRoot.K_BINARY,
                IClasspathEntry.CPE_CONTAINER,
                new Path(
                        "org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0"),
                ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, null, null, false,
                (IAccessRule[]) null, false, ClasspathEntry.NO_EXTRA_ATTRIBUTES);

        //set the build path
        IClasspathEntry[] buildPath = {
                JavaCore.newSourceEntry(
                        project.getFullPath().append(ICommonConstants.ARTIFACT_TYPE.SCRIPTING_SERVICES)),
                JavaRuntime.getDefaultJREContainerEntry(), cpWeb, cpModule, cpTomcat };

        javaProject.setRawClasspath(buildPath, project.getFullPath().append("bin"), null);

    } catch (JavaModelException e) {
        throw new CoreException(new Status(IStatus.ERROR, // NOPMD
                "org.eclipse.dirigible.ide.workspace.rcp", e.getMessage())); //$NON-NLS-1$ // NOPMD
    }

}

From source file:org.eclipse.objectteams.otdt.tests.AbstractJavaModelTests.java

License:Open Source License

protected IJavaProject createJavaProject(final String projectName, final String[] sourceFolders,
        final String[] libraries, final String[][] librariesInclusionPatterns,
        final String[][] librariesExclusionPatterns, final String[] projects,
        final String[][] projectsInclusionPatterns, final String[][] projectsExclusionPatterns,
        final boolean combineAccessRestrictions, final boolean[] exportedProjects, final String projectOutput,
        final String[] sourceOutputs, final String[][] inclusionPatterns, final String[][] exclusionPatterns,
        final String compliance, final boolean simulateImport) throws CoreException {
    final IJavaProject[] result = new IJavaProject[1];
    IWorkspaceRunnable create = new IWorkspaceRunnable() {
        public void run(IProgressMonitor monitor) throws CoreException {
            // create project
            createProject(projectName);//w w  w  . j  a v  a 2  s.  com

            // set java nature
            addJavaNature(projectName);

            // create classpath entries
            IProject project = getWorkspaceRoot().getProject(projectName);
            IPath projectPath = project.getFullPath();
            int sourceLength = sourceFolders == null ? 0 : sourceFolders.length;
            int libLength = libraries == null ? 0 : libraries.length;
            int projectLength = projects == null ? 0 : projects.length;
            IClasspathEntry[] entries = new IClasspathEntry[sourceLength + libLength + projectLength];
            for (int i = 0; i < sourceLength; i++) {
                IPath sourcePath = new Path(sourceFolders[i]);
                int segmentCount = sourcePath.segmentCount();
                if (segmentCount > 0) {
                    // create folder and its parents
                    IContainer container = project;
                    for (int j = 0; j < segmentCount; j++) {
                        IFolder folder = container.getFolder(new Path(sourcePath.segment(j)));
                        if (!folder.exists()) {
                            folder.create(true, true, null);
                        }
                        container = folder;
                    }
                }
                IPath outputPath = null;
                if (sourceOutputs != null) {
                    // create out folder for source entry
                    outputPath = sourceOutputs[i] == null ? null : new Path(sourceOutputs[i]);
                    if (outputPath != null && outputPath.segmentCount() > 0) {
                        IFolder output = project.getFolder(outputPath);
                        if (!output.exists()) {
                            output.create(true, true, null);
                        }
                    }
                }
                // inclusion patterns
                IPath[] inclusionPaths;
                if (inclusionPatterns == null) {
                    inclusionPaths = new IPath[0];
                } else {
                    String[] patterns = inclusionPatterns[i];
                    int length = patterns.length;
                    inclusionPaths = new IPath[length];
                    for (int j = 0; j < length; j++) {
                        String inclusionPattern = patterns[j];
                        inclusionPaths[j] = new Path(inclusionPattern);
                    }
                }
                // exclusion patterns
                IPath[] exclusionPaths;
                if (exclusionPatterns == null) {
                    exclusionPaths = new IPath[0];
                } else {
                    String[] patterns = exclusionPatterns[i];
                    int length = patterns.length;
                    exclusionPaths = new IPath[length];
                    for (int j = 0; j < length; j++) {
                        String exclusionPattern = patterns[j];
                        exclusionPaths[j] = new Path(exclusionPattern);
                    }
                }
                // create source entry
                entries[i] = JavaCore.newSourceEntry(projectPath.append(sourcePath), inclusionPaths,
                        exclusionPaths, outputPath == null ? null : projectPath.append(outputPath));
            }
            for (int i = 0; i < libLength; i++) {
                String lib = libraries[i];
                if (lib.startsWith("JCL")) {
                    try {
                        // ensure JCL variables are set
                        setUpJCLClasspathVariables(compliance);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                // accessible files
                IPath[] accessibleFiles;
                if (librariesInclusionPatterns == null) {
                    accessibleFiles = new IPath[0];
                } else {
                    String[] patterns = librariesInclusionPatterns[i];
                    int length = patterns.length;
                    accessibleFiles = new IPath[length];
                    for (int j = 0; j < length; j++) {
                        String inclusionPattern = patterns[j];
                        accessibleFiles[j] = new Path(inclusionPattern);
                    }
                }
                // non accessible files
                IPath[] nonAccessibleFiles;
                if (librariesExclusionPatterns == null) {
                    nonAccessibleFiles = new IPath[0];
                } else {
                    String[] patterns = librariesExclusionPatterns[i];
                    int length = patterns.length;
                    nonAccessibleFiles = new IPath[length];
                    for (int j = 0; j < length; j++) {
                        String exclusionPattern = patterns[j];
                        nonAccessibleFiles[j] = new Path(exclusionPattern);
                    }
                }
                if (lib.indexOf(File.separatorChar) == -1 && lib.charAt(0) != '/'
                        && lib.equals(lib.toUpperCase())) { // all upper case is a var
                    char[][] vars = CharOperation.splitOn(',', lib.toCharArray());
                    entries[sourceLength + i] = JavaCore.newVariableEntry(new Path(new String(vars[0])),
                            vars.length > 1 ? new Path(new String(vars[1])) : null,
                            vars.length > 2 ? new Path(new String(vars[2])) : null,
                            ClasspathEntry.getAccessRules(accessibleFiles, nonAccessibleFiles), // ClasspathEntry.NO_ACCESS_RULES,
                            ClasspathEntry.NO_EXTRA_ATTRIBUTES, false);
                } else if (lib.startsWith("org.eclipse.jdt.core.tests.model.")) { // container
                    entries[sourceLength + i] = JavaCore.newContainerEntry(new Path(lib),
                            ClasspathEntry.getAccessRules(accessibleFiles, nonAccessibleFiles),
                            new IClasspathAttribute[0], false);
                } else {
                    IPath libPath = new Path(lib);
                    if (!libPath.isAbsolute() && libPath.segmentCount() > 0
                            && libPath.getFileExtension() == null) {
                        project.getFolder(libPath).create(true, true, null);
                        libPath = projectPath.append(libPath);
                    }
                    entries[sourceLength + i] = JavaCore.newLibraryEntry(libPath, null, null,
                            ClasspathEntry.getAccessRules(accessibleFiles, nonAccessibleFiles),
                            new IClasspathAttribute[0], false);
                }
            }
            for (int i = 0; i < projectLength; i++) {
                boolean isExported = exportedProjects != null && exportedProjects.length > i
                        && exportedProjects[i];

                // accessible files
                IPath[] accessibleFiles;
                if (projectsInclusionPatterns == null) {
                    accessibleFiles = new IPath[0];
                } else {
                    String[] patterns = projectsInclusionPatterns[i];
                    int length = patterns.length;
                    accessibleFiles = new IPath[length];
                    for (int j = 0; j < length; j++) {
                        String inclusionPattern = patterns[j];
                        accessibleFiles[j] = new Path(inclusionPattern);
                    }
                }
                // non accessible files
                IPath[] nonAccessibleFiles;
                if (projectsExclusionPatterns == null) {
                    nonAccessibleFiles = new IPath[0];
                } else {
                    String[] patterns = projectsExclusionPatterns[i];
                    int length = patterns.length;
                    nonAccessibleFiles = new IPath[length];
                    for (int j = 0; j < length; j++) {
                        String exclusionPattern = patterns[j];
                        nonAccessibleFiles[j] = new Path(exclusionPattern);
                    }
                }

                entries[sourceLength + libLength + i] = JavaCore.newProjectEntry(new Path(projects[i]),
                        ClasspathEntry.getAccessRules(accessibleFiles, nonAccessibleFiles),
                        combineAccessRestrictions, new IClasspathAttribute[0], isExported);
            }

            // create project's output folder
            IPath outputPath = new Path(projectOutput);
            if (outputPath.segmentCount() > 0) {
                IFolder output = project.getFolder(outputPath);
                if (!output.exists()) {
                    output.create(true, true, monitor);
                }
            }

            // set classpath and output location
            JavaProject javaProject = (JavaProject) JavaCore.create(project);
            if (simulateImport)
                javaProject.writeFileEntries(entries, projectPath.append(outputPath));
            else
                javaProject.setRawClasspath(entries, projectPath.append(outputPath), monitor);

            // set compliance level options
            if ("1.5".equals(compliance)) {
                Map options = new HashMap();
                options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
                options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
                options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
                javaProject.setOptions(options);
            }

            result[0] = javaProject;
        }
    };
    getWorkspace().run(create, null);
    return result[0];
}