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
56 private ArchivaConfiguration archivaConfiguration;
59 * plexus.requirement role-hint="legacy"
62 @Named(value = "managedRepositoryContent#legacy")
63 private ManagedRepositoryContent repositoryContent;
66 private LegacyArtifactPath legacyArtifactPath;
68 private String groupId;
70 private String artifactId;
72 private String version;
74 private String classifier;
81 this.legacyArtifactPath = new LegacyArtifactPath();
89 public String commit()
91 this.legacyArtifactPath.setArtifact( this.groupId + ":" + this.artifactId + ":" + this.version + ":" +
92 this.classifier + ":" + this.type );
94 // Check the proposed Artifact macthes the path
95 ArtifactReference artifact = new ArtifactReference();
97 artifact.setGroupId( this.groupId );
98 artifact.setArtifactId( this.artifactId );
99 artifact.setClassifier( this.classifier );
100 artifact.setVersion( this.version );
101 artifact.setType( this.type );
103 String path = repositoryContent.toPath( artifact );
104 if ( ! path.equals( this.legacyArtifactPath.getPath() ) )
106 addActionError( "artifact reference does not match the initial path : " + path );
110 Configuration configuration = archivaConfiguration.getConfiguration();
111 configuration.addLegacyArtifactPath( legacyArtifactPath );
112 return saveConfiguration( configuration );
115 public LegacyArtifactPath getLegacyArtifactPath()
117 return legacyArtifactPath;
120 public void setLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
122 this.legacyArtifactPath = legacyArtifactPath;
125 public void validate()
127 // trim all unecessary trailing/leading white-spaces; always put this statement before the closing braces(after all validation).
128 trimAllRequestParameterValues();
131 protected String saveConfiguration( Configuration configuration )
135 archivaConfiguration.save( configuration );
136 addActionMessage( "Successfully saved configuration" );
138 catch ( IndeterminateConfigurationException e )
140 addActionError( e.getMessage() );
143 catch ( RegistryException e )
145 addActionError( "Configuration Registry Exception: " + e.getMessage() );
152 private void trimAllRequestParameterValues()
154 if(StringUtils.isNotEmpty(legacyArtifactPath.getPath()))
156 legacyArtifactPath.setPath(legacyArtifactPath.getPath().trim());
159 if(StringUtils.isNotEmpty(groupId))
161 groupId = groupId.trim();
164 if(StringUtils.isNotEmpty(artifactId))
166 artifactId = artifactId.trim();
169 if(StringUtils.isNotEmpty(version))
171 version = version.trim();
174 if(StringUtils.isNotEmpty(classifier))
176 classifier = classifier.trim();
179 if(StringUtils.isNotEmpty(type))
185 public String getGroupId()
190 public void setGroupId( String groupId )
192 this.groupId = groupId;
195 public String getArtifactId()
200 public void setArtifactId( String artifactId )
202 this.artifactId = artifactId;
205 public String getVersion()
210 public void setVersion( String version )
212 this.version = version;
215 public String getClassifier()
220 public void setClassifier( String classifier )
222 this.classifier = classifier;
225 public String getType()
230 public void setType( String type )