1 package org.apache.maven.profiles; 2 3 18 19 import org.apache.maven.model.Activation; 20 import org.apache.maven.model.ActivationFile; 21 import org.apache.maven.model.ActivationProperty; 22 import org.apache.maven.model.Profile; 23 import org.apache.maven.model.Repository; 24 25 import java.util.Iterator ; 26 import java.util.List ; 27 28 public class ProfilesConversionUtils 29 { 30 private ProfilesConversionUtils() 31 { 32 } 33 34 public static Profile convertFromProfileXmlProfile( org.apache.maven.profiles.Profile profileXmlProfile ) 35 { 36 Profile profile = new Profile(); 37 38 profile.setId( profileXmlProfile.getId() ); 39 40 profile.setSource( "profiles.xml" ); 41 42 org.apache.maven.profiles.Activation profileActivation = profileXmlProfile.getActivation(); 43 44 if ( profileActivation != null ) 45 { 46 Activation activation = new Activation(); 47 48 activation.setActiveByDefault( profileActivation.isActiveByDefault() ); 49 50 activation.setJdk( profileActivation.getJdk() ); 51 52 org.apache.maven.profiles.ActivationProperty profileProp = profileActivation.getProperty(); 53 54 if ( profileProp != null ) 55 { 56 ActivationProperty prop = new ActivationProperty(); 57 58 prop.setName( profileProp.getName() ); 59 prop.setValue( profileProp.getValue() ); 60 61 activation.setProperty( prop ); 62 } 63 64 65 ActivationOS profileOs = profileActivation.getOs(); 66 67 if ( profileOs != null ) 68 { 69 org.apache.maven.model.ActivationOS os = new org.apache.maven.model.ActivationOS(); 70 71 os.setArch( profileOs.getArch() ); 72 os.setFamily( profileOs.getFamily() ); 73 os.setName( profileOs.getName() ); 74 os.setVersion( profileOs.getVersion() ); 75 } 76 77 org.apache.maven.profiles.ActivationFile profileFile = profileActivation.getFile(); 78 79 if ( profileFile != null ) 80 { 81 ActivationFile file = new ActivationFile(); 82 83 file.setExists( profileFile.getExists() ); 84 file.setMissing( profileFile.getMissing() ); 85 86 activation.setFile( file ); 87 } 88 89 profile.setActivation( activation ); 90 } 91 else 92 { 93 profile.setActivation( new AlwaysOnActivation() ); 94 } 95 96 profile.setProperties( profileXmlProfile.getProperties() ); 97 98 List repos = profileXmlProfile.getRepositories(); 99 if ( repos != null ) 100 { 101 for ( Iterator it = repos.iterator(); it.hasNext(); ) 102 { 103 profile 104 .addRepository( 105 convertFromProfileXmlRepository( (org.apache.maven.profiles.Repository) it.next() ) ); 106 } 107 } 108 109 List pluginRepos = profileXmlProfile.getPluginRepositories(); 110 if ( pluginRepos != null ) 111 { 112 for ( Iterator it = pluginRepos.iterator(); it.hasNext(); ) 113 { 114 profile.addPluginRepository( convertFromProfileXmlRepository( (org.apache.maven.profiles.Repository) it 115 .next() ) ); 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 } 153 | Popular Tags |