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:com.ecfeed.ui.editor.ModelEditor.java

License:Open Source License

@Override
public IPackageFragmentRoot getPackageFragmentRoot() {
    if (!isProjectAvailable()) {
        return null;
    }/*w ww.j a v a  2 s  .  c  o m*/
    try {
        if (getProject().hasNature(JavaCore.NATURE_ID)) {
            IJavaProject javaProject = JavaCore.create(getProject());
            IPath path = getPath();
            if (javaProject != null) {
                for (IPackageFragmentRoot root : javaProject.getPackageFragmentRoots()) {
                    if (root.getPath().isPrefixOf(path)) {
                        return root;
                    }
                }
            }
        }
    } catch (CoreException e) {
        SystemLogger.logCatch(e.getMessage());
    }
    return null;
}

From source file:com.github.ko2ic.plugin.eclipse.taggen.core.ui.components.combo.OutputFolderCombo.java

License:Open Source License

public OutputFolderCombo(Composite parent, int style) {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot root = workspace.getRoot();
    IProject[] projects = root.getProjects();

    for (IProject project : projects) {
        try {//  ww w .  j ava 2  s  .c o m
            IJavaProject javaProject = JavaCore.create(project);
            IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
            for (IPackageFragmentRoot pRoot : roots) {
                if (pRoot.getKind() == IPackageFragmentRoot.K_SOURCE) {
                    outputFolders.add(pRoot.getPath().removeFirstSegments(1).toOSString());
                }
            }
        } catch (JavaModelException e) {
            throw Throwables.propagate(new SystemException(e));
        }
    }

    outputFolderCombo = new Combo(parent, style);
}

From source file:com.google.appengine.eclipse.core.properties.GaeProjectProperties.java

License:Open Source License

public static List<IPath> getOrmEnhancementInclusionPatterns(IProject project) {
    List<IPath> patterns = new ArrayList<IPath>();

    IEclipsePreferences prefs = getProjectProperties(project);
    String rawPropVal = prefs.get(ORM_ENHANCEMENT_INCLUSIONS, null);
    if (rawPropVal == null) {
        // If we haven't set this property yet, default to including all Java src
        IJavaProject javaProject = JavaCore.create(project);
        try {/*from  www .  ja v  a2  s .  c o  m*/
            for (IPackageFragmentRoot pkgRoot : javaProject.getAllPackageFragmentRoots()) {
                if (pkgRoot.getKind() == IPackageFragmentRoot.K_SOURCE) {
                    // Only include src roots in this project
                    if (javaProject.equals(pkgRoot.getAncestor(IJavaElement.JAVA_PROJECT))) {
                        // Get project-relative path to source root
                        IPath pattern = pkgRoot.getPath().removeFirstSegments(1).makeRelative()
                                .addTrailingSeparator();
                        patterns.add(pattern);
                    }
                }
            }
        } catch (JavaModelException e) {
            AppEngineCorePluginLog.logError(e);
        }
    } else {
        patterns = PropertiesUtilities.deserializePaths(rawPropVal);
    }

    return patterns;
}

From source file:com.google.appengine.eclipse.webtools.facet.AbstractJpaFacetHelper.java

License:Open Source License

private static void copyJpaLibraryToWebInf(IJavaProject javaProject)
        throws CoreException, FileNotFoundException {
    IProject project = javaProject.getProject();
    if (!WebAppUtilities.hasManagedWarOut(project)) {
        // Nothing to do if project war directory is not managed
        return;//  w w  w . ja va 2 s . c  o  m
    }

    // Get WEB-INF/lib folder (create if it doesn't exist)
    IFolder webInfLibFolder = WebAppUtilities.getWebInfLib(project);
    ResourceUtils.createFolderStructure(project, webInfLibFolder.getProjectRelativePath());

    // Copy jars to WEB-INF/lib
    List<IClasspathEntry> cpes = ClasspathUtil.getClasspathEntries(project,
            ProjectFacetsManager.getProjectFacet(FACET_JPT_JPA));
    for (IClasspathEntry cpe : cpes) {
        for (IPackageFragmentRoot fragment : javaProject.findPackageFragmentRoots(cpe)) {
            File srcFile = fragment.getPath().toFile();
            IFile destFile = webInfLibFolder.getFile(srcFile.getName());
            if (!destFile.exists()) {
                destFile.create(new FileInputStream(srcFile), true, null);
            }
        }
    }
}

