Search in sources :

Example 11 with ITaglibRecord

use of org.eclipse.jst.jsp.core.taglib.ITaglibRecord in project webtools.sourceediting by eclipse.

the class TestIndex method testAvailableAfterCopyingJARIntoProject.

public void testAvailableAfterCopyingJARIntoProject() throws Exception {
    // Create new project
    IProject project = BundleResourceUtil.createSimpleProject("bug_118251-f", null, null);
    assertTrue(project.exists());
    ITaglibRecord[] records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-f"));
    assertEquals("wrong number of taglib records found before unpacking", 0, records.length);
    BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/bug_118251-f", "/bug_118251-f");
    // bug_118251-f/WebContent/WEB-INF/web.xml
    // bug_118251-f/WebContent/WEB-INF/tld/sample2_for_118251-e.tld
    // bug_118251-f/WebContent/META-INF/MANIFEST.MF
    // bug_118251-f/WebContent/test1.jsp
    // bug_118251-f/.classpath
    // bug_118251-f/.project
    String url = "http://example.com/sample-taglib";
    ITaglibRecord taglibRecord = TaglibIndex.resolve("/bug_118251-f/WebContent/test1.jsp", url, false);
    assertNull("unexpected record found for " + url, taglibRecord);
    records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-f/WebContent/"));
    assertEquals("wrong number of taglib records found after unpacking but before copying", 3, records.length);
    /*
		 * increase by <b>one</b> for the URL to the TLD in the jar (one
		 * implicit for the TLD in the jar as a resource and another implicit
		 * overwriting it with the same URL to the TLD in the jar on the
		 * classpath)
		 */
    BundleResourceUtil.copyBundleEntryIntoWorkspace("/testfiles/bug_118251-sample/sample_tld.jar", "/bug_118251-f/WebContent/WEB-INF/lib/sample_tld.jar");
    taglibRecord = TaglibIndex.resolve("/bug_118251-f/WebContent/test1.jsp", url, false);
    assertNotNull("no record found for " + url, taglibRecord);
    assertTrue("record found was wrong type", taglibRecord instanceof IURLRecord);
    assertNotNull("record has no base location", ((IURLRecord) taglibRecord).getBaseLocation());
    assertEquals("record has wrong short name", "sample", ((IURLRecord) taglibRecord).getShortName());
    assertEquals("record has wrong URI", url, ((IURLRecord) taglibRecord).getDescriptor().getURI());
    URL recordURL = ((IURLRecord) taglibRecord).getURL();
    assertNotNull("record has no URL", recordURL);
    assertTrue("record has wrong URL", recordURL.toString().length() > 4);
    assertEquals("record has wrong URL protocol", "jar:", recordURL.toString().substring(0, 4));
    assertEquals("record has wrong URL", "/bug_118251-f/WebContent/WEB-INF/lib/sample_tld.jar!/folder/sample_for_118251.tld", recordURL.toString().substring(recordURL.toString().length() - 81));
    records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-f/WebContent/"));
    assertEquals("wrong number of taglib records found after copying", 4, records.length);
    records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-f/WebContent"));
    assertEquals("wrong number of taglib records found after copying", 4, records.length);
    records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-f/WebContent/WEB-INF"));
    assertEquals("wrong number of taglib records found after copying", 4, records.length);
    records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-f/WebContent/WEB-INF/web.xml"));
    assertEquals("wrong number of taglib records found after copying", 4, records.length);
}
Also used : Path(org.eclipse.core.runtime.Path) ITaglibRecord(org.eclipse.jst.jsp.core.taglib.ITaglibRecord) IURLRecord(org.eclipse.jst.jsp.core.taglib.IURLRecord) IProject(org.eclipse.core.resources.IProject) URL(java.net.URL)

Example 12 with ITaglibRecord

use of org.eclipse.jst.jsp.core.taglib.ITaglibRecord in project webtools.sourceediting by eclipse.

