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.profiles;
20  
21  import java.util.List;
22  
23  import org.apache.maven.model.Activation;
24  import org.apache.maven.model.ActivationFile;
25  import org.apache.maven.model.ActivationProperty;
26  import org.apache.maven.model.Profile;
27  import org.apache.maven.model.Repository;
28  
29  /**
30   * ProfilesConversionUtils
31   */
32  @Deprecated
33  public class ProfilesConversionUtils {
34      private ProfilesConversionUtils() {}
35  
36      public static Profile convertFromProfileXmlProfile(org.apache.maven.profiles.Profile profileXmlProfile) {
37          Profile profile = new Profile();
38  
39          profile.setId(profileXmlProfile.getId());
40  
41          profile.setSource("profiles.xml");
42  
43          org.apache.maven.profiles.Activation profileActivation = profileXmlProfile.getActivation();
44  
45          if (profileActivation != null) {
46              Activation activation = new Activation();
47  
48              activation.setActiveByDefault(profileActivation.isActiveByDefault());
49  
50              activation.setJdk(profileActivation.getJdk());
51  
52              org.apache.maven.profiles.ActivationProperty profileProp = profileActivation.getProperty();
53  
54              if (profileProp != null) {
55                  ActivationProperty prop = new ActivationProperty();
56  
57                  prop.setName(profileProp.getName());
58                  prop.setValue(profileProp.getValue());
59  
60                  activation.setProperty(prop);
61              }
62  
63              ActivationOS profileOs = profileActivation.getOs();
64  
65              if (profileOs != null) {
66                  org.apache.maven.model.ActivationOS os = new org.apache.maven.model.ActivationOS();
67  
68                  os.setArch(profileOs.getArch());
69                  os.setFamily(profileOs.getFamily());
70                  os.setName(profileOs.getName());
71                  os.setVersion(profileOs.getVersion());
72  
73                  activation.setOs(os);
74              }
75  
76              org.apache.maven.profiles.ActivationFile profileFile = profileActivation.getFile();
77  
78              if (profileFile != null) {
79                  ActivationFile file = new ActivationFile();
80  
81                  file.setExists(profileFile.getExists());
82                  file.setMissing(profileFile.getMissing());
83  
84                  activation.setFile(file);
85              }
86  
87              profile.setActivation(activation);
88          }
89  
90          profile.setProperties(profileXmlProfile.getProperties());
91  
92          List repos = profileXmlProfile.getRepositories();
93          if (repos != null) {
94              for (Object repo : repos) {
95                  profile.addRepository(convertFromProfileXmlRepository((org.apache.maven.profiles.Repository) repo));
96              }
97          }
98  
99          List pluginRepos = profileXmlProfile.getPluginRepositories();
100         if (pluginRepos != null) {
101             for (Object pluginRepo : pluginRepos) {
102                 profile.addPluginRepository(
103                         convertFromProfileXmlRepository((org.apache.maven.profiles.Repository) pluginRepo));
104             }
105         }
106 
107         return profile;
108     }
109 
110     private static Repository convertFromProfileXmlRepository(org.apache.maven.profiles.Repository profileXmlRepo) {
111         Repository repo = new Repository();
112 
113         repo.setId(profileXmlRepo.getId());
114         repo.setLayout(profileXmlRepo.getLayout());
115         repo.setName(profileXmlRepo.getName());
116         repo.setUrl(profileXmlRepo.getUrl());
117 
118         if (profileXmlRepo.getSnapshots() != null) {
119             repo.setSnapshots(convertRepositoryPolicy(profileXmlRepo.getSnapshots()));
120         }
121         if (profileXmlRepo.getReleases() != null) {
122             repo.setReleases(convertRepositoryPolicy(profileXmlRepo.getReleases()));
123         }
124 
125         return repo;
126     }
127 
128     private static org.apache.maven.model.RepositoryPolicy convertRepositoryPolicy(RepositoryPolicy profileXmlRepo) {
129         org.apache.maven.model.RepositoryPolicy policy = new org.apache.maven.model.RepositoryPolicy();
130         policy.setEnabled(profileXmlRepo.isEnabled());
131         policy.setUpdatePolicy(profileXmlRepo.getUpdatePolicy());
132         policy.setChecksumPolicy(profileXmlRepo.getChecksumPolicy());
133         return policy;
134     }
135 }