o Refactored code

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1074288 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2011-02-24 20:43:52 +00:00
parent 6f04bf8499
commit f9c3d40221
7 changed files with 90 additions and 86 deletions

View File

@ -0,0 +1,81 @@
package org.apache.maven.repository.internal;
/*
* 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.
*/
import org.apache.maven.model.Repository;
import org.sonatype.aether.artifact.Artifact;
import org.sonatype.aether.repository.RemoteRepository;
import org.sonatype.aether.repository.RepositoryPolicy;
import org.sonatype.aether.util.artifact.DefaultArtifact;
/**
* <strong>Warning:</strong> This is an internal utility class that is only public for technical reasons, it is not part
* of the public API. In particular, this class can be changed or deleted without prior notice.
*
* @author Benjamin Bentmann
*/
public class ArtifactDescriptorUtils
{
public static Artifact toPomArtifact( Artifact artifact )
{
Artifact pomArtifact = artifact;
if ( pomArtifact.getClassifier().length() > 0 || !"pom".equals( pomArtifact.getExtension() ) )
{
pomArtifact =
new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion() );
}
return pomArtifact;
}
public static RemoteRepository toRemoteRepository( Repository repository )
{
RemoteRepository result =
new RemoteRepository( repository.getId(), repository.getLayout(), repository.getUrl() );
result.setPolicy( true, toRepositoryPolicy( repository.getSnapshots() ) );
result.setPolicy( false, toRepositoryPolicy( repository.getReleases() ) );
return result;
}
public static RepositoryPolicy toRepositoryPolicy( org.apache.maven.model.RepositoryPolicy policy )
{
boolean enabled = true;
String checksums = RepositoryPolicy.CHECKSUM_POLICY_WARN;
String updates = RepositoryPolicy.UPDATE_POLICY_DAILY;
if ( policy != null )
{
enabled = policy.isEnabled();
if ( policy.getUpdatePolicy() != null )
{
updates = policy.getUpdatePolicy();
}
if ( policy.getChecksumPolicy() != null )
{
checksums = policy.getChecksumPolicy();
}
}
return new RepositoryPolicy( enabled, updates, checksums );
}
}

View File

@ -64,10 +64,7 @@ import org.sonatype.aether.util.DefaultRequestTrace;
import org.sonatype.aether.util.artifact.ArtifactProperties;
import org.sonatype.aether.util.artifact.DefaultArtifact;
import org.sonatype.aether.util.artifact.DefaultArtifactType;
import org.sonatype.aether.util.artifact.SubArtifact;
import org.sonatype.aether.util.listener.DefaultRepositoryEvent;
import org.sonatype.aether.repository.RemoteRepository;
import org.sonatype.aether.repository.RepositoryPolicy;
import org.sonatype.aether.repository.WorkspaceRepository;
import org.sonatype.aether.resolution.ArtifactDescriptorException;
import org.sonatype.aether.resolution.ArtifactDescriptorRequest;
@ -180,7 +177,7 @@ public class DefaultArtifactDescriptorReader
for ( Repository r : model.getRepositories() )
{
result.addRepository( convert( r ) );
result.addRepository( ArtifactDescriptorUtils.toRemoteRepository( r ) );
}
for ( org.apache.maven.model.Dependency dependency : model.getDependencies() )
@ -259,11 +256,7 @@ public class DefaultArtifactDescriptorReader
throw new ArtifactDescriptorException( result );
}
Artifact pomArtifact = artifact;
if ( pomArtifact.getClassifier().length() > 0 || !"pom".equals( pomArtifact.getExtension() ) )
{
pomArtifact = new SubArtifact( artifact, "", "pom" );
}
Artifact pomArtifact = ArtifactDescriptorUtils.toPomArtifact( artifact );
ArtifactResult resolveResult;
try
@ -411,37 +404,6 @@ public class DefaultArtifactDescriptorReader
return new Exclusion( exclusion.getGroupId(), exclusion.getArtifactId(), "*", "*" );
}
static RemoteRepository convert( Repository repository )
{
RemoteRepository result =
new RemoteRepository( repository.getId(), repository.getLayout(), repository.getUrl() );
result.setPolicy( true, convert( repository.getSnapshots() ) );
result.setPolicy( false, convert( repository.getReleases() ) );
return result;
}
private static RepositoryPolicy convert( org.apache.maven.model.RepositoryPolicy policy )
{
boolean enabled = true;
String checksums = RepositoryPolicy.CHECKSUM_POLICY_WARN;
String updates = RepositoryPolicy.UPDATE_POLICY_DAILY;
if ( policy != null )
{
enabled = policy.isEnabled();
if ( policy.getUpdatePolicy() != null )
{
updates = policy.getUpdatePolicy();
}
if ( policy.getChecksumPolicy() != null )
{
checksums = policy.getChecksumPolicy();
}
}
return new RepositoryPolicy( enabled, updates, checksums );
}
private void missingDescriptor( RepositorySystemSession session, RequestTrace trace, Artifact artifact,
Exception exception )
{

View File

@ -99,7 +99,7 @@ class DefaultModelResolver
}
List<RemoteRepository> newRepositories =
Collections.singletonList( DefaultArtifactDescriptorReader.convert( repository ) );
Collections.singletonList( ArtifactDescriptorUtils.toRemoteRepository( repository ) );
this.repositories =
remoteRepositoryManager.aggregateRepositories( session, repositories, newRepositories, true );

