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  
33  /**
34   * Adapt a {@link MavenExecutionRequest} to a {@link Settings} object for use in the Maven core.
35   * We want to make sure that what is ask for in the execution request overrides what is in the settings.
36   * The CLI feeds into an execution request so if a particular value is present in the execution request
37   * then we will take that over the value coming from the user settings.
38   *
39   * @author Jason van Zyl
40   */
41  class SettingsAdapter
42      extends Settings
43  {
44  
45      private MavenExecutionRequest request;
46  
47      private RuntimeInfo runtimeInfo;
48  
49      public SettingsAdapter( MavenExecutionRequest request )
50      {
51          this.request = request;
52  
53          /*
54           * NOTE: Plugins like maven-release-plugin query the path to the settings.xml to pass it into a forked Maven and
55           * the CLI will fail when called with a non-existing settings, so be sure to only point at actual files. Having
56           * a null file should be harmless as this case matches general Maven 2.x behavior...
57           */
58          File userSettings = request.getUserSettingsFile();
59          this.runtimeInfo = new RuntimeInfo( ( userSettings != null && userSettings.isFile() ) ? userSettings : null );
60      }
61  
62      @Override
63      public String getLocalRepository()
64      {
65          if ( request.getLocalRepositoryPath() != null )
66          {
67              return request.getLocalRepositoryPath().getAbsolutePath();
68          }
69  
70          return null;
71      }
72  
73      @Override
74      public boolean isInteractiveMode()
75      {
76          return request.isInteractiveMode();
77      }
78  
79      @Override
80      public boolean isOffline()
81      {
82          return request.isOffline();
83      }
84  
85      @Override
86      public List<Proxy> getProxies()
87      {
88          return request.getProxies();
89      }
90  
91      @Override
92      public List<Server> getServers()
93      {
94          return request.getServers();
95      }
96  
97      @Override
98      public List<Mirror> getMirrors()
99      {
100         return request.getMirrors();
101     }
102 
103     @Override
104     public List<Profile> getProfiles()
105     {
106         return new ArrayList<Profile>();
107     }
108 
109     @Override
110     public List<String> getActiveProfiles()
111     {
112         return request.getActiveProfiles();
113     }
114 
115     @Override
116     public List<String> getPluginGroups()
117     {
118         return request.getPluginGroups();
119     }
120 
121     @Override
122     public RuntimeInfo getRuntimeInfo()
123     {
124         return runtimeInfo;
125     }
126 
127 }