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

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

Introduction

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

Prototype

public boolean isArchive();

Source Link

Document

Returns whether this package fragment root's underlying resource is a binary archive (a JAR or zip file).

Usage

From source file:org.seasar.s2daoplugin.cache.deployment.deployer.ComponentAutoRegisterDeployer.java

License:Apache License

private boolean isFileSystem(IPackageFragmentRoot root) {
    return root != null && !root.isArchive();
}

From source file:org.seasar.s2daoplugin.cache.deployment.deployer.JarComponentAutoRegisterDeployer.java

License:Apache License

protected void doDeploy(IHandler handler) throws CoreException {
    if (referenceClass == null) {
        return;/*from   w  w w .j a  v a2 s  .  co  m*/
    }
    IPackageFragmentRoot jar = JavaProjectUtil.findPackageFragmentRoot(referenceClass.getType());
    if (!jar.isArchive()) {
        return;
    }
    IContainer base = jar.getResource().getParent();
    IResource[] archives = archives = base.members();
    IJavaProject project = jar.getJavaProject();
    for (int i = 0; i < archives.length; i++) {
        if (!"jar".equalsIgnoreCase(archives[i].getFileExtension())) {
            continue;
        }
        jar = project.getPackageFragmentRoot(archives[i].getFullPath().toString());
        if (!jar.exists()) {
            continue;
        }
        if (isAppliedJar(jar)) {
            handler.processPackageFragmentRoot(jar);
        }
    }
}

From source file:org.springframework.ide.eclipse.beans.core.internal.model.BeansJavaConfig.java

License:Open Source License

public BeansJavaConfig(IBeansProject project, IType configClass, String configClassName, Type type) {
    super(project, BeansConfigFactory.JAVA_CONFIG_TYPE + configClassName, type);

    this.configClass = configClass;
    this.configClassName = configClassName;

    modificationTimestamp = IResource.NULL_STAMP;

    if (this.configClass != null) {
        IResource resource = this.configClass.getResource();
        if (resource != null && resource instanceof IFile) {
            file = (IFile) resource;/* ww w  . j a va 2  s  .  c o  m*/
        } else {
            IClassFile classFile = configClass.getClassFile();

            PackageFragment pkg = (PackageFragment) configClass.getPackageFragment();
            IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent();

            if (root.isArchive()) {
                IPath zipPath = root.getPath();

                String classFileName = classFile.getElementName();
                String path = Util.concatWith(pkg.names, classFileName, '/');
                file = new ExternalFile(zipPath.toFile(), path, project.getProject());
            }
        }
    }

    if (file == null || !file.exists()) {
        modificationTimestamp = IResource.NULL_STAMP;
        String msg = "Beans Java config class '" + configClassName + "' not accessible";
        problems = new CopyOnWriteArraySet<ValidationProblem>();
        problems.add(new ValidationProblem(IMarker.SEVERITY_ERROR, msg, file, -1));
    } else {
        modificationTimestamp = file.getModificationStamp();
        try {
            file.setSessionProperty(IBeansConfig.CONFIG_FILE_TAG, IBeansConfig.CONFIG_FILE_TAG_VALUE);
        } catch (CoreException e) {
            BeansCorePlugin.log(new Status(IStatus.WARNING, BeansCorePlugin.PLUGIN_ID,
                    String.format("Error occured while tagging config file '%s'", file.getFullPath()), e));
        }
    }

}

From source file:org.springframework.ide.eclipse.beans.ui.properties.NonJavaResourceContentProvider.java

License:Open Source License

protected boolean isInternalLibrary(IJavaProject project, IPackageFragmentRoot root) {
    if (root.isArchive()) {
        IResource resource = root.getResource();
        if (resource != null) {
            IProject jarProject = resource.getProject();
            IProject container = root.getJavaProject().getProject();
            return container.equals(jarProject);
        }/*ww w.j  a va2  s.  c o m*/
        return false;
    }
    return true;
}

From source file:org.springframework.ide.eclipse.boot.dash.cloudfoundry.packaging.CloudApplicationArchiver.java

License:Open Source License

protected void bootRepackage(final IPackageFragmentRoot[] roots, File packagedFile) throws Exception {
    Repackager bootRepackager = new Repackager(packagedFile);
    bootRepackager.repackage(new Libraries() {

        public void doWithLibraries(LibraryCallback callBack) throws IOException {
            for (IPackageFragmentRoot root : roots) {

                if (root.isArchive()) {

                    File rootFile = new File(root.getPath().toOSString());
                    if (rootFile.exists()) {
                        callBack.library(new Library(rootFile, LibraryScope.COMPILE));
                    }/*from w w  w  .jav  a2 s.  co  m*/
                }
            }
        }
    });
}

