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

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

Introduction

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

Prototype

public static IAccessRule[] getAccessRules(IPath[] accessibleFiles, IPath[] nonAccessibleFiles) 

Source Link

Usage

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  w  w .j  a  v 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:org.eclipse.objectteams.otdt.tests.AbstractJavaModelTests.java

License:Open Source License

protected void addLibraryEntry(IJavaProject project, IPath path, IPath srcAttachmentPath,
        IPath srcAttachmentPathRoot, IPath[] accessibleFiles, IPath[] nonAccessibleFiles,
        IClasspathAttribute[] extraAttributes, boolean exported) throws JavaModelException {
    IClasspathEntry entry = JavaCore.newLibraryEntry(path, srcAttachmentPath, srcAttachmentPathRoot,
            ClasspathEntry.getAccessRules(accessibleFiles, nonAccessibleFiles), extraAttributes, exported);
    addClasspathEntry(project, entry);/*from ww w.jav  a 2  s .  com*/
}

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);//from w  ww . jav a2  s .c  om

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

From source file:org.eclipse.xtend.shared.ui.test.TestEnvironment.java

License:Open Source License

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