@@ -183,25 +183,30 @@ public static Set<String> getErrorKeys() {
183183 return new HashSet <>(errorKeys );
184184 }
185185
186+ private static final String APPLICATION = "application" ;
187+ private static final int APPLICATION_LENGTH = APPLICATION .length ();
188+
186189 private static final DirectoryStream .Filter <Path > CONFIG_FILES_FILTER = new DirectoryStream .Filter <>() {
187190 @ Override
188191 public boolean accept (final Path entry ) {
189- // Ignore .properties, because we know these are have a default loader in core
190- // Ignore profile files. The loading rules require the main file to be present, so we only need the type
191192 String filename = entry .getFileName ().toString ();
192- return Files .isRegularFile (entry ) && filename .startsWith ("application." ) && !filename .endsWith (".properties" );
193+ // Include application files with any extension and profiled files
194+ return Files .isRegularFile (entry )
195+ && filename .length () > APPLICATION_LENGTH
196+ && filename .startsWith (APPLICATION )
197+ && (filename .charAt (APPLICATION_LENGTH ) == '.' || filename .charAt (APPLICATION_LENGTH ) == '-' );
193198 }
194199 };
195200
196- public static Set <String > configFiles (Path configFilesLocation ) throws IOException {
201+ public static Set <Path > configFiles (Path configFilesLocation ) throws IOException {
197202 if (!Files .exists (configFilesLocation )) {
198203 return Collections .emptySet ();
199204 }
200205
201- Set <String > configFiles = new HashSet <>();
206+ Set <Path > configFiles = new HashSet <>();
202207 try (DirectoryStream <Path > candidates = Files .newDirectoryStream (configFilesLocation , CONFIG_FILES_FILTER )) {
203208 for (Path candidate : candidates ) {
204- configFiles .add (candidate . toUri (). toURL (). toString () );
209+ configFiles .add (candidate );
205210 }
206211 } catch (NotDirectoryException ignored ) {
207212 log .debugf ("File %s is not a directory" , configFilesLocation .toAbsolutePath ());
@@ -210,10 +215,10 @@ public static Set<String> configFiles(Path configFilesLocation) throws IOExcepti
210215 return configFiles ;
211216 }
212217
213- public static Set <String > configFilesFromLocations () throws Exception {
218+ public static Set <Path > configFilesFromLocations () throws Exception {
214219 SmallRyeConfig config = ConfigProvider .getConfig ().unwrap (SmallRyeConfig .class );
215220
216- Set <String > configFiles = new HashSet <>();
221+ Set <Path > configFiles = new HashSet <>();
217222 configFiles .addAll (configFiles (Paths .get (System .getProperty ("user.dir" ), "config" )));
218223 Optional <List <URI >> optionalLocations = config .getOptionalValues (SMALLRYE_CONFIG_LOCATIONS , URI .class );
219224 optionalLocations .ifPresent (new Consumer <List <URI >>() {
@@ -236,27 +241,41 @@ public void accept(final List<URI> locations) {
236241 return configFiles ;
237242 }
238243
239- public static void unknownConfigFiles (final Set <String > configFiles ) {
244+ public static void unknownConfigFiles (final Set <Path > configFiles ) throws Exception {
240245 SmallRyeConfig config = ConfigProvider .getConfig ().unwrap (SmallRyeConfig .class );
241246 Set <String > configNames = new HashSet <>();
242247 for (ConfigSource configSource : config .getConfigSources ()) {
243- if (configSource .getName () != null && configSource .getName ().contains ("application" )) {
248+ if (configSource .getName () != null && configSource .getName ().contains (APPLICATION )) {
244249 configNames .add (configSource .getName ());
245250 }
246251 }
247252
248- for (String configFile : configFiles ) {
253+ // Config sources names include the full path of the file, so we can check for unknowns if the file was not loaded by a source
254+ for (Path configFile : configFiles ) {
249255 boolean found = false ;
250256 for (String configName : configNames ) {
251- if (configName .contains (configFile )) {
257+ if (configName .contains (configFile . toUri (). toURL (). toString () )) {
252258 found = true ;
253259 break ;
254260 }
255261 }
256262 if (!found ) {
257- log .warnf (
258- "Unrecognized configuration file %s found; Please, check if your are providing the proper extension to load the file" ,
259- configFile );
263+ String filename = configFile .getFileName ().toString ();
264+ // is a Profile aware file
265+ if (filename .charAt (APPLICATION_LENGTH ) == '-' && filename .lastIndexOf ('.' ) != -1 ) {
266+ String unprofiledConfigFile = APPLICATION + "." + filename .substring (filename .lastIndexOf ('.' ) + 1 );
267+ String profile = filename .substring (APPLICATION_LENGTH + 1 , filename .lastIndexOf ('.' ));
268+ if (config .getProfiles ().contains (profile )
269+ && !Files .exists (Path .of (configFile .getParent ().toString (), unprofiledConfigFile ))) {
270+ log .warnf (
271+ "Profiled configuration file %s is ignored; a main %s configuration file must exist in the same location to load %s" ,
272+ configFile , unprofiledConfigFile , filename );
273+ }
274+ } else {
275+ log .warnf (
276+ "Unrecognized configuration file %s found; Please, check if your are providing the proper extension to load the file" ,
277+ configFile );
278+ }
260279 }
261280 }
262281 }
0 commit comments