mirror of https://github.com/apache/archiva.git
M2.x repo support
logs rewritted for performance add test for more complex archiva configuration remove previous check in RepositoryModelResolver (misunderstanding of class role) git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1379598 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
de6d5108af
commit
fcc715e89f
|
@ -614,7 +614,7 @@ public class Maven2RepositoryStorage
|
||||||
}
|
}
|
||||||
catch ( IOException e )
|
catch ( IOException e )
|
||||||
{
|
{
|
||||||
log.error( "Unable to checksum file " + file + ": " + e.getMessage() );
|
log.error( "Unable to checksum file {}: {},MD5", file, e.getMessage() );
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -622,7 +622,7 @@ public class Maven2RepositoryStorage
|
||||||
}
|
}
|
||||||
catch ( IOException e )
|
catch ( IOException e )
|
||||||
{
|
{
|
||||||
log.error( "Unable to checksum file " + file + ": " + e.getMessage() );
|
log.error( "Unable to checksum file {}: {},SHA1", file, e.getMessage() );
|
||||||
}
|
}
|
||||||
metadata.setSize( file.length() );
|
metadata.setSize( file.length() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ public class MavenArtifactFacet
|
||||||
|
|
||||||
public Map<String, String> toProperties()
|
public Map<String, String> toProperties()
|
||||||
{
|
{
|
||||||
HashMap<String, String> properties = new HashMap<String, String>();
|
Map<String, String> properties = new HashMap<String, String>();
|
||||||
properties.put( "type", type );
|
properties.put( "type", type );
|
||||||
if ( classifier != null )
|
if ( classifier != null )
|
||||||
{
|
{
|
||||||
|
|
|
@ -54,7 +54,6 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException;
|
|
||||||
|
|
||||||
public class RepositoryModelResolver
|
public class RepositoryModelResolver
|
||||||
implements ModelResolver
|
implements ModelResolver
|
||||||
|
@ -112,20 +111,9 @@ public class RepositoryModelResolver
|
||||||
|
|
||||||
if ( !model.exists() )
|
if ( !model.exists() )
|
||||||
{
|
{
|
||||||
if ( VersionUtil.isSnapshot( version ) ) // skygo trying to improve speed by honoring managed configuration MRM-1658
|
/**
|
||||||
{
|
*
|
||||||
if ( managedRepository.isReleases() && !managedRepository.isSnapshots() )
|
*/
|
||||||
{
|
|
||||||
throw new UnresolvableModelException("lookforsnaponreleaseonly", groupId, artifactId, version );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( !managedRepository.isReleases() && managedRepository.isSnapshots() )
|
|
||||||
{
|
|
||||||
throw new UnresolvableModelException("lookforsreleaseonsneponly", groupId, artifactId, version );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// is a SNAPSHOT ? so we can try to find locally before asking remote repositories.
|
// is a SNAPSHOT ? so we can try to find locally before asking remote repositories.
|
||||||
if ( StringUtils.contains( version, VersionUtil.SNAPSHOT ) )
|
if ( StringUtils.contains( version, VersionUtil.SNAPSHOT ) )
|
||||||
{
|
{
|
||||||
|
@ -145,21 +133,20 @@ public class RepositoryModelResolver
|
||||||
if ( success && model.exists() )
|
if ( success && model.exists() )
|
||||||
{
|
{
|
||||||
log.info(
|
log.info(
|
||||||
"Model '" + model.getAbsolutePath() + "' successfully retrieved from remote repository '"
|
"Model '{}' successfully retrieved from remote repository '{}'",
|
||||||
+ remoteRepository.getId() + "'" );
|
model.getAbsolutePath(), remoteRepository.getId() );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( ResourceDoesNotExistException e )
|
catch ( ResourceDoesNotExistException e )
|
||||||
{
|
{
|
||||||
log.info( "An exception was caught while attempting to retrieve model '" + model.getAbsolutePath()
|
log.info( "An exception was caught while attempting to retrieve model '{}' from remote repository '{}'.Reason:{}",
|
||||||
+ "' from remote repository '" + remoteRepository.getId() + "'.Reason:"
|
new Object[]{ model.getAbsolutePath(), remoteRepository.getId(), e.getMessage() } );
|
||||||
+ e.getMessage() );
|
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( Exception e )
|
||||||
{
|
{
|
||||||
log.warn( "An exception was caught while attempting to retrieve model '" + model.getAbsolutePath()
|
log.warn( "An exception was caught while attempting to retrieve model '{}' from remote repository '{}'.Reason:{}",
|
||||||
+ "' from remote repository '" + remoteRepository.getId() + "'.", e.getMessage() );
|
new Object[]{ model.getAbsolutePath(), remoteRepository.getId(), e.getMessage() } );
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -290,11 +277,11 @@ public class RepositoryModelResolver
|
||||||
|
|
||||||
artifactPath = pathTranslator.toPath( groupId, artifactId, version, filename );
|
artifactPath = pathTranslator.toPath( groupId, artifactId, version, filename );
|
||||||
|
|
||||||
log.debug( "New artifactPath : " + artifactPath );
|
log.debug( "New artifactPath :{}", artifactPath );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info( "Retrieving " + artifactPath + " from " + remoteRepository.getName() );
|
log.info( "Retrieving {} from {}", artifactPath, remoteRepository.getName() );
|
||||||
|
|
||||||
wagon.get( artifactPath, tmpResource );
|
wagon.get( artifactPath, tmpResource );
|
||||||
|
|
||||||
|
@ -414,12 +401,12 @@ public class RepositoryModelResolver
|
||||||
}
|
}
|
||||||
catch ( ConnectionException e )
|
catch ( ConnectionException e )
|
||||||
{
|
{
|
||||||
log.error( "Could not connect to " + remoteRepository.getName() + ": " + e.getMessage() );
|
log.error( "Could not connect to {}:{} ",remoteRepository.getName(), e.getMessage() );
|
||||||
connected = false;
|
connected = false;
|
||||||
}
|
}
|
||||||
catch ( AuthenticationException e )
|
catch ( AuthenticationException e )
|
||||||
{
|
{
|
||||||
log.error( "Could not connect to " + remoteRepository.getName() + ": " + e.getMessage() );
|
log.error( "Could not connect to {}:{} ",remoteRepository.getName(), e.getMessage() );
|
||||||
connected = false;
|
connected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -432,7 +419,7 @@ public class RepositoryModelResolver
|
||||||
{
|
{
|
||||||
File destFile = new File( tmpDirectory, resource.getName() + ext );
|
File destFile = new File( tmpDirectory, resource.getName() + ext );
|
||||||
|
|
||||||
log.info( "Retrieving " + remotePath + " from " + remoteRepository.getName() );
|
log.info( "Retrieving {} from {}", remotePath, remoteRepository.getName() );
|
||||||
|
|
||||||
wagon.get( remotePath, destFile );
|
wagon.get( remotePath, destFile );
|
||||||
|
|
||||||
|
@ -477,8 +464,8 @@ public class RepositoryModelResolver
|
||||||
{
|
{
|
||||||
if ( newLocation.exists() )
|
if ( newLocation.exists() )
|
||||||
{
|
{
|
||||||
log.error( "Tried to copy file " + fileToMove.getName() + " to " + newLocation.getAbsolutePath()
|
log.error( "Tried to copy file {} to {} but file with this name already exists.",
|
||||||
+ " but file with this name already exists." );
|
fileToMove.getName(), newLocation.getAbsolutePath() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,510 @@
|
||||||
|
package org.apache.archiva.metadata.repository.storage.maven2;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import org.apache.archiva.admin.model.beans.RepositoryGroup;
|
||||||
|
import org.apache.archiva.common.utils.FileUtil;
|
||||||
|
import org.apache.archiva.configuration.ArchivaConfiguration;
|
||||||
|
import org.apache.archiva.configuration.Configuration;
|
||||||
|
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
|
||||||
|
import org.apache.archiva.configuration.ProxyConnectorConfiguration;
|
||||||
|
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
|
||||||
|
import org.apache.archiva.configuration.RepositoryGroupConfiguration;
|
||||||
|
import org.apache.archiva.metadata.model.ArtifactMetadata;
|
||||||
|
import org.apache.archiva.metadata.model.Dependency;
|
||||||
|
import org.apache.archiva.metadata.model.License;
|
||||||
|
import org.apache.archiva.metadata.model.MailingList;
|
||||||
|
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
|
||||||
|
import org.apache.archiva.metadata.repository.filter.AllFilter;
|
||||||
|
import org.apache.archiva.metadata.repository.filter.Filter;
|
||||||
|
import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException;
|
||||||
|
import org.apache.archiva.proxy.common.WagonFactory;
|
||||||
|
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.maven.wagon.Wagon;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
|
||||||
|
@RunWith( ArchivaSpringJUnit4ClassRunner.class )
|
||||||
|
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
|
||||||
|
public class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest
|
||||||
|
extends TestCase
|
||||||
|
{
|
||||||
|
private static final Filter<String> ALL = new AllFilter<String>();
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@Named( value = "repositoryStorage#maven2" )
|
||||||
|
private Maven2RepositoryStorage storage;
|
||||||
|
|
||||||
|
private static final String TEST_REPO_ID = "test";
|
||||||
|
|
||||||
|
private static final String TEST_SNAP_REPO_ID = "tests";
|
||||||
|
|
||||||
|
private static final String TEST_REPO_GROUP_ID = "testrg";
|
||||||
|
|
||||||
|
private static final String TEST_REMOTE_REPO_ID = "central";
|
||||||
|
|
||||||
|
private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/";
|
||||||
|
|
||||||
|
private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/";
|
||||||
|
|
||||||
|
private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/";
|
||||||
|
|
||||||
|
private static final String TEST_SCM_CONN_BASE = "scm:svn:http://svn.example.com/repos/";
|
||||||
|
|
||||||
|
private static final String TEST_SCM_DEV_CONN_BASE = "scm:svn:https://svn.example.com/repos/";
|
||||||
|
|
||||||
|
private static final String TEST_SCM_URL_BASE = "http://svn.example.com/repos/";
|
||||||
|
|
||||||
|
private static final String EMPTY_MD5 = "d41d8cd98f00b204e9800998ecf8427e";
|
||||||
|
|
||||||
|
private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ArchivaConfiguration configuration;
|
||||||
|
|
||||||
|
private WagonFactory wagonFactory;
|
||||||
|
|
||||||
|
ManagedRepositoryConfiguration testRepo;
|
||||||
|
|
||||||
|
ManagedRepositoryConfiguration testRepoS;
|
||||||
|
|
||||||
|
Configuration c;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
@Override
|
||||||
|
public void setUp()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
super.setUp();
|
||||||
|
|
||||||
|
c = new Configuration();
|
||||||
|
|
||||||
|
testRepo = new ManagedRepositoryConfiguration();
|
||||||
|
testRepo.setId( TEST_REPO_ID );
|
||||||
|
testRepo.setLocation( new File( "target/test-repository" ).getAbsolutePath() );
|
||||||
|
testRepo.setReleases( true );
|
||||||
|
testRepo.setSnapshots( false );
|
||||||
|
c.addManagedRepository( testRepo );
|
||||||
|
|
||||||
|
testRepoS = new ManagedRepositoryConfiguration();
|
||||||
|
testRepoS.setId( TEST_SNAP_REPO_ID );
|
||||||
|
testRepoS.setLocation( new File( "target/test-repositorys" ).getAbsolutePath() );
|
||||||
|
testRepoS.setReleases( false );
|
||||||
|
testRepoS.setSnapshots( true );
|
||||||
|
c.addManagedRepository( testRepoS );
|
||||||
|
|
||||||
|
RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
|
||||||
|
testRemoteRepo.setId( TEST_REMOTE_REPO_ID );
|
||||||
|
testRemoteRepo.setLayout( "default" );
|
||||||
|
testRemoteRepo.setName( "Central Repository" );
|
||||||
|
testRemoteRepo.setUrl( "http://central.repo.com/maven2" );
|
||||||
|
testRemoteRepo.setTimeout( 10 );
|
||||||
|
c.addRemoteRepository( testRemoteRepo );
|
||||||
|
|
||||||
|
ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
|
||||||
|
proxyConnector.setSourceRepoId( TEST_REPO_ID );
|
||||||
|
proxyConnector.setTargetRepoId( TEST_REMOTE_REPO_ID );
|
||||||
|
proxyConnector.setDisabled( false );
|
||||||
|
c.addProxyConnector( proxyConnector );
|
||||||
|
|
||||||
|
ProxyConnectorConfiguration proxyConnectors = new ProxyConnectorConfiguration();
|
||||||
|
proxyConnectors.setSourceRepoId( TEST_SNAP_REPO_ID );
|
||||||
|
proxyConnectors.setTargetRepoId( TEST_REMOTE_REPO_ID );
|
||||||
|
proxyConnectors.setDisabled( false );
|
||||||
|
c.addProxyConnector( proxyConnectors );
|
||||||
|
|
||||||
|
List<String> repos = new ArrayList<String>();
|
||||||
|
repos.add( TEST_REPO_ID );
|
||||||
|
repos.add( TEST_SNAP_REPO_ID );
|
||||||
|
|
||||||
|
RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration( );
|
||||||
|
repoGroup.setId( TEST_REPO_GROUP_ID );
|
||||||
|
repoGroup.setRepositories( repos );
|
||||||
|
c.addRepositoryGroup( repoGroup );
|
||||||
|
|
||||||
|
configuration.save( c );
|
||||||
|
|
||||||
|
assertFalse ( c.getManagedRepositories().get( 0 ).isSnapshots() );
|
||||||
|
assertTrue ( c.getManagedRepositories().get( 0 ).isReleases() );
|
||||||
|
|
||||||
|
assertTrue ( c.getManagedRepositories().get( 1 ).isSnapshots() );
|
||||||
|
assertFalse ( c.getManagedRepositories().get( 1 ).isReleases() );
|
||||||
|
|
||||||
|
wagonFactory = mock( WagonFactory.class );
|
||||||
|
|
||||||
|
storage.setWagonFactory( wagonFactory );
|
||||||
|
|
||||||
|
Wagon wagon = new MockWagon();
|
||||||
|
when( wagonFactory.getWagon( "wagon#http" ) ).thenReturn( wagon );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tests for MRM-1411 - START
|
||||||
|
@Test
|
||||||
|
public void testGetProjectVersionMetadataWithParentSuccessful()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
|
||||||
|
"target/test-repository/com/example/test/test-artifact-module-a" );
|
||||||
|
|
||||||
|
ProjectVersionMetadata metadata =
|
||||||
|
storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-artifact-module-a", "1.0" );
|
||||||
|
|
||||||
|
MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
|
||||||
|
assertEquals( "jar", facet.getPackaging() );
|
||||||
|
assertEquals( "http://maven.apache.org", metadata.getUrl() );
|
||||||
|
assertEquals( "com.example.test", facet.getParent().getGroupId() );
|
||||||
|
assertEquals( "test-artifact-root", facet.getParent().getArtifactId() );
|
||||||
|
assertEquals( "1.0", facet.getParent().getVersion() );
|
||||||
|
assertEquals( "test-artifact-module-a", facet.getArtifactId() );
|
||||||
|
assertEquals( "com.example.test", facet.getGroupId() );
|
||||||
|
assertNull( metadata.getCiManagement() );
|
||||||
|
assertNotNull( metadata.getDescription() );
|
||||||
|
|
||||||
|
checkApacheLicense( metadata );
|
||||||
|
|
||||||
|
assertEquals( "1.0", metadata.getId() );
|
||||||
|
assertEquals( "Test Artifact :: Module A", metadata.getName() );
|
||||||
|
String path = "test-artifact/trunk/test-artifact-module-a";
|
||||||
|
assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
|
||||||
|
assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
|
||||||
|
assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
|
||||||
|
|
||||||
|
List<Dependency> dependencies = metadata.getDependencies();
|
||||||
|
assertEquals( 2, dependencies.size() );
|
||||||
|
assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
|
||||||
|
assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
|
||||||
|
|
||||||
|
List<String> paths = new ArrayList<String>();
|
||||||
|
paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
|
||||||
|
paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
|
||||||
|
paths.add( "target/test-repository/com/example/test/test-artifact-root" );
|
||||||
|
|
||||||
|
deleteTestArtifactWithParent( paths );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetProjectVersionMetadataWithParentNoRemoteReposConfigured()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
// remove configuration
|
||||||
|
Configuration config = configuration.getConfiguration();
|
||||||
|
RemoteRepositoryConfiguration remoteRepo = config.findRemoteRepositoryById( TEST_REMOTE_REPO_ID );
|
||||||
|
config.removeRemoteRepository( remoteRepo );
|
||||||
|
|
||||||
|
configuration.save( config );
|
||||||
|
|
||||||
|
copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
|
||||||
|
"target/test-repository/com/example/test/test-artifact-module-a" );
|
||||||
|
|
||||||
|
ProjectVersionMetadata metadata =
|
||||||
|
storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-artifact-module-a", "1.0" );
|
||||||
|
assertEquals( "1.0", metadata.getId() );
|
||||||
|
|
||||||
|
MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
|
||||||
|
assertNotNull( facet );
|
||||||
|
assertEquals( "com.example.test", facet.getGroupId() );
|
||||||
|
assertEquals( "test-artifact-module-a", facet.getArtifactId() );
|
||||||
|
assertEquals( "jar", facet.getPackaging() );
|
||||||
|
|
||||||
|
List<String> paths = new ArrayList<String>();
|
||||||
|
paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
|
||||||
|
paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
|
||||||
|
paths.add( "target/test-repository/com/example/test/test-artifact-root" );
|
||||||
|
|
||||||
|
deleteTestArtifactWithParent( paths );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetProjectVersionMetadataWithParentNotInAnyRemoteRepo()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
|
||||||
|
"target/test-repository/com/example/test/test-artifact-module-a" );
|
||||||
|
|
||||||
|
ProjectVersionMetadata metadata =
|
||||||
|
storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-parent", "1.1" );
|
||||||
|
|
||||||
|
assertEquals( "1.1", metadata.getId() );
|
||||||
|
|
||||||
|
MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
|
||||||
|
assertNotNull( facet );
|
||||||
|
assertEquals( "com.example.test", facet.getGroupId() );
|
||||||
|
assertEquals( "missing-parent", facet.getArtifactId() );
|
||||||
|
assertEquals( "jar", facet.getPackaging() );
|
||||||
|
|
||||||
|
List<String> paths = new ArrayList<String>();
|
||||||
|
paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
|
||||||
|
paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
|
||||||
|
paths.add( "target/test-repository/com/example/test/test-artifact-root" );
|
||||||
|
|
||||||
|
deleteTestArtifactWithParent( paths );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetProjectVersionMetadataWithParentSnapshotVersion()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
copyTestArtifactWithParent( "target/test-classes/com/example/test/test-snapshot-artifact-module-a",
|
||||||
|
"target/test-repositorys/com/example/test/test-snapshot-artifact-module-a" );
|
||||||
|
copyTestArtifactWithParent( "target/test-classes/com/example/test/test-snapshot-artifact-root",
|
||||||
|
"target/test-repositorys/com/example/test/test-snapshot-artifact-root" );
|
||||||
|
ProjectVersionMetadata metadata =
|
||||||
|
storage.readProjectVersionMetadata( TEST_SNAP_REPO_ID, "com.example.test", "test-snapshot-artifact-module-a",
|
||||||
|
"1.1-SNAPSHOT" );
|
||||||
|
|
||||||
|
MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
|
||||||
|
assertEquals( "jar", facet.getPackaging() );
|
||||||
|
assertEquals( "com.example.test", facet.getParent().getGroupId() );
|
||||||
|
assertEquals( "test-snapshot-artifact-root", facet.getParent().getArtifactId() );
|
||||||
|
assertEquals( "1.1-SNAPSHOT", facet.getParent().getVersion() );
|
||||||
|
assertEquals( "test-snapshot-artifact-module-a", facet.getArtifactId() );
|
||||||
|
assertEquals( "com.example.test", facet.getGroupId() );
|
||||||
|
assertNull( metadata.getCiManagement() );
|
||||||
|
assertNotNull( metadata.getDescription() );
|
||||||
|
|
||||||
|
checkApacheLicense( metadata );
|
||||||
|
|
||||||
|
assertEquals( "1.1-SNAPSHOT", metadata.getId() );
|
||||||
|
assertEquals( "Test Snapshot Artifact :: Module A", metadata.getName() );
|
||||||
|
String path = "test-snapshot-artifact/trunk/test-snapshot-artifact-module-a";
|
||||||
|
assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
|
||||||
|
assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
|
||||||
|
assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
|
||||||
|
|
||||||
|
List<Dependency> dependencies = metadata.getDependencies();
|
||||||
|
assertEquals( 2, dependencies.size() );
|
||||||
|
assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
|
||||||
|
assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
|
||||||
|
|
||||||
|
List<String> paths = new ArrayList<String>();
|
||||||
|
paths.add( "target/test-repositorys/com/example/test/test-snapshot-artifact-module-a" );
|
||||||
|
paths.add( "target/test-repositorys/com/example/test/test-snapshot-artifact-root" );
|
||||||
|
deleteTestArtifactWithParent( paths );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetProjectVersionMetadataWithParentSnapshotVersionAndSnapNotAllowed()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
copyTestArtifactWithParent( "target/test-classes/com/example/test/test-snapshot-artifact-module-a",
|
||||||
|
"target/test-repositorys/com/example/test/test-snapshot-artifact-module-a" );
|
||||||
|
|
||||||
|
ProjectVersionMetadata metadata =
|
||||||
|
storage.readProjectVersionMetadata( TEST_SNAP_REPO_ID, "com.example.test", "test-snapshot-artifact-module-a",
|
||||||
|
"1.1-SNAPSHOT" );
|
||||||
|
|
||||||
|
MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
|
||||||
|
assertEquals( "jar", facet.getPackaging() );
|
||||||
|
assertEquals( "com.example.test", facet.getParent().getGroupId() );
|
||||||
|
assertEquals( "test-snapshot-artifact-root", facet.getParent().getArtifactId() );
|
||||||
|
assertEquals( "1.1-SNAPSHOT", facet.getParent().getVersion() );
|
||||||
|
assertEquals( "test-snapshot-artifact-module-a", facet.getArtifactId() );
|
||||||
|
assertEquals( "com.example.test", facet.getGroupId() );
|
||||||
|
assertNull( metadata.getCiManagement() );
|
||||||
|
assertNotNull( metadata.getDescription() );
|
||||||
|
|
||||||
|
checkApacheLicense( metadata );
|
||||||
|
|
||||||
|
assertEquals( "1.1-SNAPSHOT", metadata.getId() );
|
||||||
|
assertEquals( "Test Snapshot Artifact :: Module A", metadata.getName() );
|
||||||
|
String path = "test-snapshot-artifact/trunk/test-snapshot-artifact-module-a";
|
||||||
|
assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
|
||||||
|
assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
|
||||||
|
assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
|
||||||
|
|
||||||
|
List<Dependency> dependencies = metadata.getDependencies();
|
||||||
|
assertEquals( 2, dependencies.size() );
|
||||||
|
assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
|
||||||
|
assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
|
||||||
|
|
||||||
|
List<String> paths = new ArrayList<String>();
|
||||||
|
paths.add( "target/test-repositorys/com/example/test/test-snapshot-artifact-module-a" );
|
||||||
|
paths.add( "target/test-repositorys/com/example/test/test-snapshot-artifact-root" );
|
||||||
|
|
||||||
|
deleteTestArtifactWithParent( paths );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetProjectVersionMetadataWithParentSnapshotVersionAndSnapNotAllowed2()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-b",
|
||||||
|
"target/test-repository/com/example/test/test-artifact-module-b" );
|
||||||
|
|
||||||
|
ProjectVersionMetadata metadata =
|
||||||
|
storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-artifact-module-b",
|
||||||
|
"1.0" );
|
||||||
|
|
||||||
|
MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
|
||||||
|
assertEquals( "jar", facet.getPackaging() );
|
||||||
|
assertEquals( "com.example.test", facet.getParent().getGroupId() );
|
||||||
|
assertEquals( "test-snapshot-artifact-root", facet.getParent().getArtifactId() );
|
||||||
|
assertEquals( "1.1-SNAPSHOT", facet.getParent().getVersion() );
|
||||||
|
assertEquals( "test-artifact-module-b", facet.getArtifactId() );
|
||||||
|
assertEquals( "com.example.test", facet.getGroupId() );
|
||||||
|
assertNull( metadata.getCiManagement() );
|
||||||
|
assertNotNull( metadata.getDescription() );
|
||||||
|
|
||||||
|
checkApacheLicense( metadata );
|
||||||
|
|
||||||
|
assertEquals( "1.0", metadata.getId() );
|
||||||
|
assertEquals( "Test Artifact :: Module B", metadata.getName() );
|
||||||
|
String path = "test-snapshot-artifact/trunk/test-artifact-module-b";
|
||||||
|
assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
|
||||||
|
assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
|
||||||
|
assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
|
||||||
|
|
||||||
|
List<Dependency> dependencies = metadata.getDependencies();
|
||||||
|
assertEquals( 2, dependencies.size() );
|
||||||
|
assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
|
||||||
|
assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
|
||||||
|
|
||||||
|
List<String> paths = new ArrayList<String>();
|
||||||
|
paths.add( "target/test-repository/com/example/test/test-artifact-module-b" );
|
||||||
|
paths.add( "target/test-repository/com/example/test/test-snapshot-artifact-root" );
|
||||||
|
|
||||||
|
deleteTestArtifactWithParent( paths );
|
||||||
|
}
|
||||||
|
// Tests for MRM-1411 - END
|
||||||
|
|
||||||
|
private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
|
||||||
|
{
|
||||||
|
assertDependency( dependency, groupId, artifactId, version, "compile" );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
|
||||||
|
String scope )
|
||||||
|
{
|
||||||
|
assertEquals( artifactId, dependency.getArtifactId() );
|
||||||
|
assertEquals( "jar", dependency.getType() );
|
||||||
|
assertEquals( version, dependency.getVersion() );
|
||||||
|
assertEquals( groupId, dependency.getGroupId() );
|
||||||
|
assertEquals( scope, dependency.getScope() );
|
||||||
|
assertNull( dependency.getClassifier() );
|
||||||
|
assertNull( dependency.getSystemPath() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertArtifact( ArtifactMetadata artifact, String id, int size, String sha1, String md5 )
|
||||||
|
{
|
||||||
|
assertEquals( id, artifact.getId() );
|
||||||
|
assertEquals( md5, artifact.getMd5() );
|
||||||
|
assertEquals( sha1, artifact.getSha1() );
|
||||||
|
assertEquals( size, artifact.getSize() );
|
||||||
|
assertEquals( "org.codehaus.plexus", artifact.getNamespace() );
|
||||||
|
assertEquals( "plexus-spring", artifact.getProject() );
|
||||||
|
assertEquals( "1.2", artifact.getVersion() );
|
||||||
|
assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
|
||||||
|
String unsubscribe, List<String> otherArchives, boolean allowPost )
|
||||||
|
{
|
||||||
|
assertEquals( archive, mailingList.getMainArchiveUrl() );
|
||||||
|
if ( allowPost )
|
||||||
|
{
|
||||||
|
assertEquals( post, mailingList.getPostAddress() );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
assertNull( mailingList.getPostAddress() );
|
||||||
|
}
|
||||||
|
assertEquals( subscribe, mailingList.getSubscribeAddress() );
|
||||||
|
assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
|
||||||
|
assertEquals( name, mailingList.getName() );
|
||||||
|
assertEquals( otherArchives, mailingList.getOtherArchives() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
|
||||||
|
String nabbleUrl )
|
||||||
|
{
|
||||||
|
List<String> otherArchives = new ArrayList<String>();
|
||||||
|
otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
|
||||||
|
if ( nabbleUrl != null )
|
||||||
|
{
|
||||||
|
otherArchives.add( nabbleUrl );
|
||||||
|
}
|
||||||
|
otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
|
||||||
|
assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
|
||||||
|
prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
|
||||||
|
prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkApacheLicense( ProjectVersionMetadata metadata )
|
||||||
|
{
|
||||||
|
assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
|
||||||
|
"http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
|
||||||
|
metadata.getLicenses() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkOrganizationApache( ProjectVersionMetadata metadata )
|
||||||
|
{
|
||||||
|
assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
|
||||||
|
assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteTestArtifactWithParent( List<String> pathsToBeDeleted )
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
for ( String path : pathsToBeDeleted )
|
||||||
|
{
|
||||||
|
File dir = new File( FileUtil.getBasedir(), path );
|
||||||
|
FileUtils.deleteDirectory( dir );
|
||||||
|
|
||||||
|
assertFalse( dir.exists() );
|
||||||
|
}
|
||||||
|
File dest = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" );
|
||||||
|
File parentPom =
|
||||||
|
new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" );
|
||||||
|
File rootPom = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" );
|
||||||
|
|
||||||
|
FileUtils.deleteDirectory( dest );
|
||||||
|
FileUtils.deleteDirectory( parentPom );
|
||||||
|
FileUtils.deleteDirectory( rootPom );
|
||||||
|
|
||||||
|
assertFalse( dest.exists() );
|
||||||
|
assertFalse( parentPom.exists() );
|
||||||
|
assertFalse( rootPom.exists() );
|
||||||
|
}
|
||||||
|
|
||||||
|
private File copyTestArtifactWithParent( String srcPath, String destPath )
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
File src = new File( FileUtil.getBasedir(), srcPath );
|
||||||
|
File dest = new File( FileUtil.getBasedir(), destPath );
|
||||||
|
|
||||||
|
FileUtils.copyDirectory( src, dest );
|
||||||
|
assertTrue( dest.exists() );
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -40,6 +40,7 @@ import org.apache.archiva.metadata.model.MailingList;
|
||||||
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
|
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
|
||||||
import org.apache.archiva.metadata.repository.filter.AllFilter;
|
import org.apache.archiva.metadata.repository.filter.AllFilter;
|
||||||
import org.apache.archiva.metadata.repository.filter.Filter;
|
import org.apache.archiva.metadata.repository.filter.Filter;
|
||||||
|
import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException;
|
||||||
import org.apache.archiva.proxy.common.WagonFactory;
|
import org.apache.archiva.proxy.common.WagonFactory;
|
||||||
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
|
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
@ -278,6 +279,33 @@ public class Maven2RepositoryMetadataResolverMRM1411Test
|
||||||
deleteTestArtifactWithParent( paths );
|
deleteTestArtifactWithParent( paths );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetProjectVersionMetadataWithParentSnapshotVersionAndSnapNotAllowed()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
testRepo.setSnapshots( false );
|
||||||
|
configuration.save( c );
|
||||||
|
assertFalse ( c.getManagedRepositories().get( 0 ).isSnapshots() );
|
||||||
|
copyTestArtifactWithParent( "target/test-classes/com/example/test/test-snapshot-artifact-module-a",
|
||||||
|
"target/test-repository/com/example/test/test-snapshot-artifact-module-a" );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ProjectVersionMetadata metadata =
|
||||||
|
storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-snapshot-artifact-module-a",
|
||||||
|
"1.1-SNAPSHOT" );
|
||||||
|
fail( "Should not be found" );
|
||||||
|
}
|
||||||
|
catch ( RepositoryStorageRuntimeException e )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> paths = new ArrayList<String>();
|
||||||
|
paths.add( "target/test-repository/com/example/test/test-snapshot-artifact-module-a" );
|
||||||
|
paths.add( "target/test-repository/com/example/test/test-snapshot-artifact-root" );
|
||||||
|
|
||||||
|
deleteTestArtifactWithParent( paths );
|
||||||
|
}
|
||||||
// Tests for MRM-1411 - END
|
// Tests for MRM-1411 - END
|
||||||
|
|
||||||
private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
|
private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
|
||||||
|
|
Loading…
Reference in New Issue