You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AddLegacyArtifactPathAction.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package org.apache.maven.archiva.web.action.admin.legacy;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.apache.maven.archiva.configuration.ArchivaConfiguration;
  21. import org.apache.maven.archiva.configuration.Configuration;
  22. import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
  23. import org.apache.maven.archiva.configuration.LegacyArtifactPath;
  24. import org.apache.maven.archiva.model.ArtifactReference;
  25. import org.apache.maven.archiva.repository.ManagedRepositoryContent;
  26. import org.codehaus.plexus.registry.RegistryException;
  27. import com.opensymphony.xwork2.Preparable;
  28. import org.apache.maven.archiva.web.action.PlexusActionSupport;
  29. /**
  30. * Add a LegacyArtifactPath to archiva configuration
  31. *
  32. * @since 1.1
  33. * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="addLegacyArtifactPathAction"
  34. */
  35. public class AddLegacyArtifactPathAction
  36. extends PlexusActionSupport
  37. implements Preparable
  38. {
  39. /**
  40. * @plexus.requirement
  41. */
  42. private ArchivaConfiguration archivaConfiguration;
  43. /**
  44. * @plexus.requirement role-hint="legacy"
  45. */
  46. private ManagedRepositoryContent repositoryContent;
  47. private LegacyArtifactPath legacyArtifactPath;
  48. private String groupId;
  49. private String artifactId;
  50. private String version;
  51. private String classifier;
  52. private String type;
  53. public void prepare()
  54. {
  55. this.legacyArtifactPath = new LegacyArtifactPath();
  56. }
  57. public String input()
  58. {
  59. return INPUT;
  60. }
  61. public String commit()
  62. {
  63. this.legacyArtifactPath.setArtifact(
  64. this.groupId + ":" + this.artifactId + ":" + this.classifier + ":" + this.version + ":" + this.type );
  65. // Check the proposed Artifact macthes the path
  66. ArtifactReference artifact = new ArtifactReference();
  67. artifact.setGroupId( this.groupId );
  68. artifact.setArtifactId( this.artifactId );
  69. artifact.setClassifier( this.classifier );
  70. artifact.setVersion( this.version );
  71. artifact.setType( this.type );
  72. String path = repositoryContent.toPath( artifact );
  73. if ( ! path.equals( this.legacyArtifactPath.getPath() ) )
  74. {
  75. addActionError( "artifact reference does not match the initial path : " + path );
  76. return ERROR;
  77. }
  78. Configuration configuration = archivaConfiguration.getConfiguration();
  79. configuration.addLegacyArtifactPath( legacyArtifactPath );
  80. return saveConfiguration( configuration );
  81. }
  82. public LegacyArtifactPath getLegacyArtifactPath()
  83. {
  84. return legacyArtifactPath;
  85. }
  86. public void setLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath )
  87. {
  88. this.legacyArtifactPath = legacyArtifactPath;
  89. }
  90. protected String saveConfiguration( Configuration configuration )
  91. {
  92. try
  93. {
  94. archivaConfiguration.save( configuration );
  95. addActionMessage( "Successfully saved configuration" );
  96. }
  97. catch ( IndeterminateConfigurationException e )
  98. {
  99. addActionError( e.getMessage() );
  100. return INPUT;
  101. }
  102. catch ( RegistryException e )
  103. {
  104. addActionError( "Configuration Registry Exception: " + e.getMessage() );
  105. return INPUT;
  106. }
  107. return SUCCESS;
  108. }
  109. public String getGroupId()
  110. {
  111. return groupId;
  112. }
  113. public void setGroupId( String groupId )
  114. {
  115. this.groupId = groupId;
  116. }
  117. public String getArtifactId()
  118. {
  119. return artifactId;
  120. }
  121. public void setArtifactId( String artifactId )
  122. {
  123. this.artifactId = artifactId;
  124. }
  125. public String getVersion()
  126. {
  127. return version;
  128. }
  129. public void setVersion( String version )
  130. {
  131. this.version = version;
  132. }
  133. public String getClassifier()
  134. {
  135. return classifier;
  136. }
  137. public void setClassifier( String classifier )
  138. {
  139. this.classifier = classifier;
  140. }
  141. public String getType()
  142. {
  143. return type;
  144. }
  145. public void setType( String type )
  146. {
  147. this.type = type;
  148. }
  149. }