private String type;
+ public String getProjectVersion( )
+ {
+ return projectVersion;
+ }
+
+ public void setProjectVersion( String projectVersion )
+ {
+ this.projectVersion = projectVersion;
+ }
+
+ private String projectVersion;
+
+
//-----------/
//- Methods -/
//-----------/
import org.apache.archiva.repository.RemoteRepository;
import org.apache.archiva.repository.RemoteRepositoryContent;
import org.apache.archiva.repository.RepositoryType;
+import org.apache.archiva.repository.content.Artifact;
+import org.apache.archiva.repository.content.ItemSelector;
+import org.apache.archiva.repository.content.base.ArchivaItemSelector;
import org.apache.archiva.repository.metadata.base.MetadataTools;
import org.apache.archiva.repository.metadata.RepositoryMetadataException;
import org.apache.archiva.repository.storage.fs.FilesystemStorage;
private StorageAsset toLocalFile(ManagedRepository repository, ArtifactReference artifact ) throws LayoutException
{
- return repository.getContent().getLayout( BaseRepositoryContentLayout.class ).toFile( artifact );
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( artifact.getGroupId( ) )
+ .withProjectId( artifact.getArtifactId( ) )
+ .withArtifactId( artifact.getArtifactId( ) )
+ .withArtifactVersion( artifact.getVersion() )
+ .withVersion( artifact.getProjectVersion( ) )
+ .withType( artifact.getType( ) ).build();
+ Artifact repoArtifact = repository.getContent( ).getLayout( BaseRepositoryContentLayout.class ).getArtifact( selector );
+ return repoArtifact.getAsset( );
}
/**
import java.nio.file.attribute.FileTime;
import java.util.concurrent.TimeUnit;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
/**
* SnapshotTransferTest
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
+ assertNotNull( downloadedFile );
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
assertNoTempFiles( expectedFile );
}
BaseRepositoryContentLayout layout = managedDefaultRepository.getLayout( BaseRepositoryContentLayout.class );
ArtifactReference artifact = managedDefaultRepository.toArtifactReference( path );
+ artifact.setProjectVersion( "1.0-SNAPSHOT" );
assertTrue( Files.exists(expectedFile) );
StorageAsset downloadedFile = proxyHandler.fetchFromProxies( managedDefaultRepository.getRepository(), artifact );
Path proxiedFile = Paths.get(REPOPATH_PROXIED1, path);
+ assertNotNull( downloadedFile );
assertFileEquals( expectedFile, downloadedFile.getFilePath(), proxiedFile );
assertNoTempFiles( expectedFile );
}
import org.apache.archiva.repository.content.Namespace;
import org.apache.archiva.repository.content.Project;
import org.apache.archiva.repository.content.Version;
+import org.apache.archiva.repository.content.base.ArchivaArtifact;
import org.apache.archiva.repository.content.base.ArchivaContentItem;
import org.apache.archiva.repository.content.base.ArchivaDataItem;
import org.apache.archiva.repository.content.base.ArchivaNamespace;
@Override
public Artifact getArtifact( ItemSelector selector ) throws ContentAccessException
{
- return null;
+ StringBuilder path = new StringBuilder(selector.getNamespace( ).replace( ".", "/" ));
+ path.append( "/" ).append( selector.getProjectId( ) ).append( "/" ).append( selector.getVersion( ) );
+ path.append( "/" ).append( selector.getArtifactId( ) ).append( "-" ).append( selector.getArtifactVersion( ) ).append( "." ).append( selector.getType( ) );
+ StorageAsset asset = fsStorage.getAsset( path.toString( ) );
+ ArchivaNamespace ns = ArchivaNamespace.withRepository( repository.getContent( ) ).withAsset( asset.getParent( ).getParent( ).getParent( ) ).withNamespace( selector.getNamespace( ) ).build( );
+ ArchivaProject project = ArchivaProject.withRepository( repository.getContent( ) ).withAsset( asset.getParent( ).getParent( ) ).withNamespace( ns ).withId( selector.getProjectId( ) ).build( );
+ ArchivaVersion version = ArchivaVersion.withRepository( repository.getContent( ) ).withAsset( asset.getParent( ) ).withProject( project ).withVersion( selector.getVersion( ) ).build( );
+ ArchivaArtifact artifact = ArchivaArtifact.withAsset( asset ).withVersion( version ).withId( selector.getArtifactId( ) ).withArtifactVersion( selector.getArtifactVersion( ) ).withType( selector.getType( ) ).build( );
+ return artifact;
}
@Override
artifact.setGroupId( metadata.getNamespace() );
artifact.setArtifactId( metadata.getProject() );
artifact.setVersion( metadata.getVersion() );
+ artifact.setProjectVersion( metadata.getProjectVersion( ) );
MavenArtifactFacet facet = (MavenArtifactFacet) metadata.getFacet( MavenArtifactFacet.FACET_ID );
if ( facet != null )
{
artifact.setGroupId( metadata.getNamespace() );
artifact.setArtifactId( metadata.getProject() );
artifact.setVersion( metadata.getVersion() );
+ artifact.setProjectVersion( metadata.getProjectVersion( ) );
MavenArtifactFacet facet = (MavenArtifactFacet) metadata.getFacet( MavenArtifactFacet.FACET_ID );
if ( facet != null )
{
import org.apache.archiva.proxy.model.ProxyConnector;
import org.apache.archiva.proxy.model.RepositoryProxyHandler;
import org.apache.archiva.repository.*;
+import org.apache.archiva.repository.content.Artifact;
+import org.apache.archiva.repository.content.ItemSelector;
import org.apache.archiva.repository.content.PathParser;
+import org.apache.archiva.repository.content.base.ArchivaItemSelector;
import org.apache.archiva.repository.maven.MavenSystemManager;
import org.apache.archiva.repository.metadata.RepositoryMetadataException;
import org.apache.archiva.repository.storage.StorageAsset;
pomReference.setGroupId(artifact.getGroupId());
pomReference.setArtifactId(artifact.getArtifactId());
pomReference.setVersion(artifact.getVersion());
+ pomReference.setProjectVersion( artifact.getProjectVersion() );
pomReference.setType("pom");
+ BaseRepositoryContentLayout layout;
+ try
+ {
+ layout = managedRepository.getContent( ).getLayout( BaseRepositoryContentLayout.class );
+ }
+ catch ( LayoutException e )
+ {
+ throw new ProxyDownloadException( "Could not set layout " + e.getMessage( ), new HashMap<>( ) );
+ }
RepositoryType repositoryType = managedRepository.getType();
if (!proxyRegistry.hasHandler(repositoryType)) {
throw new ProxyDownloadException("No proxy handler found for repository type " + repositoryType, new HashMap<>());
}
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( artifact.getGroupId( ) )
+ .withProjectId( artifact.getArtifactId( ) )
+ .withArtifactId( artifact.getArtifactId( ) )
+ .withVersion( artifact.getVersion( ) )
+ .withArtifactVersion( artifact.getVersion( ) )
+ .withType( "pom" ).build( );
+
+ Artifact pom = layout.getArtifact( selector );
+
RepositoryProxyHandler proxyHandler = proxyRegistry.getHandler(repositoryType).get(0);
// Get the artifact POM from proxied repositories if needed
proxyHandler.fetchFromProxies(managedRepository, pomReference);
// Open and read the POM from the managed repo
- StorageAsset pom = null;
- try
- {
- pom = managedRepository.getContent().getLayout( BaseRepositoryContentLayout.class ).toFile(pomReference);
- }
- catch ( LayoutException e )
- {
- throw new ProxyDownloadException( "Cannot convert layout ", new HashMap<>( ) );
- }
if (!pom.exists()) {
return;
// MavenXpp3Reader leaves the file open, so we need to close it ourselves.
Model model;
- try (Reader reader = Channels.newReader(pom.getReadChannel(), Charset.defaultCharset().name())) {
+ try (Reader reader = Channels.newReader(pom.getAsset().getReadChannel(), Charset.defaultCharset().name())) {
model = MAVEN_XPP_3_READER.read(reader);
}
import org.apache.archiva.repository.BaseRepositoryContentLayout;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.LayoutException;
+import org.apache.archiva.repository.content.ItemSelector;
+import org.apache.archiva.repository.content.base.ArchivaItemSelector;
import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.repository.storage.util.StorageUtil;
+import org.apache.commons.lang3.StringUtils;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
public Artifact build()
{
- ArtifactReference ref = new ArtifactReference();
- ref.setArtifactId( artifactMetadata.getProject() );
- ref.setGroupId( artifactMetadata.getNamespace() );
- ref.setVersion( artifactMetadata.getVersion() );
-
String type = null, classifier = null;
MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet( MavenArtifactFacet.FACET_ID );
classifier = facet.getClassifier();
}
- ref.setClassifier( classifier );
- ref.setType( type );
+ ArchivaItemSelector.Builder selectorBuilder = ArchivaItemSelector.builder( )
+ .withNamespace( artifactMetadata.getNamespace( ) )
+ .withProjectId( artifactMetadata.getProject( ) )
+ .withVersion( artifactMetadata.getProjectVersion( ) )
+ .withArtifactId( artifactMetadata.getProject( ) )
+ .withArtifactVersion( artifactMetadata.getVersion( ) );
+ if (StringUtils.isNotEmpty( type ) ) {
+ selectorBuilder.withType( type );
+ }
+ if (StringUtils.isNotEmpty( classifier )) {
+ selectorBuilder.withClassifier( classifier );
+ }
+
+
BaseRepositoryContentLayout layout;
try
{
{
throw new RuntimeException( "Could not convert to layout " + e.getMessage( ) );
}
- StorageAsset file = layout.toFile( ref );
+ org.apache.archiva.repository.content.Artifact repoArtifact = layout.getArtifact( selectorBuilder.build( ) );
+
+ String extension = repoArtifact.getExtension();
- String extension = getExtensionFromFile(file);
-
- Artifact artifact = new Artifact( ref.getGroupId(), ref.getArtifactId(), ref.getVersion() );
+ Artifact artifact = new Artifact( repoArtifact.getVersion( ).getProject( ).getNamespace( ).getNamespace( ), repoArtifact.getId( ), repoArtifact.getArtifactVersion( ) );
artifact.setRepositoryId( artifactMetadata.getRepositoryId() );
artifact.setClassifier( classifier );
artifact.setPackaging( type );
artifact.setType( type );
artifact.setFileExtension( extension );
- artifact.setPath( managedRepositoryContent.toPath( ref ) );
+ artifact.setPath( managedRepositoryContent.toPath( repoArtifact ) );
// TODO: find a reusable formatter for this
double s = this.artifactMetadata.getSize();
String symbol = "b";
DecimalFormat df = new DecimalFormat( "#,###.##", new DecimalFormatSymbols( Locale.US ) );
artifact.setSize( df.format( s ) + " " + symbol );
- artifact.setId( ref.getArtifactId() + "-" + ref.getVersion() + "." + ref.getType() );
+ artifact.setId( repoArtifact.getId() + "-" + repoArtifact.getArtifactVersion() + "." + repoArtifact.getType() );
return artifact;
import org.apache.archiva.configuration.FileTypes;
import org.apache.archiva.configuration.RepositoryGroupConfiguration;
import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.maven.content.MavenContentHelper;
import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
import org.apache.archiva.proxy.ProxyRegistry;
import org.apache.archiva.repository.EditableManagedRepository;
import org.springframework.test.context.ContextConfiguration;
import javax.inject.Inject;
+import javax.inject.Named;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
@Inject
ProxyRegistry proxyRegistry;
+ @Inject
+ @Named( "MavenContentHelper" )
+ MavenContentHelper mavenContentHelper;
@Inject
DefaultRepositoryGroupAdmin defaultRepositoryGroupAdmin;
throws RepositoryAdminException
{
org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository( repoId );
- ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent(repo, artifactMappingProviders, fileTypes, fileLockManager);
+ ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent(repo, artifactMappingProviders, fileTypes, fileLockManager);
if (repo!=null && repo instanceof EditableManagedRepository)
{
( (EditableManagedRepository) repo ).setContent( repoContent );
}
+ repoContent.setMavenContentHelper( mavenContentHelper );
return repoContent;
}