1package org.apache.archiva.repository.content.maven2;
23/*4 * Licensed to the Apache Software Foundation (ASF) under one5 * or more contributor license agreements. See the NOTICE file6 * distributed with this work for additional information7 * regarding copyright ownership. The ASF licenses this file8 * to you under the Apache License, Version 2.0 (the9 * "License"); you may not use this file except in compliance10 * with the License. You may obtain a copy of the License at11 *12 * http://www.apache.org/licenses/LICENSE-2.013 *14 * Unless required by applicable law or agreed to in writing,15 * software distributed under the License is distributed on an16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY17 * KIND, either express or implied. See the License for the18 * specific language governing permissions and limitations19 * under the License.20 */2122import org.apache.archiva.metadata.model.ArtifactMetadata;
23import org.apache.archiva.metadata.model.maven2.MavenArtifactFacet;
24import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
25import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
26import org.apache.archiva.metadata.repository.storage.maven2.DefaultArtifactMappingProvider;
27import org.apache.archiva.metadata.repository.storage.maven2.Maven2RepositoryPathTranslator;
28import org.apache.archiva.model.ArtifactReference;
29import org.apache.archiva.repository.content.PathParser;
30import org.apache.archiva.repository.layout.LayoutException;
31import org.apache.commons.lang.StringUtils;
32import org.springframework.stereotype.Service;
3334import java.util.Collections;
3536/**37 * DefaultPathParser is a parser for maven 2 (default layout) paths to ArtifactReference.38 *39 * TODO: remove in favour of path translator, this is just delegating for the most part, but won't accommodate other40 * extensions like NPanday41 *42 *43 */44 @Service( "pathParser#default" )
45publicclassDefaultPathParser46implementsPathParser47 {
48privatestaticfinal String INVALID_ARTIFACT_PATH = "Invalid path to Artifact: ";
4950privateRepositoryPathTranslator pathTranslator = newMaven2RepositoryPathTranslator(
51 Collections.<ArtifactMappingProvider>singletonList( new DefaultArtifactMappingProvider() ) );
5253/**54 * {@inheritDoc}55 *56 * @see org.apache.archiva.repository.content.PathParser#toArtifactReference(String)57 */58 @Override
59publicArtifactReference toArtifactReference( String path )
60throwsLayoutException61 {
62if ( StringUtils.isBlank( path ) )
63 {
64thrownewLayoutException( "Unable to convert blank path." );
65 }
6667ArtifactMetadata metadata;
68try69 {
70 metadata = pathTranslator.getArtifactForPath( null, path );
71 }
72catch ( IllegalArgumentException e )
73 {
74thrownewLayoutException( e.getMessage(), e );
75 }
7677ArtifactReference artifact = newArtifactReference();
78 artifact.setGroupId( metadata.getNamespace() );
79 artifact.setArtifactId( metadata.getProject() );
80 artifact.setVersion( metadata.getVersion() );
81MavenArtifactFacet facet = (MavenArtifactFacet) metadata.getFacet( MavenArtifactFacet.FACET_ID );
82if ( facet != null )
83 {
84 artifact.setClassifier( facet.getClassifier() );
85 artifact.setType( facet.getType() );
86 }
8788return artifact;
89 }
9091 }