diff --git a/modules/openapi-generator-maven-plugin/pom.xml b/modules/openapi-generator-maven-plugin/pom.xml
index 29d1eb27ccd61..8aaa298e5f73e 100644
--- a/modules/openapi-generator-maven-plugin/pom.xml
+++ b/modules/openapi-generator-maven-plugin/pom.xml
@@ -64,6 +64,12 @@
${junit.version}
test
+
+ org.apache.maven
+ maven-resolver-provider
+ 3.6.3
+ test
+
org.apache.maven.shared
maven-verifier
diff --git a/modules/openapi-generator-maven-plugin/src/test/java/org/openapitools/codegen/plugin/CodeGenMojoTest.java b/modules/openapi-generator-maven-plugin/src/test/java/org/openapitools/codegen/plugin/CodeGenMojoTest.java
index 4881db21921bd..363cc9dc4d94f 100644
--- a/modules/openapi-generator-maven-plugin/src/test/java/org/openapitools/codegen/plugin/CodeGenMojoTest.java
+++ b/modules/openapi-generator-maven-plugin/src/test/java/org/openapitools/codegen/plugin/CodeGenMojoTest.java
@@ -37,7 +37,11 @@
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
+import org.eclipse.aether.impl.DefaultServiceLocator;
+import org.eclipse.aether.repository.LocalRepository;
+import org.eclipse.aether.RepositorySystem;
public class CodeGenMojoTest extends BaseTestCase {
@Override
@@ -45,10 +49,22 @@ protected void setUp() throws Exception {
super.setUp();
}
+ public void testCommonConfigurationWithFileInputSpec() throws Exception {
+ testCommonConfiguration("file");
+ }
+
+ public void testCommonConfigurationWithResourceInputSpec() throws Exception {
+ testCommonConfiguration("resource");
+ }
+
+ public void testCommonConfigurationWithURLInputSpec() throws Exception {
+ testCommonConfiguration("url");
+ }
+
@SuppressWarnings("unchecked")
- public void testCommonConfiguration() throws Exception {
+ private void testCommonConfiguration(String profile) throws Exception {
File folder = Files.createTempDirectory("test").toFile();
- CodeGenMojo mojo = loadMojo(folder, "src/test/resources/default");
+ CodeGenMojo mojo = loadMojo(folder, "src/test/resources/default", profile);
mojo.execute();
assertEquals("java", getVariableValueFromObject(mojo, "generatorName"));
assertEquals("jersey2", getVariableValueFromObject(mojo, "library"));
@@ -65,7 +81,7 @@ public void testCommonConfiguration() throws Exception {
public void testHashGenerationFileContainsExecutionId() throws Exception {
// GIVEN
Path folder = Files.createTempDirectory("test");
- CodeGenMojo mojo = loadMojo(folder.toFile(), "src/test/resources/default", "executionId");
+ CodeGenMojo mojo = loadMojo(folder.toFile(), "src/test/resources/default", "file", "executionId");
// WHEN
mojo.execute();
@@ -86,7 +102,7 @@ public void testSkipRegenerationForClasspathSpecFileNoChange() throws Exception
//GIVEN
/* Setup the mojo */
final Path folder = Files.createTempDirectory("test-classpath");
- final CodeGenMojo mojo = loadMojo(folder.toFile(), "src/test/resources/classpath", "executionId");
+ final CodeGenMojo mojo = loadMojo(folder.toFile(), "src/test/resources/classpath", "file", "executionId");
/* Perform an initial generation */
mojo.execute();
@@ -124,7 +140,7 @@ public void testSkipRegenerationForClasspathSpecFileWithChange() throws Exceptio
//GIVEN
/* Setup the mojo */
final Path folder = Files.createTempDirectory("test-classpath");
- final CodeGenMojo mojo = loadMojo(folder.toFile(), "src/test/resources/classpath", "executionId");
+ final CodeGenMojo mojo = loadMojo(folder.toFile(), "src/test/resources/classpath", "file", "executionId");
/* Perform an initial generation */
mojo.execute();
@@ -159,7 +175,7 @@ public void testSkipRegenerationForClasspathSpecFileWithChange() throws Exceptio
public void testCollapsedSpecProduced() throws Exception {
// GIVEN
Path folder = Files.createTempDirectory("test");
- CodeGenMojo mojo = loadMojo(folder.toFile(), "src/test/resources/default", "executionId");
+ CodeGenMojo mojo = loadMojo(folder.toFile(), "src/test/resources/default", "file", "executionId");
// WHEN
mojo.execute();
@@ -172,7 +188,7 @@ public void testCollapsedSpecProduced() throws Exception {
public void testCollapsedSpecAddedToArtifacts() throws Exception {
// GIVEN
Path folder = Files.createTempDirectory("test");
- CodeGenMojo mojo = loadMojo(folder.toFile(), "src/test/resources/default", "executionId");
+ CodeGenMojo mojo = loadMojo(folder.toFile(), "src/test/resources/default", "file", "executionId");
// WHEN
mojo.execute();
@@ -187,7 +203,7 @@ public void testCollapsedSpecAddedToArtifacts() throws Exception {
public void testAnyInputSpecMustBeProvided() throws Exception {
// GIVEN
Path folder = Files.createTempDirectory("test");
- CodeGenMojo mojo = loadMojo(folder.toFile(), "src/test/resources/default", "executionId");
+ CodeGenMojo mojo = loadMojo(folder.toFile(), "src/test/resources/default", "file", "executionId");
mojo.inputSpec = null;
mojo.inputSpecRootDirectory = null;
@@ -201,7 +217,7 @@ public void testAnyInputSpecMustBeProvided() throws Exception {
public void testInputSpecRootDirectoryDoesNotRequireInputSpec() throws Exception {
// GIVEN
Path folder = Files.createTempDirectory("test");
- CodeGenMojo mojo = loadMojo(folder.toFile(), "src/test/resources/default", "executionId");
+ CodeGenMojo mojo = loadMojo(folder.toFile(), "src/test/resources/default", "file", "executionId");
mojo.inputSpec = null;
mojo.inputSpecRootDirectory = "src/test/resources/default";
@@ -214,14 +230,14 @@ public void testInputSpecRootDirectoryDoesNotRequireInputSpec() throws Exception
assertTrue(hashFolder.resolve("_merged_spec.yaml-executionId.sha256").toFile().exists());
}
- protected CodeGenMojo loadMojo(File temporaryFolder, String projectRoot) throws Exception {
- return loadMojo(temporaryFolder, projectRoot, "default");
+ protected CodeGenMojo loadMojo(File temporaryFolder, String projectRoot, String profile) throws Exception {
+ return loadMojo(temporaryFolder, projectRoot, profile, "default");
}
- protected CodeGenMojo loadMojo(File temporaryFolder, String projectRoot, String executionId) throws Exception {
+ protected CodeGenMojo loadMojo(File temporaryFolder, String projectRoot, String profile, String executionId) throws Exception {
File file = new File(projectRoot);
FileUtils.copyDirectory(file, temporaryFolder);
- MavenProject project = readMavenProject(temporaryFolder);
+ MavenProject project = readMavenProject(temporaryFolder, profile);
MavenSession session = newMavenSession(project);
MojoExecution execution = newMojoExecution("generate");
MojoExecution executionWithId = copyWithExecutionId(executionId, execution);
@@ -234,15 +250,24 @@ private MojoExecution copyWithExecutionId(String executionId, MojoExecution exec
return executionWithId;
}
- protected MavenProject readMavenProject(File basedir)
+ protected MavenProject readMavenProject(File basedir, String profile)
throws Exception {
File pom = new File(basedir, "pom.xml");
+ LocalRepository localRepo = new LocalRepository(new File(basedir, "local-repo"));
+ DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
+ RepositorySystem system = locator.getService(RepositorySystem.class);
+ DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
+ session.setLocalRepositoryManager(system.newLocalRepositoryManager(session, localRepo));
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setBaseDirectory(basedir);
+ if (profile != null) {
+ request.addActiveProfile(profile);
+ }
ProjectBuildingRequest configuration = request.getProjectBuildingRequest();
- configuration.setRepositorySession(new DefaultRepositorySystemSession());
+ configuration.setRepositorySession(session);
+ configuration.setResolveDependencies(true);
MavenProject project = lookup(ProjectBuilder.class).build(pom, configuration).getProject();
assertNotNull(project);
return project;
}
-}
\ No newline at end of file
+}
diff --git a/modules/openapi-generator-maven-plugin/src/test/resources/default/local-repo/petstore/schema/1/schema-1.jar b/modules/openapi-generator-maven-plugin/src/test/resources/default/local-repo/petstore/schema/1/schema-1.jar
new file mode 100644
index 0000000000000..5b4d1c0860f71
Binary files /dev/null and b/modules/openapi-generator-maven-plugin/src/test/resources/default/local-repo/petstore/schema/1/schema-1.jar differ
diff --git a/modules/openapi-generator-maven-plugin/src/test/resources/default/local-repo/petstore/schema/1/schema-1.pom b/modules/openapi-generator-maven-plugin/src/test/resources/default/local-repo/petstore/schema/1/schema-1.pom
new file mode 100644
index 0000000000000..bd1c51309d9a1
--- /dev/null
+++ b/modules/openapi-generator-maven-plugin/src/test/resources/default/local-repo/petstore/schema/1/schema-1.pom
@@ -0,0 +1,9 @@
+
+
+ 4.0.0
+ petstore
+ schema
+ 1
+ POM was created from install:install-file
+
diff --git a/modules/openapi-generator-maven-plugin/src/test/resources/default/local-repo/petstore/schema/maven-metadata-local.xml b/modules/openapi-generator-maven-plugin/src/test/resources/default/local-repo/petstore/schema/maven-metadata-local.xml
new file mode 100644
index 0000000000000..d66c798366f3f
--- /dev/null
+++ b/modules/openapi-generator-maven-plugin/src/test/resources/default/local-repo/petstore/schema/maven-metadata-local.xml
@@ -0,0 +1,12 @@
+
+
+ petstore
+ schema
+
+ 1
+
+ 1
+
+ 20210724220722
+
+
diff --git a/modules/openapi-generator-maven-plugin/src/test/resources/default/pom.xml b/modules/openapi-generator-maven-plugin/src/test/resources/default/pom.xml
index a2b3a7b26f6d6..67a74ce374570 100644
--- a/modules/openapi-generator-maven-plugin/src/test/resources/default/pom.xml
+++ b/modules/openapi-generator-maven-plugin/src/test/resources/default/pom.xml
@@ -1,5 +1,5 @@