Skip to content
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

1527 move zipinclude macro to core #1532

Merged
merged 27 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9e05a85
Adds rawTest macro and tests. Fix #1524.
AndreaLaGrotteria Oct 23, 2024
356ae11
Fixes spaces.
AndreaLaGrotteria Oct 23, 2024
cdff572
Fixes spaces.
AndreaLaGrotteria Oct 23, 2024
e72201d
Adds resource macro and tests. Fix #1525.
AndreaLaGrotteria Oct 23, 2024
e0ed37e
Apply requested changes.
AndreaLaGrotteria Oct 23, 2024
0633bde
Apply requested changes.
AndreaLaGrotteria Oct 23, 2024
c830ca7
Apply requested changes.
AndreaLaGrotteria Oct 23, 2024
f72d259
Apply requested changes.
AndreaLaGrotteria Oct 23, 2024
857651f
Fix for header lines offset.
AndreaLaGrotteria Oct 23, 2024
0a6b4c1
Implements suggestions.
AndreaLaGrotteria Oct 23, 2024
e972324
fix tests
sdelamo Oct 24, 2024
6a8e709
add @Nullability annotation
sdelamo Oct 24, 2024
adc0585
license lines is 0 don’t add lines attributes
sdelamo Oct 24, 2024
58fe4fb
Adds testResource macro to core. Fix #1526.
AndreaLaGrotteria Oct 24, 2024
d8c08e6
Adds supports for multi-line inputs. Makes code more modular.
AndreaLaGrotteria Oct 24, 2024
c645194
Adds supports for multi-line inputs. Makes code more modular.
AndreaLaGrotteria Oct 24, 2024
eb82a83
Adds supports for multi-line inputs. Makes code more modular.
AndreaLaGrotteria Oct 24, 2024
b295ee6
Improves path display.
AndreaLaGrotteria Oct 24, 2024
e9d59d2
Adds annotations.
AndreaLaGrotteria Oct 24, 2024
c0f3f79
Adds annotations.
AndreaLaGrotteria Oct 24, 2024
9d500ea
Adds resourceMacro and tests. Fix #1525.
AndreaLaGrotteria Oct 24, 2024
2329684
Merge branch '1525-move-resource-macro-to-core' into 1526-move-testre…
AndreaLaGrotteria Oct 24, 2024
60426d9
Adapts code to merged changes.
AndreaLaGrotteria Oct 24, 2024
0088b40
Adds zipInclude macro and tests. Fix #1527.
AndreaLaGrotteria Oct 24, 2024
0d725e1
Merge branch 'master' into 1526-move-testresource-macro-to-core
AndreaLaGrotteria Oct 25, 2024
f2a0a68
Bug fix.
AndreaLaGrotteria Oct 25, 2024
63ec0a0
Merge branch '1526-move-testresource-macro-to-core' into 1527-move-zi…
AndreaLaGrotteria Oct 25, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.micronaut.guides.core;

import io.micronaut.core.annotation.NonNull;
import jakarta.inject.Singleton;

import java.util.List;

import static io.micronaut.guides.core.MacroUtils.*;
import static io.micronaut.guides.core.MacroUtils.addIncludes;

