View Javadoc
1   package org.apache.maven.repository.internal;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.model.Repository;
23  import org.eclipse.aether.artifact.Artifact;
24  import org.eclipse.aether.artifact.DefaultArtifact;
25  import org.eclipse.aether.repository.RemoteRepository;
26  import org.eclipse.aether.repository.RepositoryPolicy;
27  
28  /**
29   * <strong>Warning:</strong> This is an internal utility class that is only public for technical reasons, it is not part
30   * of the public API. In particular, this class can be changed or deleted without prior notice.
31   *
32   * @author Benjamin Bentmann
33   */
34  public class ArtifactDescriptorUtils
35  {
36  
37      public static Artifact toPomArtifact( Artifact artifact )
38      {
39          Artifact pomArtifact = artifact;
40  
41          if ( pomArtifact.getClassifier().length() > 0 || !"pom".equals( pomArtifact.getExtension() ) )
42          {
43              pomArtifact =
44                  new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion() );
45          }
46  
47          return pomArtifact;
48      }
49  
50      public static RemoteRepository toRemoteRepository( Repository repository )
51      {
52          RemoteRepository.Builder builder =
53              new RemoteRepository.Builder( repository.getId(), repository.getLayout(), repository.getUrl() );
54          builder.setSnapshotPolicy( toRepositoryPolicy( repository.getSnapshots() ) );
55          builder.setReleasePolicy( toRepositoryPolicy( repository.getReleases() ) );
56          return builder.build();
57      }
58  
59      public static RepositoryPolicy toRepositoryPolicy( org.apache.maven.model.RepositoryPolicy policy )
60      {
61          boolean enabled = true;
62          String checksums = RepositoryPolicy.CHECKSUM_POLICY_WARN;
63          String updates = RepositoryPolicy.UPDATE_POLICY_DAILY;
64  
65          if ( policy != null )
66          {
67              enabled = policy.isEnabled();
68              if ( policy.getUpdatePolicy() != null )
69              {
70                  updates = policy.getUpdatePolicy();
71              }
72              if ( policy.getChecksumPolicy() != null )
73              {
74                  checksums = policy.getChecksumPolicy();
75              }
76          }
77  
78          return new RepositoryPolicy( enabled, updates, checksums );
79      }
80  
81  }