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.

DeleteLegacyArtifactPathAction.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 java.util.Iterator;
  21. import org.apache.maven.archiva.configuration.ArchivaConfiguration;
  22. import org.apache.maven.archiva.configuration.Configuration;
  23. import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
  24. import org.apache.maven.archiva.configuration.LegacyArtifactPath;
  25. import org.apache.maven.archiva.web.action.PlexusActionSupport;
  26. import org.codehaus.plexus.registry.RegistryException;
  27. /**
  28. * Delete a LegacyArtifactPath to archiva configuration
  29. *
  30. *
  31. * @since 1.1
  32. * @plexus.component role="com.opensymphony.xwork2.Action" role-hint="deleteLegacyArtifactPathAction"
  33. */
  34. public class DeleteLegacyArtifactPathAction
  35. extends PlexusActionSupport
  36. {
  37. /**
  38. * @plexus.requirement
  39. */
  40. private ArchivaConfiguration archivaConfiguration;
  41. private String path;
  42. public String delete()
  43. {
  44. getLogger().info( "remove [" + path + "] from legacy artifact path resolution" );
  45. Configuration configuration = archivaConfiguration.getConfiguration();
  46. for ( Iterator iterator = configuration.getLegacyArtifactPaths().iterator(); iterator.hasNext(); )
  47. {
  48. LegacyArtifactPath legacyArtifactPath = (LegacyArtifactPath) iterator.next();
  49. if (legacyArtifactPath.match( path ))
  50. {
  51. iterator.remove();
  52. }
  53. }
  54. return saveConfiguration( configuration );
  55. }
  56. protected String saveConfiguration( Configuration configuration )
  57. {
  58. try
  59. {
  60. archivaConfiguration.save( configuration );
  61. addActionMessage( "Successfully saved configuration" );
  62. }
  63. catch ( IndeterminateConfigurationException e )
  64. {
  65. addActionError( e.getMessage() );
  66. return INPUT;
  67. }
  68. catch ( RegistryException e )
  69. {
  70. addActionError( "Configuration Registry Exception: " + e.getMessage() );
  71. return INPUT;
  72. }
  73. return SUCCESS;
  74. }
  75. public String getPath()
  76. {
  77. return path;
  78. }
  79. public void setPath( String path )
  80. {
  81. this.path = path;
  82. }
  83. }