Skip to content
6 changes: 3 additions & 3 deletions eo-maven-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ one after another:
It's done by the `org.eolang.parser.EoSyntax` class in the `eo-parser` module. It takes
the source code in a plain text format and parses into XML document,
using [ANTLR4](https://www.antlr.org/) and [Xembly](https://www.xembly.org).
The output of the parser you can find in the `target/eo/parse` directory.
The output of the parser you can find in the `target/eo/1-parse` directory.
Parsed objects which are versioned (normally pulled from
[Objectionary](https://github.com/objectionary/home)) are cached in `.eo/parsed` folder.
[Objectionary](https://github.com/objectionary/home)) are cached in `.eo/1-parse` folder.

* **Optimization**.
There are a number of [XSL transformations](https://en.wikipedia.org/wiki/XSLT)
Expand All @@ -97,7 +97,7 @@ one after another:
The class `org.eolang.parser.Program` is responsible for making XSLT
transformations and the entire list of them is stored in the
`org.eolang.parser.Pack` class. Some of XLST files are sanity checks (or linters).
The output of each transformation you can find in the `target/eo/optimize` directory.
The output of each transformation you can find in the `target/eo/2-optimize` directory.

* **Compilation**.
The class `org.eolang.maven.TranspileMojo` in the `eo-maven-plugin` module is responsible
Expand Down
26 changes: 25 additions & 1 deletion eo-maven-plugin/src/main/java/org/eolang/maven/Unplace.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ final class Unplace {
*/
private final Path parent;

/**
* The file extension.
*/
private final String extension;

/**
* Ctor.
* @param dir The name of the parent dir
Expand All @@ -51,7 +56,26 @@ final class Unplace {
* @param dir The name of the parent dir
*/
Unplace(final Path dir) {
this(dir, ".eo$");
}

/**
* Ctor.
* @param dir The name of the parent dir
* @param extension The file extension
*/
Unplace(final File dir, final String extension) {
this(dir.toPath(), extension);
}

/**
* Main Ctor.
* @param dir The name of the parent dir
* @param extension The file extension
*/
Unplace(final Path dir, final String extension) {
this.parent = dir;
this.extension = extension;
}

/**
Expand All @@ -62,7 +86,7 @@ final class Unplace {
public String make(final Path file) {
return file.toString().substring(
this.parent.toString().length() + 1
).replaceAll(".eo$", "").replace(File.separator, ".");
).replaceAll(this.extension, "").replace(File.separator, ".");
Copy link
Member

Choose a reason for hiding this comment

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

@ArtemGet this looks pretty dangerous. What if this.extension will be equal to ( -- you will get runtime exception here. Try using Pattern.quote().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yegor256 Agreed, add Pattern.quote and tests.

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ public String description() {
);
}

/**
* The tojo phi.
* @return The phi.
*/
public Path phi() {
return Paths.get(this.attribute(ForeignTojos.Attribute.PHI));
}

/**
* The tojo hash.
* @return The hash.
Expand Down Expand Up @@ -204,6 +212,46 @@ public boolean notParsed() {
return res;
}

/**
* Check if the given tojo has not been parsed to phi-expression.
*
* @return True if the tojo has not been parsed to phi-expression.
*/
public boolean notPhied() {
boolean res = true;
if (this.delegate.exists(ForeignTojos.Attribute.PHI.getKey())) {
final Path phi = this.phi();
if (phi.toFile().lastModified() >= this.optimized().toFile().lastModified()) {
Logger.debug(
this, "Already executed xmir-to-phi: %s to %[file]s (it's newer than the XMIR)",
this.identifier(), phi
);
res = false;
}
}
return res;
}

/**
* Check if the given tojo has not been parsed to XMIR from phi-expression.
*
* @return True if the tojo has not been parsed from XMIR to phi-expression.
*/
public boolean notUnphied() {
boolean res = true;
if (this.delegate.exists(ForeignTojos.Attribute.XMIR.getKey())) {
final Path xmir = this.xmir();
if (xmir.toFile().lastModified() >= this.phi().toFile().lastModified()) {
Logger.debug(
this, "Already executed phi-to-xmir: %s to %[file]s (it's newer than the phi)",
this.identifier(), xmir
);
res = false;
}
}
return res;
}

/**
* Checks if tojo has hash.
* @return True if has hash, false otherwise.
Expand Down Expand Up @@ -345,6 +393,16 @@ public ForeignTojo withScope(final String scope) {
return this;
}

/**
* Set the phi.
* @param phi The phi.
* @return The tojo itself.
*/
public ForeignTojo withPhi(final Path phi) {
this.delegate.set(ForeignTojos.Attribute.PHI.getKey(), phi);
return this;
}

/**
* Return the scope of the tojo.
* @return The scope.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,12 @@ enum Attribute {
/**
* Git SHA of the object in the {@code objectionary/home}.
*/
HASH("hash");
HASH("hash"),

/**
* Absolute path of the parsed from XMIR to phi-expression file.
*/
PHI("phi");

/**
* Attribute name.
Expand Down
Loading