Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(#3811): relative /program/@source path #3883

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading