001    package org.apache.maven.repository.internal;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *   http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.maven.model.Repository;
023    import org.sonatype.aether.artifact.Artifact;
024    import org.sonatype.aether.repository.RemoteRepository;
025    import org.sonatype.aether.repository.RepositoryPolicy;
026    import org.sonatype.aether.util.artifact.DefaultArtifact;
027    
028    /**
029     * <strong>Warning:</strong> This is an internal utility class that is only public for technical reasons, it is not part
030     * of the public API. In particular, this class can be changed or deleted without prior notice.
031     * 
032     * @author Benjamin Bentmann
033     */
034    public class ArtifactDescriptorUtils
035    {
036    
037        public static Artifact toPomArtifact( Artifact artifact )
038        {
039            Artifact pomArtifact = artifact;
040    
041            if ( pomArtifact.getClassifier().length() > 0 || !"pom".equals( pomArtifact.getExtension() ) )
042            {
043                pomArtifact =
044                    new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion() );
045            }
046    
047            return pomArtifact;
048        }
049    
050        public static RemoteRepository toRemoteRepository( Repository repository )
051        {
052            RemoteRepository result =
053                new RemoteRepository( repository.getId(), repository.getLayout(), repository.getUrl() );
054            result.setPolicy( true, toRepositoryPolicy( repository.getSnapshots() ) );
055            result.setPolicy( false, toRepositoryPolicy( repository.getReleases() ) );
056            return result;
057        }
058    
059        public static RepositoryPolicy toRepositoryPolicy( org.apache.maven.model.RepositoryPolicy policy )
060        {
061            boolean enabled = true;
062            String checksums = RepositoryPolicy.CHECKSUM_POLICY_WARN;
063            String updates = RepositoryPolicy.UPDATE_POLICY_DAILY;
064    
065            if ( policy != null )
066            {
067                enabled = policy.isEnabled();
068                if ( policy.getUpdatePolicy() != null )
069                {
070                    updates = policy.getUpdatePolicy();
071                }
072                if ( policy.getChecksumPolicy() != null )
073                {
074                    checksums = policy.getChecksumPolicy();
075                }
076            }
077    
078            return new RepositoryPolicy( enabled, updates, checksums );
079        }
080    
081    }