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

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

Introduction

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

Prototype

public static IAccessRule newAccessRule(IPath filePattern, int kind) 

Source Link

Document

Creates and returns a new access rule with the given file pattern and kind.

Usage

From source file:at.bestsolution.efxclipse.tooling.pde.java7.JavaFXClassPathExtender.java

License:Open Source License

private IClasspathEntry getEntry(IVMInstall vm, BundleDescription project) {
    IPath[] paths = BuildPathSupport.getFxJarPath(vm);
    if (paths == null) {
        return null;
    } else {/*  ww w .jav  a  2s .c o  m*/
        List<IAccessRule> l = new ArrayList<IAccessRule>();
        for (ImportPackageSpecification i : project.getImportPackages()) {
            if (i.getName().startsWith("javafx")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_ACCESSIBLE));
            } else if (i.getName().startsWith("com.sun.browser")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.deploy")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.glass")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.javafx")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.media")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.openpisces")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.prism")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.scenario")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.t2k")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("com.sun.webpane")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            } else if (i.getName().startsWith("netscape.javascript")) {
                l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                        IAccessRule.K_DISCOURAGED));
            }
        }

        IClasspathAttribute[] extraAttributes = {
                JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
                        paths[1] == null || !paths[1].toFile().exists() ? BuildPathSupport.WEB_JAVADOC_LOCATION
                                : paths[1].toFile().toURI().toString()) };

        return JavaCore.newLibraryEntry(paths[0], null, null, l.toArray(new IAccessRule[0]), extraAttributes,
                false);
    }
}

From source file:at.bestsolution.efxclipse.tooling.pde.ui.classpath.JavaFXClassPathExtender.java

License:Open Source License

@Override
public List<IClasspathEntry> getInitialEntries(BundleDescription project) {
    for (String e : project.getExecutionEnvironments()) {
        IExecutionEnvironment env = EnvironmentsManager.getDefault().getEnvironment(e);

        if (env == null) {
            continue;
        }/*from   www  .j  a  v  a  2 s. com*/

        IVMInstall vm = env.getDefaultVM();

        if (vm == null) {
            for (IVMInstall i : env.getCompatibleVMs()) {
                vm = i;
                break;
            }
        }

        if (vm != null) {
            IPath[] paths = BuildPathSupport.getFxJarPath(vm);
            if (paths == null) {
                return Collections.emptyList();
            } else {
                List<IAccessRule> l = new ArrayList<IAccessRule>();
                for (ImportPackageSpecification i : project.getImportPackages()) {
                    if (i.getName().startsWith("javafx")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_ACCESSIBLE));
                    } else if (i.getName().startsWith("com.sun.browser")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("com.sun.deploy")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("com.sun.glass")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("com.sun.javafx")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("com.sun.media")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("com.sun.openpisces")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("com.sun.prism")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("com.sun.scenario")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("com.sun.t2k")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("com.sun.webpane")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    } else if (i.getName().startsWith("netscape.javascript")) {
                        l.add(JavaCore.newAccessRule(new Path(i.getName().replace('.', '/') + "/*"),
                                IAccessRule.K_DISCOURAGED));
                    }
                }

                IClasspathAttribute[] extraAttributes = {
                        JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
                                paths[1] == null || !paths[1].toFile().exists()
                                        ? BuildPathSupport.WEB_JAVADOC_LOCATION
                                        : paths[1].toFile().toURI().toString()) };

                return Collections.singletonList(JavaCore.newContainerEntry(paths[0],
                        l.toArray(new IAccessRule[0]), extraAttributes, false));
            }
        }
    }
    return Collections.emptyList();
}

From source file:com.android.ide.eclipse.adt.internal.project.AndroidClasspathContainerInitializer.java

License:Open Source License

/**
 * Generates an array of {@link IClasspathEntry} from a set of paths.
 * @see #getTargetPaths(IAndroidTarget)/*from  w  ww . j  ava 2s. c  o  m*/
 */
