Example usage for org.eclipse.jdt.core JavaCore getResolvedVariablePath

List of usage examples for org.eclipse.jdt.core JavaCore getResolvedVariablePath

Introduction

In this page you can find the example usage for org.eclipse.jdt.core JavaCore getResolvedVariablePath.

Prototype

public static IPath getResolvedVariablePath(IPath variablePath) 

Source Link

Document

Resolve a variable path (helper method).

Usage

From source file:at.bestsolution.javafx.ide.jdt.internal.jdt.CPListElement.java

License:Open Source License

public static CPListElement create(Object parent, IClasspathEntry curr, boolean newElement,
        IJavaProject project) {// w  w w .ja v a2  s .c o m
    IPath path = curr.getPath();
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

    // get the resource
    IResource res = null;
    boolean isMissing = false;
    IPath linkTarget = null;

    switch (curr.getEntryKind()) {
    case IClasspathEntry.CPE_CONTAINER:
        try {
            isMissing = project != null && (JavaCore.getClasspathContainer(path, project) == null);
        } catch (JavaModelException e) {
            isMissing = true;
        }
        break;
    case IClasspathEntry.CPE_VARIABLE:
        IPath resolvedPath = JavaCore.getResolvedVariablePath(path);
        isMissing = root.findMember(resolvedPath) == null && !resolvedPath.toFile().exists();
        break;
    case IClasspathEntry.CPE_LIBRARY:
        res = root.findMember(path);
        if (res == null) {
            if (!ArchiveFileFilter.isArchivePath(path, true)) {
                if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()
                        && root.getProject(path.segment(0)).exists()) {
                    res = root.getFolder(path);
                }
            }

            IPath rawPath = path;
            if (project != null) {
                IPackageFragmentRoot[] roots = project.findPackageFragmentRoots(curr);
                if (roots.length == 1)
                    rawPath = roots[0].getPath();
            }
            isMissing = !rawPath.toFile().exists(); // look for external JARs and folders
        } else if (res.isLinked()) {
            linkTarget = res.getLocation();
        }
        break;
    case IClasspathEntry.CPE_SOURCE:
        path = path.removeTrailingSeparator();
        res = root.findMember(path);
        if (res == null) {
            if (root.getWorkspace().validatePath(path.toString(), IResource.FOLDER).isOK()) {
                res = root.getFolder(path);
            }
            isMissing = true;
        } else if (res.isLinked()) {
            linkTarget = res.getLocation();
        }
        break;
    case IClasspathEntry.CPE_PROJECT:
        res = root.findMember(path);
        isMissing = (res == null);
        break;
    }
    CPListElement elem = new CPListElement(parent, project, curr.getEntryKind(), path, newElement, res,
            linkTarget);
    elem.setExported(curr.isExported());
    elem.setAttribute(SOURCEATTACHMENT, curr.getSourceAttachmentPath());
    elem.setAttribute(OUTPUT, curr.getOutputLocation());
    elem.setAttribute(EXCLUSION, curr.getExclusionPatterns());
    elem.setAttribute(INCLUSION, curr.getInclusionPatterns());
    elem.setAttribute(ACCESSRULES, curr.getAccessRules());
    elem.setAttribute(COMBINE_ACCESSRULES, new Boolean(curr.combineAccessRules()));

    IClasspathAttribute[] extraAttributes = curr.getExtraAttributes();
    for (int i = 0; i < extraAttributes.length; i++) {
        IClasspathAttribute attrib = extraAttributes[i];
        CPListElementAttribute attribElem = elem.findAttributeElement(attrib.getName());
        if (attribElem == null) {
            elem.createAttributeElement(attrib.getName(), attrib.getValue(), false);
        } else {
            attribElem.setValue(attrib.getValue());
        }
    }

    elem.setIsMissing(isMissing);
    return elem;
}

From source file:com.legstar.eclipse.plugin.schemagen.wizards.JavaToXsdWizardPage.java

License:Open Source License

/**
 * Given classpath entries from a java project, populate a list of
 * collections./*  w w w .  j  av a 2s.com*/
 * 
 * @param selectedPathElementsLocations the output path locations
 * @param classPathEntries the java project class path entries
 * @param javaProject the java project
 * @throws JavaModelException if invalid classpath
 */
