25
25
import java .util .Set ;
26
26
import java .util .concurrent .ConcurrentHashMap ;
27
27
28
+ import org .eclipse .jetty .io .IOResources ;
28
29
import org .eclipse .jetty .util .ExceptionUtil ;
29
30
import org .eclipse .jetty .util .FileID ;
30
31
import org .eclipse .jetty .util .StringUtil ;
@@ -606,7 +607,7 @@ protected void parseDir(Set<? extends Handler> handlers, Resource dirResource) t
606
607
607
608
try
608
609
{
609
- parseClass (handlers , dirResource , candidate . getPath () );
610
+ parseClass (handlers , dirResource , candidate );
610
611
}
611
612
catch (Exception ex )
612
613
{
@@ -629,9 +630,6 @@ protected void parseJar(Set<? extends Handler> handlers, Resource jarResource) t
629
630
if (jarResource == null )
630
631
return ;
631
632
632
- /* if (!FileID.isJavaArchive(jarResource.getPath()))
633
- return;*/
634
-
635
633
if (LOG .isDebugEnabled ())
636
634
LOG .debug ("Scanning jar {}" , jarResource );
637
635
@@ -649,27 +647,60 @@ protected void parseJar(Set<? extends Handler> handlers, Resource jarResource) t
649
647
* @param containingResource the dir or jar that the class is contained within, can be null if not known
650
648
* @param classFile the class file to parse
651
649
* @throws IOException if unable to parse
650
+ * @deprecated use {@link #parseClass(Set, Resource, Resource)} instead (which uses {@link Resource} instead of {@link Path})
652
651
*/
652
+ @ Deprecated (since = "12.0.21" , forRemoval = true )
653
653
protected void parseClass (Set <? extends Handler > handlers , Resource containingResource , Path classFile ) throws IOException
654
654
{
655
- if (LOG .isDebugEnabled ())
656
- LOG .debug ("Parse class from {}" , classFile .toUri ());
655
+ try (InputStream inputStream = Files .newInputStream (classFile ))
656
+ {
657
+ parseClass (handlers , containingResource , classFile .toUri (), inputStream );
658
+ }
659
+ }
660
+
661
+ /**
662
+ * Use ASM on a class
663
+ *
664
+ * @param handlers the handlers to look for classes in
665
+ * @param containingResource the dir or jar that the class is contained within, can be null if not known
666
+ * @param classFile the class file to parse
667
+ * @throws IOException if unable to parse
668
+ */
669
+ protected void parseClass (Set <? extends Handler > handlers , Resource containingResource , Resource classFile ) throws IOException
670
+ {
671
+ try (InputStream inputStream = IOResources .asInputStream (classFile ))
672
+ {
673
+ parseClass (handlers , containingResource , classFile .getURI (), inputStream );
674
+ }
675
+ }
657
676
658
- URI location = classFile .toUri ();
677
+ /**
678
+ * Use ASM on a class
679
+ *
680
+ * @param handlers the handlers to look for classes in
681
+ * @param containingResource the dir or jar that the class is contained within, can be null if not known
682
+ * @param classFileRef the URI reference to the classfile location
683
+ * @param inputStream the class file contents to parse
684
+ * @throws IOException if unable to parse
685
+ */
686
+ private void parseClass (Set <? extends Handler > handlers , Resource containingResource , URI classFileRef , InputStream inputStream ) throws IOException
687
+ {
688
+ if (LOG .isDebugEnabled ())
689
+ LOG .debug ("Parse class from {}" , classFileRef );
659
690
660
- try ( InputStream in = Files . newInputStream ( classFile ))
691
+ try
661
692
{
662
- ClassReader reader = new ClassReader (in );
693
+ ClassReader reader = new ClassReader (inputStream );
663
694
reader .accept (new MyClassVisitor (handlers , containingResource , _asmVersion ), ClassReader .SKIP_CODE | ClassReader .SKIP_DEBUG | ClassReader .SKIP_FRAMES );
664
695
665
696
String classname = normalize (reader .getClassName ());
666
- URI existing = _parsedClassNames .putIfAbsent (classname , location );
697
+ URI existing = _parsedClassNames .putIfAbsent (classname , classFileRef );
667
698
if (existing != null )
668
- LOG .warn ("{} scanned from multiple locations: {}, {}" , classname , existing , location );
699
+ LOG .warn ("{} scanned from multiple locations: {}, {}" , classname , existing , classFileRef );
669
700
}
670
701
catch (IllegalArgumentException | IOException e )
671
702
{
672
- throw new IOException ("Unable to parse class: " + classFile . toUri () , e );
703
+ throw new IOException ("Unable to parse class: " + classFileRef , e );
673
704
}
674
705
}
675
706
0 commit comments