You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2005/10/05 20:31:43 UTC

svn commit: r295069 - in /maven/components/trunk: maven-core-it/README.txt maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java maven-project/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java

Author: jdcasey
Date: Wed Oct  5 11:31:37 2005
New Revision: 295069

URL: http://svn.apache.org/viewcvs?rev=295069&view=rev
Log:
Resolving: MNG-1021, MNG-1049

o Added check for projectArtifact.isResolved() before attempting to read the model from it within DefaultMavenProjectBuilder, otherwise, stub out a dummy model just like if an ArtifactResolutionException occurs.

o Disabled metadata handling for AttachedArtifact...attachments should be slaves to the main artifact, deriving version info and metadata from it.

o Cleaned up entry for it2003 in maven-core-it/README.txt...that test has been removed.


Modified:
    maven/components/trunk/maven-core-it/README.txt
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java

Modified: maven/components/trunk/maven-core-it/README.txt
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-core-it/README.txt?rev=295069&r1=295068&r2=295069&view=diff
==============================================================================
--- maven/components/trunk/maven-core-it/README.txt (original)
+++ maven/components/trunk/maven-core-it/README.txt Wed Oct  5 11:31:37 2005
@@ -312,11 +312,5 @@
 
 it2002: Test the release plugin.
 
-it2003: Test that source artifacts share the same build number as the main
-        project artifact. This is only defined in the 2000 series because of
-        the exorbitant time it takes to execute (it uses a uniquely defined
-        local repository, to avoid pollution from existing artifacts in 
-        pattern matching of the results).
-
 -------------------------------------------------------------------------------
 

Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java?rev=295069&r1=295068&r2=295069&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java Wed Oct  5 11:31:37 2005
@@ -324,6 +324,7 @@
     {
         Artifact projectArtifact;
 
+        // if the artifact is not a POM, we need to construct a POM artifact based on the artifact parameter given.
         if ( "pom".equals( artifact.getType() ) )
         {
             projectArtifact = artifact;
@@ -342,62 +343,67 @@
         Model model;
         if ( project == null )
         {
-            // TODO: can't assume artifact is a POM
             try
             {
                 artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository );
 
                 File file = projectArtifact.getFile();
-                model = readModel( file );
-
-                String downloadUrl = null;
-                ArtifactStatus status = ArtifactStatus.NONE;
-
-                DistributionManagement distributionManagement = model.getDistributionManagement();
-                if ( distributionManagement != null )
+                if ( projectArtifact.isResolved() )
                 {
-                    downloadUrl = distributionManagement.getDownloadUrl();
+                    model = readModel( file );
 
-                    status = ArtifactStatus.valueOf( distributionManagement.getStatus() );
-                }
+                    String downloadUrl = null;
+                    ArtifactStatus status = ArtifactStatus.NONE;
 
-                // TODO: configurable actions dependant on status
-                if ( !projectArtifact.isSnapshot() && status.compareTo( ArtifactStatus.DEPLOYED ) < 0 )
-                {
-                    // use default policy (enabled, daily update, warn on bad checksum)
-                    ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy();
-                    // TODO: re-enable [MNG-798/865]
-                    policy.setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER );
+                    DistributionManagement distributionManagement = model.getDistributionManagement();
+                    if ( distributionManagement != null )
+                    {
+                        downloadUrl = distributionManagement.getDownloadUrl();
 
-                    if ( policy.checkOutOfDate( new Date( file.lastModified() ) ) )
+                        status = ArtifactStatus.valueOf( distributionManagement.getStatus() );
+                    }
+
+                    // TODO: configurable actions dependant on status
+                    if ( !projectArtifact.isSnapshot() && status.compareTo( ArtifactStatus.DEPLOYED ) < 0 )
                     {
-                        getLogger().info(
-                            projectArtifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" );
-                        try
-                        {
-                            projectArtifact.setResolved( false );
-                            artifactResolver.resolveAlways( projectArtifact, remoteArtifactRepositories,
-                                                            localRepository );
-                        }
-                        catch ( ArtifactResolutionException e )
+                        // use default policy (enabled, daily update, warn on bad checksum)
+                        ArtifactRepositoryPolicy policy = new ArtifactRepositoryPolicy();
+                        // TODO: re-enable [MNG-798/865]
+                        policy.setUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER );
+
+                        if ( policy.checkOutOfDate( new Date( file.lastModified() ) ) )
                         {
-                            getLogger().warn( "Error updating POM - using existing version" );
-                            getLogger().debug( "Cause", e );
+                            getLogger().info(
+                                projectArtifact.getArtifactId() + ": updating metadata due to status of '" + status + "'" );
+                            try
+                            {
+                                projectArtifact.setResolved( false );
+                                artifactResolver.resolveAlways( projectArtifact, remoteArtifactRepositories,
+                                                                localRepository );
+                            }
+                            catch ( ArtifactResolutionException e )
+                            {
+                                getLogger().warn( "Error updating POM - using existing version" );
+                                getLogger().debug( "Cause", e );
+                            }
                         }
                     }
-                }
 
-                // TODO: this is gross. Would like to give it the whole model, but maven-artifact shouldn't depend on that
-                // Can a maven-core implementation of the Artifact interface store it, and be used in the exceptions?
-                if ( downloadUrl != null )
-                {
-                    projectArtifact.setDownloadUrl( downloadUrl );
+                    // TODO: this is gross. Would like to give it the whole model, but maven-artifact shouldn't depend on that
+                    // Can a maven-core implementation of the Artifact interface store it, and be used in the exceptions?
+                    if ( downloadUrl != null )
+                    {
+                        projectArtifact.setDownloadUrl( downloadUrl );
+                    }
+                    else
+                    {
+                        projectArtifact.setDownloadUrl( model.getUrl() );
+                    }
                 }
                 else
                 {
-                    projectArtifact.setDownloadUrl( model.getUrl() );
+                    model = createStubModel( projectArtifact );
                 }
-
             }
             catch ( ArtifactResolutionException e )
             {
@@ -405,47 +411,53 @@
                 // only not found should have the below behaviour
 //                throw new ProjectBuildingException( "Unable to find the POM in the repository", e );
 
-                getLogger().warn( "\n  ***** Using defaults for missing POM " + projectArtifact.getId() + " *****\n" );
+                model = createStubModel( projectArtifact );
+            }
+        }
+        else
+        {
+            model = project.getModel();
+        }
 
