View Javadoc
1   package org.apache.maven.execution;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.util.ArrayList;
24  import java.util.List;
25  
26  import org.apache.maven.settings.Mirror;
27  import org.apache.maven.settings.Profile;
28  import org.apache.maven.settings.Proxy;
29  import org.apache.maven.settings.RuntimeInfo;
30  import org.apache.maven.settings.Server;
31  import org.apache.maven.settings.Settings;
32  import org.apache.maven.settings.SettingsUtils;
33  
34  /**
35   * Adapt a {@link MavenExecutionRequest} to a {@link Settings} object for use in the Maven core.
36   * We want to make sure that what is ask for in the execution request overrides what is in the settings.
37   * The CLI feeds into an execution request so if a particular value is present in the execution request
38   * then we will take that over the value coming from the user settings.
39   *
40   * @author Jason van Zyl
41   */
42  class SettingsAdapter
43      extends Settings
44  {
45  
46      private MavenExecutionRequest request;
47  
48      private RuntimeInfo runtimeInfo;
49  
50      public SettingsAdapter( MavenExecutionRequest request )
51      {
52          this.request = request;
53  
54          /*
55           * NOTE: Plugins like maven-release-plugin query the path to the settings.xml to pass it into a forked Maven and
56           * the CLI will fail when called with a non-existing settings, so be sure to only point at actual files. Having
57           * a null file should be harmless as this case matches general Maven 2.x behavior...
58           */
59          File userSettings = request.getUserSettingsFile();
60          this.runtimeInfo = new RuntimeInfo( ( userSettings != null && userSettings.isFile() ) ? userSettings : null );
61      }
62  
63      @Override
64      public String getLocalRepository()
65      {
66          if ( request.getLocalRepositoryPath() != null )
67          {
68              return request.getLocalRepositoryPath().getAbsolutePath();
69          }
70  
71          return null;
72      }
73  
74      @Override
75      public boolean isInteractiveMode()
76      {
77          return request.isInteractiveMode();
78      }
79  
80      @Override
81      public boolean isOffline()
82      {
83          return request.isOffline();
84      }
85  
86      @Override
87      public List<Proxy> getProxies()
88      {
89          return request.getProxies();
90      }
91  
92      @Override
93      public List<Server> getServers()
94      {
95          return request.getServers();
96      }
97  
98      @Override
99      public List<Mirror> getMirrors()
100     {
101         return request.getMirrors();
102     }
103 
104     @Override
105     public List<Profile> getProfiles()
106     {
107         List<Profile> result = new ArrayList<Profile>();
108         for ( org.apache.maven.model.Profile profile : request.getProfiles() )
109         {
110             result.add( SettingsUtils.convertToSettingsProfile( profile ) );
111         }
112         return result;
113     }
114 
115     @Override
116     public List<String> getActiveProfiles()
117     {
118         return request.getActiveProfiles();
119     }
120 
121     @Override
122     public List<String> getPluginGroups()
123     {
124         return request.getPluginGroups();
125     }
126 }