Source:
public List<DBVersion> getChangelogVersions(String currentDBVersion, String fileName) throws InternalErrorException { Pattern versionPattern = Pattern.compile("^[1-9][0-9]*[.][0-9]+[.][0-9]+"); Pattern commentPattern = Pattern.compile("^--.*"); List<DBVersion> versions = new ArrayList<>(); boolean versionFound = false; try(BufferedReader br = new BufferedReader(new InputStreamReader(ClassLoader.getSystemResourceAsStream(fileName)))) { String line = br.readLine(); while (line != null){ line = line.trim(); if(line.isEmpty() || commentPattern.matcher(line).matches()) { line = br.readLine(); continue; } if(versionPattern.matcher(line).matches()){ DBVersion version = new DBVersion(line); if(!versions.isEmpty()) { DBVersion previousVersion = versions.get(versions.size() - 1); if(version.compareTo(previousVersion) >= 0) { throw new InternalErrorException("Version numbers in changelog file are not increasing properly. " + "Version " + previousVersion.getVersion() + " should be higher than " + version.getVersion()); } } if(line.equals(currentDBVersion)){ versionFound = true; break; } List<String> commands = new ArrayList<>(); while((line = br.readLine()) != null) { line = line.trim(); if(line.isEmpty()) { break; } commands.add(line); } version.setCommands(commands); versions.add(version); } else { throw new InternalErrorException("Version does not match the pattern required in " + fileName); } } if(!versionFound) { throw new InternalErrorException("Version " + currentDBVersion + " not found in " + fileName); } } catch(IOException e) { throw new InternalErrorException("Error reading " + fileName, e); } return versions; }

Target:
public List<DBVersion> getChangelogVersions(String currentDBVersion, String fileName) throws InternalErrorException { Pattern versionPattern = Pattern.compile("^[1-9][0-9]*[.][0-9]+[.][0-9]+"); Pattern commentPattern = Pattern.compile("^--.*"); List<DBVersion> versions = new ArrayList<>(); boolean versionFound = false; Resource resource = new ClassPathResource(fileName); try(BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream()))) { String line = br.readLine(); while (line != null){ line = line.trim(); if(line.isEmpty() || commentPattern.matcher(line).matches()) { line = br.readLine(); continue; } if(versionPattern.matcher(line).matches()){ DBVersion version = new DBVersion(line); if(!versions.isEmpty()) { DBVersion previousVersion = versions.get(versions.size() - 1); if(version.compareTo(previousVersion) >= 0) { throw new InternalErrorException("Version numbers in changelog file are not increasing properly. " + "Version " + previousVersion.getVersion() + " should be higher than " + version.getVersion()); } } if(line.equals(currentDBVersion)){ versionFound = true; break; } List<String> commands = new ArrayList<>(); while((line = br.readLine()) != null) { line = line.trim(); if(line.isEmpty()) { break; } commands.add(line); } version.setCommands(commands); versions.add(version); } else { throw new InternalErrorException("Version does not match the pattern required in " + fileName); } } if(!versionFound) { throw new InternalErrorException("Version " + currentDBVersion + " not found in " + fileName); } } catch(IOException e) { throw new InternalErrorException("Error reading " + fileName, e); } return versions; }