Skip to content

Commit

Permalink
Merge branch 'master' into 3160-enable-pmd-in-eo-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
c71n93 committed Jun 24, 2024
2 parents df95e60 + bf1c21f commit ba2a9e3
Show file tree
Hide file tree
Showing 34 changed files with 604 additions and 319 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: teatimeguest/setup-texlive-action@v3.2.1
- uses: teatimeguest/setup-texlive-action@v3.3.0
with:
update-all-packages: true
packages: scheme-basic geometry xcolor naive-ebnf microtype etoolbox
Expand Down
51 changes: 19 additions & 32 deletions .github/workflows/license.yml → .github/workflows/copyrights.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,42 +20,29 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
---
name: license
on:
name: copyrights
'on':
push:
pull_request:
jobs:
license:
copyrights:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: yegor256/[email protected]
with:
fetch-depth: 0
- run: |
set -e
find . -type f \( \
-name "LICENSE.*" \
-o -name "*.sh" \
-o -name "*.yml" \
-o -name "*.yaml" \
-o -name "*.eo" \
-o -name "*.xmir" \
-o -name "*.xml" \
-o -name "*.xsl" \
-o -name "*.xsd" \
-o -name "*.ini" \
-o -name "*.java" \
-o -name "*.g4" \
-o -name "*.properties" \
-o -name "*.groovy" \) > files.txt
header="Copyright (c) 2016-$(date +%Y) Objectionary.com"
failed="false"
while IFS= read -r file; do
if ! grep -q "$header" "$file"; then
failed="true"
echo "No license in: $file"
fi
done < files.txt
if [ "${failed}" == "true" ]; then
exit 1
fi
globs: >-
**/LICENSE.txt
**/*.sh
**/*.yml
**/*.yaml
**/*.eo
**/*.xmir
**/*.xml
**/*.xsl
**/*.xsd
**/*.ini
**/*.java
**/*.g4
**/*.properties
**/*.groovy
2 changes: 1 addition & 1 deletion .github/workflows/daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: teatimeguest/setup-texlive-action@v3.2.1
- uses: teatimeguest/setup-texlive-action@v3.3.0
with:
update-all-packages: true
packages: scheme-basic geometry xcolor naive-ebnf microtype etoolbox
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ebnf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- run: |
sudo apt-get update
sudo apt-get -y install ghostscript imagemagick texlive-extra-utils pdf2svg inkscape
- uses: teatimeguest/setup-texlive-action@v3.2.1
- uses: teatimeguest/setup-texlive-action@v3.3.0
with:
update-all-packages: true
packages: scheme-basic geometry xcolor naive-ebnf microtype etoolbox
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sonar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: teatimeguest/setup-texlive-action@v3.2.1
- uses: teatimeguest/setup-texlive-action@v3.3.0
with:
update-all-packages: true
packages: scheme-basic geometry xcolor naive-ebnf microtype etoolbox
- uses: actions/setup-java@v4
with:
java-version: 20
java-version: 17
distribution: 'zulu'
- uses: actions/cache@v4
with:
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/trufflehog-oss.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# The MIT License (MIT)
#
# Copyright (c) 2016-2024 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.
---

name: trufflehog-oss
'on':
push:
branches:
- master
pull_request:
branches:
- master
jobs:
trufflehog:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Secret Scanning
uses: trufflesecurity/trufflehog@main
with:
extra_args: --only-verified
4 changes: 2 additions & 2 deletions eo-maven-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ create a file `pom.xml` with this content (it's just a sample):
<plugin>
<groupId>org.eolang</groupId>
<artifactId>eo-maven-plugin</artifactId>
<version>0.38.1</version>
<version>0.38.4</version>
<executions>
<execution>
<goals>
Expand Down Expand Up @@ -156,7 +156,7 @@ execution within `eo-maven-plugin/pom.xml`:
...
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<version>0.38.1</version>
<version>0.38.4</version>
<configuration>
<skipInstallation>true</skipInstallation>
<skipInvocation>true</skipInvocation>
Expand Down
10 changes: 5 additions & 5 deletions eo-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,25 @@ SOFTWARE.
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.9.6</version>
<version>3.9.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-model</artifactId>
<version>3.9.6</version>
<version>3.9.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.9.6</version>
<version>3.9.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.13.0</version>
<version>3.13.1</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -126,7 +126,7 @@ SOFTWARE.
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>3.9.6</version>
<version>3.9.8</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
97 changes: 71 additions & 26 deletions eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import net.sf.saxon.expr.instruct.TerminationException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
Expand Down Expand Up @@ -87,6 +88,21 @@ public final class PhiMojo extends SafeMojo {
)
private File phiOutputDir;

/**
* Whether {@link PhiMojo} should fail on critical errors or not.
* @checkstyle MemberNameCheck (10 lines)
*/
@Parameter(property = "eo.phiFailOnCritical", required = true, defaultValue = "true")
@SuppressWarnings({"PMD.ImmutableField", "PMD.LongVariable"})
private boolean phiFailOnCritical = true;

/**
* Whether {@link PhiMojo} should skip XMIRs that failed on critical errors.
* @checkstyle MemberNameCheck (10 lines)
*/
@Parameter(property = "eo.phiSkipFailed", required = true, defaultValue = "false")
private boolean phiSkipFailed;

