Skip to content

Commit

Permalink
Merge pull request #3877 from patrickpichler/bugfix/3876/fix-unreliab…
Browse files Browse the repository at this point in the history
…le-url-ordering

Fix unstable ordering of urls in gradle resolve task
  • Loading branch information
frantuma authored Feb 11, 2021
2 parents 881ceb3 + 819c989 commit 3ed9823
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.swagger.v3.plugins.gradle.tasks;

import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
Expand Down Expand Up @@ -315,30 +316,30 @@ public void resolve() throws GradleException {
}
LOGGER.info( "Resolving OpenAPI specification.." );

Set<URL> urls = StreamSupport.stream(getClasspath().spliterator(), false).map(f -> {
Stream<URL> classpathStream = StreamSupport.stream(getClasspath().spliterator(), false).map(f -> {
try {
return f.toURI().toURL();
}
catch (MalformedURLException e) {
} catch (MalformedURLException e) {
throw new GradleException(
String.format("Could not create classpath for annotations task %s.", getName()), e);
String.format("Could not create classpath for annotations task %s.", getName()), e);
}
}).collect(Collectors.toSet());
});

Set<URL> buildUrls = StreamSupport.stream(getBuildClasspath().spliterator(), false).map(f -> {
Stream<URL> buildClasspathStream = StreamSupport.stream(getBuildClasspath().spliterator(), false).map(f -> {
try {
return f.toURI().toURL();
}
catch (MalformedURLException e) {
} catch (MalformedURLException e) {
throw new GradleException(
String.format("Could not create classpath for annotations task %s.", getName()), e);
String.format("Could not create classpath for annotations task %s.", getName()), e);
}
}).collect(Collectors.toSet());
});

urls.addAll(buildUrls);
URL[] urls = Stream.concat(classpathStream, buildClasspathStream)
.distinct()
.toArray(URL[]::new);

//ClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), Thread.currentThread().getContextClassLoader());
ClassLoader classLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]));
ClassLoader classLoader = new URLClassLoader(urls);

try {
Class swaggerLoaderClass = classLoader.loadClass("io.swagger.v3.jaxrs2.integration.SwaggerLoader");
Expand Down

0 comments on commit 3ed9823

Please sign in to comment.