Skip to content

Commit

Permalink
fix(#44): output directory
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Jan 19, 2024
1 parent fa9f684 commit 762f2eb
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/it/benchmark-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ SOFTWARE.
</goals>
</execution>
</executions>
<configuration>
<ineo.outputDir>${project.basedir}/target/generated-output-sources/xmir</ineo.outputDir>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
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-output-sources/xmir/com/exam/BA.xmir')
assert file.exists()

true
3 changes: 3 additions & 0 deletions src/it/toy-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ SOFTWARE.
<goals>
<goal>fuse</goal>
</goals>
<configuration>
<outputDir>${project.basedir}/target/generated-output-sources/xmir</outputDir>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
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-output-sources/xmir/com/exam/BA.xmir')
assert file.exists()

true
28 changes: 24 additions & 4 deletions src/main/java/org/eolang/ineo/FuseMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,49 @@ 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-output-sources/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("Couldn't save file to output directory", 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 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 762f2eb

Please sign in to comment.