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

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

Introduction

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

Prototype

public static IClasspathAttribute newClasspathAttribute(String name, String value) 

Source Link

Document

Creates and returns a new classpath attribute with the given name and the given value.

Usage

From source file:at.bestsolution.efxclipse.tooling.jdt.core.internal.BuildPathSupport.java

License:Open Source License

public static IClasspathEntry getJavaFXLibraryEntry(IJavaProject project) {
    IPath[] paths = getFxJarPath(project);
    if (paths != null) {

        IPath jarLocationPath = paths[0];
        IPath javadocLocation = paths[1];
        IPath fxSource = paths[3];//from   w  w  w. j  ava2  s  .c  om

        IClasspathAttribute[] attributes;
        IAccessRule[] accessRules = {};
        if (javadocLocation == null || !javadocLocation.toFile().exists()) {
            attributes = new IClasspathAttribute[] { JavaCore.newClasspathAttribute(
                    IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, WEB_JAVADOC_LOCATION) };
        } else {
            attributes = new IClasspathAttribute[] {
                    JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
                            javadocLocation.toFile().toURI().toString()) };
        }

        if (jarLocationPath.toFile().exists()) {
            return JavaCore.newLibraryEntry(jarLocationPath, fxSource, null, accessRules, attributes, false);
        }
    }

    return null;
}

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 {//  w ww.j  av  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 w w w  .  j ava  2s.c om*/

        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: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 a va2 s  . c o m*/
        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.CPListElementAttribute.java

License:Open Source License

public IClasspathAttribute getClasspathAttribute() {
    Assert.isTrue(!fBuiltIn);
    return JavaCore.newClasspathAttribute(fKey, (String) fValue);
}

From source file:com.aerospike.project.wizards.NewAerospikeProjectWizard.java

License:Apache License

protected boolean generateJavaProject() {
    URL url = this.getClass().getResource("project.stg");
    final STGroup projectSTG = new STGroupFile(url.getPath());
    final String projectName = page.getProjectName();
    final String author = page.getAuthor();
    final String email = page.getEmail();
    final String artifactId = page.getArtifiactId();
    final String version = page.getVersion();
    final String packageString = page.getPackage();
    final String mainClass = page.getMainClassName();
    final String seedNode = page.getSeedNode();
    final String port = page.getPortString();
    final boolean generateMain = page.getGenerateMain();
    final boolean generateJUnit = page.getGenerateJUnit();
    IRunnableWithProgress op = new IRunnableWithProgress() {
        public void run(IProgressMonitor monitor) throws InvocationTargetException {
            try {
                //Create the project
                IProject project = createProject(projectName, monitor);
                project.setPersistentProperty(CoreActivator.SEED_NODE_PROPERTY, seedNode);
                project.setPersistentProperty(CoreActivator.PORT_PROPERTY, port);
                project.setPersistentProperty(CoreActivator.UDF_DIRECTORY, null);
                project.setPersistentProperty(CoreActivator.AQL_GENERATION_DIRECTORY, null);
                //make a java project
                IJavaProject javaProject = JavaCore.create(project);
                // create the classpath entries
                List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
                IExecutionEnvironmentsManager executionEnvironmentsManager = JavaRuntime
                        .getExecutionEnvironmentsManager();
                IExecutionEnvironment[] executionEnvironments = executionEnvironmentsManager
                        .getExecutionEnvironments();
                for (IExecutionEnvironment iExecutionEnvironment : executionEnvironments) {
                    // We will look for JavaSE-1.6 as the JRE container to add to our classpath
                    if ("JavaSE-1.6".equals(iExecutionEnvironment.getId())) {
                        entries.add(JavaCore
                                .newContainerEntry(JavaRuntime.newJREContainerPath(iExecutionEnvironment)));
                        break;
                    } else if ("JavaSE-1.5".equals(iExecutionEnvironment.getId())) {
                        entries.add(JavaCore
                                .newContainerEntry(JavaRuntime.newJREContainerPath(iExecutionEnvironment)));
                        break;
                    }/*from   w  w w .ja  v  a2  s .  c o m*/
                }
                IClasspathEntry mavenEntry = JavaCore.newContainerEntry(
                        new Path("org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"), new IAccessRule[0],
                        new IClasspathAttribute[] { JavaCore.newClasspathAttribute(
                                "org.eclipse.jst.component.dependency", "/WEB-INF/lib") },
                        false);
                entries.add(mavenEntry);
                javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null);
                // create source folders
                IFolder srcMainJava = project.getFolder("src/main/java");
                createFolder(srcMainJava);
                IFolder srcMainResource = project.getFolder("src/main/resource");
                createFolder(srcMainResource);
                IFolder srcTestJava = project.getFolder("src/test/java");
                createFolder(srcTestJava);
                IFolder srcTestResource = project.getFolder("src/test/resource");
                createFolder(srcTestResource);
                // create aerospike folders
                IFolder srcUDF = project.getFolder(store.getString(PreferenceConstants.UDF_PATH));
                createFolder(srcUDF);
                IFolder srcGenerated = project.getFolder(store.getString(PreferenceConstants.GENERATION_PATH));
                createFolder(srcGenerated);
                IFolder srcAql = project.getFolder("aql");
                createFolder(srcAql);
                //
                IPackageFragmentRoot mainJava = javaProject.getPackageFragmentRoot(srcMainJava);
                IPackageFragmentRoot mainResource = javaProject.getPackageFragmentRoot(srcMainResource);
                IPackageFragmentRoot testJava = javaProject.getPackageFragmentRoot(srcTestJava);
                IPackageFragmentRoot testResource = javaProject.getPackageFragmentRoot(srcTestResource);
                IPackageFragmentRoot mainGenerated = javaProject.getPackageFragmentRoot(srcGenerated);
                IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
                IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 5];
                System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
                newEntries[oldEntries.length] = JavaCore.newSourceEntry(mainJava.getPath());
                newEntries[oldEntries.length + 1] = JavaCore.newSourceEntry(mainResource.getPath());
                newEntries[oldEntries.length + 2] = JavaCore.newSourceEntry(testJava.getPath());
                newEntries[oldEntries.length + 3] = JavaCore.newSourceEntry(testResource.getPath());
                newEntries[oldEntries.length + 4] = JavaCore.newSourceEntry(mainGenerated.getPath());
                javaProject.setRawClasspath(newEntries, monitor);
                // create the pom.xml
                ST template = projectSTG.getInstanceOf("pom");
                template.add("name", projectName);
                template.add("artifactId", artifactId);
                template.add("version", version);
                template.add("author", author);
                template.add("email", email);
                template.add("mainClass", mainClass);
                template.add("package", packageString);
                createFile(project, null, "pom.xml", monitor, template);
                // create the log4J.properties
                template = projectSTG.getInstanceOf("log4J");
                template.add("package", packageString);
                template.add("mainClass", mainClass);
                createFile(project, srcMainJava, "log4j.properties", monitor, template);
                // create the .gitignore
                template = projectSTG.getInstanceOf("ignore");
                createFile(project, null, ".gitignore", monitor, template);
                // create the README
                template = projectSTG.getInstanceOf("readme");
                template.add("name", projectName);
                createFile(project, null, "README.md", monitor, template);
                // create package
                // create JUnit
                if (generateJUnit) {
                    IPackageFragment pack = javaProject.getPackageFragmentRoot(srcTestJava)
                            .createPackageFragment(packageString, false, null);
                    template = projectSTG.getInstanceOf("junit");
                    template.add("name", mainClass + "Test");
                    template.add("package", packageString);
                    template.add("classUnderTest", mainClass);
                    pack.createCompilationUnit(mainClass + "Test" + ".java", template.render(), false, monitor);
                }
                // create main class
                IPackageFragment pack = javaProject.getPackageFragmentRoot(srcMainJava)
                        .createPackageFragment(packageString, false, null);
                template = projectSTG.getInstanceOf("mainClass");
                template.add("name", mainClass);
                template.add("package", packageString);
                template.add("author", author);
                template.add("seedNode", seedNode);
                template.add("port", port);
                final ICompilationUnit cu = pack.createCompilationUnit(mainClass + ".java", template.render(),
                        false, monitor);
                // open editor on main class
                monitor.setTaskName("Opening file for editing...");
                getShell().getDisplay().asyncExec(new Runnable() {
                    public void run() {
                        IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
                                .getActivePage();
                        try {
                            IEditorPart editor = IDE.openEditor(page, (IFile) cu.getResource(), true);
                        } catch (PartInitException e) {
                        }
                    }
                });

            } catch (CoreException e) {
                throw new InvocationTargetException(e);
            } finally {
                monitor.done();
            }
        }
    };
    try {
        getContainer().run(true, false, op);
    } catch (InterruptedException e) {
        return false;
    } catch (InvocationTargetException e) {
        Throwable realException = e.getTargetException();
        MessageDialog.openError(getShell(), "Error", realException.getMessage());
        return false;
    }
    return true;
}

