Skip to content

Commit

Permalink
Merge pull request #3883 from maxonfjvipon/bug/#3811/relative-source-…
Browse files Browse the repository at this point in the history
…path

bug(#3811): relative `/program/@source` path
  • Loading branch information
yegor256 authored Feb 4, 2025
2 parents e864d3e + 705756c commit e3cc5ec
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
4 changes: 4 additions & 0 deletions eo-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ SOFTWARE.
<dependency>
<groupId>com.yegor256</groupId>
<artifactId>mktmp</artifactId>
</dependency>
<dependency>
<groupId>com.github.volodya-lombrozo</groupId>
<artifactId>xnav</artifactId>
<!-- version from parent POM -->
</dependency>
<dependency>
Expand Down
12 changes: 0 additions & 12 deletions eo-maven-plugin/src/main/java/org/eolang/maven/CopyMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,6 @@ public final class CopyMojo extends SafeMojo {
Pattern.MULTILINE
);

/**
* Directory in which .eo files are located.
*
* @checkstyle MemberNameCheck (7 lines)
*/
@Parameter(
property = "eo.sourcesDir",
required = true,
defaultValue = "${project.basedir}/src/main/eo"
)
private File sourcesDir;

/**
* Target directory with resources to be packaged in JAR.
*
Expand Down
6 changes: 3 additions & 3 deletions eo-maven-plugin/src/main/java/org/eolang/maven/ParseMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private int parsed(final ForeignTojo tojo) throws Exception {
final Path target = new Place(name).make(base, AssembleMojo.XMIR);
tojo.withXmir(
new FpDefault(
ParseMojo.parse(name),
this.parse(name),
this.cache.toPath().resolve(ParseMojo.CACHE),
this.plugin.getVersion(),
new TojoHash(tojo),
Expand All @@ -158,12 +158,12 @@ private int parsed(final ForeignTojo tojo) throws Exception {
* @param name Name of the EO object
* @return Function that parses EO source
*/
private static Func<Path, String> parse(final String name) {
private Func<Path, String> parse(final String name) {
return source -> {
final String parsed = new XMLDocument(
new Xembler(
new Directives().xpath("/program").attr(
"source", source.toAbsolutePath()
"source", this.sourcesDir.toPath().relativize(source.toAbsolutePath())
)
).applyQuietly(new EoSyntax(name, new InputOf(source)).parsed().inner())
).toString();
Expand Down
13 changes: 13 additions & 0 deletions eo-maven-plugin/src/main/java/org/eolang/maven/SafeMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ abstract class SafeMojo extends AbstractMojo {
@Parameter(property = "eo.foreignFormat", required = true, defaultValue = "csv")
protected String foreignFormat = "csv";

/**
* Directory in which .eo files are located.
*
* @checkstyle VisibilityModifierCheck (10 lines)
* @checkstyle MemberNameCheck (8 lines)
*/
@Parameter(
property = "eo.sourcesDir",
required = true,
defaultValue = "${project.basedir}/src/main/eo"
)
protected File sourcesDir;

/**
* Target directory.
* @checkstyle MemberNameCheck (10 lines)
Expand Down
26 changes: 26 additions & 0 deletions eo-maven-plugin/src/test/java/org/eolang/maven/ParseMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.eolang.maven;

import com.github.lombrozo.xnav.Xnav;
import com.yegor256.Mktmp;
import com.yegor256.MktmpResolver;
import com.yegor256.WeAreOnline;
Expand Down Expand Up @@ -224,6 +225,31 @@ void parsesConcurrentlyWithLotsOfPrograms(@Mktmp final Path temp) throws IOExcep
}
}

@Test
void injectsRelativeSource(@Mktmp final Path temp) throws IOException {
final String path = new Xnav(
new FakeMaven(temp)
.withHelloWorld()
.execute(ParseMojo.class)
.result()
.get(String.format("target/%s/foo/x/main.%s", ParseMojo.DIR, AssembleMojo.XMIR))
)
.element("program")
.attribute("source")
.text()
.get();
MatcherAssert.assertThat(
"The /program/@source attribute must be a relative path",
Paths.get(path).isAbsolute(),
Matchers.is(false)
);
MatcherAssert.assertThat(
"The /program/@source attribute must be a relative path to EO source",
path,
Matchers.equalTo(Paths.get("foo/x/main.eo").toString())
);
}

/**
* The mojo that does nothing, but executes infinitely.
* @since 0.29
Expand Down

0 comments on commit e3cc5ec

Please sign in to comment.