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
44 * plexus.component role="com.opensymphony.xwork2.Action" role-hint="addLegacyArtifactPathAction" instantiation-strategy="per-lookup"
46 @Controller( "addLegacyArtifactPathAction" )
48 public class AddLegacyArtifactPathAction
49 extends AbstractActionSupport
50 implements Preparable, Validateable
54 private ArchivaConfiguration archivaConfiguration;
57 @Named(value = "managedRepositoryContent#legacy")
58 private ManagedRepositoryContent repositoryContent;
61 private LegacyArtifactPath legacyArtifactPath;
63 private String groupId;
65 private String artifactId;
67 private String version;
69 private String classifier;
76 this.legacyArtifactPath = new LegacyArtifactPath();
84 public String commit()
86 this.legacyArtifactPath.setArtifact( this.groupId + ":" + this.artifactId + ":" + this.version + ":" +
87 this.classifier + ":" + this.type );
89 // Check the proposed Artifact macthes the path
90 ArtifactReference artifact = new ArtifactReference();
92 artifact.setGroupId( this.groupId );
93 artifact.setArtifactId( this.artifactId );
94 artifact.setClassifier( this.classifier );
95 artifact.setVersion( this.version );
96 artifact.setType( this.type );
98 String path = repositoryContent.toPath( artifact );
99 if ( ! path.equals( this.legacyArtifactPath.getPath() ) )
101 addActionError( "artifact reference does not match the initial path : " + path );
105 Configuration configuration = archivaConfiguration.getConfiguration();
106 configuration.addLegacyArtifactPath( legacyArtifactPath );
107 return saveConfiguration( configuration );
110 public LegacyArtifactPath getLegacyArtifactPath()
112 return legacyArtifactPath;
115 public void setLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
117 this.legacyArtifactPath = legacyArtifactPath;
120 public void validate()
122 // trim all unecessary trailing/leading white-spaces; always put this statement before the closing braces(after all validation).
123 trimAllRequestParameterValues();
126 protected String saveConfiguration( Configuration configuration )
130 archivaConfiguration.save( configuration );
131 addActionMessage( "Successfully saved configuration" );
133 catch ( IndeterminateConfigurationException e )
135 addActionError( e.getMessage() );
138 catch ( RegistryException e )
140 addActionError( "Configuration Registry Exception: " + e.getMessage() );
147 private void trimAllRequestParameterValues()
149 if(StringUtils.isNotEmpty(legacyArtifactPath.getPath()))
151 legacyArtifactPath.setPath(legacyArtifactPath.getPath().trim());
154 if(StringUtils.isNotEmpty(groupId))
156 groupId = groupId.trim();
159 if(StringUtils.isNotEmpty(artifactId))
161 artifactId = artifactId.trim();
164 if(StringUtils.isNotEmpty(version))
166 version = version.trim();
169 if(StringUtils.isNotEmpty(classifier))
171 classifier = classifier.trim();
174 if(StringUtils.isNotEmpty(type))
180 public String getGroupId()
185 public void setGroupId( String groupId )
187 this.groupId = groupId;
190 public String getArtifactId()
195 public void setArtifactId( String artifactId )
197 this.artifactId = artifactId;
200 public String getVersion()
205 public void setVersion( String version )
207 this.version = version;
210 public String getClassifier()
215 public void setClassifier( String classifier )
217 this.classifier = classifier;
220 public String getType()
225 public void setType( String type )