repair snapshot build numbering (previous code makes it get stuck at 1).

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@240405 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-08-27 11:42:30 +00:00
parent 7572427594
commit 0481c45fc9
7 changed files with 45 additions and 138 deletions

View File

@ -63,6 +63,7 @@ public class MavenArchiver
Artifact projectArtifact = project.getArtifact(); Artifact projectArtifact = project.getArtifact();
/* TODO: rethink this, it wasn't working
if ( projectArtifact.isSnapshot() ) if ( projectArtifact.isSnapshot() )
{ {
Manifest.Attribute buildNumberAttr = new Manifest.Attribute( "Build-Number", "" + Manifest.Attribute buildNumberAttr = new Manifest.Attribute( "Build-Number", "" +
@ -70,6 +71,7 @@ public class MavenArchiver
m.addConfiguredAttribute( buildNumberAttr ); m.addConfiguredAttribute( buildNumberAttr );
} }
*/
if ( config.getPackageName() != null ) if ( config.getPackageName() != null )
{ {
Manifest.Attribute packageAttr = new Manifest.Attribute( "Package", config.getPackageName() ); Manifest.Attribute packageAttr = new Manifest.Attribute( "Package", config.getPackageName() );
@ -231,7 +233,7 @@ public class MavenArchiver
if ( workingProject.getArtifact().isSnapshot() ) if ( workingProject.getArtifact().isSnapshot() )
{ {
workingProject.setVersion( workingProject.getSnapshotDeploymentVersion() ); workingProject.setVersion( workingProject.getArtifact().getVersion() );
} }
String groupId = workingProject.getGroupId(); String groupId = workingProject.getGroupId();

View File

@ -45,19 +45,4 @@ public class DefaultArtifactTransformationManager
} }
} }
public String getSnapshotDeploymentTimestamp()
{
return snapshotTransformation.getDeploymentTimestamp();
}
public int getSnapshotDeploymentBuildNumber( Artifact artifact )
{
return snapshotTransformation.getDeploymentBuildNumber( artifact);
}
public String getSnapshotDeploymentVersion( Artifact snapshotArtifact )
{
return snapshotTransformation.getDeploymentVersion( snapshotArtifact );
}
} }

View File

@ -17,7 +17,6 @@ package org.apache.maven.artifact.transform;
*/ */
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.artifact.metadata.AbstractVersionArtifactMetadata; import org.apache.maven.artifact.metadata.AbstractVersionArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.metadata.SnapshotArtifactMetadata; import org.apache.maven.artifact.metadata.SnapshotArtifactMetadata;
@ -26,9 +25,7 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.ResourceDoesNotExistException;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author <a href="mailto:brett@apache.org">Brett Porter</a> * @author <a href="mailto:brett@apache.org">Brett Porter</a>
@ -41,10 +38,6 @@ public class SnapshotTransformation
{ {
private String deploymentTimestamp; private String deploymentTimestamp;
private int deploymentBuildNumber = 1;
private Map buildNumbers = new HashMap();
public void transformForResolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository ) public void transformForResolve( Artifact artifact, List remoteRepositories, ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException throws ArtifactMetadataRetrievalException
{ {
@ -76,20 +69,17 @@ public class SnapshotTransformation
{ {
metadata = (SnapshotArtifactMetadata) retrieveFromRemoteRepository( artifact, remoteRepository, null, metadata = (SnapshotArtifactMetadata) retrieveFromRemoteRepository( artifact, remoteRepository, null,
ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE ); ArtifactRepositoryPolicy.CHECKSUM_POLICY_IGNORE );
updateDeploymentBuildNumber( artifact, metadata.getTimestamp(), metadata.getBuildNumber() );
} }
catch ( ResourceDoesNotExistException e ) catch ( ResourceDoesNotExistException e )
{ {
getLogger().debug( getLogger().debug( "Snapshot version metadata for: " + artifact.getId() +
"Snapshot version metadata for: " + artifact.getId() " not found. Creating a new metadata instance.", e );
+ " not found. Creating a new metadata instance.", e );
// ignore. We'll be creating this metadata if it doesn't exist... // ignore. We'll be creating this metadata if it doesn't exist...
metadata = (SnapshotArtifactMetadata) createMetadata( artifact ); metadata = (SnapshotArtifactMetadata) createMetadata( artifact );
} }
metadata.setVersion( getDeploymentTimestamp(), deploymentBuildNumber ); metadata.setVersion( getDeploymentTimestamp(), metadata.getBuildNumber() + 1 );
artifact.setResolvedVersion( metadata.constructVersion() ); artifact.setResolvedVersion( metadata.constructVersion() );
@ -97,24 +87,6 @@ public class SnapshotTransformation
} }
} }
private void updateDeploymentBuildNumber( Artifact artifact, String timestamp, int buildNumberFromMetadata )
{
// we only have to handle bumping the build number if we're on the same timestamp, somehow...miraculously
if ( deploymentTimestamp.equals( timestamp ) )
{
String artifactKey = ArtifactUtils.versionlessKey( artifact );
Integer buildNum = (Integer) buildNumbers.get( artifactKey );
if ( buildNum == null || buildNum.intValue() <= buildNumberFromMetadata )
{
buildNum = new Integer( buildNumberFromMetadata + 1 );
buildNumbers.put( artifactKey, buildNum );
}
}
}
public String getDeploymentTimestamp() public String getDeploymentTimestamp()
{ {
if ( deploymentTimestamp == null ) if ( deploymentTimestamp == null )
@ -124,35 +96,9 @@ public class SnapshotTransformation
return deploymentTimestamp; return deploymentTimestamp;
} }
public int getDeploymentBuildNumber( Artifact artifact )
{
String artifactKey = ArtifactUtils.versionlessKey( artifact );
Integer buildNum = (Integer) buildNumbers.get( artifactKey );
if ( buildNum == null )
{
buildNum = new Integer( 1 );
buildNumbers.put( artifactKey, buildNum );
}
return buildNum.intValue();
}
protected AbstractVersionArtifactMetadata createMetadata( Artifact artifact ) protected AbstractVersionArtifactMetadata createMetadata( Artifact artifact )
{ {
return new SnapshotArtifactMetadata( artifact ); return new SnapshotArtifactMetadata( artifact );
} }
public String getDeploymentVersion( Artifact artifact )
{
int buildnum = getDeploymentBuildNumber( artifact );
SnapshotArtifactMetadata metadata = (SnapshotArtifactMetadata) createMetadata( artifact );
metadata.setVersion( getDeploymentTimestamp(), buildnum );
return metadata.constructVersion();
}
} }

