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.

AbstractArtifactDiscoverer.java 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package org.apache.maven.repository.discovery;
  2. /*
  3. * Copyright 2001-2005 The Apache Software Foundation.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import org.codehaus.plexus.logging.AbstractLogEnabled;
  18. import org.codehaus.plexus.util.DirectoryScanner;
  19. import org.codehaus.plexus.util.FileUtils;
  20. import java.io.File;
  21. import java.util.ArrayList;
  22. import java.util.Arrays;
  23. import java.util.Iterator;
  24. import java.util.List;
  25. /**
  26. * Base class for artifact discoverers.
  27. *
  28. * @author John Casey
  29. * @author Brett Porter
  30. */
  31. public abstract class AbstractArtifactDiscoverer
  32. extends AbstractLogEnabled
  33. implements ArtifactDiscoverer
  34. {
  35. /**
  36. * Standard patterns to exclude from discovery as they are not artifacts.
  37. */
  38. private static final String[] STANDARD_DISCOVERY_EXCLUDES = {"bin/**", "reports/**", ".maven/**", "**/*.md5",
  39. "**/*.MD5", "**/*.sha1", "**/*.SHA1", "**/*snapshot-version", "*/website/**", "*/licenses/**", "*/licences/**",
  40. "**/.htaccess", "**/*.html", "**/*.asc", "**/*.txt", "**/*.xml", "**/README*", "**/CHANGELOG*", "**/KEYS*"};
  41. private static final String[] EMPTY_STRING_ARRAY = new String[0];
  42. private List excludedPaths = new ArrayList();
  43. private List kickedOutPaths = new ArrayList();
  44. /**
  45. * Scan the repository for artifact paths.
  46. *
  47. * @todo replace blacklisted patterns by an artifact filter
  48. */
  49. protected String[] scanForArtifactPaths( File repositoryBase, String blacklistedPatterns )
  50. {
  51. List allExcludes = new ArrayList();
  52. allExcludes.addAll( FileUtils.getDefaultExcludesAsList() );
  53. allExcludes.addAll( Arrays.asList( STANDARD_DISCOVERY_EXCLUDES ) );
  54. if ( blacklistedPatterns != null && blacklistedPatterns.length() > 0 )
  55. {
  56. allExcludes.addAll( Arrays.asList( blacklistedPatterns.split( "," ) ) );
  57. }
  58. DirectoryScanner scanner = new DirectoryScanner();
  59. scanner.setBasedir( repositoryBase );
  60. scanner.setExcludes( (String[]) allExcludes.toArray( EMPTY_STRING_ARRAY ) );
  61. scanner.scan();
  62. excludedPaths.addAll( Arrays.asList( scanner.getExcludedFiles() ) );
  63. return scanner.getIncludedFiles();
  64. }
  65. /**
  66. * Add a path to the list of files that were kicked out due to being invalid.
  67. *
  68. * @param path the path to add
  69. * @todo add a reason
  70. */
  71. protected void addKickedOutPath( String path )
  72. {
  73. kickedOutPaths.add( path );
  74. }
  75. public Iterator getExcludedPathsIterator()
  76. {
  77. return excludedPaths.iterator();
  78. }
  79. public Iterator getKickedOutPathsIterator()
  80. {
  81. return kickedOutPaths.iterator();
  82. }
  83. }