Skip to content

Commit ca48ba4

Browse files
committed
feat(#65): add docs to README + get motives at runtime
1 parent 9ae0b5d commit ca48ba4

File tree

5 files changed

+62
-17
lines changed

5 files changed

+62
-17
lines changed

.github/motives.groovy

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
3+
* SPDX-License-Identifier: MIT
4+
*/
5+
package org.eolang.lints
6+
7+
/**
8+
* This script is run using gplus in the script motives.sh.
9+
* It saves to a file named lint and the extension.md is the motive of this lint.
10+
* All files are saved to the tmp folder
11+
* @todo #65:30min after fixing this problem https://github.com/jcabi/jcabi-parent/issues/586,
12+
* move this script to the src/main/groovy folder and write a test for it.
13+
*/
14+
15+
static def saveLint(Lint<?> lint) {
16+
new File("tmp/${lint.name()}.md").text = lint.motive()
17+
}
18+
19+
new PkMono().forEach {
20+
saveLint(it)
21+
}
22+
23+
new PkWpa().forEach {
24+
saveLint(it)
25+
}

.github/motives.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,15 @@ tail() {
4141
printf '</article></section></body></html>'
4242
}
4343

44+
mkdir tmp
45+
mvn clean compile gplus:execute
46+
4447
while IFS= read -r f; do
4548
n=$(basename "${f}" .md)
4649
html=gh-pages/${tag}/${n}.html
4750
( head && pandoc "${f}" && tail ) > "${html}"
4851
echo "${n} -> $(du -b "${html}" | cut -f1) bytes"
49-
done < <(find src/main/resources/org/eolang/motives -name '*.md' | sort)
52+
done < <(find tmp -name '*.md' | sort)
5053

5154
(
5255
head

pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,23 @@
534534
</execution>
535535
</executions>
536536
</plugin>
537+
<plugin>
538+
<groupId>org.codehaus.gmavenplus</groupId>
539+
<artifactId>gmavenplus-plugin</artifactId>
540+
<version>4.1.1</version>
541+
<configuration>
542+
<scripts>
543+
<script>./.github/motives.groovy</script>
544+
</scripts>
545+
</configuration>
546+
<dependencies>
547+
<dependency>
548+
<groupId>org.apache.groovy</groupId>
549+
<artifactId>groovy</artifactId>
550+
<version>4.0.26</version>
551+
</dependency>
552+
</dependencies>
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(

0 commit comments

Comments
 (0)