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