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

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

Introduction

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

Prototype

int K_BINARY

To view the source code for org.eclipse.jdt.core IPackageFragmentRoot K_BINARY.

Click Source Link

Document

Kind constant for a binary path root.

Usage

From source file:com.google.gwt.eclipse.core.runtime.GWTJarsRuntimeTest.java

License:Open Source License

public void testGetValidationClasspathEntries() throws Exception {
    IClasspathEntry[] cpEntries = runtime.getClasspathEntries();

    // Look for the validation-specific classpath entries
    List<IClasspathEntry> validationCpEntries = new ArrayList<IClasspathEntry>();
    for (IClasspathEntry cpEntry : cpEntries) {
        if (cpEntry.getPath().lastSegment().startsWith(GWTRuntime.VALIDATION_API_JAR_PREFIX)) {
            validationCpEntries.add(cpEntry);
        }//w w  w  . ja  va2 s  .c o  m
    }

    if (validationCpEntries.size() == 0) {
        String sdkVersion = runtime.getVersion();

        // Can't be an internal version, because it would have the
        // validation jars
        assertFalse(SdkUtils.isInternal(sdkVersion));

        // Sdk version must be pre-GWT 2.3.0
        assertTrue(SdkUtils.compareVersionStrings(sdkVersion, "2.3.0") < 0);

        return;
    }

    // Make sure that there are at least two of them
    assertEquals(2, validationCpEntries.size());

    IClasspathEntry sourcesEntry = null;
    IClasspathEntry binaryEntry = null;

    for (IClasspathEntry validationClasspathEntry : validationCpEntries) {
        // Verify the entry types
        assertEquals(IClasspathEntry.CPE_LIBRARY, validationClasspathEntry.getEntryKind());
        assertEquals(IPackageFragmentRoot.K_BINARY, validationClasspathEntry.getContentKind());

        if (validationClasspathEntry.getPath().lastSegment().contains("sources")) {
            sourcesEntry = validationClasspathEntry;
        } else {
            binaryEntry = validationClasspathEntry;
        }
    }

    // Verify that the sources and binary entries correspond to each other
    assertTrue(Util.findSourcesJarForClassesJar(binaryEntry.getPath()).equals(sourcesEntry.getPath()));

    // Verify that the source attachment path has been set for the binary
    // entry
    assertTrue(binaryEntry.getSourceAttachmentPath().equals(sourcesEntry.getPath()));
}

From source file:com.ifedorenko.m2e.sourcelookup.internal.JavaProjectSources.java

License:Open Source License

private void addJavaProject(IJavaProject project) throws CoreException {
    if (project != null) {
        final Map<File, IPackageFragmentRoot> classpath = new LinkedHashMap<File, IPackageFragmentRoot>();
        for (IPackageFragmentRoot fragment : project.getPackageFragmentRoots()) {
            if (fragment.getKind() == IPackageFragmentRoot.K_BINARY
                    && fragment.getSourceAttachmentPath() != null) {
                File classpathLocation;
                if (fragment.isExternal()) {
                    classpathLocation = fragment.getPath().toFile();
                } else {
                    classpathLocation = toFile(fragment.getPath());
                }/* w w w.  j  ava 2  s  .co  m*/
                if (classpathLocation != null) {
                    classpath.put(classpathLocation, fragment);
                }
            }
        }

        final JavaProjectInfo projectInfo = new JavaProjectInfo(project, classpath);

        final Set<File> projectLocations = new HashSet<File>();

        final String jarLocation = project.getProject().getPersistentProperty(BinaryProjectPlugin.QNAME_JAR);
        if (jarLocation != null) {
            // maven binary project
            projectLocations.add(new File(jarLocation));
        } else {
            // regular project
            projectLocations.add(toFile(project.getOutputLocation()));
            for (IClasspathEntry cpe : project.getRawClasspath()) {
                if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    projectLocations.add(toFile(cpe.getOutputLocation()));
                }
            }
        }

        synchronized (lock) {
            projects.put(project, projectLocations);
            for (File projectLocation : projectLocations) {
                locations.put(projectLocation, projectInfo);
            }
        }
    }
}

From source file:com.iw.plugins.spindle.ant.AntScriptGenerator.java

License:Mozilla Public License

/**
 * @param monitor//from ww w  . java  2  s . com
 */
private void harvestBinaryLibrariesAndSourceFolders(IProgressMonitor monitor) {
    try {
        IJavaProject jproject = fTapestryProject.getJavaProject();
        if (jproject == null)
            return;

        IPackageFragmentRoot[] allRoots = jproject.getAllPackageFragmentRoots();
        for (int i = 0; i < allRoots.length; i++) {

            int kind = allRoots[i].getKind();
            switch (kind) {
            case IPackageFragmentRoot.K_BINARY:
                if (!fServletAPIRoots.contains(allRoots[i]))
                    fBinaryLibraries.add(allRoots[i]);
                break;
            case IPackageFragmentRoot.K_SOURCE:
                fSourceFolders.add(allRoots[i]);
                break;

            default:
                break;
            }
        }
    } catch (CoreException e) {
        UIPlugin.log(e);
    }
}

