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.siteview.mde.internal.core.ClasspathComputer.java

License:Open Source License

private static void addLibraryEntry(IProject project, IMonitorLibrary library, IPath sourceAttachment,
        IClasspathAttribute[] attrs, ArrayList result) throws JavaModelException {
    String name = ClasspathUtilCore.expandLibraryName(library.getName());
    IResource jarFile = project.findMember(name);
    if (jarFile == null)
        return;/*  w  ww .  jav a  2 s  . c  om*/

    IPackageFragmentRoot root = JavaCore.create(project).getPackageFragmentRoot(jarFile);
    if (root.exists() && root.getKind() == IPackageFragmentRoot.K_BINARY) {
        IClasspathEntry oldEntry = root.getRawClasspathEntry();
        // If we have the same binary root but new or different source, we should recreate the entry 
        if ((sourceAttachment == null && oldEntry.getSourceAttachmentPath() != null)
                || (sourceAttachment != null && sourceAttachment.equals(oldEntry.getSourceAttachmentPath()))) {
            if (!result.contains(oldEntry)) {
                result.add(oldEntry);
                return;
            }
        }
    }

    IClasspathEntry entry = createClasspathEntry(project, jarFile, name, sourceAttachment, attrs,
            library.isExported());
    if (!result.contains(entry))
        result.add(entry);
}

From source file:com.siteview.mde.internal.core.util.ManifestUtils.java

License:Open Source License

public static boolean isImmediateRoot(IPackageFragmentRoot root) throws JavaModelException {
    int kind = root.getKind();
    return kind == IPackageFragmentRoot.K_SOURCE
            || (kind == IPackageFragmentRoot.K_BINARY && !root.isExternal());
}

From source file:com.siteview.mde.internal.ui.editor.monitor.ImportPackageSection.java

License:Open Source License

private void setElements(ConditionalListSelectionDialog dialog) {
    Set forbidden = getForbiddenIds();
    boolean allowJava = "true".equals(getBundle().getHeader(ICoreConstants.ECLIPSE_JREBUNDLE)); //$NON-NLS-1$

    ArrayList elements = new ArrayList();
    ArrayList conditional = new ArrayList();
    IMonitorModelBase[] models = MonitorRegistry.getActiveModels();
    Set nameVersions = new HashSet(); // Set of NameVersionDescriptors, used to remove duplicate entries

    for (int i = 0; i < models.length; i++) {
        BundleDescription desc = models[i].getBundleDescription();

        // If the current model is a fragment, it can export packages only if its parent has hasExtensibleAPI set
        if (isFragmentThatCannotExportPackages(models[i]))
            continue;

        String id = desc == null ? null : desc.getSymbolicName();
        if (id == null || forbidden.contains(id))
            continue;

        ExportPackageDescription[] exported = desc.getExportPackages();
        for (int j = 0; j < exported.length; j++) {
            String name = exported[j].getName();
            NameVersionDescriptor nameVersion = new NameVersionDescriptor(exported[j].getName(),
                    exported[j].getVersion().toString(), NameVersionDescriptor.TYPE_PACKAGE);
            if (("java".equals(name) || name.startsWith("java.")) && !allowJava) //$NON-NLS-1$ //$NON-NLS-2$
                continue;
            if (nameVersions.add(nameVersion) && (fHeader == null || !fHeader.hasPackage(name)))
                elements.add(new ImportItemWrapper(exported[j]));
        }/*from  ww  w. j av  a2s .c om*/
        IMonitorModelBase model = (IMonitorModelBase) getPage().getMDEEditor().getAggregateModel();
        if (model instanceof IBundlePluginModelBase) {
            IBundleModel bmodel = ((IBundlePluginModelBase) model).getBundleModel();
            if (bmodel != null) {
                ExportPackageHeader header = (ExportPackageHeader) bmodel.getBundle()
                        .getManifestHeader(Constants.EXPORT_PACKAGE);
                if (header != null) {
                    ExportPackageObject[] pkgs = header.getPackages();
                    for (int j = 0; j < pkgs.length; j++) {
                        String name = pkgs[j].getName();
                        String version = pkgs[j].getVersion();
                        NameVersionDescriptor nameVersion = new NameVersionDescriptor(name, version,
                                NameVersionDescriptor.TYPE_PACKAGE);
                        if (nameVersions.add(nameVersion) && (fHeader == null || !fHeader.hasPackage(name)))
                            elements.add(new ImportItemWrapper(pkgs[j]));
                    }
                }
            }

        }
    }
    for (int i = 0; i < models.length; i++) {
        try {
            // add un-exported packages in workspace non-binary plug-ins
            IResource resource = models[i].getUnderlyingResource();
            IProject project = resource != null ? resource.getProject() : null;
            if (project == null || !project.hasNature(JavaCore.NATURE_ID)
                    || WorkspaceModelManager.isBinaryProject(project)
                    || !PDEProject.getManifest(project).exists())
                continue;

            // If the current model is a fragment, it can export packages only if its parent has hasExtensibleAPI set
            if (isFragmentThatCannotExportPackages(models[i]))
                continue;

            IJavaProject jp = JavaCore.create(project);
            IPackageFragmentRoot[] roots = jp.getPackageFragmentRoots();
            for (int j = 0; j < roots.length; j++) {
                if (roots[j].getKind() == IPackageFragmentRoot.K_SOURCE
                        || (roots[j].getKind() == IPackageFragmentRoot.K_BINARY && !roots[j].isExternal())) {
                    IJavaElement[] children = roots[j].getChildren();
                    for (int k = 0; k < children.length; k++) {
                        IPackageFragment f = (IPackageFragment) children[k];
                        String name = f.getElementName();
                        NameVersionDescriptor nameVersion = new NameVersionDescriptor(name, null,
                                NameVersionDescriptor.TYPE_PACKAGE);
                        if (name.equals("")) //$NON-NLS-1$
                            name = "."; //$NON-NLS-1$
                        if (nameVersions.add(nameVersion)
                                && (f.hasChildren() || f.getNonJavaResources().length > 0))
                            conditional.add(new ImportItemWrapper(f));
                    }
                }
            }
        } catch (CoreException e) {
        }
    }
    dialog.setElements(elements.toArray());
    dialog.setConditionalElements(conditional.toArray());
}

