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 com.opensymphony.xwork2.ModelDriven;
23  import org.apache.maven.artifact.installer.ArtifactInstallationException;
24  import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
25  import org.apache.maven.continuum.execution.maven.m2.MavenBuilderHelper;
26  import org.apache.maven.continuum.execution.maven.m2.SettingsConfigurationException;
27  import org.apache.maven.continuum.security.ContinuumRoleConstants;
28  import org.apache.maven.continuum.web.action.ContinuumActionSupport;
29  import org.apache.maven.model.Model;
30  import org.apache.maven.project.ProjectBuildingException;
31  import org.apache.maven.shared.app.company.CompanyPomHandler;
32  import org.apache.maven.shared.app.configuration.CompanyPom;
33  import org.apache.maven.shared.app.configuration.Configuration;
34  import org.apache.maven.shared.app.configuration.MavenAppConfiguration;
35  import org.codehaus.plexus.redback.rbac.Resource;
36  import org.codehaus.redback.integration.interceptor.SecureAction;
37  import org.codehaus.redback.integration.interceptor.SecureActionBundle;
38  import org.codehaus.redback.integration.interceptor.SecureActionException;
39  
40  import java.io.IOException;
41  
42  /**
43   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
44   * @version $Id: EditPomAction.java 1372260 2012-08-13 04:29:09Z brett $
45   * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="editPom"
46   */
47  public class EditPomAction
48      extends ContinuumActionSupport
49      implements ModelDriven, SecureAction
50  {
51      /**
52       * @plexus.requirement
53       */
54      private MavenAppConfiguration appConfiguration;
55  
56      /**
57       * @plexus.requirement
58       */
59      private CompanyPomHandler companyPomHandler;
60  
61      private Model companyModel;
62  
63      /**
64       * @plexus.requirement
65       */
66      private MavenBuilderHelper helper;
67  
68      public String execute()
69          throws IOException, ArtifactInstallationException, SettingsConfigurationException
70      {
71          // TODO: hack for passed in String[]
72          String[] logo = (String[]) companyModel.getProperties().get( "organization.logo" );
73          if ( logo != null )
74          {
75              companyModel.getProperties().put( "organization.logo", logo[0] );
76          }
77  
78          companyPomHandler.save( companyModel, helper.getLocalRepository() );
79  
80          return SUCCESS;
81      }
82  
83      public String input()
84      {
85          return INPUT;
86      }
87  
88      public Object getModel()
89      {
90          return companyModel;
91      }
92  
93      public void prepare()
94          throws ProjectBuildingException, ArtifactMetadataRetrievalException, SettingsConfigurationException
95      {
96          Configuration configuration = appConfiguration.getConfiguration();
97  
98          CompanyPom companyPom = configuration.getCompanyPom();
99          companyModel = companyPomHandler.getCompanyPomModel( companyPom, helper.getLocalRepository() );
100 
101         if ( companyModel == null )
102         {
103             companyModel = new Model();
104             companyModel.setModelVersion( "4.0.0" );
105             companyModel.setPackaging( "pom" );
106 
107             if ( companyPom != null )
108             {
109                 companyModel.setGroupId( companyPom.getGroupId() );
110                 companyModel.setArtifactId( companyPom.getArtifactId() );
111             }
112         }
113     }
114 
115     public Model getCompanyModel()
116     {
117         return companyModel;
118     }
119 
120     public SecureActionBundle getSecureActionBundle()
121         throws SecureActionException
122     {
123         SecureActionBundle bundle = new SecureActionBundle();
124         bundle.setRequiresAuthentication( true );
125         bundle.addRequiredAuthorization( ContinuumRoleConstants.CONTINUUM_MANAGE_CONFIGURATION, Resource.GLOBAL );
126 
127         return bundle;
128     }
129 }