Skip to content

Commit ad6af0f

Browse files
committed
Merge branch 'master' of github.com:objectionary/eo
2 parents 6635a57 + cdfa752 commit ad6af0f

File tree

134 files changed

+654
-439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+654
-439
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/ResolveMojoIT.java"
9+
- "eo-maven-plugin/src/test/java/org/eolang/maven/RegisterMojoIT.java"

.github/workflows/zerocracy.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
timeout-minutes: 30
1717
steps:
1818
- uses: actions/checkout@v4
19-
- uses: zerocracy/[email protected].69
19+
- uses: zerocracy/[email protected].71
2020
with:
2121
verbose: false
2222
cycles: 1
@@ -26,7 +26,7 @@ jobs:
2626
options: |
2727
vitals_url=https://www.eolang.org/zerocracy/objectionary-vitals.html
2828
factbase: objectionary.fb
29-
- uses: zerocracy/[email protected].43
29+
- uses: zerocracy/[email protected].44
3030
with:
3131
factbase: objectionary.fb
3232
output: pages

eo-maven-plugin/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<dependency>
2424
<groupId>org.eolang</groupId>
2525
<artifactId>lints</artifactId>
26-
<version>0.0.39</version>
26+
<version>0.0.42</version>
2727
</dependency>
2828
<dependency>
2929
<groupId>org.glassfish</groupId>

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

+1-22
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package org.eolang.maven;
66

77
import com.jcabi.log.Logger;
8-
import java.io.File;
98
import org.apache.maven.plugins.annotations.LifecyclePhase;
109
import org.apache.maven.plugins.annotations.Mojo;
1110

