From 086463b5b4aad0ca397d61329358190090add7cd Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Mon, 25 Jul 2005 09:51:12 +0000 Subject: [PATCH] PR: MNG-456 allow separate snapshot and release repositories deprecate existing snapshotPolicy and checksumPolicy in favour of updatePolicy and checksumPolicy within the and elements in the element. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@224707 13f79535-47bb-0310-9956-ffa450edef68 --- .../artifact/ant/AbstractArtifactTask.java | 69 +++++++-- .../apache/maven/artifact/ant/DeployTask.java | 25 +++- .../maven/artifact/ant/RemoteRepository.java | 26 ++++ .../maven/artifact/ant/RepositoryPolicy.java | 65 +++++++++ .../deployer/DefaultArtifactDeployer.java | 4 +- .../artifact/manager/DefaultWagonManager.java | 36 +++-- .../maven/artifact/manager/WagonManager.java | 3 +- .../AbstractVersionArtifactMetadata.java | 7 +- .../metadata/LatestArtifactMetadata.java | 4 +- .../metadata/SnapshotArtifactMetadata.java | 11 +- .../repository/DefaultArtifactRepository.java | 62 +++++--- .../DefaultArtifactRepositoryFactory.java | 55 +++++--- .../AbstractVersionTransformation.java | 100 +++++++------ .../LatestArtifactTransformation.java | 4 +- .../transform/SnapshotTransformation.java | 35 +---- .../artifact/ArtifactComponentTestCase.java | 12 +- .../org/apache/maven/artifact/Artifact.java | 10 ++ .../apache/maven/artifact/ArtifactUtils.java | 46 ++++-- .../maven/artifact/DefaultArtifact.java | 15 ++ .../metadata/AbstractArtifactMetadata.java | 6 +- .../artifact/metadata/ArtifactMetadata.java | 9 +- .../repository/ArtifactRepository.java | 26 +--- .../repository/ArtifactRepositoryFactory.java | 15 +- .../repository/ArtifactRepositoryPolicy.java | 94 +++++++++++++ .../transform/ArtifactTransformation.java | 12 +- .../java/org/apache/maven/cli/MavenCli.java | 10 +- .../version/DefaultPluginVersionManager.java | 2 +- maven-model/maven.mdo | 133 ++++++++++++++---- .../maven/plugin/deploy/DeployMojo.java | 11 +- .../metadata/PluginMappingDeployMojo.java | 7 +- maven-plugins/pom.xml | 18 ++- maven-profile/profiles.mdo | 116 ++++++++++++--- .../profiles/ProfilesConversionUtils.java | 18 +++ .../project/DefaultMavenProjectBuilder.java | 14 +- .../apache/maven/project/MavenProject.java | 38 ++--- .../apache/maven/project/ProjectUtils.java | 69 +++++++-- .../DefaultModelInheritanceAssembler.java | 16 +++ maven-settings/settings.mdo | 115 ++++++++++++--- .../apache/maven/settings/SettingsUtils.java | 47 +++++-- pom.xml | 23 ++- 40 files changed, 1035 insertions(+), 353 deletions(-) create mode 100644 maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/RepositoryPolicy.java create mode 100644 maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryPolicy.java diff --git a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java index 14679ac608..e1b09d2310 100755 --- a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java +++ b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/AbstractArtifactTask.java @@ -21,6 +21,7 @@ import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.model.Model; @@ -34,7 +35,6 @@ import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; -import org.codehaus.classworlds.ClassRealm; import org.codehaus.classworlds.ClassWorld; import org.codehaus.classworlds.DuplicateRealmException; import org.codehaus.plexus.PlexusContainerException; @@ -113,12 +113,15 @@ public abstract class AbstractArtifactTask { repositoryFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); - String snapshotPolicy = repository.getSnapshotPolicy(); - String checksumPolicy = repository.getChecksumPolicy(); + ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy( repository.getSnapshots(), + repository.getSnapshotPolicy(), + repository.getChecksumPolicy() ); + ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy( repository.getReleases(), + repository.getSnapshotPolicy(), + repository.getChecksumPolicy() ); artifactRepository = repositoryFactory.createArtifactRepository( "remote", repository.getUrl(), - repositoryLayout, snapshotPolicy, - checksumPolicy ); + repositoryLayout, snapshots, releases ); } finally { @@ -135,6 +138,29 @@ public abstract class AbstractArtifactTask return artifactRepository; } + private static ArtifactRepositoryPolicy buildArtifactRepositoryPolicy( + RepositoryPolicy policy, String defaultUpdatePolicy, String defaultChecksumPolicy ) + { + boolean enabled = true; + String updatePolicy = defaultUpdatePolicy; + String checksumPolicy = defaultChecksumPolicy; + + if ( policy != null ) + { + enabled = policy.isEnabled(); + if ( policy.getUpdatePolicy() != null ) + { + updatePolicy = policy.getUpdatePolicy(); + } + if ( policy.getChecksumPolicy() != null ) + { + checksumPolicy = policy.getChecksumPolicy(); + } + } + + return new ArtifactRepositoryPolicy( enabled, updatePolicy, checksumPolicy ); + } + protected LocalRepository getDefaultLocalRepository() { Settings settings = getSettings(); @@ -192,14 +218,31 @@ public abstract class AbstractArtifactTask } protected RemoteRepository createAntRemoteRepository( org.apache.maven.model.Repository pomRepository ) + { + RemoteRepository r = createAntRemoteRepositoryBase( pomRepository ); + + r.setSnapshotPolicy( pomRepository.getSnapshotPolicy() ); + + if ( pomRepository.getSnapshots() != null ) + { + r.setSnapshots( convertRepositoryPolicy( pomRepository.getSnapshots() ) ); + } + if ( pomRepository.getReleases() != null ) + { + r.setReleases( convertRepositoryPolicy( pomRepository.getReleases() ) ); + } + + return r; + } + + protected RemoteRepository createAntRemoteRepositoryBase( org.apache.maven.model.RepositoryBase pomRepository ) { // TODO: actually, we need to not funnel this through the ant repository - we should pump settings into wagon // manager at the start like m2 does, and then match up by repository id - // As is, this could potentially cause a problem with 2 remote repositories with different authentication info + // As is, this could potentially cause a problem with 2 remote repositories with different authentication info RemoteRepository r = new RemoteRepository(); r.setUrl( pomRepository.getUrl() ); - r.setSnapshotPolicy( pomRepository.getSnapshotPolicy() ); r.setLayout( pomRepository.getLayout() ); Server server = getSettings().getServer( pomRepository.getId() ); @@ -219,7 +262,6 @@ public abstract class AbstractArtifactTask { r.setUrl( mirror.getUrl() ); } - return r; } @@ -360,6 +402,15 @@ public abstract class AbstractArtifactTask { ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); // TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't - return factory.createBuildArtifact( pom.getGroupId(), pom.getArtifactId(), pom.getVersion(), pom.getPackaging() ); + return factory.createBuildArtifact( pom.getGroupId(), pom.getArtifactId(), pom.getVersion(), + pom.getPackaging() ); + } + + private static RepositoryPolicy convertRepositoryPolicy( org.apache.maven.model.RepositoryPolicy pomRepoPolicy ) + { + RepositoryPolicy policy = new RepositoryPolicy(); + policy.setEnabled( pomRepoPolicy.isEnabled() ); + policy.setUpdatePolicy( pomRepoPolicy.getUpdatePolicy() ); + return policy; } } diff --git a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/DeployTask.java b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/DeployTask.java index a332a9a340..8a42ac9ade 100755 --- a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/DeployTask.java +++ b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/DeployTask.java @@ -17,7 +17,6 @@ package org.apache.maven.artifact.ant; */ import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.deployer.ArtifactDeployer; import org.apache.maven.artifact.deployer.ArtifactDeploymentException; import org.apache.maven.artifact.metadata.ArtifactMetadata; @@ -39,6 +38,8 @@ public class DeployTask { private RemoteRepository remoteRepository; + private RemoteRepository remoteSnapshotRepository; + private File file; public void execute() @@ -60,11 +61,26 @@ public class DeployTask throw new BuildException( "A distributionManagement element is required in your POM to deploy" ); } - remoteRepository = createAntRemoteRepository( pom.getDistributionManagement().getRepository() ); + remoteRepository = createAntRemoteRepositoryBase( pom.getDistributionManagement().getRepository() ); + } + + if ( remoteSnapshotRepository == null ) + { + if ( pom.getDistributionManagement().getSnapshotRepository() != null ) + { + remoteSnapshotRepository = createAntRemoteRepositoryBase( + pom.getDistributionManagement().getSnapshotRepository() ); + } } ArtifactRepository deploymentRepository = createRemoteArtifactRepository( remoteRepository ); + ArtifactRepository snapshotRepository = null; + if ( remoteSnapshotRepository != null ) + { + snapshotRepository = createRemoteArtifactRepository( remoteSnapshotRepository ); + } + // Deploy the POM Artifact artifact = createArtifact( pom ); @@ -100,6 +116,11 @@ public class DeployTask return remoteRepository; } + public void addRemoteSnapshotRepository( RemoteRepository remoteSnapshotRepository ) + { + this.remoteSnapshotRepository = remoteSnapshotRepository; + } + public void addRemoteRepository( RemoteRepository remoteRepository ) { this.remoteRepository = remoteRepository; diff --git a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/RemoteRepository.java b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/RemoteRepository.java index d41f775e84..793f3a2527 100755 --- a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/RemoteRepository.java +++ b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/RemoteRepository.java @@ -29,12 +29,18 @@ public class RemoteRepository private Authentication authentication; + /** @deprecated use <snapshots/> and <updatePolicy> instead. */ private String snapshotPolicy; + /** @deprecated use <snapshots/> and <checksumPolicy> instead. */ private String checksumPolicy; private Proxy proxy; + private RepositoryPolicy snapshots; + + private RepositoryPolicy releases; + public String getUrl() { return ( (RemoteRepository) getInstance() ).url; @@ -84,4 +90,24 @@ public class RemoteRepository { this.checksumPolicy = checksumPolicy; } + + public RepositoryPolicy getSnapshots() + { + return snapshots; + } + + public void setSnapshots( RepositoryPolicy snapshots ) + { + this.snapshots = snapshots; + } + + public RepositoryPolicy getReleases() + { + return releases; + } + + public void setReleases( RepositoryPolicy releases ) + { + this.releases = releases; + } } diff --git a/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/RepositoryPolicy.java b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/RepositoryPolicy.java new file mode 100644 index 0000000000..312b2514e3 --- /dev/null +++ b/maven-artifact-ant/src/main/java/org/apache/maven/artifact/ant/RepositoryPolicy.java @@ -0,0 +1,65 @@ +package org.apache.maven.artifact.ant; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.tools.ant.ProjectComponent; + +/** + * Base class for a repository. + * + * @author Brett Porter + * @version $Id$ + */ +public class RepositoryPolicy + extends ProjectComponent +{ + private String updatePolicy; + + private String checksumPolicy; + + private boolean enabled = true; + + public String getUpdatePolicy() + { + return updatePolicy; + } + + public void setUpdatePolicy( String updatePolicy ) + { + this.updatePolicy = updatePolicy; + } + + public boolean isEnabled() + { + return enabled; + } + + public void setEnabled( boolean enabled ) + { + this.enabled = enabled; + } + + public String getChecksumPolicy() + { + return checksumPolicy; + } + + public void setChecksumPolicy( String checksumPolicy ) + { + this.checksumPolicy = checksumPolicy; + } +} diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java index 63c844f44b..1c11e1ab2c 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java @@ -43,10 +43,8 @@ public class DefaultArtifactDeployer ArtifactRepository localRepository ) throws ArtifactDeploymentException { - File source = null; - String extension = artifact.getArtifactHandler().getExtension(); - source = new File( basedir, finalName + "." + extension ); + File source = new File( basedir, finalName + "." + extension ); deploy( source, artifact, deploymentRepository, localRepository ); } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java index fea4e6104a..0eb8be01eb 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/DefaultWagonManager.java @@ -19,6 +19,7 @@ package org.apache.maven.artifact.manager; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.metadata.ArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; import org.apache.maven.wagon.ConnectionException; @@ -238,16 +239,26 @@ public class DefaultWagonManager { String remotePath = repository.pathOf( artifact ); - getRemoteFile( repository, destination, remotePath, downloadMonitor ); + ArtifactRepositoryPolicy policy = artifact.isSnapshot() ? repository.getSnapshots() : repository.getReleases(); + + if ( policy.isEnabled() ) + { + getRemoteFile( repository, destination, remotePath, downloadMonitor, policy.getUpdatePolicy() ); + } + else + { + getLogger().info( "Skipping disabled repository " + repository.getId() ); + } } - public void getArtifactMetadata( ArtifactMetadata metadata, ArtifactRepository remoteRepository, File destination ) + public void getArtifactMetadata( ArtifactMetadata metadata, ArtifactRepository repository, File destination, + String updatePolicy ) throws TransferFailedException, ResourceDoesNotExistException { - String remotePath = remoteRepository.pathOfMetadata( metadata ); + String remotePath = repository.pathOfMetadata( metadata ); getLogger().info( "Retrieving " + metadata ); - getRemoteFile( remoteRepository, destination, remotePath, null ); + getRemoteFile( repository, destination, remotePath, null, updatePolicy ); } public void getRepositoryMetadata( RepositoryMetadata metadata, ArtifactRepository remoteRepository, @@ -258,11 +269,11 @@ public class DefaultWagonManager getLogger().info( "Retrieving " + metadata ); - getRemoteFile( remoteRepository, destination, remotePath, null ); + getRemoteFile( remoteRepository, destination, remotePath, null, ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN ); } private void getRemoteFile( ArtifactRepository repository, File destination, String remotePath, - TransferListener downloadMonitor ) + TransferListener downloadMonitor, String updatePolicy ) throws TransferFailedException, ResourceDoesNotExistException, ChecksumFailedException { // TODO: better excetpions - transfer failed is not enough? @@ -272,7 +283,8 @@ public class DefaultWagonManager ArtifactRepository mirror = getMirror( repository.getId() ); if ( mirror != null ) { - repository = mirror; + repository = new DefaultArtifactRepository( mirror.getId(), mirror.getUrl(), repository.getLayout(), + repository.getSnapshots(), repository.getReleases() ); } String protocol = repository.getProtocol(); @@ -351,7 +363,7 @@ public class DefaultWagonManager } else { - handleChecksumFailure( repository, e.getMessage(), e.getCause() ); + handleChecksumFailure( updatePolicy, e.getMessage(), e.getCause() ); } } catch ( ResourceDoesNotExistException sha1TryException ) @@ -374,13 +386,13 @@ public class DefaultWagonManager } else { - handleChecksumFailure( repository, e.getMessage(), e.getCause() ); + handleChecksumFailure( updatePolicy, e.getMessage(), e.getCause() ); } } catch ( ResourceDoesNotExistException md5TryException ) { // this was a failed transfer, and we don't want to retry. - handleChecksumFailure( repository, "Error retrieving checksum file for " + remotePath, + handleChecksumFailure( updatePolicy, "Error retrieving checksum file for " + remotePath, md5TryException ); } } @@ -440,10 +452,10 @@ public class DefaultWagonManager } } - private void handleChecksumFailure( ArtifactRepository repository, String message, Throwable cause ) + private void handleChecksumFailure( String updatePolicy, String message, Throwable cause ) throws ChecksumFailedException { - if ( repository.failOnChecksumMismatch() ) + if ( ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL.equals( updatePolicy ) ) { throw new ChecksumFailedException( message, cause ); } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java index 9d3fcb3c9a..37a0e30814 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/manager/WagonManager.java @@ -54,7 +54,8 @@ public interface WagonManager void putArtifactMetadata( File source, ArtifactMetadata artifactMetadata, ArtifactRepository repository ) throws TransferFailedException; - void getArtifactMetadata( ArtifactMetadata metadata, ArtifactRepository remoteRepository, File destination ) + void getArtifactMetadata( ArtifactMetadata metadata, ArtifactRepository remoteRepository, File destination, + String updatePolicy ) throws TransferFailedException, ResourceDoesNotExistException; void putRepositoryMetadata( File source, RepositoryMetadata metadata, ArtifactRepository repository ) diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/metadata/AbstractVersionArtifactMetadata.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/metadata/AbstractVersionArtifactMetadata.java index 27bdc4ec4c..a45d3ccc62 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/metadata/AbstractVersionArtifactMetadata.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/metadata/AbstractVersionArtifactMetadata.java @@ -39,7 +39,7 @@ public abstract class AbstractVersionArtifactMetadata { protected static final String SNAPSHOT_VERSION_FILE = "version.txt"; - protected long lastModified = 0; + protected long lastModified; public AbstractVersionArtifactMetadata( Artifact artifact, String filename ) { @@ -82,7 +82,8 @@ public abstract class AbstractVersionArtifactMetadata } } - public void retrieveFromRemoteRepository( ArtifactRepository remoteRepository, WagonManager wagonManager ) + public void retrieveFromRemoteRepository( ArtifactRepository remoteRepository, WagonManager wagonManager, + String updatePolicy ) throws ArtifactMetadataRetrievalException, ResourceDoesNotExistException { try @@ -91,7 +92,7 @@ public abstract class AbstractVersionArtifactMetadata File destination = File.createTempFile( "maven-artifact", null ); destination.deleteOnExit(); - wagonManager.getArtifactMetadata( this, remoteRepository, destination ); + wagonManager.getArtifactMetadata( this, remoteRepository, destination, updatePolicy ); readFromFile( destination ); } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/metadata/LatestArtifactMetadata.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/metadata/LatestArtifactMetadata.java index c43bca7d04..8f76999bd9 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/metadata/LatestArtifactMetadata.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/metadata/LatestArtifactMetadata.java @@ -13,7 +13,7 @@ public class LatestArtifactMetadata public LatestArtifactMetadata( Artifact artifact ) { - super( artifact, artifact.getArtifactId() + "-" + LatestArtifactTransformation.LATEST_VERSION + "." + SNAPSHOT_VERSION_FILE ); + super( artifact, artifact.getArtifactId() + "-" + Artifact.LATEST_VERSION + "." + SNAPSHOT_VERSION_FILE ); } public String constructVersion() @@ -74,7 +74,7 @@ public class LatestArtifactMetadata public String getBaseVersion() { - return LatestArtifactTransformation.LATEST_VERSION; + return Artifact.LATEST_VERSION; } public boolean storedInArtifactDirectory() diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java index 01041d3989..7189e19a19 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/metadata/SnapshotArtifactMetadata.java @@ -25,7 +25,6 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * Contains the information stored for a snapshot. @@ -36,16 +35,14 @@ import java.util.regex.Pattern; public class SnapshotArtifactMetadata extends AbstractVersionArtifactMetadata { - private String timestamp = null; + private String timestamp; - private int buildNumber = 0; + private int buildNumber; private static final TimeZone UTC_TIME_ZONE = TimeZone.getTimeZone( "UTC" ); private static final String UTC_TIMESTAMP_PATTERN = "yyyyMMdd.HHmmss"; - public static final Pattern VERSION_FILE_PATTERN = Pattern.compile( "^(.*)-([0-9]{8}.[0-9]{6})-([0-9]+)$" ); - // TODO: very quick and nasty hack to get the same timestamp across a build - not embedder friendly private static String sessionTimestamp = null; @@ -74,7 +71,7 @@ public class SnapshotArtifactMetadata protected void setContent( String content ) { - Matcher matcher = VERSION_FILE_PATTERN.matcher( content ); + Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher( content ); if ( matcher.matches() ) { timestamp = matcher.group( 2 ); @@ -159,7 +156,7 @@ public class SnapshotArtifactMetadata if ( timestamp != null ) { String fileTimestamp = getUtcDateFormatter().format( new Date( fileTime ) ); - return ( fileTimestamp.compareTo( timestamp ) < 0 ); + return fileTimestamp.compareTo( timestamp ) < 0; } return false; } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java index bc7abefee0..8f86c93bf0 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepository.java @@ -32,26 +32,43 @@ public class DefaultArtifactRepository extends Repository implements ArtifactRepository { - private final String snapshotPolicy; - - private final String checksumPolicy; - private final ArtifactRepositoryLayout layout; + private ArtifactRepositoryPolicy snapshots; + + private ArtifactRepositoryPolicy releases; + + /** + * Create a local repository or a deployment repository. + * + * @param id the unique identifier of the repository + * @param url the URL of the repository + * @param layout the layout of the repository + */ public DefaultArtifactRepository( String id, String url, ArtifactRepositoryLayout layout ) { - this( id, url, layout, SNAPSHOT_POLICY_NEVER, CHECKSUM_POLICY_WARN ); + this( id, url, layout, null, null ); } - public DefaultArtifactRepository( String id, String url, ArtifactRepositoryLayout layout, String snapshotPolicy, String checksumPolicy ) + /** + * Create a remote download repository. + * + * @param id the unique identifier of the repository + * @param url the URL of the repository + * @param layout the layout of the repository + * @param snapshots the policies to use for snapshots + * @param releases the policies to use for releases + */ + public DefaultArtifactRepository( String id, String url, ArtifactRepositoryLayout layout, + ArtifactRepositoryPolicy snapshots, ArtifactRepositoryPolicy releases ) { super( id, url ); this.layout = layout; - this.snapshotPolicy = snapshotPolicy; - - this.checksumPolicy = checksumPolicy; + this.snapshots = snapshots; + + this.releases = releases; } public String pathOf( Artifact artifact ) @@ -63,7 +80,7 @@ public class DefaultArtifactRepository { return layout.pathOfMetadata( artifactMetadata ); } - + public String formatAsDirectory( String directory ) { return layout.formatAsDirectory( directory ); @@ -74,19 +91,18 @@ public class DefaultArtifactRepository return layout.formatAsFile( file ); } - public String getSnapshotPolicy() + public ArtifactRepositoryLayout getLayout() { - return snapshotPolicy; - } - - public String getChecksumPolicy() - { - return checksumPolicy; - } - - public boolean failOnChecksumMismatch() - { - return CHECKSUM_POLICY_FAIL.equals( checksumPolicy ); + return layout; } -} \ No newline at end of file + public ArtifactRepositoryPolicy getSnapshots() + { + return snapshots; + } + + public ArtifactRepositoryPolicy getReleases() + { + return releases; + } +} diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java index 02d255aed9..bfe8bd0544 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/repository/DefaultArtifactRepositoryFactory.java @@ -25,52 +25,67 @@ public class DefaultArtifactRepositoryFactory implements ArtifactRepositoryFactory { // TODO: use settings? - private String globalSnapshotPolicy = null; + private String globalUpdatePolicy; - private String globalChecksumPolicy = null; + private String globalChecksumPolicy; + + private boolean globalEnable = true; + + public ArtifactRepository createArtifactRepository( String id, String url, + ArtifactRepositoryLayout repositoryLayout ) + { + return new DefaultArtifactRepository( id, url, repositoryLayout ); + } public ArtifactRepository createArtifactRepository( String id, String url, ArtifactRepositoryLayout repositoryLayout, - String snapshotPolicy, String checksumPolicy ) + ArtifactRepositoryPolicy snapshots, + ArtifactRepositoryPolicy releases ) { - ArtifactRepository repo = null; - - String snapPolicy = snapshotPolicy; - - if ( globalSnapshotPolicy != null ) + if ( snapshots == null ) { - snapPolicy = globalSnapshotPolicy; + snapshots = new ArtifactRepositoryPolicy(); } - if ( snapPolicy == null ) + if ( releases == null ) { - snapPolicy = ArtifactRepository.SNAPSHOT_POLICY_NEVER; + releases = new ArtifactRepositoryPolicy(); } - String csumPolicy = checksumPolicy; + if ( globalUpdatePolicy != null ) + { + snapshots.setUpdatePolicy( globalUpdatePolicy ); + releases.setUpdatePolicy( globalUpdatePolicy ); + } if ( globalChecksumPolicy != null ) { - csumPolicy = globalChecksumPolicy; + snapshots.setChecksumPolicy( globalChecksumPolicy ); + releases.setChecksumPolicy( globalChecksumPolicy ); } - if ( csumPolicy == null ) + // TODO: needed, or can offline cover it? + if ( !globalEnable ) { - csumPolicy = ArtifactRepository.CHECKSUM_POLICY_WARN; + snapshots.setEnabled( false ); + releases.setEnabled( false ); } - repo = new DefaultArtifactRepository( id, url, repositoryLayout, snapPolicy, csumPolicy ); - - return repo; + return new DefaultArtifactRepository( id, url, repositoryLayout, snapshots, releases ); } - public void setGlobalSnapshotPolicy( String snapshotPolicy ) + public void setGlobalUpdatePolicy( String updatePolicy ) { - this.globalSnapshotPolicy = snapshotPolicy; + this.globalUpdatePolicy = updatePolicy; } public void setGlobalChecksumPolicy( String checksumPolicy ) { this.globalChecksumPolicy = checksumPolicy; } + + public void setGlobalEnable( boolean enable ) + { + this.globalEnable = enable; + } } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java index 682c64221f..3142e73529 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/AbstractVersionTransformation.java @@ -22,6 +22,7 @@ import org.apache.maven.artifact.metadata.AbstractVersionArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.VersionArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.wagon.ResourceDoesNotExistException; import org.codehaus.plexus.logging.AbstractLogEnabled; @@ -69,62 +70,74 @@ public abstract class AbstractVersionTransformation boolean checkedUpdates = false; for ( Iterator i = remoteRepositories.iterator(); i.hasNext(); ) { - ArtifactRepository remoteRepository = (ArtifactRepository) i.next(); + ArtifactRepository repository = (ArtifactRepository) i.next(); - String snapshotPolicy = remoteRepository.getSnapshotPolicy(); - // TODO: should be able to calculate this less often - boolean checkForUpdates = false; - if ( ArtifactRepository.SNAPSHOT_POLICY_ALWAYS.equals( snapshotPolicy ) ) + ArtifactRepositoryPolicy policy = artifact.isSnapshot() ? repository.getSnapshots() + : repository.getReleases(); + + if ( !policy.isEnabled() ) { - checkForUpdates = true; + getLogger().info( "Skipping disabled repository " + repository.getId() ); } - else if ( ArtifactRepository.SNAPSHOT_POLICY_DAILY.equals( snapshotPolicy ) ) + else { - if ( !localMetadata.checkedSinceDate( getMidnightBoundary() ) ) + String updatePolicy = policy.getUpdatePolicy(); + // TODO: should be able to calculate this less often + boolean checkForUpdates = false; + if ( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS.equals( updatePolicy ) ) { checkForUpdates = true; } - } - else if ( snapshotPolicy.startsWith( ArtifactRepository.SNAPSHOT_POLICY_INTERVAL ) ) - { - String s = snapshotPolicy.substring( ArtifactRepository.SNAPSHOT_POLICY_INTERVAL.length() + 1 ); - int minutes = Integer.valueOf( s ).intValue(); - Calendar cal = Calendar.getInstance(); - cal.add( Calendar.MINUTE, -minutes ); - if ( !localMetadata.checkedSinceDate( cal.getTime() ) ) + else if ( ArtifactRepositoryPolicy.UPDATE_POLICY_DAILY.equals( updatePolicy ) ) { - checkForUpdates = true; + if ( !localMetadata.checkedSinceDate( getMidnightBoundary() ) ) + { + checkForUpdates = true; + } } - } - // else assume "never" - - if ( checkForUpdates ) - { - getLogger().info( - artifact.getArtifactId() + ": checking for updates from " + remoteRepository.getId() ); - - VersionArtifactMetadata remoteMetadata; - - checkedUpdates = true; - - try + else if ( updatePolicy.startsWith( ArtifactRepositoryPolicy.UPDATE_POLICY_INTERVAL ) ) { - remoteMetadata = retrieveFromRemoteRepository( artifact, remoteRepository, localMetadata ); + String s = updatePolicy.substring( + ArtifactRepositoryPolicy.UPDATE_POLICY_INTERVAL.length() + 1 ); + int minutes = Integer.valueOf( s ).intValue(); + Calendar cal = Calendar.getInstance(); + cal.add( Calendar.MINUTE, -minutes ); + if ( !localMetadata.checkedSinceDate( cal.getTime() ) ) + { + checkForUpdates = true; + } } - catch ( ResourceDoesNotExistException e ) + // else assume "never" + + if ( checkForUpdates ) { - getLogger().debug( "Error resolving artifact version from metadata.", e ); + getLogger().info( + artifact.getArtifactId() + ": checking for updates from " + repository.getId() ); - continue; - } + VersionArtifactMetadata remoteMetadata; - int difference = remoteMetadata.compareTo( localMetadata ); - if ( difference > 0 ) - { - // remote is newer - artifact.setRepository( remoteRepository ); + checkedUpdates = true; - localMetadata = remoteMetadata; + try + { + remoteMetadata = retrieveFromRemoteRepository( artifact, repository, localMetadata, + updatePolicy ); + } + catch ( ResourceDoesNotExistException e ) + { + getLogger().debug( "Error resolving artifact version from metadata.", e ); + + continue; + } + + int difference = remoteMetadata.compareTo( localMetadata ); + if ( difference > 0 ) + { + // remote is newer + artifact.setRepository( repository ); + + localMetadata = remoteMetadata; + } } } } @@ -174,12 +187,13 @@ public abstract class AbstractVersionTransformation protected VersionArtifactMetadata retrieveFromRemoteRepository( Artifact artifact, ArtifactRepository remoteRepository, - VersionArtifactMetadata localMetadata ) + VersionArtifactMetadata localMetadata, + String updatePolicy ) throws ArtifactMetadataRetrievalException, ResourceDoesNotExistException { AbstractVersionArtifactMetadata metadata = createMetadata( artifact ); - metadata.retrieveFromRemoteRepository( remoteRepository, wagonManager ); + metadata.retrieveFromRemoteRepository( remoteRepository, wagonManager, updatePolicy ); return metadata; } diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/LatestArtifactTransformation.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/LatestArtifactTransformation.java index 92696f9be2..89315c078b 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/LatestArtifactTransformation.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/LatestArtifactTransformation.java @@ -27,12 +27,10 @@ import java.util.List; public class LatestArtifactTransformation extends AbstractVersionTransformation { - public static final String LATEST_VERSION = "LATEST"; - public void transformForResolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) throws ArtifactMetadataRetrievalException { - if ( LATEST_VERSION.equals( artifact.getVersion() ) ) + if ( Artifact.LATEST_VERSION.equals( artifact.getVersion() ) ) { String version = resolveVersion( artifact, localRepository, remoteRepositories ); if ( version != null && !version.equals( artifact.getVersion() ) ) diff --git a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java index c371712969..da2fc206a9 100644 --- a/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java +++ b/maven-artifact-manager/src/main/java/org/apache/maven/artifact/transform/SnapshotTransformation.java @@ -21,10 +21,10 @@ import org.apache.maven.artifact.metadata.AbstractVersionArtifactMetadata; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.SnapshotArtifactMetadata; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.wagon.ResourceDoesNotExistException; import java.util.List; -import java.util.regex.Matcher; /** * @author Brett Porter @@ -35,18 +35,10 @@ import java.util.regex.Matcher; public class SnapshotTransformation extends AbstractVersionTransformation { - public static final String SNAPSHOT_VERSION = "SNAPSHOT"; - public void transformForResolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) throws ArtifactMetadataRetrievalException { - Matcher m = SnapshotArtifactMetadata.VERSION_FILE_PATTERN.matcher( artifact.getBaseVersion() ); - if ( m.matches() ) - { - // This corrects the base version, but ensure it is not resolved again - artifact.setBaseVersion( m.group( 1 ) + "-" + SNAPSHOT_VERSION ); - } - else if ( isSnapshot( artifact ) ) + if ( artifact.isSnapshot() ) { String version = resolveVersion( artifact, localRepository, remoteRepositories ); artifact.updateVersion( version, localRepository ); @@ -56,12 +48,7 @@ public class SnapshotTransformation public void transformForInstall( Artifact artifact, ArtifactRepository localRepository ) throws ArtifactMetadataRetrievalException { - Matcher m = SnapshotArtifactMetadata.VERSION_FILE_PATTERN.matcher( artifact.getBaseVersion() ); - if ( m.matches() ) - { - artifact.setBaseVersion( m.group( 1 ) + "-" + SNAPSHOT_VERSION ); - } - else if ( isSnapshot( artifact ) ) + if ( artifact.isSnapshot() ) { SnapshotArtifactMetadata metadata = new SnapshotArtifactMetadata( artifact ); metadata.storeInLocalRepository( localRepository ); @@ -71,19 +58,14 @@ public class SnapshotTransformation public void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository ) throws ArtifactMetadataRetrievalException { - Matcher m = SnapshotArtifactMetadata.VERSION_FILE_PATTERN.matcher( artifact.getBaseVersion() ); - if ( m.matches() ) - { - // This corrects the base version, but ensure it is not updated again - artifact.setBaseVersion( m.group( 1 ) + "-" + SNAPSHOT_VERSION ); - } - else if ( isSnapshot( artifact ) ) + if ( artifact.isSnapshot() ) { SnapshotArtifactMetadata metadata; try { - metadata = (SnapshotArtifactMetadata) retrieveFromRemoteRepository( artifact, remoteRepository, null ); + metadata = (SnapshotArtifactMetadata) retrieveFromRemoteRepository( artifact, remoteRepository, null, + ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); } catch ( ResourceDoesNotExistException e ) { @@ -99,11 +81,6 @@ public class SnapshotTransformation } } - private static boolean isSnapshot( Artifact artifact ) - { - return artifact.getVersion().endsWith( SNAPSHOT_VERSION ); - } - protected AbstractVersionArtifactMetadata createMetadata( Artifact artifact ) { return new SnapshotArtifactMetadata( artifact ); diff --git a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/ArtifactComponentTestCase.java b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/ArtifactComponentTestCase.java index 78738529c4..a1a15d1857 100644 --- a/maven-artifact-manager/src/test/java/org/apache/maven/artifact/ArtifactComponentTestCase.java +++ b/maven-artifact-manager/src/test/java/org/apache/maven/artifact/ArtifactComponentTestCase.java @@ -18,6 +18,7 @@ package org.apache.maven.artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.codehaus.plexus.PlexusTestCase; @@ -56,7 +57,7 @@ public abstract class ArtifactComponentTestCase ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); - return (ArtifactRepository) new DefaultArtifactRepository( "test", "file://" + f.getPath(), repoLayout ); + return new DefaultArtifactRepository( "test", "file://" + f.getPath(), repoLayout ); } protected String getRepositoryLayout() @@ -74,7 +75,7 @@ public abstract class ArtifactComponentTestCase ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); - return (ArtifactRepository) new DefaultArtifactRepository( "local", "file://" + f.getPath(), repoLayout ); + return new DefaultArtifactRepository( "local", "file://" + f.getPath(), repoLayout ); } protected ArtifactRepository remoteRepository() @@ -87,9 +88,8 @@ public abstract class ArtifactComponentTestCase ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); - return (ArtifactRepository) new DefaultArtifactRepository( "test", "file://" + f.getPath(), repoLayout, - ArtifactRepository.SNAPSHOT_POLICY_NEVER, - ArtifactRepository.CHECKSUM_POLICY_WARN ); + return new DefaultArtifactRepository( "test", "file://" + f.getPath(), repoLayout, + new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy() ); } protected ArtifactRepository badRemoteRepository() @@ -98,7 +98,7 @@ public abstract class ArtifactComponentTestCase ArtifactRepositoryLayout repoLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" ); - return (ArtifactRepository) new DefaultArtifactRepository( "test", "http://foo.bar/repository", repoLayout ); + return new DefaultArtifactRepository( "test", "http://foo.bar/repository", repoLayout ); } protected void assertRemoteArtifactPresent( Artifact artifact ) diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java b/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java index 1f55c57c18..c39f78c36f 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/Artifact.java @@ -24,6 +24,8 @@ import org.apache.maven.artifact.versioning.VersionRange; import java.io.File; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Description of an artifact. @@ -33,6 +35,12 @@ import java.util.List; public interface Artifact extends Comparable { + String LATEST_VERSION = "LATEST"; + + String SNAPSHOT_VERSION = "SNAPSHOT"; + + Pattern VERSION_FILE_PATTERN = Pattern.compile( "^(.*)-([0-9]{8}.[0-9]{6})-([0-9]+)$" ); + // TODO: into scope handler String SCOPE_COMPILE = "compile"; @@ -118,4 +126,6 @@ public interface Artifact void setGroupId( String groupId ); void setArtifactId( String artifactId ); + + boolean isSnapshot(); } \ No newline at end of file diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java b/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java index 7bc472d7a8..0792c1f48f 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/ArtifactUtils.java @@ -1,5 +1,21 @@ package org.apache.maven.artifact; +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + import java.util.Collection; import java.util.HashMap; import java.util.Iterator; @@ -7,11 +23,11 @@ import java.util.Map; public final class ArtifactUtils { - + private ArtifactUtils() { } - + public static String versionlessKey( Artifact artifact ) { return versionlessKey( artifact.getGroupId(), artifact.getArtifactId() ); @@ -21,42 +37,44 @@ public final class ArtifactUtils { return groupId + ":" + artifactId; } - + public static String artifactId( String groupId, String artifactId, String type, String version ) { - return artifactId( groupId, artifactId, type, version, null, version ); + return artifactId( groupId, artifactId, type, null, version ); } - - public static String artifactId( String groupId, String artifactId, String type, String version, String classifier, String baseVersion ) + + public static String artifactId( String groupId, String artifactId, String type, String classifier, + String baseVersion ) { - return groupId + ":" + artifactId + ":" + type + ( ( classifier != null ) ? ( ":" + classifier ) : ( "" ) ) + ":" + baseVersion; + return groupId + ":" + artifactId + ":" + type + ( classifier != null ? ":" + classifier : "" ) + ":" + + baseVersion; } - + public static Map artifactMapByVersionlessId( Collection artifacts ) { Map artifactMap = new HashMap(); - + for ( Iterator it = artifacts.iterator(); it.hasNext(); ) { Artifact artifact = (Artifact) it.next(); - + artifactMap.put( versionlessKey( artifact ), artifact ); } - + return artifactMap; } public static Map artifactMapByArtifactId( Collection artifacts ) { Map artifactMap = new HashMap(); - + for ( Iterator it = artifacts.iterator(); it.hasNext(); ) { Artifact artifact = (Artifact) it.next(); - + artifactMap.put( artifact.getId(), artifact ); } - + return artifactMap; } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java b/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java index c47727f895..609ea27118 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/DefaultArtifact.java @@ -27,6 +27,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.regex.Matcher; /** * @author Jason van Zyl @@ -420,4 +421,18 @@ public class DefaultArtifact { this.artifactId = artifactId; } + + public boolean isSnapshot() + { + Matcher m = VERSION_FILE_PATTERN.matcher( getBaseVersion() ); + if ( m.matches() ) + { + setBaseVersion( m.group( 1 ) + "-" + SNAPSHOT_VERSION ); + return true; + } + else + { + return getVersion().endsWith( SNAPSHOT_VERSION ) || getVersion().equals( LATEST_VERSION ); + } + } } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java index 63e7ee48c6..4ccd80598d 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/AbstractArtifactMetadata.java @@ -37,11 +37,6 @@ public abstract class AbstractArtifactMetadata this.filename = filename; } - public void setArtifact( Artifact artifact ) - { - this.artifact = artifact; - } - public String getFilename() { return filename; @@ -71,4 +66,5 @@ public abstract class AbstractArtifactMetadata { return artifact.getBaseVersion(); } + } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java index 87639998cb..50617d9f74 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/metadata/ArtifactMetadata.java @@ -45,14 +45,6 @@ public interface ArtifactMetadata */ String getFilename(); - /** - * Set the associated artifact. - * - * @param artifact the artifact - * @todo prefer not to have this, and just modify the artifacts as they are transformed - */ - void setArtifact( Artifact artifact ); - /** * Whether the artifact metadata exists. * @return true or false @@ -71,4 +63,5 @@ public interface ArtifactMetadata String getVersion(); String getBaseVersion(); + } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java index 66d5b8aeca..6814953c91 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepository.java @@ -17,31 +17,17 @@ package org.apache.maven.artifact.repository; */ import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.metadata.ArtifactMetadata; /** - * TODO: describe + * Specifies the repository used for artifact handling. * * @author Brett Porter * @version $Id$ */ public interface ArtifactRepository { - String SNAPSHOT_POLICY_NEVER = "never"; - - String SNAPSHOT_POLICY_ALWAYS = "always"; - - String SNAPSHOT_POLICY_DAILY = "daily"; - - String SNAPSHOT_POLICY_INTERVAL = "interval"; - - String CHECKSUM_POLICY_FAIL = "fail"; - - String CHECKSUM_POLICY_WARN = "warn"; - - String CHECKSUM_ALGORITHM_SHA1 = "SHA-1"; - - String CHECKSUM_ALGORITHM_MD5 = "MD5"; String pathOf( Artifact artifact ); @@ -55,13 +41,13 @@ public interface ArtifactRepository String getBasedir(); - String getSnapshotPolicy(); - String getProtocol(); String getId(); - String getChecksumPolicy(); + ArtifactRepositoryPolicy getSnapshots(); - boolean failOnChecksumMismatch(); + ArtifactRepositoryPolicy getReleases(); + + ArtifactRepositoryLayout getLayout(); } diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java index 6a77890cbd..33b65476a3 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryFactory.java @@ -23,14 +23,17 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; */ public interface ArtifactRepositoryFactory { + String ROLE = ArtifactRepositoryFactory.class.getName(); - public static final String ROLE = ArtifactRepositoryFactory.class.getName(); + ArtifactRepository createArtifactRepository( String id, String url, ArtifactRepositoryLayout repositoryLayout ); - public ArtifactRepository createArtifactRepository( String id, String url, - ArtifactRepositoryLayout repositoryLayout, - String snapshotPolicy, String checksumPolicy ); + ArtifactRepository createArtifactRepository( String id, String url, ArtifactRepositoryLayout repositoryLayout, + ArtifactRepositoryPolicy snapshots, + ArtifactRepositoryPolicy releases ); + + void setGlobalUpdatePolicy( String snapshotPolicy ); - void setGlobalSnapshotPolicy( String snapshotPolicy ); - void setGlobalChecksumPolicy( String checksumPolicy ); + + void setGlobalEnable( boolean enable ); } \ No newline at end of file diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryPolicy.java b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryPolicy.java new file mode 100644 index 0000000000..aaf8904fc5 --- /dev/null +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/repository/ArtifactRepositoryPolicy.java @@ -0,0 +1,94 @@ +package org.apache.maven.artifact.repository;/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Describes a set of policies for a repository to use under certain conditions. + * + * @author Brett Porter + * @version $Id$ + */ +public class ArtifactRepositoryPolicy +{ + public static final String UPDATE_POLICY_NEVER = "never"; + + public static final String UPDATE_POLICY_ALWAYS = "always"; + + public static final String UPDATE_POLICY_DAILY = "daily"; + + public static final String UPDATE_POLICY_INTERVAL = "interval"; + + public static final String CHECKSUM_POLICY_FAIL = "fail"; + + public static final String CHECKSUM_POLICY_WARN = "warn"; + + private boolean enabled; + + private String updatePolicy; + + private String checksumPolicy; + + public ArtifactRepositoryPolicy() + { + this( true, null, null ); + } + + public ArtifactRepositoryPolicy( boolean enabled, String updatePolicy, String checksumPolicy ) + { + this.enabled = enabled; + + if ( updatePolicy == null ) + { + updatePolicy = UPDATE_POLICY_DAILY; + } + this.updatePolicy = updatePolicy; + + if ( checksumPolicy == null ) + { + checksumPolicy = CHECKSUM_POLICY_WARN; + } + this.checksumPolicy = checksumPolicy; + } + + public void setEnabled( boolean enabled ) + { + this.enabled = enabled; + } + + public void setUpdatePolicy( String updatePolicy ) + { + this.updatePolicy = updatePolicy; + } + + public void setChecksumPolicy( String checksumPolicy ) + { + this.checksumPolicy = checksumPolicy; + } + + public boolean isEnabled() + { + return enabled; + } + + public String getUpdatePolicy() + { + return updatePolicy; + } + + public String getChecksumPolicy() + { + return checksumPolicy; + } +} diff --git a/maven-artifact/src/main/java/org/apache/maven/artifact/transform/ArtifactTransformation.java b/maven-artifact/src/main/java/org/apache/maven/artifact/transform/ArtifactTransformation.java index 6c7181b79d..54e8d53f61 100644 --- a/maven-artifact/src/main/java/org/apache/maven/artifact/transform/ArtifactTransformation.java +++ b/maven-artifact/src/main/java/org/apache/maven/artifact/transform/ArtifactTransformation.java @@ -29,24 +29,24 @@ import java.util.List; */ public interface ArtifactTransformation { - static String ROLE = ArtifactTransformation.class.getName(); + String ROLE = ArtifactTransformation.class.getName(); /** * Take in a artifact and return the transformed artifact for locating in the remote repository. If no * transformation has occured the original artifact is returned. * - * @param artifact Artifact to be transformed. + * @param artifact Artifact to be transformed. * @param remoteRepositories the repositories to check - * @param localRepository the local repository + * @param localRepository the local repository */ - public void transformForResolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) + void transformForResolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) throws ArtifactMetadataRetrievalException; /** * Take in a artifact and return the transformed artifact for locating in the local repository. If no * transformation has occured the original artifact is returned. * - * @param artifact Artifact to be transformed. + * @param artifact Artifact to be transformed. * @param localRepository the local repository it will be stored in */ void transformForInstall( Artifact artifact, ArtifactRepository localRepository ) @@ -56,7 +56,7 @@ public interface ArtifactTransformation * Take in a artifact and return the transformed artifact for distributing toa remote repository. If no * transformation has occured the original artifact is returned. * - * @param artifact Artifact to be transformed. + * @param artifact Artifact to be transformed. * @param remoteRepository the repository to deploy to */ void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository ) diff --git a/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java index 1dac5969b5..f7134f5c0c 100644 --- a/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-core/src/main/java/org/apache/maven/cli/MavenCli.java @@ -28,6 +28,7 @@ import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.DefaultArtifactRepository; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.execution.DefaultMavenExecutionRequest; import org.apache.maven.execution.MavenExecutionRequest; @@ -401,27 +402,26 @@ public class MavenCli { settings.setOffline( true ); - // TODO: this will still check to download if the artifact does not exist locally, instead of failing as it should in offline mode - artifactRepositoryFactory.setGlobalSnapshotPolicy( ArtifactRepository.SNAPSHOT_POLICY_NEVER ); + artifactRepositoryFactory.setGlobalEnable( false ); snapshotPolicySet = true; } if ( !snapshotPolicySet && commandLine.hasOption( CLIManager.UPDATE_SNAPSHOTS ) ) { - artifactRepositoryFactory.setGlobalSnapshotPolicy( ArtifactRepository.SNAPSHOT_POLICY_ALWAYS ); + artifactRepositoryFactory.setGlobalUpdatePolicy( ArtifactRepositoryPolicy.UPDATE_POLICY_ALWAYS ); } if ( commandLine.hasOption( CLIManager.CHECKSUM_FAILURE_POLICY ) ) { System.out.println( "+ Enabling strict checksum verification on all artifact downloads." ); - artifactRepositoryFactory.setGlobalChecksumPolicy( ArtifactRepository.CHECKSUM_POLICY_FAIL ); + artifactRepositoryFactory.setGlobalChecksumPolicy( ArtifactRepositoryPolicy.CHECKSUM_POLICY_FAIL ); } else if ( commandLine.hasOption( CLIManager.CHECKSUM_WARNING_POLICY ) ) { System.out.println( "+ Disabling strict checksum verification on all artifact downloads." ); - artifactRepositoryFactory.setGlobalChecksumPolicy( ArtifactRepository.CHECKSUM_POLICY_WARN ); + artifactRepositoryFactory.setGlobalChecksumPolicy( ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN ); } return localRepository; diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java index 83e19c7142..3efd38a36f 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java @@ -158,7 +158,7 @@ public class DefaultPluginVersionManager { // 1. resolve the version to be used version = resolveMetaVersion( groupId, artifactId, project.getPluginArtifactRepositories(), localRepository, - LatestArtifactTransformation.LATEST_VERSION ); + Artifact.LATEST_VERSION ); if ( version != null ) { diff --git a/maven-model/maven.mdo b/maven-model/maven.mdo index 036086e27a..86eb269ebf 100644 --- a/maven-model/maven.mdo +++ b/maven-model/maven.mdo @@ -28,10 +28,8 @@

This is a reference for the Maven project descriptor used in Maven.

An XSD is available at:

]]> @@ -1411,11 +1409,21 @@ repository 4.0.0 - Repository + RepositoryBase + + + + snapshotRepository + 4.0.0 + + Where to deploy snapshots of artifacts to. If not given, it defaults to the repository. + + + RepositoryBase @@ -1974,7 +1982,7 @@ - Repository + RepositoryBase 4.0.0 String - - snapshotPolicy - 4.0.0 - - The policy for downloading snapshots - can be "always", "daily" (default), "interval:XXX" (in minutes) or - "never". - - String - daily - layout 4.0.0 @@ -2023,14 +2021,6 @@ String default - - checksumPolicy - 4.0.0 - What to do when verification of an artifact checksum fails - warn, fail, etc. Valid values are - "fail" or "warn" - String - warn - @@ -2038,7 +2028,7 @@ + + + Repository + RepositoryBase + 4.0.0 + + Repository contains the information needed for establishing connections with remote repoistory + + + + + snapshotPolicy + 4.0.0 + + The policy for downloading snapshots - can be "always", "daily" (default), "interval:XXX" (in minutes) or + "never" (repository is not checked, even if the snapshot is not present locally). + + String + + + + checksumPolicy + 4.0.0 + What to do when verification of an artifact checksum fails - warn, fail, etc. Valid values are + "fail" or "warn" + String + + + releases + 4.0.0 + How to handle downloading of releases from this repository + + RepositoryPolicy + + + + snapshots + 4.0.0 + How to handle downloading of snapshots from this repository + + RepositoryPolicy + + + + + + + 4.0.0 + + + + + + + RepositoryPolicy + 4.0.0 + Download policy + + + enabled + 4.0.0 + Whether to use this repository for downloading this type of artifact + boolean + true + + + updatePolicy + 4.0.0 + + The frequency for downloading updates - can be "always", "daily" (default), "interval:XXX" (in minutes) or + "never" (only if it doesn't exist locally). + + String + + + checksumPolicy + 4.0.0 + What to do when verification of an artifact checksum fails - warn, fail, etc. Valid values are + "fail" or "warn" + String + + + + Site @@ -2390,7 +2469,7 @@ activation 4.0.0 - Activation diff --git a/maven-plugins/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java b/maven-plugins/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java index b41ee67f4a..d96e24cc30 100644 --- a/maven-plugins/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java +++ b/maven-plugins/maven-deploy-plugin/src/main/java/org/apache/maven/plugin/deploy/DeployMojo.java @@ -32,6 +32,7 @@ import java.util.List; /** * Deploys an artifact to remote repository. + * * @author Emmanuel Venisse * @author John Casey (refactoring only) * @version $Id$ @@ -105,17 +106,17 @@ public class DeployMojo private List attachedArtifacts; /** - * @parameter expression="${updateReleaseInfo}" + * @parameter expression="${updateReleaseInfo}" default-value="false" */ - private boolean updateReleaseInfo = false; + private boolean updateReleaseInfo; public void execute() throws MojoExecutionException { if ( deploymentRepository == null ) { - String msg = "Deployment failed: repository element was not specified in the pom inside" - + " distributionManagement element"; + String msg = "Deployment failed: repository element was not specified in the pom inside" + + " distributionManagement element"; throw new MojoExecutionException( msg ); } @@ -151,7 +152,7 @@ public class DeployMojo Artifact attached = (Artifact) i.next(); deployer.deploy( attached.getFile(), attached, deploymentRepository, localRepository ); } - } + } catch ( ArtifactDeploymentException e ) { // TODO: deployment exception that does not give a trace diff --git a/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/PluginMappingDeployMojo.java b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/PluginMappingDeployMojo.java index 2b605bbdd2..a096e172cb 100644 --- a/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/PluginMappingDeployMojo.java +++ b/maven-plugins/maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/metadata/PluginMappingDeployMojo.java @@ -34,12 +34,13 @@ public class PluginMappingDeployMojo throws MojoExecutionException { RepositoryMetadata metadata = new PluginMappingMetadata( getProject().getGroupId() ); - + ArtifactRepository distributionRepository = getProject().getDistributionManagementArtifactRepository(); - + if ( distributionRepository == null ) { - throw new MojoExecutionException( "No distribution repository specified. You must specify a section with a valid specified within." ); + throw new MojoExecutionException( + "No distribution repository specified. You must specify a section with a valid specified within." ); } try diff --git a/maven-plugins/pom.xml b/maven-plugins/pom.xml index 60ccd73318..d03a188690 100644 --- a/maven-plugins/pom.xml +++ b/maven-plugins/pom.xml @@ -71,6 +71,11 @@ http://www.apache.org/ + + central-plugins-snapshots + Maven Central Plugins Development Repository + scp://repo1.maven.org/home/projects/maven/repository-staging/snapshots/maven2/plugins + central-plugins Maven Central Plugins Repository @@ -83,11 +88,18 @@ - central-plugins - Maven Central Plugins Repository - http://repo1.maven.org/maven2/plugins + snapshots + Maven Central Development Repository + http://snapshots.maven.codehaus.org/maven2 + + + snapshots + Maven Central Plugins Development Repository + http://snapshots.maven.codehaus.org/maven2/plugins + + maven-ant-plugin maven-assembly-plugin diff --git a/maven-profile/profiles.mdo b/maven-profile/profiles.mdo index a855085155..2c0e117a4e 100644 --- a/maven-profile/profiles.mdo +++ b/maven-profile/profiles.mdo @@ -132,8 +132,10 @@ + + - Repository + RepositoryBase 1.0.0 String - - snapshotPolicy - 1.0.0 - The policy for downloading snapshots - can be "always", - "daily" (default), "interval:XXX" (in minutes) or "never". - - String - daily - layout 1.0.0 - The type of layout this repository uses for locating and - storing artifacts - can be "legacy" or "default". + The type of layout this repository uses for locating and storing artifacts - can be "legacy" or + "default". String default - - checksumPolicy - 1.0.0 - What to do when verification of an artifact checksum fails - warn, fail, etc. Valid values are - "fail" or "warn" - String - warn - @@ -196,7 +181,7 @@ + + + Repository + RepositoryBase + 1.0.0 + + Repository contains the information needed for establishing connections with remote repoistory + + + + + snapshotPolicy + 1.0.0 + + The policy for downloading snapshots - can be "always", "daily" (default), "interval:XXX" (in minutes) or + "never" (repository is not checked, even if the snapshot is not present locally). + + String + + + + checksumPolicy + 1.0.0 + What to do when verification of an artifact checksum fails - warn, fail, etc. Valid values are + "fail" or "warn" + String + + + releases + 1.0.0 + How to handle downloading of releases from this repository + + RepositoryPolicy + + + + snapshots + 1.0.0 + How to handle downloading of snapshots from this repository + + RepositoryPolicy + + + + + + + 1.0.0 + + + + + + + RepositoryPolicy + 1.0.0 + Download policy + + + enabled + 1.0.0 + Whether to use this repository for downloading this type of artifact + boolean + true + + + updatePolicy + 1.0.0 + + The frequency for downloading updates - can be "always", "daily" (default), "interval:XXX" (in minutes) or + "never" (only if it doesn't exist locally). + + String + + + checksumPolicy + 1.0.0 + What to do when verification of an artifact checksum fails - warn, fail, etc. Valid values are + "fail" or "warn" + String + + + + ActivationProperty 1.0.0 diff --git a/maven-profile/src/main/java/org/apache/maven/profiles/ProfilesConversionUtils.java b/maven-profile/src/main/java/org/apache/maven/profiles/ProfilesConversionUtils.java index 58a170d525..cd044849fa 100644 --- a/maven-profile/src/main/java/org/apache/maven/profiles/ProfilesConversionUtils.java +++ b/maven-profile/src/main/java/org/apache/maven/profiles/ProfilesConversionUtils.java @@ -102,7 +102,25 @@ public class ProfilesConversionUtils repo.setChecksumPolicy( profileXmlRepo.getChecksumPolicy() ); repo.setUrl( profileXmlRepo.getUrl() ); + if ( profileXmlRepo.getSnapshots() != null ) + { + repo.setSnapshots( convertRepositoryPolicy( profileXmlRepo.getSnapshots() ) ); + } + if ( profileXmlRepo.getReleases() != null ) + { + repo.setReleases( convertRepositoryPolicy( profileXmlRepo.getReleases() ) ); + } + return repo; } + private static org.apache.maven.model.RepositoryPolicy convertRepositoryPolicy( RepositoryPolicy profileXmlRepo ) + { + org.apache.maven.model.RepositoryPolicy policy = new org.apache.maven.model.RepositoryPolicy(); + policy.setEnabled( profileXmlRepo.isEnabled() ); + policy.setUpdatePolicy( profileXmlRepo.getUpdatePolicy() ); + policy.setChecksumPolicy( profileXmlRepo.getChecksumPolicy() ); + return policy; + } + } diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 5668ae6db9..b224968c11 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -308,6 +308,7 @@ public class DefaultMavenProjectBuilder { Model superModel = getSuperModel(); + //noinspection CollectionDeclaredAsConcreteClass LinkedList lineage = new LinkedList(); Set aggregatedRemoteWagonRepositories = new HashSet(); @@ -434,8 +435,16 @@ public class DefaultMavenProjectBuilder DistributionManagement dm = model.getDistributionManagement(); if ( dm != null ) { - project.setDistributionManagementArtifactRepository( - ProjectUtils.buildArtifactRepository( dm.getRepository(), artifactRepositoryFactory, container ) ); + ArtifactRepository repo = ProjectUtils.buildArtifactRepositoryBase( dm.getRepository(), + artifactRepositoryFactory, container ); + project.setReleaseArtifactRepository( repo ); + + if ( dm.getSnapshotRepository() != null ) + { + repo = ProjectUtils.buildArtifactRepositoryBase( dm.getSnapshotRepository(), artifactRepositoryFactory, + container ); + project.setSnapshotArtifactRepository( repo ); + } } project.setParent( parentProject ); @@ -464,6 +473,7 @@ public class DefaultMavenProjectBuilder return project; } + /** @noinspection CollectionDeclaredAsConcreteClass*/ private MavenProject assembleLineage( Model model, LinkedList lineage, List aggregatedRemoteWagonRepositories, ArtifactRepository localRepository ) throws ProjectBuildingException diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java index 01cfbbdd6e..aa5800aa69 100644 --- a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java @@ -100,7 +100,9 @@ public class MavenProject private List pluginArtifactRepositories; - private ArtifactRepository distMgmtArtifactRepository; + private ArtifactRepository releaseArtifactRepository; + + private ArtifactRepository snapshotArtifactRepository; private List activeProfiles = new ArrayList(); @@ -833,14 +835,14 @@ public class MavenProject { return pluginArtifacts; } - + public Map getPluginArtifactMap() { if ( pluginArtifactMap == null ) { pluginArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getPluginArtifacts() ); } - + return pluginArtifactMap; } @@ -848,7 +850,7 @@ public class MavenProject { this.reportArtifacts = reportArtifacts; } - + public Set getReportArtifacts() { return reportArtifacts; @@ -860,7 +862,7 @@ public class MavenProject { reportArtifactMap = ArtifactUtils.artifactMapByVersionlessId( getReportArtifacts() ); } - + return reportArtifactMap; } @@ -957,14 +959,9 @@ public class MavenProject return pluginArtifactRepositories; } - public void setDistributionManagementArtifactRepository( ArtifactRepository distMgmtArtifactRepository ) - { - this.distMgmtArtifactRepository = distMgmtArtifactRepository; - } - public ArtifactRepository getDistributionManagementArtifactRepository() { - return distMgmtArtifactRepository; + return getArtifact().isSnapshot() ? snapshotArtifactRepository : releaseArtifactRepository; } public List getPluginRepositories() @@ -1151,12 +1148,22 @@ public class MavenProject { this.dependencyArtifacts = dependencyArtifacts; } - + + public void setReleaseArtifactRepository( ArtifactRepository releaseArtifactRepository ) + { + this.releaseArtifactRepository = releaseArtifactRepository; + } + + public void setSnapshotArtifactRepository( ArtifactRepository snapshotArtifactRepository ) + { + this.snapshotArtifactRepository = snapshotArtifactRepository; + } + public void setOriginalModel( Model originalModel ) { this.originalModel = originalModel; } - + public Model getOriginalModel() { return originalModel; @@ -1175,14 +1182,13 @@ public class MavenProject else { MavenProject otherProject = (MavenProject) other; - + return getId().equals( otherProject.getId() ); } } - + public int hashCode() { return getId().hashCode(); } - } diff --git a/maven-project/src/main/java/org/apache/maven/project/ProjectUtils.java b/maven-project/src/main/java/org/apache/maven/project/ProjectUtils.java index 21dc9c3474..eea56596fa 100644 --- a/maven-project/src/main/java/org/apache/maven/project/ProjectUtils.java +++ b/maven-project/src/main/java/org/apache/maven/project/ProjectUtils.java @@ -18,8 +18,11 @@ package org.apache.maven.project; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; +import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.model.Repository; +import org.apache.maven.model.RepositoryBase; +import org.apache.maven.model.RepositoryPolicy; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; @@ -56,6 +59,27 @@ public final class ProjectUtils return repos; } + public static ArtifactRepository buildArtifactRepositoryBase( RepositoryBase repo, + ArtifactRepositoryFactory artifactRepositoryFactory, + PlexusContainer container ) + throws ProjectBuildingException + { + if ( repo != null ) + { + String id = repo.getId(); + String url = repo.getUrl(); + + // TODO: make this a map inside the factory instead, so no lookup needed + ArtifactRepositoryLayout layout = getRepositoryLayout( repo, container ); + + return artifactRepositoryFactory.createArtifactRepository( id, url, layout ); + } + else + { + return null; + } + } + public static ArtifactRepository buildArtifactRepository( Repository repo, ArtifactRepositoryFactory artifactRepositoryFactory, PlexusContainer container ) @@ -65,14 +89,18 @@ public final class ProjectUtils { String id = repo.getId(); String url = repo.getUrl(); - String snapshotPolicy = repo.getSnapshotPolicy(); - String checksumPolicy = repo.getChecksumPolicy(); // TODO: make this a map inside the factory instead, so no lookup needed ArtifactRepositoryLayout layout = getRepositoryLayout( repo, container ); - return artifactRepositoryFactory.createArtifactRepository( id, url, layout, snapshotPolicy, - checksumPolicy ); + ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy( repo.getSnapshots(), + repo.getSnapshotPolicy(), + repo.getChecksumPolicy() ); + ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy( repo.getReleases(), + repo.getSnapshotPolicy(), + repo.getChecksumPolicy() ); + + return artifactRepositoryFactory.createArtifactRepository( id, url, layout, snapshots, releases ); } else { @@ -80,21 +108,44 @@ public final class ProjectUtils } } - private static ArtifactRepositoryLayout getRepositoryLayout( Repository mavenRepo, PlexusContainer container ) + private static ArtifactRepositoryPolicy buildArtifactRepositoryPolicy( RepositoryPolicy policy, + String defaultUpdatePolicy, + String defaultChecksumPolicy ) + { + boolean enabled = true; + String updatePolicy = defaultUpdatePolicy; + String checksumPolicy = defaultChecksumPolicy; + + if ( policy != null ) + { + enabled = policy.isEnabled(); + if ( policy.getUpdatePolicy() != null ) + { + updatePolicy = policy.getUpdatePolicy(); + } + if ( policy.getChecksumPolicy() != null ) + { + checksumPolicy = policy.getChecksumPolicy(); + } + } + + return new ArtifactRepositoryPolicy( enabled, updatePolicy, checksumPolicy ); + } + + private static ArtifactRepositoryLayout getRepositoryLayout( RepositoryBase mavenRepo, PlexusContainer container ) throws ProjectBuildingException { String layout = mavenRepo.getLayout(); - ArtifactRepositoryLayout repositoryLayout = null; + ArtifactRepositoryLayout repositoryLayout; try { repositoryLayout = (ArtifactRepositoryLayout) container.lookup( ArtifactRepositoryLayout.ROLE, layout ); } catch ( ComponentLookupException e ) { - throw new ProjectBuildingException( - "Cannot find layout implementation corresponding to: \'" + layout + - "\' for remote repository with id: \'" + mavenRepo.getId() + "\'.", e ); + throw new ProjectBuildingException( "Cannot find layout implementation corresponding to: \'" + layout + + "\' for remote repository with id: \'" + mavenRepo.getId() + "\'.", e ); } return repositoryLayout; } diff --git a/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java b/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java index 06aca89237..9ef9d4f1f9 100644 --- a/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java +++ b/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java @@ -581,6 +581,22 @@ public class DefaultModelInheritanceAssembler repository.setUrl( parentDistMgmt.getRepository().getUrl() ); } } + + if ( childDistMgmt.getSnapshotRepository() == null ) + { + if ( parentDistMgmt.getSnapshotRepository() != null ) + { + Repository repository = new Repository(); + + childDistMgmt.setSnapshotRepository( repository ); + + repository.setId( parentDistMgmt.getSnapshotRepository().getId() ); + + repository.setName( parentDistMgmt.getSnapshotRepository().getName() ); + + repository.setUrl( parentDistMgmt.getSnapshotRepository().getUrl() ); + } + } } } diff --git a/maven-settings/settings.mdo b/maven-settings/settings.mdo index 0a9b875907..f48142d747 100644 --- a/maven-settings/settings.mdo +++ b/maven-settings/settings.mdo @@ -579,8 +579,10 @@ + + - Repository + RepositoryBase 1.0.0 String - - snapshotPolicy - 1.0.0 - The policy for downloading snapshots - can be "always", - "daily" (default), "interval:XXX" (in minutes) or "never". - - String - daily - layout 1.0.0 - The type of layout this repository uses for locating and - storing artifacts - can be "legacy" or "default". + The type of layout this repository uses for locating and storing artifacts - can be "legacy" or + "default". String default - - checksumPolicy - 1.0.0 - What to do when verification of an artifact checksum fails - warn, fail, etc. Valid values are "fail" or "warn" - String - warn - @@ -642,7 +628,7 @@ + + + Repository + RepositoryBase + 1.0.0 + + Repository contains the information needed for establishing connections with remote repoistory + + + + + snapshotPolicy + 1.0.0 + + The policy for downloading snapshots - can be "always", "daily" (default), "interval:XXX" (in minutes) or + "never" (repository is not checked, even if the snapshot is not present locally). + + String + + + + checksumPolicy + 1.0.0 + What to do when verification of an artifact checksum fails - warn, fail, etc. Valid values are + "fail" or "warn" + String + + + releases + 1.0.0 + How to handle downloading of releases from this repository + + RepositoryPolicy + + + + snapshots + 1.0.0 + How to handle downloading of snapshots from this repository + + RepositoryPolicy + + + + + + + 1.0.0 + + + + + + + RepositoryPolicy + 1.0.0 + Download policy + + + enabled + 1.0.0 + Whether to use this repository for downloading this type of artifact + boolean + true + + + updatePolicy + 1.0.0 + + The frequency for downloading updates - can be "always", "daily" (default), "interval:XXX" (in minutes) or + "never" (only if it doesn't exist locally). + + String + + + checksumPolicy + 1.0.0 + What to do when verification of an artifact checksum fails - warn, fail, etc. Valid values are + "fail" or "warn" + String + + + + ActivationProperty 1.0.0 diff --git a/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java b/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java index f0ef7d2455..efacc98fe7 100644 --- a/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java +++ b/maven-settings/src/main/java/org/apache/maven/settings/SettingsUtils.java @@ -1,13 +1,5 @@ package org.apache.maven.settings; -import org.codehaus.plexus.util.StringUtils; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - /* * Copyright 2001-2005 The Apache Software Foundation. * @@ -24,9 +16,16 @@ import java.util.Map; * limitations under the License. */ +import org.codehaus.plexus.util.StringUtils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + public final class SettingsUtils { - private SettingsUtils() { // don't allow construction. @@ -51,7 +50,7 @@ public final class SettingsUtils dominantActiveProfiles = new ArrayList(); dominant.setActiveProfiles( dominantActiveProfiles ); } - + for ( Iterator it = recessiveActiveProfiles.iterator(); it.hasNext(); ) { String profileId = (String) it.next(); @@ -68,14 +67,14 @@ public final class SettingsUtils List dominantPluginGroupIds = dominant.getPluginGroups(); List recessivePluginGroupIds = recessive.getPluginGroups(); - if( recessivePluginGroupIds != null ) + if ( recessivePluginGroupIds != null ) { - if( dominantPluginGroupIds == null ) + if ( dominantPluginGroupIds == null ) { dominantPluginGroupIds = new ArrayList(); dominant.setPluginGroups( dominantPluginGroupIds ); } - + for ( Iterator it = recessivePluginGroupIds.iterator(); it.hasNext(); ) { String pluginGroupId = (String) it.next(); @@ -142,7 +141,7 @@ public final class SettingsUtils profile.setSource( "settings.xml" ); - org.apache.maven.settings.Activation settingsActivation = settingsProfile.getActivation(); + Activation settingsActivation = settingsProfile.getActivation(); if ( settingsActivation != null ) { @@ -150,7 +149,7 @@ public final class SettingsUtils activation.setJdk( settingsActivation.getJdk() ); - org.apache.maven.settings.ActivationProperty settingsProp = settingsActivation.getProperty(); + ActivationProperty settingsProp = settingsActivation.getProperty(); if ( settingsProp != null ) { @@ -197,7 +196,25 @@ public final class SettingsUtils repo.setChecksumPolicy( settingsRepo.getChecksumPolicy() ); repo.setUrl( settingsRepo.getUrl() ); + if ( settingsRepo.getSnapshots() != null ) + { + repo.setSnapshots( convertRepositoryPolicy( settingsRepo.getSnapshots() ) ); + } + if ( settingsRepo.getReleases() != null ) + { + repo.setReleases( convertRepositoryPolicy( settingsRepo.getReleases() ) ); + } + return repo; } + private static org.apache.maven.model.RepositoryPolicy convertRepositoryPolicy( RepositoryPolicy settingsPolicy ) + { + org.apache.maven.model.RepositoryPolicy policy = new org.apache.maven.model.RepositoryPolicy(); + policy.setEnabled( settingsPolicy.isEnabled() ); + policy.setUpdatePolicy( settingsPolicy.getUpdatePolicy() ); + policy.setChecksumPolicy( settingsPolicy.getChecksumPolicy() ); + return policy; + } + } diff --git a/pom.xml b/pom.xml index 50598ebb15..9841ae1dda 100644 --- a/pom.xml +++ b/pom.xml @@ -105,17 +105,32 @@ repo1 Maven Central Repository - scp://repo1.maven.org/home/projects/maven/repository-staging/to-ibiblio/maven2 + + snapshots + Maven Central Development Repository + scp://repo1.maven.org/home/projects/maven/repository-staging/snapshots/maven2 + website scp://minotaur.apache.org/www/maven.apache.org/maven2/ + + + snapshots + Maven Central Development Repository + http://snapshots.maven.codehaus.org/maven2 + + + + + snapshots + Maven Central Plugins Development Repository + http://snapshots.maven.codehaus.org/maven2/plugins + + maven-archiver