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

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

Introduction

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

Prototype

String getElementName();

Source Link

Document

Returns the name of this element.

Usage

From source file:org.eclipse.recommenders.codesearch.rcp.index.ui.IndexUpdateService.java

License:Open Source License

@Subscribe
public void onEvent(final JavaProjectOpened event) {
    if (PreferencePage.isActive() && backgroundIndexerActive) {
        final IJavaProject project = event.project;
        final IProject[] projects = { project.getProject() };
        final Workspace workspace = cast(projects[0].getWorkspace());
        final String title = "Indexing " + project.getElementName();
        new IndexerJob(title, projects, indexer, workspace);
    }//from w w w. j av  a  2  s . c  om
}

From source file:org.eclipse.recommenders.coordinates.rcp.DependencyInfos.java

License:Open Source License

public static DependencyInfo createDependencyInfoForProject(final IJavaProject project) {
    File file = project.getProject().getLocation().toFile();
    return new DependencyInfo(file, DependencyType.PROJECT,
            ImmutableMap.of(PROJECT_NAME, project.getElementName()));
}

From source file:org.eclipse.recommenders.internal.models.rcp.ProjectCoordinateProvider.java

License:Open Source License

private Optional<DependencyInfo> extractDependencyInfo(IJavaProject javaProject) {
    File location = getLocation(javaProject).orNull();
    DependencyInfo request = new DependencyInfo(location, PROJECT,
            ImmutableMap.of(PROJECT_NAME, javaProject.getElementName()));
    return of(request);
}

From source file:org.eclipse.stardust.modeling.transformation.messaging.modeling.application.transformation.launch.TransformationConfigurationTab.java

License:Open Source License

private void browseProjects() {
    IJavaProject[] projects;/*from ww  w. j ava 2s .  c om*/

    try {
        projects = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects();
    } catch (JavaModelException e) {
        projects = new IJavaProject[0];
    }

    ILabelProvider labelProvider = new JavaScriptElementLabelProvider(
            JavaScriptElementLabelProvider.SHOW_DEFAULT);
    ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), labelProvider);
    dialog.setTitle(Modeling_Messages.DIA_MSG_TRANS_RUN_CFG);
    dialog.setElements(projects);

    String projectName = projectNameText.getText();

    if (!StringUtils.isEmpty(projectName)) {
        IJavaProject javaProject = JavaCore
                .create(ResourcesPlugin.getWorkspace().getRoot().getProject(projectName));
        if (javaProject != null) {
            dialog.setInitialSelections(new Object[] { javaProject });
        }
    }

    if (dialog.open() == Window.OK) {
        IJavaProject javaProject = (IJavaProject) dialog.getFirstResult();

        if (null != javaProject) {
            updateLaunchConfigurationDialog();
            projectNameText.setText(javaProject.getElementName());
            processModelText.setText(""); //$NON-NLS-1$
            transformationApplicationViewer.setInput(null);
            tableViewer.setInput(null);
        } else {
            projectNameText.setText(""); //$NON-NLS-1$
        }
    }
    updateLaunchConfigurationDialog();
}

From source file:org.eclipse.stardust.modeling.validation.util.TypeRequestor.java

License:Open Source License

private IType getFileIType(IJavaModel model, char[] packageName, String qualifiedName, String path)
        throws JavaModelException {
    IJavaProject project = null;
    IJavaProject[] projects = model.getJavaProjects();
    for (int i = 0; i < projects.length; i++) {
        if (path.startsWith(projects[i].getElementName(), 1)) {
            if (project == null || projects[i].getElementName().length() > project.getElementName().length()) {
                project = projects[i];/*from ww  w.j a  v a 2s. c  om*/
            }
        }
    }

    if (project != null) {
        return project.findType(String.valueOf(packageName), qualifiedName);
    }
    return null;
}

From source file:org.eclipse.virgo.ide.export.BundleExportUtils.java

License:Open Source License

