Permalink
Browse files

o Refactored code

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1074288 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 6f04bf8 commit f9c3d40221456168084e8c7304f1a2e7e4fa27c1 @bentmann bentmann committed Feb 24, 2011
@@ -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 );
+ }
+
+}
@@ -64,10 +64,7 @@
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 ArtifactDescriptorResult readArtifactDescriptor( RepositorySystemSession
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 @@ private Model loadPom( RepositorySystemSession session, ArtifactDescriptorReques
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 @@ private Exclusion convert( org.apache.maven.model.Exclusion exclusion )
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 )
{
@@ -99,7 +99,7 @@ public void addRepository( Repository repository )
}
List<RemoteRepository> newRepositories =
- Collections.singletonList( DefaultArtifactDescriptorReader.convert( repository ) );
+ Collections.singletonList( ArtifactDescriptorUtils.toRemoteRepository( repository ) );
this.repositories =
remoteRepositoryManager.aggregateRepositories( session, repositories, newRepositories, true );
@@ -44,7 +44,6 @@
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 @@ private boolean isSafelyCacheable( RepositorySystemSession session, Artifact art
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
@@ -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>
@@ -44,6 +44,7 @@
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.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 ProjectBuildingResult build( Artifact artifact, boolean allowStubModel, P
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 );
@@ -32,13 +32,13 @@
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 @@ public void addRepository( Repository repository )
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 @@ public void addRepository( Repository repository )
}
}
- 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 );

0 comments on commit f9c3d40

Please sign in to comment.