Skip to content

Commit f57a299

Browse files
authored
Merge branch 'master' into bug/objectionary#3199/move-resolve-out-of-assemble
2 parents fd31abd + fdb5c53 commit f57a299

File tree

11 files changed

+178
-92
lines changed

11 files changed

+178
-92
lines changed

.codacy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
# package name contains capital letter and such names are conventional.
77
---
88
exclude_paths:
9-
- "eo-maven-plugin/src/test/java/org/eolang/maven/RegisterMojoIT.java"
9+
- "eo-maven-plugin/src/test/java/org/eolang/maven/TranspileMojoIT.java"

REUSE.toml

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
version = 1
55
[[annotations]]
66
path = [
7+
"**.csv",
8+
"**.json",
9+
"**.md",
10+
"**.txt",
11+
"**.vm",
712
"**/*.csv",
813
"**/*.jpg",
914
"**/*.json",
@@ -14,22 +19,26 @@ path = [
1419
"**/*.svg",
1520
"**/*.txt",
1621
"**/*.vm",
22+
"**/.DS_Store",
1723
"**/.gitignore",
24+
"**/.pdd",
1825
"**/.xcop",
26+
"**/CITATION.cff",
1927
"**/CNAME",
2028
"**/MANIFEST.MF",
2129
"**/README.md",
2230
"**/javax.xml.transform.TransformerFactory",
2331
"**/javax.xml.xpath.XPathFactory",
32+
".DS_Store",
2433
".codenarc",
2534
".gitattributes",
26-
".gitleaksignore",
35+
".gitignore",
2736
".mvn/jvm.config",
2837
".pdd",
2938
".xcop",
3039
"CITATION.cff",
40+
"CNAME",
3141
"CODE_OF_CONDUCT.md",
32-
"Gemfile.lock",
3342
"eo-maven-plugin/src/main/resources/org/eolang/maven/latex/latex-template.txt",
3443
"eo-maven-plugin/src/test/resources/org/eolang/maven/commits/tags.txt",
3544
"eo-runtime/src/main/resources/org/eolang/version.txt",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright (c) 2016-2025 Objectionary.com
3+
* SPDX-License-Identifier: MIT
4+
*/
5+
package org.eolang.maven;
6+
7+
import com.yegor256.MayBeSlow;
8+
import com.yegor256.Mktmp;
9+
import com.yegor256.MktmpResolver;
10+
import com.yegor256.WeAreOnline;
11+
import com.yegor256.farea.Farea;
12+
import java.nio.charset.StandardCharsets;
13+
import java.nio.file.Files;
14+
import java.nio.file.Path;
15+
import org.hamcrest.MatcherAssert;
16+
import org.hamcrest.Matchers;
17+
import org.junit.jupiter.api.Test;
18+
import org.junit.jupiter.api.extension.ExtendWith;
19+
20+
/**
21+
* Integration tests for {@link TranspileMojo}.
22+
*
23+
* @since 0.52
24+
*/
25+
@SuppressWarnings({"JTCOP.RuleAllTestsHaveProductionClass", "JTCOP.RuleNotContainsTestWord"})
26+
@ExtendWith({WeAreOnline.class, MktmpResolver.class, MayBeSlow.class, RandomProgramResolver.class})
27+
final class TranspileMojoIT {
28+
@Test
29+
void transpilesWithPackage(@Mktmp final Path temp) throws Exception {
30+
new Farea(temp).together(
31+
f -> {
32+
f.clean();
33+
f.files().file("src/main/eo/one/foo.eo").write(
34+
String.join(
35+
"\n",
36+
"+package one",
37+
"",
38+
"# no comments.",
39+
"[] > foo",
40+
" QQ.io.stdout > @",
41+
" \"Hello, world!\\n\""
42+
).getBytes(StandardCharsets.UTF_8)
43+
);
44+
new AppendedPlugin(f).value()
45+
.goals("register", "parse", "shake", "transpile");
46+
f.exec("process-sources");
47+
final String java = "EOfoo.java";
48+
final String pname = "EOone";
49+
final String pinfo = "package-info.java";
50+
MatcherAssert.assertThat(
51+
String.format(
52+
"The %s file must be generated, but it didn't",
53+
java
54+
),
55+
temp.resolve(
56+
String.format(
57+
"target/generated-sources/%s/%s",
58+
pname,
59+
java
60+
)
61+
).toFile().exists(),
62+
Matchers.is(true)
63+
);
64+
MatcherAssert.assertThat(
65+
String.format(
66+
"The %s file must contain the %s package name",
67+
pinfo,
68+
pname
69+
),
70+
Files.readString(
71+
temp.resolve(
72+
String.format(
73+
"target/generated-sources/%s/%s",
74+
pname,
75+
pinfo
76+
)
77+
),
78+
StandardCharsets.UTF_8
79+
),
80+
Matchers.containsString(String.format("package %s;", pname))
81+
);
82+
}
83+
);
84+
}
85+
86+
@Test
87+
void transpilesSimpleApp(@Mktmp final Path temp, @RandomProgram final String prog)
88+
throws Exception {
89+
new Farea(temp).together(
90+
f -> {
91+
f.clean();
92+
f.files().file("src/main/eo/foo.eo").write(prog.getBytes());
93+
new AppendedPlugin(f).value()
94+
.goals("register", "parse", "shake", "transpile");
95+
f.exec("process-sources");
96+
final String java = "EOfoo.java";
97+
final String pinfo = "package-info.java";
98+
MatcherAssert.assertThat(
99+
String.format(
100+
"The %s file is re-generated",
101+
java
102+
),
103+
temp.resolve(
104+
String.format(
105+
"target/generated-sources/%s",
106+
java
107+
)
108+
).toFile().exists(),
109+
Matchers.is(true)
110+
);
111+
MatcherAssert.assertThat(
112+
String.format(
113+
"The %s file must not exist, but it doesn't",
114+
pinfo
115+
),
116+
temp.resolve(
117+
String.format(
118+
"target/generated-sources/%s",
119+
pinfo
120+
)
121+
).toFile().exists(),
122+
Matchers.is(false)
123+
);
124+
}
125+
);
126+
}
127+
}

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

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

77
import com.yegor256.Mktmp;
88
import com.yegor256.MktmpResolver;
9-
import com.yegor256.farea.Farea;
109
import java.io.IOException;
11-
import java.nio.charset.StandardCharsets;
1210
import java.nio.file.Files;
1311
import java.nio.file.Path;
1412
import java.nio.file.Paths;
@@ -101,75 +99,6 @@ void doesNotTouchAtom(@Mktmp final Path temp) throws IOException {
10199
);
102100
}
103101

104-
@Test
105-
void transpilesWithPackage(@Mktmp final Path temp)
106-
throws Exception {
107-
new Farea(temp).together(
108-
f -> {
109-
f.clean();
110-
f.files().file("src/main/eo/one/foo.eo").write(
111-
String.join(
112-
"\n",
113-
"+package one",
114-
"+unlint object-has-data",
115-
"",
116-
"# no comments.",
117-
"[] > foo",
118-
" QQ.io.stdout > @",
119-
" \"Hello, world!\\n\"",
120-
""
121-
).getBytes(StandardCharsets.UTF_8)
122-
);
123-
f.build()
124-
.plugins()
125-
.appendItself()
126-
.execution()
127-
.goals("register", "parse", "shake", "transpile");
128-
f.exec("process-sources");
129-
}
130-
);
131-
MatcherAssert.assertThat(
132-
"the .java file is generated",
133-
temp.resolve("target/generated-sources/EOone/EOfoo.java").toFile().exists(),
134-
Matchers.is(true)
135-
);
136-
MatcherAssert.assertThat(
137-
"the package-info.java file contains the right package name",
138-
Files.readString(
139-
temp.resolve("target/generated-sources/EOone/package-info.java"),
140-
StandardCharsets.UTF_8
141-
),
142-
Matchers.containsString("package EOone;")
143-
);
144-
}
145-
146-
@Test
147-
void transpilesSimpleApp(@Mktmp final Path temp, @RandomProgram final String prog)
148-
throws Exception {
149-
new Farea(temp).together(
150-
f -> {
151-
f.clean();
152-
f.files().file("src/main/eo/foo.eo").write(prog.getBytes());
153-
f.build()
154-
.plugins()
155-
.appendItself()
156-
.execution()
157-
.goals("register", "parse", "shake", "transpile");
158-
f.exec("process-sources");
159-
}
160-
);
161-
MatcherAssert.assertThat(
162-
"the .java file is re-generated",
163-
temp.resolve("target/generated-sources/EOfoo.java").toFile().exists(),
164-
Matchers.is(true)
165-
);
166-
MatcherAssert.assertThat(
167-
"the package-info.java file contains the right package name",
168-
temp.resolve("target/generated-sources/package-info.java").toFile().exists(),
169-
Matchers.is(false)
170-
);
171-
}
172-
173102
@Test
174103
void recompilesIfModified(@Mktmp final Path temp) throws IOException {
175104
final FakeMaven maven = new FakeMaven(temp);

eo-parser/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
<dependency>
151151
<groupId>com.yegor256</groupId>
152152
<artifactId>farea</artifactId>
153-
<version>0.14.2</version>
153+
<version>0.15.0</version>
154154
<scope>test</scope>
155155
</dependency>
156156
<dependency>

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").resolve(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()
@@ -75,6 +75,15 @@ void runsAllSnippets(final String yml, final @Mktmp Path temp) throws IOExceptio
7575
Manifests.read("EO-Version")
7676
)
7777
);
78+
final String target;
79+
if (xtory.map().containsKey("target")) {
80+
target = xtory.map().get("target").toString();
81+
} else {
82+
target = "target";
83+
}
84+
f.build()
85+
.properties()
86+
.set("directory", target);
7887
f.build()
7988
.plugins()
8089
.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

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@
256256
<dependency>
257257
<groupId>com.yegor256</groupId>
258258
<artifactId>farea</artifactId>
259-
<version>0.14.2</version>
259+
<version>0.15.0</version>
260260
<scope>test</scope>
261261
</dependency>
262262
<dependency>

0 commit comments

Comments
 (0)