private void addPathElements(final List<String> selectedPathElementsLocations,
        final IClasspathEntry[] classPathEntries, final IJavaProject javaProject) throws JavaModelException {

    IClasspathEntry jreEntry = JavaRuntime.getDefaultJREContainerEntry();
    IPath projectPath = javaProject.getProject().getLocation();

    for (int i = 0; i < classPathEntries.length; i++) {
        IClasspathEntry classpathEntry = classPathEntries[i];
        String pathElementLocation = null;
        switch (classpathEntry.getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY:
            pathElementLocation = classpathEntry.getPath().toOSString();
            break;
        case IClasspathEntry.CPE_CONTAINER:
            /* No need for the default jre */
            if (classpathEntry.equals(jreEntry)) {
                break;
            }
            /* Resolve container into class path entries */
            IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(classpathEntry.getPath(),
                    javaProject);
            addPathElements(selectedPathElementsLocations, classpathContainer.getClasspathEntries(),
                    javaProject);
            break;
        case IClasspathEntry.CPE_VARIABLE:
            pathElementLocation = JavaCore.getResolvedVariablePath(classpathEntry.getPath()).toOSString();
            break;
        case IClasspathEntry.CPE_SOURCE:
            /*
             * If source has no specific output, use the project default
             * one
             */
            IPath outputLocation = classpathEntry.getOutputLocation();
            if (outputLocation == null) {
                outputLocation = javaProject.getOutputLocation();
            }
            pathElementLocation = projectPath.append(outputLocation.removeFirstSegments(1)).toOSString();
            break;
        default:
            break;
        }

        if (pathElementLocation != null && !selectedPathElementsLocations.contains(pathElementLocation)) {
            selectedPathElementsLocations.add(pathElementLocation);
        }
    }
}

From source file:com.windowtester.eclipse.ui.wizard.NewExampleProjectWizard.java

License:Open Source License

private void importProject(String projectName, IProgressMonitor monitor) throws CoreException {
    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IProject project = workspace.getRoot().getProject(projectName);
    IProjectDescription description = workspace.newProjectDescription(projectName);
    description.setLocation(null);// w ww .  j  a v  a2 s.  c o  m
    project.create(description, new SubProgressMonitor(monitor, 1));
    project.open(new SubProgressMonitor(monitor, 1));

    // Direct ECLIPSE_HOME references are different each Eclipse installation
    // so adjust the classpath accordingly

    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] classpath = javaProject.getRawClasspath();
    boolean modified = false;
    for (int i = 0; i < classpath.length; i++) {
        IClasspathEntry entry = classpath[i];
        if (entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE)
            continue;
        IPath path = entry.getPath();
        if (path.segmentCount() != 3)
            continue;
        if (!path.segment(0).equals("ECLIPSE_HOME"))
            continue;
        if (!path.segment(1).equals("plugins"))
            continue;
        String jarName = path.segment(2);
        path = path.removeLastSegments(1);
        IPath pluginsPath = JavaCore.getResolvedVariablePath(path);
        if (pluginsPath == null) {
            Logger.log("Failed to resolve " + path);
            continue;
        }
        File pluginsDir = pluginsPath.toFile();
        String jarPrefix = jarName.substring(0, jarName.indexOf('_') + 1);
        String[] childNames = pluginsDir.list();
        if (childNames == null) {
            Logger.log("Failed to obtain children for " + pluginsDir.getPath());
            continue;
        }
        for (int j = 0; j < childNames.length; j++) {
            String name = childNames[j];
            if (name.startsWith(jarPrefix)) {
                modified = true;
                classpath[i] = JavaCore.newVariableEntry(path.append(name), null, null);
                break;
            }
        }
    }
    if (modified)
        javaProject.setRawClasspath(classpath, new NullProgressMonitor());
}

From source file:eldaEditor.dialogs.TransitionPropertiesInputDialog.java

License:Open Source License

