You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2008/03/10 18:37:37 UTC

svn commit: r635614 - in /maven/core-integration-testing/trunk: core-integration-tests/src/test/java/org/apache/maven/integrationtests/ core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/ core-integration-tests/src/test/resourc...

Author: jdcasey
Date: Mon Mar 10 10:37:22 2008
New Revision: 635614

URL: http://svn.apache.org/viewvc?rev=635614&view=rev
Log:
[MNG-3415] Adding an integration test to make sure metadata files aren't written when TransferFailedException happens during metadata resolution, and that the file used for updateInterval calculations (metadata file in 2.0.x and resolver-status.properties in 2.1.x) is NOT updated on successive builds inside that updateInterval. Finally, updating AbstractMavenIntegrationTest to allow matching of specific version ranges on-demand, to allow tests to adjust things like the updateInterval check-file...this is not ideal, but provides smaller code changes and maintenance overhead than duplicating unit test classes for this behavior.

Added:
    maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3415JunkRepositoryMetadataTest.java   (with props)
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/dependency-pom.xml   (with props)
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/pom.xml   (with props)
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/src/
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/src/main/
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/src/main/java/
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/src/main/java/org/
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/src/main/java/org/apache/
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/src/main/java/org/apache/maven/
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/src/main/java/org/apache/maven/plugin/
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/src/main/java/org/apache/maven/plugin/findLocalRepo/
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/src/main/java/org/apache/maven/plugin/findLocalRepo/FindLocalRepoMojo.java   (with props)
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/pom.xml   (with props)
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/main/
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/main/java/
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/main/java/tests/
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/main/java/tests/App.java   (with props)
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/test/
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/test/java/
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/test/java/tests/
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/test/java/tests/AppTest.java   (with props)
    maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/settings.xml.in   (with props)
