3232
3333import java .io .File ;
3434import java .io .IOException ;
35- import java .net .URI ;
36- import java .net .URISyntaxException ;
37- import java .net .URL ;
35+ import java .io .InputStream ;
36+
3837import java .nio .file .Files ;
3938import java .nio .file .Path ;
39+ import java .nio .file .StandardCopyOption ;
4040import java .util .Arrays ;
4141import java .util .Collections ;
4242import java .util .HashSet ;
@@ -74,19 +74,18 @@ public static boolean validate(String ctagsBinary) {
7474 private static boolean canProcessFiles (String basePath ) {
7575 Path inputPath = Path .of (basePath , "ctagsValidationTemporaryFile.c" );
7676 final String resourceFileName = "sample.c" ;
77- Path resourcePath = getResourceFile (resourceFileName );
78- if (resourcePath == null ) {
79- return false ;
80- }
81-
82- try {
83- if (inputPath .toFile ().exists ()) {
84- Files .delete (inputPath );
77+ ClassLoader classLoader = CtagsUtil .class .getClassLoader ();
78+ try (InputStream inputStream = classLoader .getResourceAsStream (resourceFileName )) {
79+ if (inputStream == null ) {
80+ LOGGER .log (Level .SEVERE , "cannot get resource URL of ''{0}'' for ctags check" ,
81+ resourceFileName );
82+ return false ;
8583 }
86- Files .copy (resourcePath , inputPath );
84+
85+ Files .copy (inputStream , inputPath , StandardCopyOption .REPLACE_EXISTING );
8786 } catch (IOException e ) {
8887 LOGGER .log (Level .SEVERE , "cannot copy ''{0}'' to ''{1}'' for ctags check: {2}" ,
89- new Object []{resourcePath , inputPath , e });
88+ new Object []{resourceFileName , inputPath , e });
9089 return false ;
9190 }
9291
@@ -110,27 +109,6 @@ private static boolean canProcessFiles(String basePath) {
110109 return false ;
111110 }
112111
113- @ Nullable
114- private static Path getResourceFile (String resourceFileName ) {
115- ClassLoader classLoader = CtagsUtil .class .getClassLoader ();
116- URI resourceURI ;
117- try {
118- URL resourceURL = classLoader .getResource (resourceFileName );
119- if (resourceURL == null ) {
120- LOGGER .log (Level .SEVERE , "cannot get resource URL of ''{0}'' for ctags check" ,
121- resourceFileName );
122- return null ;
123- }
124- resourceURI = resourceURL .toURI ();
125- } catch (URISyntaxException e ) {
126- LOGGER .log (Level .SEVERE , "cannot perform ctags check due to missing resource file ''{0}''" ,
127- resourceFileName );
128- return null ;
129- }
130-
131- return Path .of (resourceURI );
132- }
133-
134112 @ Nullable
135113 public static String getCtagsVersion (String ctagsBinary ) {
136114 Executor executor = new Executor (new String []{ctagsBinary , "--version" });
0 commit comments