@@ -53,8 +53,74 @@ | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>metadata-model</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>archiva-storage-api</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>archiva-storage-fs</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>archiva-filelock</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>archiva-model</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>archiva-repository-layer</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>archiva-common</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.archiva</groupId> | |||
<artifactId>archiva-repository-api</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.archiva.components.registry</groupId> | |||
<artifactId>archiva-components-spring-registry-api</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>javax.inject</groupId> | |||
<artifactId>javax.inject</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.springframework</groupId> | |||
<artifactId>spring-core</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.springframework</groupId> | |||
<artifactId>spring-beans</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.commons</groupId> | |||
<artifactId>commons-lang3</artifactId> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.commons</groupId> | |||
<artifactId>commons-collections4</artifactId> | |||
</dependency> | |||
<!-- Test scope --> | |||
<dependency> | |||
<groupId>commons-io</groupId> | |||
<artifactId>commons-io</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.springframework</groupId> | |||
<artifactId>spring-test</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.archiva.maven</groupId> | |||
<artifactId>archiva-maven-metadata</artifactId> | |||
@@ -70,11 +136,6 @@ | |||
<artifactId>commons-beanutils</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.slf4j</groupId> | |||
<artifactId>slf4j-simple</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.apache.logging.log4j</groupId> | |||
<artifactId>log4j-jcl</artifactId> | |||
@@ -104,6 +165,13 @@ | |||
</systemPropertyVariables> | |||
</configuration> | |||
</plugin> | |||
<plugin> | |||
<groupId>org.apache.maven.plugins</groupId> | |||
<artifactId>maven-resources-plugin</artifactId> | |||
<configuration> | |||
<addDefaultExcludes>false</addDefaultExcludes> | |||
</configuration> | |||
</plugin> | |||
</plugins> | |||
<pluginManagement> | |||
<plugins> | |||
@@ -112,11 +180,13 @@ | |||
<artifactId>apache-rat-plugin</artifactId> | |||
<configuration> | |||
<excludes> | |||
<exclude>src/test/repositories/**</exclude> | |||
<exclude>src/test/resources/repositories/**</exclude> | |||
</excludes> | |||
</configuration> | |||
</plugin> | |||
</plugins> | |||
</pluginManagement> | |||
</build> | |||
</project> |
@@ -92,6 +92,7 @@ public class KnownScanConsumer | |||
public void processFile( String path ) | |||
throws ConsumerException | |||
{ | |||
logger.info( "Processing {}", path); | |||
this.processCount++; | |||
} | |||
@@ -33,6 +33,7 @@ import org.apache.archiva.repository.storage.FilesystemStorage; | |||
import org.apache.archiva.repository.scanner.mock.ManagedRepositoryContentMock; | |||
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; | |||
import org.apache.commons.io.FileUtils; | |||
import org.hamcrest.CoreMatchers; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.springframework.context.ApplicationContext; | |||
@@ -42,6 +43,7 @@ import javax.inject.Inject; | |||
import java.io.IOException; | |||
import java.net.URI; | |||
import java.net.URISyntaxException; | |||
import java.net.URL; | |||
import java.nio.file.Files; | |||
import java.nio.file.Path; | |||
import java.nio.file.Paths; | |||
@@ -50,10 +52,14 @@ import java.text.ParseException; | |||
import java.text.SimpleDateFormat; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.Comparator; | |||
import java.util.List; | |||
import java.util.Locale; | |||
import java.util.TimeZone; | |||
import static org.hamcrest.CoreMatchers.is; | |||
import static org.junit.Assert.assertThat; | |||
/** | |||
* RepositoryScannerTest | |||
*/ | |||
@@ -66,6 +72,22 @@ public class RepositoryScannerTest | |||
@Inject | |||
ApplicationContext applicationContext; | |||
Path repoBaseDir; | |||
private Path getRepoBaseDir() { | |||
if (repoBaseDir==null) { | |||
try | |||
{ | |||
repoBaseDir =Paths.get(Thread.currentThread( ).getContextClassLoader( ).getResource( "repositories" ).toURI()); | |||
} | |||
catch ( URISyntaxException e ) | |||
{ | |||
throw new RuntimeException( "Could not retrieve repository base directory" ); | |||
} | |||
} | |||
return repoBaseDir; | |||
} | |||
protected EditableManagedRepository createRepository( String id, String name, Path location ) throws IOException { | |||
FileLockManager lockManager = new DefaultFileLockManager(); | |||
FilesystemStorage storage = new FilesystemStorage(location.toAbsolutePath(), lockManager); | |||
@@ -84,9 +106,9 @@ public class RepositoryScannerTest | |||
private static final String[] ARTIFACT_PATTERNS = | |||
new String[]{ "**/*.jar", "**/*.pom", "**/*.rar", "**/*.zip", "**/*.war", "**/*.tar.gz" }; | |||
private ManagedRepository createDefaultRepository() throws IOException { | |||
Path repoDir = | |||
Paths.get( System.getProperty( "basedir" ), "src/test/repositories/default-repository" ); | |||
private ManagedRepository createDefaultRepository() throws IOException, URISyntaxException | |||
{ | |||
Path repoDir = getRepoBaseDir().resolve("default-repository" ); | |||
assertTrue( "Default Test Repository should exist.", Files.exists(repoDir) && Files.isDirectory(repoDir) ); | |||
@@ -96,7 +118,7 @@ public class RepositoryScannerTest | |||
private ManagedRepository createSimpleRepository() | |||
throws IOException, ParseException | |||
{ | |||
Path srcDir = Paths.get( System.getProperty( "basedir" ), "src/test/repositories/simple-repository" ); | |||
Path srcDir = getRepoBaseDir().resolve("simple-repository" ); | |||
Path repoDir = Paths.get( System.getProperty( "basedir" ), "target/test-repos/simple-repository" ); | |||
@@ -122,7 +144,7 @@ public class RepositoryScannerTest | |||
} | |||
private ManagedRepository createLegacyRepository() throws IOException { | |||
Path repoDir = Paths.get( System.getProperty( "basedir" ), "src/test/repositories/legacy-repository" ); | |||
Path repoDir = getRepoBaseDir().resolve("legacy-repository" ); | |||
assertTrue( "Legacy Test Repository should exist.", Files.exists(repoDir) && Files.isDirectory(repoDir) ); | |||
@@ -260,6 +282,16 @@ public class RepositoryScannerTest | |||
assertMinimumHits( "Stats.totalFileCount", 17, stats.getTotalFileCount() ); | |||
assertMinimumHits( "Processed Count", 17, consumer.getProcessCount() ); | |||
assertEquals( "Processed Count (of invalid items):" + badconsumer.getPaths(), 6, badconsumer.getProcessCount() ); | |||
List<String> paths = new ArrayList<>( badconsumer.getPaths() ); | |||
paths.sort( Comparator.naturalOrder() ); | |||
List<String> expected = Arrays.asList( | |||
"CVS/Root", | |||
"invalid/invalid/1/invalid-1", | |||
"javax/sql/jdbc/2.0/maven-metadata-repository.xml", | |||
"javax/sql/jdbc/maven-metadata-repository.xml", | |||
"javax/sql/maven-metadata-repository.xml", | |||
"org/apache/maven/maven-parent/4/maven-parent-4-site_en.xml"); | |||
assertThat( paths, is( expected ) ); | |||
} | |||
@Test |
@@ -0,0 +1,41 @@ | |||
<?xml version="1.0" encoding="UTF-8" ?> | |||
<!-- | |||
~ Licensed to the Apache Software Foundation (ASF) under one | |||
~ or more contributor license agreements. See the NOTICE file | |||
~ distributed with this work for additional information | |||
~ regarding copyright ownership. The ASF licenses this file | |||
~ to you under the Apache License, Version 2.0 (the | |||
~ "License"); you may not use this file except in compliance | |||
~ with the License. You may obtain a copy of the License at | |||
~ | |||
~ http://www.apache.org/licenses/LICENSE-2.0 | |||
~ | |||
~ Unless required by applicable law or agreed to in writing, | |||
~ software distributed under the License is distributed on an | |||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |||
~ KIND, either express or implied. See the License for the | |||
~ specific language governing permissions and limitations | |||
~ under the License. | |||
--> | |||
<configuration> | |||
<Properties> | |||
</Properties> | |||
<appenders> | |||
<Console name="console" target="SYSTEM_OUT"> | |||
<PatternLayout pattern="%d{ISO8601_PERIOD} [%L] [%t] %-5level %logger{3} - %msg%n"/> | |||
</Console> | |||
<!-- | |||
<RandomAccessFile name="LogFile" fileName="target/test.log"> | |||
<PatternLayout pattern="%d{ISO8601_PERIOD} [%L] [%t] %-5level %logger{3} - %msg%n"/> | |||
</RandomAccessFile> | |||
--> | |||
</appenders> | |||
<loggers> | |||
<logger name="org.apache.archiva" level="info"/> | |||
<logger name="org.apache.archiva.repository.scanner" level="info"/> | |||
<root level="error" includeLocation="true"> | |||
<appender-ref ref="console"/> | |||
</root> | |||
</loggers> | |||
</configuration> |