Skip to content

Commit 93682cc

Browse files
committed
bug(objectionary#3199): build
1 parent b6fc209 commit 93682cc

File tree

8 files changed

+39
-122
lines changed

8 files changed

+39
-122
lines changed

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

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

7-
import java.io.IOException;
87
import java.nio.file.Path;
98
import org.cactoos.BiFunc;
109
import org.cactoos.func.UncheckedBiFunc;
@@ -14,22 +13,7 @@
1413
* condition.
1514
* @since 0.41
1615
*/
17-
final class FpFork implements Footprint {
18-
/**
19-
* Lazy condition.
20-
*/
21-
private final UncheckedBiFunc<Path, Path, Boolean> condition;
22-
23-
/**
24-
* First wrapped footprint.
25-
*/
26-
private final Footprint first;
27-
28-
/**
29-
* Second wrapped footprint.
30-
*/
31-
private final Footprint second;
32-
16+
final class FpFork extends FpEnvelope {
3317
/**
3418
* Ctor.
3519
* @param condition Condition as boolean
@@ -49,19 +33,16 @@ final class FpFork implements Footprint {
4933
FpFork(
5034
final BiFunc<Path, Path, Boolean> condition, final Footprint first, final Footprint second
5135
) {
52-
this.condition = new UncheckedBiFunc<>(condition);
53-
this.first = first;
54-
this.second = second;
55-
}
56-
57-
@Override
58-
public Path apply(final Path source, final Path target) throws IOException {
59-
final Footprint footprint;
60-
if (this.condition.apply(source, target)) {
61-
footprint = this.first;
62-
} else {
63-
footprint = this.second;
64-
}
65-
return footprint.apply(source, target);
36+
super(
37+
(src, tgt) -> {
38+
final Footprint footprint;
39+
if (new UncheckedBiFunc<>(condition).apply(src, tgt)) {
40+
footprint = first;
41+
} else {
42+
footprint = second;
43+
}
44+
return footprint.apply(src, tgt);
45+
}
46+
);
6647
}
6748
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ private static String version(
169169
final List<Node> parsed
170170
) throws FileNotFoundException {
171171
final Node node;
172-
if (!parsed.isEmpty()) {
173-
node = parsed.get(0);
174-
} else {
172+
if (parsed.isEmpty()) {
175173
node = new XMLDocument(target).inner();
174+
} else {
175+
node = parsed.get(0);
176176
}
177177
return new Xnav(node)
178178
.element("program")

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

+9-68
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.jcabi.log.Logger;
88
import java.io.File;
99
import java.io.IOException;
10+
import java.nio.charset.StandardCharsets;
1011
import java.nio.file.Files;
1112
import java.nio.file.Path;
1213
import java.util.Arrays;
@@ -15,6 +16,7 @@
1516
import java.util.Optional;
1617
import org.apache.maven.plugins.annotations.LifecyclePhase;
1718
import org.apache.maven.plugins.annotations.Mojo;
19+
import org.cactoos.bytes.BytesOf;
1820
import org.cactoos.scalar.Unchecked;
1921

2022
/**
@@ -138,70 +140,6 @@ private long place() {
138140
.count();
139141
}
140142

141-
/**
142-
* Check if the file is not a source file.
143-
* @param file The file to check.
144-
* @return True if the file is not a source file.
145-
*/
146-
private boolean isNotEoSource(final Path file) {
147-
final boolean res;
148-
final Path path = this.dir.relativize(file);
149-
if (path.startsWith(CopyMojo.DIR)) {
150-
Logger.debug(
151-
this,
152-
"File %[file]s (%[size]s) is not a binary, but a source, won't place it",
153-
path, path.toFile().length()
154-
);
155-
res = false;
156-
} else {
157-
res = true;
158-
}
159-
return res;
160-
}
161-
162-
/**
163-
* Check whether the binary file has corresponding EO sources in the jar.
164-
*
165-
* <p>The method checks ONLY EO binaries and classes. All other java files or classes in jar
166-
* will be included anyway.
167-
* Let's consider the next filesystem structure:</p>
168-
*
169-
* <pre>
170-
* Source file:
171-
* - "EO-SOURCE/org/eolang/txt/x.eo" -
172-
*
173-
* Correct:
174-
* - "EOorg/EOeolang/EOtxt/x.class" - is correct since has corresponding EO source folder
175-
* - "EOorg/EOeolang/EOtxt/y&z.class" - is correct since has corresponding EO source folder
176-
* - "com/sun/jna/Callback.class" - is correct since binary file is not in EOorg folder
177-
*
178-
* Is incorrect (since has no corresponding EO source folder):
179-
* - "EOorg/EOeolang/EObool.class"
180-
* - "EOorg/x.class"
181-
* </pre>
182-
*
183-
* <p>The filter is disabled by default, works only if the parameter
184-
* "placeBinariesThatHaveSources" is set to true.</p>
185-
*
186-
* @param file The file to check.
187-
* @return True if the file has corresponding EO sources.
188-
*/
189-
private boolean hasEoSource(final Path file) {
190-
final boolean result;
191-
if (PlaceMojo.this.placeBinariesThatHaveSources && file.toString().contains("EOorg")) {
192-
final Path sources = this.dir.resolve(CopyMojo.DIR)
193-
.resolve(this.dir.relativize(file.getParent()).toString().replace("EO", ""));
194-
result = Files.exists(sources)
195-
&& Files.isDirectory(sources)
196-
&& Arrays.stream(sources.toFile().listFiles())
197-
.filter(Objects::nonNull)
198-
.anyMatch(File::isFile);
199-
} else {
200-
result = true;
201-
}
202-
return result;
203-
}
204-
205143
/**
206144
* Check if the file is not already placed.
207145
* @param file The file to check.
@@ -266,7 +204,9 @@ private void printLogInfoAboutBinary(final Path file) {
266204
private void placeBinary(final Path file) {
267205
final Path path = this.dir.relativize(file);
268206
try {
269-
final Footprint generated = new FpGenerated(Files::readString);
207+
final Footprint generated = new FpGenerated(
208+
src -> new String(new BytesOf(src).asBytes(), StandardCharsets.UTF_8)
209+
);
270210
final Path target = new FpIfTargetExists(
271211
new FpFork(this.rewrite, generated, new FpIgnore()),
272212
generated
@@ -278,10 +218,11 @@ private void placeBinary(final Path file) {
278218
);
279219
} catch (final IOException ex) {
280220
throw new IllegalStateException(
281-
String.format(
282-
"Failed to place %s to home %s with path %s",
221+
Logger.format(
222+
"Failed to place %[file]s to home %[file]s with path %s",
283223
file, PlaceMojo.this.outputDir, path
284-
), ex
224+
),
225+
ex
285226
);
286227
}
287228
}

eo-maven-plugin/src/test/java/org/eolang/maven/AssembleMojoIT.java

-14
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,6 @@ void assemblesTogether(@Mktmp final Path temp) throws IOException {
4141
.write(AssembleMojoIT.helloWorld().getBytes(StandardCharsets.UTF_8));
4242
AssembleMojoIT.appendItself(f);
4343
f.exec("package");
44-
MatcherAssert.assertThat(
45-
String.join(
46-
" ",
47-
"AssembleMojo should have placed runtime",
48-
"library, but didn't"
49-
),
50-
temp.resolve(
51-
String.format(
52-
"target/eo/%s/org.eolang/eo-runtime",
53-
ResolveMojo.DIR
54-
)
55-
).toAbsolutePath(),
56-
new ContainsFiles("**/org/eolang/Phi.class")
57-
);
5844
MatcherAssert.assertThat(
5945
String.format(
6046
"AssembleMojo should have parsed stdout object %s, but didn't",

eo-maven-plugin/src/test/java/org/eolang/maven/ResolveMojoTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ void resolvesIfRuntimeDependencyComesFromTojos(@Mktmp final Path temp) throws IO
123123
"+rt jvm org.eolang:eo-runtime:0.22.1",
124124
"+version 0.25.0\n",
125125
"# No comments.",
126-
"[] > main")
126+
"[] > main"
127+
)
127128
.execute(new FakeMaven.Resolve());
128129
MatcherAssert.assertThat(
129130
ResolveMojoTest.JAR_MUST_EXIST,

eo-runtime/pom.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@
236236
<phase>generate-test-sources</phase>
237237
<goals>
238238
<goal>register</goal>
239-
<goal>assemble</goal>
240-
<goal>lint</goal>
239+
<goal>compile</goal>
241240
<goal>xmir-to-phi</goal>
242241
<goal>phi-to-xmir</goal>
243242
<goal>transpile</goal>

eo-runtime/src/test/java/integration/SnippetIT.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,15 @@ void runsAllSnippets(final String yml, final @Mktmp Path temp) throws IOExceptio
6666
xtory.map().get("eo")
6767
).getBytes(StandardCharsets.UTF_8)
6868
);
69-
f.dependencies().appendItself();
69+
f.dependencies()
70+
.append(
71+
"org.eolang",
72+
"eo-runtime",
73+
System.getProperty(
74+
"eo.version",
75+
Manifests.read("EO-Version")
76+
)
77+
);
7078
f.build()
7179
.plugins()
7280
.append(
@@ -81,7 +89,8 @@ void runsAllSnippets(final String yml, final @Mktmp Path temp) throws IOExceptio
8189
.phase("generate-sources")
8290
.goals("register", "compile", "transpile")
8391
.configuration()
84-
.set("failOnWarning", Boolean.FALSE.toString());
92+
.set("failOnWarning", Boolean.FALSE.toString())
93+
.set("skipLinting", Boolean.TRUE.toString());
8594
f.build()
8695
.plugins()
8796
.append("org.codehaus.mojo", "exec-maven-plugin", "3.1.1")

eo-runtime/src/test/resources/jul.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# SPDX-License-Identifier: MIT
33

44
handlers = org.slf4j.bridge.SLF4JBridgeHandler
5-
.level=INFO
5+
.level=DEBUG

0 commit comments

Comments
 (0)