Example usage for org.eclipse.jdt.core IPackageFragmentRoot getPath

List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getPath

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IPackageFragmentRoot getPath.

Prototype

IPath getPath();

Source Link

Document

Returns the path to the innermost resource enclosing this element.

Usage

From source file:org.eclipse.pde.api.tools.model.tests.ApiFilterStoreTests.java

License:Open Source License

@Override
protected void setUp() throws Exception {
    createProject(TESTING_PLUGIN_PROJECT_NAME, null);
    File projectSrc = SRC_LOC.toFile();
    assertTrue("the filter source dir must exist", projectSrc.exists()); //$NON-NLS-1$
    assertTrue("the filter source dir must be a directory", projectSrc.isDirectory()); //$NON-NLS-1$
    IJavaProject project = getTestingJavaProject(TESTING_PLUGIN_PROJECT_NAME);
    IPackageFragmentRoot srcroot = project
            .findPackageFragmentRoot(project.getProject().getFullPath().append("src")); //$NON-NLS-1$
    assertNotNull("the default src root must exist", srcroot); //$NON-NLS-1$
    FileUtils.importFileFromDirectory(projectSrc, srcroot.getPath(), new NullProgressMonitor());

    // Import the test .api_filters file
    File xmlsrc = XML_LOC.append(".api_filters").toFile(); //$NON-NLS-1$
    assertTrue("the filter xml dir must exist", xmlsrc.exists()); //$NON-NLS-1$
    assertTrue("the filter xml dir must be a file", !xmlsrc.isDirectory()); //$NON-NLS-1$
    assertNotNull("no project", project); //$NON-NLS-1$
    IProject project2 = project.getProject();
    IPath settings = project2.getFullPath().append(".settings"); //$NON-NLS-1$
    FileUtils.importFileFromDirectory(xmlsrc, settings, new NullProgressMonitor());
    IResource filters = project2.findMember("/.settings/.api_filters", true); //$NON-NLS-1$
    assertNotNull("the .api_filters file must exist in the testing project", filters); //$NON-NLS-1$
}

From source file:org.eclipse.pde.api.tools.model.tests.FilterStoreTests.java

License:Open Source License

@Override
protected void setUp() throws Exception {
    createProject(TESTING_PLUGIN_PROJECT_NAME, null);
    File projectSrc = SRC_LOC.toFile();
    assertTrue("the filter source dir must exist", projectSrc.exists()); //$NON-NLS-1$
    assertTrue(";the filter source dir must be a directory", projectSrc.isDirectory()); //$NON-NLS-1$
    IJavaProject project = getTestingJavaProject(TESTING_PLUGIN_PROJECT_NAME);
    IPackageFragmentRoot srcroot = project
            .findPackageFragmentRoot(project.getProject().getFullPath().append("src")); //$NON-NLS-1$
    assertNotNull("the default src root must exist", srcroot); //$NON-NLS-1$
    FileUtils.importFileFromDirectory(projectSrc, srcroot.getPath(), new NullProgressMonitor());

    // Import the test .api_filters file
    File xmlsrc = XML_LOC.append(".api_filters").toFile(); //$NON-NLS-1$
    assertTrue("the filter xml dir must exist", xmlsrc.exists()); //$NON-NLS-1$
    assertTrue("the filter xml dir must be a file", !xmlsrc.isDirectory()); //$NON-NLS-1$
    assertNotNull("no project", project); //$NON-NLS-1$
    IProject project2 = project.getProject();
    IPath settings = project2.getFullPath().append(".settings"); //$NON-NLS-1$
    FileUtils.importFileFromDirectory(xmlsrc, settings, new NullProgressMonitor());
    IResource filters = project2.findMember("/.settings/.api_filters", true); //$NON-NLS-1$
    assertNotNull("the .api_filters file must exist in the testing project", filters); //$NON-NLS-1$
}

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

License:Open Source License

/**
 * Adds a new source container specified by the container name to the source
 * path of the specified project/*from w  w w .  j av  a  2s.  c  o m*/
 * 
 * @param jproject
 * @param containerName
 * @return the package fragment root of the container name
 * @throws CoreException
 */
public static IPackageFragmentRoot addSourceContainer(IJavaProject jproject, String containerName)
        throws CoreException {
    IProject project = jproject.getProject();
    IPackageFragmentRoot root = jproject.getPackageFragmentRoot(addFolderToProject(project, containerName));
    IClasspathEntry cpe = JavaCore.newSourceEntry(root.getPath());
    addToClasspath(jproject, cpe);
    return root;
}

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

License:Open Source License