private static void setManifestFile(IJavaProject project, JarPackageData jarPackage, Shell shell,
        List<IStatus> warnings) {
    IResource manifest = getOutputManifestFile(project);
    if (manifest != null) {
        File manifestFile = manifest.getLocation().toFile();
        boolean exists = manifestFile.exists();
        if (exists) {
            BufferedReader reader;
            try {
                reader = new BufferedReader(new FileReader(manifestFile));
                char charactor = 'a';
                while (reader.ready()) {
                    charactor = (char) reader.read();
                }//from  w  w w .  ja  v a2s  .c om

                if (charactor != '\n') {
                    warnings.add(new Status(IStatus.WARNING, ServerExportPlugin.PLUGIN_ID,
                            "Manifest file for project " + project.getElementName()
                                    + " is missing a '\\n' at the end of file. The exported bundle might not work properly."));
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            jarPackage.setGenerateManifest(false);
            jarPackage.setManifestLocation(manifest.getFullPath());
        } else {
            jarPackage.setGenerateManifest(true);
        }
    } else {
        jarPackage.setGenerateManifest(true);
    }
}

From source file:org.eclipse.virgo.ide.jdt.internal.core.classpath.ServerClasspathContainer.java

License:Open Source License

/**
 * Creates the {@link DependencyLocator} to be used for resolution.
 *
 * @param javaProject the {@link IJavaProject} to resolve dependencies for.
 * @return a configured and ready to use {@link DependencyLocator}
 * @throws IOException/*from  w ww  .  j av a 2s. com*/
 */
private IDependencyLocator createDependencyLocator(IJavaProject javaProject) throws CoreException, IOException {
    final Set<String> workspaceBundles = new LinkedHashSet<String>();

    // First add projects that belong to the same par project
    for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
        Set<String> parBundles = new HashSet<String>();
        if (FacetUtils.isParProject(project)) {
            boolean hasBundle = false;
            Par par = FacetUtils.getParDefinition(project);
            if (par != null && par.getBundle() != null) {
                for (Bundle bundle : par.getBundle()) {
                    if (bundle.getSymbolicName().equals(javaProject.getElementName())) {
                        hasBundle = true;
                    }
                    parBundles.add(bundle.getSymbolicName());
                }
            }

            if (hasBundle) {
                for (String bundleName : parBundles) {
                    IProject bundleProject = ResourcesPlugin.getWorkspace().getRoot().getProject(bundleName);
                    addWorkspaceBundle(workspaceBundles, bundleProject);
                }

                // Add any nested or linked jars from the PAR
                project.accept(new IResourceVisitor() {

                    public boolean visit(IResource resource) throws CoreException {
                        if (resource instanceof IFile && resource.getFileExtension().equals("jar")) {
                            IPath jarLocation = resource.getRawLocation();
                            IPath resolvedJarLocation = JavaCore.getResolvedVariablePath(jarLocation);
                            if (resolvedJarLocation != null) {
                                workspaceBundles.add(resolvedJarLocation.removeLastSegments(1).toString()
                                        + File.separator + "{bundle}");
                            } else {
                                workspaceBundles.add(jarLocation.removeLastSegments(1).toString()
                                        + File.separator + "{bundle}");
                            }
                        }
                        return true;
                    }
                }, IResource.DEPTH_ONE, false);

            }
        }
    }

    // Secondly add all explicit dependent projects
    for (IProject project : javaProject.getProject().getDescription().getReferencedProjects()) {
        addWorkspaceBundle(workspaceBundles, project);
    }

    // Thirdly add the current plugin to resolve exported packages from the same bundle
    addWorkspaceBundle(workspaceBundles, javaProject.getProject());

    // Store targeted runtimes to display in the description
    this.serverRuntimes = ServerUtils.getTargettedRuntimes(javaProject.getProject());

    // Adjust the last modified date on the META-INF and root folder
    ClasspathUtils.adjustLastModifiedDate(javaProject, false);
    ClasspathUtils.adjustLastModifiedDate(javaProject, true);

    // Create DependencyLocator with path to server.config and server.profile
    return ServerUtils.createDependencyLocator(javaProject.getProject(),
            workspaceBundles.toArray(new String[workspaceBundles.size()]));
}

From source file:org.eclipse.virgo.ide.jdt.internal.core.classpath.ServerClasspathContainerUpdateJob.java

License:Open Source License

/**
 * Private constructor to create an instance
 *
 * @param javaProject the {@link IJavaProject} the class path container should be updated for
 * @param types the change types happened to the manifest
 *///from  ww  w .  j av a 2  s .  c  om
private ServerClasspathContainerUpdateJob(IJavaProject javaProject, Set<Type> types) {
    super("Updating bundle classpath container for project '" + javaProject.getElementName() + "'");
    this.javaProject = javaProject;
    this.types = types;
}

From source file:org.eclipse.virgo.ide.jdt.internal.core.util.ClasspathUtils.java

License:Open Source License

/**
 * Triggers an class path container update on depending {@link IJavaProject}s.
 *///from   ww w .j  a va2  s  . c  om
private static void updateClasspathContainerForDependingBundles(IJavaProject javaProject) {

    BundleManifest updatedBundleManifest = BundleManifestCorePlugin.getBundleManifestManager()
            .getBundleManifest(javaProject);
    Set<String> updatedPackageExports = BundleManifestCorePlugin.getBundleManifestManager()
            .getPackageExports(javaProject);

    if (updatedBundleManifest != null && updatedBundleManifest.getBundleSymbolicName() != null) {
        String bundleSymbolicName = updatedBundleManifest.getBundleSymbolicName().getSymbolicName();
        for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
            try {

                // Only dm server bundle projects are of interest
                if (!javaProject.getProject().equals(project) && FacetUtils.isBundleProject(project)) {

                    IJavaProject jp = JavaCore.create(project);
                    BundleManifest manifest = BundleManifestCorePlugin.getBundleManifestManager()
                            .getBundleManifest(jp);

                    boolean refreshClasspath = false;
                    if (manifest != null) {

                        // Check for Require-Bundle dependency
                        if (manifest.getRequireBundle() != null) {
                            for (RequiredBundle requiredBundle : manifest.getRequireBundle()
                                    .getRequiredBundles()) {
                                if (bundleSymbolicName != null
                                        && bundleSymbolicName.equals(requiredBundle.getBundleSymbolicName())) {
                                    refreshClasspath = true;
                                    break;
                                }
                            }
                        }

                        // Check for export -> import package dependency
                        if (manifest.getImportPackage() != null) {
                            for (ImportedPackage packageImport : manifest.getImportPackage()
                                    .getImportedPackages()) {
                                if (updatedPackageExports.contains(packageImport.getPackageName())) {
                                    refreshClasspath = true;
                                    break;
                                }
                            }
                        }

                        // Check for explicit project dependencies
                        for (String requiredProjectName : jp.getRequiredProjectNames()) {
                            if (requiredProjectName.equals(javaProject.getElementName())) {
                                refreshClasspath = true;
                                break;
                            }
                        }

                        // Schedule class path container update
                        if (refreshClasspath) {
                            ServerClasspathContainerUpdateJob.scheduleClasspathContainerUpdateJob(jp,
                                    BundleManifestManager.IMPORTS_CHANGED);
                        }
                    }
                }
            } catch (Exception e) {
                JdtCorePlugin.log(e);
            }
        }
    }
}

