aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2020-06-13 20:21:51 +0200
committerMartin Stockhammer <martin_s@apache.org>2020-06-13 20:21:51 +0200
commit628e67094518645923c0b12504cf6925b9e2c839 (patch)
tree144d851d8ea14b5a52528c7249e0b02428442db9 /archiva-modules
parenta548587e47dec678af021f428c80f08ddc728177 (diff)
downloadarchiva-628e67094518645923c0b12504cf6925b9e2c839.tar.gz
archiva-628e67094518645923c0b12504cf6925b9e2c839.zip
Cleanup of APIs
Diffstat (limited to 'archiva-modules')
-rw-r--r--archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/RepositoryProxyHandler.java16
-rw-r--r--archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java81
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaItemSelector.java17
-rw-r--r--archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArtifactUtil.java17
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/AbstractDefaultRepositoryContent.java254
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ArtifactInfo.java42
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java23
-rw-r--r--archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java20
-rw-r--r--archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java121
9 files changed, 302 insertions, 289 deletions
diff --git a/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/RepositoryProxyHandler.java b/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/RepositoryProxyHandler.java
index f6c9259a3..42dd67fc0 100644
--- a/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/RepositoryProxyHandler.java
+++ b/archiva-modules/archiva-base/archiva-proxy-api/src/main/java/org/apache/archiva/proxy/model/RepositoryProxyHandler.java
@@ -66,22 +66,6 @@ public interface RepositoryProxyHandler
* If the artifact is found, it is downloaded and placed into the source repository
* filesystem.
*
- * @deprecated Replaced by {@link #fetchFromProxies(ManagedRepository, Artifact)}
- * @param repository the source repository to use. (must be a managed repository)
- * @param artifact the artifact to fetch.
- * @return the file that was obtained, or null if no content was obtained
- * @throws ProxyDownloadException if there was a problem fetching the content from the target repositories.
- */
- StorageAsset fetchFromProxies( ManagedRepository repository, ArtifactReference artifact )
- throws ProxyDownloadException;
-
- /**
- * Performs the artifact fetch operation against the target repositories
- * of the provided source repository.
- * <p>
- * If the artifact is found, it is downloaded and placed into the source repository
- * filesystem.
- *
* @param repository the source repository to use. (must be a managed repository)
* @param artifact the artifact to fetch.
* @return the file that was obtained, or null if no content was obtained
diff --git a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java
index 2373fb938..99ca6ca2f 100644
--- a/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java
+++ b/archiva-modules/archiva-base/archiva-proxy/src/main/java/org/apache/archiva/proxy/DefaultRepositoryProxyHandler.java
@@ -62,7 +62,6 @@ import org.apache.archiva.scheduler.ArchivaTaskScheduler;
import org.apache.archiva.scheduler.repository.model.RepositoryTask;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.SystemUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MarkerFactory;
@@ -275,86 +274,6 @@ public abstract class DefaultRepositoryProxyHandler implements RepositoryProxyHa
}
@Override
- public StorageAsset fetchFromProxies( ManagedRepository repository, ArtifactReference artifact )
- throws ProxyDownloadException
- {
- StorageAsset localFile = null;
- Map<String, Exception> previousExceptions = new LinkedHashMap<>();
- try
- {
- localFile = toLocalFile( repository, artifact );
- }
- catch ( LayoutException e )
- {
- previousExceptions.put( "LayoutException", e );
- throw new ProxyDownloadException( "Could not convert to BasicRepositoryContentLayout " + e.getMessage( ), previousExceptions);
- }
-
- Properties requestProperties = new Properties();
- requestProperties.setProperty( "filetype", "artifact" );
- requestProperties.setProperty( "version", artifact.getVersion() );
- requestProperties.setProperty( "managedRepositoryId", repository.getId() );
-
- List<ProxyConnector> connectors = getProxyConnectors( repository );
- for ( ProxyConnector connector : connectors )
- {
- if ( !connector.isEnabled() )
- {
- continue;
- }
-
- RemoteRepository targetRepository = connector.getTargetRepository();
- requestProperties.setProperty( "remoteRepositoryId", targetRepository.getId() );
-
- String targetPath = targetRepository.getContent().toPath( artifact );
-
- if ( SystemUtils.IS_OS_WINDOWS )
- {
- // toPath use system PATH_SEPARATOR so on windows url are \ which doesn't work very well :-)
- targetPath = PathUtil.separatorsToUnix( targetPath );
- }
-
- try
- {
- StorageAsset downloadedFile =
- transferFile( connector, targetRepository, targetPath, repository, localFile, requestProperties,
- true );
-
- if ( fileExists(downloadedFile) )
- {
- log.debug( "Successfully transferred: {}", downloadedFile.getPath() );
- return downloadedFile;
- }
- }
- catch ( NotFoundException e )
- {
- log.debug( "Artifact {} not found on repository \"{}\".", Keys.toKey( artifact ),
- targetRepository.getId() );
- }
- catch ( NotModifiedException e )
- {
- log.debug( "Artifact {} not updated on repository \"{}\".", Keys.toKey( artifact ),
- targetRepository.getId() );
- }
- catch ( ProxyException e )
- {
- validatePolicies( this.downloadErrorPolicies, connector.getPolicies(), requestProperties, artifact,
- targetRepository.getContent(), localFile, e, previousExceptions );
- }
- }
-
- if ( !previousExceptions.isEmpty() )
- {
- throw new ProxyDownloadException( "Failures occurred downloading from some remote repositories",
- previousExceptions );
- }
-
- log.debug( "Exhausted all target repositories, artifact {} not found.", Keys.toKey( artifact ) );
-
- return null;
- }
-
- @Override
public StorageAsset fetchFromProxies( ManagedRepository repository, String path )
{
StorageAsset localFile = repository.getAsset( path );
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaItemSelector.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaItemSelector.java
index cb5063087..e36ca2c97 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaItemSelector.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArchivaItemSelector.java
@@ -92,6 +92,23 @@ public class ArchivaItemSelector implements ItemSelector
return this;
}
+ public Builder withSelector(ItemSelector givenSelector) {
+ selector.namespace = givenSelector.getNamespace( );
+ selector.projectId = givenSelector.getProjectId( );
+ selector.version = givenSelector.getVersion( );
+ selector.extension = givenSelector.getExtension( );
+ selector.artifactId = givenSelector.getArtifactId( );
+ selector.artifactVersion = givenSelector.getArtifactVersion( );
+ selector.recurse = givenSelector.recurse( );
+ for (Map.Entry<String, String> att : givenSelector.getAttributes().entrySet()) {
+ selector.setAttribute( att.getKey( ), att.getValue( ) );
+ }
+ selector.type = givenSelector.getType( );
+ selector.classifier = givenSelector.getClassifier( );
+ selector.includeRelatedArtifacts = givenSelector.includeRelatedArtifacts( );
+ return this;
+ }
+
public Builder withNamespace( String namespace )
{
if (namespace!=null)
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArtifactUtil.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArtifactUtil.java
index fe964b945..14a14db4c 100644
--- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArtifactUtil.java
+++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/content/base/ArtifactUtil.java
@@ -48,23 +48,6 @@ public class ArtifactUtil
*
* @param repository The repository, where the artifact is stored.
* @param artifactReference The artifact reference.
- * @return The absolute path to the artifact.
- * @throws RepositoryException
- */
- public Path getArtifactPath( ManagedRepository repository, ArtifactReference artifactReference ) throws RepositoryException
- {
- final ManagedRepositoryContent content = repositoryContentFactory.getManagedRepositoryContent( repository );
- final String artifactPath;
- artifactPath = content.toPath( artifactReference );
- return Paths.get( repository.getLocation( ) ).resolve( artifactPath );
- }
-
- /**
- * Returns the physical location of a given artifact in the repository. There is no check for the
- * existence of the returned file.
- *
- * @param repository The repository, where the artifact is stored.
- * @param artifactReference The artifact reference.
* @return The asset representation of the artifact.
* @throws RepositoryException
*/
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/AbstractDefaultRepositoryContent.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/AbstractDefaultRepositoryContent.java
index 3bd7203f8..01949dea0 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/AbstractDefaultRepositoryContent.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/AbstractDefaultRepositoryContent.java
@@ -19,15 +19,10 @@ package org.apache.archiva.repository.maven.content;
*/
import org.apache.archiva.common.utils.VersionUtil;
-import org.apache.archiva.metadata.maven.model.MavenArtifactFacet;
-import org.apache.archiva.metadata.model.ArtifactMetadata;
import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
import org.apache.archiva.repository.content.base.ArchivaItemSelector;
import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
-import org.apache.archiva.model.ArchivaArtifact;
import org.apache.archiva.model.ArtifactReference;
-import org.apache.archiva.model.ProjectReference;
-import org.apache.archiva.model.VersionedReference;
import org.apache.archiva.repository.LayoutException;
import org.apache.archiva.repository.RepositoryContent;
import org.apache.archiva.repository.content.ItemSelector;
@@ -36,6 +31,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* AbstractDefaultRepositoryContent - common methods for working with default (maven 2) layout.
@@ -54,6 +51,9 @@ public abstract class AbstractDefaultRepositoryContent implements RepositoryCont
protected static final char ARTIFACT_SEPARATOR = '-';
+ private static final Pattern TIMESTAMP_PATTERN = Pattern.compile( "([0-9]{8}.[0-9]{6})-([0-9]+).*" );
+ private static final Pattern MAVEN_PLUGIN_PATTERN = Pattern.compile( "^(maven-.*-plugin)|(.*-maven-plugin)$" );
+
private RepositoryPathTranslator pathTranslator;
private List<? extends ArtifactMappingProvider> artifactMappingProviders;
@@ -75,6 +75,177 @@ public abstract class AbstractDefaultRepositoryContent implements RepositoryCont
this.artifactMappingProviders = artifactMappingProviders;
}
+ public ArchivaItemSelector.Builder getArtifactFromFilename( String namespace, String projectId, String projectVersion,
+ String artifactFileName )
+ {
+ if ( !artifactFileName.startsWith( projectId + "-" ) )
+ {
+ throw new IllegalArgumentException( "Not a valid artifact path in a Maven 2 repository, filename '" + artifactFileName
+ + "' doesn't start with artifact ID '" + projectId + "'" );
+ }
+
+ int index = projectId.length() + 1;
+ String version;
+ String idSubStrFromVersion = artifactFileName.substring( index );
+ if ( idSubStrFromVersion.startsWith( projectVersion ) && !VersionUtil.isUniqueSnapshot( projectVersion ) )
+ {
+ // non-snapshot versions, or non-timestamped snapshot versions
+ version = projectVersion;
+ }
+ else if ( VersionUtil.isGenericSnapshot( projectVersion ) )
+ {
+ // timestamped snapshots
+ try
+ {
+ int mainVersionLength = projectVersion.length() - 8; // 8 is length of "SNAPSHOT"
+ if ( mainVersionLength == 0 )
+ {
+ throw new IllegalArgumentException(
+ "Timestamped snapshots must contain the main version, filename was '" + artifactFileName + "'" );
+ }
+
+ Matcher m = TIMESTAMP_PATTERN.matcher( idSubStrFromVersion.substring( mainVersionLength ) );
+ m.matches();
+ String timestamp = m.group( 1 );
+ String buildNumber = m.group( 2 );
+ version = idSubStrFromVersion.substring( 0, mainVersionLength ) + timestamp + "-" + buildNumber;
+ }
+ catch ( IllegalStateException e )
+ {
+ throw new IllegalArgumentException( "Not a valid artifact path in a Maven 2 repository, filename '" + artifactFileName
+ + "' doesn't contain a timestamped version matching snapshot '"
+ + projectVersion + "'", e);
+ }
+ }
+ else
+ {
+ // invalid
+ throw new IllegalArgumentException(
+ "Not a valid artifact path in a Maven 2 repository, filename '" + artifactFileName + "' doesn't contain version '"
+ + projectVersion + "'" );
+ }
+
+ String classifier;
+ String ext;
+ index += version.length();
+ if ( index == artifactFileName.length() )
+ {
+ // no classifier or extension
+ classifier = null;
+ ext = null;
+ }
+ else
+ {
+ char c = artifactFileName.charAt( index );
+ if ( c == '-' )
+ {
+ // classifier up until '.'
+ int extIndex = artifactFileName.indexOf( '.', index );
+ if ( extIndex >= 0 )
+ {
+ classifier = artifactFileName.substring( index + 1, extIndex );
+ ext = artifactFileName.substring( extIndex + 1 );
+ }
+ else
+ {
+ classifier = artifactFileName.substring( index + 1 );
+ ext = null;
+ }
+ }
+ else if ( c == '.' )
+ {
+ // rest is the extension
+ classifier = null;
+ ext = artifactFileName.substring( index + 1 );
+ }
+ else
+ {
+ throw new IllegalArgumentException( "Not a valid artifact path in a Maven 2 repository, filename '" + artifactFileName
+ + "' expected classifier or extension but got '"
+ + artifactFileName.substring( index ) + "'" );
+ }
+ }
+
+ ArchivaItemSelector.Builder selectorBuilder = ArchivaItemSelector.builder( )
+ .withNamespace( namespace )
+ .withProjectId( projectId )
+ .withArtifactId( projectId )
+ .withVersion( projectVersion )
+ .withArtifactVersion( version )
+ .withClassifier( classifier );
+
+
+ // we use our own provider here instead of directly accessing Maven's artifact handlers as it has no way
+ // to select the correct order to apply multiple extensions mappings to a preferred type
+ // TODO: this won't allow the user to decide order to apply them if there are conflicts or desired changes -
+ // perhaps the plugins could register missing entries in configuration, then we just use configuration
+ // here?
+
+ String type = null;
+ for ( ArtifactMappingProvider mapping : artifactMappingProviders )
+ {
+ type = mapping.mapClassifierAndExtensionToType( classifier, ext );
+ if ( type != null )
+ {
+ break;
+ }
+ }
+
+ // TODO: this is cheating! We should check the POM metadata instead
+ if ( type == null && "jar".equals( ext ) && isArtifactIdValidMavenPlugin( projectId ) )
+ {
+ type = "maven-plugin";
+ }
+
+ // use extension as default
+ if ( type == null )
+ {
+ type = ext;
+ }
+
+ // TODO: should we allow this instead?
+ if ( type == null )
+ {
+ throw new IllegalArgumentException(
+ "Not a valid artifact path in a Maven 2 repository, filename '" + artifactFileName + "' does not have a type" );
+ }
+
+ selectorBuilder.withType( type );
+
+
+ return selectorBuilder;
+ }
+
+ public boolean isArtifactIdValidMavenPlugin( String artifactId )
+ {
+ return MAVEN_PLUGIN_PATTERN.matcher( artifactId ).matches();
+ }
+
+ private ArchivaItemSelector getArtifactForPath( String relativePath )
+ {
+ String[] parts = relativePath.replace( '\\', '/' ).split( "/" );
+
+ int len = parts.length;
+ if ( len < 4 )
+ {
+ throw new IllegalArgumentException(
+ "Not a valid artifact path in a Maven 2 repository, not enough directories: " + relativePath );
+ }
+
+ String fileName = parts[--len];
+ String baseVersion = parts[--len];
+ String artifactId = parts[--len];
+ StringBuilder namespaceBuilder = new StringBuilder();
+ for ( int i = 0; i < len - 1; i++ )
+ {
+ namespaceBuilder.append( parts[i] );
+ namespaceBuilder.append( '.' );
+ }
+ namespaceBuilder.append( parts[len - 1] );
+
+ return getArtifactFromFilename( namespaceBuilder.toString(), artifactId, baseVersion, fileName ).build();
+ }
+
@Override
public ItemSelector toItemSelector( String path ) throws LayoutException
{
@@ -82,22 +253,10 @@ public abstract class AbstractDefaultRepositoryContent implements RepositoryCont
{
throw new LayoutException( "Unable to convert blank path." );
}
-
try
{
- ArtifactMetadata metadata = pathTranslator.getArtifactForPath( null, path );
- ArchivaItemSelector.Builder builder = ArchivaItemSelector.builder( ).withNamespace( metadata.getNamespace( ) )
- .withProjectId( metadata.getProject( ) )
- .withVersion( metadata.getProjectVersion( ) )
- .withArtifactId( metadata.getProject( ) )
- .withArtifactVersion( metadata.getVersion( ) );
- MavenArtifactFacet facet = (MavenArtifactFacet) metadata.getFacet( MavenArtifactFacet.FACET_ID );
- if ( facet != null )
- {
- builder.withClassifier( facet.getClassifier() );
- builder.withType( facet.getType() );
- }
- return builder.build( );
+
+ return getArtifactForPath( path );
}
catch ( IllegalArgumentException e )
{
@@ -106,13 +265,6 @@ public abstract class AbstractDefaultRepositoryContent implements RepositoryCont
}
- public String toPath ( ProjectReference reference) {
- final StringBuilder path = new StringBuilder();
- path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR );
- path.append( reference.getArtifactId( ) );
- return path.toString( );
- }
-
@Override
public String toPath ( ItemSelector selector ) {
if (selector==null) {
@@ -153,61 +305,11 @@ public abstract class AbstractDefaultRepositoryContent implements RepositoryCont
}
- public String toMetadataPath( ProjectReference reference )
- {
- final StringBuilder path = new StringBuilder();
- path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR );
- path.append( reference.getArtifactId() ).append( PATH_SEPARATOR );
- path.append( MAVEN_METADATA );
- return path.toString();
- }
-
public String toPath( String namespace )
{
return formatAsDirectory( namespace );
}
- public String toPath( VersionedReference reference )
- {
- final StringBuilder path = new StringBuilder();
- path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR );
- path.append( reference.getArtifactId() ).append( PATH_SEPARATOR );
- if ( reference.getVersion() != null )
- {
- // add the version only if it is present
- path.append( VersionUtil.getBaseVersion( reference.getVersion() ) );
- }
- return path.toString();
- }
-
- public String toMetadataPath( VersionedReference reference )
- {
- StringBuilder path = new StringBuilder();
-
- path.append( formatAsDirectory( reference.getGroupId() ) ).append( PATH_SEPARATOR );
- path.append( reference.getArtifactId() ).append( PATH_SEPARATOR );
- if ( reference.getVersion() != null )
- {
- // add the version only if it is present
- path.append( VersionUtil.getBaseVersion( reference.getVersion() ) ).append( PATH_SEPARATOR );
- }
- path.append( MAVEN_METADATA );
-
- return path.toString();
- }
-
- public String toPath( ArchivaArtifact reference )
- {
- if ( reference == null )
- {
- throw new IllegalArgumentException( "ArchivaArtifact cannot be null" );
- }
-
- String baseVersion = VersionUtil.getBaseVersion( reference.getVersion() );
- return toPath( reference.getGroupId(), reference.getArtifactId(), baseVersion, reference.getVersion(),
- reference.getClassifier(), reference.getType() );
- }
-
@Override
public String toPath( ArtifactReference reference )
{
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ArtifactInfo.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ArtifactInfo.java
new file mode 100644
index 000000000..3a198cc8b
--- /dev/null
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ArtifactInfo.java
@@ -0,0 +1,42 @@
+package org.apache.archiva.repository.maven.content;
+
+/*
+ * 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 org.apache.archiva.repository.content.ArtifactType;
+import org.apache.archiva.repository.content.BaseArtifactTypes;
+import org.apache.archiva.repository.storage.StorageAsset;
+
+/**
+ * @author Martin Stockhammer <martin_s@apache.org>
+ */ // Simple object to hold artifact information
+class ArtifactInfo
+{
+ protected String id;
+ protected String version;
+ protected String extension;
+ protected String remainder;
+ protected String type;
+ protected String classifier;
+ protected String contentType;
+ protected String namespace;
+ protected String project;
+ protected String projectVersion;
+ protected StorageAsset asset;
+ protected ArtifactType artifactType = BaseArtifactTypes.MAIN;
+}
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java
index 57bcc9ee1..cfc7354c8 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContent.java
@@ -23,7 +23,6 @@ import org.apache.archiva.common.utils.FileUtils;
import org.apache.archiva.common.utils.VersionUtil;
import org.apache.archiva.configuration.FileTypes;
import org.apache.archiva.metadata.maven.MavenMetadataReader;
-import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.repository.BaseRepositoryContentLayout;
import org.apache.archiva.repository.ContentAccessException;
@@ -35,7 +34,6 @@ import org.apache.archiva.repository.ManagedRepository;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.ManagedRepositoryContentLayout;
import org.apache.archiva.repository.content.Artifact;
-import org.apache.archiva.repository.content.ArtifactType;
import org.apache.archiva.repository.content.BaseArtifactTypes;
import org.apache.archiva.repository.content.ContentItem;
import org.apache.archiva.repository.content.DataItem;
@@ -50,8 +48,6 @@ import org.apache.archiva.repository.content.base.ArchivaNamespace;
import org.apache.archiva.repository.content.base.ArchivaProject;
import org.apache.archiva.repository.content.base.ArchivaVersion;
import org.apache.archiva.repository.content.base.builder.ArtifactOptBuilder;
-import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
-import org.apache.archiva.repository.maven.metadata.storage.DefaultArtifactMappingProvider;
import org.apache.archiva.repository.storage.RepositoryStorage;
import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.repository.storage.util.StorageUtil;
@@ -299,6 +295,11 @@ public class ManagedDefaultRepositoryContent
if ( selector.hasVersion( ) && selector.hasArtifactId( ) )
{
return getArtifact( selector );
+ } else if ( !selector.hasVersion() && selector.hasArtifactVersion() && selector.hasArtifactId() ) {
+ String baseVersion = VersionUtil.getBaseVersion( selector.getArtifactVersion( ) );
+ ItemSelector selector1 = ArchivaItemSelector.builder( ).withSelector( selector )
+ .withVersion(baseVersion).build();
+ return getArtifact( selector1 );
}
else if ( selector.hasProjectId( ) && selector.hasVersion( ) )
{
@@ -634,20 +635,6 @@ public class ManagedDefaultRepositoryContent
return this;
}
- // Simple object to hold artifact information
- private static class ArtifactInfo
- {
- private String id;
- private String version;
- private String extension;
- private String remainder;
- private String type;
- private String classifier;
- private String contentType;
- private StorageAsset asset;
- private ArtifactType artifactType = BaseArtifactTypes.MAIN;
- }
-
private ArtifactInfo getArtifactInfoFromPath( final String genericVersion, final StorageAsset path )
{
final ArtifactInfo info = new ArtifactInfo( );
diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java
index e8b6e26e5..3344df005 100644
--- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java
+++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java
@@ -147,26 +147,6 @@ public class ManagedDefaultRepositoryContentTest
"1.0-alpha-11-20070314.211405-9", "1.0-alpha-11-20070316.175232-11" } );
}
- @Test
- public void testToMetadataPathFromProjectReference()
- {
- ProjectReference reference = new ProjectReference();
- reference.setGroupId( "com.foo" );
- reference.setArtifactId( "foo-tool" );
-
- assertEquals( "com/foo/foo-tool/maven-metadata.xml", repoContent.toMetadataPath( reference ) );
- }
-
- @Test
- public void testToMetadataPathFromVersionReference()
- {
- VersionedReference reference = new VersionedReference();
- reference.setGroupId( "com.foo" );
- reference.setArtifactId( "foo-tool" );
- reference.setVersion( "1.0" );
-
- assertEquals( "com/foo/foo-tool/1.0/maven-metadata.xml", repoContent.toMetadataPath( reference ) );
- }
@Test
@Override
diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java
index 881d0d8f0..ab25128ed 100644
--- a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java
+++ b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/api/DefaultFileUploadService.java
@@ -22,28 +22,28 @@ import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import org.apache.archiva.admin.model.RepositoryAdminException;
import org.apache.archiva.admin.model.admin.ArchivaAdministration;
-import org.apache.archiva.admin.model.beans.ManagedRepository;
-import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.checksum.ChecksumAlgorithm;
import org.apache.archiva.checksum.ChecksumUtil;
import org.apache.archiva.checksum.ChecksummedFile;
import org.apache.archiva.common.utils.VersionComparator;
import org.apache.archiva.common.utils.VersionUtil;
+import org.apache.archiva.components.taskqueue.TaskQueueException;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.metadata.model.facets.AuditEvent;
import org.apache.archiva.model.ArchivaRepositoryMetadata;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.model.SnapshotVersion;
-import org.apache.archiva.components.taskqueue.TaskQueueException;
+import org.apache.archiva.repository.ReleaseScheme;
import org.apache.archiva.repository.Repository;
import org.apache.archiva.repository.RepositoryException;
import org.apache.archiva.repository.RepositoryNotFoundException;
import org.apache.archiva.repository.RepositoryRegistry;
import org.apache.archiva.repository.RepositoryType;
-import org.apache.archiva.repository.content.base.ArtifactUtil;
+import org.apache.archiva.repository.content.ItemSelector;
+import org.apache.archiva.repository.content.base.ArchivaItemSelector;
import org.apache.archiva.repository.metadata.MetadataReader;
-import org.apache.archiva.repository.metadata.base.MetadataTools;
import org.apache.archiva.repository.metadata.RepositoryMetadataException;
+import org.apache.archiva.repository.metadata.base.MetadataTools;
import org.apache.archiva.repository.metadata.base.RepositoryMetadataWriter;
import org.apache.archiva.repository.storage.StorageAsset;
import org.apache.archiva.rest.api.services.ArchivaRestServiceException;
@@ -71,12 +71,24 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
-import java.io.*;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
import java.net.URLDecoder;
-import java.nio.file.*;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.TimeZone;
import java.util.concurrent.CopyOnWriteArrayList;
/**
@@ -96,12 +108,6 @@ public class DefaultFileUploadService
private HttpServletRequest httpServletRequest;
@Inject
- private ManagedRepositoryAdmin managedRepositoryAdmin;
-
- @Inject
- private ArtifactUtil artifactUtil;
-
- @Inject
private ArchivaAdministration archivaAdministration;
@Inject
@@ -301,24 +307,18 @@ public class DefaultFileUploadService
return Boolean.FALSE;
}
- try {
- ManagedRepository managedRepository = managedRepositoryAdmin.getManagedRepository(repositoryId);
-
- if (managedRepository == null) {
- // TODO i18n ?
- throw new ArchivaRestServiceException("Cannot find managed repository with id " + repositoryId,
- Response.Status.BAD_REQUEST.getStatusCode(), null);
- }
+ org.apache.archiva.repository.ManagedRepository repository = repositoryRegistry.getManagedRepository(repositoryId);
+ if (repository == null) {
+ // TODO i18n ?
+ throw new ArchivaRestServiceException("Cannot find managed repository with id " + repositoryId,
+ Response.Status.BAD_REQUEST.getStatusCode(), null);
+ }
- if (VersionUtil.isSnapshot(version) && !managedRepository.isSnapshots()) {
- // TODO i18n ?
- throw new ArchivaRestServiceException(
- "Managed repository with id " + repositoryId + " do not accept snapshots",
- Response.Status.BAD_REQUEST.getStatusCode(), null);
- }
- } catch (RepositoryAdminException e) {
- throw new ArchivaRestServiceException(e.getMessage(),
- Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
+ if (VersionUtil.isSnapshot(version) && !repository.getActiveReleaseSchemes().contains( ReleaseScheme.SNAPSHOT )) {
+ // TODO i18n ?
+ throw new ArchivaRestServiceException(
+ "Managed repository with id " + repositoryId + " do not accept snapshots",
+ Response.Status.BAD_REQUEST.getStatusCode(), null);
}
// get from the session file with groupId/artifactId
@@ -366,12 +366,15 @@ public class DefaultFileUploadService
boolean fixChecksums =
!(archivaAdministration.getKnownContentConsumers().contains("create-missing-checksums"));
- org.apache.archiva.repository.ManagedRepository repoConfig = repositoryRegistry.getManagedRepository(repositoryId);
-
- ArtifactReference artifactReference = createArtifactRef(fileMetadata, groupId, artifactId, version);
- artifactReference.setType(packaging);
+ org.apache.archiva.repository.ManagedRepository repository = repositoryRegistry.getManagedRepository(repositoryId);
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( groupId )
+ .withProjectId( artifactId )
+ .withArtifactId( artifactId )
+ .withArtifactVersion( version )
+ .withExtension( packaging ).build();
- StorageAsset pomPath = artifactUtil.getArtifactAsset(repoConfig, artifactReference);
+ StorageAsset pomPath = repository.getContent( ).getItem( selector ).getAsset();
StorageAsset targetPath = pomPath.getParent();
String pomFilename = pomPath.getName();
@@ -381,18 +384,15 @@ public class DefaultFileUploadService
pomFilename = FilenameUtils.removeExtension(pomFilename) + ".pom";
copyFile(Paths.get(fileMetadata.getServerFileName()), targetPath, pomFilename, fixChecksums);
- triggerAuditEvent(repoConfig.getId(), targetPath.resolve(pomFilename).toString(), AuditEvent.UPLOAD_FILE);
- queueRepositoryTask(repoConfig.getId(), targetPath.resolve(pomFilename));
+ triggerAuditEvent(repository.getId(), targetPath.resolve(pomFilename).toString(), AuditEvent.UPLOAD_FILE);
+ queueRepositoryTask(repository.getId(), targetPath.resolve(pomFilename));
log.debug("Finished Saving POM");
} catch (IOException ie) {
log.error("IOException for POM {}", ie.getMessage());
throw new ArchivaRestServiceException("Error encountered while uploading pom file: " + ie.getMessage(),
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ie);
- } catch (RepositoryException rep) {
- log.error("RepositoryException for POM {}", rep.getMessage());
- throw new ArchivaRestServiceException("Repository exception: " + rep.getMessage(),
- Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), rep);
- } catch (RepositoryAdminException e) {
+ }
+ catch (RepositoryAdminException e) {
log.error("RepositoryAdminException for POM {}", e.getMessage());
throw new ArchivaRestServiceException("RepositoryAdmin exception: " + e.getMessage(),
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
@@ -405,13 +405,16 @@ public class DefaultFileUploadService
log.debug("Saving file");
try {
- org.apache.archiva.repository.ManagedRepository repoConfig = repositoryRegistry.getManagedRepository(repositoryId);
+ org.apache.archiva.repository.ManagedRepository repository = repositoryRegistry.getManagedRepository(repositoryId);
- ArtifactReference artifactReference = createArtifactRef(fileMetadata, groupId, artifactId, version);
- artifactReference.setType(
- StringUtils.isEmpty(fileMetadata.getPackaging()) ? packaging : fileMetadata.getPackaging());
+ ItemSelector selector = ArchivaItemSelector.builder( )
+ .withNamespace( groupId )
+ .withProjectId( artifactId )
+ .withArtifactId( artifactId )
+ .withArtifactVersion( version )
+ .withExtension( packaging ).build();
- StorageAsset artifactPath = artifactUtil.getArtifactAsset(repoConfig, artifactReference);
+ StorageAsset artifactPath = repository.getContent( ).getItem( selector ).getAsset();
StorageAsset targetPath = artifactPath.getParent();
log.debug("artifactPath: {} found targetPath: {}", artifactPath, targetPath);
@@ -450,19 +453,19 @@ public class DefaultFileUploadService
try {
StorageAsset targetFile = targetPath.resolve(filename);
- if (targetFile.exists() && !VersionUtil.isSnapshot(version) && repoConfig.blocksRedeployments()) {
+ if (targetFile.exists() && !VersionUtil.isSnapshot(version) && repository.blocksRedeployments()) {
throw new ArchivaRestServiceException(
- "Overwriting released artifacts in repository '" + repoConfig.getId() + "' is not allowed.",
+ "Overwriting released artifacts in repository '" + repository.getId() + "' is not allowed.",
Response.Status.BAD_REQUEST.getStatusCode(), null);
} else {
copyFile(Paths.get(fileMetadata.getServerFileName()), targetPath, filename, fixChecksums);
- triggerAuditEvent(repoConfig.getId(), artifactPath.toString(), AuditEvent.UPLOAD_FILE);
- queueRepositoryTask(repoConfig.getId(), targetFile);
+ triggerAuditEvent(repository.getId(), artifactPath.toString(), AuditEvent.UPLOAD_FILE);
+ queueRepositoryTask(repository.getId(), targetFile);
}
} catch (IOException ie) {
log.error("IOException copying file: {}", ie.getMessage(), ie);
throw new ArchivaRestServiceException(
- "Overwriting released artifacts in repository '" + repoConfig.getId() + "' is not allowed.",
+ "Overwriting released artifacts in repository '" + repository.getId() + "' is not allowed.",
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ie);
}
@@ -476,11 +479,11 @@ public class DefaultFileUploadService
try {
StorageAsset generatedPomFile =
createPom(targetPath, pomFilename, fileMetadata, groupId, artifactId, version, packaging);
- triggerAuditEvent(repoConfig.getId(), targetPath.resolve(pomFilename).toString(), AuditEvent.UPLOAD_FILE);
+ triggerAuditEvent(repository.getId(), targetPath.resolve(pomFilename).toString(), AuditEvent.UPLOAD_FILE);
if (fixChecksums) {
fixChecksums(generatedPomFile);
}
- queueRepositoryTask(repoConfig.getId(), generatedPomFile);
+ queueRepositoryTask(repository.getId(), generatedPomFile);
} catch (IOException ie) {
throw new ArchivaRestServiceException(
"Error encountered while writing pom file: " + ie.getMessage(),
@@ -499,12 +502,8 @@ public class DefaultFileUploadService
packaging);
}
}
- } catch (RepositoryNotFoundException re) {
- log.error("RepositoryNotFoundException during save {}", re.getMessage());
- re.printStackTrace();
- throw new ArchivaRestServiceException("Target repository cannot be found: " + re.getMessage(),
- Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), re);
- } catch (RepositoryException rep) {
+ }
+ catch (RepositoryException rep) {
log.error("RepositoryException during save {}", rep.getMessage());
throw new ArchivaRestServiceException("Repository exception: " + rep.getMessage(),
Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), rep);