From source file:com.siteview.mde.internal.ui.wizards.tools.ConvertJarsAction.java

License:Open Source License

/**
 * @see IActionDelegate#selectionChanged(IAction, ISelection)
 *//*from  w ww .  ja va  2s. co  m*/
public void selectionChanged(IAction action, ISelection s) {
    boolean enabled = true;
    if (s instanceof IStructuredSelection) {
        selection = (IStructuredSelection) s;
        if (selection.size() == 0)
            return;
        Iterator i = selection.iterator();
        while (i.hasNext()) {
            Object obj = i.next();
            if (obj instanceof IPackageFragmentRoot) {
                try {
                    IPackageFragmentRoot packageFragment = (IPackageFragmentRoot) obj;
                    if (packageFragment.getKind() == IPackageFragmentRoot.K_BINARY) {
                        if (MDE.hasPluginNature(packageFragment.getJavaProject().getProject())) {
                            if (packageFragment.getRawClasspathEntry()
                                    .getEntryKind() == IClasspathEntry.CPE_LIBRARY)
                                continue;
                        }
                    }
                } catch (JavaModelException e) {
                }
            }
            enabled = false;
            break;
        }
    } else {
        enabled = false;
        this.selection = null;
    }
    action.setEnabled(enabled);
}

From source file:com.siteview.mde.launching.PDESourcePathProvider.java

License:Open Source License

/**
 * Adds runtime classpath entries for binary package fragment roots contained within
 * the project/*  w w w  .j a v a2 s .  c o  m*/
 * 
 * @param jProject
 *          the Java project whose roots are to be enumerated
 * @param all
 *          a list of accumulated runtime classpath entries
 * @throws CoreException
 *          if unable to evaluate the package fragment roots
 */
private void addBinaryPackageFragmentRoots(IJavaProject jProject, List all) throws CoreException {
    IPackageFragmentRoot[] roots = jProject.getPackageFragmentRoots();
    for (int j = 0; j < roots.length; j++) {
        if (roots[j].getKind() == IPackageFragmentRoot.K_BINARY && !PDEJavaHelper.isJRELibrary(roots[j])) {
            IRuntimeClasspathEntry rte = JavaRuntime.newArchiveRuntimeClasspathEntry(roots[j].getPath());
            IPath path = roots[j].getSourceAttachmentPath();
            if (path != null) {
                rte.setSourceAttachmentPath(path);
                rte.setSourceAttachmentRootPath(roots[j].getSourceAttachmentRootPath());
            }
            if (!all.contains(rte))
                all.add(rte);
        }
    }

}

From source file:com.technophobia.substeps.step.ProjectStepImplementationLoader.java

License:Open Source License

private String[] findDependenciesFor(final IJavaProject javaProject) {
    try {//from  w  ww. ja  v  a 2  s.co m
        final IPackageFragmentRoot[] fragmentRoots = javaProject.getPackageFragmentRoots();
        final Collection<String> rootPaths = new ArrayList<String>(fragmentRoots.length);
        for (int i = 0; i < fragmentRoots.length; i++) {
            if (fragmentRoots[i].getKind() == IPackageFragmentRoot.K_BINARY) {
                final String path = getPathFor(fragmentRoots[i]);
                if (path != null) {
                    rootPaths.add(path);
                }
            }
        }
        return rootPaths.toArray(new String[rootPaths.size()]);
    } catch (final JavaModelException ex) {
        FeatureEditorPlugin.instance()
                .warn("Could not get package fragment roots for project " + javaProject.getProject().getName());
        return new String[0];
    }
}

From source file:dynamicrefactoring.integration.ModelGenerator.java

License:Open Source License

/**
 * Realiza la carga de bibliotecas bsicas del API de Java.
 * //from w w w.ja va  2 s. c  o m
 * Es un paso previo necesario para poder utilizar las clases de dichos
 * paquetes en las clases a partir de las cuales se quiere generar un modelo.
 * 
 * @throws Exception si se produce un error al acceder a los ficheros JAR
 * que se supone contienen las bibliotecas.
 */
