Example usage for org.eclipse.jdt.core IJavaProject exists

List of usage examples for org.eclipse.jdt.core IJavaProject exists

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject exists.

Prototype

boolean exists();

Source Link

Document

Returns whether this Java element exists in the model.

Usage

From source file:org.apache.ivyde.eclipse.cp.IvyClasspathContainerHelper.java

License:Apache License

public static List<IvyClasspathContainer> getContainers(IProject project) {
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject != null && javaProject.exists()) {
        return getContainers(javaProject);
    }//from   ww  w .j  av a  2 s .  co m
    return Collections.emptyList();
}

From source file:org.apache.ivyde.internal.eclipse.IvyNature.java

License:Apache License

public void deconfigure() throws CoreException {
    IJavaProject javaProject = JavaCore.create(project);
    if (!javaProject.exists()) {
        return;//from   w  ww .  j  a va  2s . c  o  m
    }
    IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
    List newEntries = new ArrayList();

    for (int i = 0; i < classpathEntries.length; i++) {
        if (!IvyClasspathContainerHelper.isIvyClasspathContainer(classpathEntries[i].getPath())) {
            newEntries.add(classpathEntries[i]);
        }
    }

    if (newEntries.size() != classpathEntries.length) {
        IClasspathEntry[] newClasspathEntries = (IClasspathEntry[]) newEntries
                .toArray(new IClasspathEntry[newEntries.size()]);
        javaProject.setRawClasspath(newClasspathEntries, null);
    }

    IvyMarkerManager ivyMarkerManager = IvyPlugin.getDefault().getIvyMarkerManager();
    ivyMarkerManager.removeMarkers(project);
}

From source file:org.apache.sling.ide.eclipse.core.internal.BundleStateHelper.java

License:Apache License

private static Object doRecalcDecorationState(IServer server, IProject project) {
    try {/*from   w w  w . j a va  2  s.  c  o  m*/
        if (!ProjectHelper.isBundleProject(project)) {
            return EMPTY_STATE;
        }
        IJavaProject javaProject = ProjectHelper.asJavaProject(project);
        String hostname = server.getHost();
        int launchpadPort = server.getAttribute(ISlingLaunchpadServer.PROP_PORT, 8080);
        if (project.exists() && !javaProject.exists()) {
            // then it's not a java project..
            return EMPTY_STATE;
        }
        IPath outputLocation = javaProject.getOutputLocation();
        outputLocation = outputLocation.removeFirstSegments(1);
        IPath manifestFilePath = outputLocation.append("META-INF/MANIFEST.MF");
        IFile manifestFile = project.getFile(manifestFilePath);
        String bundlename;
        if (manifestFile.exists()) {
            Manifest manifest = new Manifest(manifestFile.getContents());
            bundlename = manifest.getMainAttributes().getValue("Bundle-SymbolicName");
        } else {
            String groupId = ProjectHelper.getMavenProperty(project, "groupId");
            String artifactId = ProjectHelper.getMavenProperty(project, "artifactId");
            if (groupId == null || groupId.isEmpty()) {
                bundlename = artifactId;
            } else {
                bundlename = groupId + "." + artifactId;
            }
        }
        String username = server.getAttribute(ISlingLaunchpadServer.PROP_USERNAME, "admin");
        String password = server.getAttribute(ISlingLaunchpadServer.PROP_PASSWORD, "admin");
        GetMethod method = new GetMethod(
                "http://" + hostname + ":" + launchpadPort + "/system/console/bundles/" + bundlename + ".json");
        int resultCode = getHttpClient(username, password).executeMethod(method);
        if (resultCode != HttpStatus.SC_OK) {
            return " [" + resultCode + "]";
        }
        String responseBodyAsString = method.getResponseBodyAsString(16 * 1024); // relevant data is in first 1k anyway
        JSONObject result = new JSONObject(responseBodyAsString);
        JSONArray dataArray = (JSONArray) result.get("data");
        JSONObject firstElement = (JSONObject) dataArray.get(0);
        return " [" + firstElement.get("state") + "]";
    } catch (Exception e) {
        e.printStackTrace();
        return e.getMessage();
    }
}