@Singleton
public class TestResourceMacroSubstitution implements MacroSubstitution {
private final GuidesConfiguration guidesConfiguration;
private final LicenseLoader licenseLoader;
public TestResourceMacroSubstitution(GuidesConfiguration guidesConfiguration, LicenseLoader licenseLoader) {
this.guidesConfiguration = guidesConfiguration;
this.licenseLoader = licenseLoader;
}

@Override
public String substitute(String str, String slug, GuidesOption option) {
for(String line : findMacroLines(str, "testResource")){

String name = extractName(line, "testResource");
String appName = extractAppName(line);
List<String> tags = extractTags(line);
String indent = extractIndent(line);
String sourcePath = testResourcePath(appName, name);
String extension = resolveAsciidoctorLanguage(name);

List<String> lines = addIncludes(option, licenseLoader, guidesConfiguration, slug, sourcePath, extension, indent, tags);

str = str.replace(line,String.join("\n", lines));
}
return str;
}

@NonNull
private static String testResourcePath(@NonNull String appName, @NonNull String fileName) {
String module = appName.isEmpty() ? "" : appName + "/";
return module + "src/" + "test/resources/" + fileName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.micronaut.guides.core;

import jakarta.inject.Singleton;

import java.util.List;

import static io.micronaut.guides.core.MacroUtils.*;
import static io.micronaut.guides.core.MacroUtils.addIncludes;

@Singleton
public class ZipIncludeMacroSubstitution implements MacroSubstitution {
private final GuidesConfiguration guidesConfiguration;
private final LicenseLoader licenseLoader;

public ZipIncludeMacroSubstitution(GuidesConfiguration guidesConfiguration, LicenseLoader licenseLoader) {
this.guidesConfiguration = guidesConfiguration;
this.licenseLoader = licenseLoader;
}

@Override
public String substitute(String str, String slug, GuidesOption option) {
for(String line : findMacroLines(str, "zipInclude")) {

String name = extractName(line, "zipInclude");
List<String> tags = extractTags(line);
String indent = extractIndent(line);
String sourcePath = name;
String extension = resolveAsciidoctorLanguage(name);

List<String> lines = addIncludes(option, licenseLoader, guidesConfiguration, slug, sourcePath, extension, indent, tags);

str = str.replace(line,String.join("\n", lines));
}
return str;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private List<String> attributes() {
if (getTags().size() > 1) {
attributes.add("tags=" + String.join(";", getTags()));
} else if (getTags().size() == 1) {
attributes.add("tag=" + getTags().getFirst());
attributes.add("tag=" + getTags().get(0));
}
}
if (getIndent() != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.micronaut.guides.core;

import io.micronaut.starter.api.TestFramework;
import io.micronaut.starter.options.BuildTool;
import io.micronaut.starter.options.Language;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

@MicronautTest(startApplication = false)
public class TestResourceMacroSubstitutionTest {

@Inject
TestResourceMacroSubstitution testResourceMacroSubstitution;

@Test
void testSubstitute() {
String str = "testResource:application-test.yml[tag=testcontainers]";
String resJava = testResourceMacroSubstitution.substitute(str, "micronaut-metrics-oci", new GuidesOption(BuildTool.GRADLE, Language.JAVA, TestFramework.JUNIT));
String expectedJava = """
[source,yaml]
.src/test/resources/application-test.yml
----
include::{sourceDir}/micronaut-metrics-oci/micronaut-metrics-oci-gradle-java/src/test/resources/application-test.yml[tag=testcontainers]
----""";
assertEquals(expectedJava, resJava);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.micronaut.guides.core;

import io.micronaut.starter.api.TestFramework;
import io.micronaut.starter.options.BuildTool;
import io.micronaut.starter.options.Language;
import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

@MicronautTest(startApplication = false)
public class ZipIncludeSubstitutionTest {

@Inject
ZipIncludeMacroSubstitution zipIncludeMacroSubstitution;

@Test
void testSubstitute() {
String str = """
A fast way to start using Kafka is https://hub.docker.com/r/confluentinc/cp-kafka/[via Docker]. Create this `docker-compose.yml` file:

zipInclude:docker/docker-compose.yml[]""";
String resJava = zipIncludeMacroSubstitution.substitute(str, "micronaut-kafka", new GuidesOption(BuildTool.GRADLE, Language.JAVA, TestFramework.JUNIT));
String expectedJava = """
A fast way to start using Kafka is https://hub.docker.com/r/confluentinc/cp-kafka/[via Docker]. Create this `docker-compose.yml` file:

[source,yaml]
.docker/docker-compose.yml
----
include::{sourceDir}/micronaut-kafka/micronaut-kafka-gradle-java/docker/docker-compose.yml[]
----""";
assertEquals(expectedJava, resJava);
}
}
Loading