private void loadBasicLibraries() throws Exception {

    String JRE_root = JavaRuntime.getVMInstall(project).getInstallLocation().getAbsolutePath();

    BinaryLoader binaryLoader = new BinaryLoader();

    String rtPath = null;

    IClasspathEntry[] classpath = project.getResolvedClasspath(true);
    for (int i = 0; i < classpath.length; i++) {
        if (classpath[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY
                && classpath[i].getContentKind() == IPackageFragmentRoot.K_BINARY) {
            IPath path = classpath[i].getPath();
            if (path.toOSString().endsWith(BASIC_JAR)) {
                rtPath = path.toOSString();
                // Se aaden el resto de bibliotecas de forma normal.
            } else if (path.toOSString().toLowerCase().endsWith(LIB_EXTENSION))
                // Salvo las que pertenezcan al JRE o el JDK.
                if (!path.toOSString().startsWith(JRE_root)) {
                    // Si la ruta no es relativa al proyecto.
                    if (!path.toOSString().startsWith(project.getPath().toOSString())) {
                        binaryLoader.addClassesFromJar(path.toOSString());
                        // Para las rutas relativas al proyecto.
                    } else {
                        String relativePath = path.removeFirstSegments(1).toOSString();
                        if (project.getJavaProject().getResource() != null) {
                            String projectPath = project.getJavaProject().getResource().getLocation()
                                    .toOSString();
                            binaryLoader.addClassesFromJar(projectPath + File.separatorChar + //$NON-NLS-1$
                                    relativePath);
                        }
                    }
                }
        }
    }

    if (rtPath == null) {
        rtPath = JRE_root + File.separatorChar + BASIC_JAR; //$NON-NLS-1$
    }

    binaryLoader.addClassesFromJar(rtPath);

    //for (int i = 0; i < LIBRARIES.length; i++)
    //   binaryLoader.addClassesFromPackageInJar(LIBRARIES[i], rtPath);

    binaryLoader.load();
}

From source file:eu.cloudwave.wp5.feedback.eclipse.base.resources.core.java.FeedbackJavaProjectImpl.java

License:Apache License

/**
 * Returns all package fragments of the Java project. Package fragments that only contain binary files are NOT
 * included.//from   www  .j  a  v a2s . c  o  m
 * 
 * @return a {@link Set} containing all package fragments that contain Java source files
 */
private Set<IPackageFragment> getPackageFragmentsContainingSourceFiles() {
    final Set<IPackageFragment> packageFragments = Sets.newHashSet();
    if (getJavaProject().exists()) {
        try {
            for (final IPackageFragment packageFragment : getJavaProject().getPackageFragments()) {
                if (packageFragment.getKind() != IPackageFragmentRoot.K_BINARY) {
                    packageFragments.add(packageFragment);
                }
            }
        } catch (final JavaModelException e) {
            Logger.print(String.format(JAVA_MODEL_EXCEPTION_MSG_PATTERN, PACKAGE_FRAGMENT));
            // do nothing, package fragment is simply not added to the list
        }
    }
    return packageFragments;
}

From source file:fede.workspace.eclipse.java.fields.JavaElementTreeController.java

License:Apache License

/**
 * Select fragment root.// ww w .  j  a v a  2  s  .co  m
 * 
 * @param pfr
 *            the pfr
 * 
 * @return true, if successful
 * 
 * @throws JavaModelException
 *             the java model exception
 */
protected boolean selectFragmentRoot(IPackageFragmentRoot pfr) throws JavaModelException {
    //      String attrName = (String) getUIField().getLocal("package-select-attribut-jar");
    //      if (attrName != null) {
    //         Item theItem = getItem();
    //         Object jarListObj = theItem.getAttribute(attrName);
    //         if (jarListObj instanceof List) {
    //            List<String> jarList = (List<String>) jarListObj;
    //            if (jarList.contains(pfr.getElementName())) {
    //               return true;
    //            }
    //
    //         }
    //      }

    if (pfr.getKind() == IPackageFragmentRoot.K_BINARY) {
        return false;
    }
    return true;
}

From source file:fede.workspace.eclipse.java.fields.PackageListController.java

License:Apache License

/**
 * Select fragment root.//from  w  ww.  j ava2s .  c  o m
 * 
 * @param pfr
 *            the pfr
 * 
 * @return true, if successful
 * 
 * @throws JavaModelException
 *             the java model exception
 */
protected boolean selectFragmentRoot(IPackageFragmentRoot pfr) throws JavaModelException {
    //      String attrName = (String) getUIField().getLocal("package-select-attribut-jar");
    //      if (attrName != null) {
    //         Item theItem = (Item) getUIField().getContext();
    //         Object jarListObj = theItem.getAttribute(attrName);
    //         if (jarListObj instanceof List) {
    //            List<String> jarList = (List<String>) jarListObj;
    //            if (jarList.contains(pfr.getElementName())) {
    //               return true;
    //            }
    //
    //         }
    //      }

    if (pfr.getKind() == IPackageFragmentRoot.K_BINARY) {
        return false;
    }
    return true;
}