From 88d49cb04f4dcbe5ff9cae70f91ef3c85a3c50f6 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Fri, 12 Aug 2005 21:55:00 +0000 Subject: [PATCH] o Improving toString for Dependency in the 4.0.0 version codeSegment in maven.mdo o Improving error messages for ResourceDoesNotExistException in the transformations o Adding specificity to the dependency validation stuff, to output which dependency is offending... o Added it1013 to show off the new dependency validation stuff. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@232399 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractVersionTransformation.java | 4 +- .../transform/SnapshotTransformation.java | 4 ++ maven-core-it/it1013/expected-results.txt | 3 + maven-core-it/it1013/goals.txt | 1 + maven-core-it/it1013/pom.xml | 14 +++++ .../java/org/apache/maven/it1001/Dummy.java | 5 ++ maven-model/maven.mdo | 11 +++- .../validation/DefaultModelValidator.java | 61 ++++++++++++++++--- .../validation/DefaultModelValidatorTest.java | 22 ++----- 9 files changed, 97 insertions(+), 28 deletions(-) create mode 100644 maven-core-it/it1013/expected-results.txt create mode 100644 maven-core-it/it1013/goals.txt create mode 100644 maven-core-it/it1013/pom.xml create mode 100644 maven-core-it/it1013/src/main/java/org/apache/maven/it1001/Dummy.java diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java index 36f4095dd3..7b6ab2a730 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java @@ -98,7 +98,9 @@ public abstract class AbstractVersionTransformation } catch ( ResourceDoesNotExistException e ) { - getLogger().debug( "Error resolving artifact version from metadata.", e ); + getLogger().debug( + "Artifact version metadata for: " + artifact.getId() + + " could not be found on repository: " + repository.getId(), e ); continue; } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java index 37c1193383..f678203d4a 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java @@ -69,6 +69,10 @@ public class SnapshotTransformation } catch ( ResourceDoesNotExistException e ) { + getLogger().debug( + "Snapshot version metadata for: " + artifact.getId() + + " not found. Creating a new metadata instance.", e ); + // ignore. We'll be creating this metadata if it doesn't exist... metadata = (SnapshotArtifactMetadata) createMetadata( artifact ); } diff --git a/maven-core-it/it1013/expected-results.txt b/maven-core-it/it1013/expected-results.txt new file mode 100644 index 0000000000..b576289f9b --- /dev/null +++ b/maven-core-it/it1013/expected-results.txt @@ -0,0 +1,3 @@ +target/classes/org/apache/maven/it0000/Person.class +target/test-classes/org/apache/maven/it0000/PersonTest.class +target/maven-core-it0000-1.0.jar diff --git a/maven-core-it/it1013/goals.txt b/maven-core-it/it1013/goals.txt new file mode 100644 index 0000000000..ba3bd78738 --- /dev/null +++ b/maven-core-it/it1013/goals.txt @@ -0,0 +1 @@ +package diff --git a/maven-core-it/it1013/pom.xml b/maven-core-it/it1013/pom.xml new file mode 100644 index 0000000000..4252c584d1 --- /dev/null +++ b/maven-core-it/it1013/pom.xml @@ -0,0 +1,14 @@ + + 4.0.0 + org.apache.maven.it + maven-core-it1001 + jar + 1.0 + + + + junit + junit + + + diff --git a/maven-core-it/it1013/src/main/java/org/apache/maven/it1001/Dummy.java b/maven-core-it/it1013/src/main/java/org/apache/maven/it1001/Dummy.java new file mode 100644 index 0000000000..481597cd1d --- /dev/null +++ b/maven-core-it/it1013/src/main/java/org/apache/maven/it1001/Dummy.java @@ -0,0 +1,5 @@ +package org.apache.maven.it1000; + +public class Dummy +{ +} diff --git a/maven-model/maven.mdo b/maven-model/maven.mdo index 245c7a7e77..0907fa6d94 100644 --- a/maven-model/maven.mdo +++ b/maven-model/maven.mdo @@ -1265,7 +1265,7 @@ - 3.0.0+ + 3.0.0 + + 4.0.0 + + 4.0.0 + *
    + *
  • string.length != null + *
  • string.length > 0 + *
+ */ + private boolean validateSubElementStringNotEmpty( Object subElementInstance, String fieldName, ModelValidationResult result, String string ) + { + if ( !validateSubElementNotNull( subElementInstance, fieldName, result, string ) ) + { + return false; + } + + if ( string.length() > 0 ) + { + return true; + } + + result.addMessage( "In " + subElementInstance + ":\n\n -> '" + fieldName + "' is missing." ); return false; } @@ -187,4 +209,23 @@ public class DefaultModelValidator return false; } + + /** + * Asserts: + *

+ *

    + *
  • string != null + *
+ */ + private boolean validateSubElementNotNull( Object subElementInstance, String fieldName, ModelValidationResult result, Object object ) + { + if ( object != null ) + { + return true; + } + + result.addMessage( "In " + subElementInstance + ":\n\n -> '" + fieldName + "' is missing." ); + + return false; + } } diff --git a/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java b/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java index 831c33c1dd..7557849d34 100644 --- a/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/validation/DefaultModelValidatorTest.java @@ -72,7 +72,7 @@ public class DefaultModelValidatorTest assertEquals( 1, result.getMessageCount() ); - assertEquals( "'packaging' is empty.", result.getMessage( 0 ) ); + assertEquals( "'packaging' is missing.", result.getMessage( 0 ) ); } public void testMissingVersion() @@ -92,7 +92,7 @@ public class DefaultModelValidatorTest assertEquals( 1, result.getMessageCount() ); - assertEquals( "'dependencies.dependency.artifactId' is missing.", result.getMessage( 0 ) ); + assertTrue( result.getMessage( 0 ).indexOf( "'dependencies.dependency.artifactId' is missing." ) > -1 ); } public void testMissingDependencyGroupId() @@ -102,7 +102,7 @@ public class DefaultModelValidatorTest assertEquals( 1, result.getMessageCount() ); - assertEquals( "'dependencies.dependency.groupId' is missing.", result.getMessage( 0 ) ); + assertTrue( result.getMessage( 0 ).indexOf( "'dependencies.dependency.groupId' is missing." ) > -1 ); } public void testMissingDependencyVersion() @@ -112,7 +112,7 @@ public class DefaultModelValidatorTest assertEquals( 1, result.getMessageCount() ); - assertEquals( "'dependencies.dependency.version' is missing.", result.getMessage( 0 ) ); + assertTrue( result.getMessage( 0 ).indexOf( "'dependencies.dependency.version' is missing." ) > -1 ); } public void testMissingDependencyManagementArtifactId() @@ -122,7 +122,7 @@ public class DefaultModelValidatorTest assertEquals( 1, result.getMessageCount() ); - assertEquals( "'dependencyManagement.dependencies.dependency.artifactId' is missing.", result.getMessage( 0 ) ); + assertTrue( result.getMessage( 0 ).indexOf( "'dependencyManagement.dependencies.dependency.artifactId' is missing." ) > -1 ); } public void testMissingDependencyManagementGroupId() @@ -132,17 +132,7 @@ public class DefaultModelValidatorTest assertEquals( 1, result.getMessageCount() ); - assertEquals( "'dependencyManagement.dependencies.dependency.groupId' is missing.", result.getMessage( 0 ) ); - } - - public void testMissingDependencyManagementVersion() - throws Exception - { - ModelValidationResult result = validate( "missing-dependency-mgmt-version-pom.xml" ); - - assertEquals( 1, result.getMessageCount() ); - - assertEquals( "'dependencyManagement.dependencies.dependency.version' is missing.", result.getMessage( 0 ) ); + assertTrue( result.getMessage( 0 ).indexOf( "'dependencyManagement.dependencies.dependency.groupId' is missing." ) > -1 ); } public void testMissingAll()