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

feat(#65): get lints for gh-pages in runtime #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
62 changes: 62 additions & 0 deletions .github/workflows/createlintlist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2025 Objectionary.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
---
'on':
push:
branches:
- master

jobs:
create_lint_list:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 21
- run: |
GH_PAGES_BRANCH=gh-pages

mvn clean
mvn package -DskipTests

JAR_PREFIX="jar:file:$(readlink -f target/printAll.jar)\!/org/eolang/motives/"

MOTIVES=$(java -jar target/printAll.jar | cut -c ${#JAR_PREFIX}-)

jar xvf target/printAll.jar /org/eolang/motives/

cd org/eolang/motives/

git init
git config user.name 'Marat-Tim'
git config user.email 'rurikcat@gmail.com'
git checkout -b $GH_PAGES_BRANCH
echo "$MOTIVES" | xargs -n 1 git add || true
echo "${MOTIVES//\(.*\)/[\1](\1)\n}" > README.md
git add README.md

git commit -m "test"
REPO=https://Marat-Tim:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git remote add origin $REPO
git push --force origin $GH_PAGES_BRANCH
31 changes: 31 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ SOFTWARE.
<version>1.37</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.16</version>
</dependency>
</dependencies>
<profiles>
<profile>
Expand Down Expand Up @@ -386,6 +391,32 @@ SOFTWARE.
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>printAll</finalName>
<archive>
<manifest>
<mainClass>
org.eolang.lints.PrintAllLints
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>pw.krejci</groupId>
<artifactId>jmh-maven-plugin</artifactId>
Expand Down
81 changes: 81 additions & 0 deletions src/main/java/org/eolang/lints/JavaLint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2025 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.eolang.lints;

import com.jcabi.xml.XML;
import io.github.secretx33.resourceresolver.ClassPathResource;
import java.io.IOException;
import java.util.Collection;
import java.util.Locale;
import org.cactoos.text.FormattedText;
import org.cactoos.text.IoCheckedText;

/**
* Override {@link Lint#motive()} method. Overridden method will return path to the file on the
* classpath with the same name as the class of the decorated object but in camel-case.
*
* @since 0.0.0
*/
public final class JavaLint implements Lint<XML> {
/**
* Decorated object.
*/
private final Lint<XML> lint;

public JavaLint(final Lint<XML> lint) {
this.lint = lint;
}

@Override
public String name() {
return this.lint.name();
}

@Override
public Collection<Defect> defects(final XML entity) throws IOException {
return this.lint.defects(entity);
}

@Override
public String motive() throws IOException {
final String classname = this.lint.getClass()
.getSimpleName()
.replaceAll("([a-z0-9])([A-Z])", "$1-$2")
.toLowerCase(Locale.ROOT);
String packagename = this.lint.getClass().getPackage().getName();
packagename = packagename.substring(packagename.lastIndexOf('.') + 1);
return new ClassPathResource(
new IoCheckedText(
new FormattedText(
"org/eolang/motives/%s/%s.md",
packagename,
classname
)
).asString()
)
.getURL()
.toString();
}

}
12 changes: 8 additions & 4 deletions src/main/java/org/eolang/lints/PkMono.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
package org.eolang.lints;

import com.jcabi.xml.XML;
import java.util.Arrays;
import javax.annotation.concurrent.ThreadSafe;
import org.cactoos.iterable.IterableEnvelope;
import org.cactoos.iterable.IterableOf;
import org.cactoos.iterable.Joined;
import org.cactoos.iterable.Mapped;
import org.cactoos.iterable.Shuffled;
import org.eolang.lints.comments.LtAsciiOnly;
import org.eolang.lints.misc.LtTestNotVerb;
Expand All @@ -51,9 +52,12 @@ final class PkMono extends IterableEnvelope<Lint<XML>> {
new Shuffled<>(
new Joined<Lint<XML>>(
new PkByXsl(),
Arrays.asList(
new LtAsciiOnly(),
new LtTestNotVerb()
new Mapped<Lint<XML>>(
JavaLint::new,
new IterableOf<>(
new LtAsciiOnly(),
new LtTestNotVerb()
)
)
)
)
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/org/eolang/lints/PrintAllLints.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2025 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.eolang.lints;

import com.jcabi.xml.XML;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
* Print all lints.
*
* @since 0.0.0
*/
public final class PrintAllLints {
private PrintAllLints() {
}

@SuppressWarnings({"PMD.ProhibitPublicStaticMethods", "PMD.AvoidThrowingRawExceptionTypes"})
public static void main(final String[] args) {
final List<Lint<XML>> alllints = new ArrayList<>(50);
new PkMono().forEach(alllints::add);
alllints.stream()
.map(
lint -> {
try {
return lint.motive();
} catch (final IOException exception) {
throw new RuntimeException(exception);
}
}
)
.forEach(System.out::println);
}

}
5 changes: 1 addition & 4 deletions src/main/java/org/eolang/lints/comments/LtAsciiOnly.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@
* For now we just reusing object line number (via @line), which is not correct
* for specifying on which line of the program comment is located. This issue
* can be solved after <a href="https://github.com/objectionary/eo/issues/3536">this one</a>.
* @todo #19:45min Create Lint envelope called `JavaLint` that will fetch motive from
* Markdown file based on the lint's name (Java class name) and lint's dimension
* (Java package name, e.g. `comments`).
* @checkstyle StringLiteralsConcatenationCheck (30 lines)
*/
public final class LtAsciiOnly implements Lint<XML> {
Expand Down Expand Up @@ -90,7 +87,7 @@ public String name() {
public String motive() throws IOException {
return new IoCheckedText(
new TextOf(
new ResourceOf("org/eolang/motives/comments/ascii-only.md")
new ResourceOf("org/eolang/motives/comments/lt-ascii-only.md")
)
).asString();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/eolang/lints/misc/LtTestNotVerb.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public String motive() throws IOException {
return new UncheckedText(
new TextOf(
new ResourceOf(
"org/eolang/motives/misc/test-object-is-not-verb-in-singular.md"
"org/eolang/motives/misc/lt-test-not-verb.md"
)
)
).asString();
Expand Down
Loading