32
32
33
33
import java .io .File ;
34
34
import java .io .IOException ;
35
- import java .net .URI ;
36
- import java .net .URISyntaxException ;
37
- import java .net .URL ;
35
+ import java .io .InputStream ;
36
+
38
37
import java .nio .file .Files ;
39
38
import java .nio .file .Path ;
39
+ import java .nio .file .StandardCopyOption ;
40
40
import java .util .Arrays ;
41
41
import java .util .Collections ;
42
42
import java .util .HashSet ;
@@ -74,19 +74,18 @@ public static boolean validate(String ctagsBinary) {
74
74
private static boolean canProcessFiles (String basePath ) {
75
75
Path inputPath = Path .of (basePath , "ctagsValidationTemporaryFile.c" );
76
76
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 ;
85
83
}
86
- Files .copy (resourcePath , inputPath );
84
+
85
+ Files .copy (inputStream , inputPath , StandardCopyOption .REPLACE_EXISTING );
87
86
} catch (IOException e ) {
88
87
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 });
90
89
return false ;
91
90
}
92
91
@@ -110,27 +109,6 @@ private static boolean canProcessFiles(String basePath) {
110
109
return false ;
111
110
}
112
111
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
-
134
112
@ Nullable
135
113
public static String getCtagsVersion (String ctagsBinary ) {
136
114
Executor executor = new Executor (new String []{ctagsBinary , "--version" });
0 commit comments