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