Skip to content

chore(cts): update dependency on cts generation for java #505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/generation.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = {
'!clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/exceptions/**',
'!clients/algoliasearch-client-java-2/algoliasearch-core/src/main/java/com/algolia/utils/**',

'tests/output/java/build.gradle',
'tests/output/java/src/test/java/com/algolia/methods/**', // this could be added automatically by the script, but with overhead
'tests/output/java/src/test/java/com/algolia/client/**',

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ public abstract class CtsManager {

public abstract void addSupportingFiles(List<SupportingFile> supportingFiles);

public List<Object> getPackageDependencies() {
return null;
}

protected void addExtraToBundle(Map<String, Object> bundle) {}

public void addDataToBundle(Map<String, Object> bundle) {
bundle.put("packageDependencies", this.getPackageDependencies());
this.addExtraToBundle(bundle);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
package com.algolia.codegen.cts.manager;

import com.algolia.codegen.Utils;
import java.util.*;
import org.openapitools.codegen.SupportingFile;

public class JavaCtsManager extends CtsManager {

public void addSupportingFiles(List<SupportingFile> supportingFiles) {}
public void addSupportingFiles(List<SupportingFile> supportingFiles) {
supportingFiles.add(
new SupportingFile("build.mustache", ".", "build.gradle")
);
}

protected void addExtraToBundle(Map<String, Object> bundle) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so clean 💙

bundle.put(
"packageVersion",
Utils
.readJsonFile("config/clients.config.json")
.get("java")
.get("packageVersion")
.asText()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void addSupportingFiles(List<SupportingFile> supportingFiles) {
);
}

public List<Object> getPackageDependencies() {
private List<Object> getPackageDependencies() {
List<Object> result = new ArrayList<Object>();

JsonNode openApiToolsConfig = Utils.readJsonFile(
Expand Down Expand Up @@ -45,6 +45,7 @@ public List<Object> getPackageDependencies() {
}

protected void addExtraToBundle(Map<String, Object> bundle) {
bundle.put("packageDependencies", this.getPackageDependencies());
bundle.put("utilsPackageVersion", this.getUtilsPackageVersion());
}

Expand Down
31 changes: 31 additions & 0 deletions tests/CTS/methods/requests/templates/java/build.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
plugins {
id 'java'
}

repositories {
mavenCentral()
}

dependencies {
testImplementation 'com.algolia:algoliasearch-client-java:{{packageVersion}}-SNAPSHOT'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know if semver works with the SNAPSHOT suffix ? in that case we could maybe remove SNAPSHOT everywhere and just have it in the clients.config.json file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I don't remember what SNAPSHOT means in Java. Can you remind me? Is it always SNAPSHOT, or can it be something else?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's like experimental, it will be released on a different central repository that user have to opt in if they want to use the SNAPSHOT, so once this is out of beta the SNAPSHOT will be removed.
I read that semver accepts suffix value after dash but I'm not sure

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it's fine it this stays here it works well like this, it's just a small improvement if possible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

semver works with ${major}.${minor}.${patch}-${WHATEVER-POSTFIX}.${number} format, which means something like 1.0.0-beta.9. Ending with SNAPSHOT but without number wouldn't work AFAIK.

testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
testImplementation 'org.skyscreamer:jsonassert:1.5.0'
testImplementation 'com.google.code.gson:gson:2.8.9'
}

group = 'com.algolia'
version = '1.0'
description = 'java-tests'
java.sourceCompatibility = JavaVersion.VERSION_1_8

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

test() {
useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
showStandardStreams = true
}
}