Modified:
    maven/core-integration-testing/trunk/maven-integration-test-helper/src/main/java/org/apache/maven/integrationtests/AbstractMavenIntegrationTestCase.java

Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3415JunkRepositoryMetadataTest.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3415JunkRepositoryMetadataTest.java?rev=635614&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3415JunkRepositoryMetadataTest.java (added)
+++ maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3415JunkRepositoryMetadataTest.java Mon Mar 10 10:37:22 2008
@@ -0,0 +1,405 @@
+package org.apache.maven.integrationtests;
+
+import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
+import org.apache.maven.it.VerificationException;
+import org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.FileUtils;
+import org.apache.maven.it.util.IOUtil;
+import org.apache.maven.it.util.ResourceExtractor;
+import org.apache.maven.it.util.StringUtils;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * This is a sample integration test. The IT tests typically
+ * operate by having a sample project in the
+ * /src/test/resources folder along with a junit test like
+ * this one. The junit test uses the verifier (which uses
+ * the invoker) to invoke a new instance of Maven on the
+ * project in the resources folder. It then checks the
+ * results. This is a non-trivial example that shows two
+ * phases. See more information inline in the code.
+ *
+ * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
+ *
+ */
+public class MavenITmng3415JunkRepositoryMetadataTest
+    extends AbstractMavenIntegrationTestCase
+{
+    private static final String RESOURCE_BASE = "/mng-3415-junk-repository-metadata";
+
+    public MavenITmng3415JunkRepositoryMetadataTest()
+        throws InvalidVersionSpecificationException
+    {
+        // we're going to control the test execution according to the maven version present within each test method.
+        // all methods should execute as long as we're using maven 2.0.9+, but the specific tests may vary a little
+        // depending on which version we're using above 2.0.8.
+        super( "(2.0.8,)" ); // only test in 2.0.9+
+    }
+
+    /**
+     * This test simply verifies that when a metadata transfer fails (network error, etc.)
+     * no metadata file is written to the local repository.
+     *
+     * Steps executed to verify this test:
+     *
+     * 0. Find the local repository directory:
+     *    a. build the maven-find-local-repo-plugin, then run it, to spit out the path of the
+     *       local repository in use by default. Read the output file to get this path.
+     *       (Yes, it's heavy, but it's reliable.)
+     * 1. Setup the test:
+     *    a. Make sure the metadata for the test-repo is NOT in the local repository.
+     *    b. Make sure the dependency POM IS in the local repository, so we're not
+     *       distracted by failed builds that are unrelated.
+     *    c. Create the settings file for use in this test, which contains the invalid
+     *       remote repository entry.
+     * 2. Build the test project the first time
+     *    a. Verify that a TransferFailedException is in the build output for the test-repo
+     *    b. Verify that the metadata for the dependency POM is NOT in the local
+     *       repository afterwards.
+     * 3. Build the test project the second time
+     *    a. See (2.a) and (2.b) above; the same criteria applies here.
+     */
+    public void testShouldNotStoreMetadataOnTransferFailedException()
+        throws Exception
+    {
+        String methodName = getMethodName();
+
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), RESOURCE_BASE );
+        File projectDir = new File( testDir, "project" );
+
+        File logFile = new File( projectDir, "log.txt" );
+
+        String proto = "invalid";
+
+        File settings = writeSettings( proto, testDir );
+        File localRepo = findLocalRepoDirectory();
+
+        setupDummyDependency( testDir, localRepo, true );
+
+        Verifier verifier;
+
+        verifier = new Verifier( projectDir.getAbsolutePath() );
+
+        List cliOptions = new ArrayList();
+        cliOptions.add( "-X" );
+        cliOptions.add( "-s" );
+        cliOptions.add( settings.getPath() );
+
+        verifier.setCliOptions( cliOptions );
+        verifier.executeGoal( "package" );
+
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        File firstLogFile = new File( testDir, "log-" + methodName + "-firstBuild.txt" );
+        logFile.renameTo( firstLogFile );
+
+        assertMetadataMissing( localRepo );
+
+        setupDummyDependency( testDir, localRepo, true );
+
+        verifier.executeGoal( "package" );
+
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        File secondLogFile = new File( testDir, "log-" + methodName + "-secondBuild.txt" );
+        logFile.renameTo( secondLogFile );
+
+        assertMetadataMissing( localRepo );
+    }
+
+    private String getMethodName()
+    {
+        return new Throwable().getStackTrace()[1].getMethodName();
+    }
+
+    /**
+     * This test simply verifies that when metadata doesn't exist on the remote
+     * repository, a basic metadata file is written to the local repository.
+     *
+     * Steps executed to verify this test:
+     *
+     * 0. Find the local repository directory:
+     *    a. build the maven-find-local-repo-plugin, then run it, to spit out the path of the
+     *       local repository in use by default. Read the output file to get this path.
+     *       (Yes, it's heavy, but it's reliable.)
+     * 1. Setup the test:
+     *    a. Make sure the metadata for the test-repo is NOT in the local repository.
+     *    b. Make sure the dependency POM IS in the local repository, so we're not
+     *       distracted by failed builds that are unrelated.
+     *    c. Create the settings file for use in this test, which contains the VALID
+     *       remote repository entry.
+     * 2. Build the test project the first time
+     *    a. Verify that a log message checking the remote repository for the metadata file
+     *       is in the build output for the test-repo
+     * 3. Build the test project the second time
+     *    a. Verify that a log message checking the remote repository for the metadata file
+     *       IS NOT in the build output for the test-repo
+     *    b. Verify that the file used for updateInterval calculations was NOT changed from
+     *       the first build.
+     *
+     * @fixme: Find a better mechanism for testing this than matching console output!
+     */
+    public void testShouldNotRepeatedlyUpdateOnResourceNotFoundException()
+        throws Exception
+    {
+        String methodName = getMethodName();
+
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), RESOURCE_BASE );
+        File projectDir = new File( testDir, "project" );
+
+        File logFile = new File( projectDir, "log.txt" );
+
+        File settings = writeSettings( "file", testDir );
+        File localRepo = findLocalRepoDirectory();
+
+        setupDummyDependency( testDir, localRepo, true );
+
+        Verifier verifier;
+
+        verifier = new Verifier( projectDir.getAbsolutePath() );
+
+        List cliOptions = new ArrayList();
+        cliOptions.add( "-X" );
+        cliOptions.add( "-s" );
+        cliOptions.add( settings.getPath() );
+
+        verifier.setCliOptions( cliOptions );
+
+        verifier.executeGoal( "package" );
+
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        File firstLogFile = new File( testDir, "log-" + methodName + "-firstBuild.txt" );
+        logFile.renameTo( firstLogFile );
+
+        // FIXME: There really should be a better way than this!
+        assertOutputLinePresent( verifier, firstLogFile, "snapshot tests:missing:1.0-SNAPSHOT: checking for updates from testing-repo" );
+
+        File updateCheckFile = getUpdateCheckFile( localRepo );
+        long firstLastMod = updateCheckFile.lastModified();
+
+        setupDummyDependency( testDir, localRepo, false );
+
+        verifier.executeGoal( "package" );
+
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        File secondLogFile = new File( testDir, "log-" + methodName + "-secondBuild.txt" );
+        logFile.renameTo( secondLogFile );
+
+        // FIXME: There really should be a better way than this!
+        assertOutputLineMissing( verifier, secondLogFile, "snapshot tests:missing:1.0-SNAPSHOT: checking for updates from testing-repo" );
+
+        assertEquals( "Last-modified time should be unchanged from first build through second build for the file we use for updateInterval checks.", firstLastMod, updateCheckFile.lastModified() );
+    }
+
+    private void assertMetadataMissing( File localRepo )
+    {
+        File metadata = getMetadataFile( localRepo );
+
+        assertFalse( "Metadata file should NOT be present in local repository: "
+                     + metadata.getAbsolutePath(), metadata.exists() );
+    }
+
+    private void setupDummyDependency( File testDir,
+                                       File localRepo,
+                                       boolean resetUpdateInterval )
+        throws VerificationException, IOException
+    {
+        File metadata = getMetadataFile( localRepo );
+
+        if ( resetUpdateInterval && metadata.exists() )
+        {
+            System.out.println( "Deleting metadata file: " + metadata );
+            metadata.delete();
+        }
+
+        File resolverStatus = new File( metadata.getParentFile(), "resolver-status.properties" );
+        if ( resetUpdateInterval && resolverStatus.exists() )
+        {
+            System.out.println( "Deleting resolver-status.properties file related to: " + metadata );
+            resolverStatus.delete();
+        }
+
+        File dir = metadata.getParentFile();
+
+        System.out.println( "Setting up dependency POM in: " + dir );
+
+        File pom = new File( dir, "missing-1.0-SNAPSHOT.pom" );
+
+        if ( pom.exists() )
+        {
+            System.out.println( "Deleting pre-existing POM: " + pom );
+            pom.delete();
+        }
+
+        File pomSrc = new File( testDir, "dependency-pom.xml" );
+
+        System.out.println( "Copying dependency POM\nfrom: " + pomSrc + "\nto: " + pom );
+
+        FileUtils.copyFile( pomSrc, pom );
+    }
+
+    private File getMetadataFile( File localRepo )
+    {
+        File dir = new File( localRepo, "tests/missing/1.0-SNAPSHOT" );
+
+        dir.mkdirs();
+
+        return new File( dir, "maven-metadata-testing-repo.xml" );
+    }
+
+    /**
+     * If the current maven version is < 2.1, we'll use the metadata file itself (old maven-artifact code)...
+     * otherwise, use the new resolver-status.properties file (new artifact code).
+     */
+    private File getUpdateCheckFile( File localRepo )
+        throws InvalidVersionSpecificationException
+    {
+        File dir = new File( localRepo, "tests/missing/1.0-SNAPSHOT" );
+
+        dir.mkdirs();
+
+        if ( matchesVersionRange( "(2.0.8,2.1-SNAPSHOT)" ) )
+        {
+            return new File( dir, "maven-metadata-testing-repo.xml" );
+        }
+        else
+        {
+            return new File( dir, "resolver-status.properties" );
+        }
+    }
+
+    private File findLocalRepoDirectory()
+        throws VerificationException, IOException
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(),
+                                                                 RESOURCE_BASE
+                                                                                 + "/maven-find-local-repo-plugin" );
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+
+        verifier.deleteArtifact( "org.apache.maven.plugins", "maven-find-local-repo-plugin", "1.0-SNAPSHOT", "jar" );
+
+        verifier.executeGoal( "install" );
+
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        verifier.executeGoal( "find-local-repo:find" );
+
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        List lines = verifier.loadFile( new File( testDir, "target/local-repository-location.txt" ),
+                                        false );
+
+        File localRepo = new File( (String) lines.get( 0 ) );
+
+        System.out.println( "Using local repository at: " + localRepo );
+
+        return localRepo;
+    }
+
+    private File writeSettings( String repositoryProtocol,
+                                File testDir )
+        throws IOException
+    {
+        File settingsIn = new File( testDir, "settings.xml.in" );
+
+        String settingsContent = null;
+        Reader reader = null;
+        try
+        {
+            reader = new FileReader( settingsIn );
+            settingsContent = IOUtil.toString( reader );
+        }
+        finally
+        {
+            IOUtil.close( reader );
+        }
+
+        settingsContent = StringUtils.replace( settingsContent, "@PROTO@", repositoryProtocol );
+        settingsContent = StringUtils.replace( settingsContent,
+                                               "@TESTDIR@",
+                                               testDir.getAbsolutePath() );
+
+        File settingsOut = new File( testDir, "settings.xml" );
+
+        System.out.println( "Writing tets settings to: " + settingsOut );
+
+        if ( settingsOut.exists() )
+        {
+            settingsOut.delete();
+        }
+
+        Writer writer = null;
+        try
+        {
+            writer = new FileWriter( settingsOut );
+            IOUtil.copy( settingsContent, writer );
+        }
+        finally
+        {
+            IOUtil.close( writer );
+        }
+
+        return settingsOut;
+    }
+
+    private void assertOutputLinePresent( Verifier verifier,
+                                   File logFile,
+                                   String lineContents )
+        throws VerificationException
+    {
+        List lines = verifier.loadFile( logFile, false );
+
+        boolean found = false;
+        for ( Iterator it = lines.iterator(); it.hasNext(); )
+        {
+            String line = (String) it.next();
+            if ( line.indexOf( lineContents ) > -1 )
+            {
+                found = true;
+                break;
+            }
+        }
+
+        assertTrue( "Build output in:\n\n" + logFile + "\n\nshould contain line with contents:\n\n" + lineContents + "\n", found );
+    }
+
+    private void assertOutputLineMissing( Verifier verifier,
+                                   File logFile,
+                                   String lineContents )
+        throws VerificationException
+    {
+        List lines = verifier.loadFile( logFile, false );
+
+        boolean found = false;
+        for ( Iterator it = lines.iterator(); it.hasNext(); )
+        {
+            String line = (String) it.next();
+            if ( line.indexOf( lineContents ) > -1 )
+            {
+                found = true;
+                break;
+            }
+        }
+
+        assertFalse( "Build output in:\n\n" + logFile + "\n\nshould NOT contain line with contents:\n\n" + lineContents + "\n", found );
+    }
+
+}