View File

@ -44,7 +44,6 @@ import org.sonatype.aether.RepositoryListener;
import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.SyncContext;
import org.sonatype.aether.util.DefaultRequestTrace;
import org.sonatype.aether.util.artifact.SubArtifact;
import org.sonatype.aether.util.listener.DefaultRepositoryEvent;
import org.sonatype.aether.util.metadata.DefaultMetadata;
import org.sonatype.aether.artifact.Artifact;
@ -455,11 +454,7 @@ public class DefaultVersionResolver
return true;
}
Artifact pomArtifact = artifact;
if ( pomArtifact.getClassifier().length() > 0 || !"pom".equals( pomArtifact.getExtension() ) )
{
pomArtifact = new SubArtifact( artifact, "", "pom" );
}
Artifact pomArtifact = ArtifactDescriptorUtils.toPomArtifact( artifact );
return workspace.findArtifact( pomArtifact ) == null;
}

View File

@ -56,7 +56,6 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-aether-provider</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.sonatype.aether</groupId>

View File

@ -44,6 +44,7 @@ import org.apache.maven.model.building.ModelSource;
import org.apache.maven.model.building.StringModelSource;
import org.apache.maven.model.resolution.ModelResolver;
import org.apache.maven.repository.RepositorySystem;
import org.apache.maven.repository.internal.ArtifactDescriptorUtils;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
@ -58,7 +59,6 @@ import org.sonatype.aether.repository.WorkspaceRepository;
import org.sonatype.aether.resolution.ArtifactRequest;
import org.sonatype.aether.resolution.ArtifactResult;
import org.sonatype.aether.util.DefaultRequestTrace;
import org.sonatype.aether.util.artifact.SubArtifact;
/**
* @version $Id$
@ -247,10 +247,7 @@ public class DefaultProjectBuilder
throws ProjectBuildingException
{
org.sonatype.aether.artifact.Artifact pomArtifact = RepositoryUtils.toArtifact( artifact );
if ( !pomArtifact.getExtension().equals( "pom" ) )
{
pomArtifact = new SubArtifact( pomArtifact, "", "pom" );
}
pomArtifact = ArtifactDescriptorUtils.toPomArtifact( pomArtifact );
InternalConfig config = new InternalConfig( request, null, null );

View File

@ -32,13 +32,13 @@ import org.apache.maven.model.building.ModelSource;
import org.apache.maven.model.resolution.InvalidRepositoryException;
import org.apache.maven.model.resolution.ModelResolver;
import org.apache.maven.model.resolution.UnresolvableModelException;
import org.apache.maven.repository.internal.ArtifactDescriptorUtils;
import org.sonatype.aether.RepositorySystem;
import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.RequestTrace;
import org.sonatype.aether.artifact.Artifact;
import org.sonatype.aether.impl.RemoteRepositoryManager;
import org.sonatype.aether.repository.RemoteRepository;
import org.sonatype.aether.repository.RepositoryPolicy;
import org.sonatype.aether.resolution.ArtifactRequest;
import org.sonatype.aether.resolution.ArtifactResolutionException;
import org.sonatype.aether.util.artifact.DefaultArtifact;
@ -113,7 +113,8 @@ class ProjectModelResolver
return;
}
List<RemoteRepository> newRepositories = Collections.singletonList( convert( repository ) );
List<RemoteRepository> newRepositories =
Collections.singletonList( ArtifactDescriptorUtils.toRemoteRepository( repository ) );
if ( ProjectBuildingRequest.RepositoryMerging.REQUEST_DOMINANT.equals( repositoryMerging ) )
{
@ -128,37 +129,6 @@ class ProjectModelResolver
}
}
private static RemoteRepository convert( Repository repository )
{
RemoteRepository result =
new RemoteRepository( repository.getId(), repository.getLayout(), repository.getUrl() );
result.setPolicy( true, convert( repository.getSnapshots() ) );
result.setPolicy( false, convert( repository.getReleases() ) );
return result;
}
private static RepositoryPolicy convert( org.apache.maven.model.RepositoryPolicy policy )
{
boolean enabled = true;
String checksums = RepositoryPolicy.CHECKSUM_POLICY_WARN;
String updates = RepositoryPolicy.UPDATE_POLICY_DAILY;
if ( policy != null )
{
enabled = policy.isEnabled();
if ( policy.getUpdatePolicy() != null )
{
updates = policy.getUpdatePolicy();
}
if ( policy.getChecksumPolicy() != null )
{
checksums = policy.getChecksumPolicy();
}
}
return new RepositoryPolicy( enabled, updates, checksums );
}
public ModelResolver newCopy()
{
return new ProjectModelResolver( this );