View File

@ -1,5 +1,21 @@
package org.apache.maven.artifact.repository.metadata; package org.apache.maven.artifact.repository.metadata;
/*
* Copyright 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.io.File; import java.io.File;
public interface RepositoryMetadata public interface RepositoryMetadata

View File

@ -1,5 +1,21 @@
package org.apache.maven.artifact.transform; package org.apache.maven.artifact.transform;
/*
* 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.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepository;
@ -44,19 +60,4 @@ public interface ArtifactTransformationManager
void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository ) void transformForDeployment( Artifact artifact, ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException; throws ArtifactMetadataRetrievalException;
/**
* Return the timestamp which will be used to deploy artifacts from this build.
*/
String getSnapshotDeploymentTimestamp();
/**
* Return the buildnumber which will be used to deploy artifacts from this build.
*/
int getSnapshotDeploymentBuildNumber( Artifact snapshotArtifact );
/**
* Return the artifact-version which will be used to deploy artifacts from this build.
*/
String getSnapshotDeploymentVersion( Artifact snapshotArtifact );
} }

View File

@ -605,15 +605,6 @@ public class DefaultMavenProjectBuilder
project.getVersion(), project.getPackaging() ); project.getVersion(), project.getPackaging() );
project.setArtifact( projectArtifact ); project.setArtifact( projectArtifact );
if ( projectArtifact.isSnapshot() )
{
project.setSnapshotDeploymentVersion(
transformationManager.getSnapshotDeploymentVersion( projectArtifact ) );
project.setSnapshotDeploymentBuildNumber(
transformationManager.getSnapshotDeploymentBuildNumber( projectArtifact ) );
}
project.setPluginArtifactRepositories( ProjectUtils.buildArtifactRepositories( model.getPluginRepositories(), project.setPluginArtifactRepositories( ProjectUtils.buildArtifactRepositories( model.getPluginRepositories(),
artifactRepositoryFactory, artifactRepositoryFactory,
container ) ); container ) );

View File

@ -137,10 +137,6 @@ public class MavenProject
private Build buildOverlay; private Build buildOverlay;
private String snapshotDeploymentVersion;
private int snapshotDeploymentBuildNumber = -1;
public MavenProject( Model model ) public MavenProject( Model model )
{ {
this.model = model; this.model = model;
@ -187,9 +183,6 @@ public class MavenProject
this.originalModel = ModelUtils.cloneModel( project.originalModel ); this.originalModel = ModelUtils.cloneModel( project.originalModel );
} }
this.snapshotDeploymentVersion = project.snapshotDeploymentVersion;
this.snapshotDeploymentBuildNumber = project.snapshotDeploymentBuildNumber;
// TODO: need to clone this too? // TODO: need to clone this too?
this.artifact = project.artifact; this.artifact = project.artifact;
} }
@ -1359,31 +1352,4 @@ public class MavenProject
{ {
} }
public void setSnapshotDeploymentVersion( String deploymentVersion )
{
this.snapshotDeploymentVersion = deploymentVersion;
}
public String getSnapshotDeploymentVersion()
{
if ( snapshotDeploymentVersion == null )
{
return getVersion();
}
else
{
return snapshotDeploymentVersion;
}
}
public void setSnapshotDeploymentBuildNumber( int deploymentBuildNumber )
{
this.snapshotDeploymentBuildNumber = deploymentBuildNumber;
}
public int getSnapshotDeploymentBuildNumber()
{
return snapshotDeploymentBuildNumber;
}
} }