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.resolver.internal.ant;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.apache.maven.settings.Activation;
25  import org.apache.maven.settings.ActivationFile;
26  import org.apache.maven.settings.ActivationOS;
27  import org.apache.maven.settings.ActivationProperty;
28  import org.apache.maven.settings.Profile;
29  import org.apache.maven.settings.Repository;
30  import org.apache.maven.settings.RepositoryPolicy;
31  
32  /**
33   * Utility methods to read settings from Mavens settings.xml.
34   */
35  class SettingsUtils {
36  
37      public static List<org.apache.maven.model.Profile> convert(List<Profile> profiles) {
38          if (profiles == null) {
39              return null;
40          }
41  
42          List<org.apache.maven.model.Profile> results = new ArrayList<>();
43  
44          for (Profile profile : profiles) {
45              results.add(convert(profile));
46          }
47  
48          return results;
49      }
50  
51      static org.apache.maven.model.Profile convert(Profile profile) {
52          if (profile == null) {
53              return null;
54          }
55  
56          org.apache.maven.model.Profile result = new org.apache.maven.model.Profile();
57  
58          result.setId(profile.getId());
59          result.setProperties(profile.getProperties());
60          result.setSource("settings.xml");
61          result.setActivation(convert(profile.getActivation()));
62  
63          for (Repository repo : profile.getRepositories()) {
64              result.addRepository(convert(repo));
65          }
66  
67          for (Repository repo : profile.getPluginRepositories()) {
68              result.addPluginRepository(convert(repo));
69          }
70  
71          return result;
72      }
73  
74      static org.apache.maven.model.Activation convert(Activation activation) {
75          if (activation == null) {
76              return null;
77          }
78  
79          org.apache.maven.model.Activation result = new org.apache.maven.model.Activation();
80  
81          result.setActiveByDefault(activation.isActiveByDefault());
82          result.setJdk(activation.getJdk());
83          result.setFile(convert(activation.getFile()));
84          result.setProperty(convert(activation.getProperty()));
85          result.setOs(convert(activation.getOs()));
86  
87          return result;
88      }
89  
90      static org.apache.maven.model.ActivationOS convert(ActivationOS activation) {
91          if (activation == null) {
92              return null;
93          }
94  
95          org.apache.maven.model.ActivationOS result = new org.apache.maven.model.ActivationOS();
96  
97          result.setArch(activation.getArch());
98          result.setFamily(activation.getFamily());
99          result.setName(activation.getName());
100         result.setVersion(activation.getVersion());
101 
102         return result;
103     }
104 
105     static org.apache.maven.model.ActivationProperty convert(ActivationProperty activation) {
106         if (activation == null) {
107             return null;
108         }
109 
110         org.apache.maven.model.ActivationProperty result = new org.apache.maven.model.ActivationProperty();
111 
112         result.setName(activation.getName());
113         result.setValue(activation.getValue());
114 
115         return result;
116     }
117 
118     static org.apache.maven.model.ActivationFile convert(ActivationFile activation) {
119         if (activation == null) {
120             return null;
121         }
122 
123         org.apache.maven.model.ActivationFile result = new org.apache.maven.model.ActivationFile();
124 
125         result.setExists(activation.getExists());
126         result.setMissing(activation.getMissing());
127 
128         return result;
129     }
130 
131     static org.apache.maven.model.Repository convert(Repository repo) {
132         if (repo == null) {
133             return null;
134         }
135 
136         org.apache.maven.model.Repository result = new org.apache.maven.model.Repository();
137 
138         result.setId(repo.getId());
139         result.setUrl(repo.getUrl());
140         result.setLayout(repo.getLayout());
141         result.setReleases(convert(repo.getReleases()));
142         result.setSnapshots(convert(repo.getSnapshots()));
143 
144         return result;
145     }
146 
147     static org.apache.maven.model.RepositoryPolicy convert(RepositoryPolicy policy) {
148         if (policy == null) {
149             return null;
150         }
151 
152         org.apache.maven.model.RepositoryPolicy result = new org.apache.maven.model.RepositoryPolicy();
153 
154         result.setEnabled(policy.isEnabled());
155         result.setChecksumPolicy(policy.getChecksumPolicy());
156         result.setUpdatePolicy(policy.getUpdatePolicy());
157 
158         return result;
159     }
160 }