mirror of https://github.com/apache/maven.git
[MNG-2408] Modification to keep metadata files from writing when the main version is LATEST or RELEASE (these are meta-versions).
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@439352 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5d99b35cfe
commit
b92af0e49f
|
@ -54,5 +54,9 @@
|
|||
<groupId>org.apache.maven.wagon</groupId>
|
||||
<artifactId>wagon-provider-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -113,6 +113,14 @@ public abstract class AbstractRepositoryMetadata
|
|||
{
|
||||
changed = metadata.merge( this.metadata );
|
||||
}
|
||||
|
||||
// beware meta-versions!
|
||||
String version = metadata.getVersion();
|
||||
if ( version != null && ( Artifact.LATEST_VERSION.equals( version ) || Artifact.RELEASE_VERSION.equals( version ) ) )
|
||||
{
|
||||
// meta-versions are not valid <version/> values...don't write them.
|
||||
changed = false;
|
||||
}
|
||||
|
||||
if ( changed )
|
||||
{
|
||||
|
|
|
@ -0,0 +1,158 @@
|
|||
package org.apache.maven.artifact.repository.metadata;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.artifact.testutils.MockManager;
|
||||
import org.apache.maven.artifact.testutils.TestFileManager;
|
||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class AbstractRepositoryMetadataTest
|
||||
extends TestCase
|
||||
{
|
||||
|
||||
private MockManager mm = new MockManager();
|
||||
private TestFileManager fileManager = new TestFileManager( "AbstractRepositoryMetadataTest.test.", "" );
|
||||
|
||||
public void tearDown() throws IOException
|
||||
{
|
||||
fileManager.cleanUp();
|
||||
}
|
||||
|
||||
public void testUpdateRepositoryMetadata_ShouldNotStoreIfMainVersionIsLATEST()
|
||||
throws IOException, XmlPullParserException
|
||||
{
|
||||
MockAndControlForArtifactRepository local = new MockAndControlForArtifactRepository();
|
||||
MockAndControlForArtifactRepository remote = new MockAndControlForArtifactRepository();
|
||||
|
||||
File basedir = fileManager.createTempDir();
|
||||
|
||||
String path = "metadata.xml";
|
||||
|
||||
Metadata m = new Metadata();
|
||||
m.setVersion( Artifact.LATEST_VERSION );
|
||||
|
||||
TestRepoMetadata trm = new TestRepoMetadata( m );
|
||||
|
||||
local.expectGetBasedir( basedir );
|
||||
local.expectPathOfLocalRepositoryMetadata( trm, remote.repository, path );
|
||||
|
||||
mm.replayAll();
|
||||
|
||||
trm.updateRepositoryMetadata( local.repository, remote.repository );
|
||||
|
||||
fileManager.assertFileExistence( basedir, path, false );
|
||||
|
||||
mm.verifyAll();
|
||||
}
|
||||
|
||||
public void testUpdateRepositoryMetadata_ShouldNotStoreIfMainVersionIsRELEASE()
|
||||
throws IOException, XmlPullParserException
|
||||
{
|
||||
MockAndControlForArtifactRepository local = new MockAndControlForArtifactRepository();
|
||||
MockAndControlForArtifactRepository remote = new MockAndControlForArtifactRepository();
|
||||
|
||||
File basedir = fileManager.createTempDir();
|
||||
|
||||
String path = "metadata.xml";
|
||||
|
||||
Metadata m = new Metadata();
|
||||
m.setVersion( Artifact.RELEASE_VERSION );
|
||||
|
||||
TestRepoMetadata trm = new TestRepoMetadata( m );
|
||||
|
||||
local.expectGetBasedir( basedir );
|
||||
local.expectPathOfLocalRepositoryMetadata( trm, remote.repository, path );
|
||||
|
||||
mm.replayAll();
|
||||
|
||||
trm.updateRepositoryMetadata( local.repository, remote.repository );
|
||||
|
||||
fileManager.assertFileExistence( basedir, path, false );
|
||||
|
||||
mm.verifyAll();
|
||||
}
|
||||
|
||||
private final class MockAndControlForArtifactRepository
|
||||
{
|
||||
MockControl control;
|
||||
|
||||
ArtifactRepository repository;
|
||||
|
||||
public MockAndControlForArtifactRepository()
|
||||
{
|
||||
control = MockControl.createControl( ArtifactRepository.class );
|
||||
mm.add( control );
|
||||
|
||||
repository = ( ArtifactRepository ) control.getMock();
|
||||
}
|
||||
|
||||
public void expectPathOfLocalRepositoryMetadata( TestRepoMetadata trm, ArtifactRepository remote, String path )
|
||||
{
|
||||
repository.pathOfLocalRepositoryMetadata( trm, remote );
|
||||
control.setReturnValue( path, MockControl.ONE_OR_MORE );
|
||||
}
|
||||
|
||||
public void expectGetBasedir( File basedir )
|
||||
{
|
||||
repository.getBasedir();
|
||||
control.setReturnValue( basedir.getAbsolutePath(), MockControl.ONE_OR_MORE );
|
||||
}
|
||||
}
|
||||
|
||||
private static final class TestRepoMetadata
|
||||
extends AbstractRepositoryMetadata
|
||||
{
|
||||
|
||||
protected TestRepoMetadata( Metadata metadata )
|
||||
{
|
||||
super( metadata );
|
||||
}
|
||||
|
||||
public boolean isSnapshot()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setRepository( ArtifactRepository remoteRepository )
|
||||
{
|
||||
}
|
||||
|
||||
public String getArtifactId()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getBaseVersion()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getGroupId()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object getKey()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean storedInArtifactVersionDirectory()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean storedInGroupDirectory()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package org.apache.maven.artifact.testutils;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class MockManager
|
||||
{
|
||||
|
||||
private List mockControls = new ArrayList();
|
||||
|
||||
public void add( MockControl control )
|
||||
{
|
||||
mockControls.add( control );
|
||||
}
|
||||
|
||||
public void replayAll()
|
||||
{
|
||||
for ( Iterator it = mockControls.iterator(); it.hasNext(); )
|
||||
{
|
||||
MockControl control = ( MockControl ) it.next();
|
||||
|
||||
control.replay();
|
||||
}
|
||||
}
|
||||
|
||||
public void verifyAll()
|
||||
{
|
||||
for ( Iterator it = mockControls.iterator(); it.hasNext(); )
|
||||
{
|
||||
MockControl control = ( MockControl ) it.next();
|
||||
|
||||
control.verify();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,231 @@
|
|||
package org.apache.maven.artifact.testutils;
|
||||
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
import org.codehaus.plexus.util.IOUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class TestFileManager
|
||||
{
|
||||
|
||||
public static final String TEMP_DIR_PATH = System.getProperty( "java.io.tmpdir" );
|
||||
|
||||
private List filesToDelete = new ArrayList();
|
||||
|
||||
private final String baseFilename;
|
||||
|
||||
private final String fileSuffix;
|
||||
|
||||
private StackTraceElement callerInfo;
|
||||
|
||||
private Thread cleanupWarning;
|
||||
|
||||
private boolean warnAboutCleanup = false;
|
||||
|
||||
public TestFileManager( String baseFilename, String fileSuffix )
|
||||
{
|
||||
this.baseFilename = baseFilename;
|
||||
this.fileSuffix = fileSuffix;
|
||||
|
||||
initializeCleanupMonitoring();
|
||||
}
|
||||
|
||||
private void initializeCleanupMonitoring()
|
||||
{
|
||||
callerInfo = new NullPointerException().getStackTrace()[2];
|
||||
|
||||
Runnable warning = new Runnable()
|
||||
{
|
||||
|
||||
public void run()
|
||||
{
|
||||
maybeWarnAboutCleanUp();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
cleanupWarning = new Thread( warning );
|
||||
|
||||
Runtime.getRuntime().addShutdownHook( cleanupWarning );
|
||||
}
|
||||
|
||||
private void maybeWarnAboutCleanUp()
|
||||
{
|
||||
if ( warnAboutCleanup )
|
||||
{
|
||||
System.out.println( "[WARNING] TestFileManager from: " + callerInfo.getClassName() + " not cleaned up!" );
|
||||
}
|
||||
}
|
||||
|
||||
public void markForDeletion( File toDelete )
|
||||
{
|
||||
filesToDelete.add( toDelete );
|
||||
warnAboutCleanup = true;
|
||||
}
|
||||
|
||||
public synchronized File createTempDir()
|
||||
{
|
||||
try
|
||||
{
|
||||
Thread.sleep( 20 );
|
||||
}
|
||||
catch ( InterruptedException e )
|
||||
{
|
||||
}
|
||||
|
||||
File dir = new File( TEMP_DIR_PATH, baseFilename + System.currentTimeMillis() );
|
||||
|
||||
dir.mkdirs();
|
||||
markForDeletion( dir );
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
public synchronized File createTempFile()
|
||||
throws IOException
|
||||
{
|
||||
File tempFile = File.createTempFile( baseFilename, fileSuffix );
|
||||
tempFile.deleteOnExit();
|
||||
markForDeletion( tempFile );
|
||||
|
||||
return tempFile;
|
||||
}
|
||||
|
||||
public void cleanUp()
|
||||
throws IOException
|
||||
{
|
||||
for ( Iterator it = filesToDelete.iterator(); it.hasNext(); )
|
||||
{
|
||||
File file = ( File ) it.next();
|
||||
|
||||
if ( file.exists() )
|
||||
{
|
||||
if ( file.isDirectory() )
|
||||
{
|
||||
FileUtils.deleteDirectory( file );
|
||||
}
|
||||
else
|
||||
{
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
it.remove();
|
||||
}
|
||||
|
||||
warnAboutCleanup = false;
|
||||
}
|
||||
|
||||
public void assertFileExistence( File dir, String filename, boolean shouldExist )
|
||||
{
|
||||
File file = new File( dir, filename );
|
||||
|
||||
if ( shouldExist )
|
||||
{
|
||||
Assert.assertTrue( file.exists() );
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.assertFalse( file.exists() );
|
||||
}
|
||||
}
|
||||
|
||||
public void assertFileContents( File dir, String filename, String contentsTest )
|
||||
throws IOException
|
||||
{
|
||||
assertFileExistence( dir, filename, true );
|
||||
|
||||
File file = new File( dir, filename );
|
||||
|
||||
FileReader reader = null;
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
try
|
||||
{
|
||||
reader = new FileReader( file );
|
||||
|
||||
IOUtil.copy( reader, writer );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( reader );
|
||||
}
|
||||
|
||||
Assert.assertEquals( contentsTest, writer.toString() );
|
||||
}
|
||||
|
||||
public File createFile( File dir, String filename, String contents )
|
||||
throws IOException
|
||||
{
|
||||
File file = new File( dir, filename );
|
||||
|
||||
file.getParentFile().mkdirs();
|
||||
|
||||
FileWriter writer = null;
|
||||
|
||||
try
|
||||
{
|
||||
writer = new FileWriter( file );
|
||||
|
||||
IOUtil.copy( new StringReader( contents ), writer );
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( writer );
|
||||
}
|
||||
|
||||
markForDeletion( file );
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
public String getFileContents( File file )
|
||||
throws IOException
|
||||
{
|
||||
String result = null;
|
||||
|
||||
FileReader reader = null;
|
||||
try
|
||||
{
|
||||
reader = new FileReader( file );
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
|
||||
IOUtil.copy( reader, writer );
|
||||
|
||||
result = writer.toString();
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close( reader );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void finalize()
|
||||
throws Throwable
|
||||
{
|
||||
maybeWarnAboutCleanUp();
|
||||
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
public File createFile( String filename, String content )
|
||||
throws IOException
|
||||
{
|
||||
File dir = createTempDir();
|
||||
return createFile( dir, filename, content );
|
||||
}
|
||||
|
||||
}
|
6
pom.xml
6
pom.xml
|
@ -183,6 +183,12 @@
|
|||
<artifactId>wagon-http-lightweight</artifactId>
|
||||
<version>1.0-alpha-6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<version>1.2_Java1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<distributionManagement>
|
||||
|
|
Loading…
Reference in New Issue