Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Dec 6, 2023
2 parents 1c8472b + 454d3be commit 015f738
Show file tree
Hide file tree
Showing 15 changed files with 193 additions and 193 deletions.
4 changes: 2 additions & 2 deletions eo-maven-plugin/src/it/custom_goals/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
*/
[
'target/eo/5-resolve',
'target/eo/6-pre',
'target/eo/7-transpile',
'target/eo/7-pre',
'target/eo/8-transpile',
].each { assert !new File(basedir, it).exists() }

true
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ public final class AssembleMojo extends SafeMojo {

/**
* Whether we should fail on error.
* @checkstyle MemberNameCheck (7 lines)
* @checkstyle MemberNameCheck (11 lines)
* @since 0.23.0
* @todo #2443:90min Remove the following failOnError flag. Now we
* have already got rid from it in {@link OptimizeMojo} and {@link VerifyMojo}.
* We need to make failOnError the behaviour default.
*/
@SuppressWarnings("PMD.ImmutableField")
@Parameter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public final class BinarizeParseMojo extends SafeMojo {
public void exec() throws IOException {
new File(this.targetDir.toPath().resolve("Lib/").toString()).mkdirs();
for (final ForeignTojo tojo : this.scopedTojos().withOptimized()) {
final Path file = tojo.shaken();
final Path file = tojo.verified();
this.getFFIs(new XMLDocument(file))
.forEach(FFINode::generateUnchecked);
}
Expand Down
38 changes: 1 addition & 37 deletions eo-maven-plugin/src/main/java/org/eolang/maven/OptimizeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
package org.eolang.maven;

import com.jcabi.log.Logger;
import com.yegor256.xsline.TrDefault;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collection;
Expand Down Expand Up @@ -87,31 +86,6 @@ public final class OptimizeMojo extends SafeMojo {
@Parameter(property = "eo.trackOptimizationSteps", required = true, defaultValue = "false")
private boolean trackOptimizationSteps;

/**
* Whether we should fail on error.
*
* @checkstyle MemberNameCheck (7 lines)
* @since 0.23.0
*/
@SuppressWarnings("PMD.ImmutableField")
@Parameter(
property = "eo.failOnError",
defaultValue = "true")
private boolean failOnError = true;

/**
* Whether we should fail on warn.
*
* @checkstyle MemberNameCheck (10 lines)
*/
@SuppressWarnings("PMD.ImmutableField")
@Parameter(
property = "eo.failOnWarning",
required = true,
defaultValue = "false"
)
private boolean failOnWarning;

@Override
public void exec() throws IOException {
final Collection<ForeignTojo> tojos = this.scopedTojos().withXmir();
Expand Down Expand Up @@ -157,17 +131,7 @@ private Optimization optimization() {
} else {
opt = new OptTrain(new ParsingTrain());
}
if (this.failOnError) {
opt = new OptTrain(opt, "/org/eolang/parser/fail-on-errors.xsl");
}
if (this.failOnWarning) {
opt = new OptTrain(opt, "/org/eolang/parser/fail-on-warnings.xsl");
}
if (this.failOnError) {
opt = new OptTrain(opt, "/org/eolang/parser/fail-on-critical.xsl");
} else {
opt = new OptTrain(opt, new TrDefault<>());
}
opt = new OptTrain(opt, "/org/eolang/parser/fail-on-critical.xsl");
return opt;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,15 @@
@SuppressWarnings("PMD.LongVariable")
public final class TranspileMojo extends SafeMojo {

/**
* The directory where to put pre-transpile files.
*/
public static final String PRE = "7-pre";

/**
* The directory where to transpile to.
*/
public static final String DIR = "7-transpile";
public static final String DIR = "8-transpile";

/**
* Extension for compiled sources in XMIR format (XML).
Expand Down Expand Up @@ -104,11 +109,6 @@ public final class TranspileMojo extends SafeMojo {
*/
private static final Pattern JAVA_EXT = Pattern.compile(".java", Pattern.LITERAL);

/**
* The directory where to put pre-transpile files.
*/
private static final String PRE = "6-pre";

/**
* Target directory.
* @checkstyle MemberNameCheck (7 lines)
Expand Down Expand Up @@ -185,7 +185,7 @@ public void exec() throws IOException {
*/
private int transpile(final ForeignTojo tojo) throws IOException {
final int saved;
final Path file = tojo.shaken();
final Path file = tojo.verified();
final XML input = new XMLDocument(file);
final String name = input.xpath("/program/@name").get(0);
final Place place = new Place(name);
Expand Down
65 changes: 55 additions & 10 deletions eo-maven-plugin/src/main/java/org/eolang/maven/VerifyMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,33 @@
*/
package org.eolang.maven;

import com.jcabi.log.Logger;
import com.yegor256.xsline.TrDefault;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collection;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.cactoos.iterable.Filtered;
import org.cactoos.map.MapEntry;
import org.cactoos.map.MapOf;
import org.eolang.maven.optimization.OptTrain;
import org.eolang.maven.optimization.Optimization;
import org.eolang.maven.tojos.ForeignTojo;

/**
* Mojo that checks errors and warnings after "assemble" phase.
*
* @since 0.31.0
* @todo #1708:30min Implement VerifyMojo. VerifyMojo should check all errors
* and critical errors in xmir after {@link AssembleMojo} is finished. Also if
* {@code failOnWarning} flag is set to true - mojo should check warnings. When
* mojo is implemented - need to remove "failOnError" flag from
* {@link OptimizeMojo} and put "verify" step right after "assemble" in all
* pom.xml files
*/
@Mojo(
name = "verify",
defaultPhase = LifecyclePhase.PROCESS_SOURCES,
threadSafe = true
)
public final class VerifyMojo extends SafeMojo {

/**
* Whether we should fail on warning.
*
Expand All @@ -60,11 +65,51 @@ public final class VerifyMojo extends SafeMojo {

@Override
void exec() throws IOException {
throw new UnsupportedOperationException(
String.format(
"The VerifyMojo is not implemented yet, failOnWarning is %s",
this.failOnWarning
final Collection<ForeignTojo> tojos = this.scopedTojos().withXmir();
final int total = new OptimizedTojos(
new Filtered<>(
ForeignTojo::notVerified,
tojos
),
this.optimization(),
new OptimizationTask(
new MapOf<String, Path>(
new MapEntry<>(OptimizationFolder.TARGET.key(), this.targetDir.toPath()),
new MapEntry<>(OptimizationFolder.CACHE.key(), this.cache)
),
new MapOf<String, String>(
new MapEntry<>(OptimizationFolder.TARGET.key(), "6-verify"),
new MapEntry<>(OptimizationFolder.CACHE.key(), "verified")
),
ForeignTojo::withVerified,
ForeignTojo::shaken
)
).count();
if (total > 0) {
Logger.info(
this,
"Verified %d out of %d XMIR program(s)", total,
tojos.size()
);
} else {
Logger.debug(this, "No XMIR programs out of %d verify", tojos.size());
}
}

/**
* Verifying optimizations for tojos.
*
* @return Verifying optimizations
*/
private Optimization optimization() {
Optimization opt = new OptTrain(
new OptTrain(new TrDefault<>()),
"/org/eolang/parser/fail-on-errors.xsl"
);
if (this.failOnWarning) {
opt = new OptTrain(opt, "/org/eolang/parser/fail-on-warnings.xsl");
}
return opt;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ public Path optimized() {
return Paths.get(this.delegate.get(ForeignTojos.Attribute.OPTIMIZED.key()));
}

/**
* The tojo verified xmir.
* @return The verified xmir.
*/
public Path verified() {
return Paths.get(this.delegate.get(ForeignTojos.Attribute.VERIFIED.key()));
}

/**
* The tojo shaken xmir.
* @return The shaken xmir.
Expand Down Expand Up @@ -170,6 +178,27 @@ public boolean notShaken() {
return res;
}

/**
* Checks if tojo was not already verified.
*
* @return True if optimization is required, false otherwise.
*/
public boolean notVerified() {
final Path src = this.xmir();
boolean res = true;
if (this.delegate.exists(ForeignTojos.Attribute.VERIFIED.key())) {
final Path tgt = this.verified();
if (tgt.toFile().lastModified() >= src.toFile().lastModified()) {
Logger.debug(
this, "Already verified %s to %s",
new Rel(src), new Rel(tgt)
);
res = false;
}
}
return res;
}

/**
* Check if the given tojo has not been parsed.
*
Expand Down Expand Up @@ -261,6 +290,16 @@ public ForeignTojo withShaken(final Path xmir) {
return this;
}

/**
* Set the verified xmir.
* @param xmir The verified xmir.
* @return The tojo itself.
*/
public ForeignTojo withVerified(final Path xmir) {
this.delegate.set(ForeignTojos.Attribute.VERIFIED.key(), xmir.toString());
return this;
}

/**
* Set the eo path.
* @param source The eo path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,11 @@ enum Attribute {
*/
SHAKEN("shaken"),

/**
* Path to the verified xmir file.
*/
VERIFIED("verified"),

/**
* Absolute location of SODG file.
*/
Expand Down
3 changes: 3 additions & 0 deletions eo-maven-plugin/src/test/java/org/eolang/maven/FakeMaven.java
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ public Iterator<Class<? extends AbstractMojo>> iterator() {
ParseMojo.class,
OptimizeMojo.class,
ShakeMojo.class,
VerifyMojo.class,
TranspileMojo.class
).iterator();
}
Expand All @@ -672,6 +673,7 @@ public Iterator<Class<? extends AbstractMojo>> iterator() {
ParseMojo.class,
OptimizeMojo.class,
ShakeMojo.class,
VerifyMojo.class,
BinarizeMojo.class
).iterator();
}
Expand All @@ -690,6 +692,7 @@ public Iterator<Class<? extends AbstractMojo>> iterator() {
ParseMojo.class,
OptimizeMojo.class,
ShakeMojo.class,
VerifyMojo.class,
BinarizeParseMojo.class
).iterator();
}
Expand Down
Loading

2 comments on commit 015f738

@0pdd
Copy link

@0pdd 0pdd commented on 015f738 Dec 6, 2023

Choose a reason for hiding this comment

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

Puzzle 1708-536ee550 disappeared from eo-maven-plugin/src/main/java/org/eolang/maven/VerifyMojo.java), that's why I closed #2443. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link

@0pdd 0pdd commented on 015f738 Dec 6, 2023

Choose a reason for hiding this comment

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

Puzzle 2443-427f9946 discovered in eo-maven-plugin/src/main/java/org/eolang/maven/AssembleMojo.java) and submitted as #2678. 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.