From source file:com.amazonaws.eclipse.android.sdk.classpath.AndroidSdkClasspathContainer.java

License:Open Source License

/**
 * Loads the JDT classpath entries for the AWS SDK for Android from the
 * specified SDK install and returns them as a list.
 *
 * @param sdkInstall//from w w w.  j  a va 2 s .c  o m
 *            The SDK install from which to load the classpath entries.
 *
 * @return A list of the JDT classpath entries for the AWS SDK for Android
 *         at the specified install base.
 */
private List<IClasspathEntry> loadSdkClasspathEntries(AbstractSdkInstall sdkInstall) {
    List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
    IPath sdkJarPath = null, sdkSourceJarPath = null;

    try {
        File sdkJar = sdkInstall.getSdkJar();
        sdkJarPath = project.getLocation().append("libs").append(sdkJar.getName());
    } catch (FileNotFoundException e) {
        // The SDK has been deleted, there's no classpath entries anymore.
        return new ArrayList<IClasspathEntry>();
    }
    IClasspathAttribute externalJavadocPath = JavaCore.newClasspathAttribute(
            IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, sdkInstall.getJavadocURL());
    if (externalJavadocPath.getValue() != null) {
        classpathEntries.add(JavaCore.newLibraryEntry(sdkJarPath, sdkSourceJarPath, null, new IAccessRule[0],
                new IClasspathAttribute[] { externalJavadocPath }, true));
    } else {
        classpathEntries.add(JavaCore.newLibraryEntry(sdkJarPath, sdkSourceJarPath, null, new IAccessRule[0],
                new IClasspathAttribute[0], true));
    }

    for (File jarFile : sdkInstall.getThirdPartyJars()) {
        IPath thirdPartyJarPath = new Path(jarFile.getAbsolutePath());
        classpathEntries.add(JavaCore.newLibraryEntry(thirdPartyJarPath, thirdPartyJarPath, null, true));
    }

    return classpathEntries;
}

