1 package org.apache.archiva.repository.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
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.metadata.model.ArtifactMetadata;
23 import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
24 import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
25 import org.apache.archiva.metadata.repository.storage.maven2.DefaultArtifactMappingProvider;
26 import org.apache.archiva.metadata.repository.storage.maven2.Maven2RepositoryPathTranslator;
27 import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet;
28 import org.apache.commons.lang.StringUtils;
29 import org.apache.archiva.model.ArtifactReference;
30 import org.apache.archiva.repository.layout.LayoutException;
31 import org.springframework.stereotype.Service;
33 import java.util.Collections;
36 * DefaultPathParser is a parser for maven 2 (default layout) paths to ArtifactReference.
38 * TODO: remove in favour of path translator, this is just delegating for the most part, but won't accommodate other
39 * extensions like NPanday
43 @Service( "pathParser#default" )
44 public class DefaultPathParser
47 private static final String INVALID_ARTIFACT_PATH = "Invalid path to Artifact: ";
49 private RepositoryPathTranslator pathTranslator = new Maven2RepositoryPathTranslator(
50 Collections.<ArtifactMappingProvider>singletonList( new DefaultArtifactMappingProvider() ) );
55 * @see org.apache.archiva.repository.content.PathParser#toArtifactReference(java.lang.String)
57 public ArtifactReference toArtifactReference( String path )
58 throws LayoutException
60 if ( StringUtils.isBlank( path ) )
62 throw new LayoutException( "Unable to convert blank path." );
65 ArtifactMetadata metadata;
68 metadata = pathTranslator.getArtifactForPath( null, path );
70 catch ( IllegalArgumentException e )
72 throw new LayoutException( e.getMessage(), e );
75 ArtifactReference artifact = new ArtifactReference();
76 artifact.setGroupId( metadata.getNamespace() );
77 artifact.setArtifactId( metadata.getProject() );
78 artifact.setVersion( metadata.getVersion() );
79 MavenArtifactFacet facet = (MavenArtifactFacet) metadata.getFacet( MavenArtifactFacet.FACET_ID );
82 artifact.setClassifier( facet.getClassifier() );
83 artifact.setType( facet.getType() );