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 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
56
57
58
59 public class ConfigureAppearanceAction
60 extends AbstractFooterAction
61 implements ModelDriven, SecureAction
62 {
63
64
65
66 private MavenAppConfiguration appConfiguration;
67
68
69
70
71 private Configuration configuration;
72
73 private Model companyModel;
74
75
76
77
78 private CompanyPomHandler companyPomHandler;
79
80
81
82
83 private MavenBuilderHelper helper;
84
85
86
87
88 private MavenSettingsBuilder mavenSettingsBuilder;
89
90
91
92
93 private ArtifactRepositoryFactory artifactRepositoryFactory;
94
95
96
97
98 private ArtifactRepositoryLayout layout;
99
100
101
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
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 }