From source file:com.iw.plugins.spindle.ant.AntScriptGenerator.java

License:Mozilla Public License

/**
 *  /*w  ww.ja v a  2  s .  c om*/
 */
private void harvestServletJars(IProgressMonitor monitor) {
    try {
        IJavaProject jproject = fTapestryProject.getJavaProject();
        if (jproject == null)
            return;

        // let's locate all occurances of a package in the project classpath that
        // we know should be
        // from the java servlet jar..

        SearchPattern pattern = SearchPattern.createPattern("javax.servlet.http", IJavaSearchConstants.PACKAGE,
                IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);

        IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { jproject });

        //we could get lots of hits for various reasons so lets collect the ones
        // we are interested in..
        //we collect the roots (jars) that contain the package of interest.
        final List roots = new ArrayList();

        SearchRequestor requestor = new SearchRequestor() {
            public void acceptSearchMatch(SearchMatch match) throws CoreException {
                //only keep the roots that are in jar files and that we have not
                // already seen!
                Object element = match.getElement();
                if (element instanceof IPackageFragment) {
                    IPackageFragment frag = (IPackageFragment) element;
                    if (frag.getKind() == IPackageFragmentRoot.K_BINARY) {
                        IPackageFragmentRoot root = (IPackageFragmentRoot) frag.getParent();
                        if (!roots.contains(root))
                            roots.add(root);
                    }
                }
            }
        };
        //    Search - do the search
        SearchEngine searchEngine = new SearchEngine();
        searchEngine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
                scope, requestor, monitor);

        if (!roots.isEmpty())
            fServletAPIRoots = roots;

    } catch (CoreException e) {
        UIPlugin.log(e);
    }
}

From source file:com.iw.plugins.spindle.ui.wizards.fields.PackageDialogField.java

License:Mozilla Public License

public IStatus packageChanged() {
    SpindleStatus status = new SpindleStatus();
    checkButtonEnabled();//from  ww  w  .ja  v  a 2  s  . c o m
    String packName = getTextValue();
    if (!"".equals(packName)) {
        IStatus val = JavaConventions.validatePackageName(packName);
        if (val.getSeverity() == IStatus.ERROR) {
            status.setError(UIPlugin.getString(name + ".error.InvalidPackageName", val.getMessage()));
            return status;
        } else if (val.getSeverity() == IStatus.WARNING) {
            status.setWarning(UIPlugin.getString(name + ".warning.DiscouragedPackageName", val.getMessage()));
            // continue
        }
    } else {

        status.setError(UIPlugin.getString(name + ".error.defaultPackage"));
        return status;
    }

    IPackageFragmentRoot root;
    if (container == null) {
        root = null;
    } else {
        root = container.getPackageFragmentRoot();
    }
    if (root != null) {
        IPackageFragment pack = root.getPackageFragment(packName);
        try {
            if (fSourcePackagesOnly && root.getKind() == IPackageFragmentRoot.K_BINARY) {
                status.setError(UIPlugin.getString(name + ".error.PackageMustBeSource"));
                return status;
            }

            IPath rootPath = root.getPath();
            IPath outputPath = root.getJavaProject().getOutputLocation();
            if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
                // if the bin folder is inside of our root, dont allow to name a
                // package
                // like the bin folder
                IPath packagePath = pack.getUnderlyingResource().getFullPath();
                if (outputPath.isPrefixOf(packagePath)) {
                    status.setError(UIPlugin.getString(name + ".error.ClashOutputLocation"));
                    return status;
                }
            }
        } catch (JavaModelException e) {
            UIPlugin.log(e);
            // let pass
        }

        currentPackage = pack;
        if (currentPackage != null && nameField != null) {
            try {
                IContainer folder = (IContainer) getPackageFragment().getUnderlyingResource();

                boolean isComponent = nameField.getKind() == AbstractNameField.COMPONENT_NAME;
                IFile file = folder
                        .getFile(new Path(nameField.getTextValue() + (isComponent ? ".jwc" : ".page")));
                if (file.exists()) {

                    status.setError(UIPlugin.getString(name + ".error.ComponentAlreadyExists",
                            file.getFullPath().toString()));
                    return status;
                }
            } catch (JavaModelException e) {
                UIPlugin.log(e);
            }
        }
    } else {
        status.setError("");
    }
    return status;
}

From source file:com.iw.plugins.spindle.util.lookup.TapestryLookup.java

License:Mozilla Public License

