Lines 11-26
Link Here
|
11 |
package org.eclipse.jst.jsp.core.internal.taglib; |
11 |
package org.eclipse.jst.jsp.core.internal.taglib; |
12 |
|
12 |
|
13 |
|
13 |
|
14 |
import java.io.File; |
|
|
15 |
import java.util.ArrayList; |
14 |
import java.util.ArrayList; |
16 |
import java.util.Collection; |
15 |
import java.util.Collection; |
17 |
import java.util.HashMap; |
16 |
import java.util.HashMap; |
18 |
import java.util.HashSet; |
|
|
19 |
import java.util.Hashtable; |
17 |
import java.util.Hashtable; |
20 |
import java.util.Iterator; |
18 |
import java.util.Iterator; |
21 |
import java.util.List; |
19 |
import java.util.List; |
22 |
import java.util.Map; |
20 |
import java.util.Map; |
23 |
import java.util.Set; |
|
|
24 |
|
21 |
|
25 |
import javax.servlet.jsp.tagext.TagAttributeInfo; |
22 |
import javax.servlet.jsp.tagext.TagAttributeInfo; |
26 |
import javax.servlet.jsp.tagext.TagData; |
23 |
import javax.servlet.jsp.tagext.TagData; |
Lines 30-45
Link Here
|
30 |
import javax.servlet.jsp.tagext.ValidationMessage; |
27 |
import javax.servlet.jsp.tagext.ValidationMessage; |
31 |
import javax.servlet.jsp.tagext.VariableInfo; |
28 |
import javax.servlet.jsp.tagext.VariableInfo; |
32 |
|
29 |
|
33 |
import org.eclipse.core.resources.IFile; |
|
|
34 |
import org.eclipse.core.resources.IFolder; |
35 |
import org.eclipse.core.resources.IProject; |
30 |
import org.eclipse.core.resources.IProject; |
36 |
import org.eclipse.core.resources.ResourcesPlugin; |
|
|
37 |
import org.eclipse.core.runtime.CoreException; |
38 |
import org.eclipse.core.runtime.IPath; |
31 |
import org.eclipse.core.runtime.IPath; |
39 |
import org.eclipse.core.runtime.NullProgressMonitor; |
32 |
import org.eclipse.core.runtime.NullProgressMonitor; |
40 |
import org.eclipse.core.runtime.Platform; |
33 |
import org.eclipse.core.runtime.Platform; |
41 |
import org.eclipse.jdt.core.IClasspathContainer; |
|
|
42 |
import org.eclipse.jdt.core.IClasspathEntry; |
43 |
import org.eclipse.jdt.core.IJavaProject; |
34 |
import org.eclipse.jdt.core.IJavaProject; |
44 |
import org.eclipse.jdt.core.JavaCore; |
35 |
import org.eclipse.jdt.core.JavaCore; |
45 |
import org.eclipse.jdt.core.JavaModelException; |
36 |
import org.eclipse.jdt.core.JavaModelException; |
Lines 83-99
Link Here
|
83 |
} |
74 |
} |
84 |
|
75 |
|
85 |
private IProject fProject = null; |
76 |
private IProject fProject = null; |
86 |
private TaglibClassLoader fLoader = null; |
77 |
private ClassLoader fLoader = null; |
87 |
|
78 |
|
88 |
private Set fProjectEntries = null; |
|
|
89 |
private Map fTranslationProblems = null; |
79 |
private Map fTranslationProblems = null; |
90 |
private Set fContainerEntries = null; |
|
|
91 |
private IJavaProject fJavaProject; |
80 |
private IJavaProject fJavaProject; |
92 |
|
81 |
|
93 |
public TaglibHelper(IProject project) { |
82 |
public TaglibHelper(IProject project) { |
|
|
83 |
super(); |
94 |
setProject(project); |
84 |
setProject(project); |
95 |
fProjectEntries = new HashSet(); |
|
|
96 |
fContainerEntries = new HashSet(); |
97 |
fTranslationProblems = new HashMap(); |
85 |
fTranslationProblems = new HashMap(); |
98 |
} |
86 |
} |
99 |
|
87 |
|
Lines 178-184
Link Here
|
178 |
* @param node |
166 |
* @param node |
179 |
*/ |
167 |
*/ |
180 |
private void addVariables(List results, CMNode node, ITextRegionCollection customTag) { |
168 |
private void addVariables(List results, CMNode node, ITextRegionCollection customTag) { |
181 |
|
|
|
182 |
List list = ((TLDElementDeclaration) node).getVariables(); |
169 |
List list = ((TLDElementDeclaration) node).getVariables(); |
183 |
Iterator it = list.iterator(); |
170 |
Iterator it = list.iterator(); |
184 |
while (it.hasNext()) { |
171 |
while (it.hasNext()) { |
Lines 240-246
Link Here
|
240 |
if (teiClassname == null || teiClassname.length() == 0 || fJavaProject == null) |
227 |
if (teiClassname == null || teiClassname.length() == 0 || fJavaProject == null) |
241 |
return; |
228 |
return; |
242 |
|
229 |
|
243 |
TaglibClassLoader loader = getClassloader(); |
230 |
ClassLoader loader = getClassloader(); |
244 |
|
231 |
|
245 |
Class teiClass = null; |
232 |
Class teiClass = null; |
246 |
try { |
233 |
try { |
Lines 611-817
Link Here
|
611 |
return tagDataTable; |
598 |
return tagDataTable; |
612 |
} |
599 |
} |
613 |
|
600 |
|
614 |
private TaglibClassLoader getClassloader() { |
601 |
private ClassLoader getClassloader() { |
615 |
if (fLoader == null) { |
602 |
if (fLoader == null) { |
616 |
fLoader = new TaglibClassLoader(this.getClass().getClassLoader()); |
603 |
fLoader = new BuildPathClassLoader(fJavaProject); |
617 |
fProjectEntries.clear(); |
|
|
618 |
fContainerEntries.clear(); |
619 |
addClasspathEntriesForProject(getProject(), fLoader); |
620 |
} |
604 |
} |
621 |
return fLoader; |
605 |
return fLoader; |
622 |
} |
606 |
} |
623 |
|
607 |
|
624 |
/** |
608 |
/** |
625 |
* @param loader |
|
|
626 |
*/ |
627 |
private void addClasspathEntriesForProject(IProject p, TaglibClassLoader loader) { |
628 |
|
629 |
// avoid infinite recursion and closed project |
630 |
if (!p.isAccessible() || fProjectEntries.contains(p.getFullPath().toString())) |
631 |
return; |
632 |
fProjectEntries.add(p.getFullPath().toString()); |
633 |
|
634 |
// add things on classpath that we are interested in |
635 |
try { |
636 |
if (p.hasNature(JavaCore.NATURE_ID)) { |
637 |
|
638 |
IJavaProject project = JavaCore.create(p); |
639 |
|
640 |
try { |
641 |
IClasspathEntry[] entries = project.getResolvedClasspath(true); |
642 |
addDefaultDirEntry(loader, project); |
643 |
addClasspathEntries(loader, project, entries); |
644 |
} |
645 |
catch (JavaModelException e) { |
646 |
Logger.logException(e); |
647 |
} |
648 |
} |
649 |
} |
650 |
catch (CoreException e) { |
651 |
Logger.logException(e); |
652 |
} |
653 |
} |
654 |
|
655 |
private void addClasspathEntries(TaglibClassLoader loader, IJavaProject project, IClasspathEntry[] entries) throws JavaModelException { |
656 |
IClasspathEntry entry; |
657 |
for (int i = 0; i < entries.length; i++) { |
658 |
|
659 |
entry = entries[i]; |
660 |
if (DEBUG) |
661 |
System.out.println("current entry is: " + entry); //$NON-NLS-1$ |
662 |
|
663 |
switch (entry.getEntryKind()) { |
664 |
case IClasspathEntry.CPE_SOURCE : |
665 |
addSourceEntry(loader, entry); |
666 |
break; |
667 |
case IClasspathEntry.CPE_LIBRARY : |
668 |
addLibraryEntry(loader, entry.getPath()); |
669 |
break; |
670 |
case IClasspathEntry.CPE_PROJECT : |
671 |
addProjectEntry(loader, entry); |
672 |
break; |
673 |
case IClasspathEntry.CPE_VARIABLE : |
674 |
addVariableEntry(loader, entry); |
675 |
break; |
676 |
case IClasspathEntry.CPE_CONTAINER : |
677 |
addContainerEntry(loader, project, entry); |
678 |
break; |
679 |
} |
680 |
} |
681 |
} |
682 |
|
683 |
/** |
684 |
* @param loader |
685 |
* @param entry |
686 |
*/ |
687 |
private void addVariableEntry(TaglibClassLoader loader, IClasspathEntry entry) { |
688 |
if (DEBUG) |
689 |
System.out.println(" -> adding variable entry: [" + entry + "]"); //$NON-NLS-1$ //$NON-NLS-2$ |
690 |
|
691 |
// variable should either be a project or a library entry |
692 |
|
693 |
// BUG 169431 |
694 |
String variableName = entry.getPath().toString(); |
695 |
IPath variablePath = JavaCore.getResolvedVariablePath(entry.getPath()); |
696 |
variablePath = JavaCore.getClasspathVariable(variableName); |
697 |
|
698 |
// RATLC01076854 |
699 |
// variable paths may not exist |
700 |
// in that case null will be returned |
701 |
if (variablePath != null) { |
702 |
if (variablePath.segments().length == 1) { |
703 |
IProject varProj = ResourcesPlugin.getWorkspace().getRoot().getProject(variablePath.toString()); |
704 |
if (varProj != null && varProj.exists()) { |
705 |
addClasspathEntriesForProject(varProj, loader); |
706 |
return; |
707 |
} |
708 |
} |
709 |
addLibraryEntry(loader, variablePath); |
710 |
} |
711 |
} |
712 |
|
713 |
/** |
714 |
* @param loader |
715 |
* @param project |
716 |
* @param entry |
717 |
* @throws JavaModelException |
718 |
*/ |
719 |
private void addContainerEntry(TaglibClassLoader loader, IJavaProject project, IClasspathEntry entry) throws JavaModelException { |
720 |
|
721 |
IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), project); |
722 |
if (container != null) { |
723 |
String uniqueProjectAndContainerPath = project.getProject().getFullPath().append(container.getPath()).toString(); |
724 |
/* |
725 |
* Avoid infinite recursion, but track containers for each project |
726 |
* separately as they may return different values. This may mean |
727 |
* indexing JREs multiple times, however. |
728 |
*/ |
729 |
if (!fContainerEntries.contains(uniqueProjectAndContainerPath)) { |
730 |
fContainerEntries.add(uniqueProjectAndContainerPath); |
731 |
|
732 |
IClasspathEntry[] cpes = container.getClasspathEntries(); |
733 |
// recursive call here |
734 |
addClasspathEntries(loader, project, cpes); |
735 |
} |
736 |
} |
737 |
} |
738 |
|
739 |
/** |
740 |
* @param loader |
741 |
* @param entry |
742 |
*/ |
743 |
private void addProjectEntry(TaglibClassLoader loader, IClasspathEntry entry) { |
744 |
if (DEBUG) |
745 |
System.out.println(" -> project entry: [" + entry + "]"); //$NON-NLS-1$ //$NON-NLS-2$ |
746 |
|
747 |
IPath path = entry.getPath(); |
748 |
IProject referenceProject = ResourcesPlugin.getWorkspace().getRoot().getProject(path.segment(0)); |
749 |
if (referenceProject != null && referenceProject.isAccessible()) { |
750 |
addClasspathEntriesForProject(referenceProject, loader); |
751 |
} |
752 |
} |
753 |
|
754 |
/** |
755 |
* @param loader |
756 |
* @param project |
757 |
* @param projectLocation |
758 |
* @throws JavaModelException |
759 |
*/ |
760 |
private void addDefaultDirEntry(TaglibClassLoader loader, IJavaProject project) throws JavaModelException { |
761 |
// add default bin directory for the project |
762 |
IPath outputPath = project.getOutputLocation(); |
763 |
loader.addFolder(outputPath); |
764 |
} |
765 |
|
766 |
/** |
767 |
* @param loader |
768 |
* @param entry |
769 |
*/ |
770 |
private void addLibraryEntry(TaglibClassLoader loader, IPath libPath) { |
771 |
String libPathString = libPath.toString(); |
772 |
File file = new File(libPathString); |
773 |
|
774 |
if (file.exists()) { |
775 |
if (file.isDirectory()) { |
776 |
loader.addDirectory(libPathString); |
777 |
} |
778 |
else { |
779 |
loader.addJar(libPathString); |
780 |
} |
781 |
} |
782 |
else { |
783 |
if (libPath.segmentCount() > 1) { |
784 |
IFile ifile = ResourcesPlugin.getWorkspace().getRoot().getFile(libPath); |
785 |
if (ifile != null && ifile.isAccessible()) { |
786 |
loader.addFile(libPath); |
787 |
} |
788 |
else { |
789 |
IFolder ifolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(libPath); |
790 |
if (ifolder != null && ifolder.isAccessible()) { |
791 |
loader.addFolder(libPath); |
792 |
} |
793 |
} |
794 |
} |
795 |
else { |
796 |
loader.addFolder(libPath); |
797 |
} |
798 |
} |
799 |
} |
800 |
|
801 |
/** |
802 |
* @param loader |
803 |
* @param entry |
804 |
*/ |
805 |
private void addSourceEntry(TaglibClassLoader loader, IClasspathEntry entry) { |
806 |
// add bin directory for specific entry if it has |
807 |
// one |
808 |
IPath outputLocation = entry.getOutputLocation(); |
809 |
if (outputLocation != null) { |
810 |
loader.addFolder(outputLocation); |
811 |
} |
812 |
} |
813 |
|
814 |
/** |
815 |
* @return Returns the fModelQuery. |
609 |
* @return Returns the fModelQuery. |
816 |
*/ |
610 |
*/ |
817 |
public ModelQuery getModelQuery(IDocument doc) { |
611 |
public ModelQuery getModelQuery(IDocument doc) { |
Lines 880-883
Link Here
|
880 |
} |
674 |
} |
881 |
} |
675 |
} |
882 |
} |
676 |
} |
|
|
677 |
|
678 |
/** |
679 |
* |
680 |
*/ |
681 |
public void dispose() { |
682 |
fLoader = null; |
683 |
fJavaProject = null; |
684 |
fProject = null; |
685 |
fTranslationProblems = null; |
686 |
} |
883 |
} |
687 |
} |