Skip to content

Commit fdb5c53

Browse files
authored
Merge pull request objectionary#3991 from maxonfjvipon/bug/objectionary#3986/fix-build-in-main
bug(objectionary#3986): fix target path resolving + fixing arguments of main object
2 parents d18fa8f + 41e7127 commit fdb5c53

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

eo-runtime/src/main/java/org/eolang/Main.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ private static void run(final List<String> opts) throws Exception {
162162
}
163163
final Phi app = Phi.Φ.take(obj);
164164
if (opts.size() > 1) {
165-
Phi args = Phi.Φ.take("org.eolang.tuple");
165+
Phi args = Phi.Φ.take("org.eolang.tuple").take("empty");
166166
for (int idx = 1; idx < opts.size(); ++idx) {
167167
args = args.take("with");
168168
args.put(0, new Data.ToPhi(opts.get(idx)));

eo-runtime/src/main/java/org/eolang/PhPackage.java

+4-11
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public boolean hasRho() {
6969

7070
@Override
7171
public Phi take(final String name) {
72-
final String obj = this.eoPackage(name);
72+
final String obj = String.join(".", this.pkg, name);
7373
final String key = new JavaPath(obj).toString();
7474
return this.objects.computeIfAbsent(
7575
key,
@@ -109,23 +109,16 @@ public byte[] delta() {
109109
throw new ExFailure("Can't take #data() from package object \"%s\"", this.pkg);
110110
}
111111

112-
/**
113-
* Creates eo-package path by name.
114-
* @param name The name of an en object.
115-
* @return Eo-package path.
116-
*/
117-
private String eoPackage(final String name) {
118-
return String.join(".", this.pkg, name);
119-
}
120-
121112
/**
122113
* Load phi object by package name from ClassLoader.
123114
* @param path Path to directory or .java file
124115
* @param object Object FQN
125116
* @return Phi
126117
*/
127118
private Phi loadPhi(final String path, final String object) {
128-
final Path pth = Paths.get("target/classes", path.replace(".", File.separator));
119+
final Path pth = new File(
120+
this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath()
121+
).toPath().resolve(path.replace(".", File.separator));
129122
final Phi phi;
130123
if (Files.exists(pth) && Files.isDirectory(pth)) {
131124
phi = new PhPackage(object);

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ final class SnippetIT {
4848
@SuppressWarnings("unchecked")
4949
void runsAllSnippets(final String yml, final @Mktmp Path temp) throws IOException {
5050
final Xtory xtory = new XtSticky(new XtYaml(yml));
51-
final String file = xtory.map().get("file").toString();
5251
Assumptions.assumeFalse(xtory.map().containsKey("skip"));
52+
final String file = xtory.map().get("file").toString();
5353
new Farea(temp).together(
5454
f -> {
5555
f.properties()
@@ -67,6 +67,15 @@ void runsAllSnippets(final String yml, final @Mktmp Path temp) throws IOExceptio
6767
).getBytes(StandardCharsets.UTF_8)
6868
);
6969
f.dependencies().appendItself();
70+
final String target;
71+
if (xtory.map().containsKey("target")) {
72+
target = xtory.map().get("target").toString();
73+
} else {
74+
target = "target";
75+
}
76+
f.build()
77+
.properties()
78+
.set("directory", target);
7079
f.build()
7180
.plugins()
7281
.append(

eo-runtime/src/test/resources/org/eolang/snippets/fibo.yaml

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ eo: |
99
+alias org.eolang.io.stdout
1010
+alias org.eolang.txt.sprintf
1111
+package org.eolang.snippets
12-
+unlint object-has-data
13-
+unlint broken-alias-second
1412
1513
# No comments.
16-
[args] > fibo
14+
[] > fibo
1715
# No comments.
1816
[n] > f
1917
if. > @
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
2+
# SPDX-License-Identifier: MIT
3+
---
4+
out:
5+
- ".*Hello, Jeff.*"
6+
- ".*eoc/classes.*"
7+
- ".*eoc/eo/5-resolve.*"
8+
- ".*eoc/eo-foreign.csv.*"
9+
file: simple.eo
10+
args: [ "simple", "Jeff" ]
11+
target: "eoc"
12+
eo: |
13+
+alias org.eolang.io.stdout
14+
+alias org.eolang.txt.sprintf
15+
16+
# No comments.
17+
[args] > simple
18+
stdout > @
19+
sprintf *1
20+
"Hello, %s"
21+
args.at 0

0 commit comments

Comments
 (0)