1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 package org.apache.maven.settings;
20
21 /**
22 * Several convenience methods to handle settings
23 *
24 * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
25 */
26 public final class SettingsUtils {
27
28 private SettingsUtils() {
29 // don't allow construction.
30 }
31
32 /**
33 * @param dominant
34 * @param recessive
35 * @param recessiveSourceLevel
36 */
37 public static void merge(Settings dominant, Settings recessive, String recessiveSourceLevel) {
38 if (dominant != null && recessive != null) {
39 dominant.delegate = SettingsUtilsV4.merge(dominant.getDelegate(), recessive.getDelegate());
40 }
41 }
42
43 /**
44 * @param modelProfile
45 * @return a profile
46 */
47 public static Profile convertToSettingsProfile(org.apache.maven.model.Profile modelProfile) {
48 return new Profile(SettingsUtilsV4.convertToSettingsProfile(modelProfile.getDelegate()));
49 }
50
51 /**
52 * @param settingsProfile
53 * @return a profile
54 */
55 public static org.apache.maven.model.Profile convertFromSettingsProfile(Profile settingsProfile) {
56 return new org.apache.maven.model.Profile(
57 SettingsUtilsV4.convertFromSettingsProfile(settingsProfile.getDelegate()));
58 }
59
60 /**
61 * @param settings could be null
62 * @return a new instance of settings or null if settings was null.
63 */
64 public static Settings copySettings(Settings settings) {
65 if (settings == null) {
66 return null;
67 }
68
69 Settings clone = new Settings();
70 clone.setActiveProfiles(settings.getActiveProfiles());
71 clone.setInteractiveMode(settings.isInteractiveMode());
72 clone.setLocalRepository(settings.getLocalRepository());
73 clone.setMirrors(settings.getMirrors());
74 clone.setOffline(settings.isOffline());
75 clone.setPluginGroups(settings.getPluginGroups());
76 clone.setProfiles(settings.getProfiles());
77 clone.setProxies(settings.getProxies());
78 clone.setServers(settings.getServers());
79 clone.setSourceLevel(settings.getSourceLevel());
80 clone.setUsePluginRegistry(settings.isUsePluginRegistry());
81
82 return clone;
83 }
84 }