From source file:com.google.gdt.eclipse.appengine.rpc.util.JavaUtils.java

License:Open Source License

public static String getPackageFragmentRootText(IPackageFragmentRoot packageFragmentRoot) {
    return (packageFragmentRoot == null) ? "" : packageFragmentRoot.getPath().makeRelative().toString(); //$NON-NLS-1$
}

From source file:com.google.gdt.eclipse.core.ClasspathUtilities.java

License:Open Source License

public static IClasspathEntry getNullableRawClasspathEntryForPackageFragmentRoot(IPackageFragmentRoot root)
        throws JavaModelException {

    IClasspathEntry rawEntry = null;//from  w w w  .j av a2 s . com
    {
        JavaProject project = (JavaProject) root.getJavaProject();
        // force the reverse rawEntry cache to be populated
        project.getResolvedClasspath(true);
        @SuppressWarnings("rawtypes")
        Map rootPathToRawEntries = project.getPerProjectInfo().rootPathToRawEntries;
        if (rootPathToRawEntries != null) {
            rawEntry = (IClasspathEntry) rootPathToRawEntries.get(root.getPath());
        }
    }
    return rawEntry;
}

From source file:com.google.gdt.eclipse.managedapis.impl.ManagedApiProjectImpl.java

License:Open Source License

public String getPathRelativeToManagedApiRoot(IPackageFragmentRoot fragmentRoot) {
    if (isPackageFragmentRootInManagedApi(fragmentRoot)) {
        IFolder rootFolder = getManagedApiRootFolder();
        int rootLength = rootFolder != null ? rootFolder.getFullPath().segmentCount() : 0;
        return fragmentRoot.getPath().removeFirstSegments(rootLength).segment(0);
    } else {//from   w  ww  .j  a va  2 s.  c  om
        return null;
    }
}

From source file:com.google.gdt.eclipse.managedapis.impl.ManagedApiProjectImpl.java

License:Open Source License

public boolean isPackageFragmentRootInManagedApi(IPackageFragmentRoot fragmentRoot) {
    IFolder rootFolder = getManagedApiRootFolder();

    return rootFolder != null && rootFolder.getFullPath().isPrefixOf(fragmentRoot.getPath());
}

From source file:com.google.gdt.eclipse.maven.sdk.GWTMavenRuntime.java

License:Open Source License

/**
 * Find the classpath for get-dev.jar which is used to run super dev mode.
 *
 * @return IClasspathEntry for the path to gwt-dev.jar
 * @throws JavaModelException/*from   w  w  w .ja v a  2  s .c o  m*/
 */
private IClasspathEntry findGwtCodeServerClasspathEntry() throws JavaModelException {
    IType type = javaProject
            .findType(GwtLaunchConfigurationProcessorUtilities.SUPERDEVMODE_CODESERVER_MAIN_TYPE);
    if (type == null) {
        return null;
    }

    IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) type
            .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
    if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_BINARY) {
        return JavaCore.newLibraryEntry(packageFragmentRoot.getPath(), null, null);
    }

    return null;
}

From source file:com.google.gdt.eclipse.maven.sdk.GWTMavenRuntime.java

License:Open Source License

private IClasspathEntry findGwtUserClasspathEntry() throws JavaModelException {
    /*/*from w  w w  .  j a va2 s  .  co  m*/
     * Note that the type that we're looking for to determine if we're part of the gwt-user library
     * is different than the one that is used by the superclass. This is because the class that the
     * superclass is querying for, "com.google.gwt.core.client.GWT", also exists in the gwt-servlet
     * library, and for some reason, this sometimes ends up on the build path for Maven projects.
     *
     * TODO: See why Maven is putting gwt-servlet on the build path.
     *
     * TODO: Change the class query in the superclass to "com.google.gwt.junit.client.GWTTestCase"
     */
    IType type = javaProject.findType("com.google.gwt.junit.client.GWTTestCase");

    if (type == null) {
        return null;
    }

    IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) type
            .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
    if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_BINARY) {
        // TODO: If the Maven javadoc and source libs for gwt-dev.jar are
        // available, attach them here.
        return JavaCore.newLibraryEntry(packageFragmentRoot.getPath(), null, null);
    }

    return null;
}