1 package org.apache.archiva.repository.content.maven2;
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.model.maven2.MavenArtifactFacet;
24 import org.apache.archiva.metadata.repository.storage.RepositoryPathTranslator;
25 import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
26 import org.apache.archiva.metadata.repository.storage.maven2.DefaultArtifactMappingProvider;
27 import org.apache.archiva.metadata.repository.storage.maven2.Maven2RepositoryPathTranslator;
28 import org.apache.archiva.model.ArtifactReference;
29 import org.apache.archiva.repository.LayoutException;
30 import org.apache.archiva.repository.content.PathParser;
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() ) );
56 * @see org.apache.archiva.repository.content.PathParser#toArtifactReference(String)
59 public ArtifactReference toArtifactReference( String path )
60 throws LayoutException
62 if ( StringUtils.isBlank( path ) )
64 throw new LayoutException( "Unable to convert blank path." );
67 ArtifactMetadata metadata;
70 metadata = pathTranslator.getArtifactForPath( null, path );
72 catch ( IllegalArgumentException e )
74 throw new LayoutException( e.getMessage(), e );
77 ArtifactReference artifact = new ArtifactReference();
78 artifact.setGroupId( metadata.getNamespace() );
79 artifact.setArtifactId( metadata.getProject() );
80 artifact.setVersion( metadata.getVersion() );
81 MavenArtifactFacet facet = (MavenArtifactFacet) metadata.getFacet( MavenArtifactFacet.FACET_ID );
84 artifact.setClassifier( facet.getClassifier() );
85 artifact.setType( facet.getType() );