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
58 public void prepare()
\r
60 this.legacyArtifactPath = new LegacyArtifactPath();
\r
63 public String input()
\r
68 public String commit()
\r
70 ArtifactReference artifact = new ArtifactReference();
\r
72 artifact.setGroupId( this.legacyArtifactPath.getGroupId() );
\r
73 artifact.setArtifactId( this.legacyArtifactPath.getArtifactId() );
\r
74 artifact.setClassifier( this.legacyArtifactPath.getClassifier() );
\r
75 artifact.setVersion( this.legacyArtifactPath.getVersion() );
\r
76 artifact.setType( this.legacyArtifactPath.getType() );
\r
78 String path = repositoryContent.toPath( artifact );
\r
79 if ( ! path.equals( this.legacyArtifactPath.getPath() ) )
\r
81 addActionError( "artifact reference does not match the initial path : " + path );
\r
85 Configuration configuration = archivaConfiguration.getConfiguration();
\r
86 configuration.addLegacyArtifactPath( legacyArtifactPath );
\r
87 return saveConfiguration( configuration );
\r
90 public LegacyArtifactPath getLegacyArtifactPath()
\r
92 return legacyArtifactPath;
\r
95 public void setLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
\r
97 this.legacyArtifactPath = legacyArtifactPath;
\r
100 protected String saveConfiguration( Configuration configuration )
\r
104 archivaConfiguration.save( configuration );
\r
105 addActionMessage( "Successfully saved configuration" );
\r
107 catch ( IndeterminateConfigurationException e )
\r
109 addActionError( e.getMessage() );
\r
112 catch ( RegistryException e )
\r
114 addActionError( "Configuration Registry Exception: " + e.getMessage() );
\r