1 package org.apache.archiva.repository.maven.content;
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.metadata.model.ArtifactMetadata;
22 import org.apache.archiva.metadata.maven.model.MavenArtifactFacet;
23 import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
24 import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
25 import org.apache.archiva.repository.maven.metadata.storage.DefaultArtifactMappingProvider;
26 import org.apache.archiva.repository.maven.metadata.storage.Maven2RepositoryPathTranslator;
27 import org.apache.archiva.repository.LayoutException;
28 import org.apache.archiva.repository.content.ItemSelector;
29 import org.apache.archiva.repository.content.PathParser;
30 import org.apache.archiva.repository.content.base.ArchivaItemSelector;
31 import org.apache.commons.lang3.StringUtils;
32 import org.springframework.stereotype.Service;
34 import java.util.Collections;
37 * DefaultPathParser is a parser for maven 2 (default layout) paths to ArtifactReference.
39 * TODO: remove in favour of path translator, this is just delegating for the most part, but won't accommodate other
40 * extensions like NPanday
44 @Service( "pathParser#default" )
45 public class DefaultPathParser
48 private static final String INVALID_ARTIFACT_PATH = "Invalid path to Artifact: ";
50 private RepositoryPathTranslator pathTranslator = new Maven2RepositoryPathTranslator(
51 Collections.<ArtifactMappingProvider>singletonList( new DefaultArtifactMappingProvider() ) );
54 public ItemSelector toItemSelector( String path ) throws LayoutException
56 if ( StringUtils.isBlank( path ) )
58 throw new LayoutException( "Unable to convert blank path." );
63 ArtifactMetadata metadata = pathTranslator.getArtifactForPath( null, path );
64 ArchivaItemSelector.Builder builder = ArchivaItemSelector.builder( ).withNamespace( metadata.getNamespace( ) )
65 .withProjectId( metadata.getProject( ) )
66 .withVersion( metadata.getProjectVersion( ) )
67 .withArtifactId( metadata.getProject( ) )
68 .withArtifactVersion( metadata.getVersion( ) );
69 MavenArtifactFacet facet = (MavenArtifactFacet) metadata.getFacet( MavenArtifactFacet.FACET_ID );
72 builder.withClassifier( facet.getClassifier() );
73 builder.withType( facet.getType() );
75 return builder.build( );
77 catch ( IllegalArgumentException e )
79 throw new LayoutException( e.getMessage(), e );