1 package org.apache.maven.archiva.web.action.admin.legacy;
\r
4 * Licensed to the Apache Software Foundation (ASF) under one
\r
5 * or more contributor license agreements. See the NOTICE file
\r
6 * distributed with this work for additional information
\r
7 * regarding copyright ownership. The ASF licenses this file
\r
8 * to you under the Apache License, Version 2.0 (the
\r
9 * "License"); you may not use this file except in compliance
\r
10 * with the License. You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing,
\r
15 * software distributed under the License is distributed on an
\r
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
\r
17 * KIND, either express or implied. See the License for the
\r
18 * specific language governing permissions and limitations
\r
19 * under the License.
\r
22 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
\r
23 import org.apache.maven.archiva.configuration.Configuration;
\r
24 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
\r
25 import org.apache.maven.archiva.configuration.LegacyArtifactPath;
\r
26 import org.apache.maven.archiva.model.ArtifactReference;
\r
27 import org.apache.maven.archiva.repository.ManagedRepositoryContent;
\r
28 import org.codehaus.plexus.registry.RegistryException;
\r
29 import org.codehaus.plexus.xwork.action.PlexusActionSupport;
\r
31 import com.opensymphony.webwork.components.ActionError;
\r
32 import com.opensymphony.xwork.Preparable;
\r
35 * Add a LegacyArtifactPath to archiva configuration
\r
38 * @plexus.component role="com.opensymphony.xwork.Action" role-hint="addLegacyArtifactPathAction"
\r
40 public class AddLegacyArtifactPathAction
\r
41 extends PlexusActionSupport
\r
42 implements Preparable
\r
45 * @plexus.requirement
\r
47 private ArchivaConfiguration archivaConfiguration;
\r
50 * @plexus.requirement role-hint="legacy"
\r
52 private ManagedRepositoryContent repositoryContent;
\r
55 private LegacyArtifactPath legacyArtifactPath;
\r
57 private String groupId;
\r
59 private String artifactId;
\r
61 private String version;
\r
63 private String classifier;
\r
65 private String type;
\r
68 public void prepare()
\r
70 this.legacyArtifactPath = new LegacyArtifactPath();
\r
73 public String input()
\r
78 public String commit()
\r
80 this.legacyArtifactPath.setArtifact(
\r
81 this.groupId + ":" + this.artifactId + ":" + this.classifier + ":" + this.version + ":" + this.type );
\r
83 // Check the proposed Artifact macthes the path
\r
84 ArtifactReference artifact = new ArtifactReference();
\r
86 artifact.setGroupId( this.groupId );
\r
87 artifact.setArtifactId( this.artifactId );
\r
88 artifact.setClassifier( this.classifier );
\r
89 artifact.setVersion( this.version );
\r
90 artifact.setType( this.type );
\r
92 String path = repositoryContent.toPath( artifact );
\r
93 if ( ! path.equals( this.legacyArtifactPath.getPath() ) )
\r
95 addActionError( "artifact reference does not match the initial path : " + path );
\r
99 Configuration configuration = archivaConfiguration.getConfiguration();
\r
100 configuration.addLegacyArtifactPath( legacyArtifactPath );
\r
101 return saveConfiguration( configuration );
\r
104 public LegacyArtifactPath getLegacyArtifactPath()
\r
106 return legacyArtifactPath;
\r
109 public void setLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
\r
111 this.legacyArtifactPath = legacyArtifactPath;
\r
114 protected String saveConfiguration( Configuration configuration )
\r
118 archivaConfiguration.save( configuration );
\r
119 addActionMessage( "Successfully saved configuration" );
\r
121 catch ( IndeterminateConfigurationException e )
\r
123 addActionError( e.getMessage() );
\r
126 catch ( RegistryException e )
\r
128 addActionError( "Configuration Registry Exception: " + e.getMessage() );
\r
135 public String getGroupId()
\r
140 public void setGroupId( String groupId )
\r
142 this.groupId = groupId;
\r
145 public String getArtifactId()
\r
150 public void setArtifactId( String artifactId )
\r
152 this.artifactId = artifactId;
\r
155 public String getVersion()
\r
160 public void setVersion( String version )
\r
162 this.version = version;
\r
165 public String getClassifier()
\r
170 public void setClassifier( String classifier )
\r
172 this.classifier = classifier;
\r
175 public String getType()
\r
180 public void setType( String type )
\r