-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Description
Udayakumar opened SPR-16117 and commented
I am working on a drools project. The goal is to search all the rules(*.rdrl) files in the classpath and write it into the KieFileSystem. The rules file(.rdrl) will be present under multiple jar files. These jar files were added as a dependency in the drools project.
Below is the code that is used to find all the .rdrl files.
ClassLoader classloader = this.getClass().getClassLoader();
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(classloader);
for (Resource file : resourcePatternResolver.getResources("classpath*:/**/*.rdrl")) {
System.out.println("name: " + file.getURL());
kieFileSystem.write(ResourceFactory.newUrlResource(file.getURL()));
}
Below is the sample output printed by the above code
name: jar:file:/C:/mvn_repo/com/myteam/OOP_Modular/1.0.0/OOP_Modular-1.0.0.jar!/com/myteam/oop_modular/OOP_MOD_Network_In_Network.rdrl
name: jar:file:/C:/mvn_repo/com/myteam/OOP_Modular/1.0.0/OOP_Modular-1.0.0.jar!/com/myteam/oop_modular/OOP_MOD_Individual1.rdrl
name: jar:file:c:\mvn_repo\com\myteam\OOP_Modular\1.0.0\OOP_Modular-1.0.0.jar!/com/myteam/oop_modular/OOP_MOD_Network_In_Network.rdrl
name: jar:file:c:\mvn_repo\com\myteam\OOP_Modular\1.0.0\OOP_Modular-1.0.0.jar!/com/myteam/oop_modular/OOP_MOD_Individual1.rdrl
As seen from the above output there are two entries for the same files OOP_MOD_Network_In_Network.rdrl and OOP_MOD_Individual1.rdrl. When you look at the output, the path is exactly same except that one starts with /C: and other with c:
Because of this issue, since i am trying to write each rule twice into kiefilesystem, it throws an exception saying "Duplicate rule name".
Note: When using pattern such as ("classpath*:com/**/*.rdrl"), the resources are returned only once but we are not sure if the rules file will be present only under 'com', it can also be under 'org' or anything else.
System: Windows 7, JDK 1.8
Affects: 4.3.12, 5.0.1
Issue Links:
PathMatchingResourcePatternResolver
provides duplicate resources when usingclasspath*:
prefix combined with ant-style [SPR-15989] #20539 PathMatchingResourcePatternResolver provides duplicate resources when using classpath* prefix combined with ant-style- PathMatchingResourcePatternResolver does not consider manifest based classpaths [SPR-13685] #18260 PathMatchingResourcePatternResolver does not consider manifest based classpaths
Referenced from: commits 8904de2, a2f5e12
Backported to: 4.3.13