use of org.eclipse.jdt.core.IJarEntryResource in project xtext-eclipse by eclipse.
the class PackageFragmentRootWalker method traverse.
public T traverse(IPackageFragmentRoot root, boolean stopOnFirstResult) throws JavaModelException {
T result = null;
if (root.exists() && existsPhysically(root)) {
Object[] resources = root.getNonJavaResources();
TraversalState state = new TraversalState(root);
for (Object object : resources) {
if (object instanceof IJarEntryResource) {
result = traverse((IJarEntryResource) object, stopOnFirstResult, state);
if (stopOnFirstResult && result != null)
return result;
}
}
IJavaElement[] children = root.getChildren();
for (IJavaElement javaElement : children) {
if (javaElement instanceof IPackageFragment) {
result = traverse((IPackageFragment) javaElement, stopOnFirstResult, state);
if (stopOnFirstResult && result != null)
return result;
}
}
}
return result;
}
use of org.eclipse.jdt.core.IJarEntryResource in project xtext-eclipse by eclipse.
the class Storage2UriMapperJavaImpl method initializeData.
/**
* @since 2.4
*/
protected PackageFragmentRootData initializeData(final IPackageFragmentRoot root) {
final PackageFragmentRootData data = new PackageFragmentRootData(computeModificationStamp(root));
data.addRoot(root);
if (shouldHandle(root)) {
try {
final SourceAttachmentPackageFragmentRootWalker<Void> walker = new SourceAttachmentPackageFragmentRootWalker<Void>() {
@Override
protected URI getURI(IFile file, org.eclipse.xtext.ui.resource.PackageFragmentRootWalker.TraversalState state) {
if (!uriValidator.isPossiblyManaged(file))
return null;
return super.getURI(file, state);
}
@Override
protected URI getURI(IJarEntryResource jarEntry, org.eclipse.xtext.ui.resource.PackageFragmentRootWalker.TraversalState state) {
if (!uriValidator.isPossiblyManaged(jarEntry))
return null;
final URI uri = locator.getURI(root, jarEntry, state);
if (!uriValidator.isValid(uri, jarEntry))
return null;
return uri;
}
@Override
protected Void handle(URI uri, IStorage storage, org.eclipse.xtext.ui.resource.PackageFragmentRootWalker.TraversalState state) {
data.uri2Storage.put(uri, storage);
return null;
}
};
walker.traverse(root, false);
if (walker.getBundleSymbolicName() != null)
data.uriPrefix = URI.createPlatformResourceURI(walker.getBundleSymbolicName() + "/", true);
} catch (RuntimeException e) {
log.error(e.getMessage(), e);
} catch (JavaModelException e) {
log.debug(e.getMessage(), e);
}
}
return data;
}
use of org.eclipse.jdt.core.IJarEntryResource in project jbosstools-base by jbosstools.
the class ModelObjectStorageEditorInput method findJarEntryFile.
IJarEntryResource findJarEntryFile() {
XModelObject o = object;
JarEntryFile f = null;
JarEntryResource current = null;
String packageName = "";
List<String> parts = new ArrayList<String>();
List<XModelObject> os = new ArrayList<XModelObject>();
while (o != null && o.getFileType() != XModelObject.SYSTEM) {
String part = o.getFileType() == XModelObject.FILE ? FileAnyImpl.toFileName(o) : o.getFileType() == XModelObject.FOLDER ? o.getAttributeValue(XModelObjectConstants.ATTR_NAME) : null;
if (part != null) {
parts.add(0, part);
os.add(0, o);
if (f == null) {
f = new JarEntryFile(part) {
public InputStream getContents() throws CoreException {
return storage.getContents();
}
};
current = f;
} else {
if (packageName.length() > 0) {
packageName = part + "." + packageName;
} else {
packageName = part;
}
JarEntryDirectory d = new JarEntryDirectory(part);
current.setParent(d);
current = d;
}
}
o = o.getParent();
}
// if(!(o instanceof JarSystemImpl)) return null;
String file = Paths.expand(o.get(XModelObjectConstants.ATTR_NAME_LOCATION), o.getModel().getProperties());
IProject p = EclipseResourceUtil.getProject(o);
IJavaProject jp = EclipseResourceUtil.getJavaProject(p);
if (jp == null)
return null;
IPackageFragmentRoot root = null;
try {
IPackageFragmentRoot[] rs = jp.getAllPackageFragmentRoots();
for (IPackageFragmentRoot r : rs) {
if (r.getResource() != null && r.getResource().exists() && r.getResource().getLocation().toString().equals(file)) {
root = r;
} else if (r.getPath() != null && r.getPath().toString().equals(file)) {
root = r;
}
}
} catch (CoreException e) {
ModelUIPlugin.getDefault().logError(e);
}
if (root == null) {
root = jp.getPackageFragmentRoot(file);
}
if (root == null) {
return null;
}
if (current != null && !"META-INF".equalsIgnoreCase(current.getName()) && packageName.length() > 0) {
IPackageFragment pf = root.getPackageFragment(packageName);
f.setParent(pf);
} else {
current.setParent(root);
if (!(o instanceof JarSystemImpl)) {
Object q = root;
NonJavaResource nj = null;
for (int i = 0; i < parts.size(); i++) {
IResource ri = (IResource) os.get(i).getAdapter(IResource.class);
if (ri == null) {
return f;
}
nj = new NonJavaResource(q, ri);
q = nj;
}
if (nj != null) {
return nj;
}
}
}
return f;
}
use of org.eclipse.jdt.core.IJarEntryResource in project quarkus-ls by redhat-developer.
the class QuarkusConfigRootProvider method getJavadoc.
/**
* Returns the Javadoc from the given field. There are 3 strategies to extract
* the Javadoc:
*
* <ul>
* <li>try to extract Javadoc from the source (from '.java' source file or from
* JAR which is linked to source).</li>
* <li>try to get Javadoc from the attached Javadoc.</li>
* <li>get Javadoc from the Quarkus properties file stored in JAR META-INF/
* </ul>
*
* @param field the field to process
* @param javadocCache the Javadoc cache
* @param monitor the progress monitor
* @return the doc entry for the field
* @throws JavaModelException
*/
private static String getJavadoc(IField field, Map<IPackageFragmentRoot, Properties> javadocCache, IProgressMonitor monitor) throws JavaModelException {
// TODO: get Javadoc from source anad attached doc by processing Javadoc tag as
// markdown
// Try to get javadoc from sources
/*
* String javadoc = findJavadocFromSource(field); if (javadoc != null) { return
* javadoc; } // Try to get attached javadoc javadoc =
* field.getAttachedJavadoc(monitor); if (javadoc != null) { return javadoc; }
*/
// Try to get the javadoc inside the META-INF/quarkus-javadoc.properties of the
// JAR
IPackageFragmentRoot packageRoot = (IPackageFragmentRoot) field.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
Properties properties = javadocCache.get(packageRoot);
if (properties == null) {
properties = new Properties();
javadocCache.put(packageRoot, properties);
IJarEntryResource quarkusJavadocResource = findJavadocFromQuakusJavadocProperties(packageRoot);
if (quarkusJavadocResource != null) {
try {
properties.load(quarkusJavadocResource.getContents());
} catch (Exception e) {
// TODO : log it
e.printStackTrace();
}
}
}
if (properties.isEmpty()) {
return null;
}
// The META-INF/quarkus-javadoc.properties stores Javadoc without $ . Ex:
// io.quarkus.deployment.SslProcessor.SslConfig.native_=Enable native SSL
// support.
String fieldKey = field.getDeclaringType().getFullyQualifiedName() + "." + field.getElementName();
// Here field key contains '$'
// Ex : io.quarkus.deployment.SslProcessor$SslConfig.native_
// replace '$' with '.'
fieldKey = fieldKey.replace('$', '.');
return properties.getProperty(fieldKey);
}
use of org.eclipse.jdt.core.IJarEntryResource in project xtext-eclipse by eclipse.
the class PackageFragmentRootWalkerTest method testTraversePackageFragmentRoot.
@Test
public void testTraversePackageFragmentRoot() throws Exception {
IJavaProject project = createJavaProject("foo");
String jarName = "JarWalkerTest.jar";
IFile file = project.getProject().getFile(jarName);
file.create(getClass().getResourceAsStream(jarName), true, new NullProgressMonitor());
addJarToClasspath(project, file);
final Set<IPath> pathes = new HashSet<IPath>();
PackageFragmentRootWalker<Void> walker = new PackageFragmentRootWalker<Void>() {
@Override
protected Void handle(IJarEntryResource jarEntry, TraversalState state) {
pathes.add(jarEntry.getFullPath());
return null;
}
};
for (IPackageFragmentRoot root : project.getPackageFragmentRoots()) {
if (root.getElementName().equals(jarName))
walker.traverse(root, false);
}
assertEquals(3, pathes.size());
}
Aggregations