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

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

Introduction

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

Prototype

Object[] getNonJavaResources() throws JavaModelException;

Source Link

Document

Returns an array of non-Java resources contained in this package fragment root.

Usage

From source file:ca.ecliptical.pde.ds.search.DescriptorQueryParticipant.java

License:Open Source License

private IJarEntryResource findJarEntry(IPackageFragmentRoot packageRoot, IPath path) throws JavaModelException {
    for (Object nonJavaResource : packageRoot.getNonJavaResources()) {
        if (nonJavaResource instanceof IJarEntryResource) {
            IJarEntryResource result = findJarEntry((IJarEntryResource) nonJavaResource, path);
            if (result != null)
                return result;
        }// ww w.j  ava  2  s  .com
    }

    return null;
}

From source file:ca.uwaterloo.gsd.wpi.code.WpiMappingInterpreter.java

License:Open Source License

public WorkspacePluginModel getWorkspacePluginModel(IJavaProject project, IType type) {
    IFile pluginXml = null;/*  w ww.j  a v a2 s  .  c om*/
    InputStream pluginXmlInputStream = null;

    if (!type.isBinary() && type.getJavaProject().equals(project))
        pluginXml = project.getProject().getFile("plugin.xml");
    else {
        IJavaElement parent = type.getPackageFragment().getParent();
        if (parent instanceof IPackageFragmentRoot) {
            IPackageFragmentRoot root = (IPackageFragmentRoot) parent;
            Object[] resources;
            try {
                resources = root.getNonJavaResources();
                for (int i = 0; i < resources.length; i++) {
                    if (resources[i] instanceof IFile) {
                        IFile file = (IFile) resources[i];
                        if (file.getName().equals("plugin.xml")) {
                            pluginXml = file;
                            break;
                        }
                    } else if (resources[i] instanceof JarEntryFile) {
                        JarEntryFile file = (JarEntryFile) resources[i];
                        if (file.getName().equals("plugin.xml")) {
                            pluginXmlInputStream = file.getContents();
                            break;
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    if (pluginXml != null && pluginXml.exists() || pluginXmlInputStream != null) {
        WorkspacePluginModel pluginModel = new WorkspacePluginModel(pluginXml, false);
        if (pluginModel != null) {
            if (pluginXmlInputStream != null) {
                try {
                    pluginModel.reload(pluginXmlInputStream, false);
                } catch (CoreException e) {
                    e.printStackTrace();
                }
            } else
                pluginModel.load();
        }
        return pluginModel;
    }
    return null;
}

From source file:ccw.ClojureCore.java

License:Open Source License

/**
 * Tries to open a clojure file in an editor
 * @return an editor input if the file has been found, or null
 *///ww  w. j  ava2  s . c o  m
private static IEditorInput findEditorInput(IPackageFragmentRoot packageFragmentRoot,
        IPackageFragment packageFragment, String searchedPackage, String searchedFileName)
        throws JavaModelException {
    if (packageFragment.exists() && packageFragment.getElementName().equals(searchedPackage)) {
        for (Object njr : packageFragment.isDefaultPackage() ? packageFragmentRoot.getNonJavaResources()
                : packageFragment.getNonJavaResources()) {
            if (njr instanceof IJarEntryResource) {
                IJarEntryResource jer = (IJarEntryResource) njr;
                if (jer.getName().equals(searchedFileName)) {
                    return new JarEntryEditorInput(jer);
                }
            } else if (njr instanceof IFile) {
                IFile file = (IFile) njr;
                if (file.getName().equals(searchedFileName)) {
                    return new FileEditorInput(file);
                }
            } else if (njr instanceof File) {
                File f = (File) njr;
                if (f.getName().equals(searchedFileName)) {
                    IFileStore fileStore = EFS.getLocalFileSystem().getStore(f.toURI());
                    return new FileStoreEditorInput(fileStore);
                }
            }
        }
    }
    return null;
}

From source file:com.amashchenko.eclipse.strutsclipse.ProjectUtil.java

License:Apache License

public static List<JarEntryStorage> findJarEntryStrutsResources(final IDocument document) {
    List<JarEntryStorage> results = new ArrayList<JarEntryStorage>();
    try {// ww  w  .  j a v a  2s  .  c  o m
        IJavaProject javaProject = getCurrentJavaProject(document);

        if (javaProject != null && javaProject.exists()) {
            IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
            for (IPackageFragmentRoot root : roots) {
                if (root.isArchive()) {
                    Object[] nonJavaResources = root.getNonJavaResources();
                    for (Object nonJavaRes : nonJavaResources) {
                        if (nonJavaRes instanceof IJarEntryResource) {
                            IJarEntryResource jarEntry = (IJarEntryResource) nonJavaRes;
                            if (jarEntry.isFile() && (StrutsXmlConstants.STRUTS_DEFAULT_FILE_NAME
                                    .equals(jarEntry.getName())
                                    || StrutsXmlConstants.STRUTS_PLUGIN_FILE_NAME.equals(jarEntry.getName()))) {
                                results.add(new JarEntryStorage(root.getPath(), jarEntry));
                            }
                        }
                    }
                }
            }
        }
    } catch (JavaModelException e) {
        e.printStackTrace();
    }
    return results;
}

From source file:com.cisco.yangide.core.YangJarFileEntryResource.java

License:Open Source License

private Object resolveParent(IPackageFragmentRoot parent, IPath path) {
    if (path.segmentCount() > 0) {
        try {//w w w.j ava 2  s  .co  m
            for (Object element : parent.getNonJavaResources()) {
                if (element instanceof IJarEntryResource) {
                    IJarEntryResource res = (IJarEntryResource) element;
                    if (path.segment(0).equals(res.getName())) {
                        return resolveParent(res, path.removeFirstSegments(1));
                    }
                }
            }
        } catch (Exception e) {
            YangCorePlugin.log(e);
        }
    }
    return parent;
}

From source file:com.codenvy.ide.ext.java.server.JavaNavigation.java

License:Open Source License

protected Object[] getPackageFragmentRootContent(IPackageFragmentRoot root) throws JavaModelException {

    // hierarchical package mode
    ArrayList<Object> result = new ArrayList<>();
    getHierarchicalPackageChildren(root, null, result);
    Object[] nonJavaResources = root.getNonJavaResources();
    for (int i = 0; i < nonJavaResources.length; i++) {
        result.add(nonJavaResources[i]);
    }/*from  w  w w .j  a  v a 2 s  . c  om*/
    return result.toArray();
}

From source file:com.codenvy.ide.ext.java.server.JavaNavigation.java

License:Open Source License

public List<JarEntry> getChildren(JavaProject project, int rootId, String path) throws JavaModelException {
    IPackageFragmentRoot root = getPackageFragmentRoot(project, rootId);
    if (root == null) {
        return NO_ENTRIES;
    }/*from   www  .j  a v  a  2 s .  c  o  m*/

    if (path.startsWith("/")) {
        // jar file and folders
        Object[] resources = root.getNonJavaResources();
        for (Object resource : resources) {
            if (resource instanceof JarEntryDirectory) {
                JarEntryDirectory directory = (JarEntryDirectory) resource;
                Object[] children = findJarDirectoryChildren(directory, path);
                if (children != null) {
                    return convertToJarEntry(children, root);
                }
            }
        }

    } else {
        // packages and class files
        IPackageFragment fragment = root.getPackageFragment(path);
        if (fragment == null) {
            return NO_ENTRIES;
        }
        return convertToJarEntry(getPackageContent(fragment), root);
    }
    return NO_ENTRIES;
}

From source file:com.codenvy.ide.ext.java.server.JavaNavigation.java

License:Open Source License

public String getContent(JavaProject project, int rootId, String path) throws CoreException {
    IPackageFragmentRoot root = getPackageFragmentRoot(project, rootId);
    if (root == null) {
        return null;
    }//from ww  w .ja v  a2 s  .co m

    if (path.startsWith("/")) {
        //non java file
        if (root instanceof JarPackageFragmentRoot) {
            JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot) root;
            ZipFile jar = null;
            try {
                jar = jarPackageFragmentRoot.getJar();
                ZipEntry entry = jar.getEntry(path.substring(1));
                if (entry != null) {
                    try (InputStream stream = jar.getInputStream(entry)) {
                        return IoUtil.readStream(stream);
                    } catch (IOException e) {
                        LOG.error("Can't read file content: " + entry.getName(), e);
                    }
                }
            } finally {
                if (jar != null) {
                    jarPackageFragmentRoot.closeJar(jar);
                }
            }
        }
        Object[] resources = root.getNonJavaResources();

        for (Object resource : resources) {
            if (resource instanceof JarEntryFile) {
                JarEntryFile file = (JarEntryFile) resource;
                if (file.getFullPath().toOSString().equals(path)) {
                    return readFileContent(file);
                }
            }
            if (resource instanceof JarEntryDirectory) {
                JarEntryDirectory directory = (JarEntryDirectory) resource;
                JarEntryFile file = findJarFile(directory, path);
                if (file != null) {
                    return readFileContent(file);
                }
            }
        }
    } else {
        //java class or file
        IType type = project.findType(path);
        if (type != null && type.isBinary()) {
            IClassFile classFile = type.getClassFile();
            if (classFile.getSourceRange() != null) {
                return classFile.getSource();
            } else {
                return sourcesGenerator.generateSource(classFile.getType());
            }
        }
    }
    return null;
}

From source file:com.codenvy.ide.ext.java.server.JavaNavigation.java

License:Open Source License

public JarEntry getEntry(JavaProject project, int rootId, String path) throws CoreException {
    IPackageFragmentRoot root = getPackageFragmentRoot(project, rootId);
    if (root == null) {
        return null;
    }/*  w ww.  j a va  2  s  . c o  m*/
    if (path.startsWith("/")) {

        JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot) root;
        ZipFile jar = null;
        try {
            jar = jarPackageFragmentRoot.getJar();
            ZipEntry entry = jar.getEntry(path.substring(1));
            if (entry != null) {
                JarEntry result = DtoFactory.getInstance().createDto(JarEntry.class);
                result.setType(JarEntryType.FILE);
                result.setPath(path);
                result.setName(entry.getName().substring(entry.getName().lastIndexOf("/") + 1));
                return result;
            }
        } finally {
            if (jar != null) {
                jarPackageFragmentRoot.closeJar(jar);
            }
        }

        Object[] resources = root.getNonJavaResources();

        for (Object resource : resources) {
            if (resource instanceof JarEntryFile) {
                JarEntryFile file = (JarEntryFile) resource;
                if (file.getFullPath().toOSString().equals(path)) {
                    return getJarEntryResource(file);
                }
            }
            if (resource instanceof JarEntryDirectory) {
                JarEntryDirectory directory = (JarEntryDirectory) resource;
                JarEntryFile file = findJarFile(directory, path);
                if (file != null) {
                    return getJarEntryResource(file);
                }
            }
        }

    } else {
        //java class or file
        IType type = project.findType(path);
        if (type != null && type.isBinary()) {
            IClassFile classFile = type.getClassFile();
            return getJarClass(classFile);
        }
    }

    return null;
}

From source file:com.redhat.ceylon.eclipse.code.explorer.PackageExplorerContentProvider.java

License:Open Source License

@Override
protected Object[] getPackageFragmentRootContent(IPackageFragmentRoot root) throws JavaModelException {
    ArrayList<Object> result = new ArrayList<Object>();
    if (fIsFlatLayout) {
        Object[] content = super.getPackageFragmentRootContent(root);
        List<IPackageFragment> defaultModulePackages = new ArrayList<IPackageFragment>();
        for (Object o : content) {
            if (o instanceof IPackageFragment) {
                defaultModulePackages.add((IPackageFragment) o);
            }/* w  w  w  .  jav a2s. c  o m*/
        }
        for (Object o : content) {
            if (o instanceof IPackageFragment) {
                IPackageFragment pf = (IPackageFragment) o;
                if (pf.isDefaultPackage()) {
                    defaultModulePackages.remove(pf);
                    for (Object dpc : getPackageContent(pf)) {
                        result.add(dpc);
                    }
                } else {
                    for (Object f : pf.getNonJavaResources()) {
                        if (f instanceof IFile) {
                            if (((IFile) f).getName().equals("module.ceylon")) {
                                result.add(pf);
                                defaultModulePackages.remove(pf);
                                for (IPackageFragment c : new ArrayList<IPackageFragment>(
                                        defaultModulePackages)) {
                                    if (pf.getPath().isPrefixOf(c.getPath())) {
                                        defaultModulePackages.remove(c);
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            } else {
                result.add(o);
            }
        }
        result.addAll(defaultModulePackages);
    } else {
        // hierarchical package mode
        getHierarchicalPackageChildren(root, null, result);
        if (!isProjectPackageFragmentRoot(root)) {
            Object[] nonJavaResources = root.getNonJavaResources();
            for (int i = 0; i < nonJavaResources.length; i++) {
                result.add(nonJavaResources[i]);
            }
        }
    }
    return result.toArray();
}