private List fillExceptionCombo(Combo exceptionComnbo) {
    List exceptionList = new ArrayList<String>();
    // creo il javaProject
    IJavaProject jProject = JavaCore.create(project);
    try {// w  w w  .  j ava 2  s.c o  m
        // recupero il jar di actiware
        IPackageFragmentRoot jar = jProject.findPackageFragmentRoot(JavaCore.getResolvedVariablePath(
                JavaCore.newVariableEntry(CodeGenerator.frameworkPath, null, null).getPath()));

        for (int i = 1; i < jar.getChildren().length; i++) {
            IPackageFragment jarFragment = (IPackageFragment) JavaCore
                    .create(jar.getChildren()[i].getHandleIdentifier());
            if (jarFragment.getElementName().startsWith("eldaframework.eldaevent.exception")) {
                IClassFile[] classArray = jarFragment.getClassFiles();
                for (int j = 0; j < classArray.length; j++) {
                    String name = classArray[j].getElementName().replaceAll(".class", "");
                    exceptionComnbo.add(name);
                    exceptionList.add(name);
                }
            }
        }
    } catch (JavaModelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return exceptionList;
}

From source file:org.apache.felix.sigil.eclipse.model.util.JavaHelper.java

License:Apache License

private static Collection<IClasspathEntry> newProjectEntry(ISigilProjectModel n, IAccessRule[] rules,
        IClasspathAttribute[] attributes, boolean export) throws CoreException {
    ArrayList<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
    entries.add(JavaCore.newProjectEntry(n.getProject().getFullPath(), rules, false, attributes, export));
    for (IClasspathEntry e : n.getJavaModel().getRawClasspath()) {
        String encoded = n.getJavaModel().encodeClasspathEntry(e);
        if (n.getBundle().getClasspathEntrys().contains(encoded)) {
            switch (e.getEntryKind()) {
            case IClasspathEntry.CPE_LIBRARY:
                entries.add(JavaCore.newLibraryEntry(e.getPath(), e.getSourceAttachmentPath(),
                        e.getSourceAttachmentRootPath(), rules, attributes, export));
                break;
            case IClasspathEntry.CPE_VARIABLE:
                IPath path = JavaCore.getResolvedVariablePath(e.getPath());
                if (path != null) {
                    IPath spath = e.getSourceAttachmentPath();
                    if (spath != null) {
                        spath = JavaCore.getResolvedVariablePath(spath);
                    }/*ww w . j av a  2s.c o m*/

                    entries.add(JavaCore.newLibraryEntry(path, spath, e.getSourceAttachmentRootPath(), rules,
                            attributes, export));
                }
                break;
            }
        }
    }

    return entries;
}

From source file:org.eclipse.ajdt.internal.ui.wizards.PathBlock.java

License:Open Source License

private CPListElement[] openVariableSelectionDialog() {
    List existingElements = fPathList.getElements();
    ArrayList<IPath> existingPaths = new ArrayList<IPath>(existingElements.size());
    for (int i = 0; i < existingElements.size(); i++) {
        CPListElement elem = (CPListElement) existingElements.get(i);
        if (elem.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
            existingPaths.add(elem.getPath());
        }//ww w .  j a v  a2  s  .  c o  m
    }
    IPath[] existingPathsArray = existingPaths.toArray(new IPath[existingPaths.size()]);

    IPath[] paths = BuildPathDialogAccess.chooseVariableEntries(getShell(), existingPathsArray);
    if (paths != null) {
        ArrayList<CPListElement> result = new ArrayList<CPListElement>();
        for (int i = 0; i < paths.length; i++) {
            CPListElement elem = new CPListElement(fCurrJProject, IClasspathEntry.CPE_VARIABLE, paths[i], null);
            IPath resolvedPath = JavaCore.getResolvedVariablePath(paths[i]);
            elem.setIsMissing((resolvedPath == null) || !resolvedPath.toFile().exists());
            if (!existingElements.contains(elem)) {
                result.add(elem);
            }
        }
        return result.toArray(new CPListElement[result.size()]);
    }
    return null;
}

From source file:org.eclipse.birt.report.designer.internal.ui.ide.adapters.IDEClassPathBlock.java

License:Open Source License

private static IDECPListElement createCPVariableElement(IPath path) {
    IDECPListElement elem = new IDECPListElement(IClasspathEntry.CPE_VARIABLE, path, null);
    IPath resolvedPath = JavaCore.getResolvedVariablePath(path);
    elem.setIsMissing((resolvedPath == null) || !resolvedPath.toFile().exists());
    return elem;/*  w  ww  . j  av  a2s .  c o  m*/
}

From source file:org.eclipse.jst.common.ui.internal.assembly.wizard.VariableReferenceWizardFragment.java

License:Open Source License

public void performFinish(IProgressMonitor monitor) throws CoreException {
    IVirtualComponent rootComponent = (IVirtualComponent) getTaskModel()
            .getObject(IReferenceWizardConstants.ROOT_COMPONENT);
    String runtimeLoc = (String) getTaskModel().getObject(IReferenceWizardConstants.DEFAULT_LIBRARY_LOCATION);
    if (selected != null) {
        ArrayList<IVirtualReference> refList = new ArrayList<IVirtualReference>();
        //         for (int i = 0; i < selected.length; i++) {
        IPath variablePath = getVariablePath(selected);
        IPath resolvedPath = JavaCore.getResolvedVariablePath(variablePath);
        java.io.File file = new java.io.File(resolvedPath.toOSString());
        if (file.isFile() && file.exists()) {
            String type = VirtualArchiveComponent.VARARCHIVETYPE + IPath.SEPARATOR;
            IVirtualComponent archive = ComponentCore.createArchiveComponent(rootComponent.getProject(),
                    type + variablePath.toString());
            VirtualReference ref = new VirtualReference(rootComponent, archive);
            ref.setArchiveName(resolvedPath.lastSegment());
            if (runtimeLoc != null) {
                ref.setRuntimePath(new Path(runtimeLoc).makeAbsolute());
            }//from www .  j a  va2 s .c om
            refList.add(ref);
        }
        //         }
        IVirtualReference[] finalRefs = refList.toArray(new IVirtualReference[refList.size()]);
        getTaskModel().putObject(IReferenceWizardConstants.FINAL_REFERENCE, finalRefs);
    }
}

From source file:org.eclipse.jst.j2ee.internal.AddModulestoEARPropertiesPage.java

License:Open Source License

private void handleSelectVariableButton() {
    IPath existingPath[] = new Path[0];
    IPath[] paths = BuildPathDialogAccess.chooseVariableEntries(propPage.getShell(), existingPath);

    if (paths != null) {
        refresh();/*w w  w .ja va 2 s. c o m*/
        for (int i = 0; i < paths.length; i++) {
            IPath resolvedPath = JavaCore.getResolvedVariablePath(paths[i]);

            java.io.File file = new java.io.File(resolvedPath.toOSString());
            if (file.isFile() && file.exists()) {
                String type = VirtualArchiveComponent.VARARCHIVETYPE + IPath.SEPARATOR;

                IVirtualComponent archive = ComponentCore.createArchiveComponent(earComponent.getProject(),
                        type + paths[i].toString());

                this.addPotentialNewReference(archive);
            } else {
                //display error
            }
        }
        refresh();
    }
}

From source file:org.eclipse.jst.j2ee.internal.WebLibDependencyPropertiesPage.java

License:Open Source License

public void handleSelectVariableButton() {
    if (JavaEEProjectUtilities.isDynamicWebProject(project)) {
        IPath existingPath[] = new Path[0];
        IPath[] selected = BuildPathDialogAccess.chooseVariableEntries(propPage.getShell(), existingPath);

        if (selected != null) {
            String type = VirtualArchiveComponent.VARARCHIVETYPE + IPath.SEPARATOR;
            for (int i = 0; i < selected.length; i++) {
                IPath resolvedPath = JavaCore.getResolvedVariablePath(selected[i]);
                java.io.File file = new java.io.File(resolvedPath.toOSString());
                if (file.isFile() && file.exists()) {
                    createRef(type + selected[i].toString());
                } else {
                    // display error
                }//  w  ww .jav  a 2 s  .c  o  m
            }
            refresh();
        }
    }
}