@@ -101,37 +101,45 @@ protected Stream<String> filesInDirectory( final String directory ) {
101
101
final String path = jarIndex > 0 ? url .substring ( 0 , jarIndex +4 ).replace ( "jar:file:" , "" ) : url ;
102
102
final File jarFile = new File (path );
103
103
if (jarFile .isFile ()) {
104
- final List <String > fileList = new ArrayList <>();
105
- final JarFile jar = new JarFile (jarFile );
106
- final Enumeration <JarEntry > entries = jar .entries ();
107
- final String dir = directory .endsWith ( "/" ) ? directory : directory + "/" ;
108
- while (entries .hasMoreElements ()) {
109
- final String name = entries .nextElement ().getName ();
110
- if (name .contains ( dir ))
111
- {
112
- final String fileName = name .replace ( dir , "" );
113
- if (StringUtils .isNotBlank ( fileName ))
114
- {
115
- fileList .add ( fileName );
116
- }
117
- }
118
- }
119
- jar .close ();
120
- return fileList .stream ();
104
+ return getFilesFromJar ( directory , jarFile );
121
105
} else {
122
- final InputStream directoryUrl = getClass ().getClassLoader ().getResourceAsStream ( directory );
123
- if ( directoryUrl == null ) {
124
- LOG .warn ( "No such classpath directory {}" , directory );
125
- return Stream .empty ();
126
- }
127
- return Arrays .stream ( IOUtils .toString ( directoryUrl , StandardCharsets .UTF_8 ).split ( "\\ n" ) );
106
+ return getFilesFromResources ( directory );
128
107
}
129
108
} catch ( final IOException exception ) {
130
109
LOG .warn ( "Could not list files in classpath directory {}" , directory , exception );
131
110
return Stream .empty ();
132
111
}
133
112
}
134
113
114
+ private Stream <String > getFilesFromResources ( String directory ) throws IOException {
115
+ final InputStream directoryUrl = getClass ().getClassLoader ().getResourceAsStream ( directory );
116
+ if ( directoryUrl == null ) {
117
+ LOG .warn ( "No such classpath directory {}" , directory );
118
+ return Stream .empty ();
119
+ }
120
+ return Arrays .stream ( IOUtils .toString ( directoryUrl , StandardCharsets .UTF_8 ).split ( "\\ n" ) );
121
+ }
122
+
123
+ private Stream <String > getFilesFromJar ( String directory , File jarFile ) throws IOException {
124
+ final List <String > fileList = new ArrayList <>();
125
+ final JarFile jar = new JarFile ( jarFile );
126
+ final Enumeration <JarEntry > entries = jar .entries ();
127
+ final String dir = directory .endsWith ( "/" ) ? directory : directory + "/" ;
128
+ while (entries .hasMoreElements ()) {
129
+ final String name = entries .nextElement ().getName ();
130
+ if (name .contains ( dir ))
131
+ {
132
+ final String fileName = name .replace ( dir , "" );
133
+ if (StringUtils .isNotBlank ( fileName ))
134
+ {
135
+ fileList .add ( fileName );
136
+ }
137
+ }
138
+ }
139
+ jar .close ();
140
+ return fileList .stream ();
141
+ }
142
+
135
143
@ Override
136
144
public Try <Model > apply ( final AspectModelUrn aspectModelUrn ) {
137
145
final String modelsRootTrailingSlash = modelsRoot .isEmpty () ? "" : "/" ;
0 commit comments