/**
* Pass XMIR to Optimizations train or not.
* This flag is used for test in order not to optimize XMIR twice:
Expand All @@ -100,12 +116,7 @@ public final class PhiMojo extends SafeMojo {
@Override
public void exec() {
final Home home = new HmBase(this.phiOutputDir);
final Train<Shift> train;
if (this.phiOptimize) {
train = new ParsingTrain();
} else {
train = new TrDefault<>();
}
final Train<Shift> train = this.train();
final int count = new SumOf(
new Threads<>(
Runtime.getRuntime().availableProcessors(),
Expand All @@ -127,8 +138,18 @@ public void exec() {
String.format(".%s", PhiMojo.EXT)
)
);
int amount;
try {
home.save(PhiMojo.translated(train, xml), relative);
Logger.info(
this,
"Translated to phi: %[file]s (%[size]s) -> %[file]s (%[size]s)",
processed,
xmir.toFile().length(),
relative,
this.phiOutputDir.toPath().resolve(relative).toFile().length()
);
amount = 1;
} catch (final ImpossibleToPhiTranslationException exception) {
Logger.debug(
this,
Expand All @@ -139,16 +160,20 @@ public void exec() {
String.format("Couldn't translate %s to phi", processed),
exception
);
} catch (final IllegalArgumentException exception) {
if (exception.getCause() instanceof TerminationException
&& this.phiSkipFailed) {
Logger.info(
this,
"%[file]s failed on critical error, but skipped because phiSkipFailed=true",
processed
);
amount = 0;
} else {
throw exception;
}
}
Logger.info(
this,
"Translated to phi: %[file]s (%[size]s) -> %[file]s (%[size]s)",
processed,
xmir.toFile().length(),
relative,
this.phiOutputDir.toPath().resolve(relative).toFile().length()
);
return 1;
return amount;
},
new Walk(this.phiInputDir.toPath())
)
Expand All @@ -167,6 +192,36 @@ count, new Rel(this.phiInputDir), new Rel(this.phiOutputDir)
}
}

/**
* Build transformations train depends on flags.
* @return Transformations train
*/
private Train<Shift> train() {
final Train<Shift> train;
if (this.phiOptimize) {
train = new ParsingTrain();
} else {
train = new TrDefault<>();
}
final Train.Temporary<Shift> dependent;
if (this.phiFailOnCritical) {
dependent = new TrClasspath<>(
"/org/eolang/parser/fail-on-critical.xsl",
"/org/eolang/maven/phi/to-phi.xsl"
);
} else {
dependent = new TrClasspath<>("/org/eolang/maven/phi/to-phi.xsl");
}
return new TrJoined<>(
train,
new TrClasspath<>(
"/org/eolang/parser/critical-errors/duplicate-names.xsl",
"/org/eolang/maven/phi/incorrect-inners.xsl"
).back(),
dependent.back()
);
}

/**
* Translate given xmir to phi calculus expression.
* @param train Train that optimize and translates given xmir
Expand All @@ -176,17 +231,7 @@ count, new Rel(this.phiInputDir), new Rel(this.phiOutputDir)
*/
private static String translated(final Train<Shift> train, final XML xmir)
throws ImpossibleToPhiTranslationException {
final XML translated = new Xsline(
new TrJoined<>(
train,
new TrClasspath<>(
"/org/eolang/parser/critical-errors/duplicate-names.xsl",
"/org/eolang/maven/phi/incorrect-inners.xsl",
"/org/eolang/parser/fail-on-critical.xsl",
"/org/eolang/maven/phi/to-phi.xsl"
).back()
)
).pass(xmir);
final XML translated = new Xsline(train).pass(xmir);
Logger.debug(PhiMojo.class, "XML after translation to phi:\n%s", translated);
final List<String> phi = translated.xpath("phi/text()");
if (phi.isEmpty()) {
Expand Down
14 changes: 12 additions & 2 deletions eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,18 @@ public void exec() throws IOException {
)
);
names.add(name);
tojo.withSource(this.pull(name).toAbsolutePath())
.withHash(new ChNarrow(name.hash()));
try {
tojo.withSource(this.pull(name).toAbsolutePath())
.withHash(new ChNarrow(name.hash()));
} catch (final IOException exception) {
throw new IOException(
String.format(
"Failed to pull object discovered at %s",
tojo.discoveredAt()
),
exception
);
}
}
Logger.info(
this,
Expand Down
Loading

3 comments on commit ba2a9e3

@0pdd
Copy link

@0pdd 0pdd commented on ba2a9e3 Jun 25, 2024

Choose a reason for hiding this comment

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

Puzzle 3160-4ce0c9ff discovered in eo-runtime/pom.xml) and submitted as #3238. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on ba2a9e3 Jun 25, 2024

Choose a reason for hiding this comment

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

Puzzle 3160-01d3ed77 discovered in eo-runtime/src/main/java/org/eolang/BytesOf.java) and submitted as #3239. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link

@0pdd 0pdd commented on ba2a9e3 Jun 25, 2024

Choose a reason for hiding this comment

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

Puzzle 3160-edcd4ffd discovered in eo-runtime/src/main/java/org/eolang/Data.java) and submitted as #3240. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.