[MNG-7404] Drop deprecated prefixless expressions

Fixed failing unit tests to use the 'project.' prefix and removed legacy
unit tests that tested support for prefixless expressions.

Closes #696.
This commit is contained in:
Giovanni van der Schelde 2022-03-15 10:40:44 +01:00 committed by Maarten Mulders
parent ca9aa8f4f3
commit 93196d4bb7
8 changed files with 9 additions and 286 deletions

View File

@ -736,40 +736,6 @@ public class PomConstructionTest
}
}
@Test
public void testInterpolationOfLegacyExpressionsThatDontIncludeTheProjectPrefix()
throws Exception
{
PomTestWrapper pom = buildPom( "unprefixed-expression-interpolation/child" );
assertEquals( pom.getBasedir(), new File( pom.getValue( "properties/projectDir" ).toString() ) );
assertEquals( "org.apache.maven.its.mng3831.child", pom.getValue( "properties/projectGroupId" ) );
assertEquals( "child", pom.getValue( "properties/projectArtifactId" ) );
assertEquals( "2.0-alpha-1", pom.getValue( "properties/projectVersion" ) );
assertEquals( "jar", pom.getValue( "properties/projectPackaging" ) );
assertEquals( "child-name", pom.getValue( "properties/projectName" ) );
assertEquals( "child-desc", pom.getValue( "properties/projectDesc" ) );
assertEquals( "https://child.org/", pom.getValue( "properties/projectUrl" ) );
assertEquals( "2008", pom.getValue( "properties/projectYear" ) );
assertEquals( "child-org-name", pom.getValue( "properties/projectOrgName" ) );
assertEquals( "2.0.0", pom.getValue( "properties/projectPrereqMvn" ) );
assertEquals( "https://scm.org/", pom.getValue( "properties/projectScmUrl" ) );
assertEquals( "https://issue.org/", pom.getValue( "properties/projectIssueUrl" ) );
assertEquals( "https://ci.org/", pom.getValue( "properties/projectCiUrl" ) );
assertEquals( "child-dist-repo", pom.getValue( "properties/projectDistRepoName" ) );
assertEquals( "https://dist.org/", pom.getValue( "properties/projectDistRepoUrl" ) );
assertEquals( "https://site.org/", pom.getValue( "properties/projectDistSiteUrl" ) );
assertEquals( "org.apache.maven.its.mng3831", pom.getValue( "properties/parentGroupId" ) );
assertEquals( "parent", pom.getValue( "properties/parentArtifactId" ) );
assertEquals( "1.0", pom.getValue( "properties/parentVersion" ) );
assertThat( pom.getValue( "properties/projectBuildOut" ).toString(), endsWith( "bin" ) );
assertThat( pom.getValue( "properties/projectSiteOut" ).toString(), endsWith( "doc" ) );
}
@Test
public void testInterpolationWithBasedirAlignedDirectories()

View File

