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