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