@ -1,104 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
https://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.
-->
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven.its.mng3831</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
</parent>
<groupId>org.apache.maven.its.mng3831.child</groupId>
<artifactId>child</artifactId>
<version>2.0-alpha-1</version>
<packaging>jar</packaging>
<name>child-name</name>
<description>child-desc</description>
<url>https://child.org/</url>
<inceptionYear>2008</inceptionYear>
<organization>
<name>child-org-name</name>
</organization>
<prerequisites>
<maven>2.0.0</maven>
</prerequisites>
<scm>
<url>https://scm.org/</url>
</scm>
<issueManagement>
<url>https://issue.org/</url>
</issueManagement>
<ciManagement>
<url>https://ci.org/</url>
</ciManagement>
<distributionManagement>
<repository>
<id>maven-core-it</id>
<name>child-dist-repo</name>
<url>https://dist.org/</url>
</repository>
<site>
<id>maven-core-it</id>
<name>child-site</name>
<url>https://site.org/</url>
</site>
</distributionManagement>
<properties>
<!-- this is where we collect all the interpolated values for the POM dump -->
<projectDir>${basedir}</projectDir>
<projectGroupId>${groupId}</projectGroupId>
<projectArtifactId>${artifactId}</projectArtifactId>
<projectVersion>${version}</projectVersion>
<projectPackaging>${packaging}</projectPackaging>
<projectName>${name}</projectName>
<projectDesc>${description}</projectDesc>
<projectUrl>${url}</projectUrl>
<projectYear>${inceptionYear}</projectYear>
<projectOrgName>${organization.name}</projectOrgName>
<projectPrereqMvn>${prerequisites.maven}</projectPrereqMvn>
<projectScmUrl>${scm.url}</projectScmUrl>
<projectIssueUrl>${issueManagement.url}</projectIssueUrl>
<projectCiUrl>${ciManagement.url}</projectCiUrl>
<projectDistRepoName>${distributionManagement.repository.name}</projectDistRepoName>
<projectDistRepoUrl>${distributionManagement.repository.url}</projectDistRepoUrl>
<projectDistSiteUrl>${distributionManagement.site.url}</projectDistSiteUrl>
<projectBuildOut>${build.outputDirectory}</projectBuildOut>
<projectSiteOut>${reporting.outputDirectory}</projectSiteOut>
<parentGroupId>${parent.groupId}</parentGroupId>
<parentArtifactId>${parent.artifactId}</parentArtifactId>
<parentVersion>${parent.version}</parentVersion>
</properties>
<build>
<outputDirectory>target/bin</outputDirectory>
</build>
<reporting>
<outputDirectory>target/doc</outputDirectory>
</reporting>
</project>

View File

@ -1,36 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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
https://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.
-->
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.its.mng3831</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>Maven Integration Test :: MNG-3831</name>
<description>Test POM interpolation with expressions of the form $ { * } (ugly but real)</description>
<modules>
<module>parent/child</module>
</modules>
</project>

View File

@ -31,13 +31,11 @@ import javax.inject.Inject;
import org.apache.maven.model.Model;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.path.PathTranslator;
import org.apache.maven.model.path.UrlNormalizer;
import org.codehaus.plexus.interpolation.AbstractValueSource;
import org.codehaus.plexus.interpolation.InterpolationPostProcessor;
import org.codehaus.plexus.interpolation.MapBasedValueSource;
import org.codehaus.plexus.interpolation.ObjectBasedValueSource;
import org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor;
import org.codehaus.plexus.interpolation.PrefixedObjectValueSource;
import org.codehaus.plexus.interpolation.PrefixedValueSourceWrapper;
@ -90,21 +88,14 @@ public abstract class AbstractStringBasedModelInterpolator
}
protected List<ValueSource> createValueSources( final Model model, final File projectDir,
final ModelBuildingRequest config,
final ModelProblemCollector problems )
final ModelBuildingRequest config )
{
Properties modelProperties = model.getProperties();
ValueSource projectPrefixValueSource = new PrefixedObjectValueSource( PROJECT_PREFIXES, model, false );
ValueSource prefixlessObjectBasedValueSource = new ObjectBasedValueSource( model );
if ( config.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 )
{
prefixlessObjectBasedValueSource =
new ProblemDetectingValueSource( prefixlessObjectBasedValueSource, "", "project.", problems );
}
// NOTE: Order counts here!
List<ValueSource> valueSources = new ArrayList<>( 9 );
List<ValueSource> valueSources = new ArrayList<>( 8 );
if ( projectDir != null )
{
@ -159,8 +150,6 @@ public abstract class AbstractStringBasedModelInterpolator
}
} );
valueSources.add( prefixlessObjectBasedValueSource );
return valueSources;
}

View File

