Skip to content

Commit

Permalink
Ensure that QuarkusClassLoader returns the same URL format as URLClas…
Browse files Browse the repository at this point in the history
…sLoader

The URLClassLoader adds a trailing slash when resolving a directory so we
should do the same to prevent the QuarkusClassLoader from returning
multiple entries for the same directory.

This should properly fix the Flyway issue
  • Loading branch information
geoand committed Jun 25, 2020
1 parent e712f74 commit 4e58a7d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
Expand Down Expand Up @@ -102,7 +103,7 @@ void build(BuildProducer<FeatureBuildItem> featureProducer,

Collection<String> dataSourceNames = getDataSourceNames(jdbcDataSourceBuildItems);

Set<String> applicationMigrations = discoverApplicationMigrations(getMigrationLocations(dataSourceNames));
List<String> applicationMigrations = discoverApplicationMigrations(getMigrationLocations(dataSourceNames));
recorder.setApplicationMigrationFiles(applicationMigrations);

Set<Class<?>> javaMigrationClasses = new HashSet<>();
Expand Down Expand Up @@ -195,9 +196,9 @@ private Collection<String> getMigrationLocations(Collection<String> dataSourceNa
return migrationLocations;
}

private Set<String> discoverApplicationMigrations(Collection<String> locations) throws IOException, URISyntaxException {
private List<String> discoverApplicationMigrations(Collection<String> locations) throws IOException, URISyntaxException {
try {
Set<String> applicationMigrationResources = new HashSet<>();
List<String> applicationMigrationResources = new ArrayList<>();
// Locations can be a comma separated list
for (String location : locations) {
// Strip any 'classpath:' protocol prefixes because they are assumed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,15 @@ public String getPath() {
@Override
public URL getUrl() {
try {
return file.toUri().toURL();
URI uri = file.toUri();
// the URLClassLoader doesn't add trailing slashes to directories, so we make sure we return
// the same URL as it would to avoid having QuarkusClassLoader return different URLs
// (one with a trailing slash and one without) for same resource
if (uri.getPath().endsWith("/")) {
String uriStr = uri.toString();
return new URL(uriStr.substring(0, uriStr.length() - 1));
}
return uri.toURL();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit 4e58a7d

Please sign in to comment.