-                model = new Model();
-                model.setModelVersion( "4.0.0" );
-                model.setArtifactId( projectArtifact.getArtifactId() );
-                model.setGroupId( projectArtifact.getGroupId() );
-                model.setVersion( projectArtifact.getVersion() );
-                // TODO: not correct in some instances
-                model.setPackaging( projectArtifact.getType() );
+        return model;
+    }
 
-                model.setDistributionManagement( new DistributionManagement() );
-                model.getDistributionManagement().setStatus( ArtifactStatus.GENERATED.toString() );
+    private Model createStubModel(Artifact projectArtifact)
+    {
+        getLogger().warn( "\n  ***** Using defaults for missing POM " + projectArtifact.getId() + " *****\n" );
+
+        Model model = new Model();
+        model.setModelVersion( "4.0.0" );
+        model.setArtifactId( projectArtifact.getArtifactId() );
+        model.setGroupId( projectArtifact.getGroupId() );
+        model.setVersion( projectArtifact.getVersion() );
+        // TODO: not correct in some instances
+        model.setPackaging( projectArtifact.getType() );
+
+        model.setDistributionManagement( new DistributionManagement() );
+        model.getDistributionManagement().setStatus( ArtifactStatus.GENERATED.toString() );
 
 /* TODO: we should only do this if we can verify the existence of the JAR itself
-                File file = artifact.getFile();
-                file.getParentFile().mkdirs();
+        File file = artifact.getFile();
+        file.getParentFile().mkdirs();
 
-                FileWriter writer = null;
-                try
-                {
-                    writer = new FileWriter( file );
+        FileWriter writer = null;
+        try
+        {
+            writer = new FileWriter( file );
 
-                    MavenXpp3Writer w = new MavenXpp3Writer();
-                    w.write( writer, model );
-                }
-                catch ( IOException ioe )
-                {
-                    getLogger().warn( "Attempted to write out a temporary generated POM, but failed", ioe );
-                }
-                finally
-                {
-                    IOUtil.close( writer );
-                }
-*/
-            }
+            MavenXpp3Writer w = new MavenXpp3Writer();
+            w.write( writer, model );
         }
-        else
+        catch ( IOException ioe )
         {
-            model = project.getModel();
+            getLogger().warn( "Attempted to write out a temporary generated POM, but failed", ioe );
         }
-
+        finally
+        {
+            IOUtil.close( writer );
+        }
+*/
         return model;
     }
 

Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java?rev=295069&r1=295068&r2=295069&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/AttachedArtifact.java Wed Oct  5 11:31:37 2005
@@ -4,10 +4,13 @@
 import org.apache.maven.artifact.DefaultArtifact;
 import org.apache.maven.artifact.InvalidArtifactRTException;
 import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.metadata.ArtifactMetadata;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
 import org.apache.maven.artifact.versioning.VersionRange;
 
+import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 
 public class AttachedArtifact
@@ -110,6 +113,16 @@
     public boolean isSnapshot()
     {
         return parent.isSnapshot();
+    }
+
+    public void addMetadata( ArtifactMetadata metadata )
+    {
+        // ignore. The parent artifact will handle metadata.
+    }
+
+    public Collection getMetadataList()
+    {
+        return Collections.EMPTY_LIST;
     }
 
 }