@ -1,86 +0,0 @@
package org.apache.maven.model.interpolation;
/*
* 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.
*/
import java.util.List;
import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.model.building.ModelProblem.Version;
import org.apache.maven.model.building.ModelProblemCollectorRequest;
import org.codehaus.plexus.interpolation.ValueSource;
/**
* Wraps another value source and intercepts interpolated expressions, checking for problems.
*
* @author Benjamin Bentmann
*/
class ProblemDetectingValueSource
implements ValueSource
{
private final ValueSource valueSource;
private final String bannedPrefix;
private final String newPrefix;
private final ModelProblemCollector problems;
ProblemDetectingValueSource( ValueSource valueSource, String bannedPrefix, String newPrefix,
ModelProblemCollector problems )
{
this.valueSource = valueSource;
this.bannedPrefix = bannedPrefix;
this.newPrefix = newPrefix;
this.problems = problems;
}
@Override
public Object getValue( String expression )
{
Object value = valueSource.getValue( expression );
if ( value != null && expression.startsWith( bannedPrefix ) )
{
String msg = "The expression ${" + expression + "} is deprecated.";
if ( newPrefix != null && newPrefix.length() > 0 )
{
msg += " Please use ${" + newPrefix + expression.substring( bannedPrefix.length() ) + "} instead.";
}
problems.add( new ModelProblemCollectorRequest( Severity.WARNING, Version.V20 ).setMessage( msg ) );
}
return value;
}
@Override
public List getFeedback()
{
return valueSource.getFeedback();
}
@Override
public void clearFeedback()
{
valueSource.clearFeedback();
}
}

View File

@ -85,7 +85,7 @@ public class StringSearchModelInterpolator
void interpolateObject( Object obj, Model model, File projectDir, ModelBuildingRequest config,
ModelProblemCollector problems )
{
List<? extends ValueSource> valueSources = createValueSources( model, projectDir, config, problems );
List<? extends ValueSource> valueSources = createValueSources( model, projectDir, config );
List<? extends InterpolationPostProcessor> postProcessors = createPostProcessors( model, projectDir, config );
InnerInterpolator innerInterpolator = createInterpolator( valueSources, postProcessors, problems );

View File

@ -107,7 +107,7 @@ public class StringVisitorModelInterpolator
public Model interpolateModel( Model model, File projectDir, ModelBuildingRequest config,
ModelProblemCollector problems )
{
List<? extends ValueSource> valueSources = createValueSources( model, projectDir, config, problems );
List<? extends ValueSource> valueSources = createValueSources( model, projectDir, config );
List<? extends InterpolationPostProcessor> postProcessors =
createPostProcessors( model, projectDir, config );

View File

@ -230,7 +230,7 @@ public abstract class AbstractModelInterpolatorTest
model.setVersion( "3.8.1" );
Dependency dep = new Dependency();
dep.setVersion( "${version}" );
dep.setVersion( "${project.version}" );
model.addDependency( dep );
@ -239,7 +239,7 @@ public abstract class AbstractModelInterpolatorTest
final SimpleProblemCollector collector = new SimpleProblemCollector();
Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
collector );
assertCollectorState( 0, 0, 1, collector );
assertCollectorState( 0, 0, 0, collector );
assertEquals( "3.8.1", ( out.getDependencies().get( 0 ) ).getVersion() );
}
@ -288,7 +288,7 @@ public abstract class AbstractModelInterpolatorTest
model.setArtifactId( "foo" );
Dependency dep = new Dependency();
dep.setVersion( "${artifactId}-${version}" );
dep.setVersion( "${project.artifactId}-${project.version}" );
model.addDependency( dep );
@ -297,7 +297,7 @@ public abstract class AbstractModelInterpolatorTest
final SimpleProblemCollector collector = new SimpleProblemCollector();
Model out = interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ),
collector );
assertCollectorState( 0, 0, 2, collector );
assertCollectorState( 0, 0, 0, collector );
assertEquals( "foo-3.8.1", ( out.getDependencies().get( 0 ) ).getVersion() );
}
@ -426,25 +426,19 @@ public abstract class AbstractModelInterpolatorTest
build.addResource( res );
Resource res2 = new Resource();
res2.setDirectory( "${build.sourceDirectory}" );
build.addResource( res2 );
model.setBuild( build );
ModelInterpolator interpolator = createInterpolator();
final SimpleProblemCollector collector = new SimpleProblemCollector();
Model out = interpolator.interpolateModel( model, null, createModelBuildingRequest( context ), collector );
assertCollectorState( 0, 0, 1, collector );
assertCollectorState( 0, 0, 0, collector );
List<Resource> outResources = out.getBuild().getResources();
Iterator<Resource> resIt = outResources.iterator();
assertEquals( build.getSourceDirectory(), resIt.next().getDirectory() );
assertEquals( build.getSourceDirectory(), resIt.next().getDirectory() );
}
@Test