Skip to content

Commit ce54568

Browse files
committed
feat(#65): get motives at runtime
1 parent 75e9d7b commit ce54568

File tree

5 files changed

+112
-17
lines changed

5 files changed

+112
-17
lines changed

.github/motives.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ fi
1414
rm -rf "gh-pages/${tag}"
1515
mkdir -p "gh-pages/${tag}"
1616

17+
mkdir "gh-pages/${tag}-md"
18+
mvn clean compile exec:java "-Dexec.args=${tag}"
19+
1720
while IFS= read -r f; do
1821
n=$(basename "${f}" .md)
1922
html=gh-pages/${tag}/${n}.html
2023
pandoc "${f}" -o "${html}"
2124
echo "${n} -> $(du -b "${html}" | cut -f1) bytes"
22-
done < <(find src/main/resources/org/eolang/motives -name '*.md')
25+
done < <(find "gh-pages/${tag}-md" -name '*.md')
2326

2427
list_them() {
2528
printf "<ul>\n"

pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@
243243
<configuration>
244244
<excludes>
245245
<exclude>pmd:/src/it/.*</exclude>
246+
<exclude>pmd:/src/main/java/org/eolang/lints/SaveAll.java</exclude>
246247
<exclude>checkstyle:/src/it/.*</exclude>
248+
<exclude>checkstyle:/src/main/java/org/eolang/lints/SaveAll.java</exclude>
247249
<exclude>duplicatefinder:.*</exclude>
248250
<exclude>dependencies:.*</exclude>
249251
</excludes>
@@ -534,6 +536,21 @@
534536
</execution>
535537
</executions>
536538
</plugin>
539+
<plugin>
540+
<groupId>org.codehaus.mojo</groupId>
541+
<artifactId>exec-maven-plugin</artifactId>
542+
<version>3.5.0</version>
543+
<executions>
544+
<execution>
545+
<goals>
546+
<goal>java</goal>
547+
</goals>
548+
</execution>
549+
</executions>
550+
<configuration>
551+
<mainClass>org.eolang.lints.SaveAll</mainClass>
552+
</configuration>
553+
</plugin>
537554
</plugins>
538555
</build>
539556
</project>

src/main/java/org/eolang/lints/LtByXsl.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
import com.jcabi.xml.XMLDocument;
1212
import com.jcabi.xml.XSL;
1313
import com.jcabi.xml.XSLDocument;
14+
import io.github.secretx33.resourceresolver.DefaultResourceLoader;
1415
import java.io.IOException;
16+
import java.nio.charset.StandardCharsets;
1517
import java.util.Collection;
1618
import java.util.LinkedList;
1719
import java.util.Optional;
@@ -40,9 +42,9 @@ final class LtByXsl implements Lint<XML> {
4042
private final XSL sheet;
4143

4244
/**
43-
* Motive document.
45+
* Path to motive document.
4446
*/
45-
private final Input doc;
47+
private final String doc;
4648

4749
/**
4850
* Ctor.
@@ -54,20 +56,18 @@ final class LtByXsl implements Lint<XML> {
5456
new ResourceOf(
5557
String.format("org/eolang/lints/%s.xsl", xsl)
5658
),
57-
new ResourceOf(
58-
String.format("org/eolang/motives/%s.md", xsl)
59-
)
59+
String.format("org/eolang/motives/%s.md", xsl)
6060
);
6161
}
6262

6363
/**
6464
* Ctor.
65-
* @param xsl Relative path of XSL
66-
* @param motive Relative path of a motive document
65+
* @param xsl Absolute path of XSL
66+
* @param motive Absolute path of a motive document
6767
* @throws IOException If fails
6868
*/
6969
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
70-
LtByXsl(final Input xsl, final Input motive) throws IOException {
70+
LtByXsl(final Input xsl, final String motive) throws IOException {
7171
final XML xml = new XMLDocument(new IoCheckedText(new TextOf(xsl)).asString());
7272
this.rule = new Xnav(xml.toString())
7373
.element("xsl:stylesheet")
@@ -117,7 +117,9 @@ public Collection<Defect> defects(final XML xmir) {
117117

118118
@Override
119119
public String motive() throws IOException {
120-
return new IoCheckedText(new TextOf(this.doc)).asString();
120+
return new DefaultResourceLoader()
121+
.getResource(this.doc)
122+
.getContentAsString(StandardCharsets.UTF_8);
121123
}
122124

123125
/**

src/main/java/org/eolang/lints/PkByXsl.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,11 @@ private static Iterable<Lint<XML>> all() {
5454
res ->
5555
new LtByXsl(
5656
new InputOf(res.getInputStream()),
57-
new InputOf(
58-
PkByXsl.XSL_PATTERN.matcher(
59-
PkByXsl.LINTS_PATH.matcher(
60-
res.getURL().toString()
61-
).replaceAll("eolang/motives")
62-
).replaceAll(".md")
63-
)
57+
PkByXsl.XSL_PATTERN.matcher(
58+
PkByXsl.LINTS_PATH.matcher(
59+
res.getURL().toString()
60+
).replaceAll("eolang/motives")
61+
).replaceAll(".md")
6462
),
6563
Arrays.asList(
6664
new PathMatchingResourcePatternResolver().getResources(
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
3+
* SPDX-License-Identifier: MIT
4+
*/
5+
package org.eolang.lints;
6+
7+
import java.io.IOException;
8+
import java.nio.file.Files;
9+
import java.nio.file.Path;
10+
import java.time.ZoneOffset;
11+
import java.time.ZonedDateTime;
12+
import java.time.format.DateTimeFormatter;
13+
import java.util.Locale;
14+
import java.util.stream.Collectors;
15+
import java.util.stream.Stream;
16+
import org.cactoos.iterable.Joined;
17+
18+
public class SaveAll {
19+
public static void main(String[] args) throws IOException {
20+
if (args.length != 1) {
21+
throw new IllegalStateException("First arg must exist and point to version");
22+
}
23+
Stream.Builder<String> names = Stream.builder();
24+
new Joined<Lint<?>>(
25+
new PkWpa(),
26+
new PkMono()
27+
).forEach(lint -> {
28+
names.add(lint.name());
29+
try {
30+
Files.writeString(
31+
Path.of(
32+
"gh-pages",
33+
args[0] + "-md",
34+
lint.name() + ".md"
35+
),
36+
lint.motive()
37+
);
38+
} catch (IOException e) {
39+
throw new RuntimeException(e);
40+
}
41+
});
42+
Files.writeString(
43+
Path.of("gh-pages/README.md"),
44+
String.format(
45+
String.join(
46+
"\n",
47+
"Latest version: %s",
48+
"",
49+
"List of lints in this version:",
50+
"",
51+
names.build()
52+
.map(
53+
name -> String.format(
54+
"- [%1$s](%2$s/%1$s.md)",
55+
name,
56+
args[0] + "-md"
57+
)
58+
)
59+
.collect(Collectors.joining("\n")),
60+
"",
61+
String.format(
62+
"Published on %s.",
63+
ZonedDateTime.now(ZoneOffset.UTC).format(
64+
DateTimeFormatter.ofPattern(
65+
"EEE MMM dd HH:mm:ss zzz yyyy",
66+
Locale.ENGLISH
67+
)
68+
)
69+
)
70+
),
71+
args[0]
72+
)
73+
);
74+
}
75+
}

0 commit comments

Comments
 (0)