Skip to content

Commit

Permalink
Use fake version instead of 999-SNAPSHOT in devtools-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy committed Apr 23, 2021
1 parent e3fc195 commit 4a15f79
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.KOTLIN;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest;
Expand All @@ -20,7 +21,12 @@ public class ConfigYamlCodestartTest {
void testContent() throws Throwable {
codestartTest.checkGeneratedSource("org.acme.GreetingConfig");
codestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "src/main/resources/application.yml");
//codestartTest.buildAllProjects();
}

@Test
@EnabledIfSystemProperty(named = "build-projects", matches = "true")
void buildAllProjectsForLocalUse() throws Throwable {
codestartTest.buildAllProjects();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.JAVA;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest;
Expand All @@ -20,7 +21,12 @@ void testContent() throws Throwable {
codestartTest.checkGeneratedSource("org.acme.MyFunctions");
codestartTest.checkGeneratedTestSource("org.acme.MyFunctionsTest");
codestartTest.checkGeneratedTestSource("org.acme.MyFunctionsIT");
//codestartTest.buildAllProjects();
}

@Test
@EnabledIfSystemProperty(named = "build-projects", matches = "true")
void buildAllProjectsForLocalUse() throws Throwable {
codestartTest.buildAllProjects();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static io.quarkus.devtools.testing.SnapshotTesting.checkContains;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.devtools.project.BuildTool;
Expand Down Expand Up @@ -34,7 +35,11 @@ void testContent() throws Throwable {

codestartGradleTest.assertThatGeneratedFile(JAVA, "README.md")
.satisfies(checkContains("./gradlew quarkusDev --quarkus-args='Quarky'"));
}

//codestartTest.buildAllProjects();
@Test
@EnabledIfSystemProperty(named = "build-projects", matches = "true")
void buildAllProjectsForLocalUse() throws Throwable {
codestartTest.buildAllProjects();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static io.quarkus.devtools.codestarts.quarkus.QuarkusCodestartCatalog.Language.KOTLIN;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.devtools.testing.codestarts.QuarkusCodestartTest;
Expand All @@ -20,6 +21,11 @@ public class RESTEasyQuteCodestartTest {
void testContent() throws Throwable {
codestartTest.checkGeneratedSource("org.acme.SomePage");
codestartTest.assertThatGeneratedFileMatchSnapshot(JAVA, "src/main/resources/templates/page.qute.html");
//codestartTest.buildAllProjects();
}

@Test
@EnabledIfSystemProperty(named = "build-projects", matches = "true")
void buildAllProjectsForLocalUse() throws Throwable {
codestartTest.buildAllProjects();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public static Optional<String> getBuildtool(final Map<String, Object> data) {
public static Map<String, Object> buildCodestartData(final Codestart codestart, final String languageName,
final Map<String, Object> data) {
final Optional<Map<String, Object>> value = NestedMaps.getValue(data, codestart.getName());
Map<String, Object> codestartData = new HashMap<>();
codestartData.putAll(data);
NestedMaps.deepMerge(codestartData, codestart.getLocalData(languageName));
value.ifPresent(map -> NestedMaps.deepMerge(codestartData, map));
return codestartData;
Map<String, Object> withLocalCodestartData = NestedMaps.deepMerge(data, codestart.getLocalData(languageName));
if (!value.isPresent()) {
return withLocalCodestartData;
}
return NestedMaps.deepMerge(withLocalCodestartData, value.get());
}

public static Map<String, Object> buildCodestartProjectData(Collection<Codestart> baseCodestarts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public void process(Path targetDirectory, String relativePath, List<TargetFile>
for (TargetFile codestartFile : codestartFiles) {
final String content = codestartFile.getContent();
if (!content.trim().isEmpty()) {
final Map o = YAML_MAPPER.readerFor(Map.class).readValue(content);
NestedMaps.deepMerge(config, o);
final Map<String, Object> o = YAML_MAPPER.readerFor(Map.class).readValue(content);
config.putAll(NestedMaps.deepMerge(config, o));
}
}
final Path targetPath = targetDirectory.resolve(relativePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,33 @@ public static <T> Optional<T> getValue(Map<String, Object> data, String path) {

public static <T> Map<String, T> deepMerge(final Stream<Map<String, T>> mapStream) {
final Map<String, T> out = new HashMap<>();
mapStream.forEach(m -> deepMerge(out, m));
mapStream.forEach(m -> internalDeepMerge(out, m));
return out;
}

public static Map<String, Object> deepMerge(final Map<String, Object> left, final Map<String, Object> right) {
final Map<String, Object> out = new HashMap<>();
internalDeepMerge(out, left);
internalDeepMerge(out, right);
return out;
}

@SuppressWarnings({ "rawtypes", "unchecked" })
public static void deepMerge(Map left, Map right) {
private static void internalDeepMerge(Map left, Map right) {
for (Object key : right.keySet()) {
Object rightValue = right.get(key);
Object leftValue = left.get(key);

if (rightValue instanceof Map && leftValue instanceof Map) {
deepMerge((Map) leftValue, (Map) rightValue);
internalDeepMerge((Map) leftValue, (Map) rightValue);
} else if (rightValue instanceof Collection && leftValue instanceof Collection) {
Collection c = new LinkedHashSet();
c.addAll((Collection) leftValue);
c.addAll((Collection) rightValue);
left.put(key, c);
} else if (rightValue instanceof Map) {
final Map map = new HashMap();
deepMerge(map, (Map) rightValue);
internalDeepMerge(map, (Map) rightValue);
left.put(key, map);
} else if (rightValue instanceof Collection) {
left.put(key, new LinkedHashSet((Collection) rightValue));
Expand All @@ -57,11 +64,13 @@ public static void deepMerge(Map left, Map right) {
|| rightValue instanceof Float
|| rightValue instanceof Long
|| rightValue instanceof Double
|| rightValue instanceof String) {
|| rightValue instanceof String
|| rightValue == null) {
// Override
left.put(key, rightValue);
} else {
throw new IllegalArgumentException("Invalid value type for deepMerge: " + rightValue.getClass());
}
// else ignore
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
Expand All @@ -23,12 +24,12 @@ class NestedMapsTest {

@Test
void testDeepMerge() {
final HashMap<String, Object> target = new HashMap<>();

NestedMaps.deepMerge(target, NESTED_MAP_1);
NestedMaps.deepMerge(target, NESTED_MAP_2);
final Map<String, Object> target = NestedMaps.deepMerge(NESTED_MAP_1, NESTED_MAP_2);

checkTargetMap(target);
((Map) target.get("hello")).put("world", "changed");
final Map<String, Object> targetAgain = NestedMaps.deepMerge(NESTED_MAP_1, NESTED_MAP_2);
checkTargetMap(targetAgain);
}

@Test
Expand Down Expand Up @@ -67,7 +68,7 @@ private void checkTargetMap(Map<String, Object> target) {

assertThat(NestedMaps.getValue(target, "bar.foo.bar.foo")).hasValue("bar");
assertThat(NestedMaps.getValue(target, "bar.foo.bar.baz")).hasValue("foo");
assertThat(NestedMaps.getValue(target, "hello")).hasValue("world");
assertThat(NestedMaps.getValue(target, "hello.world")).hasValue("helloworld");
assertThat((Collection) NestedMaps.getValue(target, "list").get()).containsExactly("foo", "bar", "baz");
}

Expand All @@ -82,7 +83,7 @@ void testUnflatten() {
data.put("baz", "bar");
data.put("bar.foo.bar.foo", "bar");
data.put("bar.foo.bar.baz", "foo");
data.put("hello", "world");
data.put("hello", Collections.singletonMap("world", "helloworld"));
data.put("list", Arrays.asList("foo", "bar", "baz"));
final Map<String, Object> target = NestedMaps.unflatten(data);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ bar:
foo: bar
baz: foo
hello:
world
world: helloworld
list:
- baz
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "io.quarkus:quarkus-bom-quarkus-platform-descriptor:999-SNAPSHOT:json:999-SNAPSHOT",
"id": "io.quarkus:quarkus-fake-bom:999-FAKE:json:999-FAKE",
"platform": true,
"bom": "io.quarkus:quarkus-bom::pom:999-SNAPSHOT",
"bom": "io.quarkus:quarkus-bom::pom:999-FAKE",
"derived-from": [],
"extensions": [
{
Expand All @@ -26,13 +26,13 @@
"kotlin",
"scala"
],
"artifact": "io.quarkus:quarkus-descriptor-json"
"artifact": "io.quarkus:fake-artifact"
},
"built-with-quarkus-core": "999-SNAPSHOT"
"built-with-quarkus-core": "999-FAKE"
},
"artifact": "io.quarkus:quarkus-resteasy-reactive::jar:999-SNAPSHOT",
"artifact": "io.quarkus:quarkus-resteasy-reactive::jar:999-FAKE",
"origins": [
"io.quarkus:quarkus-bom-quarkus-platform-descriptor:999-SNAPSHOT:json:999-SNAPSHOT"
"io.quarkus:quarkus-fake-bom:999-FAKE:json:999-FAKE"
]
},
{
Expand All @@ -56,13 +56,13 @@
"java",
"kotlin"
],
"artifact": "io.quarkus:quarkus-descriptor-json"
"artifact": "io.quarkus:fake-artifact"
},
"built-with-quarkus-core": "999-SNAPSHOT"
"built-with-quarkus-core": "999-FAKE"
},
"artifact": "io.quarkus:quarkus-config-yaml::jar:999-SNAPSHOT",
"artifact": "io.quarkus:quarkus-config-yaml::jar:999-FAKE",
"origins": [
"io.quarkus:quarkus-bom-quarkus-platform-descriptor:999-SNAPSHOT:json:999-SNAPSHOT"
"io.quarkus:quarkus-fake-bom:999-FAKE:json:999-FAKE"
]
},
{
Expand All @@ -88,13 +88,13 @@
"kotlin",
"scala"
],
"artifact": "io.quarkus:quarkus-descriptor-json"
"artifact": "io.quarkus:fake-artifact"
},
"built-with-quarkus-core": "999-SNAPSHOT"
"built-with-quarkus-core": "999-FAKE"
},
"artifact": "io.quarkus:quarkus-resteasy::jar:999-SNAPSHOT",
"artifact": "io.quarkus:quarkus-resteasy::jar:999-FAKE",
"origins": [
"io.quarkus:quarkus-bom-quarkus-platform-descriptor:999-SNAPSHOT:json:999-SNAPSHOT"
"io.quarkus:quarkus-fake-bom:999-FAKE:json:999-FAKE"
]
},
{
Expand All @@ -117,13 +117,13 @@
"kotlin",
"scala"
],
"artifact": "io.quarkus:quarkus-descriptor-json"
"artifact": "io.quarkus:fake-artifact"
},
"built-with-quarkus-core": "999-SNAPSHOT"
"built-with-quarkus-core": "999-FAKE"
},
"artifact": "io.quarkus:quarkus-spring-web::jar:999-SNAPSHOT",
"artifact": "io.quarkus:quarkus-spring-web::jar:999-FAKE",
"origins": [
"io.quarkus:quarkus-bom-quarkus-platform-descriptor:999-SNAPSHOT:json:999-SNAPSHOT"
"io.quarkus:quarkus-fake-bom:999-FAKE:json:999-FAKE"
]
},
{
Expand All @@ -141,13 +141,13 @@
"codestart": {
"name": "kotlin",
"kind": "core",
"artifact": "io.quarkus:quarkus-descriptor-json"
"artifact": "io.quarkus:fake-artifact"
},
"built-with-quarkus-core": "999-SNAPSHOT"
"built-with-quarkus-core": "999-FAKE"
},
"artifact": "io.quarkus:quarkus-kotlin::jar:999-SNAPSHOT",
"artifact": "io.quarkus:quarkus-kotlin::jar:999-FAKE",
"origins": [
"io.quarkus:quarkus-bom-quarkus-platform-descriptor:999-SNAPSHOT:json:999-SNAPSHOT"
"io.quarkus:quarkus-fake-bom:999-FAKE:json:999-FAKE"
]
},
{
Expand All @@ -164,13 +164,13 @@
"codestart": {
"name": "scala",
"kind": "core",
"artifact": "io.quarkus:quarkus-descriptor-json"
"artifact": "io.quarkus:fake-artifact"
},
"built-with-quarkus-core": "999-SNAPSHOT"
"built-with-quarkus-core": "999-FAKE"
},
"artifact": "io.quarkus:quarkus-scala::jar:999-SNAPSHOT",
"artifact": "io.quarkus:quarkus-scala::jar:999-FAKE",
"origins": [
"io.quarkus:quarkus-bom-quarkus-platform-descriptor:999-SNAPSHOT:json:999-SNAPSHOT"
"io.quarkus:quarkus-fake-bom:999-FAKE:json:999-FAKE"
]
}
],
Expand Down Expand Up @@ -305,21 +305,21 @@
"kotlin-version": "1.4.31",
"scala-version": "2.12.13",
"scala-plugin-version": "4.4.0",
"quarkus-core-version": "999-SNAPSHOT",
"quarkus-core-version": "999-FAKE",
"maven-plugin-groupId": "io.quarkus",
"maven-plugin-artifactId": "quarkus-maven-plugin",
"maven-plugin-version": "999-SNAPSHOT",
"maven-plugin-version": "999-FAKE",
"gradle-plugin-id": "io.quarkus",
"gradle-plugin-version": "999-SNAPSHOT",
"gradle-plugin-version": "999-FAKE",
"supported-maven-versions": "[3.6.2,)",
"proposed-maven-version": "3.6.3",
"maven-wrapper-version": "0.7.7",
"gradle-wrapper-version": "6.8.3"
}
},
"codestarts-artifacts": [
"io.quarkus:quarkus-platform-descriptor-json::jar:999-SNAPSHOT"
"io.quarkus:fake-artifact::jar:999-FAKE"
]
},
"quarkus-core-version": "999-SNAPSHOT"
"quarkus-core-version": "999-FAKE"
}

0 comments on commit 4a15f79

Please sign in to comment.