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.pde.api.tools.util.tests.ApiBaselineManagerTests.java

License:Open Source License

/**
 * Tests that the output folder settings for a source folder cause the class
 * file containers to be updated/*from w w w .  j  a va2s  .c  o  m*/
 */
public void testWPUpdateOutputFolderSrcFolderChanged() throws Exception {
    IJavaProject project = getTestingProject();
    IApiComponent component = getWorkspaceBaseline().getApiComponent(project.getElementName());
    assertNotNull("the workspace component must exist", component); //$NON-NLS-1$
    int before = component.getApiTypeContainers().length;

    ProjectUtils.addFolderToProject(project.getProject(), "bin3"); //$NON-NLS-1$
    IContainer container = ProjectUtils.addFolderToProject(project.getProject(), "src2"); //$NON-NLS-1$
    // add to bundle class path
    IBundleProjectService service = ProjectUtils.getBundleProjectService();
    IBundleClasspathEntry next = service.newBundleClasspathEntry(new Path("src2"), new Path("bin3"), //$NON-NLS-1$//$NON-NLS-2$
            new Path("next.jar")); //$NON-NLS-1$
    ProjectUtils.addBundleClasspathEntry(project.getProject(), next);
    waitForAutoBuild();

    // retrieve updated component
    component = getWorkspaceBaseline().getApiComponent(project.getElementName());
    assertTrue("there must be one more container after the change", //$NON-NLS-1$
            before < component.getApiTypeContainers().length);
    IPackageFragmentRoot root = project.getPackageFragmentRoot(container);
    assertTrue("the class file container for src2 must be 'bin3'", //$NON-NLS-1$
            "bin3".equals(root.getRawClasspathEntry().getOutputLocation().toFile().getName())); //$NON-NLS-1$
}

From source file:org.eclipse.pde.api.tools.util.tests.ApiBaselineManagerTests.java

License:Open Source License

/**
 * Tests that adding a package does not update the workspace baseline
 *///from  w  w  w.j a va  2s.c  o  m
public void testWPUpdatePackageAdded() throws Exception {
    IJavaProject project = getTestingProject();
    assertNotNull("The testing project must exist", project); //$NON-NLS-1$

    // add the package
    assertTestPackage(project,
            new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute(), "a.test1.c.d"); //$NON-NLS-1$

    IApiDescription desc = getTestProjectApiDescription();
    assertNotNull("the testing project api description must exist", desc); //$NON-NLS-1$
    IApiAnnotations annot = desc.resolveAnnotations(Factory.packageDescriptor("a.test1.c.d")); //$NON-NLS-1$
    assertNotNull("the annotations for package " + TESTING_PACKAGE + " should exist", annot); //$NON-NLS-1$ //$NON-NLS-2$
}

From source file:org.eclipse.pde.api.tools.util.tests.ApiBaselineManagerTests.java

License:Open Source License

/**
 * Tests that removing a package updates the workspace baseline This test
 * removes the a.b.c package being used in all tests thus far, and should be
 * run last// www .j a v  a2s . co m
 */
public void testWPUpdatePackageRemoved() throws Exception {
    IJavaProject project = getTestingProject();
    assertNotNull("The testing project must exist", project); //$NON-NLS-1$

    // add the package
    IPath srcroot = new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute();
    IPackageFragment fragment = assertTestPackage(project, srcroot, "a.test2"); //$NON-NLS-1$
    assertNotNull("the package " + TESTING_PACKAGE + " must exist", fragment); //$NON-NLS-1$ //$NON-NLS-2$

    // remove the package
    fragment.delete(true, new NullProgressMonitor());

    IApiDescription desc = getTestProjectApiDescription();
    assertNotNull("the testing project api description must exist", desc); //$NON-NLS-1$
    IApiAnnotations annot = desc.resolveAnnotations(Factory.packageDescriptor("a.test2")); //$NON-NLS-1$
    assertNull("the annotations for package " + TESTING_PACKAGE + " should not exist", annot); //$NON-NLS-1$ //$NON-NLS-2$
}

From source file:org.eclipse.pde.api.tools.util.tests.ApiBaselineManagerTests.java

License:Open Source License

/**
 * Tests that an exported package addition in the PDE model is reflected in
 * the workspace api baseline//from   ww  w  . j a v  a 2  s.  c  o  m
 */
public void testWPUpdateExportPackageAdded() throws Exception {
    IJavaProject project = getTestingProject();
    assertNotNull("The testing project must exist", project); //$NON-NLS-1$

    // add package
    assertTestPackage(project,
            new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute(), "export1"); //$NON-NLS-1$

    // update
    setPackageToApi(project, "export1"); //$NON-NLS-1$
    IApiAnnotations annot = getTestProjectApiDescription()
            .resolveAnnotations(Factory.packageDescriptor("export1")); //$NON-NLS-1$
    assertNotNull("there must be an annotation for the new exported package", annot); //$NON-NLS-1$
    assertTrue("the newly exported package must be API visibility", //$NON-NLS-1$
            annot.getVisibility() == VisibilityModifiers.API);
}

From source file:org.eclipse.pde.api.tools.util.tests.ApiBaselineManagerTests.java

License:Open Source License

/**
 * Tests that changing a directive to x-internal on an exported package
 * causes the workspace api baseline to be updated
 */// w ww.j  a v  a 2s . co m
public void testWPUPdateExportPackageDirectiveChangedToInternal() throws Exception {
    IJavaProject project = getTestingProject();
    assertNotNull("The testing project must exist", project); //$NON-NLS-1$

    // add package
    assertTestPackage(project,
            new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute(), "export1"); //$NON-NLS-1$

    // export the package
    ProjectUtils.addExportedPackage(project.getProject(), "export1", true, null); //$NON-NLS-1$

    // check the description
    IApiAnnotations annot = getTestProjectApiDescription()
            .resolveAnnotations(Factory.packageDescriptor("export1")); //$NON-NLS-1$
    assertNotNull("there must be an annotation for the new exported package", annot); //$NON-NLS-1$
    assertTrue("the changed exported package must be PRIVATE visibility", //$NON-NLS-1$
            annot.getVisibility() == VisibilityModifiers.PRIVATE);
}

From source file:org.eclipse.pde.api.tools.util.tests.ApiBaselineManagerTests.java

License:Open Source License

/**
 * Tests that an exported package removal in the PDE model is reflected in
 * the workspace api baseline//from w  w  w . j  a v  a2s  .co m
 */
public void testWPUpdateExportPackageRemoved() throws Exception {
    IJavaProject project = getTestingProject();
    assertNotNull("The testing project must exist", project); //$NON-NLS-1$

    // add package
    assertTestPackage(project,
            new Path(project.getElementName()).append(ProjectUtils.SRC_FOLDER).makeAbsolute(), "export1"); //$NON-NLS-1$

    setPackageToApi(project, "export1"); //$NON-NLS-1$
    IApiAnnotations annot = getTestProjectApiDescription()
            .resolveAnnotations(Factory.packageDescriptor("export1")); //$NON-NLS-1$
    assertNotNull("there must be an annotation for the new exported package", annot); //$NON-NLS-1$
    assertTrue("the newly exported package must be API visibility", //$NON-NLS-1$
            annot.getVisibility() == VisibilityModifiers.API);

    // remove exported packages
    IBundleProjectService service = ProjectUtils.getBundleProjectService();
    IBundleProjectDescription description = service.getDescription(project.getProject());
    description.setPackageExports(null);
    description.apply(null);

    // check the API description
    annot = getTestProjectApiDescription().resolveAnnotations(Factory.packageDescriptor("export1")); //$NON-NLS-1$
    assertNotNull("should still be an annotation for the package", annot); //$NON-NLS-1$
    assertTrue("unexported package must be private", VisibilityModifiers.isPrivate(annot.getVisibility())); //$NON-NLS-1$
}

From source file:org.eclipse.pde.ds.internal.annotations.DSAnnotationCompilationParticipant.java

License:Open Source License

@Override
public int aboutToBuild(IJavaProject project) {
    if (debug.isDebugging())
        debug.trace(String.format("About to build project: %s", project.getElementName())); //$NON-NLS-1$

    int result = READY_FOR_BUILD;

    int[] retval = new int[1];
    ProjectState state = getState(project, retval);
    result = retval[0];//from w ww  .ja  va 2 s  .c  om

    processingContext.put(project, new ProjectContext(state));

    if (state.getFormatVersion() != ProjectState.FORMAT_VERSION) {
        state.setFormatVersion(ProjectState.FORMAT_VERSION);
        result = NEEDS_FULL_BUILD;
    }

    String path = Platform.getPreferencesService().getString(Activator.PLUGIN_ID, Activator.PREF_PATH,
            Activator.DEFAULT_PATH,
            new IScopeContext[] { new ProjectScope(project.getProject()), InstanceScope.INSTANCE });
    if (!path.equals(state.getPath())) {
        state.setPath(path);
        result = NEEDS_FULL_BUILD;
    }

    String errorLevelStr = Platform.getPreferencesService().getString(Activator.PLUGIN_ID,
            Activator.PREF_VALIDATION_ERROR_LEVEL, ValidationErrorLevel.error.toString(),
            new IScopeContext[] { new ProjectScope(project.getProject()), InstanceScope.INSTANCE });
    ValidationErrorLevel errorLevel = getEnumValue(errorLevelStr, ValidationErrorLevel.class,
            ValidationErrorLevel.error);

    if (errorLevel != state.getErrorLevel()) {
        state.setErrorLevel(errorLevel);
        result = NEEDS_FULL_BUILD;
    }

    String missingUnbindMethodLevelStr = Platform.getPreferencesService().getString(Activator.PLUGIN_ID,
            Activator.PREF_MISSING_UNBIND_METHOD_ERROR_LEVEL, errorLevelStr,
            new IScopeContext[] { new ProjectScope(project.getProject()), InstanceScope.INSTANCE });
    ValidationErrorLevel missingUnbindMethodLevel = getEnumValue(missingUnbindMethodLevelStr,
            ValidationErrorLevel.class, errorLevel);

    if (missingUnbindMethodLevel != state.getMissingUnbindMethodLevel()) {
        state.setMissingUnbindMethodLevel(missingUnbindMethodLevel);
        result = NEEDS_FULL_BUILD;
    }

    return result;
}

