List of usage examples for org.eclipse.jdt.internal.core JarPackageFragmentRoot getPackageFragment
@Override
public PackageFragment getPackageFragment(String[] pkgName)
From source file:org.jboss.tools.common.text.ext.hyperlink.xml.FaceletSourceTagHyperlink.java
License:Open Source License
/** * /*from w ww . j a v a 2 s . co m*/ * @param project project from which we are going to open File * @param classPathResource resource relativy to class path * @param xmodelPath xmodel path to file * @return */ private static JarEntryEditorInput seachResourceInClassPath(IProject project, IPath classPathResource, IPath xmodelPath) { IJavaProject javaProject = JavaCore.create(project); try { for (IPackageFragmentRoot fragmentRoot : javaProject.getAllPackageFragmentRoots()) { if (fragmentRoot instanceof JarPackageFragmentRoot) { JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot) fragmentRoot; ZipEntry zipEntry = jarPackageFragmentRoot.getJar().getEntry(classPathResource.toString()); //the name of jar file shoul be in xmodel path //for now if model have following if (zipEntry != null && xmodelPath.toString().contains(fragmentRoot.getElementName())) { JarEntryFile fileInJar = new JarEntryFile(classPathResource.lastSegment()); Object parent = null; String parentName = classPathResource.removeLastSegments(1).toString(); if (parentName.length() == 0) { parent = jarPackageFragmentRoot; } else { parent = jarPackageFragmentRoot .getPackageFragment(classPathResource.removeLastSegments(1).toString()); } fileInJar.setParent(parent); JarEntryEditorInput jarEditorInput = new JarEntryEditorInput(fileInJar); return jarEditorInput; } } } } catch (JavaModelException e) { ExtensionsPlugin.getDefault().logError(e); } catch (CoreException e) { ExtensionsPlugin.getDefault().logError(e); } return null; }
From source file:org.jboss.tools.jsf.vpe.jsf.test.jbide.JBIDE4510Test.java
License:Open Source License
public void testCorrectDoctypeOnFileFromJarArchive() throws Throwable { IProject project = ProjectsLoader.getInstance().getProject(JsfAllTests.IMPORT_JBIDE3247_PROJECT_NAME); /*//ww w.j a v a 2 s. c om * Project should exist in the workspace */ assertNotNull("Project was not found in the workspace: " //$NON-NLS-1$ + JsfAllTests.IMPORT_JBIDE3247_PROJECT_NAME, project); IFile jarArchive = (IFile) project.findMember(JAR_NAME); /* * Jar file should exist in the project. */ assertNotNull("File was not found in the project: " //$NON-NLS-1$ + JsfAllTests.IMPORT_JBIDE3247_PROJECT_NAME + "/" + JAR_NAME, //$NON-NLS-1$ jarArchive); IJavaProject javaProject = JavaCore.create(project); /* * Project should be correctly transformed. */ assertNotNull("Cannot process java project:" //$NON-NLS-1$ + JsfAllTests.IMPORT_JBIDE3247_PROJECT_NAME, javaProject); IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(jarArchive.getLocation().toString()); /* * Root element should have the correct type. */ if (root instanceof JarPackageFragmentRoot) { JarPackageFragmentRoot jarRoot = (JarPackageFragmentRoot) root; IPackageFragment pf = jarRoot.getPackageFragment(PACKAGE_NAME); JarEntryFile jarFile = new JarEntryFile(SHORT_NAME); jarFile.setParent(pf); JarEntryEditorInput jarEditorInput = new JarEntryEditorInput(jarFile); JSPMultiPageEditor editor = openEditor(jarEditorInput); /* * Verify that the editor is opened. */ assertNotNull( "Visual Page Editor with a file from the jar archive should have been opened but it wasn't.", //$NON-NLS-1$ editor); /* * Get the DOM document */ nsIDOMDocument document = TestUtil.getVpeVisualDocument(editor); nsIDOMDocumentType doctype = document.getDoctype(); /* * Doctype should present for the current file. */ assertNotNull("Doctype should present for the specified file: " //$NON-NLS-1$ + JsfAllTests.IMPORT_JBIDE3247_PROJECT_NAME + "/" //$NON-NLS-1$ + JAR_NAME + "/" + FILE_NAME, doctype); //$NON-NLS-1$ /* * Doctype should have the correct type. */ assertEquals("Doctype should have the correct type: \" HTML \", but was: " + doctype.getNodeName(), //$NON-NLS-1$ "HTML", doctype.getNodeName()); //$NON-NLS-1$ } else { /* * Fail the test when we cannot process jar file correctly. */ fail("Jar file cannot be processed. Jar file: " //$NON-NLS-1$ + JsfAllTests.IMPORT_JBIDE3247_PROJECT_NAME + "/" //$NON-NLS-1$ + JAR_NAME); } }
From source file:org.jboss.tools.jsf.vpe.jsf.test.jbide.OpenOnInJarPackageFragment_JBIDE5682.java
License:Open Source License
public void testOpenOnInJarPackageFragment() throws Throwable { IProject project = ProjectsLoader.getInstance().getProject(JsfAllTests.IMPORT_JSF_20_PROJECT_NAME); IJavaProject javaProject = JavaCore.create(project); IPackageFragmentRoot fragmentRoot = javaProject .getPackageFragmentRoot(javaProject.getPath().toString() + "/" //$NON-NLS-1$ + JAR_LIB_PATH);//from ww w . j a v a 2 s .co m JarPackageFragmentRoot jarPackageFragmentRoot = (JarPackageFragmentRoot) fragmentRoot; JarEntryFile fileInJar = new JarEntryFile(TEST_FILE); PackageFragment fragment = jarPackageFragmentRoot.getPackageFragment(FRAGMENT_PATH); fileInJar.setParent(fragment); JarEntryEditorInput editorInput = new JarEntryEditorInput(fileInJar); OpenOnUtil.checkOpenOnInEditor(editorInput, getEditorId(fileInJar.getName()), 78, 44, "IfHandler.class"); //$NON-NLS-1$ }