From source file:com.amazonaws.eclipse.lambda.project.classpath.LambdaRuntimeClasspathContainer.java

License:Open Source License

private IClasspathEntry loadRuntimeClasspathEntry(LambdaRuntimeLibraryComponent component) {
    IPath classJarPath = new Path(component.getClassJarFile().getAbsolutePath());

    IClasspathAttribute attrs[] = new IClasspathAttribute[0];
    if (component.getJavadocJarFile() != null) {
        attrs = new IClasspathAttribute[] {
                JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME,
                        constructJavadocLocationAttributeValue(component.getJavadocJarFile())) };
    }/*from  w  ww  .  j  a v  a 2  s .  c o m*/

    return JavaCore.newLibraryEntry(classJarPath, null, null, new IAccessRule[0], attrs, true);
}

From source file:com.amazonaws.eclipse.sdk.ui.classpath.AwsClasspathContainer.java

License:Open Source License

/**
 * Loads the JDT classpath entries for the AWS SDK for Java from the specified
 * SDK install and returns them as a list.
 *
 * @param sdkInstall//from www .  j av a2 s  .  c  om
 *            The SDK install from which to load the classpath entries.
 *
 * @return A list of the JDT classpath entries for the AWS SDK for Java at the
 *         specified install base.
 */
private List<IClasspathEntry> loadSdkClasspathEntries(SdkInstall sdkInstall) {
    List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
    IPath sdkJarPath, sdkSourceJarPath;

    try {
        sdkJarPath = new Path(sdkInstall.getSdkJar().getAbsolutePath());
        sdkSourceJarPath = new Path(sdkInstall.getSdkSourceJar().getAbsolutePath());
    } catch (FileNotFoundException e) {
        // The SDK has been deleted, there's no classpath entries anymore.
        return new ArrayList<IClasspathEntry>();
    }
    IClasspathAttribute externalJavadocPath = JavaCore.newClasspathAttribute(
            IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, sdkInstall.getJavadocURL());
    if (externalJavadocPath.getValue() != null) {
        classpathEntries.add(JavaCore.newLibraryEntry(sdkJarPath, sdkSourceJarPath, null, new IAccessRule[0],
                new IClasspathAttribute[] { externalJavadocPath }, true));
    } else {
        classpathEntries.add(JavaCore.newLibraryEntry(sdkJarPath, sdkSourceJarPath, null, new IAccessRule[0],
                new IClasspathAttribute[0], true));
    }

    for (File jarFile : sdkInstall.getThirdPartyJars()) {
        IPath thirdPartyJarPath = new Path(jarFile.getAbsolutePath());
        classpathEntries.add(JavaCore.newLibraryEntry(thirdPartyJarPath, thirdPartyJarPath, null, true));
    }

    return classpathEntries;
}

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 ww w.j  av a2  s  . 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()]);
}