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