Skip to content
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
8 changes: 6 additions & 2 deletions apache-maven/src/assembly/maven/bin/mvn
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,14 @@ find_file_argument_basedir() {
)
}

# concatenates all lines of a file
# concatenates all lines of a file and replaces variables
concat_lines() {
if [ -f "$1" ]; then
echo "`tr -s '\r\n' ' ' < "$1"`"
# First transform line endings to spaces
content=$(tr -s '\r\n' ' ' < "$1")
# Handle both ${var} and $var formats, only substitute MAVEN_PROJECTBASEDIR
echo "$content" | sed -e "s|\${MAVEN_PROJECTBASEDIR}|$MAVEN_PROJECTBASEDIR|g" \
-e "s|\$MAVEN_PROJECTBASEDIR|$MAVEN_PROJECTBASEDIR|g"
fi
}

Expand Down
8 changes: 7 additions & 1 deletion apache-maven/src/assembly/maven/bin/mvn.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,13 @@ cd /d "%EXEC_DIR%"
if not exist "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadJvmConfig

@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_OPTS=!JVM_CONFIG_MAVEN_OPTS! %%a
set JVM_CONFIG_MAVEN_OPTS=
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do (
set "line=%%a"
set "line=!line:$MAVEN_PROJECTBASEDIR=%MAVEN_PROJECTBASEDIR%!"
set "line=!line:${MAVEN_PROJECTBASEDIR}=%MAVEN_PROJECTBASEDIR%!"
set JVM_CONFIG_MAVEN_OPTS=!JVM_CONFIG_MAVEN_OPTS! !line!
)
@endlocal & set MAVEN_OPTS=%MAVEN_OPTS% %JVM_CONFIG_MAVEN_OPTS%

:endReadJvmConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.it;

import java.io.File;
import java.util.Properties;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-8598">MNG-8598</a>:
* Verify that ${MAVEN_PROJECTBASEDIR} and $MAVEN_PROJECTBASEDIR in .mvn/jvm.config are properly
* substituted with the actual project base directory.
*/
public class MavenITmng8598JvmConfigSubstitutionTest extends AbstractMavenIntegrationTestCase {
public MavenITmng8598JvmConfigSubstitutionTest() {
super("[4.0.0-rc-4,)");
}

@Test
public void testProjectBasedirSubstitution() throws Exception {
File testDir = extractResources("/mng-8598");

Verifier verifier = newVerifier(testDir.getAbsolutePath());
verifier.addCliArgument(
"-Dexpression.outputFile=" + new File(testDir, "target/pom.properties").getAbsolutePath());
verifier.setForkJvm(true); // custom .mvn/jvm.config
verifier.addCliArgument("validate");
verifier.execute();
verifier.verifyErrorFreeLog();

Properties props = verifier.loadProperties("target/pom.properties");
String expectedPath = testDir.getAbsolutePath().replace('\\', '/');
assertEquals(
expectedPath + "/curated",
props.getProperty("project.properties.curatedPathProp").replace('\\', '/'));
assertEquals(
expectedPath + "/simple",
props.getProperty("project.properties.simplePathProp").replace('\\', '/'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public TestSuiteOrdering() {
* the tests are to finishing. Newer tests are also more likely to fail, so this is
* a fail fast technique as well.
*/
suite.addTestSuite(MavenITmng8598JvmConfigSubstitutionTest.class);
suite.addTestSuite(MavenITmng8653AfterAndEachPhasesWithConcurrentBuilderTest.class);
suite.addTestSuite(MavenITmng5668AfterPhaseExecutionTest.class);
suite.addTestSuite(MavenITmng8648ProjectStartedEventsTest.class);
Expand Down
2 changes: 2 additions & 0 deletions its/core-it-suite/src/test/resources/mng-8598/.mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-DcuratedPath=${MAVEN_PROJECTBASEDIR}/curated
-DsimplePath=$MAVEN_PROJECTBASEDIR/simple
39 changes: 39 additions & 0 deletions its/core-it-suite/src/test/resources/mng-8598/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.its.mng8598</groupId>
<artifactId>jvm-config-substitution</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<properties>
<curatedPathProp>${curatedPath}</curatedPathProp>
<simplePathProp>${simplePath}</simplePathProp>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-expression</artifactId>
<version>2.1-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>eval</goal>
</goals>
<phase>validate</phase>
<configuration>
<outputFile>${expression.outputFile}</outputFile>
<expressions>
<expression>project/properties/curatedPathProp</expression>
<expression>project/properties/simplePathProp</expression>
</expressions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>