From source file:org.eclipse.pde.ds.internal.annotations.DSAnnotationCompilationParticipant.java

License:Open Source License

@Override
public void buildFinished(IJavaProject project) {
    ProjectContext projectContext = processingContext.remove(project);
    if (projectContext != null) {
        ProjectState state = projectContext.getState();
        // check if unprocessed CUs still exist; if not, their mapped files are now abandoned
        HashSet<String> abandoned = new HashSet<>(projectContext.getAbandoned());
        for (String cuKey : projectContext.getUnprocessed()) {
            boolean exists = false;
            try {
                IJavaElement cu = project.findElement(new Path(cuKey));
                IResource file;/*from w  w  w .  j  a va2  s  .  c  om*/
                if (cu != null && cu.getElementType() == IJavaElement.COMPILATION_UNIT
                        && (file = cu.getResource()) != null && file.exists())
                    exists = true;
            } catch (JavaModelException e) {
                Activator.log(e);
            }

            if (!exists) {
                if (debug.isDebugging())
                    debug.trace(String.format("Mapped CU %s no longer exists.", cuKey)); //$NON-NLS-1$

                Collection<String> dsKeys = state.removeMappings(cuKey);
                if (dsKeys != null)
                    abandoned.addAll(dsKeys);
            }
        }

        // retain abandoned files that are still mapped elsewhere
        HashSet<String> retained = new HashSet<>();
        for (String cuKey : state.getCompilationUnits()) {
            Collection<String> dsKeys = state.getModelFiles(cuKey);
            if (dsKeys != null)
                retained.addAll(dsKeys);
        }

        abandoned.removeAll(retained);

        if (projectContext.isChanged()) {
            try {
                saveState(project.getProject(), state);
            } catch (IOException e) {
                Activator.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error saving file mappings.", e)); //$NON-NLS-1$
            }
        }

        // delete all abandoned files
        ArrayList<IStatus> deleteStatuses = new ArrayList<>(2);
        for (String dsKey : abandoned) {
            IPath path = Path.fromPortableString(dsKey);

            if (debug.isDebugging())
                debug.trace(String.format("Deleting %s", path)); //$NON-NLS-1$

            IFile file = PDEProject.getBundleRelativeFile(project.getProject(), path);
            if (file.exists()) {
                try {
                    file.delete(true, null);
                } catch (CoreException e) {
                    deleteStatuses.add(e.getStatus());
                }
            }
        }

        if (!deleteStatuses.isEmpty())
            Activator.log(new MultiStatus(Activator.PLUGIN_ID, 0,
                    deleteStatuses.toArray(new IStatus[deleteStatuses.size()]),
                    "Error deleting generated files.", null)); //$NON-NLS-1$

        if (!retained.isEmpty() || !abandoned.isEmpty())
            updateProject(project.getProject(), retained, abandoned);
    }

    if (debug.isDebugging())
        debug.trace(String.format("Build finished for project: %s", project.getElementName())); //$NON-NLS-1$
}

From source file:org.eclipse.rap.ui.internal.launch.rwt.delegate.RWTLaunchDelegate_Test.java

License:Open Source License

public void testGetJavaProject() throws CoreException {
    TestProject testProject = new TestProject();
    IJavaProject javaProject = testProject.getJavaProject();
    rwtLaunchConfig.setProjectName(javaProject.getElementName());

    IJavaProject returnedJavaProject = launchDelegate.getJavaProject(launchConfig);

    assertEquals(javaProject, returnedJavaProject);
}

From source file:org.eclipse.rap.ui.internal.launch.rwt.tab.ProjectSection.java

License:Open Source License

private void handleSelectJavaProject() {
    IJavaProject project = selectJavaProject();
    if (project != null) {
        String projectName = project.getElementName();
        txtProject.setText(projectName);
    }//ww w . ja  va  2 s  .co m
}