From source file:org.cloudfoundry.ide.eclipse.internal.server.core.standalone.StandaloneFacetHandler.java

License:Open Source License

public boolean canAddFacet() {
    if (project == null || !project.isAccessible() || hasFacet()) {
        return false;
    }/* w w  w. jav  a2 s  .c  o  m*/

    IJavaProject javaProject = CloudFoundryProjectUtil.getJavaProject(project);
    return javaProject != null && javaProject.exists();
}

From source file:org.cloudfoundry.ide.eclipse.internal.server.core.standalone.StandaloneHandler.java

License:Open Source License

public List<RuntimeType> getRuntimeTypes() {
    if (appTypes == null) {
        IProject project = getProject();
        if (project != null) {
            IJavaProject javaProject = CloudFoundryProjectUtil.getJavaProject(project);
            if (javaProject != null && javaProject.exists()) {
                appTypes = new JavaRuntimeTypeHelper(cloudServer).getRuntimeTypes();
            }/*  www .  j a  v a  2s. c  o  m*/
        }

        if (appTypes == null) {
            appTypes = Collections.emptyList();
        }
    }
    return appTypes;
}

From source file:org.cloudfoundry.ide.eclipse.server.core.internal.debug.DebugProvider.java

License:Open Source License

@Override
public boolean isDebugSupported(CloudFoundryApplicationModule appModule, CloudFoundryServer cloudServer) {
    IJavaProject javaProject = CloudFoundryProjectUtil.getJavaProject(appModule);
    return javaProject != null && javaProject.exists() && containsDebugFiles(javaProject);
}

From source file:org.cloudfoundry.ide.eclipse.server.standalone.internal.application.JavaPackageFragmentRootHandler.java

License:Open Source License

protected List<IJavaProject> getOrderedJavaProjects(IJavaProject project) {
    List<String> collectedProjects = new ArrayList<String>();
    getOrderedJavaProjectNames(Arrays.asList(project.getProject().getName()), collectedProjects);

    List<IJavaProject> projects = new ArrayList<IJavaProject>();

    for (String name : collectedProjects) {
        IProject prj = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
        if (prj != null) {
            IJavaProject jvPrj = JavaCore.create(prj);
            if (jvPrj != null && jvPrj.exists()) {
                projects.add(jvPrj);//from  w ww  . j  av a2 s.  c o m
            }
        }
    }

    return projects;

}

From source file:org.cloudfoundry.ide.eclipse.server.standalone.internal.application.JavaPackageFragmentRootHandler.java

License:Open Source License

protected void getOrderedJavaProjectNames(List<String> sameLevelRequiredProjects,
        List<String> collectedProjects) {
    // The order in which required projects are collected is as follows,
    // with the RHS
    // being required projects of the LHS
    // A -> BC
    // B -> D//from w  ww  . java 2  s  . c o m
    // C -> E
    // = total 5 projects, added in the order that they are encountered.
    // so final ordered list should be ABCDE
    if (sameLevelRequiredProjects == null) {
        return;
    }
    List<String> nextLevelRequiredProjects = new ArrayList<String>();
    // First add the current level java projects in the order they appear
    // and also collect each one's required names.
    for (String name : sameLevelRequiredProjects) {
        try {
            IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
            if (project != null) {
                IJavaProject jvPrj = JavaCore.create(project);
                if (jvPrj != null && jvPrj.exists()) {
                    if (!collectedProjects.contains(name)) {
                        collectedProjects.add(name);
                    }
                    String[] names = jvPrj.getRequiredProjectNames();
                    if (names != null && names.length > 0) {
                        for (String reqName : names) {
                            if (!nextLevelRequiredProjects.contains(reqName)) {
                                nextLevelRequiredProjects.add(reqName);
                            }
                        }
                    }
                }
            }

        } catch (JavaModelException e) {
            CloudFoundryPlugin.logError(e);
        }

    }

    // Now recurse to fetch the required projects for the
    // list of java projects that were added at the current level above
    if (!nextLevelRequiredProjects.isEmpty()) {
        getOrderedJavaProjectNames(nextLevelRequiredProjects, collectedProjects);

    }
}