Propchange: maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3415JunkRepositoryMetadataTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-integration-tests/src/test/java/org/apache/maven/integrationtests/MavenITmng3415JunkRepositoryMetadataTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/dependency-pom.xml
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/dependency-pom.xml?rev=635614&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/dependency-pom.xml (added)
+++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/dependency-pom.xml Mon Mar 10 10:37:22 2008
@@ -0,0 +1,9 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>tests</groupId>
+  <artifactId>missing</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
+
+</project>

Propchange: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/dependency-pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/dependency-pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/pom.xml?rev=635614&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/pom.xml (added)
+++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/pom.xml Mon Mar 10 10:37:22 2008
@@ -0,0 +1,27 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.maven.plugins</groupId>
+  <artifactId>maven-find-local-repo-plugin</artifactId>
+  <packaging>maven-plugin</packaging>
+  <version>1.0-SNAPSHOT</version>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>

Propchange: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/src/main/java/org/apache/maven/plugin/findLocalRepo/FindLocalRepoMojo.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/src/main/java/org/apache/maven/plugin/findLocalRepo/FindLocalRepoMojo.java?rev=635614&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/src/main/java/org/apache/maven/plugin/findLocalRepo/FindLocalRepoMojo.java (added)
+++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/src/main/java/org/apache/maven/plugin/findLocalRepo/FindLocalRepoMojo.java Mon Mar 10 10:37:22 2008
@@ -0,0 +1,82 @@
+package org.apache.maven.plugin.findLocalRepo;
+
+/*
+ * 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.repository.ArtifactRepository;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+/**
+ * @goal find
+ * @requiresProject false
+ */
+public class FindLocalRepoMojo
+    extends AbstractMojo
+{
+    /**
+     * Location of the file containing the local repository path.
+     * @parameter expression="${output}" default-value="${project.build.directory}/local-repository-location.txt"
+     * @required
+     */
+    private File output;
+
+    /**
+     * @parameter default-value="${localRepository}"
+     * @required
+     * @readonly
+     */
+    private ArtifactRepository localRepository;
+
+    public void execute()
+        throws MojoExecutionException
+    {
+        if ( !output.exists() )
+        {
+            output.getParentFile().mkdirs();
+        }
+
+        FileWriter w = null;
+        try
+        {
+            w = new FileWriter( output );
+
+            w.write( String.valueOf( new File( localRepository.getBasedir() ).getAbsolutePath() ) );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Error creating file " + output, e );
+        }
+        finally
+        {
+            if ( w != null )
+            {
+                try
+                {
+                    w.close();
+                }
+                catch ( IOException e )
+                {
+                    // ignore
+                }
+            }
+        }
+    }
+}