the class TestIndex method testAvailableFromExportedOnBuildpathFromAnotherProject.

public void testAvailableFromExportedOnBuildpathFromAnotherProject() throws Exception {
    TaglibIndex.shutdown();
    // Create project 1
    IProject project = BundleResourceUtil.createSimpleProject("testavailable1", null, null);
    assertTrue(project.isAccessible());
    BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/testavailable1", "/testavailable1");
    // Create project 2
    IProject project2 = BundleResourceUtil.createSimpleProject("testavailable2", null, null);
    assertTrue(project2.isAccessible());
    BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/testavailable2", "/testavailable2");
    BundleResourceUtil.copyBundleEntryIntoWorkspace("/testfiles/bug_118251-sample/sample_tld.jar", "/testavailable2/WebContent/WEB-INF/lib/sample_tld.jar");
    TaglibIndex.startup();
    // make sure project 1 sees no taglibs
    ITaglibRecord[] records = TaglibIndex.getAvailableTaglibRecords(new Path("/testavailable1/WebContent"));
    assertEquals("ITaglibRecords were found", 0, records.length);
    // make sure project 2 sees two taglibs
    ITaglibRecord[] records2 = TaglibIndex.getAvailableTaglibRecords(new Path("/testavailable2/WebContent"));
    if (records2.length != 2) {
        for (int i = 0; i < records2.length; i++) {
            System.err.println(records2[i]);
        }
    }
    assertEquals("total ITaglibRecord count doesn't match", 2, records2.length);
    TaglibIndex.shutdown();
    TaglibIndex.startup();
    records2 = TaglibIndex.getAvailableTaglibRecords(new Path("/testavailable2/WebContent"));
    assertEquals("total ITaglibRecord count doesn't match after restart", 2, records2.length);
    IJavaProject created = JavaCore.create(project2);
    assertTrue("/availabletest2 not a Java project", created.exists());
    // export the jar from project 2
    IClasspathEntry[] entries = created.getRawClasspath();
    boolean found = false;
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry entry = entries[i];
        if (entry.getPath().equals(new Path("/testavailable2/WebContent/WEB-INF/lib/sample_tld.jar"))) {
            found = true;
            assertFalse("was exported", entry.isExported());
            ((ClasspathEntry) entry).isExported = true;
        }
    }
    assertTrue("/testavailable2/WebContent/WEB-INF/lib/sample_tld.jar was not found in build path", found);
    IClasspathEntry[] entries2 = new IClasspathEntry[entries.length];
    System.arraycopy(entries, 1, entries2, 0, entries.length - 1);
    entries2[entries.length - 1] = entries[0];
    created.setRawClasspath(entries2, new NullProgressMonitor());
    entries = created.getRawClasspath();
    found = false;
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry entry = entries[i];
        if (entry.getPath().equals(new Path("/testavailable2/WebContent/WEB-INF/lib/sample_tld.jar"))) {
            found = true;
            assertTrue("/testavailable2/WebContent/WEB-INF/lib/sample_tld.jar was not exported", ((ClasspathEntry) entry).isExported);
        }
    }
    assertTrue("/testavailable2/WebContent/WEB-INF/lib/sample_tld.jar was not found (and exported) in build path", found);
    // project 2 should still have just two taglibs
    records = TaglibIndex.getAvailableTaglibRecords(new Path("/testavailable2/WebContent"));
    assertEquals("total ITaglibRecord count doesn't match (after exporting jar)", 2, records.length);
    // now one taglib should be visible from project 1
    records = TaglibIndex.getAvailableTaglibRecords(new Path("/testavailable1/WebContent"));
    assertEquals("total ITaglibRecord count doesn't match (after exporting jar), classpath provider problem?", 1, records.length);
    TaglibIndex.shutdown();
    TaglibIndex.startup();
    // project 2 should still have just two taglibs
    records = TaglibIndex.getAvailableTaglibRecords(new Path("/testavailable2/WebContent"));
    assertEquals("total ITaglibRecord count doesn't match (after exporting jar and restarting)", 2, records.length);
    // and one taglib should still be visible from project 1
    records = TaglibIndex.getAvailableTaglibRecords(new Path("/testavailable1/WebContent"));
    assertEquals("total ITaglibRecord count doesn't match (after exporting jar and restarting)", 1, records.length);
}
Also used : Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ITaglibRecord(org.eclipse.jst.jsp.core.taglib.ITaglibRecord) IProject(org.eclipse.core.resources.IProject)

