maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sisb...@apache.org
Subject svn commit: r700331 - in /maven/components/trunk/maven-project/src/main/java/org/apache/maven/project: DefaultMavenProjectBuilder.java DefaultRepositoryHelper.java RepositoryHelper.java
Date Tue, 30 Sep 2008 04:13:09 GMT
Author: sisbell
Date: Mon Sep 29 21:13:08 2008
New Revision: 700331

URL: http://svn.apache.org/viewvc?rev=700331&view=rev
Log:
Small perf tweak.

Modified:
    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/DefaultRepositoryHelper.java
    maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/RepositoryHelper.java

Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java?rev=700331&r1=700330&r2=700331&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
Mon Sep 29 21:13:08 2008
@@ -166,7 +166,8 @@
             return project;
         }        
         
-        File f = artifact.getFile();
+        File f = (artifact.getFile() != null) ? artifact.getFile() :
+                new File( localRepository.getBasedir(), localRepository.pathOf( artifact
) );;
         repositoryHelper.findModelFromRepository( artifact, remoteArtifactRepositories, localRepository
);
 
         ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setLocalRepository(
localRepository );

Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultRepositoryHelper.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultRepositoryHelper.java?rev=700331&r1=700330&r2=700331&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultRepositoryHelper.java
(original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/DefaultRepositoryHelper.java
Mon Sep 29 21:13:08 2008
@@ -74,18 +74,23 @@
 
     private MavenXpp3Reader modelReader;
 
-    private static HashMap<String, Model> cache = new HashMap<String, Model>();
+    private static HashMap<String, Artifact> cache = new HashMap<String, Artifact>();
 
     private Logger getLogger()
     {
         return logger;
     }
 
-    public Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories,
+    public void findModelFromRepository( Artifact artifact, List remoteArtifactRepositories,
                                           ArtifactRepository localRepository )
         throws ProjectBuildingException
     {
 
+        if(cache.containsKey(artifact.getId()))
+        {
+            artifact.setFile(cache.get(artifact.getId()).getFile());
+        }
+
         String projectId = safeVersionlessKey( artifact.getGroupId(), artifact.getArtifactId()
);
         remoteArtifactRepositories = normalizeToArtifactRepositories( remoteArtifactRepositories,
projectId );
 
@@ -106,48 +111,13 @@
                                                                      artifact.getVersion(),
artifact.getScope() );
         }
 
-        Model legacy_model;
         try
         {
             artifactResolver.resolve( projectArtifact, remoteArtifactRepositories, localRepository
);
 
             File file = projectArtifact.getFile();
             artifact.setFile( file );
-            if(cache.containsKey(projectId))
-            {
-                legacy_model = cache.get(projectId);
-            }
-            else
-            {
-                legacy_model = readModelLegacy( projectId, file, false );
-                cache.put(projectId, legacy_model);
-            }
-
-            String downloadUrl = null;
-
-            ArtifactStatus status = ArtifactStatus.NONE;
-
-            DistributionManagement distributionManagement = legacy_model.getDistributionManagement();
-
-            if ( distributionManagement != null )
-            {
-                downloadUrl = distributionManagement.getDownloadUrl();
-
-                status = ArtifactStatus.valueOf( distributionManagement.getStatus() );
-            }
-
-            checkStatusAndUpdate( projectArtifact, status, file, remoteArtifactRepositories,
localRepository );
-
-            // 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( legacy_model.getUrl() );
-            }
+            cache.put(artifact.getId(), artifact);
         }
         catch ( ArtifactResolutionException e )
         {
@@ -160,8 +130,6 @@
                                                 "POM '" + projectId + "' not found in repository:
" + e.getMessage(),
                                                 e );
         }
-
-        return legacy_model;
     }
 
     public List buildArtifactRepositories( Model model )
@@ -277,56 +245,6 @@
         return ArtifactUtils.versionlessKey( gid, aid );
     }
 
-    private void checkModelVersion( String modelSource, String projectId, File file )
-        throws InvalidProjectModelException
-    {
-        if ( modelSource.indexOf( "<modelVersion>4.0.0" ) < 0 )
-        {
-            throw new InvalidProjectModelException( projectId, "Not a v" + MAVEN_MODEL_VERSION
+ " POM.", file );
-        }
-    }
-
-    private Model readModelLegacy( String projectId, File file, boolean strict )
-        throws ProjectBuildingException
-    {
-        Reader reader = null;
-        try
-        {
-            reader = ReaderFactory.newXmlReader( file );
-
-            String modelSource = IOUtil.toString( reader );
-
-            checkModelVersion( modelSource, projectId, file );
-
-            StringReader sReader = new StringReader( modelSource );
-
-            try
-            {
-                return new MavenXpp3Reader().read( sReader, strict );
-            }
-            catch ( XmlPullParserException e )
-            {
-                throw new InvalidProjectModelException( projectId, "Parse error reading POM.
Reason: " + e.getMessage(),
-                                                        file, e );
-            }
-        }
-        catch ( FileNotFoundException e )
-        {
-            throw new ProjectBuildingException( projectId,
-                                                "Could not find the model file '" + file.getAbsolutePath()
+ "'.", file,
-                                                e );
-        }
-        catch ( IOException e )
-        {
-            throw new ProjectBuildingException( projectId, "Failed to build model from file
'" +
-                file.getAbsolutePath() + "'.\nError: \'" + e.getLocalizedMessage() + "\'",
file, e );
-        }
-        finally
-        {
-            IOUtil.close( reader );
-        }
-    }
-
     private void collectInitialRepositoriesFromModel( LinkedHashSet collected, Model model,
File pomFile,
                                                       boolean validProfilesXmlLocation,
                                                       ProfileActivationContext profileActivationContext
)
@@ -359,43 +277,6 @@
         }
     }
 
-    private void checkStatusAndUpdate( Artifact projectArtifact, ArtifactStatus status, File
file,
-                                       List remoteArtifactRepositories, ArtifactRepository
localRepository )
-        throws ArtifactNotFoundException
-    {
-        // 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 );
-
-            if ( policy.checkOutOfDate( new Date( file.lastModified() ) ) )
-            {
-                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 );
-                }
-                catch ( ArtifactNotFoundException e )
-                {
-                    getLogger().warn( "Error updating POM - not found. Removing local copy."
);
-                    getLogger().debug( "Cause", e );
-                    file.delete();
-                    throw e;
-                }
-            }
-        }
-    }
-
 
     public void initialize()
         throws InitializationException

Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/RepositoryHelper.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/RepositoryHelper.java?rev=700331&r1=700330&r2=700331&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/RepositoryHelper.java
(original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/RepositoryHelper.java
Mon Sep 29 21:13:08 2008
@@ -18,7 +18,7 @@
 
     String ROLE = RepositoryHelper.class.getName();
 
-    Model findModelFromRepository( Artifact artifact, List remoteArtifactRepositories,
+    void findModelFromRepository( Artifact artifact, List remoteArtifactRepositories,
                                    ArtifactRepository localRepository )
         throws ProjectBuildingException;
 



Mime
View raw message