Skip to content
Open
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
29 changes: 29 additions & 0 deletions .github/motives.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
* SPDX-License-Identifier: MIT
*/
package org.eolang.lints

/**
* This script is run using gplus in the script motives.sh.
* This script saves a file with the lint name and extension .md to the tmp folder.
* The motive of this lint is preserved as content.
* These files are saved for all active lints in the project.
* @todo #65:15min after fixing this problem with creation of groovy folder
* https://github.com/jcabi/jcabi-parent/issues/586,
* move this script to the src/main/groovy folder in package org.eolang.lints
* @todo #65:15min after moving motives.groovy into src/main/groovy we should add test,
* that verifies that this script correctly saves a list of all lint motifs to the tmp folder
*/

static def saveLint(Lint<?> lint) {
Copy link
Member

Choose a reason for hiding this comment

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

@Marat-Tim maybe we can setup tests for saveLint() method, in the src/test/groovy? Otherwise, we don't and won't know if we break something during the future modifications. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@h1alexbel when I tried to do this, I got an error jcabi/jcabi-parent#586

I added a puzzle to this fix

Copy link
Member

Choose a reason for hiding this comment

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

@Marat-Tim maybe you can remove the puzzle, since we released a new version of jcabi-parent?

new File("tmp/${lint.name()}.md").text = lint.motive()
}

new PkMono().forEach {
saveLint(it)
}

new PkWpa().forEach {
saveLint(it)
}
5 changes: 4 additions & 1 deletion .github/motives.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ tail() {
printf '</article></section></body></html>'
}

mkdir tmp
mvn clean compile gplus:execute

while IFS= read -r f; do
n=$(basename "${f}" .md)
html=gh-pages/${tag}/${n}.html
( head && pandoc "${f}" && tail ) > "${html}"
echo "${n} -> $(du -b "${html}" | cut -f1) bytes"
done < <(find src/main/resources/org/eolang/motives -name '*.md' | sort)
done < <(find tmp -name '*.md' | sort)

(
head
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ This Java package is a collection of "lints" (aka "checkers") for
formatting. This is about best practices and readiness of code
for successful compilation and execution.

You can find the current full list of rules [here][lints-list].

We use this package as a dependency in the
[EO-to-Java compiler][EO]:

Expand Down Expand Up @@ -171,3 +173,4 @@ If you want the code to be checked using
[XMIR]: https://news.eolang.org/2022-11-25-xmir-guide.html
[EO]: https://www.eolang.org
[benchmark-gha]: https://github.com/objectionary/lints/actions/runs/14839302036
[lints-list]: https://www.objectionary.com/lints/
17 changes: 17 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,23 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>4.1.1</version>
<configuration>
<scripts>
<script>./.github/motives.groovy</script>
Copy link
Member

Choose a reason for hiding this comment

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

@Marat-Tim let's move the script into src/main/groovy/org/eolang/lints/motives.groovy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@h1alexbel when I tried to do this, I got an error jcabi/jcabi-parent#586

I added a puzzle to this fix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@h1alexbel I'm not sure how to check this - could the presence of a groovy folder cause the entire Groovy runtime to be bundled into the final JAR?

Copy link
Member

@h1alexbel h1alexbel May 13, 2025

Choose a reason for hiding this comment

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

@Marat-Tim in the jcabi-parent, we have this groovy profile:

<profile>
  <!--
  Compile Groovy sources from src/main/groovy and src/test/groovy
  directories.
  -->
  <id>groovy</id>
  <activation>
    <file>
      <exists>${basedir}/src/main/groovy</exists>
    </file>
  </activation>
  <dependencies>
    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-all</artifactId>
      <version>3.0.24</version>
      <type>pom</type>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.gmavenplus</groupId>
        <artifactId>gmavenplus-plugin</artifactId>
        <version>4.2.0</version>
        <configuration>
          <verbose>true</verbose>
        </configuration>
        <executions>
          <execution>
            <id>jcabi-groovy</id>
            <goals>
              <goal>compile</goal>
              <goal>compileTests</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</profile>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@h1alexbel Honestly, I don't quite get it
When I run mvn install without any profiles, I see that classes from the groovy folder end up in target/classes
I'm concerned that this might cause the Groovy runtime to be bundled into the final JAR
Are my concerns unfounded?

Copy link
Member

Choose a reason for hiding this comment

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

@Marat-Tim correct. Your Groovy scripts should be located in the target/classes. From there you can invoke them using gmavenplus-plugin passing path to the script:

<scripts>
  <script>src/main/groovy/org/eolang/lints/SaveMotives.groovy</script>
</scripts>

</scripts>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy</artifactId>
<version>4.0.26</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
20 changes: 11 additions & 9 deletions src/main/java/org/eolang/lints/LtByXsl.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import com.jcabi.xml.XMLDocument;
import com.jcabi.xml.XSL;
import com.jcabi.xml.XSLDocument;
import io.github.secretx33.resourceresolver.DefaultResourceLoader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Optional;
Expand Down Expand Up @@ -40,9 +42,9 @@ final class LtByXsl implements Lint<XML> {
private final XSL sheet;

/**
* Motive document.
* Path to motive document.
*/
private final Input doc;
private final String doc;

/**
* Ctor.
Expand All @@ -54,20 +56,18 @@ final class LtByXsl implements Lint<XML> {
new ResourceOf(
String.format("org/eolang/lints/%s.xsl", xsl)
),
new ResourceOf(
String.format("org/eolang/motives/%s.md", xsl)
)
String.format("org/eolang/motives/%s.md", xsl)
);
}

/**
* Ctor.
* @param xsl Relative path of XSL
* @param motive Relative path of a motive document
* @param xsl Absolute path of XSL
* @param motive Absolute path of a motive document
* @throws IOException If fails
*/
@SuppressWarnings("PMD.ConstructorOnlyInitializesOrCallOtherConstructors")
LtByXsl(final Input xsl, final Input motive) throws IOException {
LtByXsl(final Input xsl, final String motive) throws IOException {
final XML xml = new XMLDocument(new IoCheckedText(new TextOf(xsl)).asString());
this.rule = new Xnav(xml.toString())
.element("xsl:stylesheet")
Expand Down Expand Up @@ -117,7 +117,9 @@ public Collection<Defect> defects(final XML xmir) {

@Override
public String motive() throws IOException {
return new IoCheckedText(new TextOf(this.doc)).asString();
return new DefaultResourceLoader()
.getResource(this.doc)
.getContentAsString(StandardCharsets.UTF_8);
}

/**
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/org/eolang/lints/PkByXsl.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,11 @@ private static Iterable<Lint<XML>> all() {
res ->
new LtByXsl(
new InputOf(res.getInputStream()),
new InputOf(
PkByXsl.XSL_PATTERN.matcher(
PkByXsl.LINTS_PATH.matcher(
res.getURL().toString()
).replaceAll("eolang/motives")
).replaceAll(".md")
)
PkByXsl.XSL_PATTERN.matcher(
PkByXsl.LINTS_PATH.matcher(
res.getURL().toString()
).replaceAll("eolang/motives")
).replaceAll(".md")
),
Arrays.asList(
new PathMatchingResourcePatternResolver().getResources(
Expand Down
Loading