@Override
protected void setUp() throws Exception {
    super.setUp();
    createProject(TESTING_PROJECT_NAME, null);
    IJavaProject project = getTestingJavaProject(TESTING_PROJECT_NAME);
    assertNotNull("The java project must have been created", project); //$NON-NLS-1$
    IPackageFragmentRoot srcroot = ProjectUtils.addSourceContainer(project, ProjectUtils.SRC_FOLDER);
    assertNotNull("the src root must have been created", srcroot); //$NON-NLS-1$

    File src = new File(JAVADOC_SRC_DIR);
    assertTrue("the source dir must exist", src.exists()); //$NON-NLS-1$
    assertTrue("the source dir must be a directory", src.isDirectory()); //$NON-NLS-1$
    assertNotNull("the srcroot for the test java project must not be null", srcroot); //$NON-NLS-1$
    FileUtils.importFilesFromDirectory(src, srcroot.getPath().append("javadoc"), new NullProgressMonitor()); //$NON-NLS-1$

    ApiToolingSetupRefactoring refactoring = new ApiToolingSetupRefactoring();
    CompositeChange change = new CompositeChange("Test"); //$NON-NLS-1$
    createTagChanges(change, project, componentxml);
    refactoring.addChange(change);/* w ww  .j  a  v  a2s  .c  om*/
    performRefactoring(refactoring);
}

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

License:Open Source License

/**
 * Tests importing the java source for the Javadoc tag update tests
 *///from  w ww .  j a v  a  2 s  .c o m
public void testImportJavadocTestSource() {
    try {
        File dest = new File(JAVADOC_SRC_DIR);
        assertTrue("the source dir must exist", dest.exists()); //$NON-NLS-1$
        assertTrue("the source dir must be a directory", dest.isDirectory()); //$NON-NLS-1$
        IJavaProject project = getTestingJavaProject(TESTING_PROJECT_NAME);
        IPackageFragmentRoot srcroot = project.getPackageFragmentRoot(ProjectUtils.SRC_FOLDER);
        assertNotNull("the srcroot for the test java project must not be null", srcroot); //$NON-NLS-1$
        FileUtils.importFilesFromDirectory(dest, project.getPath().append(srcroot.getPath()).append("javadoc"), //$NON-NLS-1$
                new NullProgressMonitor());
        // try to look up a file to test if it worked
        IType type = project.findType("javadoc.JavadocTestClass1", new NullProgressMonitor()); //$NON-NLS-1$
        assertNotNull("the JavadocTestClass1 type should exist in the javadoc package", type); //$NON-NLS-1$
    } catch (Exception e) {
        fail(e.getMessage());
    }
}

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

License:Open Source License

/**
 * Tests importing the java source for the javadoc tag reading tests
 */// w  ww . j  a  v a  2 s .  c o  m
