1 package org.apache.maven.archiva.web.action.admin.legacy;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
23 import org.apache.maven.archiva.configuration.Configuration;
24 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
25 import org.apache.maven.archiva.configuration.LegacyArtifactPath;
26 import org.apache.maven.archiva.model.ArtifactReference;
27 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
28 import org.codehaus.plexus.registry.RegistryException;
30 import com.opensymphony.xwork2.Preparable;
31 import com.opensymphony.xwork2.Validateable;
32 import org.apache.commons.lang.StringUtils;
33 import org.apache.maven.archiva.web.action.AbstractActionSupport;
34 import org.springframework.context.annotation.Scope;
35 import org.springframework.stereotype.Controller;
37 import javax.inject.Inject;
38 import javax.inject.Named;
41 * Add a LegacyArtifactPath to archiva configuration
45 @Controller( "addLegacyArtifactPathAction" )
47 public class AddLegacyArtifactPathAction
48 extends AbstractActionSupport
49 implements Preparable, Validateable
53 private ArchivaConfiguration archivaConfiguration;
56 @Named(value = "managedRepositoryContent#legacy")
57 private ManagedRepositoryContent repositoryContent;
60 private LegacyArtifactPath legacyArtifactPath;
62 private String groupId;
64 private String artifactId;
66 private String version;
68 private String classifier;
75 this.legacyArtifactPath = new LegacyArtifactPath();
83 public String commit()
85 this.legacyArtifactPath.setArtifact( this.groupId + ":" + this.artifactId + ":" + this.version + ":" +
86 this.classifier + ":" + this.type );
88 // Check the proposed Artifact macthes the path
89 ArtifactReference artifact = new ArtifactReference();
91 artifact.setGroupId( this.groupId );
92 artifact.setArtifactId( this.artifactId );
93 artifact.setClassifier( this.classifier );
94 artifact.setVersion( this.version );
95 artifact.setType( this.type );
97 String path = repositoryContent.toPath( artifact );
98 if ( ! path.equals( this.legacyArtifactPath.getPath() ) )
100 addActionError( "artifact reference does not match the initial path : " + path );
104 Configuration configuration = archivaConfiguration.getConfiguration();
105 configuration.addLegacyArtifactPath( legacyArtifactPath );
106 return saveConfiguration( configuration );
109 public LegacyArtifactPath getLegacyArtifactPath()
111 return legacyArtifactPath;
114 public void setLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
116 this.legacyArtifactPath = legacyArtifactPath;
119 public void validate()
121 // trim all unecessary trailing/leading white-spaces; always put this statement before the closing braces(after all validation).
122 trimAllRequestParameterValues();
125 protected String saveConfiguration( Configuration configuration )
129 archivaConfiguration.save( configuration );
130 addActionMessage( "Successfully saved configuration" );
132 catch ( IndeterminateConfigurationException e )
134 addActionError( e.getMessage() );
137 catch ( RegistryException e )
139 addActionError( "Configuration Registry Exception: " + e.getMessage() );
146 private void trimAllRequestParameterValues()
148 if(StringUtils.isNotEmpty(legacyArtifactPath.getPath()))
150 legacyArtifactPath.setPath(legacyArtifactPath.getPath().trim());
153 if(StringUtils.isNotEmpty(groupId))
155 groupId = groupId.trim();
158 if(StringUtils.isNotEmpty(artifactId))
160 artifactId = artifactId.trim();
163 if(StringUtils.isNotEmpty(version))
165 version = version.trim();
168 if(StringUtils.isNotEmpty(classifier))
170 classifier = classifier.trim();
173 if(StringUtils.isNotEmpty(type))
179 public String getGroupId()
184 public void setGroupId( String groupId )
186 this.groupId = groupId;
189 public String getArtifactId()
194 public void setArtifactId( String artifactId )
196 this.artifactId = artifactId;
199 public String getVersion()
204 public void setVersion( String version )
206 this.version = version;
209 public String getClassifier()
214 public void setClassifier( String classifier )
216 this.classifier = classifier;
219 public String getType()
224 public void setType( String type )