Propchange: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/src/main/java/org/apache/maven/plugin/findLocalRepo/FindLocalRepoMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/maven-find-local-repo-plugin/src/main/java/org/apache/maven/plugin/findLocalRepo/FindLocalRepoMojo.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/pom.xml
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/pom.xml?rev=635614&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/pom.xml (added)
+++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/pom.xml Mon Mar 10 10:37:22 2008
@@ -0,0 +1,23 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>tests</groupId>
+  <artifactId>project</artifactId>
+  <version>1</version>
+
+  <dependencies>
+    <dependency>
+      <groupId>tests</groupId>
+      <artifactId>missing</artifactId>
+      <version>1.0-SNAPSHOT</version>
+      <type>pom</type>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>

Propchange: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/main/java/tests/App.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/main/java/tests/App.java?rev=635614&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/main/java/tests/App.java (added)
+++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/main/java/tests/App.java Mon Mar 10 10:37:22 2008
@@ -0,0 +1,13 @@
+package tests;
+
+/**
+ * Hello world!
+ *
+ */
+public class App 
+{
+    public static void main( String[] args )
+    {
+        System.out.println( "Hello World!" );
+    }
+}

Propchange: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/main/java/tests/App.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/main/java/tests/App.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/test/java/tests/AppTest.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/test/java/tests/AppTest.java?rev=635614&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/test/java/tests/AppTest.java (added)
+++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/test/java/tests/AppTest.java Mon Mar 10 10:37:22 2008
@@ -0,0 +1,38 @@
+package tests;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest 
+    extends TestCase
+{
+    /**
+     * Create the test case
+     *
+     * @param testName name of the test case
+     */
+    public AppTest( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * @return the suite of tests being tested
+     */
+    public static Test suite()
+    {
+        return new TestSuite( AppTest.class );
+    }
+
+    /**
+     * Rigourous Test :-)
+     */
+    public void testApp()
+    {
+        assertTrue( true );
+    }
+}

Propchange: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/test/java/tests/AppTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/project/src/test/java/tests/AppTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/settings.xml.in
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/settings.xml.in?rev=635614&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/settings.xml.in (added)
+++ maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/settings.xml.in Mon Mar 10 10:37:22 2008
@@ -0,0 +1,16 @@
+<settings>
+  <profiles>
+    <profile>
+      <id>remote-repository</id>
+      <repositories>
+        <repository>
+          <id>testing-repo</id>
+          <url>@PROTO@://@TESTDIR@/remote-repository</url>
+        </repository>
+      </repositories>
+    </profile>
+  </profiles>
+  <activeProfiles>
+    <activeProfile>remote-repository</activeProfile>
+  </activeProfiles>
+</settings>
\ No newline at end of file

Propchange: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/settings.xml.in
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-integration-tests/src/test/resources/mng-3415-junk-repository-metadata/settings.xml.in
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/core-integration-testing/trunk/maven-integration-test-helper/src/main/java/org/apache/maven/integrationtests/AbstractMavenIntegrationTestCase.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/maven-integration-test-helper/src/main/java/org/apache/maven/integrationtests/AbstractMavenIntegrationTestCase.java?rev=635614&r1=635613&r2=635614&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/maven-integration-test-helper/src/main/java/org/apache/maven/integrationtests/AbstractMavenIntegrationTestCase.java (original)
+++ maven/core-integration-testing/trunk/maven-integration-test-helper/src/main/java/org/apache/maven/integrationtests/AbstractMavenIntegrationTestCase.java Mon Mar 10 10:37:22 2008
@@ -54,6 +54,31 @@
         }
     }
 
+    /**
+     * This allows fine-grained control over execution of individual test methods
+     * by allowing tests to adjust to the current maven version, or else simply avoid
+     * executing altogether if the wrong version is present.
+     */
+    protected boolean matchesVersionRange( String versionRangeStr )
+        throws InvalidVersionSpecificationException
+    {
+        versionRange = VersionRange.createFromVersionSpec( versionRangeStr );
+
+        String v = System.getProperty( "maven.version" );
+        if ( v != null )
+        {
+            version = new DefaultArtifactVersion( v );
+            return versionRange.containsVersion( version );
+        }
+        else
+        {
+            out.println( "WARNING: " + getITName() + ": version range '" + versionRange
+                + "' supplied but no maven version found - returning true for match check." );
+
+            return true;
+        }
+    }
+
     protected void runTest()
         throws Throwable
     {