From source file:org.springframework.ide.eclipse.internal.uaa.monitor.LibraryUsageMonitor.java

License:Open Source License

@SuppressWarnings("deprecation")
private ProductMatch readPackageFragmentRoot(IJavaProject source, IPackageFragmentRoot entry)
        throws JavaModelException {
    // Quick assertion that we only check JARs that exist
    if (!entry.exists() || !entry.isArchive()) {
        return null;
    }//from w w  w  . jav a  2 s .  c o m

    // Check for previous matches or misses
    if (matches.containsKey(entry.getElementName())) {
        ProductMatch match = matches.get(entry.getElementName());
        return match;
    } else if (noMatches.contains(entry.getElementName())) {
        return null;
    }

    String groupId = null;
    String artifactId = null;
    String version = null;
    ProductInfo productInfo = null;

    JarEntryDirectory metaInfDirectory = getJarEntryDirectory(entry);

    // Step 1: Check META-INF/maven
    if (metaInfDirectory != null) {
        for (IJarEntryResource jarEntryResource : metaInfDirectory.getChildren()) {
            if ("maven".equals(jarEntryResource.getName())) {
                Product product = readMaven(jarEntryResource, entry);
                if (product != null) {
                    groupId = product.getGroupId();
                    artifactId = product.getArtifactId();
                    version = product.getVersion();
                    break;
                }
            }
        }
    }

    // Step 2: Check path if it follows the Maven convention of groupId/artifactId/version
    if (artifactId == null || groupId == null) {
        IPath jarPath = entry.getPath();

        IPath m2RepoPath = JavaCore.getClasspathVariable(M2_REPO);
        if (m2RepoPath == null) {
            m2RepoPath = ResourcesPlugin.getWorkspace().getPathVariableManager().getValue(M2_REPO);
        }
        if (m2RepoPath != null && m2RepoPath.isPrefixOf(jarPath)) {
            jarPath = jarPath.removeFirstSegments(m2RepoPath.segmentCount());
            int segments = jarPath.segmentCount();
            for (int i = 0; i < segments - 1; i++) {
                if (i == 0) {
                    groupId = jarPath.segment(i);
                } else if (i > 0 && i < segments - 3) {
                    groupId += "." + jarPath.segment(i);
                } else if (i == segments - 3) {
                    artifactId = jarPath.segment(i);
                } else if (i == segments - 2) {
                    version = jarPath.segment(i);
                }
            }
        }
    }

    // Step 3: Check for typeName match
    if (artifactId == null || groupId == null) {
        for (ProductInfo info : getProducts()) {
            String typeName = info.getTypeName();
            String packageName = "";
            if (typeName != null) {
                int i = typeName.lastIndexOf('.');
                if (i > 0) {
                    packageName = typeName.substring(0, i);
                    typeName = typeName.substring(i + 1);
                }
                IPackageFragment packageFragment = entry.getPackageFragment(packageName);
                if (packageFragment.exists()) {
                    if (packageFragment.getClassFile(typeName + ClassUtils.CLASS_FILE_SUFFIX).exists()) {
                        artifactId = info.getArtifactId();
                        groupId = info.getGroupId();
                        productInfo = info;
                        break;
                    }
                }
            }
        }
    }

    // Step 4: Obtain version from MANIFEST.MF
    if (groupId != null && artifactId != null && metaInfDirectory != null && version == null) {
        for (IJarEntryResource jarEntryResource : metaInfDirectory.getChildren()) {
            if (MANIFEST_FILE_NAME.equals(jarEntryResource.getName())) {
                version = readManifest(jarEntryResource, entry);
            }
        }
    }

    // Step 5: Obtain version from file name
    if (groupId != null && artifactId != null && version == null && entry.getPath() != null) {
        String fileName = entry.getPath().lastSegment();

        // Use regular expression to match any version number
        Matcher matcher = VERSION_PATTERN.matcher(fileName);
        if (matcher.matches()) {
            StringBuilder builder = new StringBuilder();
            for (int i = 1; i <= matcher.groupCount(); i++) {
                builder.append(matcher.group(i));
            }
            version = builder.toString();
        }
    }

    // Step 6: Construct the ProductMatch
    ProductMatch productMatch = null;
    if (productInfo == null) {
        for (ProductInfo info : getProducts()) {
            if (info.getArtifactId().equals(artifactId) && info.getGroupId().equals(groupId)) {
                productInfo = info;
                productMatch = new ProductMatch(info, version);
                break;
            }
        }
    } else {
        productMatch = new ProductMatch(productInfo, version);
    }

    // Step 7: Store ProductMatch for faster access in subsequent runs
    if (productMatch != null) {
        matches.put(entry.getElementName(), productMatch);
        return productMatch;
    } else {
        noMatches.add(entry.getElementName());
        return null;
    }
}