From source file:org.eclipse.vjet.eclipse.javalaunch.utils.SourcePathUtil.java

License:Open Source License

/**
 * Creates a string list of the source paths needed to build in this project.
 * @param launchProject/* www  . ja v  a  2s . c  o m*/
 * @return 
 * @throws CoreException
 */
public static String getSourcePathString(IProject launchProject) throws CoreException {

    IJavaProject javaProject = EclipseResourceUtils.getJavaProject(launchProject);
    List<File> sourcePaths = new ArrayList<File>(100);

    if (javaProject != null) {

        // Create a list to store all the projects
        Map<String, IJavaProject> transitiveClosureProjectList = new LinkedHashMap<String, IJavaProject>();
        Map<String, IPath> transitiveLibrary = new LinkedHashMap<String, IPath>();

        // Start with the passed in project
        transitiveClosureProjectList.put(javaProject.getElementName(), javaProject);

        // Get the transitive clousure of all the projects
        EclipseResourceUtils.getTransitiveClosureDependencies(javaProject, transitiveClosureProjectList,
                transitiveLibrary);

        IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();

        // Add all the source paths of all the projects
        for (IJavaProject project : transitiveClosureProjectList.values()) {

            IClasspathEntry[] classPathEntries = project.getResolvedClasspath(true);

            EclipseResourceUtils.getProjectSourcePaths(sourcePaths, workspaceRoot, classPathEntries);

        }
        for (IPath path : transitiveLibrary.values()) {
            sourcePaths.add(path.toFile());
        }
    } else {
        return "";
    }

    // Convert to semi-colon delimeted string
    StringBuilder sb = new StringBuilder(512);
    for (File sourcePath : sourcePaths) {

        sb.append(sourcePath.getAbsolutePath());
        sb.append(File.pathSeparator);

    }

    // Return the semi-colon list minus the last semi-colon
    return sb.substring(0, sb.length() - 1);
}