001package 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 022import org.apache.maven.model.Activation; 023import org.apache.maven.model.ActivationFile; 024import org.apache.maven.model.ActivationProperty; 025import org.apache.maven.model.Profile; 026import org.apache.maven.model.Repository; 027 028import java.util.List; 029 030@Deprecated 031public class ProfilesConversionUtils 032{ 033 private ProfilesConversionUtils() 034 { 035 } 036 037 public static Profile convertFromProfileXmlProfile( org.apache.maven.profiles.Profile profileXmlProfile ) 038 { 039 Profile profile = new Profile(); 040 041 profile.setId( profileXmlProfile.getId() ); 042 043 profile.setSource( "profiles.xml" ); 044 045 org.apache.maven.profiles.Activation profileActivation = profileXmlProfile.getActivation(); 046 047 if ( profileActivation != null ) 048 { 049 Activation activation = new Activation(); 050 051 activation.setActiveByDefault( profileActivation.isActiveByDefault() ); 052 053 activation.setJdk( profileActivation.getJdk() ); 054 055 org.apache.maven.profiles.ActivationProperty profileProp = profileActivation.getProperty(); 056 057 if ( profileProp != null ) 058 { 059 ActivationProperty prop = new ActivationProperty(); 060 061 prop.setName( profileProp.getName() ); 062 prop.setValue( profileProp.getValue() ); 063 064 activation.setProperty( prop ); 065 } 066 067 068 ActivationOS profileOs = profileActivation.getOs(); 069 070 if ( profileOs != null ) 071 { 072 org.apache.maven.model.ActivationOS os = new org.apache.maven.model.ActivationOS(); 073 074 os.setArch( profileOs.getArch() ); 075 os.setFamily( profileOs.getFamily() ); 076 os.setName( profileOs.getName() ); 077 os.setVersion( profileOs.getVersion() ); 078 079 activation.setOs( os ); 080 } 081 082 org.apache.maven.profiles.ActivationFile profileFile = profileActivation.getFile(); 083 084 if ( profileFile != null ) 085 { 086 ActivationFile file = new ActivationFile(); 087 088 file.setExists( profileFile.getExists() ); 089 file.setMissing( profileFile.getMissing() ); 090 091 activation.setFile( file ); 092 } 093 094 profile.setActivation( activation ); 095 } 096 097 profile.setProperties( profileXmlProfile.getProperties() ); 098 099 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}