From source file:org.switchyard.tools.ui.SwitchYardModelUtils.java

License:Open Source License

/**
 * Return the corresponding resource for the resource path.
 * /*w ww. ja va 2s  .  com*/
 * @param project the project containing the resource (or reference)
 * @param resourcePath the location relative to the project's classpath
 * @return the corresponding resource.
 */
public static IResource getJavaResource(IProject project, String resourcePath) {
    if (project == null || resourcePath == null || resourcePath.length() == 0) {
        return null;
    }

    IJavaProject jp = JavaCore.create(project);
    if (jp == null) {
        return null;
    }
    resourcePath = URI.create(resourcePath).getPath();
    try {
        for (IPackageFragmentRoot pfr : jp.getAllPackageFragmentRoots()) {
            if (pfr.isArchive() || pfr.isExternal()) {
                continue;
            }
            final IPath path = pfr.getPath().append(resourcePath);
            IFile file = project.getWorkspace().getRoot().getFile(path);
            if (file.exists()) {
                return file;
            }
        }
    } catch (JavaModelException e) {
        return null;
    }
    return null;
}

From source file:org.wso2.developerstudio.eclipse.utils.jdt.JavaUtils.java

License:Open Source License

public static IPackageFragmentRoot[] getReferencedLibrariesForProject(IProject project)
        throws JavaModelException {
    IJavaProject p = JavaCore.create(project);
    IPackageFragmentRoot[] packageFragmentRoots = null;
    if (p != null) {
        packageFragmentRoots = p.getPackageFragmentRoots();
    }//from w  w  w .j av  a 2  s.co  m

    ArrayList<IPackageFragmentRoot> jarClassPaths = new ArrayList<IPackageFragmentRoot>();
    if (packageFragmentRoots != null) {
        for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) {
            if (isWebApp && packageFragmentRoot.isArchive()) {
                if (packageFragmentRoot.getRawClasspathEntry().getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                    jarClassPaths.add(packageFragmentRoot);
                }

            } else if (!isWebApp) {
                if (packageFragmentRoot.getRawClasspathEntry().getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                    jarClassPaths.add(packageFragmentRoot);
                }
            }
        }
    }
    return jarClassPaths.toArray(new IPackageFragmentRoot[] {});
}

From source file:org.wso2.developerstudio.eclipse.utils.jdt.JavaUtils.java

License:Open Source License

public static IPackageFragmentRoot[] getReferencedVariableLibrariesForProject(IProject project)
        throws JavaModelException {
    IJavaProject p = JavaCore.create(project);
    IPackageFragmentRoot[] packageFragmentRoots = p.getPackageFragmentRoots();
    ArrayList<IPackageFragmentRoot> jarClassPaths = new ArrayList<IPackageFragmentRoot>();
    for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) {
        if (isWebApp && packageFragmentRoot.isArchive()) {
            IClasspathEntry rawClasspathEntry = packageFragmentRoot.getRawClasspathEntry();
            IClasspathEntry resolvedClasspathEntry = JavaCore.getResolvedClasspathEntry(rawClasspathEntry);
            if (rawClasspathEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE
                    && resolvedClasspathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                jarClassPaths.add(packageFragmentRoot);
            }/* w  ww.  j a  va 2 s. com*/
        } else if (!isWebApp) {
            IClasspathEntry rawClasspathEntry = packageFragmentRoot.getRawClasspathEntry();
            IClasspathEntry resolvedClasspathEntry = JavaCore.getResolvedClasspathEntry(rawClasspathEntry);
            if (rawClasspathEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE
                    && resolvedClasspathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                jarClassPaths.add(packageFragmentRoot);
            }
        }
    }
    return jarClassPaths.toArray(new IPackageFragmentRoot[] {});
}

From source file:org.wso2.developerstudio.eclipse.utils.jdt.JavaUtils.java

License:Open Source License

public static IPackageFragmentRoot[] getSourceFoldersForProject(IProject project) throws JavaModelException {
    IJavaProject p = JavaCore.create(project);
    IPackageFragmentRoot[] packageFragmentRoots = p.getPackageFragmentRoots();
    ArrayList<IPackageFragmentRoot> jarClassPaths = new ArrayList<IPackageFragmentRoot>();
    for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) {
        if (isWebApp && packageFragmentRoot.isArchive()) {
            if (packageFragmentRoot.getRawClasspathEntry().getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                jarClassPaths.add(packageFragmentRoot);
            }//from w  w w.java2 s .  co m
        } else if (!isWebApp) {
            if (packageFragmentRoot.getRawClasspathEntry().getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                jarClassPaths.add(packageFragmentRoot);
            }
        }
    }
    return jarClassPaths.toArray(new IPackageFragmentRoot[] {});
}