public void testImportClassesTestSource() {
    try {
        File dest = new File(JAVADOC_READ_SRC_DIR);
        assertTrue("the source dir must exist", dest.exists()); //$NON-NLS-1$
        assertTrue("the source dir must be a directory", dest.isDirectory()); //$NON-NLS-1$
        IJavaProject project = getTestingJavaProject(TESTING_PROJECT_NAME);
        IPackageFragmentRoot srcroot = project.getPackageFragmentRoot(ProjectUtils.SRC_FOLDER);
        assertNotNull("the srcroot for the test java project must not be null", srcroot); //$NON-NLS-1$
        FileUtils.importFilesFromDirectory(dest,
                project.getPath().append(srcroot.getPath()).append("a").append("b").append("c"), //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                new NullProgressMonitor());
    } catch (Exception e) {
        fail(e.getMessage());
    }
}

From source file:org.eclipse.pde.internal.core.SearchablePluginsManager.java

License:Open Source License

private IPackageFragmentRoot findPackageFragmentRoot(IPath jarPath) {
    IJavaProject jProject = getProxyProject();
    if (jProject != null) {
        try {/* w ww .j ava  2s .c  om*/
            IPackageFragmentRoot[] roots = jProject.getAllPackageFragmentRoots();
            for (int i = 0; i < roots.length; i++) {
                IPackageFragmentRoot root = roots[i];
                IPath path = root.getPath();
                if (path.equals(jarPath))
                    return root;

            }
        } catch (JavaModelException e) {
        }
    }

    // Find in other plug-in (and fragments) projects dependencies
    IPluginModelBase[] pluginModels = PluginRegistry.getWorkspaceModels();
    for (int i = 0; i < pluginModels.length; i++) {
        IProject project = pluginModels[i].getUnderlyingResource().getProject();
        IJavaProject javaProject = JavaCore.create(project);
        try {
            IPackageFragmentRoot[] roots = javaProject.getAllPackageFragmentRoots();
            for (int j = 0; j < roots.length; j++) {
                IPackageFragmentRoot root = roots[j];
                IPath path = root.getPath();
                if (path.equals(jarPath))
                    return root;
            }
        } catch (JavaModelException e) {
        }
    }

    return null;
}

From source file:org.eclipse.pde.internal.ui.views.plugins.ImportActionGroup.java

License:Open Source License

private static IPluginModelBase getModel(Object next) {
    IPluginModelBase model = null;/*from  w  ww  .  j  a  v  a2  s  . co  m*/
    if (next instanceof IPluginModelBase) {
        model = (IPluginModelBase) next;
    } else if (next instanceof IPluginBase) {
        model = ((IPluginBase) next).getPluginModel();
    } else if (next instanceof IPluginExtension) {
        model = ((IPluginExtension) next).getPluginModel();
    } else if (next instanceof IPluginExtensionPoint) {
        model = ((IPluginExtensionPoint) next).getPluginModel();
    } else if (next instanceof BundleDescription) {
        model = PDECore.getDefault().getModelManager().findModel((BundleDescription) next);
    } else if (next instanceof BundleSpecification) {
        // Required for contents of Target Platform State View
        BundleDescription desc = (BundleDescription) ((BundleSpecification) next).getSupplier();
        if (desc != null) {
            model = PDECore.getDefault().getModelManager().findModel(desc);
        }
    } else if (next instanceof IPackageFragmentRoot) {
        // Required for context menu on PDE classpath container entries
        IPackageFragmentRoot root = (IPackageFragmentRoot) next;
        if (root.isExternal()) {
            String path = root.getPath().toOSString();
            IPluginModelBase[] externalModels = PDECore.getDefault().getModelManager().getExternalModels();
            for (int i = 0; i < externalModels.length; i++) {
                if (path.equals(externalModels[i].getInstallLocation())) {
                    return externalModels[i];
                }
            }
        }
    }
    return model;

}

From source file:org.eclipse.rap.ui.internal.launch.rwt.tests.TestProject.java

License:Open Source License

private void initializeJavaProject() throws CoreException {
    initializeProject();/*  www  . j  a v  a 2  s.  co m*/
    if (!isJavaProjectCreated()) {
        addNature(JavaCore.NATURE_ID);
        javaProject = JavaCore.create(project);

        IFolder binFolder = createFolder(DEFAULT_OUTPUT_FOLDER);
        javaProject.setOutputLocation(binFolder.getFullPath(), newProgressMonitor());

        IPath jrePath = JavaRuntime.getDefaultJREContainerEntry().getPath();
        IClasspathEntry jreEntry = JavaCore.newContainerEntry(jrePath);
        javaProject.setRawClasspath(new IClasspathEntry[] { jreEntry }, newProgressMonitor());

        IFolder sourceFolder = createFolder(DEFAULT_SOURCE_FOLDER);
        IPackageFragmentRoot packageRoot = javaProject.getPackageFragmentRoot(sourceFolder);
        IClasspathEntry entry = JavaCore.newSourceEntry(packageRoot.getPath());
        addClasspathEntry(entry);

        waitForAutoBuild();
    }
}

From source file:org.eclipse.recommenders.internal.coordinates.rcp.EclipseDependencyListener.java

License:Open Source License

public static Set<IPackageFragmentRoot> detectJREPackageFragementRoots(final IJavaProject javaProject) {
    // Please note that this is merely a heuristic to detect if a Jar is part of the JRE or not:
    // All Jars in the JRE_Container which are not located in the ext folder are considered part of the JRE.
    Set<IPackageFragmentRoot> jreRoots = new HashSet<IPackageFragmentRoot>();
    try {/*from   w  w w  .jav  a 2 s  .com*/
        for (IClasspathEntry entry : javaProject.getRawClasspath()) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                if (entry.getPath().toString().contains("org.eclipse.jdt.launching.JRE_CONTAINER")) { //$NON-NLS-1$
                    for (IPackageFragmentRoot packageFragmentRoot : javaProject
                            .findPackageFragmentRoots(entry)) {
                        if (!packageFragmentRoot.getPath().toFile().getParentFile().getName().equals("ext")) { //$NON-NLS-1$
                            jreRoots.add(packageFragmentRoot);
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        Logs.log(LogMessages.ERROR_FAILED_TO_DETECT_PROJECT_JRE, e, javaProject);
    }
    return jreRoots;
}