List of usage examples for org.eclipse.jdt.internal.core JarEntryDirectory getChildren
@Override
public IJarEntryResource[] getChildren()
From source file:org.eclipse.che.plugin.java.server.JavaNavigation.java
License:Open Source License
private Object[] findJarDirectoryChildren(JarEntryDirectory directory, String path) { String directoryPath = directory.getFullPath().toOSString(); if (directoryPath.equals(path)) { return directory.getChildren(); }//from w w w .j av a 2s . co m if (path.startsWith(directoryPath)) { for (IJarEntryResource resource : directory.getChildren()) { String childrenPath = resource.getFullPath().toOSString(); if (childrenPath.equals(path)) { return resource.getChildren(); } if (path.startsWith(childrenPath) && resource instanceof JarEntryDirectory) { findJarDirectoryChildren((JarEntryDirectory) resource, path); } } } return null; }
From source file:org.eclipse.che.plugin.java.server.JavaNavigation.java
License:Open Source License
private JarEntryFile findJarFile(JarEntryDirectory directory, String path) { for (IJarEntryResource children : directory.getChildren()) { if (children.isFile() && children.getFullPath().toOSString().equals(path)) { return (JarEntryFile) children; }/* www .j a v a 2s . c om*/ if (!children.isFile()) { JarEntryFile file = findJarFile((JarEntryDirectory) children, path); if (file != null) { return file; } } } return null; }
From source file:org.springframework.ide.eclipse.beans.ui.properties.NonJavaResourceContentProvider.java
License:Open Source License
private Object[] getResources(JarEntryDirectory element) { return element.getChildren(); }
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; }// w w w . j a va 2 s .co 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; } }