Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jan 19, 2024
2 parents 0905683 + 0b5e7c5 commit c7c1e19
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/it/benchmark-example/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import groovy.xml.XmlSlurper

file = new File(basedir, 'target/generated-sources/xmir/com/exam/BA.xmir')
file = new File(basedir, 'target/generated-sources/fused-xmir/com/exam/BA.xmir')
assert file.exists()

true
2 changes: 1 addition & 1 deletion src/it/toy-example/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import groovy.xml.XmlSlurper

file = new File(basedir, 'target/generated-sources/xmir/com/exam/BA.xmir')
file = new File(basedir, 'target/generated-sources/fused-xmir/com/exam/BA.xmir')
assert file.exists()

true
33 changes: 28 additions & 5 deletions src/main/java/org/eolang/ineo/FuseMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,52 @@ public final class FuseMojo extends AbstractMojo {
* @checkstyle MemberNameCheck (10 lines)
*/
@Parameter(
property = "sourcesDir",
property = "ineo.sourcesDir",
required = true,
defaultValue = "${project.build.directory}/generated-sources/xmir"
)
private File sourcesDir;

/**
* Output directory.
* @checkstyle MemberNameCheck (10 lines)
*/
@Parameter(
property = "ineo.outputDir",
required = true,
defaultValue = "${project.build.directory}/generated-sources/fused-xmir"
)
private File outputDir;

@Override
public void execute() {
Logger.info(this, "Processing files in %s", this.sourcesDir);
for (final Path file : new FilesOf(this.sourcesDir)) {
Logger.info(this, "Processing %s", file);
final XML before = new XMLDocumentOf(file);
final XML after = FuseMojo.TRANSFORMATION.transform(before);
if (!before.equals(after)) {
final Path path = this.outputDir.toPath().resolve(
this.sourcesDir.toPath().relativize(file)
);
if (before.equals(after)) {
try {
new Saved(before, path).value();
} catch (final IOException ex) {
throw new IllegalStateException(
String.format("Couldn't rewrite XMIR to output directory: %s", path),
ex
);
}
} else {
Logger.info(this, "Found fuse optimization in %s", file.getFileName());
try {
final String pckg = this.sourcesDir.toPath().relativize(file).toString()
.replace(String.format("%s%s", File.separator, file.getFileName()), "");
final Path generated = this.sourcesDir.toPath().resolve(
final Path generated = this.outputDir.toPath().resolve(
String.join(File.separator, pckg, "BA.xmir")
);
new Home(
new Saved(after, file),
new Saved(after, path),
new Saved(
new XMLDocument(
new Xembler(
Expand All @@ -112,7 +135,7 @@ public void execute() {
).save();
Logger.info(this, "New XMIR was generated: %s", generated);
} catch (final IOException ex) {
throw new IllegalStateException("Couldn't save file after transformation", ex);
throw new IllegalStateException("Couldn't save XMIR after transformation", ex);
} catch (final ImpossibleModificationException ex) {
throw new IllegalStateException("Couldn't transform fused XMIR", ex);
}
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/eolang/ineo/Saved.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.eolang.ineo;

import com.jcabi.log.Logger;
import com.jcabi.xml.XML;
import java.io.IOException;
import java.nio.file.Path;
Expand Down Expand Up @@ -114,9 +115,12 @@ private Saved(final Func<Path, Long> func, final Scalar<Path> pth) {
public Long value() throws IOException {
try {
return new IoChecked<>(
() -> this.origin.apply(
this.path.value()
)
() -> {
final Path file = this.path.value();
final long size = this.origin.apply(file);
Logger.info(this, "Written file: %s", file);
return size;
}
).value();
} catch (final IOException ex) {
throw new IOException(
Expand Down

0 comments on commit c7c1e19

Please sign in to comment.