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

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

Introduction

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

Prototype

IProject getProject();

Source Link

Document

Returns the IProject on which this IJavaProject was created.

Usage

From source file:com.centurylink.mdw.plugin.launch.CucumberLaunchTab.java

License:Apache License

protected void createProjectSection(Composite parent) {
    List<IJavaProject> javaProjects = null;
    try {/*www. j a v  a2 s  .  c  o  m*/
        javaProjects = WorkflowProjectManager.getJavaProjects();
    } catch (JavaModelException ex) {
        PluginMessages.log(ex);
    }
    if (javaProjects == null || javaProjects.size() == 0)
        MessageDialog.openError(parent.getShell(), "Error", "No Java projects found");

    new Label(parent, SWT.NONE).setText("Project: ");
    projectCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
    GridData gd = new GridData(GridData.BEGINNING);
    gd.verticalIndent = 3;
    gd.widthHint = 200;
    projectCombo.setLayoutData(gd);
    projectCombo.removeAll();
    for (IJavaProject javaProject : javaProjects)
        projectCombo.add(javaProject.getProject().getName());

    projectCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            project = WorkflowProjectManager.getProject(projectCombo.getText());
            folder = null;
            featureLocText.setText("");
            resetTests();
            refreshTestCasesTable();
            setDirty(true);
            validatePage();
        }
    });
}

From source file:com.centurylink.mdw.plugin.project.assembly.ProjectConfigurator.java

License:Apache License

private void addJarsToClasspath(IJavaProject javaProject, IFolder libFolder, IProgressMonitor monitor)
        throws JavaModelException {
    List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
    for (IClasspathEntry existingEntry : javaProject.getRawClasspath())
        classpathEntries.add(existingEntry);

    File libDir = new File(libFolder.getRawLocation().toOSString());
    if (libDir.exists() && libDir.isDirectory()) {
        File[] jarFiles = libDir.listFiles(new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.endsWith(".jar") && !name.endsWith("_src.jar");
            }//  w w w .  j a  va 2s. c  o  m
        });

        for (File jarFile : jarFiles) {
            IPath path = libFolder.getFile(jarFile.getName()).getFullPath();
            IClasspathEntry newEntry = JavaCore.newLibraryEntry(path, null, null);
            boolean already = false;
            for (IClasspathEntry existing : javaProject.getRawClasspath()) {
                if (existing.getPath().equals(newEntry.getPath())) {
                    already = true;
                    break;
                }
            }
            if (!already)
                classpathEntries.add(newEntry);
        }

        javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[0]), monitor);
        J2EEComponentClasspathUpdater.getInstance().queueUpdateModule(javaProject.getProject());
    }
}

From source file:com.centurylink.mdw.plugin.project.WorkflowProjectManager.java

License:Apache License

/**
 * Get the workflow project whose source project corresponds to a specified
 * java project/*w  w  w. j  a va2  s . co m*/
 */
public WorkflowProject getWorkflowProject(IJavaProject javaProject) throws CoreException {
    return getWorkflowProject(javaProject.getProject().getName());
}

From source file:com.centurylink.mdw.plugin.project.WorkflowProjectPage.java

License:Apache License