@@ -32,32 +31,12 @@ final void exec() {
3231
);
3332
return;
3433
}
35-
if (this.purge(this.targetDir)) {
34+
if (new Deleted(this.targetDir).get()) {
3635
Logger.info(
3736
this,
3837
"Deleted all files in the %[file]s directory",
3938
this.targetDir
4039
);
4140
}
4241
}
43-
44-
/**
45-
* Recursive deletion.
46-
*
47-
* @param dir Directory to be deleted
48-
* @return State {@code true} if deleted, {@code false} otherwise
49-
*/
50-
private boolean purge(final File dir) {
51-
final File[] contents = dir.listFiles();
52-
if (null != contents) {
53-
for (final File file : contents) {
54-
this.purge(file);
55-
}
56-
}
57-
final boolean state = dir.delete();
58-
if (state) {
59-
Logger.debug(this, "The directory %[file]s purged", dir);
60-
}
61-
return state;
62-
}
6342
}

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ public Iterator<Dependency> iterator() {
6363
);
6464
final Collection<Dependency> deps = new HashSet<>(0);
6565
for (final TjForeign tojo : list) {
66-
if (ParseMojo.ZERO.equals(tojo.version())
67-
&& !this.discover) {
66+
if (ParseMojo.ZERO.equals(tojo.version()) && !this.discover) {
6867
Logger.debug(
6968
this,
7069
"Program %s skipped due to its zero version",
@@ -73,7 +72,7 @@ public Iterator<Dependency> iterator() {
7372
continue;
7473
}
7574
final Optional<Dependency> opt = DcsDefault.artifact(tojo.xmir());
76-
if (!opt.isPresent()) {
75+
if (opt.isEmpty()) {
7776
Logger.debug(this, "No dependencies for %s", tojo.description());
7877
continue;
7978
}
@@ -105,10 +104,15 @@ public Iterator<Dependency> iterator() {
105104
*/
106105
private static Optional<Dependency> artifact(final Path file) {
107106
final Collection<String> coords = DcsDefault.jvms(file);
107+
if (coords.size() > 1) {
108+
throw new IllegalStateException(
109+
Logger.format("Too many (%d) dependencies at %[file]s", coords.size(), file)
110+
);
111+
}
108112
final Optional<Dependency> dep;
109113
if (coords.isEmpty()) {
110114
dep = Optional.empty();
111-
} else if (coords.size() == 1) {
115+
} else {
112116
final String[] parts = coords.iterator().next().split(":");
113117
final Dependency dependency = new Dependency();
114118
dependency.setGroupId(parts[0]);
@@ -122,10 +126,6 @@ private static Optional<Dependency> artifact(final Path file) {
122126
}
123127
dependency.setScope("transpile");
124128
dep = Optional.of(dependency);
125-
} else {
126-
throw new IllegalStateException(
127-
Logger.format("Too many (%d) dependencies at %[file]s", coords.size(), file)
128-
);
129129
}
130130
return dep;
131131
}
@@ -148,13 +148,13 @@ private static Collection<String> jvms(final Path file) {
148148
meta -> {
149149
final Xnav xnav = new Xnav(meta);
150150
final Optional<String> head = xnav.element("head").text();
151-
final boolean runtime = head.isPresent() && "rt".equals(head.get());
151+
final boolean runtime = head.map("rt"::equals).orElse(false);
152152
final Optional<Xnav> part = xnav.elements(
153153
Filter.withName("part")
154154
).findFirst();
155155
return runtime
156156
&& part.isPresent()
157-
&& "jvm".equals(part.get().text().get());
157+
&& part.get().text().map("jvm"::equals).orElse(false);
158158
}
159159
)
160160
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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.jcabi.log.Logger;
8+
import java.io.File;
9+
import java.util.function.Supplier;
10+
11+
/**
12+
* Deleting a directory with files or just a file.
13+
*
14+
* @since 0.52
15+
*/
16+
final class Deleted implements Supplier<Boolean> {
17+
/**
18+
* Target file or directory to be deleted.
19+
*/
20+
private final File target;
21+
22+
/**
23+
* Ctor.
24+
* @param file File or directory to be deleted
25+
*/
26+
Deleted(final File file) {
27+
this.target = file;
28+
}
29+
30+
@Override
31+
public Boolean get() {
32+
return this.purge(this.target);
33+
}
34+
35+
/**
36+
* Recursive deletion.
37+
*
38+
* @param dir File or directory to be deleted
39+
* @return State {@code true} if deleted, {@code false} otherwise
40+
*/
41+
private boolean purge(final File dir) {
42+
if (dir.isDirectory()) {
43+
final File[] contents = dir.listFiles();
44+
if (null != contents) {
45+
for (final File file : contents) {
46+
this.purge(file);
47+
}
48+
}
49+
}
50+
final boolean state = dir.delete();
51+
if (state) {
52+
Logger.debug(this, "The file or directory %[file]s purged", dir);
53+
}
54+
return state;
55+
}
56+
}

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ private int lintAll(final ConcurrentHashMap<Severity, Integer> counts) throws IO
160160
for (final Map.Entry<String, Path> ent : paths.entrySet()) {
161161
pkg.put(ent.getKey(), new XMLDocument(ent.getValue()));
162162
}
163-
final Collection<Defect> defects = new Programs(pkg).defects();
163+
final Collection<Defect> defects = new Programs(pkg)
164+
.without("unlint-non-existing-defect").defects();
164165
for (final Defect defect : defects) {
165166
counts.compute(defect.severity(), (sev, before) -> before + 1);
166167
LintMojo.embed(
@@ -258,15 +259,15 @@ private static String summary(final ConcurrentHashMap<Severity, Integer> counts)
258259
* @param xmir The XML before linting
259260
* @param counts Counts of errors, warnings, and critical
260261
* @return XML after linting
261-
* @todo #3934:35min Remove .without() from Program to enable `unknown-metas`
262-
* and `unsorted-metas` lints. Currently we disabled them since lints does not
263-
* support `+spdx` meta yet. Once <a href="https://github.com/objectionary/lints/issues/354">this</a>
264-
* issue will be resolved, we should enable all lints.
262+
* @todo #3977:25min Enable `unlint-non-existing-defect` lint.
263+
* Currently its disabled because of <a href="https://github.com/objectionary/lints/issues/385">this</a>
264+
* bug. Once issue will be resolved, we should enable this lint. Don't forget to enable
265+
* this lint in WPA scope too.
265266
*/
266267
private static XML linted(final XML xmir, final ConcurrentHashMap<Severity, Integer> counts) {
267268
final Directives dirs = new Directives();
268269
final Collection<Defect> defects = new Program(xmir).without(
269-
"unknown-metas", "unsorted-metas"
270+
"unlint-non-existing-defect"
270271
).defects();
271272
if (!defects.isEmpty()) {
272273
dirs.xpath("/program").addIf("errors").strict(1);

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

+11-15
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.github.lombrozo.xnav.Filter;
88
import com.github.lombrozo.xnav.Xnav;
99
import com.jcabi.log.Logger;
10-
import java.io.FileNotFoundException;
1110
import java.io.IOException;
1211
import java.nio.file.Path;
1312
import java.util.Collection;
@@ -16,7 +15,6 @@
1615
import java.util.stream.Stream;
1716
import org.apache.maven.plugins.annotations.LifecyclePhase;
1817
import org.apache.maven.plugins.annotations.Mojo;
19-
import org.cactoos.iterable.Filtered;
2018
import org.cactoos.iterable.IterableOf;
2119
import org.cactoos.iterable.Mapped;
2220
import org.cactoos.list.ListOf;
@@ -89,9 +87,7 @@ private void probe() throws IOException {
8987
continue;
9088
}
9189
++count;
92-
this.scopedTojos()
93-
.add(object)
94-
.withDiscoveredAt(src);
90+
this.scopedTojos().add(object).withDiscoveredAt(src);
9591
probed.add(object);
9692
}
9793
tojo.withProbed(count);
@@ -123,17 +119,13 @@ private void probe() throws IOException {
123119
*
124120
* @param file The .xmir file
125121
* @return List of foreign objects found
126-
* @throws FileNotFoundException If not found
127122
*/
128-
private Collection<String> probes(final Path file) throws FileNotFoundException {
123+
private Collection<String> probes(final Path file) {
129124
final long start = System.currentTimeMillis();
130125
final Collection<String> objects = new ListOf<>(
131126
new Mapped<>(
132127
ProbeMojo::noPrefix,
133-
new Filtered<>(
134-
obj -> !obj.isEmpty(),
135-
ProbeMojo.probeMetas(file)
136-
)
128+
ProbeMojo.metas(file)
137129
).iterator()
138130
);
139131
if (objects.isEmpty()) {
@@ -151,12 +143,13 @@ private Collection<String> probes(final Path file) throws FileNotFoundException
151143
}
152144

153145
/**
154-
* Return probe metas.
155-
* The equivalent xpath is: "/program/metas/meta[head/text() = 'probe']/tail/text()"
146+
* Return metas for probing.
147+
* The equivalent xpath is:
148+
* "/program/metas/meta[head/text()='probe' or head/text()='also']/tail[not(text()='')]/text()"
156149
* @param file XML file
157150
* @return Metas to probe
158151
*/
159-
private static Iterable<String> probeMetas(final Path file) {
152+
private static Iterable<String> metas(final Path file) {
160153
return new IterableOf<>(
161154
new Xnav(file)
162155
.element("program")
@@ -170,11 +163,14 @@ private static Iterable<String> probeMetas(final Path file) {
170163
final Optional<String> head = new Xnav(meta)
171164
.element("head")
172165
.text();
173-
return head.isPresent() && "probe".equals(head.get());
166+
return head.map(
167+
text -> "probe".equals(text) || "also".equals(text)
168+
).orElse(false);
174169
}
175170
)
176171
)
177172
.map(meta -> meta.element("tail").text().get())
173+
.filter(meta -> !meta.isEmpty())
178174
)
179175
.orElse(Stream.of())
180176
.iterator()

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

+15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package org.eolang.maven;
66

77
import com.jcabi.log.Logger;
8+
import java.io.File;
89
import java.nio.file.Path;
910
import java.util.Collection;
1011
import java.util.Set;
@@ -67,6 +68,7 @@ public void exec() {
6768
String.format("sourcesDir is null. Please specify a valid sourcesDir for %s", this)
6869
);
6970
}
71+
this.removeOldFiles();
7072
final Pattern pattern = Pattern.compile("^[a-zA-Z0-9\\-]+\\.eo$");
7173
final int before = this.scopedTojos().size();
7274
if (before > 0) {
@@ -104,4 +106,17 @@ public void exec() {
104106
sources.size(), this.sourcesDir, this.foreign, this.includeSources, this.excludeSources
105107
);
106108
}
109+
110+
private void removeOldFiles() {
111+
final File[] files = {
112+
this.foreign,
113+
this.targetDir.toPath().resolve(PullMojo.DIR).toFile(),
114+
this.targetDir.toPath().resolve(ResolveMojo.DIR).toFile(),
115+
};
116+
for (final File file : files) {
117+
if (file.exists()) {
118+
new Deleted(file).get();
119+
}
120+
}
121+
}
107122
}

eo-maven-plugin/src/main/resources/org/eolang/maven/shake/add-probes.xsl

+4-5
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
<!--
88
For every object FQN add probe meta
99
with fully qualified name of the object.
10-
Example:
11-
For object:
10+
For instance, for object:
1211
<o base=".abc" ... >
1312
<o base=".edf" ... >
1413
<o base="Q.number"/>
1514
</o>
1615
</o>
1716
18-
Metas will be added:
17+
The next metas will be added:
1918
<meta>
2019
<head>probe</head>
2120
<tail>Q.org</tail>
@@ -92,9 +91,9 @@
9291
<xsl:variable name="parts" select="tokenize(@base, '\.')"/>
9392
<xsl:for-each select="$parts">
9493
<xsl:variable name="pos" select="position()"/>
95-
<p>
94+
<a>
9695
<xsl:value-of select="string-join($parts[position()&lt;=$pos], '.')"/>
97-
</p>
96+
</a>
9897
</xsl:for-each>
9998
<xsl:apply-templates select="o" mode="create"/>
10099
</xsl:template>

0 commit comments

Comments
 (0)