Example 13 with ITaglibRecord

use of org.eclipse.jst.jsp.core.taglib.ITaglibRecord in project webtools.sourceediting by eclipse.

the class TestIndex method testAvailableAfterCopyingJARIntoProject2.

public void testAvailableAfterCopyingJARIntoProject2() throws Exception {
    // Create new project
    IProject project = BundleResourceUtil.createSimpleProject("bug_118251-g", null, null);
    assertTrue(project.exists());
    ITaglibRecord[] records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-g"));
    assertEquals("wrong number of taglib records found before unpacking", 0, records.length);
    BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/bug_118251-g", "/bug_118251-g");
    // bug_118251-g/Web Content/WEB-INF/web.xml
    // bug_118251-g/Web Content/WEB-INF/tld/sample2_for_118251-e.tld
    // bug_118251-g/Web Content/META-INF/MANIFEST.MF
    // bug_118251-g/Web Content/test1.jsp
    // bug_118251-g/.classpath
    // bug_118251-g/.project
    String url = "http://example.com/sample-taglib";
    ITaglibRecord taglibRecord = TaglibIndex.resolve("/bug_118251-g/Web Content/test1.jsp", url, false);
    assertNull("unexpected record found for " + url, taglibRecord);
    records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-g/Web Content/"));
    assertEquals("wrong number of taglib records found after unpacking but before copying", 3, records.length);
    /*
		 * increase by <b>one</b> for the URL to the TLD in the jar (one
		 * implicit for the TLD in the jar as a resource and another implicit
		 * overwriting it with the same URL to the TLD in the jar on the
		 * classpath)
		 */
    BundleResourceUtil.copyBundleEntryIntoWorkspace("/testfiles/bug_118251-sample/sample_tld.jar", "/bug_118251-g/Web Content/WEB-INF/lib/sample_tld.jar");
    taglibRecord = TaglibIndex.resolve("/bug_118251-g/Web Content/test1.jsp", url, false);
    assertNotNull("no record found for " + url, taglibRecord);
    assertTrue("record found was wrong type", taglibRecord instanceof IURLRecord);
    assertNotNull("record has no base location", ((IURLRecord) taglibRecord).getBaseLocation());
    assertEquals("record has wrong short name", "sample", ((IURLRecord) taglibRecord).getShortName());
    assertEquals("record has wrong URI", url, ((IURLRecord) taglibRecord).getDescriptor().getURI());
    URL recordURL = ((IURLRecord) taglibRecord).getURL();
    assertNotNull("record has no URL", recordURL);
    assertTrue("record has wrong URL", recordURL.toString().length() > 4);
    assertEquals("record has wrong URL protocol", "jar:", recordURL.toString().substring(0, 4));
    assertEquals("record has wrong URL", "/bug_118251-g/Web Content/WEB-INF/lib/sample_tld.jar!/folder/sample_for_118251.tld", recordURL.toString().substring(recordURL.toString().length() - 82));
    records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-g/Web Content/"));
    assertEquals("wrong number of taglib records found after copying", 4, records.length);
    records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-g/Web Content"));
    assertEquals("wrong number of taglib records found after copying", 4, records.length);
    records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-g/Web Content/WEB-INF"));
    assertEquals("wrong number of taglib records found after copying", 4, records.length);
    records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-g/Web Content/WEB-INF/web.xml"));
    assertEquals("wrong number of taglib records found after copying", 4, records.length);
}
Also used : Path(org.eclipse.core.runtime.Path) ITaglibRecord(org.eclipse.jst.jsp.core.taglib.ITaglibRecord) IURLRecord(org.eclipse.jst.jsp.core.taglib.IURLRecord) IProject(org.eclipse.core.resources.IProject) URL(java.net.URL)

