Skip to content

Commit addb4c1

Browse files
committed
bug(objectionary#3199): fix saving
1 parent 5a7a673 commit addb4c1

File tree

8 files changed

+40
-24
lines changed

8 files changed

+40
-24
lines changed

eo-maven-plugin/src/main/java/org/eolang/maven/FpDefault.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
*/
55
package org.eolang.maven;
66

7+
import java.nio.charset.StandardCharsets;
78
import java.nio.file.Path;
89
import java.util.function.Supplier;
910
import org.cactoos.Func;
11+
import org.cactoos.Input;
12+
import org.cactoos.io.InputOf;
1013

1114
/**
1215
* Default footprint that covers all the scenarios of updating target
@@ -63,7 +66,15 @@ final class FpDefault extends FpEnvelope {
6366
final Supplier<String> hash,
6467
final Path tail
6568
) {
66-
this(new FpGenerated(content), base, semver, hash, tail);
69+
this(
70+
new FpGenerated(
71+
src -> new InputOf(content.apply(src))
72+
),
73+
base,
74+
semver,
75+
hash,
76+
tail
77+
);
6778
}
6879

6980
/**

eo-maven-plugin/src/main/java/org/eolang/maven/FpGenerated.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import java.io.IOException;
88
import java.nio.file.Path;
99
import org.cactoos.Func;
10-
import org.cactoos.scalar.ScalarOf;
10+
import org.cactoos.Input;
11+
import org.cactoos.func.UncheckedFunc;
1112

1213
/**
1314
* Footprint that saves content generated from lambda to the target file.
@@ -17,18 +18,18 @@ final class FpGenerated implements Footprint {
1718
/**
1819
* Content function.
1920
*/
20-
private final Func<Path, String> content;
21+
private final UncheckedFunc<Path, Input> content;
2122

2223
/**
2324
* Ctor.
24-
* @param content Content function
25+
* @param content Content as bytes
2526
*/
26-
FpGenerated(final Func<Path, String> content) {
27-
this.content = content;
27+
FpGenerated(final Func<Path, Input> content) {
28+
this.content = new UncheckedFunc<>(content);
2829
}
2930

3031
@Override
3132
public Path apply(final Path source, final Path target) throws IOException {
32-
return new Saved(new ScalarOf<>(this.content, source), target).value();
33+
return new Saved(this.content.apply(source), target).value();
3334
}
3435
}

eo-maven-plugin/src/main/java/org/eolang/maven/PlaceMojo.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66

77
import com.jcabi.log.Logger;
88
import java.io.IOException;
9-
import java.nio.charset.StandardCharsets;
109
import java.nio.file.Files;
1110
import java.nio.file.Path;
1211
import java.util.Collection;
1312
import java.util.Optional;
1413
import org.apache.maven.plugins.annotations.LifecyclePhase;
1514
import org.apache.maven.plugins.annotations.Mojo;
16-
import org.cactoos.bytes.BytesOf;
15+
import org.cactoos.io.InputOf;
1716
import org.cactoos.scalar.Unchecked;
1817

1918
/**
@@ -201,9 +200,7 @@ private void printLogInfoAboutBinary(final Path file) {
201200
private void placeBinary(final Path file) {
202201
final Path path = this.dir.relativize(file);
203202
try {
204-
final Footprint generated = new FpGenerated(
205-
src -> new String(new BytesOf(src).asBytes(), StandardCharsets.UTF_8)
206-
);
203+
final Footprint generated = new FpGenerated(InputOf::new);
207204
final Path target = new FpIfTargetExists(
208205
new FpFork(this.rewrite, generated, new FpIgnore()),
209206
generated

eo-maven-plugin/src/main/java/org/eolang/maven/PullMojo.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.util.function.Supplier;
1414
import org.apache.maven.plugins.annotations.LifecyclePhase;
1515
import org.apache.maven.plugins.annotations.Mojo;
16-
import org.cactoos.text.TextOf;
1716

1817
/**
1918
* Pull EO files from Objectionary.
@@ -136,7 +135,7 @@ private Path pulled(final String object, final Path base, final String hsh) thro
136135
"Pulling %s object from remote objectionary with hash %s",
137136
object, hsh
138137
);
139-
return new TextOf(this.objectionary.get(object)).asString();
138+
return this.objectionary.get(object);
140139
}
141140
);
142141
final Footprint both = new FpUpdateBoth(generated, che);

eo-maven-plugin/src/main/java/org/eolang/maven/Saved.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com.jcabi.log.Logger;
88
import java.io.IOException;
9+
import java.nio.charset.StandardCharsets;
910
import java.nio.file.Path;
1011
import org.cactoos.Input;
1112
import org.cactoos.Scalar;
@@ -15,7 +16,6 @@
1516
import org.cactoos.io.TeeInput;
1617
import org.cactoos.scalar.IoChecked;
1718
import org.cactoos.scalar.LengthOf;
18-
import org.cactoos.text.TextOf;
1919

2020
/**
2121
* Content saved to the file.
@@ -39,16 +39,16 @@ final class Saved implements Scalar<Path> {
3939
* @param target Path to save content to
4040
*/
4141
Saved(final String content, final Path target) {
42-
this(new InputOf(content), target);
42+
this(content.getBytes(StandardCharsets.UTF_8), target);
4343
}
4444

4545
/**
4646
* Ctor.
47-
* @param content Content as scalar
47+
* @param content Content as bytes
4848
* @param target Path to save content to
4949
*/
50-
Saved(final Scalar<String> content, final Path target) {
51-
this(new TextOf(content), target);
50+
Saved(final byte[] content, final Path target) {
51+
this(new InputOf(content), target);
5252
}
5353

5454
/**

eo-maven-plugin/src/main/java/org/eolang/maven/TranspileMojo.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.apache.maven.plugins.annotations.Parameter;
3434
import org.apache.maven.plugins.annotations.ResolutionScope;
3535
import org.cactoos.func.StickyFunc;
36+
import org.cactoos.io.InputOf;
3637
import org.cactoos.text.Joined;
3738
import org.eolang.parser.TrFull;
3839

@@ -259,7 +260,14 @@ private int javaGenerated(
259260
this, "Generated %[file]s (%[size]s) file from %[file]s (%[size]s)",
260261
tgt, tgt.toFile().length(), target, target.toFile().length()
261262
);
262-
return new Joined("", clazz.element("java").text().get()).asString();
263+
return new InputOf(
264+
new Joined(
265+
"",
266+
clazz.elements(Filter.withName("java")).map(
267+
java -> java.text().orElse("")
268+
).collect(Collectors.toList())
269+
)
270+
);
263271
}
264272
);
265273
final Footprint both = new FpUpdateBoth(generated, che);

eo-runtime/src/test/groovy/check-folders-numbering.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ List<String> allowed = [
1212
'1-parse',
1313
'2-shake',
1414
'4-pull',
15-
'5-resolve',
16-
'6-lint',
15+
'5-lint',
16+
'6-resolve',
1717
'7-pre',
1818
'8-transpile',
1919
'phi',

eo-runtime/src/test/groovy/check-target-files.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ List<String> expected = [
88
'eo/1-parse/org/eolang/fs/dir.xmir',
99
'eo/2-shake/org/eolang/error.xmir',
1010
'eo/2-shake/org/eolang/sys/os.xmir',
11-
'eo/6-lint/org/eolang/go.xmir',
11+
'eo/5-lint/org/eolang/go.xmir',
1212
'eo/8-transpile/org/eolang/malloc.xmir',
1313
'eo/phi/org/eolang/number.phi',
1414
'eo/unphi/org/eolang/number.xmir',
1515
'eo-test/1-parse/org/eolang/bool-tests.xmir',
1616
'eo-test/2-shake/org/eolang/go-tests.xmir',
17-
'eo-test/6-lint/org/eolang/dataized-tests.xmir',
17+
'eo-test/5-lint/org/eolang/dataized-tests.xmir',
1818
'eo-test/8-transpile/org/eolang/runtime-tests.xmir',
1919
'eo-test/phi/org/eolang/number-tests.phi',
2020
'eo-test/unphi/org/eolang/number-tests.xmir',

0 commit comments

Comments
 (0)