Skip to content

Commit

Permalink
fix(objectionary#2938): exception
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Mar 15, 2024
1 parent 9ecb995 commit 80f9c2a
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions eo-maven-plugin/src/main/java/org/eolang/maven/PhiMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
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 @@ -124,7 +125,19 @@ public void exec() {
String.format(".%s", PhiMojo.EXT)
)
);
home.save(PhiMojo.translated(train, xml), relative);
try {
home.save(PhiMojo.translated(train, xml), relative);
} catch (final ImpossibleToPhiTranslationException exception) {
Logger.error(
this,
"XML is not translatable to phi:\n%s",
xml.toString()
);
throw new IllegalStateException(
String.format("Couldn't translate %s to phi", processed),
exception
);
}
Logger.info(
this,
"Translated to phi: %[file]s (%[size]s) -> %[file]s (%[size]s)",
Expand Down Expand Up @@ -158,12 +171,29 @@ count, new Rel(this.phiInputDir), new Rel(this.phiOutputDir)
* @param xmir Text of xmir
* @return Translated xmir
*/
private static String translated(final Train<Shift> train, final XML xmir) {
return new Xsline(
private static String translated(final Train<Shift> train, final XML xmir) throws ImpossibleToPhiTranslationException {
final List<String> translated = new Xsline(
train.with(new StClasspath("/org/eolang/maven/phi/to-phi.xsl"))
)
.pass(xmir)
.xpath("phi/text()")
.get(0);
).pass(xmir).xpath("phi/text()");
if (translated.isEmpty()) {
throw new ImpossibleToPhiTranslationException(
"Xpath 'phi/text()' is not found in translated XMIR"
);
}
return translated.get(0);
}

/**
* Exception which indicates that translation to phi can't be processed.
* @since 0.36.0
*/
static class ImpossibleToPhiTranslationException extends Exception {
/**
* Ctor.
* @param cause Cause of the exception.
*/
ImpossibleToPhiTranslationException(final String cause) {
super(cause);
}
}
}

0 comments on commit 80f9c2a

Please sign in to comment.