Skip to content

Commit

Permalink
Bump and proper package (#39)
Browse files Browse the repository at this point in the history
* Bump Kiota and generate in a namespace friendly folder

* cleanup
  • Loading branch information
andreaTP authored Oct 26, 2023
1 parent 8debd02 commit 463b745
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@

import org.junit.Test;

import apisdk.models.Widget;
import com.apisdk.models.Widget;

public class BasicCodegenTest {

@Test
public void test() throws Exception {
Class.forName("apisdk.models.Widget");
Class.forName("com.apisdk.models.Widget");

Widget widget = new Widget();
widget.setName("Test");
Expand Down
20 changes: 16 additions & 4 deletions plugin/src/main/java/com/redhat/cloud/kiota/maven/KiotaMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class KiotaMojo extends AbstractMojo {
/**
* Version of Kiota to be used
*/
@Parameter(defaultValue = "1.6.1")
@Parameter(defaultValue = "1.7.0")
private String kiotaVersion;

// Kiota Options
Expand Down Expand Up @@ -101,6 +101,15 @@ public class KiotaMojo extends AbstractMojo {
@Parameter(defaultValue = "${project.build.directory}/generated-sources/kiota")
private File targetDirectory;

private File finalTargetDirectory() {
Path namespaceResolver = targetDirectory.toPath();

for (String part: namespace.split("\\.")) {
namespaceResolver = namespaceResolver.resolve(part);
}
return namespaceResolver.toFile();
}

/**
* Language to generate the code for:
* <CSharp|Go|Java|PHP|Python|Ruby|Shell|Swift|TypeScript>
Expand All @@ -119,7 +128,7 @@ public class KiotaMojo extends AbstractMojo {
* The namespace to use for the core client class specified with the --class-name option. [default: ApiSdk]
*
*/
@Parameter(defaultValue = "ApiSdk")
@Parameter(defaultValue = "com.apisdk")
private String namespace;

/**
Expand Down Expand Up @@ -225,7 +234,7 @@ private String runProcess(List<String> cmd, boolean returnOutput) {
if (ps.exitValue() != 0) {
throw new RuntimeException("Error executing the Kiota command, exit code is " + ps.exitValue());
}
File kiotaLockFile = new File(targetDirectory, "kiota-lock.json");
File kiotaLockFile = new File(finalTargetDirectory(), "kiota-lock.json");
if (!kiotaLockFile.exists()) {
throw new RuntimeException("Error executing the Kiota command, no output found, cannot find the generated lock file.");
}
Expand Down Expand Up @@ -268,11 +277,14 @@ private void executeKiota(String binary, File openApiSpec) {
throw new IllegalArgumentException("Spec file not found on the path: " + openApiSpec.getAbsolutePath());
}
List<String> cmd = new ArrayList<>();
finalTargetDirectory().mkdirs();
String finalTargetDirectory = finalTargetDirectory().getAbsolutePath();

cmd.add(binary);
cmd.add("generate");
// process command line options
cmd.add("--openapi"); cmd.add(openApiSpec.getAbsolutePath());
cmd.add("--output"); cmd.add(targetDirectory.getAbsolutePath());
cmd.add("--output"); cmd.add(finalTargetDirectory);
cmd.add("--language"); cmd.add(language);
cmd.add("--class-name"); cmd.add(clientClass);
cmd.add("--namespace-name"); cmd.add(namespace);
Expand Down

0 comments on commit 463b745

Please sign in to comment.