1 package org.apache.archiva.maven.repository.metadata;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
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
21 import org.apache.archiva.common.utils.VersionComparator;
22 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
23 import org.apache.archiva.maven.repository.AbstractRepositoryLayerTestCase;
24 import org.apache.archiva.maven.repository.MavenManagedRepository;
25 import org.apache.archiva.maven.repository.metadata.storage.mock.MockConfiguration;
26 import org.apache.archiva.policies.CachedFailuresPolicy;
27 import org.apache.archiva.policies.ChecksumPolicy;
28 import org.apache.archiva.policies.ReleasesPolicy;
29 import org.apache.archiva.policies.SnapshotsPolicy;
30 import org.apache.archiva.repository.ManagedRepositoryContent;
31 import org.apache.archiva.repository.RemoteRepositoryContent;
32 import org.apache.archiva.repository.RepositoryContentProvider;
33 import org.apache.archiva.repository.content.ItemSelector;
34 import org.apache.archiva.repository.content.LayoutException;
35 import org.apache.archiva.repository.content.base.ArchivaItemSelector;
36 import org.apache.archiva.repository.metadata.RepositoryMetadataException;
37 import org.apache.archiva.repository.metadata.base.MetadataTools;
38 import org.apache.commons.io.FileUtils;
39 import org.apache.commons.lang3.StringUtils;
40 import org.junit.Test;
41 import org.springframework.test.context.ContextConfiguration;
42 import org.xml.sax.SAXException;
43 import org.xmlunit.builder.DiffBuilder;
44 import org.xmlunit.diff.Diff;
45 import org.xmlunit.diff.Difference;
47 import javax.inject.Inject;
48 import javax.inject.Named;
49 import javax.xml.parsers.ParserConfigurationException;
50 import java.io.IOException;
51 import java.net.URISyntaxException;
52 import java.nio.charset.Charset;
53 import java.nio.file.Files;
54 import java.nio.file.Path;
55 import java.nio.file.Paths;
56 import java.util.ArrayList;
57 import java.util.Collections;
58 import java.util.List;
61 import static org.junit.Assert.*;
66 @SuppressWarnings( "deprecation" )
67 @ContextConfiguration (
68 { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-metadata-tools-test.xml" } )
69 public class MetadataToolsTest
70 extends AbstractRepositoryLayerTestCase
73 @Named ( "metadataTools#test" )
74 private MetadataTools tools;
77 @Named ( "archivaConfiguration#mock" )
78 protected MockConfiguration config;
80 private Path getRepositoryPath(String repoName) {
83 return Paths.get( Thread.currentThread( ).getContextClassLoader( ).getResource( "repositories/" + repoName ).toURI( ) );
85 catch ( URISyntaxException e )
87 throw new RuntimeException( "Could not resolve repository path " + e.getMessage( ), e );
92 public void testGatherSnapshotVersionsA()
95 removeProxyConnector( "test-repo", "apache-snapshots" );
96 removeProxyConnector( "test-repo", "internal-snapshots" );
97 removeProxyConnector( "test-repo", "snapshots.codehaus.org" );
99 assertSnapshotVersions( "snap_shots_a", "1.0-alpha-11-SNAPSHOT",
100 new String[]{ "1.0-alpha-11-SNAPSHOT", "1.0-alpha-11-20070221.194724-2",
101 "1.0-alpha-11-20070302.212723-3", "1.0-alpha-11-20070303.152828-4",
102 "1.0-alpha-11-20070305.215149-5", "1.0-alpha-11-20070307.170909-6",
103 "1.0-alpha-11-20070314.211405-9", "1.0-alpha-11-20070316.175232-11" } );
107 public void testGatherSnapshotVersionsAWithProxies()
110 // These proxied repositories do not need to exist for the purposes of this unit test,
111 // just the repository ids are important.
112 createProxyConnector( "test-repo", "apache-snapshots" );
113 createProxyConnector( "test-repo", "internal-snapshots" );
114 createProxyConnector( "test-repo", "snapshots.codehaus.org" );
116 assertSnapshotVersions( "snap_shots_a", "1.0-alpha-11-SNAPSHOT",
117 new String[]{ "1.0-alpha-11-SNAPSHOT", "1.0-alpha-11-20070221.194724-2",
118 "1.0-alpha-11-20070302.212723-3", "1.0-alpha-11-20070303.152828-4",
119 "1.0-alpha-11-20070305.215149-5", "1.0-alpha-11-20070307.170909-6",
120 "1.0-alpha-11-20070314.211405-9", "1.0-alpha-11-20070315.033030-10"
121 /* Arrives in via snapshots.codehaus.org proxy */,
122 "1.0-alpha-11-20070316.175232-11" } );
126 public void testGetRepositorySpecificName()
129 RemoteRepositoryContent repoJavaNet =
130 createRemoteRepositoryContent( "maven2-repository.dev.java.net", "Java.net Repository for Maven 2",
131 "http://download.java.net/maven/2/", "default" );
132 RemoteRepositoryContent repoCentral =
133 createRemoteRepositoryContent( "central", "Central Global Repository", "http://repo1.maven.org/maven2/",
136 String convertedName =
137 tools.getRepositorySpecificName( repoJavaNet, "commons-lang/commons-lang/maven-metadata.xml" );
138 assertMetadataPath( "commons-lang/commons-lang/maven-metadata-maven2-repository.dev.java.net.xml",
141 convertedName = tools.getRepositorySpecificName( repoCentral, "commons-lang/commons-lang/maven-metadata.xml" );
142 assertMetadataPath( "commons-lang/commons-lang/maven-metadata-central.xml", convertedName );
145 // TODO: replace with group tests
146 // public void testUpdateProjectBadArtifact()
151 // assertUpdatedProjectMetadata( "bad_artifact", null );
152 // fail( "Should have thrown an IOException on a bad artifact." );
154 // catch ( IOException e )
161 public void testUpdateProjectNonExistingVersion()
164 ManagedRepositoryContent testRepo = createTestRepoContent();
165 ItemSelector reference = ArchivaItemSelector.builder()
166 .withNamespace( "org.apache.archiva.metadata.tests" )
167 .withProjectId( "missing_artifact" ).build();
169 prepProjectTestRepo( testRepo, reference );
171 // check metadata prior to update -- should contain the non-existing artifact version
172 assertProjectMetadata( testRepo, reference, "missing_artifact",
173 new String[]{ "1.0-SNAPSHOT", "1.1-SNAPSHOT", "1.2-SNAPSHOT" }, "1.2-SNAPSHOT", null );
175 tools.updateProjectMetadata( testRepo, reference );
177 // metadata should not contain the non-existing artifact version -- 1.1-SNAPSHOT
178 assertProjectMetadata( testRepo, reference, "missing_artifact", new String[]{ "1.0-SNAPSHOT", "1.2-SNAPSHOT" },
179 "1.2-SNAPSHOT", null );
183 public void testUpdateProjectMissingMultipleVersions()
186 assertUpdatedProjectMetadata( "missing_metadata_b",
187 new String[]{ "1.0", "1.0.1", "2.0", "2.0.1", "2.0-20070821-dev" },
188 "2.0-20070821-dev", "2.0-20070821-dev" );
192 public void testUpdateProjectMissingMultipleVersionsWithProxies()
195 // Attach the (bogus) proxies to the managed repo.
196 // These proxied repositories do not need to exist for the purposes of this unit test,
197 // just the repository ids are important.
198 createProxyConnector( "test-repo", "central" );
199 createProxyConnector( "test-repo", "java.net" );
201 assertUpdatedProjectMetadata( "proxied_multi",
202 new String[]{ "1.0-spec" /* in java.net */, "1.0" /* in managed, and central */,
203 "1.0.1" /* in central */, "1.1" /* in managed */, "2.0-proposal-beta"
204 /* in java.net */, "2.0-spec" /* in java.net */, "2.0"
205 /* in central, and java.net */, "2.0.1" /* in java.net */, "2.1"
206 /* in managed */, "3.0" /* in central */, "3.1" /* in central */ }, "3.1",
211 public void testUpdateProjectSimpleYetIncomplete()
214 assertUpdatedProjectMetadata( "incomplete_metadata_a", new String[]{ "1.0" }, "1.0", "1.0" );
218 public void testUpdateProjectSimpleYetMissing()
221 assertUpdatedProjectMetadata( "missing_metadata_a", new String[]{ "1.0" }, "1.0", "1.0" );
225 public void testUpdateVersionSimple10()
228 assertUpdatedReleaseVersionMetadata( "missing_metadata_a", "1.0" );
232 public void testUpdateVersionSimple20()
235 assertUpdatedReleaseVersionMetadata( "missing_metadata_b", "2.0" );
239 public void testUpdateVersionSimple20NotSnapshot()
242 assertUpdatedReleaseVersionMetadata( "missing_metadata_b", "2.0-20070821-dev" );
246 public void testUpdateVersionSnapshotA()
249 assertUpdatedSnapshotVersionMetadata( "snap_shots_a", "1.0-alpha-11-SNAPSHOT", "20070316", "175232", "11" );
253 public void testToPathFromVersionReference()
255 ItemSelector selector = ArchivaItemSelector.builder( )
256 .withNamespace( "com.foo" )
257 .withArtifactId( "foo-tool" )
258 .withProjectId( "foo-tool" )
259 .withVersion( "1.0" ).build( );
261 assertEquals( "com/foo/foo-tool/1.0/maven-metadata.xml", tools.toPath( selector ) );
265 public void testToPathFromProjectReference()
267 ItemSelector selector = ArchivaItemSelector.builder( )
268 .withNamespace( "com.foo" )
269 .withProjectId( "foo-tool" )
270 .withArtifactId( "foo-tool" ).build( );
272 assertEquals( "com/foo/foo-tool/maven-metadata.xml", tools.toPath( selector ) );
276 public void testToProjectReferenceFooTools()
277 throws RepositoryMetadataException
279 assertProjectReference( "com.foo", "foo-tools", "com/foo/foo-tools/maven-metadata.xml" );
283 public void testToProjectReferenceAReallyLongPath()
284 throws RepositoryMetadataException
286 String groupId = "net.i.have.a.really.long.path.just.for.the.hell.of.it";
287 String artifactId = "a";
288 String path = "net/i/have/a/really/long/path/just/for/the/hell/of/it/a/maven-metadata.xml";
290 assertProjectReference( groupId, artifactId, path );
294 public void testToProjectReferenceCommonsLang()
295 throws RepositoryMetadataException
297 String groupId = "commons-lang";
298 String artifactId = "commons-lang";
299 String path = "commons-lang/commons-lang/maven-metadata.xml";
301 assertProjectReference( groupId, artifactId, path );
304 private void assertProjectReference( String groupId, String artifactId, String path )
305 throws RepositoryMetadataException
307 ItemSelector reference = tools.toProjectSelector( path );
309 assertNotNull( "Reference should not be null.", reference );
310 assertEquals( "ProjectReference.groupId", groupId, reference.getNamespace() );
311 assertEquals( "ProjectReference.artifactId", artifactId, reference.getArtifactId() );
315 public void testToVersionedReferenceFooTool()
316 throws RepositoryMetadataException
318 String groupId = "com.foo";
319 String artifactId = "foo-tool";
320 String version = "1.0";
321 String path = "com/foo/foo-tool/1.0/maven-metadata.xml";
323 assertVersionedReference( groupId, artifactId, version, path );
327 public void testToVersionedReferenceAReallyLongPath()
328 throws RepositoryMetadataException
330 String groupId = "net.i.have.a.really.long.path.just.for.the.hell.of.it";
331 String artifactId = "a";
332 String version = "1.1-alpha-1";
333 String path = "net/i/have/a/really/long/path/just/for/the/hell/of/it/a/1.1-alpha-1/maven-metadata.xml";
335 assertVersionedReference( groupId, artifactId, version, path );
339 public void testToVersionedReferenceCommonsLang()
340 throws RepositoryMetadataException
342 String groupId = "commons-lang";
343 String artifactId = "commons-lang";
344 String version = "2.1";
345 String path = "commons-lang/commons-lang/2.1/maven-metadata.xml";
347 assertVersionedReference( groupId, artifactId, version, path );
351 public void testToVersionedReferenceSnapshot()
352 throws RepositoryMetadataException
354 String groupId = "com.foo";
355 String artifactId = "foo-connector";
356 String version = "2.1-SNAPSHOT";
357 String path = "com/foo/foo-connector/2.1-SNAPSHOT/maven-metadata.xml";
359 assertVersionedReference( groupId, artifactId, version, path );
362 private void assertVersionedReference( String groupId, String artifactId, String version, String path )
363 throws RepositoryMetadataException
365 ItemSelector reference = tools.toVersionedSelector( path );
366 assertNotNull( "Reference should not be null.", reference );
368 assertEquals( "VersionedReference.groupId", groupId, reference.getNamespace() );
369 assertEquals( "VersionedReference.artifactId", artifactId, reference.getArtifactId() );
370 assertEquals( "VersionedReference.version", version, reference.getVersion() );
373 private void assertSnapshotVersions( String artifactId, String version, String[] expectedVersions )
376 Path repoRootDir = getRepositoryPath( "metadata-repository" );
378 ItemSelector reference = ArchivaItemSelector.builder( )
379 .withNamespace( "org.apache.archiva.metadata.tests" )
380 .withArtifactId( artifactId )
381 .withProjectId( artifactId )
382 .withVersion( version ).build( );
384 MavenManagedRepository repo =
385 createRepository( "test-repo", "Test Repository: " + name.getMethodName(), repoRootDir );
387 RepositoryContentProvider provider = applicationContext.getBean( "repositoryContentProvider#maven", RepositoryContentProvider.class );
389 ManagedRepositoryContent repoContent =
390 provider.createManagedContent( repo );
392 Set<String> testedVersionSet = tools.gatherSnapshotVersions( repoContent, reference );
394 // Sort the list (for asserts)
395 List<String> testedVersions = new ArrayList<>();
396 testedVersions.addAll( testedVersionSet );
397 Collections.sort( testedVersions, new VersionComparator() );
399 // Test the expected array of versions, to the actual tested versions
400 assertEquals( "Assert Snapshot Versions: length/size", expectedVersions.length, testedVersions.size() );
402 for ( int i = 0; i < expectedVersions.length; i++ )
404 String actualVersion = testedVersions.get( i );
405 assertEquals( "Snapshot Versions[" + i + "]", expectedVersions[i], actualVersion );
409 private void assertProjectMetadata( String expectedMetadata, ManagedRepositoryContent repository,
410 ItemSelector reference )
411 throws LayoutException, IOException, SAXException, ParserConfigurationException
413 Path metadataFile = repository.getRepository().getRoot().getFilePath().resolve(tools.toPath( reference ) );
414 String actualMetadata = org.apache.archiva.common.utils.FileUtils.readFileToString( metadataFile, Charset.defaultCharset() );
416 Diff detailedDiff = DiffBuilder.compare( expectedMetadata ).withTest( actualMetadata ).checkForSimilar().build();
417 if ( detailedDiff.hasDifferences() )
419 for ( Difference diff : detailedDiff.getDifferences() ) {
420 System.out.println( diff );
422 // If it isn't similar, dump the difference.
423 assertEquals( expectedMetadata, actualMetadata );
427 private void assertMetadata( String expectedMetadata, ManagedRepositoryContent repository,
428 ItemSelector reference )
429 throws LayoutException, IOException, SAXException, ParserConfigurationException
431 Path metadataFile = repository.getRepository().getRoot().getFilePath().resolve( tools.toPath( reference ) );
432 String actualMetadata = org.apache.archiva.common.utils.FileUtils.readFileToString( metadataFile, Charset.defaultCharset() );
434 Diff detailedDiff = DiffBuilder.compare( expectedMetadata ).withTest( actualMetadata ).checkForSimilar().build();
435 if ( detailedDiff.hasDifferences() )
437 for ( Difference diff : detailedDiff.getDifferences() ) {
438 System.out.println( diff );
440 // If it isn't similar, dump the difference.
441 assertEquals( expectedMetadata, actualMetadata );
445 private void assertMetadataPath( String expected, String actual )
447 assertEquals( "Repository Specific Metadata Path", expected, actual );
450 private void assertUpdatedProjectMetadata( String artifactId, String[] expectedVersions, String latestVersion,
451 String releaseVersion )
454 ManagedRepositoryContent testRepo = createTestRepoContent();
455 ItemSelector reference = ArchivaItemSelector.builder( )
456 .withNamespace( "org.apache.archiva.metadata.tests" )
457 .withProjectId( artifactId ).build();
459 prepProjectTestRepo( testRepo, reference );
461 tools.updateProjectMetadata( testRepo, reference );
463 StringBuilder buf = new StringBuilder();
464 buf.append( "<metadata>\n" );
465 buf.append( " <groupId>" ).append( reference.getNamespace() ).append( "</groupId>\n" );
466 buf.append( " <artifactId>" ).append( reference.getProjectId() ).append( "</artifactId>\n" );
467 // buf.append( " <version>1.0</version>\n" );
469 if ( expectedVersions != null )
471 buf.append( " <versioning>\n" );
472 if ( latestVersion != null )
474 buf.append( " <latest>" ).append( latestVersion ).append( "</latest>\n" );
476 if ( releaseVersion != null )
478 buf.append( " <release>" ).append( releaseVersion ).append( "</release>\n" );
481 buf.append( " <versions>\n" );
482 for ( int i = 0; i < expectedVersions.length; i++ )
484 buf.append( " <version>" ).append( expectedVersions[i] ).append( "</version>\n" );
486 buf.append( " </versions>\n" );
487 buf.append( " </versioning>\n" );
489 buf.append( "</metadata>" );
491 assertProjectMetadata( buf.toString(), testRepo, reference );
494 private void assertProjectMetadata( ManagedRepositoryContent testRepo, ItemSelector reference,
495 String artifactId, String[] expectedVersions, String latestVersion,
496 String releaseVersion )
499 StringBuilder buf = new StringBuilder();
500 buf.append( "<metadata>\n" );
501 buf.append( " <groupId>" ).append( reference.getNamespace() ).append( "</groupId>\n" );
502 buf.append( " <artifactId>" ).append( reference.getProjectId() ).append( "</artifactId>\n" );
504 if ( expectedVersions != null )
506 buf.append( " <versioning>\n" );
507 if ( latestVersion != null )
509 buf.append( " <latest>" ).append( latestVersion ).append( "</latest>\n" );
511 if ( releaseVersion != null )
513 buf.append( " <release>" ).append( releaseVersion ).append( "</release>\n" );
516 buf.append( " <versions>\n" );
517 for ( int i = 0; i < expectedVersions.length; i++ )
519 buf.append( " <version>" ).append( expectedVersions[i] ).append( "</version>\n" );
521 buf.append( " </versions>\n" );
522 buf.append( " </versioning>\n" );
524 buf.append( "</metadata>" );
526 assertProjectMetadata( buf.toString(), testRepo, reference );
530 private void assertUpdatedReleaseVersionMetadata( String artifactId, String version )
533 ManagedRepositoryContent testRepo = createTestRepoContent();
535 ItemSelector selector = ArchivaItemSelector.builder()
536 .withNamespace( "org.apache.archiva.metadata.tests" )
537 .withProjectId( artifactId )
538 .withArtifactId( artifactId )
539 .withVersion( version ).build();
541 prepTestRepo( testRepo, selector );
543 tools.updateVersionMetadata( testRepo, selector );
545 StringBuilder buf = new StringBuilder();
546 buf.append( "<metadata>\n" );
547 buf.append( " <groupId>" ).append( selector.getNamespace() ).append( "</groupId>\n" );
548 buf.append( " <artifactId>" ).append( selector.getArtifactId() ).append( "</artifactId>\n" );
549 buf.append( " <version>" ).append( selector.getVersion() ).append( "</version>\n" );
550 buf.append( "</metadata>" );
552 assertMetadata( buf.toString(), testRepo, selector );
555 private void assertUpdatedSnapshotVersionMetadata( String artifactId, String version, String expectedDate,
556 String expectedTime, String expectedBuildNumber )
559 ManagedRepositoryContent testRepo = createTestRepoContent();
560 ItemSelector reference = ArchivaItemSelector.builder()
561 .withNamespace( "org.apache.archiva.metadata.tests" )
562 .withArtifactId( artifactId )
563 .withProjectId( artifactId )
564 .withVersion( version ).build();
566 prepTestRepo( testRepo, reference );
568 tools.updateVersionMetadata( testRepo, reference );
570 StringBuilder buf = new StringBuilder();
571 buf.append( "<metadata>\n" );
572 buf.append( " <groupId>" ).append( reference.getNamespace() ).append( "</groupId>\n" );
573 buf.append( " <artifactId>" ).append( reference.getArtifactId() ).append( "</artifactId>\n" );
574 buf.append( " <version>" ).append( reference.getVersion() ).append( "</version>\n" );
575 buf.append( " <versioning>\n" );
576 buf.append( " <snapshot>\n" );
577 buf.append( " <buildNumber>" ).append( expectedBuildNumber ).append( "</buildNumber>\n" );
578 buf.append( " <timestamp>" );
579 buf.append( expectedDate ).append( "." ).append( expectedTime );
580 buf.append( "</timestamp>\n" );
581 buf.append( " </snapshot>\n" );
582 buf.append( " <lastUpdated>" ).append( expectedDate ).append( expectedTime ).append( "</lastUpdated>\n" );
583 buf.append( " </versioning>\n" );
584 buf.append( "</metadata>" );
586 assertMetadata( buf.toString(), testRepo, reference );
589 private void removeProxyConnector( String sourceRepoId, String targetRepoId )
591 ProxyConnectorConfiguration toRemove = null;
592 for ( ProxyConnectorConfiguration pcc : config.getConfiguration().getProxyConnectors() )
594 if ( pcc.getTargetRepoId().equals( targetRepoId ) && pcc.getSourceRepoId().equals( sourceRepoId ) )
599 if ( toRemove != null )
601 config.getConfiguration().removeProxyConnector( toRemove );
602 String prefix = "proxyConnectors.proxyConnector(" + "1" + ")"; // XXX
603 config.triggerChange( prefix + ".sourceRepoId", toRemove.getSourceRepoId() );
604 config.triggerChange( prefix + ".targetRepoId", toRemove.getTargetRepoId() );
605 config.triggerChange( prefix + ".proxyId", toRemove.getProxyId() );
606 config.triggerChange( prefix + ".policies.releases", toRemove.getPolicy( "releases", "" ) );
607 config.triggerChange( prefix + ".policies.checksum", toRemove.getPolicy( "checksum", "" ) );
608 config.triggerChange( prefix + ".policies.snapshots", toRemove.getPolicy( "snapshots", "" ) );
609 config.triggerChange( prefix + ".policies.cache-failures", toRemove.getPolicy( "cache-failures", "" ) );
613 private void createProxyConnector( String sourceRepoId, String targetRepoId )
615 ProxyConnectorConfiguration connectorConfig = new ProxyConnectorConfiguration();
616 connectorConfig.setSourceRepoId( sourceRepoId );
617 connectorConfig.setTargetRepoId( targetRepoId );
618 connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_CHECKSUM, ChecksumPolicy.IGNORE.getId() );
619 connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_RELEASES, ReleasesPolicy.ALWAYS.getId() );
620 connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_SNAPSHOTS, SnapshotsPolicy.ALWAYS.getId() );
621 connectorConfig.addPolicy( ProxyConnectorConfiguration.POLICY_CACHE_FAILURES, CachedFailuresPolicy.NO.getId() );
623 int count = config.getConfiguration().getProxyConnectors().size();
624 config.getConfiguration().addProxyConnector( connectorConfig );
626 // Proper Triggering ...
627 String prefix = "proxyConnectors.proxyConnector(" + count + ")";
628 config.triggerChange( prefix + ".sourceRepoId", connectorConfig.getSourceRepoId() );
629 config.triggerChange( prefix + ".targetRepoId", connectorConfig.getTargetRepoId() );
630 config.triggerChange( prefix + ".proxyId", connectorConfig.getProxyId() );
631 config.triggerChange( prefix + ".policies.releases", connectorConfig.getPolicy( "releases", "" ) );
632 config.triggerChange( prefix + ".policies.checksum", connectorConfig.getPolicy( "checksum", "" ) );
633 config.triggerChange( prefix + ".policies.snapshots", connectorConfig.getPolicy( "snapshots", "" ) );
634 config.triggerChange( prefix + ".policies.cache-failures", connectorConfig.getPolicy( "cache-failures", "" ) );
637 private ManagedRepositoryContent createTestRepoContent()
640 Path repoRoot = Paths.get( "target/metadata-tests/" + name.getMethodName() );
641 if ( Files.exists(repoRoot) )
643 org.apache.archiva.common.utils.FileUtils.deleteDirectory( repoRoot );
646 Files.createDirectories(repoRoot);
648 MavenManagedRepository repoConfig =
649 createRepository( "test-repo", "Test Repository: " + name.getMethodName(), repoRoot );
651 RepositoryContentProvider provider = applicationContext.getBean( "repositoryContentProvider#maven", RepositoryContentProvider.class );
653 ManagedRepositoryContent repoContent =
654 provider.createManagedContent( repoConfig );
658 private void prepProjectTestRepo( ManagedRepositoryContent repo, ItemSelector reference)
661 String groupDir = StringUtils.replaceChars( reference.getNamespace(), '.', '/' );
662 String path = groupDir + "/" + reference.getArtifactId();
664 Path srcRepoDir = getRepositoryPath( "metadata-repository" );
665 Path srcDir = srcRepoDir.resolve( path );
666 Path destDir = repo.getRepository().getRoot().getFilePath().resolve( path );
668 assertTrue( "Source Dir exists: " + srcDir, Files.exists(srcDir) );
669 Files.createDirectories(destDir);
671 FileUtils.copyDirectory( srcDir.toFile(), destDir.toFile() );
674 private void prepTestRepo( ManagedRepositoryContent repo, ItemSelector reference )
677 String groupDir = StringUtils.replaceChars( reference.getNamespace(), '.', '/' );
678 String path = groupDir + "/" + reference.getArtifactId();
680 Path srcRepoDir = getRepositoryPath( "metadata-repository" );
681 Path srcDir = srcRepoDir.resolve( path );
682 Path destDir = repo.getRepository().getRoot().getFilePath().resolve( path );
684 assertTrue( "Source Dir exists: " + srcDir, Files.exists(srcDir) );
685 Files.createDirectories(destDir);
687 FileUtils.copyDirectory( srcDir.toFile(), destDir.toFile() );