1 package org.apache.maven.settings;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.List;
23
24 import org.apache.maven.model.ActivationFile;
25 import org.apache.maven.settings.merge.MavenSettingsMerger;
26
27
28
29
30
31
32 public final class SettingsUtils
33 {
34
35 private SettingsUtils()
36 {
37
38 }
39
40
41
42
43
44
45 public static void merge( Settings dominant, Settings recessive, String recessiveSourceLevel )
46 {
47 new MavenSettingsMerger().merge( dominant, recessive, recessiveSourceLevel );
48 }
49
50
51
52
53
54 public static org.apache.maven.model.Profile convertFromSettingsProfile( Profile settingsProfile )
55 {
56 org.apache.maven.model.Profile profile = new org.apache.maven.model.Profile();
57
58 profile.setId( settingsProfile.getId() );
59
60 profile.setSource( "settings.xml" );
61
62 Activation settingsActivation = settingsProfile.getActivation();
63
64 if ( settingsActivation != null )
65 {
66 org.apache.maven.model.Activation activation = new org.apache.maven.model.Activation();
67
68 activation.setActiveByDefault( settingsActivation.isActiveByDefault() );
69
70 activation.setJdk( settingsActivation.getJdk() );
71
72 ActivationProperty settingsProp = settingsActivation.getProperty();
73
74 if ( settingsProp != null )
75 {
76 org.apache.maven.model.ActivationProperty prop = new org.apache.maven.model.ActivationProperty();
77
78 prop.setName( settingsProp.getName() );
79 prop.setValue( settingsProp.getValue() );
80
81 activation.setProperty( prop );
82 }
83
84 ActivationOS settingsOs = settingsActivation.getOs();
85
86 if ( settingsOs != null )
87 {
88 org.apache.maven.model.ActivationOS os = new org.apache.maven.model.ActivationOS();
89
90 os.setArch( settingsOs.getArch() );
91 os.setFamily( settingsOs.getFamily() );
92 os.setName( settingsOs.getName() );
93 os.setVersion( settingsOs.getVersion() );
94
95 activation.setOs( os );
96 }
97
98 org.apache.maven.settings.ActivationFile settingsFile = settingsActivation.getFile();
99
100 if ( settingsFile != null )
101 {
102 ActivationFile file = new ActivationFile();
103
104 file.setExists( settingsFile.getExists() );
105 file.setMissing( settingsFile.getMissing() );
106
107 activation.setFile( file );
108 }
109
110 profile.setActivation( activation );
111 }
112
113 profile.setProperties( settingsProfile.getProperties() );
114
115 List<Repository> repos = settingsProfile.getRepositories();
116 if ( repos != null )
117 {
118 for ( Repository repo : repos )
119 {
120 profile.addRepository( convertFromSettingsRepository( repo ) );
121 }
122 }
123
124 List<Repository> pluginRepos = settingsProfile.getPluginRepositories();
125 if ( pluginRepos != null )
126 {
127 for ( Repository pluginRepo : pluginRepos )
128 {
129 profile.addPluginRepository( convertFromSettingsRepository( pluginRepo ) );
130 }
131 }
132
133 return profile;
134 }
135
136
137
138
139
140 private static org.apache.maven.model.Repository convertFromSettingsRepository( Repository settingsRepo )
141 {
142 org.apache.maven.model.Repository repo = new org.apache.maven.model.Repository();
143
144 repo.setId( settingsRepo.getId() );
145 repo.setLayout( settingsRepo.getLayout() );
146 repo.setName( settingsRepo.getName() );
147 repo.setUrl( settingsRepo.getUrl() );
148
149 if ( settingsRepo.getSnapshots() != null )
150 {
151 repo.setSnapshots( convertRepositoryPolicy( settingsRepo.getSnapshots() ) );
152 }
153 if ( settingsRepo.getReleases() != null )
154 {
155 repo.setReleases( convertRepositoryPolicy( settingsRepo.getReleases() ) );
156 }
157
158 return repo;
159 }
160
161
162
163
164
165 private static org.apache.maven.model.RepositoryPolicy convertRepositoryPolicy( RepositoryPolicy settingsPolicy )
166 {
167 org.apache.maven.model.RepositoryPolicy policy = new org.apache.maven.model.RepositoryPolicy();
168 policy.setEnabled( settingsPolicy.isEnabled() );
169 policy.setUpdatePolicy( settingsPolicy.getUpdatePolicy() );
170 policy.setChecksumPolicy( settingsPolicy.getChecksumPolicy() );
171 return policy;
172 }
173
174
175
176
177
178 public static Settings copySettings( Settings settings )
179 {
180 if ( settings == null )
181 {
182 return null;
183 }
184
185 Settings clone = new Settings();
186 clone.setActiveProfiles( settings.getActiveProfiles() );
187 clone.setInteractiveMode( settings.isInteractiveMode() );
188 clone.setLocalRepository( settings.getLocalRepository() );
189 clone.setMirrors( settings.getMirrors() );
190 clone.setModelEncoding( settings.getModelEncoding() );
191 clone.setOffline( settings.isOffline() );
192 clone.setPluginGroups( settings.getPluginGroups() );
193 clone.setProfiles( settings.getProfiles() );
194 clone.setProxies( settings.getProxies() );
195 clone.setServers( settings.getServers() );
196 clone.setSourceLevel( settings.getSourceLevel() );
197 clone.setUsePluginRegistry( settings.isUsePluginRegistry() );
198
199 return clone;
200 }
201 }