private static IClasspathEntry[] createClasspathEntriesFromPaths(String[] paths, IAndroidTarget target) {
    ArrayList<IClasspathEntry> list = new ArrayList<IClasspathEntry>();

    // First, we create the IClasspathEntry for the framework.
    // now add the android framework to the class path.
    // create the path object.
    IPath androidLib = new Path(paths[CACHE_INDEX_JAR]);

    IPath androidSrc = null;
    String androidSrcOsPath = null;
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    if (target != null) {
        androidSrcOsPath = ProjectHelper.loadStringProperty(root, getAndroidSourceProperty(target));
    }
    if (androidSrcOsPath != null && androidSrcOsPath.trim().length() > 0) {
        androidSrc = new Path(androidSrcOsPath);
    }
    if (androidSrc == null) {
        androidSrc = new Path(paths[CACHE_INDEX_SRC]);
        File androidSrcFile = new File(paths[CACHE_INDEX_SRC]);
        if (!androidSrcFile.isDirectory()) {
            androidSrc = null;
        }
    }

    if (androidSrc == null && target != null) {
        Bundle bundle = getSourceBundle();

        if (bundle != null) {
            AndroidVersion version = target.getVersion();
            String apiString = version.getApiString();
            String sourcePath = apiString + SOURCES_ZIP;
            URL sourceURL = bundle.getEntry(sourcePath);
            if (sourceURL != null) {
                URL url = null;
                try {
                    url = FileLocator.resolve(sourceURL);
                } catch (IOException ignore) {
                }
                if (url != null) {
                    androidSrcOsPath = url.getFile();
                    if (new File(androidSrcOsPath).isFile()) {
                        androidSrc = new Path(androidSrcOsPath);
                    }
                }
            }
        }
    }

    // create the java doc link.
    String androidApiURL = ProjectHelper.loadStringProperty(root, PROPERTY_ANDROID_API);
    String apiURL = null;
    if (androidApiURL != null && testURL(androidApiURL)) {
        apiURL = androidApiURL;
    } else {
        if (testURL(paths[CACHE_INDEX_DOCS_URI])) {
            apiURL = paths[CACHE_INDEX_DOCS_URI];
        } else if (testURL(ANDROID_API_REFERENCE)) {
            apiURL = ANDROID_API_REFERENCE;
        }
    }

    IClasspathAttribute[] attributes = null;
    if (apiURL != null && !NULL_API_URL.equals(apiURL)) {
        IClasspathAttribute cpAttribute = JavaCore
                .newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, apiURL);
        attributes = new IClasspathAttribute[] { cpAttribute };
    }
    // create the access rule to restrict access to classes in
    // com.android.internal
    IAccessRule accessRule = JavaCore.newAccessRule(new Path("com/android/internal/**"), //$NON-NLS-1$
            IAccessRule.K_NON_ACCESSIBLE);

    IClasspathEntry frameworkClasspathEntry = JavaCore.newLibraryEntry(androidLib, androidSrc, // source attachment path
            null, // default source attachment root path.
            new IAccessRule[] { accessRule }, attributes, false // not exported.
    );

    list.add(frameworkClasspathEntry);

    // now deal with optional libraries
    if (paths.length >= 5) {
        String docPath = paths[CACHE_INDEX_OPT_DOCS_URI];
        int i = 4;
        while (i < paths.length) {
            Path jarPath = new Path(paths[i++]);

            attributes = null;
            if (docPath.length() > 0) {
                attributes = new IClasspathAttribute[] { JavaCore
                        .newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, docPath) };
            }

            IClasspathEntry entry = JavaCore.newLibraryEntry(jarPath, null, // source attachment path
                    null, // default source attachment root path.
                    null, attributes, false // not exported.
            );
            list.add(entry);
        }
    }

    if (apiURL != null) {
        ProjectHelper.saveStringProperty(root, PROPERTY_ANDROID_API, apiURL);
    }
    if (androidSrc != null && target != null) {
        ProjectHelper.saveStringProperty(root, getAndroidSourceProperty(target), androidSrc.toOSString());
    }
    return list.toArray(new IClasspathEntry[list.size()]);
}

From source file:com.android.ide.eclipse.adt.project.internal.AndroidClasspathContainerInitializer.java

License:Open Source License

/**
 * Generates an array of {@link IClasspathEntry} from a set of paths.
 * @see #getTargetPaths(IAndroidTarget)/*  w w  w.java  2 s  .c  o  m*/
 */
private static IClasspathEntry[] createClasspathEntriesFromPaths(String[] paths) {
    ArrayList<IClasspathEntry> list = new ArrayList<IClasspathEntry>();

    // First, we create the IClasspathEntry for the framework.
    // now add the android framework to the class path.
    // create the path object.
    IPath android_lib = new Path(paths[CACHE_INDEX_JAR]);
    IPath android_src = new Path(paths[CACHE_INDEX_SRC]);

    // create the java doc link.
    IClasspathAttribute cpAttribute = JavaCore.newClasspathAttribute(
            IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, paths[CACHE_INDEX_DOCS_URI]);

    // create the access rule to restrict access to classes in com.android.internal
    IAccessRule accessRule = JavaCore.newAccessRule(new Path("com/android/internal/**"), //$NON-NLS-1$
            IAccessRule.K_NON_ACCESSIBLE);

    IClasspathEntry frameworkClasspathEntry = JavaCore.newLibraryEntry(android_lib, android_src, // source attachment path
            null, // default source attachment root path.
            new IAccessRule[] { accessRule }, new IClasspathAttribute[] { cpAttribute }, false // not exported.
    );

    list.add(frameworkClasspathEntry);

    // now deal with optional libraries
    if (paths.length >= 5) {
        String docPath = paths[CACHE_INDEX_OPT_DOCS_URI];
        int i = 4;
        while (i < paths.length) {
            Path jarPath = new Path(paths[i++]);

            IClasspathAttribute[] attributes = null;
            if (docPath.length() > 0) {
                attributes = new IClasspathAttribute[] { JavaCore
                        .newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, docPath) };
            }

            IClasspathEntry entry = JavaCore.newLibraryEntry(jarPath, null, // source attachment path
                    null, // default source attachment root path.
                    null, attributes, false // not exported.
            );
            list.add(entry);
        }
    }

    return list.toArray(new IClasspathEntry[list.size()]);
}

