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 org.apache.maven.archiva.web.action.PlexusActionSupport;
34 * Add a LegacyArtifactPath to archiva configuration
37 * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="addLegacyArtifactPathAction" instantiation-strategy="per-lookup"
39 public class AddLegacyArtifactPathAction
40 extends PlexusActionSupport
46 private ArchivaConfiguration archivaConfiguration;
49 * @plexus.requirement role-hint="legacy"
51 private ManagedRepositoryContent repositoryContent;
54 private LegacyArtifactPath legacyArtifactPath;
56 private String groupId;
58 private String artifactId;
60 private String version;
62 private String classifier;
69 this.legacyArtifactPath = new LegacyArtifactPath();
77 public String commit()
79 this.legacyArtifactPath.setArtifact(
80 this.groupId + ":" + this.artifactId + ":" + this.classifier + ":" + this.version + ":" + this.type );
82 // Check the proposed Artifact macthes the path
83 ArtifactReference artifact = new ArtifactReference();
85 artifact.setGroupId( this.groupId );
86 artifact.setArtifactId( this.artifactId );
87 artifact.setClassifier( this.classifier );
88 artifact.setVersion( this.version );
89 artifact.setType( this.type );
91 String path = repositoryContent.toPath( artifact );
92 if ( ! path.equals( this.legacyArtifactPath.getPath() ) )
94 addActionError( "artifact reference does not match the initial path : " + path );
98 Configuration configuration = archivaConfiguration.getConfiguration();
99 configuration.addLegacyArtifactPath( legacyArtifactPath );
100 return saveConfiguration( configuration );
103 public LegacyArtifactPath getLegacyArtifactPath()
105 return legacyArtifactPath;
108 public void setLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
110 this.legacyArtifactPath = legacyArtifactPath;
113 protected String saveConfiguration( Configuration configuration )
117 archivaConfiguration.save( configuration );
118 addActionMessage( "Successfully saved configuration" );
120 catch ( IndeterminateConfigurationException e )
122 addActionError( e.getMessage() );
125 catch ( RegistryException e )
127 addActionError( "Configuration Registry Exception: " + e.getMessage() );
134 public String getGroupId()
139 public void setGroupId( String groupId )
141 this.groupId = groupId;
144 public String getArtifactId()
149 public void setArtifactId( String artifactId )
151 this.artifactId = artifactId;
154 public String getVersion()
159 public void setVersion( String version )
161 this.version = version;
164 public String getClassifier()
169 public void setClassifier( String classifier )
171 this.classifier = classifier;
174 public String getType()
179 public void setType( String type )