You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Enrico Olivelli <eo...@gmail.com> on 2018/12/28 23:20:48 UTC

Re: [maven] 01/01: [MNG-6213] Validate scope in dependencyManagement

Il ven 28 dic 2018, 23:40 <mi...@apache.org> ha scritto:

> This is an automated email from the ASF dual-hosted git repository.
>
> michaelo pushed a commit to branch MNG-6213
> in repository https://gitbox.apache.org/repos/asf/maven.git
>
> commit 859e344f4d5f7bfa00caf7343ea6554138e9dcf7
> Author: Michael Warnecke <13...@nordakademie.de>
> AuthorDate: Sat Sep 23 18:37:09 2017 +0200
>
>     [MNG-6213] Validate scope in dependencyManagement
>
>     This closes #131
> ---
>  .../model/validation/DefaultModelValidator.java    | 10 ++-
>  .../validation/DefaultModelValidatorTest.java      | 10 +++
>  .../validation/bad-dependency-management-scope.xml | 72
> ++++++++++++++++++++++
>  3 files changed, 90 insertions(+), 2 deletions(-)
>
> diff --git
> a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
> b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
> index 1c84776..f58d03a 100644
> ---
> a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
> +++
> b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
> @@ -105,13 +105,13 @@ public class DefaultModelValidator
>                                    + ", the parent element cannot have the
> same groupId:artifactId as the project.",
>                                parent );
>              }
> -
> +
>              if ( equals( "LATEST", parent.getVersion() ) || equals(
> "RELEASE", parent.getVersion() ) )
>              {
>                  addViolation( problems, Severity.WARNING, Version.BASE,
> "parent.version", null,
>                                "is either LATEST or RELEASE (both of them
> are being deprecated)", parent );
>              }
> -
> +
>          }
>
>          if ( request.getValidationLevel() >=
> ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 )
> @@ -598,6 +598,12 @@ public class DefaultModelValidator
>
>                      validateEffectiveModelAgainstDependency( prefix,
> problems, m, d, request );
>                  }
> +                else
> +                {
> +                    validateEnum( prefix + "scope", problems,
> Severity.WARNING, Version.V20, d.getScope(),
> +                                  d.getManagementKey(), d, "provided",
> "compile", "runtime", "test", "system",
> +                                  "import" );
>

Don't we have a constant for the list of available scopes?

Enrico


+                }
>              }
>          }
>      }
> diff --git
> a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
> b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
> index 3f31526..a9d4c00 100644
> ---
> a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
> +++
> b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
> @@ -339,6 +339,16 @@ public class DefaultModelValidatorTest
>          assertTrue( result.getWarnings().get( 1 ).contains( "test:g" ) );
>      }
>
> +    public void testBadDependencyManagementScope()
> +        throws Exception
> +    {
> +        SimpleProblemCollector result = validate(
> "bad-dependency-management-scope.xml" );
> +
> +        assertViolations( result, 0, 0, 1 );
> +
> +        assertContains( result.getWarnings().get( 0 ), "test:g" );
> +    }
> +
>      public void testBadDependencyVersion()
>          throws Exception
>      {
> diff --git
> a/maven-model-builder/src/test/resources/poms/validation/bad-dependency-management-scope.xml
> b/maven-model-builder/src/test/resources/poms/validation/bad-dependency-management-scope.xml
> new file mode 100644
> index 0000000..6b37a85
> --- /dev/null
> +++
> b/maven-model-builder/src/test/resources/poms/validation/bad-dependency-management-scope.xml
> @@ -0,0 +1,72 @@
> +<!--
> +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>
> +  <modelVersion>4.0.0</modelVersion>
> +  <artifactId>aid</artifactId>
> +  <groupId>gid</groupId>
> +  <version>0.1</version>
> +
> +  <dependencyManagement>
> +    <dependencies>
> +      <dependency>
> +        <groupId>test</groupId>
> +        <artifactId>a</artifactId>
> +        <version>0.2</version>
> +      </dependency>
> +      <dependency>
> +        <groupId>test</groupId>
> +        <artifactId>b</artifactId>
> +        <version>0.2</version>
> +        <scope>compile</scope>
> +      </dependency>
> +      <dependency>
> +        <groupId>test</groupId>
> +        <artifactId>c</artifactId>
> +        <version>0.2</version>
> +        <scope>runtime</scope>
> +      </dependency>
> +      <dependency>
> +        <groupId>test</groupId>
> +        <artifactId>d</artifactId>
> +        <version>0.2</version>
> +        <scope>test</scope>
> +      </dependency>
> +      <dependency>
> +        <groupId>test</groupId>
> +        <artifactId>e</artifactId>
> +        <version>0.2</version>
> +        <scope>provided</scope>
> +      </dependency>
> +      <dependency>
> +        <groupId>test</groupId>
> +        <artifactId>f</artifactId>
> +        <version>0.2</version>
> +        <scope>import</scope>
> +      </dependency>
> +      <dependency>
> +        <groupId>test</groupId>
> +        <artifactId>g</artifactId>
> +        <version>1</version>
> +        <type>pom</type>
> +        <scope>include</scope>
> +      </dependency>
> +    </dependencies>
> +  </dependencyManagement>
> +</project>
>
> --


-- Enrico Olivelli

Re: [maven] 01/01: [MNG-6213] Validate scope in dependencyManagement

Posted by Enrico Olivelli <eo...@gmail.com>.
Il sab 29 dic 2018, 00:36 Michael Osipov <mi...@apache.org> ha scritto:

> Am 2018-12-29 um 00:20 schrieb Enrico Olivelli:
> > Il ven 28 dic 2018, 23:40 <mi...@apache.org> ha scritto:
> >
> >> This is an automated email from the ASF dual-hosted git repository.
> >>
> >> michaelo pushed a commit to branch MNG-6213
> >> in repository https://gitbox.apache.org/repos/asf/maven.git
> >>
> >> commit 859e344f4d5f7bfa00caf7343ea6554138e9dcf7
> >> Author: Michael Warnecke <13...@nordakademie.de>
> >> AuthorDate: Sat Sep 23 18:37:09 2017 +0200
> >>
> >>      [MNG-6213] Validate scope in dependencyManagement
> >>
> >>      This closes #131
> >> ---
> >>   .../model/validation/DefaultModelValidator.java    | 10 ++-
> >>   .../validation/DefaultModelValidatorTest.java      | 10 +++
> >>   .../validation/bad-dependency-management-scope.xml | 72
> >> ++++++++++++++++++++++
> >>   3 files changed, 90 insertions(+), 2 deletions(-)
> >>
> >> diff --git
> >>
> a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
> >>
> b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
> >> index 1c84776..f58d03a 100644
> >> ---
> >>
> a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
> >> +++
> >>
> b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
> >> @@ -105,13 +105,13 @@ public class DefaultModelValidator
> >>                                     + ", the parent element cannot have
> the
> >> same groupId:artifactId as the project.",
> >>                                 parent );
> >>               }
> >> -
> >> +
> >>               if ( equals( "LATEST", parent.getVersion() ) || equals(
> >> "RELEASE", parent.getVersion() ) )
> >>               {
> >>                   addViolation( problems, Severity.WARNING,
> Version.BASE,
> >> "parent.version", null,
> >>                                 "is either LATEST or RELEASE (both of
> them
> >> are being deprecated)", parent );
> >>               }
> >> -
> >> +
> >>           }
> >>
> >>           if ( request.getValidationLevel() >=
> >> ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 )
> >> @@ -598,6 +598,12 @@ public class DefaultModelValidator
> >>
> >>                       validateEffectiveModelAgainstDependency( prefix,
> >> problems, m, d, request );
> >>                   }
> >> +                else
> >> +                {
> >> +                    validateEnum( prefix + "scope", problems,
> >> Severity.WARNING, Version.V20, d.getScope(),
> >> +                                  d.getManagementKey(), d, "provided",
> >> "compile", "runtime", "test", "system",
> >> +                                  "import" );
> >>
> >
> > Don't we have a constant for the list of available scopes?
>
> None which I am aware of. Watch carefully because regular deps don't
> have "import" scope.
>

Oh I see,
Thanks for your advice

Enrico

> --


-- Enrico Olivelli

Re: [maven] 01/01: [MNG-6213] Validate scope in dependencyManagement

Posted by Michael Osipov <mi...@apache.org>.
Am 2018-12-29 um 00:20 schrieb Enrico Olivelli:
> Il ven 28 dic 2018, 23:40 <mi...@apache.org> ha scritto:
> 
>> This is an automated email from the ASF dual-hosted git repository.
>>
>> michaelo pushed a commit to branch MNG-6213
>> in repository https://gitbox.apache.org/repos/asf/maven.git
>>
>> commit 859e344f4d5f7bfa00caf7343ea6554138e9dcf7
>> Author: Michael Warnecke <13...@nordakademie.de>
>> AuthorDate: Sat Sep 23 18:37:09 2017 +0200
>>
>>      [MNG-6213] Validate scope in dependencyManagement
>>
>>      This closes #131
>> ---
>>   .../model/validation/DefaultModelValidator.java    | 10 ++-
>>   .../validation/DefaultModelValidatorTest.java      | 10 +++
>>   .../validation/bad-dependency-management-scope.xml | 72
>> ++++++++++++++++++++++
>>   3 files changed, 90 insertions(+), 2 deletions(-)
>>
>> diff --git
>> a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
>> b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
>> index 1c84776..f58d03a 100644
>> ---
>> a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
>> +++
>> b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
>> @@ -105,13 +105,13 @@ public class DefaultModelValidator
>>                                     + ", the parent element cannot have the
>> same groupId:artifactId as the project.",
>>                                 parent );
>>               }
>> -
>> +
>>               if ( equals( "LATEST", parent.getVersion() ) || equals(
>> "RELEASE", parent.getVersion() ) )
>>               {
>>                   addViolation( problems, Severity.WARNING, Version.BASE,
>> "parent.version", null,
>>                                 "is either LATEST or RELEASE (both of them
>> are being deprecated)", parent );
>>               }
>> -
>> +
>>           }
>>
>>           if ( request.getValidationLevel() >=
>> ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 )
>> @@ -598,6 +598,12 @@ public class DefaultModelValidator
>>
>>                       validateEffectiveModelAgainstDependency( prefix,
>> problems, m, d, request );
>>                   }
>> +                else
>> +                {
>> +                    validateEnum( prefix + "scope", problems,
>> Severity.WARNING, Version.V20, d.getScope(),
>> +                                  d.getManagementKey(), d, "provided",
>> "compile", "runtime", "test", "system",
>> +                                  "import" );
>>
> 
> Don't we have a constant for the list of available scopes?

None which I am aware of. Watch carefully because regular deps don't 
have "import" scope.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org