From source file:com.codenvy.ide.ext.java.server.core.launching.environments.DefaultAccessRuleParticipant.java

License:Open Source License

public IAccessRule[][] getAccessRules(IExecutionEnvironment environment, IVMInstallType vm,
        LibraryLocation[] libraries, IJavaProject project) {
    IAccessRule[][] allRules = null;//from   w  ww.  j av  a2  s  .c  o  m
    allRules = fgRules.get(environment.getId());
    if (allRules == null || allRules.length != libraries.length) {
        // if a different number of libraries, create a new set of rules
        String[] packages = retrieveSystemPackages(environment);
        IAccessRule[] packageRules = null;
        if (packages.length > 0) {
            packageRules = new IAccessRule[packages.length + 1];
            for (int i = 0; i < packages.length; i++) {
                packageRules[i] = JavaCore.newAccessRule(new Path(packages[i].replace('.', IPath.SEPARATOR)),
                        IAccessRule.K_ACCESSIBLE);
            }
            // add IGNORE_IF_BETTER flag in case another explicit entry allows access (see bug 228488)
            packageRules[packages.length] = JavaCore.newAccessRule(new Path("**/*"),
                    IAccessRule.K_NON_ACCESSIBLE | IAccessRule.IGNORE_IF_BETTER);
            //$NON-NLS-1$
        } else {
            packageRules = new IAccessRule[0];
        }
        allRules = new IAccessRule[libraries.length][];
        for (int i = 0; i < allRules.length; i++) {
            allRules[i] = packageRules;
        }
        fgRules.put(environment.getId(), allRules);
    }
    return allRules;
}

From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java

License:Open Source License

public static IAccessRule[] getAccessRules(IPath[] accessibleFiles, IPath[] nonAccessibleFiles) {
    int accessibleFilesLength = accessibleFiles == null ? 0 : accessibleFiles.length;
    int nonAccessibleFilesLength = nonAccessibleFiles == null ? 0 : nonAccessibleFiles.length;
    int length = accessibleFilesLength + nonAccessibleFilesLength;
    if (length == 0)
        return null;
    IAccessRule[] accessRules = new IAccessRule[length];
    for (int i = 0; i < accessibleFilesLength; i++) {
        accessRules[i] = JavaCore.newAccessRule(accessibleFiles[i], IAccessRule.K_ACCESSIBLE);
    }/* w w  w. ja va  2s .co  m*/
    for (int i = 0; i < nonAccessibleFilesLength; i++) {
        accessRules[accessibleFilesLength + i] = JavaCore.newAccessRule(nonAccessibleFiles[i],
                IAccessRule.K_NON_ACCESSIBLE);
    }
    return accessRules;
}

From source file:com.google.cloud.tools.eclipse.appengine.libraries.persistence.SerializableAccessRules.java

License:Apache License

public IAccessRule toAccessRule() {
    return JavaCore.newAccessRule(new Path(pattern), ruleKind.kind);
}

From source file:com.google.cloud.tools.eclipse.appengine.libraries.repository.LibraryClasspathContainerResolverService.java

License:Apache License

private static IAccessRule[] getAccessRules(List<Filter> filters) {
    IAccessRule[] accessRules = new IAccessRule[filters.size()];
    int idx = 0;/*w  ww. j  a  va 2s  .c o m*/
    for (Filter filter : filters) {
        int accessRuleKind = filter.isExclude() ? IAccessRule.K_NON_ACCESSIBLE : IAccessRule.K_ACCESSIBLE;
        accessRules[idx++] = JavaCore.newAccessRule(new Path(filter.getPattern()), accessRuleKind);
    }
    return accessRules;
}

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

License:Open Source License

private static synchronized IAccessRule getAccessibleRule(IPath path) {
    IAccessRule rule = (IAccessRule) ACCESSIBLE_RULES.get(path);
    if (rule == null) {
        rule = JavaCore.newAccessRule(path, IAccessRule.K_ACCESSIBLE);
        ACCESSIBLE_RULES.put(path, rule);
    }//from  www. j a  va2 s.  c o  m
    return rule;
}

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

License:Open Source License

private static synchronized IAccessRule getDiscouragedRule(IPath path) {
    IAccessRule rule = (IAccessRule) DISCOURAGED_RULES.get(path);
    if (rule == null) {
        rule = JavaCore.newAccessRule(path, IAccessRule.K_DISCOURAGED);
        DISCOURAGED_RULES.put(path, rule);
    }//from   www .  j  a v a 2  s .  com
    return rule;
}