1 package org.apache.maven.continuum.web.action.admin;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import com.opensymphony.xwork2.ModelDriven;
23 import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
24 import org.apache.maven.artifact.repository.ArtifactRepository;
25 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
26 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
27 import org.apache.maven.continuum.execution.maven.m2.MavenBuilderHelper;
28 import org.apache.maven.continuum.execution.maven.m2.SettingsConfigurationException;
29 import org.apache.maven.continuum.security.ContinuumRoleConstants;
30 import org.apache.maven.continuum.web.action.component.AbstractFooterAction;
31 import org.apache.maven.continuum.web.appareance.AppareanceConfiguration;
32 import org.apache.maven.model.Model;
33 import org.apache.maven.project.ProjectBuildingException;
34 import org.apache.maven.settings.MavenSettingsBuilder;
35 import org.apache.maven.settings.Profile;
36 import org.apache.maven.settings.Repository;
37 import org.apache.maven.settings.Settings;
38 import org.apache.maven.shared.app.company.CompanyPomHandler;
39 import org.apache.maven.shared.app.configuration.Configuration;
40 import org.apache.maven.shared.app.configuration.MavenAppConfiguration;
41 import org.codehaus.plexus.redback.rbac.Resource;
42 import org.codehaus.plexus.registry.RegistryException;
43 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
44 import org.codehaus.redback.integration.interceptor.SecureAction;
45 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
46 import org.codehaus.redback.integration.interceptor.SecureActionException;
47
48 import java.io.IOException;
49 import java.util.ArrayList;
50 import java.util.List;
51 import java.util.Map;
52
53
54
55
56
57
58 public class ConfigureAppearanceAction
59 extends AbstractFooterAction
60 implements ModelDriven, SecureAction
61 {
62
63
64
65 private MavenAppConfiguration appConfiguration;
66
67
68
69
70 private Configuration configuration;
71
72 private Model companyModel;
73
74
75
76
77 private CompanyPomHandler companyPomHandler;
78
79
80
81
82 private MavenBuilderHelper helper;
83
84
85
86
87 private MavenSettingsBuilder mavenSettingsBuilder;
88
89
90
91
92 private ArtifactRepositoryFactory artifactRepositoryFactory;
93
94
95
96
97 private ArtifactRepositoryLayout layout;
98
99
100
101
102 private AppareanceConfiguration appareanceConfiguration;
103
104 public String execute()
105 throws IOException, RegistryException
106 {
107 appConfiguration.save( configuration );
108
109 return SUCCESS;
110 }
111
112 public String input()
113 throws IOException, RegistryException
114 {
115 return INPUT;
116 }
117
118 public Object getModel()
119 {
120 return configuration;
121 }
122
123 public void prepare()
124 throws ProjectBuildingException, ArtifactMetadataRetrievalException, SettingsConfigurationException,
125 XmlPullParserException, IOException
126 {
127
128 Settings settings = mavenSettingsBuilder.buildSettings( false );
129
130
131 List<String> profileIds = settings.getActiveProfiles();
132 List<Profile> profiles = settings.getProfiles();
133 List<ArtifactRepository> remoteRepositories = new ArrayList<ArtifactRepository>();
134 Map<String, Profile> profilesAsMap = settings.getProfilesAsMap();
135 if ( profileIds != null && !profileIds.isEmpty() )
136 {
137 for ( String profileId : profileIds )
138 {
139 Profile profile = profilesAsMap.get( profileId );
140 if ( profile != null )
141 {
142 List<Repository> repos = profile.getRepositories();
143 if ( repos != null && !repos.isEmpty() )
144 {
145 for ( Repository repo : repos )
146 {
147 remoteRepositories.add( artifactRepositoryFactory.createArtifactRepository( repo.getId(),
148 repo.getUrl(),
149 layout, null,
150 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 }