Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dependency scan and do not modify inputSpec provided by user
Browse files Browse the repository at this point in the history
It is still possible to provide JARs as inputSpec, however the user has to provide it by hand.

Providing dependencies in plugin section still allows correct inputSpec resolution on classpath.
parenko committed Jul 8, 2024
1 parent 6e2bde1 commit 1d517fd
Showing 1 changed file with 7 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@
* Goal which generates client/server code from a OpenAPI json/yaml definition.
*/
@SuppressWarnings({"unused", "MismatchedQueryAndUpdateOfCollection"})
@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES, requiresDependencyResolution = ResolutionScope.COMPILE, threadSafe = true)
@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true)
public class CodeGenMojo extends AbstractMojo {

private final Logger LOGGER = LoggerFactory.getLogger(CodeGenMojo.class);
@@ -623,13 +623,7 @@ public void execute() throws MojoExecutionException {
}

if (isNotEmpty(inputSpec)) {
URL url = inputSpecRemoteUrl();

if ((! inputSpecFile.exists()) && url != null) {
configurator.setInputSpec(url.toString());
} else {
configurator.setInputSpec(inputSpec);
}
configurator.setInputSpec(inputSpec);
}

if (isNotEmpty(gitHost)) {
@@ -1015,35 +1009,15 @@ private String calculateInputSpecHash(String inputSpec) {
}

/**
* Try to parse inputSpec setting string into URL (truly remote or resource)
* Try to parse inputSpec setting string into URL
* @return A valid URL or null if inputSpec is not a valid URL
*/
private URL inputSpecRemoteUrl() {
URL url = dependencyClassLoader().getResource(inputSpec);

if (url == null) {
try {
url = new URI(FilenameUtils.separatorsToUnix(inputSpec)).toURL();
} catch (URISyntaxException | MalformedURLException | IllegalArgumentException e) {
}
}

return url;
}

private ClassLoader dependencyClassLoader() {
List<URL> list = new ArrayList<>();

for (Artifact artifact : project.getArtifacts()) {
try {
if (artifact.isResolved() && artifact.getType().equals("jar")) {
list.add(new URL("jar:" + artifact.getFile().toURI() + "!/"));
}
} catch (Exception e) {
}
try {
return new URI(FilenameUtils.separatorsToUnix(inputSpec)).toURL();
} catch (URISyntaxException | MalformedURLException | IllegalArgumentException ignored) {
return null;
}

return new URLClassLoader(list.toArray(new URL[] { }), getClass().getClassLoader());
}

/**

0 comments on commit 1d517fd

Please sign in to comment.