Example 14 with ITaglibRecord

use of org.eclipse.jst.jsp.core.taglib.ITaglibRecord in project webtools.sourceediting by eclipse.

the class TLDCMDocumentManager method loadTaglib.

/**
 * Loads the taglib from the specified URI. It must point to a valid
 * taglib descriptor to work.
 */
protected CMDocument loadTaglib(String uri) {
    CMDocument document = null;
    IPath currentPath = getCurrentParserPath();
    if (currentPath != null) {
        ITaglibRecord record = TaglibIndex.resolve(currentPath.toString(), uri, false);
        if (record != null) {
            document = getCMDocumentBuilder().createCMDocument(record);
        } else {
            /* Not a very-often used code path (we hope) */
            IPath currentBaseLocation = getCurrentBaseLocation();
            if (currentBaseLocation != null) {
                String location = URIResolverPlugin.createResolver().resolve(currentBaseLocation.toString(), null, uri);
                if (location != null) {
                    if (_debug) {
                        // $NON-NLS-2$//$NON-NLS-1$
                        System.out.println("Loading tags from " + uri + " at " + location);
                    }
                    document = getCMDocumentBuilder().createCMDocument(location);
                }
            }
        }
    }
    return document;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) IPath(org.eclipse.core.runtime.IPath) ITaglibRecord(org.eclipse.jst.jsp.core.taglib.ITaglibRecord)

Example 15 with ITaglibRecord

use of org.eclipse.jst.jsp.core.taglib.ITaglibRecord in project webtools.sourceediting by eclipse.

the class TLDCMDocumentManager method getCacheKey.

/**
 * Derives an unique cache key for the give URI. The URI is "resolved" and
 * a unique value generated from the result. This ensures that two
 * different relative references from different files do not have
 * overlapping TLD records in the shared cache if they don't resolve to
 * the same TLD.
 *
 * @param uri
 * @return
 */
protected Object getCacheKey(String uri) {
    IPath currentParserPath = getCurrentParserPath();
    if (currentParserPath == null)
        return null;
    ITaglibRecord record = TaglibIndex.resolve(currentParserPath.toString(), uri, false);
    if (record != null) {
        return getUniqueIdentifier(record);
    }
    String location = URIResolverPlugin.createResolver().resolve(getCurrentBaseLocation().toString(), null, uri);
    return location;
}
Also used : IPath(org.eclipse.core.runtime.IPath) ITaglibRecord(org.eclipse.jst.jsp.core.taglib.ITaglibRecord)

Aggregations

ITaglibRecord (org.eclipse.jst.jsp.core.taglib.ITaglibRecord)16 IProject (org.eclipse.core.resources.IProject)10 Path (org.eclipse.core.runtime.Path)10 IPath (org.eclipse.core.runtime.IPath)5 IFile (org.eclipse.core.resources.IFile)4 URL (java.net.URL)3 CMElementDeclarationImpl (org.eclipse.jst.jsp.core.internal.contentmodel.tld.CMElementDeclarationImpl)3 ITLDRecord (org.eclipse.jst.jsp.core.taglib.ITLDRecord)3 IURLRecord (org.eclipse.jst.jsp.core.taglib.IURLRecord)3 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)3 CoreException (org.eclipse.core.runtime.CoreException)2 CMDocumentFactoryTLD (org.eclipse.jst.jsp.core.internal.contentmodel.tld.CMDocumentFactoryTLD)2 IJarRecord (org.eclipse.jst.jsp.core.taglib.IJarRecord)2 ITagDirRecord (org.eclipse.jst.jsp.core.taglib.ITagDirRecord)2 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)2 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)2 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)2 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)2 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)2 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)2