private void createSourceProjectControls(Composite parent, int ncol) {
    new Label(parent, SWT.NONE).setText("Project Name:");

    sourceProjectNameTextField = new Text(parent, SWT.SINGLE | SWT.BORDER);
    GridData gd = new GridData(GridData.BEGINNING);
    gd.widthHint = 200;/*from ww w  .j a v a 2  s .  c o  m*/
    gd.horizontalSpan = ncol - 2;
    sourceProjectNameTextField.setLayoutData(gd);
    sourceProjectNameTextField.setTextLimit(50);
    final boolean updateEarBasedOnSource = getProject().getEarProjectName() == null;
    sourceProjectNameTextField.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            String workflowProjectName = sourceProjectNameTextField.getText().trim();
            getProject().setSourceProjectName(workflowProjectName);
            if (updateEarBasedOnSource)
                getProject().setEarProjectName(workflowProjectName + "Ear");
            if (getWizard() instanceof EarProjectWizard) {
                EarProjectWizard earProjectWizard = (EarProjectWizard) getWizard();
                earProjectWizard.getDataModel().setProperty(
                        IFacetProjectCreationDataModelProperties.FACET_PROJECT_NAME,
                        getProject().getEarProjectName());
            }
            handleFieldChanged();
        }
    });
    // when activated by adding facet to existing cloud project
    if (getProject().isCloudProject() && getProject().getEarProjectName() != null) {
        getProject().setSourceProjectName(getProject().getEarProjectName());
        sourceProjectNameTextField.setText(getProject().getSourceProjectName());
        if (getProject().isCloudProject())
            sourceProjectNameTextField.setEditable(false);
    }

    Label existing = new Label(parent, SWT.BEGINNING);
    existing.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL));
    // adding facet to existing EAR project
    if (getProject().isEarProject()) {
        existing.setText("  (Existing Java Project)");
        if (getProject().getEarProjectName() != null) {
            IProject proj = MdwPlugin.getWorkspaceRoot().getProject(getProject().getEarProjectName());
            if (proj != null) {
                IJavaProject relatedJavaProj = WorkflowProjectManager.getInstance().getRelatedJavaProject(proj);
                if (relatedJavaProj != null)
                    sourceProjectNameTextField.setText(relatedJavaProj.getProject().getName());
            }
        }
    }
}

From source file:com.centurylink.mdw.plugin.ResourceWrapper.java

License:Apache License

public IProject getProject() {
    IProject project = null;/*ww w  . ja  v a 2s .c  om*/
    if (adaptable != null) {
        project = (IProject) adaptable.getAdapter(IProject.class);
        if (project == null) {
            IJavaProject javaProj = (IJavaProject) adaptable.getAdapter(IJavaProject.class);
            if (javaProj == null) {
                if (adaptable instanceof IJavaElement)
                    javaProj = ((IJavaElement) adaptable).getJavaProject();
            }
            if (javaProj != null)
                project = javaProj.getProject();
        }
    } else {
        if (resourceObj instanceof IProject)
            project = (IProject) resourceObj;
        else if (resourceObj instanceof IJavaProject)
            project = ((IJavaProject) resourceObj).getProject();
        else if (resourceObj instanceof IJavaElement)
            project = ((IJavaElement) resourceObj).getJavaProject().getProject();
    }
    return project;
}

From source file:com.cisco.yangide.core.indexing.IndexAllProject.java

License:Open Source License

