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  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 ( Iterator it = repos.iterator(); it.hasNext(); )
103             {
104                 profile
105                     .addRepository(
106                         convertFromProfileXmlRepository( (org.apache.maven.profiles.Repository) it.next() ) );
107             }
108         }
109 
110         List pluginRepos = profileXmlProfile.getPluginRepositories();
111         if ( pluginRepos != null )
112         {
113             for ( Iterator it = pluginRepos.iterator(); it.hasNext(); )
114             {
115                 profile.addPluginRepository( convertFromProfileXmlRepository( (org.apache.maven.profiles.Repository) it
116                     .next() ) );
117             }
118         }
119 
120         return profile;
121     }
122 
123     private static Repository convertFromProfileXmlRepository( org.apache.maven.profiles.Repository profileXmlRepo )
124     {
125         Repository repo = new Repository();
126 
127         repo.setId( profileXmlRepo.getId() );
128         repo.setLayout( profileXmlRepo.getLayout() );
129         repo.setName( profileXmlRepo.getName() );
130         repo.setUrl( profileXmlRepo.getUrl() );
131 
132         if ( profileXmlRepo.getSnapshots() != null )
133         {
134             repo.setSnapshots( convertRepositoryPolicy( profileXmlRepo.getSnapshots() ) );
135         }
136         if ( profileXmlRepo.getReleases() != null )
137         {
138             repo.setReleases( convertRepositoryPolicy( profileXmlRepo.getReleases() ) );
139         }
140 
141         return repo;
142     }
143 
144     private static org.apache.maven.model.RepositoryPolicy convertRepositoryPolicy( RepositoryPolicy profileXmlRepo )
145     {
146         org.apache.maven.model.RepositoryPolicy policy = new org.apache.maven.model.RepositoryPolicy();
147         policy.setEnabled( profileXmlRepo.isEnabled() );
148         policy.setUpdatePolicy( profileXmlRepo.getUpdatePolicy() );
149         policy.setChecksumPolicy( profileXmlRepo.getChecksumPolicy() );
150         return policy;
151     }
152 
153 }