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;
29 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
31 import com.opensymphony.webwork.components.ActionError;
32 import com.opensymphony.xwork.Preparable;
35 * Add a LegacyArtifactPath to archiva configuration
38 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="addLegacyArtifactPathAction"
40 public class AddLegacyArtifactPathAction
41 extends PlexusActionSupport
47 private ArchivaConfiguration archivaConfiguration;
50 * @plexus.requirement role-hint="legacy"
52 private ManagedRepositoryContent repositoryContent;
55 private LegacyArtifactPath legacyArtifactPath;
57 private String groupId;
59 private String artifactId;
61 private String version;
63 private String classifier;
70 this.legacyArtifactPath = new LegacyArtifactPath();
78 public String commit()
80 this.legacyArtifactPath.setArtifact(
81 this.groupId + ":" + this.artifactId + ":" + this.classifier + ":" + this.version + ":" + this.type );
83 // Check the proposed Artifact macthes the path
84 ArtifactReference artifact = new ArtifactReference();
86 artifact.setGroupId( this.groupId );
87 artifact.setArtifactId( this.artifactId );
88 artifact.setClassifier( this.classifier );
89 artifact.setVersion( this.version );
90 artifact.setType( this.type );
92 String path = repositoryContent.toPath( artifact );
93 if ( ! path.equals( this.legacyArtifactPath.getPath() ) )
95 addActionError( "artifact reference does not match the initial path : " + path );
99 Configuration configuration = archivaConfiguration.getConfiguration();
100 configuration.addLegacyArtifactPath( legacyArtifactPath );
101 return saveConfiguration( configuration );
104 public LegacyArtifactPath getLegacyArtifactPath()
106 return legacyArtifactPath;
109 public void setLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
111 this.legacyArtifactPath = legacyArtifactPath;
114 protected String saveConfiguration( Configuration configuration )
118 archivaConfiguration.save( configuration );
119 addActionMessage( "Successfully saved configuration" );
121 catch ( IndeterminateConfigurationException e )
123 addActionError( e.getMessage() );
126 catch ( RegistryException e )
128 addActionError( "Configuration Registry Exception: " + e.getMessage() );
135 public String getGroupId()
140 public void setGroupId( String groupId )
142 this.groupId = groupId;
145 public String getArtifactId()
150 public void setArtifactId( String artifactId )
152 this.artifactId = artifactId;
155 public String getVersion()
160 public void setVersion( String version )
162 this.version = version;
165 public String getClassifier()
170 public void setClassifier( String classifier )
172 this.classifier = classifier;
175 public String getType()
180 public void setType( String type )