@Override
public boolean execute(IProgressMonitor progressMonitor) {
    System.err.println("[I] Project: " + project.getName());

    if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) {
        return true;
    }//from w w  w.j av  a 2  s .c o  m

    if (!this.project.isAccessible()) {
        return true;
    }
    final HashSet<IPath> ignoredPath = new HashSet<IPath>();
    final HashSet<IPath> externalJarsPath = new HashSet<IPath>();
    try {
        JavaProject proj = (JavaProject) JavaCore.create(project);
        final HashSet<String> projectScope = new HashSet<>();
        projectScope.add(project.getName());

        if (proj != null) {
            IClasspathEntry[] classpath = proj.getResolvedClasspath();
            for (int i = 0, length = classpath.length; i < length; i++) {
                IClasspathEntry entry = classpath[i];
                IPath entryPath = entry.getPath();
                IPath output = entry.getOutputLocation();
                if (output != null && !entryPath.equals(output)) {
                    ignoredPath.add(output);
                }

                // index dependencies projects
                if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                    IProject prj = ResourcesPlugin.getWorkspace().getRoot()
                            .getProject(entry.getPath().lastSegment());
                    if (prj != null && prj.exists()) {
                        this.manager.indexAll(prj);
                        projectScope.add(prj.getName());
                    }
                }
            }
            IPackageFragmentRoot[] roots = proj.getAllPackageFragmentRoots();
            for (int i = 0, length = roots.length; i < length; i++) {
                IPath entryPath = roots[i].getPath();
                if (entryPath != null && entryPath.toFile().exists()
                        && entryPath.lastSegment().toLowerCase().endsWith(".jar")) {
                    externalJarsPath.add(entryPath);
                }
            }
            // Update project information with set of project dependencies
            YangProjectInfo yangProjectInfo = (YangProjectInfo) YangCorePlugin.create(project)
                    .getElementInfo(null);
            yangProjectInfo.setProjectScope(projectScope);
            // fill indirect scope
            HashSet<String> indirectScope = new HashSet<String>();
            indirectScope.add(project.getName());
            for (IJavaProject jproj : JavaCore.create(ResourcesPlugin.getWorkspace().getRoot())
                    .getJavaProjects()) {
                if (jproj != proj) {
                    for (String name : jproj.getRequiredProjectNames()) {
                        if (name.equals(project.getName())) {
                            indirectScope.add(jproj.getProject().getName());
                        }
                    }
                }
            }
            yangProjectInfo.setIndirectScope(indirectScope);
        }
    } catch (JavaModelException | YangModelException e) {
        // java project doesn't exist: ignore
    }

    for (IPath iPath : externalJarsPath) {
        try (JarFile jarFile = new JarFile(iPath.toFile())) {
            ZipEntry entry = jarFile.getEntry("META-INF/yang/");
            if (entry != null) {
                this.manager.addJarFile(project, iPath);
            }
        } catch (IOException e) {
            YangCorePlugin.log(e);
        }
    }
    try {
        final HashSet<IFile> indexedFiles = new HashSet<IFile>();
        project.accept(new IResourceProxyVisitor() {
            @Override
            public boolean visit(IResourceProxy proxy) {
                if (IndexAllProject.this.isCancelled) {
                    return false;
                }
                if (!ignoredPath.isEmpty() && ignoredPath.contains(proxy.requestFullPath())) {
                    return false;
                }
                if (proxy.getType() == IResource.FILE) {
                    if (CoreUtil.isYangLikeFileName(proxy.getName())) {
                        IFile file = (IFile) proxy.requestResource();
                        indexedFiles.add(file);
                    }
                    return false;
                }
                return true;
            }
        }, IResource.NONE);

        for (IFile iFile : indexedFiles) {
            this.manager.addSource(iFile);
        }
    } catch (CoreException e) {
        this.manager.removeIndexFamily(project);
        return false;
    }
    return true;
}

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

License:Open Source License

