001    package org.apache.maven.profiles;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *  http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.maven.model.Activation;
023    import org.apache.maven.model.ActivationFile;
024    import org.apache.maven.model.ActivationProperty;
025    import org.apache.maven.model.Profile;
026    import org.apache.maven.model.Repository;
027    
028    import java.util.Iterator;
029    import java.util.List;
030    
031    @Deprecated
032    public class ProfilesConversionUtils
033    {
034        private ProfilesConversionUtils()
035        {
036        }
037    
038        public static Profile convertFromProfileXmlProfile( org.apache.maven.profiles.Profile profileXmlProfile )
039        {
040            Profile profile = new Profile();
041    
042            profile.setId( profileXmlProfile.getId() );
043    
044            profile.setSource( "profiles.xml" );
045    
046            org.apache.maven.profiles.Activation profileActivation = profileXmlProfile.getActivation();
047    
048            if ( profileActivation != null )
049            {
050                Activation activation = new Activation();
051    
052                activation.setActiveByDefault( profileActivation.isActiveByDefault() );
053    
054                activation.setJdk( profileActivation.getJdk() );
055    
056                org.apache.maven.profiles.ActivationProperty profileProp = profileActivation.getProperty();
057    
058                if ( profileProp != null )
059                {
060                    ActivationProperty prop = new ActivationProperty();
061    
062                    prop.setName( profileProp.getName() );
063                    prop.setValue( profileProp.getValue() );
064    
065                    activation.setProperty( prop );
066                }
067    
068                
069                ActivationOS profileOs = profileActivation.getOs();
070                
071                if ( profileOs != null )
072                {
073                    org.apache.maven.model.ActivationOS os = new org.apache.maven.model.ActivationOS();
074    
075                    os.setArch( profileOs.getArch() );
076                    os.setFamily( profileOs.getFamily() );
077                    os.setName( profileOs.getName() );
078                    os.setVersion( profileOs.getVersion() );
079    
080                    activation.setOs( os );
081                }
082                
083                org.apache.maven.profiles.ActivationFile profileFile = profileActivation.getFile();
084    
085                if ( profileFile != null )
086                {
087                    ActivationFile file = new ActivationFile();
088    
089                    file.setExists( profileFile.getExists() );
090                    file.setMissing( profileFile.getMissing() );
091    
092                    activation.setFile( file );
093                }
094    
095                profile.setActivation( activation );
096            }
097    
098            profile.setProperties( profileXmlProfile.getProperties() );
099    
100            List repos = profileXmlProfile.getRepositories();
101            if ( repos != null )
102            {
103                for ( Iterator it = repos.iterator(); it.hasNext(); )
104                {
105                    profile
106                        .addRepository(
107                            convertFromProfileXmlRepository( (org.apache.maven.profiles.Repository) it.next() ) );
108                }
109            }
110    
111            List pluginRepos = profileXmlProfile.getPluginRepositories();
112            if ( pluginRepos != null )
113            {
114                for ( Iterator it = pluginRepos.iterator(); it.hasNext(); )
115                {
116                    profile.addPluginRepository( convertFromProfileXmlRepository( (org.apache.maven.profiles.Repository) it
117                        .next() ) );
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    }