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.PlexusActionSupport;
36 * Add a LegacyArtifactPath to archiva configuration
39 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="addLegacyArtifactPathAction" instantiation-strategy="per-lookup"
41 public class AddLegacyArtifactPathAction
42 extends PlexusActionSupport
43 implements Preparable, Validateable
48 private ArchivaConfiguration archivaConfiguration;
51 * @plexus.requirement role-hint="legacy"
53 private ManagedRepositoryContent repositoryContent;
56 private LegacyArtifactPath legacyArtifactPath;
58 private String groupId;
60 private String artifactId;
62 private String version;
64 private String classifier;
71 this.legacyArtifactPath = new LegacyArtifactPath();
79 public String commit()
81 this.legacyArtifactPath.setArtifact( this.groupId + ":" + this.artifactId + ":" + this.version + ":" +
82 this.classifier + ":" + this.type );
84 // Check the proposed Artifact macthes the path
85 ArtifactReference artifact = new ArtifactReference();
87 artifact.setGroupId( this.groupId );
88 artifact.setArtifactId( this.artifactId );
89 artifact.setClassifier( this.classifier );
90 artifact.setVersion( this.version );
91 artifact.setType( this.type );
93 String path = repositoryContent.toPath( artifact );
94 if ( ! path.equals( this.legacyArtifactPath.getPath() ) )
96 addActionError( "artifact reference does not match the initial path : " + path );
100 Configuration configuration = archivaConfiguration.getConfiguration();
101 configuration.addLegacyArtifactPath( legacyArtifactPath );
102 return saveConfiguration( configuration );
105 public LegacyArtifactPath getLegacyArtifactPath()
107 return legacyArtifactPath;
110 public void setLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
112 this.legacyArtifactPath = legacyArtifactPath;
115 public void validate()
117 // trim all unecessary trailing/leading white-spaces; always put this statement before the closing braces(after all validation).
118 trimAllRequestParameterValues();
121 protected String saveConfiguration( Configuration configuration )
125 archivaConfiguration.save( configuration );
126 addActionMessage( "Successfully saved configuration" );
128 catch ( IndeterminateConfigurationException e )
130 addActionError( e.getMessage() );
133 catch ( RegistryException e )
135 addActionError( "Configuration Registry Exception: " + e.getMessage() );
142 private void trimAllRequestParameterValues()
144 if(StringUtils.isNotEmpty(legacyArtifactPath.getPath()))
146 legacyArtifactPath.setPath(legacyArtifactPath.getPath().trim());
149 if(StringUtils.isNotEmpty(groupId))
151 groupId = groupId.trim();
154 if(StringUtils.isNotEmpty(artifactId))
156 artifactId = artifactId.trim();
159 if(StringUtils.isNotEmpty(version))
161 version = version.trim();
164 if(StringUtils.isNotEmpty(classifier))
166 classifier = classifier.trim();
169 if(StringUtils.isNotEmpty(type))
175 public String getGroupId()
180 public void setGroupId( String groupId )
182 this.groupId = groupId;
185 public String getArtifactId()
190 public void setArtifactId( String artifactId )
192 this.artifactId = artifactId;
195 public String getVersion()
200 public void setVersion( String version )
202 this.version = version;
205 public String getClassifier()
210 public void setClassifier( String classifier )
212 this.classifier = classifier;
215 public String getType()
220 public void setType( String type )