View Javadoc
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   */
25  public final class SettingsUtils {
26  
27      private SettingsUtils() {
28          // don't allow construction.
29      }
30  
31      /**
32       * @param dominant
33       * @param recessive
34       * @param recessiveSourceLevel
35       */
36      public static void merge(Settings dominant, Settings recessive, String recessiveSourceLevel) {
37          if (dominant != null && recessive != null) {
38              dominant.delegate = SettingsUtilsV4.merge(dominant.getDelegate(), recessive.getDelegate());
39          }
40      }
41  
42      /**
43       * @param modelProfile
44       * @return a profile
45       */
46      public static Profile convertToSettingsProfile(org.apache.maven.model.Profile modelProfile) {
47          return new Profile(SettingsUtilsV4.convertToSettingsProfile(modelProfile.getDelegate()));
48      }
49  
50      /**
51       * @param settingsProfile
52       * @return a profile
53       */
54      public static org.apache.maven.model.Profile convertFromSettingsProfile(Profile settingsProfile) {
55          return new org.apache.maven.model.Profile(
56                  SettingsUtilsV4.convertFromSettingsProfile(settingsProfile.getDelegate()));
57      }
58  
59      /**
60       * @param settings could be null
61       * @return a new instance of settings or null if settings was null.
62       */
63      public static Settings copySettings(Settings settings) {
64          if (settings == null) {
65              return null;
66          }
67  
68          Settings clone = new Settings();
69          clone.setActiveProfiles(settings.getActiveProfiles());
70          clone.setInteractiveMode(settings.isInteractiveMode());
71          clone.setLocalRepository(settings.getLocalRepository());
72          clone.setMirrors(settings.getMirrors());
73          clone.setOffline(settings.isOffline());
74          clone.setPluginGroups(settings.getPluginGroups());
75          clone.setProfiles(settings.getProfiles());
76          clone.setProxies(settings.getProxies());
77          clone.setServers(settings.getServers());
78          clone.setSourceLevel(settings.getSourceLevel());
79          clone.setUsePluginRegistry(settings.isUsePluginRegistry());
80  
81          return clone;
82      }
83  }