From source file:org.codecover.eclipse.InstrumentableItemsManager.java

License:Open Source License

private void saveInstrumentableItems(XMLMemento memento) {
    for (Map.Entry<IJavaProject, Map<IPackageFragment, Set<ICompilationUnit>>> entry : this.markedJavaElements
            .entrySet()) {/*from w  w  w .j  a  v  a  2 s  .  c  o m*/
        Map<IPackageFragment, Set<ICompilationUnit>> subMap = entry.getValue();
        IJavaProject javaProject = entry.getKey();

        // If the map is empty, we don't need to create a project node.
        // If the project doesn't exists, we don't create a node.
        if (subMap.isEmpty() || !javaProject.exists()) {
            continue;
        }

        IMemento projectNode = memento.createChild(TAG_I_JAVA_PROJECT);
        projectNode.putString(TAG_INFO, getIJavaElementInfo(javaProject));

        for (Map.Entry<IPackageFragment, Set<ICompilationUnit>> subEntry : subMap.entrySet()) {
            Set<ICompilationUnit> set = subEntry.getValue();
            IPackageFragment packageFragment = subEntry.getKey();

            // If the set is empty, we don't need to create a package node.
            // If the package doesn't exists, we don't create a node.
            if (set.isEmpty() || !packageFragment.exists()) {
                continue;
            }

            IMemento packageNode = projectNode.createChild(TAG_I_PACKAGE_FRAGMENT);
            packageNode.putString(TAG_INFO, getIJavaElementInfo(packageFragment));

            for (ICompilationUnit compilationUnit : set) {

                // If the compilationUnit doesn't exists, we don't create a
                // node.
                if (!compilationUnit.exists()) {
                    continue;
                }

                IMemento compilationUnitNode = packageNode.createChild(TAG_I_COMPILATION_UNIT);
                compilationUnitNode.putString(TAG_INFO, getIJavaElementInfo(compilationUnit));
            }
        }
    }
}

From source file:org.codehaus.groovy.eclipse.refactoring.test.RefactoringTest.java

License:Open Source License

private void restoreTestProject() throws Exception {
    IJavaProject javaProject = getRoot().getJavaProject();
    if (javaProject.exists()) {
        IClasspathEntry srcEntry = getRoot().getRawClasspathEntry();
        try {//from  ww  w. ja  v  a 2  s. c  om
            IClasspathEntry[] jreEntries = RefactoringTestSetup.getJRELibrariesAsRawClasspathEntry();
            IClasspathEntry[] cpes = javaProject.getRawClasspath();
            ArrayList newCPEs = new ArrayList();
            boolean cpChanged = false;
            for (int i = 0; i < cpes.length; i++) {
                IClasspathEntry cpe = cpes[i];
                boolean isJREEntry = false;
                for (int j = 0; j < jreEntries.length; j++) {
                    if (cpe.equals(jreEntries[j])) {
                        isJREEntry = true;
                        break;
                    }
                }
                if (cpe.equals(srcEntry) || isJREEntry) {
                    newCPEs.add(cpe);
                } else {
                    cpChanged = true;
                }
            }
            if (cpChanged) {
                IClasspathEntry[] newCPEsArray = (IClasspathEntry[]) newCPEs
                        .toArray(new IClasspathEntry[newCPEs.size()]);
                javaProject.setRawClasspath(newCPEsArray, null);
            }
        } catch (JavaModelException e) {
            System.err.println(
                    "Exception thrown when trying to restore project to original state.  We can probable ignore this.");
            e.printStackTrace();
        }

        Object[] nonJavaResources = javaProject.getNonJavaResources();
        for (int i = 0; i < nonJavaResources.length; i++) {
            Object kid = nonJavaResources[i];
            if (kid instanceof IResource) {
                IResource resource = (IResource) kid;
                if (!PROJECT_RESOURCE_CHILDREN.contains(resource.getName())) {
                    JavaProjectHelper.delete(resource);
                }
            }
        }
    }
}