mirror of https://github.com/apache/maven.git
[MNG-6305] Validation of CI friendly version incorrect
o Checkin that only the three expression changelist, revision and sha1 are valid in a version. o Added some tests.
This commit is contained in:
parent
df5169bdf9
commit
2295c17b45
|
@ -61,6 +61,12 @@ public abstract class AbstractStringBasedModelInterpolator
|
|||
public static final String CHANGELIST_PROPERTY = "changelist";
|
||||
|
||||
public static final String REVISION_PROPERTY = "revision";
|
||||
|
||||
public static final String SHA1_PROPERTY_EXPRESSION = "${" + SHA1_PROPERTY + "}";
|
||||
|
||||
public static final String CHANGELIST_PROPERTY_EXPRESSION = "${" + CHANGELIST_PROPERTY + "}";
|
||||
|
||||
public static final String REVISION_PROPERTY_EXPRESSION = "${" + REVISION_PROPERTY + "}";
|
||||
|
||||
private static final List<String> PROJECT_PREFIXES = Arrays.asList( "pom.", "project." );
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.maven.model.Activation;
|
||||
|
@ -65,6 +66,13 @@ public class DefaultModelValidator
|
|||
implements ModelValidator
|
||||
{
|
||||
|
||||
private static final Pattern CI_FRIENDLY_EXPRESSION = Pattern.compile( "\\$\\{(.+?)\\}" );
|
||||
|
||||
private static final List<String> CI_FRIENDLY_POSSIBLE_PROPERTY_NAMES =
|
||||
Arrays.asList( AbstractStringBasedModelInterpolator.REVISION_PROPERTY,
|
||||
AbstractStringBasedModelInterpolator.CHANGELIST_PROPERTY,
|
||||
AbstractStringBasedModelInterpolator.SHA1_PROPERTY );
|
||||
|
||||
private static final Pattern ID_REGEX = Pattern.compile( "[A-Za-z0-9_\\-.]+" );
|
||||
|
||||
private static final Pattern ID_WITH_WILDCARDS_REGEX = Pattern.compile( "[A-Za-z0-9_\\-.?*]+" );
|
||||
|
@ -532,7 +540,7 @@ private void validate20RawDependenciesSelfReferencing( ModelProblemCollector pro
|
|||
ModelBuildingRequest request )
|
||||
{
|
||||
// We only check for groupId/artifactId cause if there is another
|
||||
// module with the same groupId/artifactId this will fail the build
|
||||
// module with the same groupId/artifactId this will fail the build
|
||||
// earlier like "Project '...' is duplicated in the reactor.
|
||||
// So it is sufficient to check only groupId/artifactId and not the
|
||||
// packaging type.
|
||||
|
@ -855,7 +863,6 @@ private boolean validateStringNoExpression( String fieldName, ModelProblemCollec
|
|||
private boolean validateVersionNoExpression( String fieldName, ModelProblemCollector problems, Severity severity,
|
||||
Version version, String string, InputLocationTracker tracker )
|
||||
{
|
||||
|
||||
if ( !hasExpression( string ) )
|
||||
{
|
||||
return true;
|
||||
|
@ -868,18 +875,19 @@ private boolean validateVersionNoExpression( String fieldName, ModelProblemColle
|
|||
// revision
|
||||
// sha1
|
||||
//
|
||||
string = string.trim();
|
||||
if ( string.contains( "${" + AbstractStringBasedModelInterpolator.CHANGELIST_PROPERTY + "}" )
|
||||
|| string.contains( "${" + AbstractStringBasedModelInterpolator.REVISION_PROPERTY + "}" )
|
||||
|| string.contains( "${" + AbstractStringBasedModelInterpolator.SHA1_PROPERTY + "}" ) )
|
||||
Matcher m = CI_FRIENDLY_EXPRESSION.matcher( string.trim() );
|
||||
while ( m.find() )
|
||||
{
|
||||
return true;
|
||||
if ( !CI_FRIENDLY_POSSIBLE_PROPERTY_NAMES.contains( m.group( 1 ) ) )
|
||||
{
|
||||
addViolation( problems, severity, version, fieldName, null,
|
||||
"contains an expression but should be a constant.", tracker );
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
addViolation( problems, severity, version, fieldName, null, "contains an expression but should be a constant.",
|
||||
tracker );
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean hasExpression( String value )
|
||||
|
|
|
@ -419,18 +419,19 @@ public void testHardCodedSystemPath()
|
|||
assertViolations( result, 0, 0, 1 );
|
||||
|
||||
assertContains( result.getWarnings().get( 0 ),
|
||||
"'dependencies.dependency.systemPath' for test:a:jar should use a variable instead of a hard-coded path" );
|
||||
"'dependencies.dependency.systemPath' for test:a:jar should use a variable instead of a hard-coded path" );
|
||||
|
||||
SimpleProblemCollector result_31 = validateRaw( "hard-coded-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
|
||||
SimpleProblemCollector result_31 =
|
||||
validateRaw( "hard-coded-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
|
||||
|
||||
assertViolations( result_31, 0, 0, 3 );
|
||||
|
||||
assertContains( result_31.getWarnings().get( 0 ),
|
||||
"'dependencies.dependency.scope' for test:a:jar declares usage of deprecated 'system' scope" );
|
||||
"'dependencies.dependency.scope' for test:a:jar declares usage of deprecated 'system' scope" );
|
||||
assertContains( result_31.getWarnings().get( 1 ),
|
||||
"'dependencies.dependency.systemPath' for test:a:jar should use a variable instead of a hard-coded path" );
|
||||
"'dependencies.dependency.systemPath' for test:a:jar should use a variable instead of a hard-coded path" );
|
||||
assertContains( result_31.getWarnings().get( 2 ),
|
||||
"'dependencies.dependency.scope' for test:b:jar declares usage of deprecated 'system' scope" );
|
||||
"'dependencies.dependency.scope' for test:b:jar declares usage of deprecated 'system' scope" );
|
||||
|
||||
}
|
||||
|
||||
|
@ -625,22 +626,23 @@ public void testSystemPathRefersToProjectBasedir()
|
|||
assertViolations( result, 0, 0, 2 );
|
||||
|
||||
assertContains( result.getWarnings().get( 0 ),
|
||||
"'dependencies.dependency.systemPath' for test:a:jar should not point at files within the project directory" );
|
||||
"'dependencies.dependency.systemPath' for test:a:jar should not point at files within the project directory" );
|
||||
assertContains( result.getWarnings().get( 1 ),
|
||||
"'dependencies.dependency.systemPath' for test:b:jar should not point at files within the project directory" );
|
||||
"'dependencies.dependency.systemPath' for test:b:jar should not point at files within the project directory" );
|
||||
|
||||
SimpleProblemCollector result_31 = validateRaw( "basedir-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
|
||||
SimpleProblemCollector result_31 =
|
||||
validateRaw( "basedir-system-path.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_1 );
|
||||
|
||||
assertViolations( result_31, 0, 0, 4 );
|
||||
|
||||
assertContains( result_31.getWarnings().get( 0 ),
|
||||
"'dependencies.dependency.scope' for test:a:jar declares usage of deprecated 'system' scope" );
|
||||
"'dependencies.dependency.scope' for test:a:jar declares usage of deprecated 'system' scope" );
|
||||
assertContains( result_31.getWarnings().get( 1 ),
|
||||
"'dependencies.dependency.systemPath' for test:a:jar should not point at files within the project directory" );
|
||||
"'dependencies.dependency.systemPath' for test:a:jar should not point at files within the project directory" );
|
||||
assertContains( result_31.getWarnings().get( 2 ),
|
||||
"'dependencies.dependency.scope' for test:b:jar declares usage of deprecated 'system' scope" );
|
||||
"'dependencies.dependency.scope' for test:b:jar declares usage of deprecated 'system' scope" );
|
||||
assertContains( result_31.getWarnings().get( 3 ),
|
||||
"'dependencies.dependency.systemPath' for test:b:jar should not point at files within the project directory" );
|
||||
"'dependencies.dependency.systemPath' for test:b:jar should not point at files within the project directory" );
|
||||
}
|
||||
|
||||
public void testInvalidVersionInPluginManagement()
|
||||
|
@ -703,16 +705,16 @@ public void testMissingReportPluginVersion()
|
|||
}
|
||||
|
||||
public void testDeprecatedDependencyMetaversionsLatestAndRelease()
|
||||
throws Exception
|
||||
throws Exception
|
||||
{
|
||||
SimpleProblemCollector result = validateRaw( "deprecated-dependency-metaversions-latest-and-release.xml" );
|
||||
|
||||
assertViolations( result, 0, 0, 2 );
|
||||
|
||||
assertContains( result.getWarnings().get( 0 ),
|
||||
"'dependencies.dependency.version' for test:a:jar is either LATEST or RELEASE (both of them are being deprecated)" );
|
||||
"'dependencies.dependency.version' for test:a:jar is either LATEST or RELEASE (both of them are being deprecated)" );
|
||||
assertContains( result.getWarnings().get( 1 ),
|
||||
"'dependencies.dependency.version' for test:b:jar is either LATEST or RELEASE (both of them are being deprecated)" );
|
||||
"'dependencies.dependency.version' for test:b:jar is either LATEST or RELEASE (both of them are being deprecated)" );
|
||||
}
|
||||
|
||||
public void testSelfReferencingDependencyInRawModel()
|
||||
|
@ -727,4 +729,56 @@ public void testSelfReferencingDependencyInRawModel()
|
|||
|
||||
}
|
||||
|
||||
public void testCiFriendlySha1()
|
||||
throws Exception
|
||||
{
|
||||
SimpleProblemCollector result = validateRaw( "raw-model/ok-ci-friendly-sha1.xml" );
|
||||
assertViolations( result, 0, 0, 0 );
|
||||
}
|
||||
|
||||
public void testCiFriendlyRevision()
|
||||
throws Exception
|
||||
{
|
||||
SimpleProblemCollector result = validateRaw( "raw-model/ok-ci-friendly-revision.xml" );
|
||||
assertViolations( result, 0, 0, 0 );
|
||||
}
|
||||
|
||||
public void testCiFriendlyChangeList()
|
||||
throws Exception
|
||||
{
|
||||
SimpleProblemCollector result = validateRaw( "raw-model/ok-ci-friendly-changelist.xml" );
|
||||
assertViolations( result, 0, 0, 0 );
|
||||
}
|
||||
|
||||
public void testCiFriendlyAllExpressions()
|
||||
throws Exception
|
||||
{
|
||||
SimpleProblemCollector result = validateRaw( "raw-model/ok-ci-friendly-all-expressions.xml" );
|
||||
assertViolations( result, 0, 0, 0 );
|
||||
}
|
||||
|
||||
public void testCiFriendlyBad()
|
||||
throws Exception
|
||||
{
|
||||
SimpleProblemCollector result = validateRaw( "raw-model/bad-ci-friendly.xml" );
|
||||
assertViolations( result, 0, 0, 1 );
|
||||
assertEquals( "'version' contains an expression but should be a constant.", result.getWarnings().get( 0 ) );
|
||||
}
|
||||
|
||||
public void testCiFriendlyBadSha1Plus()
|
||||
throws Exception
|
||||
{
|
||||
SimpleProblemCollector result = validateRaw( "raw-model/bad-ci-friendly-sha1plus.xml" );
|
||||
assertViolations( result, 0, 0, 1 );
|
||||
assertEquals( "'version' contains an expression but should be a constant.", result.getWarnings().get( 0 ) );
|
||||
}
|
||||
|
||||
public void testCiFriendlyBadSha1Plus2()
|
||||
throws Exception
|
||||
{
|
||||
SimpleProblemCollector result = validateRaw( "raw-model/bad-ci-friendly-sha1plus2.xml" );
|
||||
assertViolations( result, 0, 0, 1 );
|
||||
assertEquals( "'version' contains an expression but should be a constant.", result.getWarnings().get( 0 ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<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>com.example.group</groupId>
|
||||
<artifactId>valid-version-sha1plus</artifactId>
|
||||
<version>${sha1}${wrong}</version>
|
||||
|
||||
<description>
|
||||
This will test if the validation for the ci friendly versions
|
||||
is working correct.
|
||||
</description>
|
||||
</project>
|
|
@ -0,0 +1,31 @@
|
|||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<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>com.example.group</groupId>
|
||||
<artifactId>valid-version-sha1plus</artifactId>
|
||||
<version>${sha1}${wrong}${revision}</version>
|
||||
|
||||
<description>
|
||||
This will test if the validation for the ci friendly versions
|
||||
is working correct.
|
||||
</description>
|
||||
</project>
|
|
@ -0,0 +1,31 @@
|
|||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<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>com.example.group</groupId>
|
||||
<artifactId>valid-version-wrong</artifactId>
|
||||
<version>${wrong}</version>
|
||||
|
||||
<description>
|
||||
This will test if the validation for the ci friendly versions
|
||||
is working correct.
|
||||
</description>
|
||||
</project>
|
|
@ -0,0 +1,31 @@
|
|||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<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>com.example.group</groupId>
|
||||
<artifactId>valid-version-sha1</artifactId>
|
||||
<version>${revision}${changelist}${sha1}</version>
|
||||
|
||||
<description>
|
||||
This will test if the validation for the ci friendly versions
|
||||
is working correct.
|
||||
</description>
|
||||
</project>
|
|
@ -0,0 +1,31 @@
|
|||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<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>com.example.group</groupId>
|
||||
<artifactId>valid-version-changelist</artifactId>
|
||||
<version>${changelist}</version>
|
||||
|
||||
<description>
|
||||
This will test if the validation for the ci friendly versions
|
||||
is working correct.
|
||||
</description>
|
||||
</project>
|
|
@ -0,0 +1,31 @@
|
|||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<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>com.example.group</groupId>
|
||||
<artifactId>valid-version-revision</artifactId>
|
||||
<version>${revision}</version>
|
||||
|
||||
<description>
|
||||
This will test if the validation for the ci friendly versions
|
||||
is working correct.
|
||||
</description>
|
||||
</project>
|
|
@ -0,0 +1,31 @@
|
|||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<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>com.example.group</groupId>
|
||||
<artifactId>valid-version-sha1</artifactId>
|
||||
<version>${sha1}</version>
|
||||
|
||||
<description>
|
||||
This will test if the validation for the ci friendly versions
|
||||
is working correct. This c
|
||||
</description>
|
||||
</project>
|
Loading…
Reference in New Issue