private void computeDependents(IJavaProject project, HashSet set, HashSet visited) {
    if (visited.contains(project))
        return;/*w  ww  . j  a  v a2 s . c om*/
    visited.add(project);
    IProject[] dependents = project.getProject().getReferencingProjects();
    for (int i = 0; i < dependents.length; i++) {
        try {
            IJavaProject dependent = JavaCore.create(dependents[i]);
            IPackageFragmentRoot[] roots = dependent.getPackageFragmentRoots();
            set.add(dependent.getPath());
            for (int j = 0; j < roots.length; j++) {
                IPackageFragmentRoot pkgFragmentRoot = roots[j];
                if (pkgFragmentRoot.isArchive()) {
                    set.add(pkgFragmentRoot.getPath());
                }
            }
            computeDependents(dependent, set, visited);
        } catch (JavaModelException e) {
            // project is not a java project
        }
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java

License:Open Source License

/**
 * Locates the package declarations corresponding to the search pattern.
 *//*from w  ww . j av  a 2s.  c  o m*/
protected void locatePackageDeclarations(SearchPattern searchPattern, SearchParticipant participant,
        IJavaProject[] projects) throws CoreException {
    if (this.progressMonitor != null && this.progressMonitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    if (searchPattern instanceof OrPattern) {
        SearchPattern[] patterns = ((OrPattern) searchPattern).patterns;
        for (int i = 0, length = patterns.length; i < length; i++) {
            locatePackageDeclarations(patterns[i], participant, projects);
        }
    } else if (searchPattern instanceof PackageDeclarationPattern) {
        IJavaElement focus = searchPattern.focus;
        if (focus != null) {
            if (encloses(focus)) {
                SearchMatch match = new PackageDeclarationMatch(
                        focus.getAncestor(IJavaElement.PACKAGE_FRAGMENT), SearchMatch.A_ACCURATE, -1, -1,
                        participant, focus.getResource());
                report(match);
            }
            return;
        }
        PackageDeclarationPattern pkgPattern = (PackageDeclarationPattern) searchPattern;
        boolean isWorkspaceScope = this.scope == JavaModelManager.getJavaModelManager().getWorkspaceScope();
        IPath[] scopeProjectsAndJars = isWorkspaceScope ? null : this.scope.enclosingProjectsAndJars();
        int scopeLength = isWorkspaceScope ? 0 : scopeProjectsAndJars.length;
        SimpleSet packages = new SimpleSet();
        for (int i = 0, length = projects.length; i < length; i++) {
            IJavaProject javaProject = projects[i];
            if (this.progressMonitor != null) {
                if (this.progressMonitor.isCanceled())
                    throw new OperationCanceledException();
                this.progressWorked++;
                if ((this.progressWorked % this.progressStep) == 0)
                    this.progressMonitor.worked(this.progressStep);
            }
            // Verify that project belongs to the scope
            if (!isWorkspaceScope) {
                boolean found = false;
                for (int j = 0; j < scopeLength; j++) {
                    if (javaProject.getPath().equals(scopeProjectsAndJars[j])) {
                        found = true;
                        break;
                    }
                }
                if (!found)
                    continue;
            }
            // Get all project package fragment names
            this.nameLookup = ((JavaProject) projects[i]).newNameLookup(this.workingCopies);
            IPackageFragment[] packageFragments = this.nameLookup
                    .findPackageFragments(new String(pkgPattern.pkgName), false, true);
            int pLength = packageFragments == null ? 0 : packageFragments.length;
            // Report matches avoiding duplicate names
            for (int p = 0; p < pLength; p++) {
                IPackageFragment fragment = packageFragments[p];
                if (packages.addIfNotIncluded(fragment) == null)
                    continue;
                if (encloses(fragment)) {
                    IResource resource = fragment.getResource();
                    if (resource == null) // case of a file in an external jar
                        resource = javaProject.getProject();
                    try {
                        if (encloses(fragment)) {
                            SearchMatch match = new PackageDeclarationMatch(fragment, SearchMatch.A_ACCURATE,
                                    -1, -1, participant, resource);
                            report(match);
                        }
                    } catch (JavaModelException e) {
                        throw e;
                    } catch (CoreException e) {
                        throw new JavaModelException(e);
                    }
                }
            }
        }
    }
}

From source file:com.codenvy.ide.ext.java.server.javadoc.JavaDocLocations.java

License:Open Source License

private static void setProjectJavadocLocation(IJavaProject project, String url) throws CoreException {
    project.getProject().setPersistentProperty(PROJECT_JAVADOC, url);
}

From source file:com.codenvy.ide.ext.java.server.javadoc.JavaDocLocations.java

License:Open Source License

public static URL getProjectJavadocLocation(IJavaProject project) {
    if (!project.getProject().isAccessible()) {
        return null;
    }/*  w w w.ja  va 2s .co  m*/
    try {
        String prop = project.getProject().getPersistentProperty(PROJECT_JAVADOC);
        if (prop == null) {
            return null;
        }
        return parseURL(prop);
    } catch (CoreException e) {
        LOG.error(e.getMessage(), e);
    }
    return null;
}