Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

ProjectReaderConsumer.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package org.apache.maven.archiva.cli;
  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.io.File;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
  24. import org.apache.maven.archiva.consumers.ConsumerException;
  25. import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
  26. import org.apache.maven.archiva.model.ArchivaProjectModel;
  27. import org.apache.maven.archiva.repository.project.ProjectModelException;
  28. import org.apache.maven.archiva.repository.project.ProjectModelReader;
  29. import org.apache.maven.archiva.repository.project.readers.ProjectModel400Reader;
  30. /**
  31. * ProjectReaderConsumer
  32. *
  33. * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
  34. * @version $Id$
  35. *
  36. * @plexus.component role="org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer"
  37. * role-hint="read-poms"
  38. * instantiation-strategy="per-lookup"
  39. */
  40. public class ProjectReaderConsumer
  41. extends AbstractProgressConsumer
  42. implements KnownRepositoryContentConsumer
  43. {
  44. /**
  45. * @plexus.configuration default-value="read-poms"
  46. */
  47. private String id;
  48. /**
  49. * @plexus.configuration default-value="Read POMs and report anomolies."
  50. */
  51. private String description;
  52. private ProjectModelReader reader;
  53. private ManagedRepositoryConfiguration repo;
  54. private List includes;
  55. public ProjectReaderConsumer()
  56. {
  57. reader = new ProjectModel400Reader();
  58. includes = new ArrayList();
  59. includes.add( "**/*.pom" );
  60. }
  61. public String getDescription()
  62. {
  63. return description;
  64. }
  65. public String getId()
  66. {
  67. return id;
  68. }
  69. public boolean isPermanent()
  70. {
  71. return false;
  72. }
  73. public List getExcludes()
  74. {
  75. return null;
  76. }
  77. public List getIncludes()
  78. {
  79. return includes;
  80. }
  81. public void beginScan( ManagedRepositoryConfiguration repository )
  82. throws ConsumerException
  83. {
  84. super.beginScan( repository );
  85. this.repo = repository;
  86. }
  87. public void processFile( String path )
  88. throws ConsumerException
  89. {
  90. super.processFile( path );
  91. File pomFile = new File( repo.getLocation(), path );
  92. try
  93. {
  94. ArchivaProjectModel model = reader.read( pomFile );
  95. if ( model == null )
  96. {
  97. System.err.println( "Got null model on " + pomFile );
  98. }
  99. }
  100. catch ( ProjectModelException e )
  101. {
  102. System.err.println( "Unable to process: " + pomFile );
  103. e.printStackTrace( System.out );
  104. }
  105. }
  106. }