public IPackageFragment findPackageFragment(IStorage storage) throws JavaModelException {
    if (storage instanceof JarEntryFileFaker) {
        storage = (IStorage) storage.getAdapter(IStorage.class);
    }//from  w w  w .  j a  va2 s  .  co  m
    if (storage instanceof IResource) {

        IPackageFragment result = (IPackageFragment) project
                .findPackageFragment(((IResource) storage).getParent().getFullPath());

        if (result != null) {

            return result;

        }
    }
    for (int i = 0; i < fPackageFragmentRoots.length; i++) {
        boolean isBinary = fPackageFragmentRoots[i].getKind() == IPackageFragmentRoot.K_BINARY;
        Object[] children = null;
        try {
            children = fPackageFragmentRoots[i].getChildren();
            if (children == null) {
                continue;
            }
            for (int j = 0; j < children.length; j++) {
                IPackageFragment fragment = (IPackageFragment) children[j];

                Object[] nonJavaResources = fragment.getNonJavaResources();

                if (nonJavaResources.length == 0) {

                    nonJavaResources = getSourcePackageResources(fragment);

                }

                for (int k = 0; k < nonJavaResources.length; k++) {
                    if (nonJavaResources[k].equals(storage)) {
                        return fragment;
                    }
                }
            }
        } catch (CoreException ex) {
            //do nothing
        }
    }
    return null;

}

From source file:com.iw.plugins.spindle.util.lookup.TapestryLookup.java

License:Mozilla Public License

public boolean seek(String name, IPackageFragment pkg, boolean partialMatch, int acceptFlags,
        ILookupRequestor requestor) {/*from  w  w w  .j a  v a  2 s . c  o m*/

    if (!initialized) {
        throw new Error("not initialized");
    }
    boolean stopLooking = false;
    String matchName = partialMatch ? name.toLowerCase() : name;
    if (pkg == null) {
        findAllManaged(matchName, partialMatch, requestor, acceptFlags);
        return stopLooking;
    }
    IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent();

    try {
        int packageFlavor = root.getKind();

        switch (packageFlavor) {
        case IPackageFragmentRoot.K_BINARY:
            if ((acceptFlags & WRITEABLE) != 0) {
                break;
            }
            stopLooking = seekInBinaryPackage(matchName, pkg, partialMatch, acceptFlags, requestor);
            break;
        case IPackageFragmentRoot.K_SOURCE:
            stopLooking = seekInSourcePackage(matchName, pkg, partialMatch, acceptFlags, requestor);
            break;
        default:
            return stopLooking;
        }
    } catch (JavaModelException e) {
        return stopLooking;
    }
    return stopLooking;
}

From source file:com.iw.plugins.spindle.wizards.project.NewProjectUtils.java

License:Mozilla Public License

private static void addToClasspath(String jarFileName, IJavaProject jproject, IProgressMonitor monitor)
        throws InterruptedException, CoreException {

    URL installUrl = TapestryPlugin.getDefault().getDescriptor().getInstallURL();

    URL jarURL = null;//w  w  w  .j  a v a2  s .  com
    try {

        jarURL = new URL(installUrl, jarFileName);

        jarURL = Platform.resolve(jarURL);

    } catch (IOException e) {
    }

    if (jarURL == null) {

        return;

    }

    IClasspathEntry[] classpath = jproject.getRawClasspath();

    IClasspathEntry[] newClasspath = new IClasspathEntry[classpath.length + 1];

    System.arraycopy(classpath, 0, newClasspath, 0, classpath.length);

    newClasspath[classpath.length] = new ClasspathEntry(IPackageFragmentRoot.K_BINARY,
            ClasspathEntry.CPE_LIBRARY, new Path(jarURL.getFile()), new Path[] {}, null, null, null, false);

    jproject.setRawClasspath(newClasspath, monitor);

}

From source file:com.liferay.ide.adt.core.model.internal.JavaPackageNameDefaultValueService.java

License:Open Source License

@Override
protected String compute() {
    final IJavaProject project = op().adapt(IJavaProject.class);

    try {// w  ww.  j  ava2 s.c  o m
        final IPackageFragmentRoot[] roots = project.getPackageFragmentRoots();

        for (IPackageFragmentRoot root : roots) {
            if (root.getKind() != IPackageFragmentRoot.K_BINARY) {
                for (IJavaElement element : root.getChildren()) {
                    if (element instanceof IPackageFragment) {
                        final IPackageFragment fragment = (IPackageFragment) element;

                        if (!fragment.isDefaultPackage() && !fragment.hasSubpackages()) {
                            return fragment.getElementName();
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        ADTCore.logError(e.getMessage(), e);
    }

    return null;
}

From source file:com.microsoft.javapkgsrv.JavaElementLabelComposer.java

License:Open Source License

private static IClasspathEntry getClasspathEntry(IPackageFragmentRoot root) throws JavaModelException {
    IClasspathEntry rawEntry = root.getRawClasspathEntry();
    int rawEntryKind = rawEntry.getEntryKind();
    switch (rawEntryKind) {
    case IClasspathEntry.CPE_LIBRARY:
    case IClasspathEntry.CPE_VARIABLE:
    case IClasspathEntry.CPE_CONTAINER: // should not happen, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=305037
        if (root.isArchive() && root.getKind() == IPackageFragmentRoot.K_BINARY) {
            IClasspathEntry resolvedEntry = root.getResolvedClasspathEntry();
            if (resolvedEntry.getReferencingEntry() != null)
                return resolvedEntry;
            else/*from  ww w. ja v a 2 s  .  co m*/
                return rawEntry;
        }
    }
    return rawEntry;
}