View Javadoc

1   package org.apache.maven.continuum.web.action.admin;
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.IOException;
23  import java.util.ArrayList;
24  import java.util.List;
25  import java.util.Map;
26  
27  import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
28  import org.apache.maven.artifact.repository.ArtifactRepository;
29  import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
30  import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
31  import org.apache.maven.continuum.execution.maven.m2.MavenBuilderHelper;
32  import org.apache.maven.continuum.execution.maven.m2.SettingsConfigurationException;
33  import org.apache.maven.continuum.security.ContinuumRoleConstants;
34  import org.apache.maven.continuum.web.action.component.AbstractFooterAction;
35  import org.apache.maven.continuum.web.appareance.AppareanceConfiguration;
36  import org.apache.maven.model.Model;
37  import org.apache.maven.project.ProjectBuildingException;
38  import org.apache.maven.settings.MavenSettingsBuilder;
39  import org.apache.maven.settings.Profile;
40  import org.apache.maven.settings.Repository;
41  import org.apache.maven.settings.Settings;
42  import org.apache.maven.shared.app.company.CompanyPomHandler;
43  import org.apache.maven.shared.app.configuration.Configuration;
44  import org.apache.maven.shared.app.configuration.MavenAppConfiguration;
45  import org.codehaus.plexus.redback.rbac.Resource;
46  import org.codehaus.plexus.registry.RegistryException;
47  import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
48  import org.codehaus.redback.integration.interceptor.SecureAction;
49  import org.codehaus.redback.integration.interceptor.SecureActionBundle;
50  import org.codehaus.redback.integration.interceptor.SecureActionException;
51  
52  import com.opensymphony.xwork2.ModelDriven;
53  
54  /**
55   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
56   * @version $Id: ConfigureAppearanceAction.java 729461 2008-12-26 08:38:10Z olamy $
57   * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="configureAppearance"
58   */
59  public class ConfigureAppearanceAction
60      extends AbstractFooterAction
61      implements ModelDriven, SecureAction
62  {
63      /**
64       * @plexus.requirement
65       */
66      private MavenAppConfiguration appConfiguration;
67  
68      /**
69       * The configuration.
70       */
71      private Configuration configuration;
72  
73      private Model companyModel;
74  
75      /**
76       * @plexus.requirement
77       */
78      private CompanyPomHandler companyPomHandler;
79  
80      /**
81       * @plexus.requirement
82       */
83      private MavenBuilderHelper helper;
84  
85      /**
86       * @plexus.requirement
87       */
88      private MavenSettingsBuilder mavenSettingsBuilder;
89  
90      /**
91       * @plexus.requirement
92       */
93      private ArtifactRepositoryFactory artifactRepositoryFactory;
94  
95      /**
96       * @plexus.requirement role-hint="default"
97       */
98      private ArtifactRepositoryLayout layout;
99  
100     /**
101      * @plexus.requirement
102      */
103     private AppareanceConfiguration appareanceConfiguration;
104 
105     public String execute()
106         throws IOException, RegistryException
107     {
108         appConfiguration.save( configuration );
109 
110         return SUCCESS;
111     }
112 
113     public String input()
114         throws IOException, RegistryException
115     {
116         return INPUT;
117     }
118 
119     public Object getModel()
120     {
121         return configuration;
122     }
123 
124     public void prepare()
125         throws ProjectBuildingException, ArtifactMetadataRetrievalException, SettingsConfigurationException,
126         XmlPullParserException, IOException
127     {
128 
129         Settings settings = mavenSettingsBuilder.buildSettings( false );
130 
131         // Load extra repositories from active profiles
132         List<String> profileIds = settings.getActiveProfiles();
133         List<Profile> profiles = settings.getProfiles();
134         List<ArtifactRepository> remoteRepositories = new ArrayList<ArtifactRepository>();
135         Map<String, Profile> profilesAsMap = settings.getProfilesAsMap();
136         if ( profileIds != null && !profileIds.isEmpty() )
137         {
138             for ( String profileId : profileIds )
139             {
140                 Profile profile = profilesAsMap.get( profileId );
141                 if ( profile != null )
142                 {
143                     List<Repository> repos = profile.getRepositories();
144                     if ( repos != null && !repos.isEmpty() )
145                     {
146                         for ( Repository repo : repos )
147                         {
148                             remoteRepositories.add(
149                                 artifactRepositoryFactory.createArtifactRepository( repo.getId(), repo
150                                     .getUrl(), layout, null, null ) );
151                         }
152                     }
153                 }
154             }
155         }
156         configuration = appConfiguration.getConfiguration();
157 
158         companyModel = companyPomHandler.getCompanyPomModel( configuration.getCompanyPom(), helper.getLocalRepository(),
159                                                              remoteRepositories );
160 
161         this.setFooter( appareanceConfiguration.getFooter() );
162     }
163 
164     public Model getCompanyModel()
165     {
166         return companyModel;
167     }
168 
169     public SecureActionBundle getSecureActionBundle()
170         throws SecureActionException
171     {
172         SecureActionBundle bundle = new SecureActionBundle();
173         bundle.setRequiresAuthentication( true );
174         bundle.addRequiredAuthorization( ContinuumRoleConstants.CONTINUUM_MANAGE_CONFIGURATION, Resource.GLOBAL );
175 
176         return bundle;
177     }
178 
179 }