Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 132783 Details for
Bug 265550
Review Ant task consistency
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Tests
Ant-Tests.patch (text/plain), 164.72 KB, created by
Matthew Piggott
on 2009-04-22 10:53:22 EDT
(
hide
)
Description:
Tests
Filename:
MIME Type:
Creator:
Matthew Piggott
Created:
2009-04-22 10:53:22 EDT
Size:
164.72 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.equinox.p2.tests >Index: src/org/eclipse/equinox/p2/tests/mirror/AllTests.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/mirror/AllTests.java,v >retrieving revision 1.2 >diff -u -r1.2 AllTests.java >--- src/org/eclipse/equinox/p2/tests/mirror/AllTests.java 1 Oct 2008 20:34:48 -0000 1.2 >+++ src/org/eclipse/equinox/p2/tests/mirror/AllTests.java 22 Apr 2009 14:52:17 -0000 >@@ -23,6 +23,8 @@ > suite.addTestSuite(MetadataMirrorApplicationTest.class); > suite.addTestSuite(ArtifactRepositoryCleanupTest.class); > suite.addTestSuite(MetadataRepositoryCleanupTest.class); >+ suite.addTestSuite(NewMirrorApplicationArtifactTest.class); >+ suite.addTestSuite(NewMirrorApplicationMetadataTest.class); > return suite; > } > >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.tests/META-INF/MANIFEST.MF,v >retrieving revision 1.61 >diff -u -r1.61 MANIFEST.MF >--- META-INF/MANIFEST.MF 20 Apr 2009 14:24:41 -0000 1.61 >+++ META-INF/MANIFEST.MF 22 Apr 2009 14:52:17 -0000 >@@ -6,6 +6,7 @@ > Bundle-Localization: plugin > Bundle-Version: 1.1.0.qualifier > Import-Package: javax.xml.parsers, >+ org.eclipse.ant.core, > org.eclipse.ecf.filetransfer, > org.eclipse.equinox.internal.p2.artifact.mirror, > org.eclipse.equinox.internal.p2.artifact.processors.md5, >@@ -50,6 +51,7 @@ > org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository, > org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository, > org.eclipse.equinox.internal.provisional.spi.p2.repository, >+ org.eclipse.equinox.p2.internal.repository.tools, > org.eclipse.equinox.spi.p2.publisher, > org.eclipse.internal.provisional.equinox.p2.jarprocessor, > org.eclipse.osgi.service.datalocation, >Index: src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationMetadataTest.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationMetadataTest.java >diff -N src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationMetadataTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationMetadataTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,967 @@ >+/******************************************************************************* >+ * Copyright (c) 2008, 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.equinox.p2.tests.mirror; >+ >+import java.io.File; >+import java.net.*; >+import java.util.HashMap; >+import java.util.Map; >+import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository; >+import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; >+import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; >+import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; >+import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; >+import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; >+import org.eclipse.equinox.internal.provisional.p2.query.Collector; >+import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; >+import org.eclipse.equinox.internal.simpleconfigurator.utils.URIUtil; >+import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication; >+import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor; >+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; >+import org.eclipse.osgi.util.NLS; >+ >+/* >+ * Modified from MetadataMirrorApplicationTest >+ */ >+public class NewMirrorApplicationMetadataTest extends AbstractProvisioningTest { >+ protected File destRepoLocation; >+ protected File sourceRepoLocation; //helloworldfeature >+ protected File sourceRepo2Location; //anotherfeature >+ protected File sourceRepo3Location; //helloworldfeature + yetanotherfeature >+ protected File sourceRepo4Location; //helloworldfeature v1.0.1 >+ >+ protected Exception exception = null; >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.equinox.p2.tests.AbstractProvisioningTest#setUp() >+ */ >+ protected void setUp() throws Exception { >+ super.setUp(); >+ //load all the repositories >+ sourceRepoLocation = getTestData("0.0", "/testData/mirror/mirrorSourceRepo1 with space"); >+ sourceRepo2Location = getTestData("0.1", "/testData/mirror/mirrorSourceRepo2"); >+ sourceRepo3Location = getTestData("0.2", "/testData/mirror/mirrorSourceRepo3"); >+ sourceRepo4Location = getTestData("0.3", "/testData/mirror/mirrorSourceRepo4"); >+ >+ //create destination location >+ destRepoLocation = new File(getTempFolder(), "BasicMirrorApplicationTest"); >+ AbstractProvisioningTest.delete(destRepoLocation); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.equinox.p2.tests.AbstractProvisioningTest#tearDown() >+ */ >+ protected void tearDown() throws Exception { >+ //remove all the repositories >+ getMetadataRepositoryManager().removeRepository(destRepoLocation.toURI()); >+ getMetadataRepositoryManager().removeRepository(sourceRepoLocation.toURI()); >+ getMetadataRepositoryManager().removeRepository(sourceRepo2Location.toURI()); >+ getMetadataRepositoryManager().removeRepository(sourceRepo3Location.toURI()); >+ getMetadataRepositoryManager().removeRepository(sourceRepo4Location.toURI()); >+ exception = null; >+ //delete the destination location (no left over files for the next test) >+ delete(destRepoLocation); >+ super.tearDown(); >+ } >+ >+ /** >+ * Runs mirror application with default arguments. source is the source repo, >+ * destination is the destination repo, append is if the "-writeMode clean" argument should be excluded >+ * >+ * Note: We use URL here because command line applications traffic in unencoded URLs, >+ * so we can't use java.net.URI which will always use the encoded form >+ */ >+ private void basicRunMirrorApplication(String message, URL source, URL destination, boolean append) throws Exception { >+ MirrorApplication app = new MirrorApplication(); >+ >+ if (destination != null) { >+ RepositoryDescriptor dest = new RepositoryDescriptor(); >+ dest.setLocation(URIUtil.fromString(destination.toExternalForm())); >+ dest.setAppend(append); >+ dest.setKind("metadata"); >+ app.addDestination(dest); >+ } >+ >+ if (source != null) { >+ RepositoryDescriptor src = new RepositoryDescriptor(); >+ src.setLocation(URIUtil.fromString(source.toExternalForm())); >+ src.setKind("metadata"); >+ app.addSource(src); >+ } >+ app.run(null); >+ } >+ >+ private void basicRunMirrorApplication(String message, URL source, URL destination, boolean append, String name) throws Exception { >+ MirrorApplication app = new MirrorApplication(); >+ >+ if (destination != null) { >+ RepositoryDescriptor dest = new RepositoryDescriptor(); >+ dest.setLocation(URIUtil.fromString(destination.toExternalForm())); >+ dest.setAppend(append); >+ dest.setKind("metadata"); >+ dest.setName(name); >+ app.addDestination(dest); >+ } >+ >+ if (source != null) { >+ RepositoryDescriptor src = new RepositoryDescriptor(); >+ src.setLocation(URIUtil.fromString(source.toExternalForm())); >+ src.setKind("metadata"); >+ app.addSource(src); >+ } >+ app.run(null); >+ } >+ >+ /** >+ * just a wrapper method for compatibility >+ */ >+ private void runMirrorApplication(String message, File source, File destination, boolean append) { >+ try { >+ basicRunMirrorApplication(message, source.toURL(), destination.toURL(), append); >+ } catch (Exception e) { >+ fail(message, e); >+ } >+ } >+ >+ /** >+ * Takes 2 collectors, compares them, and returns the number of unique keys >+ * Needed to verify that only the appropriate number of files have been transfered by the mirror application >+ */ >+ private int getNumUnique(Collector c1, Collector c2) { >+ Object[] repo1 = c1.toCollection().toArray(); >+ Object[] repo2 = c2.toCollection().toArray(); >+ >+ //initialize to the size of both collectors >+ int numKeys = repo1.length + repo2.length; >+ >+ for (int i = 0; i < repo1.length; i++) { >+ for (int j = 0; j < repo2.length; j++) { >+ if (isEqual((IInstallableUnit) repo1[i], (IInstallableUnit) repo2[j])) >+ numKeys--; >+ //identical keys has bee found, therefore the number of unique keys is one less than previously thought >+ } >+ } >+ return numKeys; >+ } >+ >+ /** >+ * Tests mirroring all metadata in a repository to an empty repository >+ * Source contains A, B >+ * Target contains >+ */ >+ private void metadataMirrorToEmpty(String message, boolean append) { >+ //destination repo is created blank >+ runMirrorApplication(message + ".0", sourceRepoLocation, destRepoLocation, append); //do not append >+ } >+ >+ /** >+ * Tests mirroring all metadata in a repository to a repository populated with non-duplicate entries >+ * Source contains A, B >+ * Target contains C, D >+ */ >+ private void metadataMirrorToPopulated(String message, boolean append) { >+ //Setup: populate destination with non-duplicate metadata >+ runMirrorApplication(message + ".0", sourceRepo2Location, destRepoLocation, false); //value of append does not matter >+ >+ try { >+ //Setup: ensure setup completed successfully >+ assertContentEquals(message + ".1", getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail(message + ".2", e); >+ } >+ >+ //mirror test data >+ runMirrorApplication(message + ".4", sourceRepoLocation, destRepoLocation, append); >+ } >+ >+ /** >+ * Tests mirroring all metadata in a repository to a repository populated with exact duplicate data >+ * @throws Exception >+ * Source contains A, B >+ * Target contains A, B >+ */ >+ private void metadataMirrorToFullDuplicate(String message, boolean append) { >+ //Setup: populate destination with duplicate metadata >+ runMirrorApplication(message + ".0", sourceRepoLocation, destRepoLocation, false); //value of append does not matter >+ >+ try { >+ //Setup: verify contents >+ assertContentEquals(message + ".1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail(message + ".2", e); >+ } >+ >+ //mirror test data >+ runMirrorApplication(message + ".4", sourceRepoLocation, destRepoLocation, append); >+ } >+ >+ /** >+ * Tests mirroring all metadata in a repository to a repository populated with partially duplicate data >+ * Source contains A, B, C, D >+ * Target contains A, B >+ */ >+ private void metadataMirrorToPartialDuplicate(String message, boolean append) { >+ //Setup: populate destination with duplicate metadata >+ runMirrorApplication(message + ".0", sourceRepoLocation, destRepoLocation, false); //value of append does not matter >+ >+ try { >+ //Setup: verify contents >+ assertContentEquals(message + ".1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail(message + ".2", e); >+ } >+ >+ //mirror test data >+ runMirrorApplication(message + ".4", sourceRepo3Location, destRepoLocation, append); >+ } >+ >+ /** >+ * Tests mirroring all metadata in a repository to a repository populated with both full duplicate and non-duplicate data >+ * Source contains A, B >+ * Target contains A, B, C, D >+ */ >+ private void metadataMirrorToPopulatedWithFullDuplicate(String message, boolean append) { >+ //Setup: populate destination with non-duplicate metadata >+ runMirrorApplication(message + ".0", sourceRepo3Location, destRepoLocation, false); //value of append does not matter >+ >+ try { >+ //Setup: verify >+ assertContentEquals(message + ".1", getMetadataRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail(message + ".2", e); >+ } >+ >+ //mirror duplicate data >+ runMirrorApplication(message + ".4", sourceRepoLocation, destRepoLocation, append); >+ } >+ >+ /** >+ * Tests mirroring all metadata in a repository to a repository populated with both partial duplicate and non-duplicate data >+ * Source contains A, B, C, D >+ * Target contains A, B, E, F >+ */ >+ private void metadataMirrorToPopulatedWithPartialDuplicate(String message, boolean append) { >+ //Setup: populate destination with non-duplicate metadata >+ runMirrorApplication(message + ".0", sourceRepo2Location, destRepoLocation, false); //value of append does not matter >+ >+ try { >+ //Setup: verify >+ assertContentEquals(message + ".1", getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail(message + ".2", e); >+ } >+ >+ //Setup: populate destination with duplicate metadata >+ runMirrorApplication(message + ".4", sourceRepoLocation, destRepoLocation, true); >+ >+ try { >+ //Setup: verify >+ assertContains(message + ".5", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ assertContains(message + ".6", getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail(message + ".7", e); >+ } >+ >+ //mirror duplicate data >+ runMirrorApplication(message + ".7", sourceRepo3Location, destRepoLocation, append); >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to an empty repository >+ * Source contains A, B >+ * Target contains >+ */ >+ private File metadataMirrorEmpty(String message, boolean append) { >+ //Setup: Create an empty repository >+ File emptyRepository = new File(getTempFolder(), getUniqueString()); >+ //Setup: remove repository if it exists >+ getMetadataRepositoryManager().removeRepository(emptyRepository.toURI()); >+ //Setup: delete any data that may be in the folder >+ AbstractProvisioningTest.delete(emptyRepository); >+ try { >+ getMetadataRepositoryManager().createRepository(emptyRepository.toURI(), "Empty Repository", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); >+ } catch (ProvisionException e) { >+ fail(message + ".1", e); >+ } >+ >+ try { >+ basicRunMirrorApplication(message + ".0", emptyRepository.toURL(), destRepoLocation.toURL(), append); >+ } catch (Exception e) { >+ exception = e; >+ } >+ >+ return emptyRepository; //return the repository for use in verification >+ } >+ >+ /** >+ * Tests mirroring all metadata from an empty repository >+ * Source contains >+ */ >+ private File metadataMirrorEmptyToPopulated(String message, boolean append) { >+ //Setup: Populate the repository >+ runMirrorApplication(message + ".0", sourceRepoLocation, destRepoLocation, false); >+ >+ return metadataMirrorEmpty(message + ".1", append); //create the empty repository, perform the mirror, pass the result back >+ } >+ >+ /** >+ * Tests mirroring all metadata in a repository to an empty repository >+ * Source contains A, B >+ * Target contains >+ * Expected is A, B >+ */ >+ public void testMetadataMirrorToEmpty() { >+ metadataMirrorToEmpty("1.0", true); //run the test with append set to true >+ >+ try { >+ //verify destination's content >+ assertContentEquals("1.1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("1.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all metadata in a repository to an empty repository with "-writeMode clean" >+ * Source contains A, B >+ * Target contains >+ * Expected is A, B >+ */ >+ public void testMetadataMirrorToEmptyWithClean() { >+ metadataMirrorToEmpty("2.0", false); //run the test with append set to false >+ >+ try { >+ //verify destination's content >+ assertContentEquals("2.1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("2.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all metadata in a repository to a repository populated with exact duplicate data >+ * Source contains A, B >+ * Target contains A, B >+ * Expected is A, B >+ */ >+ public void testMetadataMirrorToFullDuplicate() { >+ metadataMirrorToFullDuplicate("3.0", true); //run the test with append set to true >+ >+ try { >+ //verify destination's content >+ assertContentEquals("3.1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("3.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all metadata in a repository to a repository populated with exact duplicate data with "-writeMode clean" >+ * Source contains A, B >+ * Target contains A, B >+ * Expected is A, B >+ */ >+ public void testMetadataMirrorToFullDuplicateWithClean() { >+ metadataMirrorToFullDuplicate("4.0", false); //run the test with append set to false >+ >+ try { >+ //verify destination's content >+ assertContentEquals("4.1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("4.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all metadata in a repository to a repository populated with non-duplicate entries >+ * Source contains A, B >+ * Target contains C, D >+ * Expected is A, B, C, D >+ */ >+ public void testMetadataMirrorToPopulated() { >+ metadataMirrorToPopulated("5.0", true); //run the test with append set to true >+ >+ try { >+ //verify destination's content >+ assertContains("5.1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ assertContains("5.2", getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ //checks that the destination has the correct number of keys (no extras) >+ assertEquals("5.3", getNumUnique(getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null), getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null)), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null).size()); >+ } catch (ProvisionException e) { >+ fail("5.4", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all metadata in a repository to a repository populated with non-duplicate entries with "-writeMode clean" >+ * Source contains A, B >+ * Target contains C, D >+ * Expected is A, B >+ */ >+ public void testMetadataMirrorToPopulatedWithClean() { >+ metadataMirrorToPopulated("6.0", false); //run the test with append set to false >+ >+ try { >+ //verify destination's content >+ assertContentEquals("6.1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("6.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all metadata in a repository to a repository populated with partially duplicate data >+ * Source contains A, B, C, D >+ * Target contains A, B >+ * Expected is A, B, C, D >+ */ >+ public void testMetadataMirrorToPartialDuplicate() { >+ metadataMirrorToPartialDuplicate("7.0", true); //run the test with append set to true >+ >+ try { >+ //verify destination's content >+ assertContentEquals("7.1", getMetadataRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("7.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all metadata in a repository to a repository populated with partially duplicate data with "-writeMode clean" >+ * Source contains A, B, C, D >+ * Target contains A, B >+ * Expected is A, B, C, D >+ */ >+ public void testMetadataMirrorToPartialDuplicateWithClean() { >+ metadataMirrorToPartialDuplicate("8.0", false); //run the test with append set to false >+ >+ try { >+ //verify destination's content >+ assertContentEquals("8.1", getMetadataRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("8.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all metadata in a repository to a repository populated with both full duplicate and non-duplicate data >+ * Source contains A, B >+ * Target contains A, B, C, D >+ * Expected is A, B, C, D >+ */ >+ public void testMetadataMirrorToPopulatedWithFullDuplicate() { >+ metadataMirrorToPopulatedWithFullDuplicate("9.0", true); //run the test with append set to true >+ >+ try { >+ //verify destination's content >+ assertContentEquals("9.1", getMetadataRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("9.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all metadata in a repository to a repository populated with both full duplicate and non-duplicate data with "-writeMode clean" >+ * Source contains A, B >+ * Target contains A, B, C, D >+ * Expected is A, B >+ */ >+ public void testMetadataMirrorToPopulatedWithFullDuplicateWithClean() { >+ metadataMirrorToPopulatedWithFullDuplicate("10.0", false); //run the test with append set to false >+ >+ try { >+ //verify destination's content >+ assertContentEquals("10.1", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("10.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all metadata in a repository to a repository populated with both partial duplicate and non-duplicate data >+ * Source contains A, B, C, D >+ * Target contains A, B, E, F >+ * Expected is A, B, C, D, E, F >+ */ >+ public void testMetadataMirrorToPopulatedWithPartialDuplicate() { >+ metadataMirrorToPopulatedWithPartialDuplicate("11.0", true); //run the test with append set to true >+ >+ try { >+ //verify destination's content >+ assertContains("11.1", getMetadataRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ assertContains("11.2", getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ //checks that the destination has the correct number of keys (no extras) >+ assertEquals("11.3", getNumUnique(getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null), getMetadataRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null)), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null).size()); >+ } catch (ProvisionException e) { >+ fail("11.4", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all metadata in a repository to a repository populated with both partial duplicate and non-duplicate data with "-writeMode clean" >+ * Source contains A, B, C, D >+ * Target contains A, B, E, F >+ * Expected is A, B, C, D >+ */ >+ public void testMetadataMirrorToPopulatedWithPartialDuplicateWithClean() { >+ metadataMirrorToPopulatedWithPartialDuplicate("12.0", false); //run the test with append set to false >+ >+ try { >+ //verify destination's content >+ assertContentEquals("12.1", getMetadataRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("12.2", e); >+ } >+ } >+ >+ /** >+ * Tests MirrorApplication's behaviour when given an invalid source repository >+ */ >+ public void testMetadataMirrorFromInvalid() { >+ //get a temp folder >+ File invalidRepository = new File(getTempFolder(), getUniqueString()); >+ //delete any data that may exist in that temp folder >+ delete(invalidRepository); >+ >+ try { >+ basicRunMirrorApplication("13.1", invalidRepository.toURL(), destRepoLocation.toURL(), true); >+ //we expect a provisioning exception to be thrown and should never get here >+ fail("13.0 ProvisionExpection not thrown"); >+ } catch (ProvisionException e) { >+ return; //correct type of exception has been received >+ } catch (Exception e) { >+ fail("13.2", e); >+ } >+ } >+ >+ /** >+ * Tests MirrorApplication's behaviour when given an invalid destination repository >+ */ >+ public void testMetadataMirrorToInvalid() { >+ URI invalidDestRepository = null; >+ try { >+ invalidDestRepository = new URI("http://foobar.com/abcdefg"); >+ basicRunMirrorApplication("14.1", sourceRepoLocation.toURL(), invalidDestRepository.toURL(), true); >+ //we expect an illegal state exception to be thrown and should never get here >+ fail("14.0 IllegalStateExpection not thrown"); >+ } catch (ProvisionException e) { >+ assertEquals("Unexpected error message", NLS.bind(org.eclipse.equinox.p2.internal.repository.tools.Messages.exception_invalidDestination, URIUtil.toUnencodedString(invalidDestRepository)), e.getMessage()); >+ return; //correct type of exception has been thrown >+ } catch (Exception e) { >+ fail("14.1", e); >+ } finally { >+ if (invalidDestRepository != null) >+ getArtifactRepositoryManager().removeRepository(invalidDestRepository); >+ } >+ } >+ >+ /** >+ * Tests MirrorApplication's behaviour when given both an invalid source and an invalid destination repository >+ */ >+ public void testMetadataMirrorBothInvalid() { >+ File invalidRepository = new File(getTempFolder(), getUniqueString()); >+ delete(invalidRepository); >+ >+ try { >+ URI invalidDestRepository = new URI("http://foobar.com/abcdefg"); >+ basicRunMirrorApplication("15.1", invalidRepository.toURL(), invalidDestRepository.toURL(), true); >+ //we expect a provisioning exception to be thrown and should never get here >+ fail("15.0 ProvisionExpection not thrown"); >+ } catch (ProvisionException e) { >+ return; //correct type of exception has been thrown >+ } catch (Exception e) { >+ fail("15.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring an empty repository to another empty repository >+ * Source contains >+ * Target contains >+ * Expected is >+ */ >+ public void testMetadataMirrorEmptyToEmpty() { >+ File emptyRepository = null; >+ try { >+ emptyRepository = metadataMirrorEmptyToPopulated("19.0", false); >+ assertTrue("Unexpected exception type", exception instanceof ProvisionException); >+ >+ try { >+ //verify destination's content >+ assertContentEquals("16.1", getMetadataRepositoryManager().loadRepository(emptyRepository.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("16.2", e); >+ } >+ } finally { >+ if (emptyRepository != null) { >+ //remove the empty repository >+ getMetadataRepositoryManager().removeRepository(emptyRepository.toURI()); >+ //delete any leftover data >+ delete(emptyRepository); >+ } >+ } >+ } >+ >+ /** >+ * Tests mirroring an empty repository to a populated repository >+ * Source contains >+ * Target contains A, B >+ * Expected is A, B >+ */ >+ public void testArtifactMirrorEmptyToPopulated() { >+ File emptyRepository = null; >+ try { >+ emptyRepository = metadataMirrorEmptyToPopulated("17.0", true); >+ assertTrue("Unexpected exception type", exception instanceof ProvisionException); >+ >+ try { >+ //verify destination's content >+ assertContains("17.1", getMetadataRepositoryManager().loadRepository(emptyRepository.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ assertContentEquals("17.2", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("17.3", e); >+ } >+ } finally { >+ if (emptyRepository != null) { >+ //remove the empty repository >+ getMetadataRepositoryManager().removeRepository(emptyRepository.toURI()); >+ //delete any leftover data >+ delete(emptyRepository); >+ } >+ } >+ } >+ >+ /** >+ * Tests mirroring an empty repository to a populated repository with "-writeMode clean" >+ * Source contains >+ * Target contains A, B >+ * Expected is >+ */ >+ public void testArtifactMirrorEmptyToPopulatedWithClean() { >+ File emptyRepository = null; >+ try { >+ emptyRepository = metadataMirrorEmptyToPopulated("18.0", false); >+ assertTrue("Unexpected exception type", exception instanceof ProvisionException); >+ >+ try { >+ //verify destination's content >+ assertContentEquals("18.1", getMetadataRepositoryManager().loadRepository(emptyRepository.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("18.2", e); >+ } >+ } finally { >+ //remove the empty repository >+ getMetadataRepositoryManager().removeRepository(emptyRepository.toURI()); >+ //delete any leftover data >+ delete(emptyRepository); >+ } >+ } >+ >+ /** >+ * Tests mirroring a repository to itself >+ * Source contains A, B >+ * Target contains A, B >+ * Expected is A, B >+ */ >+ public void testArtifactMirrorSourceIsDestination() { >+ //Setup: Populate the repository >+ runMirrorApplication("19.0", sourceRepoLocation, destRepoLocation, false); >+ >+ //run the mirror application with the source being the same as the destination >+ runMirrorApplication("19.1", destRepoLocation, destRepoLocation, true); >+ >+ try { >+ //verify destination's content >+ assertContentEquals("19.2", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("19.3", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring a repository with a different version of the same package >+ * Source contains A, B (v1.0.1) >+ * Target contains A, B (v1.0.0) >+ * Expected is A, B (v1.0.0) and A, B (v1.0.1) >+ */ >+ public void testArtifactMirrorDifferentVersions() { >+ //Setup: Populate the repository >+ runMirrorApplication("20.0", sourceRepoLocation, destRepoLocation, false); >+ >+ //start a mirror application where the source contains the same artifacts but with a different version compared to the destination >+ runMirrorApplication("20.1", sourceRepo4Location, destRepoLocation, true); >+ >+ try { >+ //verify destination's content >+ assertContains("20.2", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ assertContains("20.3", getMetadataRepositoryManager().loadRepository(sourceRepo4Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ //checks that the destination has the correct number of keys (no extras) >+ assertEquals("20.4", getNumUnique(getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null), getMetadataRepositoryManager().loadRepository(sourceRepo4Location.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null)), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null).size()); >+ } catch (ProvisionException e) { >+ fail("20.5", e); >+ } >+ } >+ >+ /** >+ * Tests how mirror application handles an unspecified source >+ */ >+ public void testArtifactMirrorNullSource() { >+ try { >+ basicRunMirrorApplication("21.1", null, destRepoLocation.toURL(), true); >+ //We expect the IllegalStateException to be thrown >+ fail("21.3 IllegalStateException not thrown"); >+ } catch (ProvisionException e) { >+ return; //expected type of exception has been thrown >+ } catch (Exception e) { >+ fail("21.2", e); >+ } >+ } >+ >+ /** >+ * Tests how mirror application handles an unspecified destination >+ */ >+ public void testArtifactMirrorNullDestination() { >+ try { >+ basicRunMirrorApplication("21.1", sourceRepoLocation.toURL(), null, true); >+ //We expect the IllegalStateException to be thrown >+ fail("22.3 IllegalStateException not thrown"); >+ } catch (ProvisionException e) { >+ return; //expected type of exception has been thrown >+ } catch (Exception e) { >+ fail("22.2", e); >+ } >+ } >+ >+ /** >+ * Tests how mirror application handles both an unspecified source and an unspecified destination >+ */ >+ public void testArtifactMirrorNullBoth() { >+ try { >+ basicRunMirrorApplication("23.0", null, null, true); >+ //We expect the IllegalStateException to be thrown >+ fail("23.2 IllegalStateException not thrown"); >+ } catch (ProvisionException e) { >+ return; //expected type of exception has been thrown >+ } catch (Exception e) { >+ fail("23.1", e); >+ } >+ } >+ >+ /** >+ * Ensures that a repository created before the mirror application is run does not have its properties changed >+ */ >+ public void testExistingArtifactRepoProperties() { >+ //Setup: create the destination >+ String name = "Destination Name"; >+ Map properties = null; //default properties >+ try { >+ //create the repository and get the resulting properties >+ properties = getMetadataRepositoryManager().createRepository(destRepoLocation.toURI(), name, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties).getProperties(); >+ } catch (ProvisionException e) { >+ fail("25.0", e); >+ } >+ >+ //run the mirror application >+ metadataMirrorToEmpty("25.2", true); >+ >+ try { >+ IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null); >+ assertEquals("25.3", name, repository.getName()); >+ assertRepositoryProperties("25.4", properties, repository.getProperties()); >+ } catch (ProvisionException e) { >+ fail("25.5", e); >+ } >+ } >+ >+ /** >+ * Ensures that a repository created by the mirror application has specified name >+ * For Bug 256909 >+ */ >+ public void testNewArtifactRepoWithNewName() { >+ String name = "Bug 256909 test - new"; >+ try { >+ //set the arguments >+ //run the mirror application >+ basicRunMirrorApplication("Bug 256909 Test", sourceRepoLocation.toURL(), destRepoLocation.toURL(), false, name); >+ } catch (MalformedURLException e) { >+ fail("Error creating URLs for Source/Detination", e); >+ } catch (Exception e) { >+ fail("Error running mirror application", e); >+ } >+ >+ try { >+ assertEquals("Assert name was set correct", name, getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null).getName()); >+ } catch (ProvisionException e) { >+ fail("Cannot obtain destination", e); >+ } >+ } >+ >+ /** >+ * Ensures that an existing destination used by the mirror application is given specified name >+ * For Bug 256909 >+ */ >+ public void testExistingArtifactRepoWithNewName() { >+ String oldName = "The original naem for Bug 256909 test - existing"; >+ String newName = "Bug 256909 test - existing"; >+ //Setup create the repository >+ IMetadataRepository destinationRepo = null; >+ try { >+ destinationRepo = getMetadataRepositoryManager().createRepository(destRepoLocation.toURI(), oldName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); >+ assertTrue(destinationRepo.isModifiable()); >+ } catch (ProvisionException e) { >+ fail("Error creating repo at destination", e); >+ } >+ assertEquals("Assert name is set correctly before mirror", oldName, destinationRepo.getName()); >+ >+ try { >+ basicRunMirrorApplication("Bug 256809 Test", sourceRepoLocation.toURL(), destRepoLocation.toURL(), true, newName); >+ } catch (MalformedURLException e) { >+ fail("Error creating URLs for Source/Detination", e); >+ } catch (Exception e) { >+ fail("Error running mirror application", e); >+ } >+ >+ try { >+ assertEquals("Assert name is set correctly after mirror", newName, getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null).getName()); >+ } catch (ProvisionException e) { >+ fail("Error loading destination", e); >+ } >+ } >+ >+ //for Bug 235683 >+ public void testMirrorCompressedSource() { >+ File compressedSource = getTestData("0", "/testData/mirror/mirrorCompressedRepo"); >+ >+ //Setup: get the content.jar file >+ File compressedMetadataXML = new File(compressedSource.getAbsoluteFile() + "/content.jar"); >+ //Setup: make sure content.jar exists >+ assertTrue("1", compressedMetadataXML.exists()); >+ >+ try { >+ basicRunMirrorApplication("2", compressedSource.toURL(), destRepoLocation.toURL(), false); >+ } catch (MalformedURLException e) { >+ fail("3", e); >+ } catch (Exception e) { >+ fail("4", e); >+ } >+ >+ //get the content.jar file >+ File destMetadataXML = new File(destRepoLocation.getAbsolutePath() + "/content.jar"); >+ //make sure content.jar exists >+ assertTrue("5", destMetadataXML.exists()); >+ } >+ >+ //for Bug 235683 >+ public void testMirrorCompressedSourcetoUncompressedDestination() { >+ File compressedSource = getTestData("0", "/testData/mirror/mirrorCompressedRepo"); >+ >+ //Setup: get the content.jar file >+ File compressedMetadataXML = new File(compressedSource.getAbsoluteFile() + "/content.jar"); >+ //Setup: make sure content.jar exists >+ assertTrue("1", compressedMetadataXML.exists()); >+ >+ //Setup: create the destination >+ try { >+ String name = "Destination Name " + destRepoLocation; >+ getMetadataRepositoryManager().createRepository(destRepoLocation.toURI(), name, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); >+ } catch (ProvisionException e) { >+ fail("2", e); >+ } >+ >+ try { >+ basicRunMirrorApplication("3", compressedSource.toURL(), destRepoLocation.toURL(), false); >+ } catch (MalformedURLException e) { >+ fail("4", e); >+ } catch (Exception e) { >+ fail("5", e); >+ } >+ >+ //get the content.jar file >+ File destMetadataXML = new File(destRepoLocation.getAbsolutePath() + "/content.jar"); >+ //make sure content.jar does not exist >+ assertFalse("6", destMetadataXML.exists()); >+ //get the content.xml file >+ destMetadataXML = new File(destRepoLocation.getAbsolutePath() + "/content.xml"); >+ //make sure content.xml exists >+ assertTrue("7", destMetadataXML.exists()); >+ } >+ >+ public void testMirrorUncompressedSourceToCompressedDestination() { >+ File uncompressedSource = getTestData("0", "/testData/mirror/mirrorSourceRepo3"); >+ >+ //Setup: get the content.xml file >+ File uncompressedContentXML = new File(uncompressedSource.getAbsoluteFile() + "/content.xml"); >+ //Setup: make sure content.xml exists >+ assertTrue("1", uncompressedContentXML.exists()); >+ >+ //Setup: create the destination >+ try { >+ String name = "Destination Name " + destRepoLocation; >+ Map property = new HashMap(); >+ property.put(IRepository.PROP_COMPRESSED, "true"); >+ getMetadataRepositoryManager().createRepository(destRepoLocation.toURI(), name, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, property); >+ } catch (ProvisionException e) { >+ fail("2", e); >+ } >+ >+ assertTrue("2.1", new File(destRepoLocation, "content.jar").exists()); >+ try { >+ basicRunMirrorApplication("3", uncompressedSource.toURL(), destRepoLocation.toURL(), false); >+ } catch (MalformedURLException e) { >+ fail("4", e); >+ } catch (Exception e) { >+ fail("5", e); >+ } >+ >+ //get the content.jar file >+ File destMetadataXML = new File(destRepoLocation.getAbsolutePath() + "/content.jar"); >+ //make sure content.jar does exist >+ assertTrue("6", destMetadataXML.exists()); >+ //get the content.xml file >+ destMetadataXML = new File(destRepoLocation.getAbsolutePath() + "/content.xml"); >+ //make sure content.xml exists >+ assertFalse("7", destMetadataXML.exists()); >+ } >+ >+ public void testMirrorApplicationWithCompositeSource() { >+ //Setup Make composite repository >+ File repoLocation = new File(getTempFolder(), "CompositeMetadataMirrorTest"); >+ AbstractProvisioningTest.delete(repoLocation); >+ IMetadataRepository repo = null; >+ try { >+ repo = getMetadataRepositoryManager().createRepository(repoLocation.toURI(), "metadata name", IMetadataRepositoryManager.TYPE_COMPOSITE_REPOSITORY, null); >+ } catch (ProvisionException e) { >+ fail("Could not create repository"); >+ } >+ //ensure proper type of repository has been created >+ if (!(repo instanceof CompositeMetadataRepository)) >+ fail("Repository is not a CompositeMetadataRepository"); >+ //Populate source >+ File child1 = getTestData("1", "/testData/mirror/mirrorSourceRepo1 with space"); >+ File child2 = getTestData("2", "/testData/mirror/mirrorSourceRepo2"); >+ ((CompositeMetadataRepository) repo).addChild(child1.toURI()); >+ ((CompositeMetadataRepository) repo).addChild(child2.toURI()); >+ >+ runMirrorApplication("Mirroring from Composite Source", repoLocation, destRepoLocation, false); >+ >+ try { >+ assertContentEquals("Verifying contents", repo, getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ >+ //Verify that result is the same as mirroring from the 2 repositories seperately >+ assertContains("3", getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ assertContains("4", getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ //checks that the destination has the correct number of keys (no extras) >+ assertEquals("5", getNumUnique(getMetadataRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null), getMetadataRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null)), getMetadataRepositoryManager().loadRepository(destRepoLocation.toURI(), null).query(InstallableUnitQuery.ANY, new Collector(), null).size()); >+ } catch (ProvisionException e) { >+ fail("Could not load destination", e); >+ } >+ } >+} >Index: src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java >diff -N src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,656 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.equinox.p2.tests.ant; >+ >+import java.io.*; >+import java.net.URI; >+import java.net.URISyntaxException; >+import java.util.Iterator; >+import java.util.Properties; >+import org.eclipse.core.runtime.*; >+import org.eclipse.equinox.internal.p2.artifact.processors.md5.Messages; >+import org.eclipse.equinox.internal.p2.director.PermissiveSlicer; >+import org.eclipse.equinox.internal.p2.metadata.InstallableUnit; >+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; >+import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; >+import org.eclipse.equinox.internal.provisional.p2.core.Version; >+import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; >+import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; >+import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; >+import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; >+import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; >+import org.eclipse.equinox.internal.provisional.p2.query.Collector; >+import org.eclipse.equinox.internal.provisional.p2.query.IQueryable; >+import org.eclipse.equinox.p2.tests.AbstractAntProvisioningTest; >+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; >+import org.eclipse.equinox.spi.p2.publisher.PublisherHelper; >+import org.eclipse.osgi.util.NLS; >+ >+public class MirrorTaskTest extends AbstractAntProvisioningTest { >+ private static final String MIRROR_TASK = "p2.mirror"; >+ private URI destinationRepo; >+ private URI artifactRepo, sliceArtifactRepo, sliceRepo, sourceRepo2, zipRepo; >+ >+ public void setUp() throws Exception { >+ super.setUp(); >+ // Get a random location to create a repository >+ destinationRepo = (new File(getTempFolder(), getUniqueString())).toURI(); >+ artifactRepo = getTestData("error loading data", "testData/mirror/mirrorPackedRepo").toURI(); >+ sourceRepo2 = getTestData("error loading data", "testData/mirror/mirrorSourceRepo2").toURI(); >+ sliceRepo = getTestData("error loading data", "testData/permissiveSlicer").toURI(); >+ sliceArtifactRepo = getTestData("error loading data", "testData/testRepos/updateSite").toURI(); >+ zipRepo = getTestData("error loading data", "/testData/mirror/zippedRepo.zip").toURI(); >+ } >+ >+ public void tearDown() throws Exception { >+ // Remove repository manager references >+ getArtifactRepositoryManager().removeRepository(destinationRepo); >+ getMetadataRepositoryManager().removeRepository(destinationRepo); >+ getArtifactRepositoryManager().removeRepository(sliceRepo); >+ getMetadataRepositoryManager().removeRepository(sliceRepo); >+ getArtifactRepositoryManager().removeRepository(sourceRepo2); >+ getMetadataRepositoryManager().removeRepository(sourceRepo2); >+ getArtifactRepositoryManager().removeRepository(zipRepo); >+ getMetadataRepositoryManager().removeRepository(zipRepo); >+ // Cleanup disk >+ delete(new File(destinationRepo).getParentFile()); >+ super.tearDown(); >+ } >+ >+ /* >+ * Test that it is possible to mirror by only specifying an Artifact repository >+ */ >+ public void testMirrorArtifactOnly() { >+ AntTaskElement mirror = createMirrorTask(TYPE_ARTIFACT); >+ mirror.addElement(createSourceElement(artifactRepo, null)); >+ runAntTask(); >+ >+ assertEquals("Different number of Artifact Keys", getArtifactKeyCount(artifactRepo), getArtifactKeyCount(destinationRepo)); >+ assertEquals("Different number of ArtifactDescriptors", getArtifactDescriptorCount(artifactRepo), getArtifactDescriptorCount(destinationRepo)); >+ } >+ >+ /* >+ * Test that it is possible to mirror when only specifying a Metadata repository >+ */ >+ public void testMirrorMetadataOnly() { >+ AntTaskElement mirror = createMirrorTask(TYPE_METADATA); >+ mirror.addElement(createSourceElement(null, sourceRepo2)); >+ runAntTask(); >+ >+ assertEquals("Different number of IUs", getIUCount(sourceRepo2), getIUCount(destinationRepo)); >+ } >+ >+ /* >+ * Test we can mirror from a zipped repository >+ */ >+ public void testMirrorFromZip() { >+ URI localAddress = null; >+ try { >+ localAddress = URIUtil.fromString(new File(zipRepo).toString()); >+ } catch (URISyntaxException e) { >+ fail("failed to convert zip repo location"); >+ } >+ AntTaskElement mirror = createMirrorTask(TYPE_BOTH); >+ mirror.addElement(createSourceElement(localAddress, localAddress)); >+ runAntTask(); >+ >+ assertEquals("Wrong number of ArtifactKeys", getArtifactKeyCount(URIUtil.toJarURI(zipRepo, null)), getArtifactKeyCount(destinationRepo)); >+ assertEquals("Wrong number of ArtifactDescriptors", getArtifactDescriptorCount(URIUtil.toJarURI(zipRepo, null)), getArtifactDescriptorCount(destinationRepo)); >+ assertEquals("Different number of IUs", getIUCount(sourceRepo2), getIUCount(destinationRepo)); >+ } >+ >+ /* >+ * Test that all IUs can be mirrored >+ */ >+ public void testMirrorAllIUSpecified() throws ProvisionException { >+ AntTaskElement mirror = createMirrorTask(TYPE_BOTH); >+ mirror.addElement(createSourceElement(sourceRepo2, sourceRepo2)); >+ addAllIUs(mirror, getMetadataRepositoryManager().loadRepository(sourceRepo2, null)); >+ runAntTask(); >+ >+ assertEquals("Different number of Artifact Keys", getArtifactKeyCount(sourceRepo2), getArtifactKeyCount(destinationRepo)); >+ assertContentEquals("IUs differ", getMetadataRepositoryManager().loadRepository(sourceRepo2, null), getMetadataRepositoryManager().loadRepository(destinationRepo, null)); >+ assertEquals("Different number of IUs", getIUCount(sourceRepo2), getIUCount(destinationRepo)); >+ assertContentEquals("Artifacts differ", getArtifactRepositoryManager().loadRepository(sourceRepo2, null), getArtifactRepositoryManager().loadRepository(destinationRepo, null)); >+ } >+ >+ /* >+ * Test that we only mirror specified IUs & Artifacts >+ */ >+ public void testMirrorSomeIUSpecified() { >+ AntTaskElement mirror = createMirrorTask(TYPE_BOTH); >+ mirror.addElement(createSourceElement(sourceRepo2, sourceRepo2)); >+ mirror.addElement(createIUElement("anotherplugin", "1.0.0")); >+ >+ runAntTask(); >+ >+ assertEquals("Wrong number of ArtifactKeys", 1, getArtifactKeyCount(destinationRepo)); >+ assertEquals("Wrong number of IUs", 1, getIUCount(destinationRepo)); >+ } >+ >+ /* >+ * Test that the proper exception is thrown when no IU is provided >+ */ >+ public void testMirrorNoIUNoRepo() { >+ AntTaskElement mirror = createMirrorTask(TYPE_BOTH); >+ mirror.addElement(createSourceElement(sourceRepo2, null)); >+ >+ Exception exception = null; >+ try { >+ runAntTaskWithExceptions(); >+ } catch (CoreException e) { >+ exception = e; >+ } >+ if (exception == null) >+ fail("No exception thrown"); >+ if (!(rootCause(exception) instanceof ProvisionException) && !rootCause(exception).getMessage().contains("No IUs")) >+ fail("Exception is of an unexpected type or message", rootCause(exception)); >+ >+ } >+ >+ /* >+ * Test that all IUs are mirrored when none are specified >+ */ >+ public void testMirrorNoIUSpecified() { >+ AntTaskElement mirror = createMirrorTask(TYPE_BOTH); >+ mirror.addElement(createSourceElement(sourceRepo2, sourceRepo2)); >+ >+ runAntTask(); >+ >+ try { >+ assertEquals("Different number of Artifact Keys", getArtifactKeyCount(sourceRepo2), getArtifactKeyCount(destinationRepo)); >+ assertContentEquals("Artifacts differ", getArtifactRepositoryManager().loadRepository(sourceRepo2, null), getArtifactRepositoryManager().loadRepository(destinationRepo, null)); >+ assertEquals("Different number of IUs", getIUCount(sourceRepo2), getIUCount(destinationRepo)); >+ assertContentEquals("IUs differ", getMetadataRepositoryManager().loadRepository(sourceRepo2, null), getMetadataRepositoryManager().loadRepository(destinationRepo, null)); >+ } catch (ProvisionException e) { >+ fail("Failed to compare results", e); >+ } >+ } >+ >+ /* >+ * Test the handling of invalid destinations with the mirror task >+ */ >+ public void testMirrorWithInvalidDestination() throws URISyntaxException { >+ URI location = new URI("invalid:/scheme"); >+ >+ AntTaskElement mirror = new AntTaskElement(MIRROR_TASK); >+ mirror.addElement(getRepositoryElement(location, TYPE_BOTH)); >+ mirror.addElement(createSourceElement(sourceRepo2, sourceRepo2)); >+ addTask(mirror); >+ >+ Throwable exception = null; >+ try { >+ runAntTaskWithExceptions(); >+ } catch (Exception e) { >+ exception = e; >+ } >+ if (exception == null) >+ fail("No Exception thrown"); >+ >+ while (exception.getCause() != null && !(exception instanceof ProvisionException)) >+ exception = exception.getCause(); >+ assertTrue("Unexpected error", NLS.bind(org.eclipse.equinox.p2.internal.repository.tools.Messages.exception_invalidDestination, location).equals(exception.getMessage())); >+ } >+ >+ /* >+ * Test the handling of invalid destinations with the mirror task >+ */ >+ public void testMirrorWithInvalidSource() throws URISyntaxException { >+ URI location = new URI("invalid:/scheme2"); >+ >+ AntTaskElement mirror = createMirrorTask(TYPE_BOTH); >+ mirror.addElement(createSourceElement(location, location)); >+ addTask(mirror); >+ >+ Throwable exception = null; >+ try { >+ runAntTaskWithExceptions(); >+ } catch (Exception e) { >+ exception = e; >+ } >+ if (exception == null) >+ fail("No Exception thrown"); >+ >+ while (exception.getCause() != null && !(exception instanceof ProvisionException)) >+ exception = exception.getCause(); >+ assertTrue("Unexpected error", NLS.bind(org.eclipse.equinox.p2.internal.repository.tools.Messages.exception_invalidSource, location).equals(exception.getMessage())); >+ } >+ >+ /* >+ * Test slicing options >+ */ >+ public void testSlicingFollowStrict() { >+ IMetadataRepository repo = null; >+ try { >+ repo = loadMetadataRepository(sliceRepo); >+ } catch (ProvisionException e) { >+ fail("Loading repository failed", e); >+ } >+ Collector c = repo.query(new InstallableUnitQuery("org.eclipse.rcp.feature.group"), new Collector(), new NullProgressMonitor()); >+ IInstallableUnit iu = (IInstallableUnit) c.iterator().next(); >+ >+ AntTaskElement mirror = createMirrorTask(TYPE_METADATA); >+ mirror.addElement(createSourceElement(null, sliceRepo)); >+ mirror.addElement(createSlicingOption(null, null, true, null, "win32,win32,x86")); >+ mirror.addElement(createIUElement(iu.getId(), iu.getVersion().toString())); >+ >+ runAntTask(); >+ >+ Properties p = getSliceProperties(); >+ p.setProperty("org.eclipse.update.install.features", String.valueOf(true)); >+ PermissiveSlicer slicer = new PermissiveSlicer(repo, p, true, true, true, true); >+ IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); >+ assertEquals("Different number of IUs", result.query(InstallableUnitQuery.ANY, new Collector(), new NullProgressMonitor()).size(), getIUCount(destinationRepo)); >+ >+ try { >+ assertIUContentEquals("IUs differ", result, getMetadataRepositoryManager().loadRepository(destinationRepo, null)); >+ } catch (ProvisionException e) { >+ fail("Failed to compare contents", e); >+ } >+ } >+ >+ public void testSlicingIncludeNonGreedy() { >+ IMetadataRepository repo = null; >+ try { >+ repo = loadMetadataRepository(sliceRepo); >+ } catch (ProvisionException e) { >+ fail("Loading repository failed", e); >+ } >+ Collector c = repo.query(new InstallableUnitQuery("org.eclipse.rcp.feature.group"), new Collector(), new NullProgressMonitor()); >+ IInstallableUnit iu = (IInstallableUnit) c.iterator().next(); >+ >+ AntTaskElement mirror = createMirrorTask(TYPE_METADATA); >+ mirror.addElement(createSourceElement(null, sliceRepo)); >+ mirror.addElement(createSlicingOption(null, false, null, null, null)); >+ mirror.addElement(createIUElement(iu.getId(), iu.getVersion().toString())); >+ >+ runAntTask(); >+ >+ PermissiveSlicer slicer = new PermissiveSlicer(repo, new Properties(), true, false, true, false); >+ IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); >+ >+ assertEquals("Different number of IUs", result.query(InstallableUnitQuery.ANY, new Collector(), new NullProgressMonitor()).size(), getIUCount(destinationRepo)); >+ try { >+ assertIUContentEquals("IUs differ", result, getMetadataRepositoryManager().loadRepository(destinationRepo, null)); >+ } catch (ProvisionException e) { >+ fail("Failed to compare contents", e); >+ } >+ } >+ >+ public void testSlicingIncludeOptionalDependencies() { >+ IMetadataRepository repo = null; >+ try { >+ repo = loadMetadataRepository(sliceRepo); >+ } catch (ProvisionException e) { >+ fail("Loading repository failed", e); >+ } >+ Collector c = repo.query(new InstallableUnitQuery("org.eclipse.rcp.feature.group"), new Collector(), new NullProgressMonitor()); >+ IInstallableUnit iu = (IInstallableUnit) c.iterator().next(); >+ >+ AntTaskElement mirror = createMirrorTask(TYPE_METADATA); >+ mirror.addElement(createSourceElement(null, sliceRepo)); >+ mirror.addElement(createSlicingOption(false, null, null, null, "win32,win32,x86")); >+ mirror.addElement(createIUElement(iu.getId(), iu.getVersion().toString())); >+ >+ runAntTask(); >+ >+ Properties p = getSliceProperties(); >+ p.setProperty("org.eclipse.update.install.features", String.valueOf(true)); >+ PermissiveSlicer slicer = new PermissiveSlicer(repo, p, false, true, true, false); >+ IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); >+ assertEquals("Different number of IUs", result.query(InstallableUnitQuery.ANY, new Collector(), new NullProgressMonitor()).size(), getIUCount(destinationRepo)); >+ try { >+ assertIUContentEquals("IUs differ", result, getMetadataRepositoryManager().loadRepository(destinationRepo, null)); >+ } catch (ProvisionException e) { >+ fail("Failed to compare contents", e); >+ } >+ } >+ >+ /* >+ * Test the platform filter >+ */ >+ public void testSlicingPlatformFilter() { >+ IMetadataRepository repo = null; >+ try { >+ repo = loadMetadataRepository(sliceRepo); >+ } catch (ProvisionException e) { >+ fail("Loading repository failed", e); >+ } >+ Collector c = repo.query(new InstallableUnitQuery("org.eclipse.rcp.feature.group"), new Collector(), new NullProgressMonitor()); >+ IInstallableUnit iu = (IInstallableUnit) c.iterator().next(); >+ >+ AntTaskElement mirror = createMirrorTask(TYPE_METADATA); >+ mirror.addElement(createSourceElement(null, sliceRepo)); >+ mirror.addElement(createSlicingOption(null, null, null, null, "win32,win32,x86")); >+ mirror.addElement(createIUElement(iu.getId(), iu.getVersion().toString())); >+ >+ runAntTask(); >+ >+ Properties p = getSliceProperties(); >+ p.setProperty("org.eclipse.update.install.features", String.valueOf(true)); >+ PermissiveSlicer slicer = new PermissiveSlicer(repo, p, true, true, true, false); >+ IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); >+ assertEquals("Different number of IUs", result.query(InstallableUnitQuery.ANY, new Collector(), new NullProgressMonitor()).size(), getIUCount(destinationRepo)); >+ try { >+ assertIUContentEquals("IUs differ", result, getMetadataRepositoryManager().loadRepository(destinationRepo, null)); >+ } catch (ProvisionException e) { >+ fail("Failed to compare contents", e); >+ } >+ } >+ >+ /* >+ * Test disabling includeFeatures for SlicingOptions >+ */ >+ public void testSlicingIncludeFeaturesFalse() { >+ IMetadataRepository repo = null; >+ try { >+ repo = loadMetadataRepository(sliceRepo); >+ } catch (ProvisionException e) { >+ fail("Loading repository failed", e); >+ } >+ Collector c = repo.query(new InstallableUnitQuery("org.eclipse.rcp.feature.group"), new Collector(), new NullProgressMonitor()); >+ IInstallableUnit iu = (IInstallableUnit) c.iterator().next(); >+ >+ // Create task >+ AntTaskElement mirror = createMirrorTask(TYPE_METADATA); >+ mirror.addElement(createSourceElement(null, sliceRepo)); >+ mirror.addElement(createSlicingOption(null, null, null, false, "win32,win32,x86")); >+ mirror.addElement(createIUElement(iu.getId(), iu.getVersion().toString())); >+ >+ runAntTask(); >+ >+ Properties p = getSliceProperties(); >+ PermissiveSlicer slicer = new PermissiveSlicer(repo, p, true, true, true, false); >+ IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); >+ assertEquals("Different number of IUs", result.query(InstallableUnitQuery.ANY, new Collector(), new NullProgressMonitor()).size(), getIUCount(destinationRepo)); >+ try { >+ assertIUContentEquals("IUs differ", result, getMetadataRepositoryManager().loadRepository(destinationRepo, null)); >+ } catch (ProvisionException e) { >+ fail("Failed to compare contents", e); >+ } >+ } >+ >+ /* >+ * Tests the results of a slice are used to mirror artifacts >+ */ >+ public void testSlicingArtifactsMirrored() { >+ IMetadataRepository repo = null; >+ try { >+ repo = loadMetadataRepository(sliceArtifactRepo); >+ } catch (ProvisionException e) { >+ fail("Loading repository failed", e); >+ } >+ Collector c = repo.query(new InstallableUnitQuery("test.feature.feature.group"), new Collector(), new NullProgressMonitor()); >+ IInstallableUnit iu = (IInstallableUnit) c.iterator().next(); >+ >+ // Create task >+ AntTaskElement mirror = createMirrorTask(TYPE_BOTH); >+ mirror.addElement(createSourceElement(sliceArtifactRepo, sliceArtifactRepo)); >+ mirror.addElement(createSlicingOption(null, null, null, false, "win32,win32,x86")); >+ mirror.addElement(createIUElement(iu.getId(), iu.getVersion().toString())); >+ >+ runAntTask(); >+ >+ Properties p = getSliceProperties(); >+ PermissiveSlicer slicer = new PermissiveSlicer(repo, p, true, true, true, false); >+ IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor()); >+ >+ assertEquals("Different number of IUs", result.query(InstallableUnitQuery.ANY, new Collector(), new NullProgressMonitor()).size(), getIUCount(destinationRepo)); >+ assertEquals("Different number of ArtifactKeys", getArtifactKeyCount(result.query(InstallableUnitQuery.ANY, new Collector(), new NullProgressMonitor())), getArtifactKeyCount(destinationRepo)); >+ try { >+ assertArtifactKeyContentEquals("Different ArtifactKeys", result.query(InstallableUnitQuery.ANY, new Collector(), new NullProgressMonitor()), destinationRepo); >+ assertIUContentEquals("IUs differ", result, getMetadataRepositoryManager().loadRepository(destinationRepo, null)); >+ } catch (ProvisionException e) { >+ fail("Failed to compare contents", e); >+ } >+ >+ } >+ >+ /* >+ * Test the result of a slice which results in no IUs >+ */ >+ public void testSlicingInvalid() { >+ AntTaskElement mirror = createMirrorTask(TYPE_METADATA); >+ mirror.addElement(createSourceElement(null, sliceRepo)); >+ mirror.addElement(createSlicingOption(null, null, null, null, "win32,win32,x86")); >+ >+ Exception exception = null; >+ try { >+ runAntTaskWithExceptions(); >+ } catch (Exception e) { >+ exception = e; >+ } >+ >+ if (exception == null || !(rootCause(exception) instanceof ProvisionException)) { >+ fail("Unexpected exception type", exception); >+ } >+ } >+ >+ /* >+ * Modified from org.eclipse.equinox.p2.tests.mirror.ArtifactMirrorApplicationTest >+ */ >+ public void testBaselineCompareUsingMD5Comparator() { >+ //Setup create descriptors with different md5 values >+ IArtifactKey dupKey = PublisherHelper.createBinaryArtifactKey("testKeyId", new Version("1.2.3")); >+ File artifact1 = getTestData("0.0", "/testData/mirror/mirrorSourceRepo1 with space/content.xml"); >+ File artifact2 = getTestData("0.0", "/testData/mirror/mirrorSourceRepo2/content.xml"); >+ >+ //Setup Copy the file to the baseline >+ File repoLocation = getTestFolder(getUniqueString()); >+ File baselineLocation = getTestFolder(getUniqueString()); >+ File baselineBinaryDirectory = new File(baselineLocation, "binary"); >+ baselineBinaryDirectory.mkdir(); >+ File baselineContentLocation = new File(baselineBinaryDirectory, "testKeyId_1.2.3"); >+ AbstractProvisioningTest.copy("Copying File to baseline", artifact2, baselineContentLocation); >+ >+ IArtifactDescriptor descriptor1 = PublisherHelper.createArtifactDescriptor(dupKey, artifact1); >+ IArtifactDescriptor descriptor2 = PublisherHelper.createArtifactDescriptor(dupKey, baselineContentLocation); >+ >+ assertEquals("Ensuring Descriptors are the same", descriptor1, descriptor2); >+ assertNotSame("Ensuring MD5 values are different", descriptor1.getProperty(IArtifactDescriptor.DOWNLOAD_MD5), descriptor2.getProperty(IArtifactDescriptor.DOWNLOAD_MD5)); >+ >+ //Setup make repositories >+ IArtifactRepository repo = null; >+ IArtifactRepository baseline = null; >+ try { >+ repo = createRepositoryWithIU(repoLocation.toURI(), descriptor1); >+ baseline = createRepositoryWithIU(baselineLocation.toURI(), descriptor2); >+ } catch (ProvisionException e) { >+ fail("Error creating repositories", e); >+ } >+ >+ //Comparator prints to stderr, redirect that to a file >+ PrintStream oldErr = System.err; >+ PrintStream newErr = null; >+ PrintStream oldOut = System.out; >+ PrintStream newOut = null; >+ try { >+ (new File(destinationRepo)).mkdir(); >+ newErr = new PrintStream(new FileOutputStream(new File(new File(destinationRepo), "sys.err"))); >+ newOut = new PrintStream(new FileOutputStream(new File(new File(destinationRepo), "sys.out"))); >+ } catch (FileNotFoundException e) { >+ fail("Error redirecting outputs", e); >+ } >+ >+ try { >+ System.setErr(newErr); >+ System.setOut(newOut); >+ >+ // Create task >+ AntTaskElement mirror = createMirrorTask(TYPE_BOTH); >+ // Add source >+ mirror.addElement(createSourceElement(repoLocation.toURI(), repoLocation.toURI())); >+ // set verbose >+ mirror.addAttribute("verbose", String.valueOf(true)); >+ >+ // Create a comparator element >+ AntTaskElement comparator = new AntTaskElement("comparator"); >+ comparator.addElement(getRepositoryElement(baselineLocation.toURI(), null)); >+ mirror.addElement(comparator); >+ >+ runAntTaskWithExceptions(); >+ } catch (Exception e) { >+ fail("Running mirror application with baseline compare", rootCause(e)); >+ } finally { >+ System.setErr(oldErr); >+ newErr.close(); >+ System.setOut(oldOut); >+ newOut.close(); >+ } >+ >+ IArtifactRepository destination = null; >+ try { >+ destination = getArtifactRepositoryManager().loadRepository(destinationRepo, null); >+ } catch (ProvisionException e) { >+ fail("Error loading destination", e); >+ } >+ >+ IArtifactDescriptor[] destDescriptors = destination.getArtifactDescriptors(descriptor2.getArtifactKey()); >+ assertEquals("Ensuring destination has correct number of descriptors", 1, destDescriptors.length); >+ assertEquals("Ensuring destination contains the descriptor from the baseline", descriptor2.getProperty(IArtifactDescriptor.DOWNLOAD_MD5), destDescriptors[0].getProperty(IArtifactDescriptor.DOWNLOAD_MD5)); >+ String msg = NLS.bind(Messages.warning_differentMD5, new Object[] {URIUtil.toUnencodedString(baseline.getLocation()), URIUtil.toUnencodedString(repo.getLocation()), descriptor1}); >+ >+ assertLogContains(msg); >+ } >+ >+ private Properties getSliceProperties() { >+ Properties p = new Properties(); >+ p.setProperty("osgi.os", "win32"); >+ p.setProperty("osgi.ws", "win32"); >+ p.setProperty("osgi.arch", "x86"); >+ return p; >+ } >+ >+ protected AntTaskElement createSlicingOption(Boolean includeOptional, Boolean includeNonGreedy, Boolean followStrict, Boolean includeFeatures, String platformFilter) { >+ AntTaskElement slicing = new AntTaskElement("slicingoptions"); >+ if (followStrict != null) >+ slicing.addAttribute("followstrict", followStrict.toString()); >+ if (includeFeatures != null) >+ slicing.addAttribute("includefeatures", includeFeatures.toString()); >+ if (includeNonGreedy != null) >+ slicing.addAttribute("includenongreedy", includeNonGreedy.toString()); >+ if (includeOptional != null) >+ slicing.addAttribute("includeoptional", includeOptional.toString()); >+ if (platformFilter != null) >+ slicing.addAttribute("platformfilter", platformFilter); >+ return slicing; >+ } >+ >+ /* >+ * Create an IU for a descriptor and the IU+descriptor to the specified repo >+ */ >+ protected IArtifactRepository createRepositoryWithIU(URI repoLocation, IArtifactDescriptor descriptor) throws ProvisionException { >+ IArtifactRepository artifactRepository = getArtifactRepositoryManager().createRepository(repoLocation, "Repo 1", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); >+ artifactRepository.addDescriptor(descriptor); >+ >+ IMetadataRepository metaRepo = getMetadataRepositoryManager().createRepository(repoLocation, "Repo", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); >+ InstallableUnit iu = new InstallableUnit(); >+ iu.setId(descriptor.getArtifactKey().getId() + "IU"); >+ iu.setVersion(descriptor.getArtifactKey().getVersion()); >+ iu.setArtifacts(new IArtifactKey[] {descriptor.getArtifactKey()}); >+ metaRepo.addInstallableUnits(new IInstallableUnit[] {iu}); >+ >+ return artifactRepository; >+ } >+ >+ /* >+ * Get the number of ArtifactKeys in a repository >+ */ >+ protected int getArtifactKeyCount(URI location) { >+ try { >+ return getArtifactRepositoryManager().loadRepository(location, null).getArtifactKeys().length; >+ } catch (ProvisionException e) { >+ fail("Failed to load repository " + URIUtil.toUnencodedString(location) + " for ArtifactDescriptor count"); >+ return -1; >+ } >+ } >+ >+ /* >+ * Get the number of ArtifactKeys in a repository >+ */ >+ protected int getArtifactKeyCount(Collector ius) { >+ int count = 0; >+ for (Iterator iter = ius.iterator(); iter.hasNext();) >+ count += ((InstallableUnit) iter.next()).getArtifacts().length; >+ return count; >+ } >+ >+ /* >+ * Get the number of ArtifactDescriptors in a repository >+ */ >+ protected int getArtifactDescriptorCount(URI location) { >+ int count = 0; >+ try { >+ IArtifactRepository repo = getArtifactRepositoryManager().loadRepository(location, null); >+ IArtifactKey[] keys = repo.getArtifactKeys(); >+ for (int i = 0; i < keys.length; i++) >+ count += repo.getArtifactDescriptors(keys[i]).length; >+ } catch (ProvisionException e) { >+ fail("Failed to load repository " + URIUtil.toUnencodedString(location) + " for ArtifactDescriptor count"); >+ } >+ return count; >+ } >+ >+ /* >+ * Get the number of IUs in a repository >+ */ >+ protected int getIUCount(URI location) { >+ try { >+ return getMetadataRepositoryManager().loadRepository(location, null).query(InstallableUnitQuery.ANY, new Collector(), null).size(); >+ } catch (ProvisionException e) { >+ fail("Failed to load repository " + URIUtil.toUnencodedString(location) + " for ArtifactDescriptor count"); >+ return -1; >+ } >+ } >+ >+ /* >+ * Add all IUs to the parent element >+ */ >+ protected void addAllIUs(AntTaskElement parent, IMetadataRepository repo) { >+ Collector collector = repo.query(InstallableUnitQuery.ANY, new Collector(), null); >+ >+ for (Iterator iter = collector.iterator(); iter.hasNext();) { >+ IInstallableUnit iu = (IInstallableUnit) iter.next(); >+ parent.addElement(createIUElement(iu.getId(), iu.getVersion().toString())); >+ } >+ } >+ >+ /* >+ * Create an element from the specified information >+ */ >+ protected AntTaskElement createIUElement(String id, String version) { >+ AntTaskElement iu = new AntTaskElement("iu"); >+ iu.addAttributes(new String[] {"id", id, "version", version}); >+ return iu; >+ } >+ >+ /* >+ * Create the base mirror task & add it to the script >+ */ >+ protected AntTaskElement createMirrorTask(String type) { >+ AntTaskElement mirror = new AntTaskElement(MIRROR_TASK); >+ mirror.addElement(getRepositoryElement(destinationRepo, type)); >+ addTask(mirror); >+ return mirror; >+ } >+ >+ /* >+ * Create a source element with the specified repositories >+ */ >+ protected AntTaskElement createSourceElement(URI artifact, URI metadata) { >+ AntTaskElement source = new AntTaskElement("source"); >+ if (artifact != null) >+ source.addElement(getRepositoryElement(artifact, AbstractAntProvisioningTest.TYPE_ARTIFACT)); >+ if (metadata != null) >+ source.addElement(getRepositoryElement(metadata, AbstractAntProvisioningTest.TYPE_METADATA)); >+ return source; >+ } >+} >Index: src/org/eclipse/equinox/p2/tests/ant/CompositeRepositoryTaskTest.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/tests/ant/CompositeRepositoryTaskTest.java >diff -N src/org/eclipse/equinox/p2/tests/ant/CompositeRepositoryTaskTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/tests/ant/CompositeRepositoryTaskTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,455 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.equinox.p2.tests.ant; >+ >+import java.io.File; >+import java.net.MalformedURLException; >+import java.net.URI; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.URIUtil; >+import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository; >+import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository; >+import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; >+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; >+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; >+import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; >+import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; >+import org.eclipse.equinox.internal.provisional.p2.repository.ICompositeRepository; >+import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; >+import org.eclipse.equinox.p2.tests.AbstractAntProvisioningTest; >+ >+public class CompositeRepositoryTaskTest extends AbstractAntProvisioningTest { >+ private static final String ADD_ELEMENT = "add"; >+ private static final String REMOVE_ELEMENT = "remove"; >+ private URI compositeSite; >+ private URI childSite, childSite2; >+ >+ public void setUp() throws Exception { >+ super.setUp(); >+ // Get a random location to create a repository >+ compositeSite = (new File(getTempFolder(), getUniqueString())).toURI(); >+ childSite = getTestData("Loading test data", "testData/testRepos/simple.1").toURI(); >+ childSite2 = new URI("memory:/in/memory"); >+ } >+ >+ public void tearDown() throws Exception { >+ // Remove repository manager references >+ getArtifactRepositoryManager().removeRepository(compositeSite); >+ getMetadataRepositoryManager().removeRepository(compositeSite); >+ >+ getArtifactRepositoryManager().removeRepository(childSite); >+ getMetadataRepositoryManager().removeRepository(childSite); >+ getArtifactRepositoryManager().removeRepository(childSite2); >+ getMetadataRepositoryManager().removeRepository(childSite2); >+ >+ // Cleanup disk >+ delete(new File(compositeSite)); >+ super.tearDown(); >+ } >+ >+ /* >+ * Test adding a child to an existing artifact repository >+ */ >+ public void testAddChildToExistingArtifactRepository() throws Exception { >+ // Create repository >+ createCompositeRepository(TYPE_ARTIFACT); >+ // Create the modify repository task >+ AntTaskElement modify = createCompositeRepositoryTaskElement(TYPE_ARTIFACT); >+ addTask(modify); >+ >+ // Create the Add element >+ AntTaskElement add = new AntTaskElement(ADD_ELEMENT); >+ add.addElement(getRepositoryElement(childSite, TYPE_ARTIFACT)); >+ modify.addElement(add); >+ >+ // Run the task >+ runAntTask(); >+ >+ CompositeArtifactRepository repo = (CompositeArtifactRepository) getCompositeRepository(TYPE_ARTIFACT); >+ assertTrue("Repository does not contain child", repo.getChildren().contains(childSite)); >+ } >+ >+ /* >+ * Test what occurs when no children are added to the newly created Composite repository >+ */ >+ public void testCreateNoChidlren() { >+ AntTaskElement modify = createCompositeRepositoryTaskElement(TYPE_BOTH); >+ addTask(modify); >+ runAntTask(); >+ >+ if (getArtifactRepositoryManager().contains(compositeSite)) >+ getArtifactRepositoryManager().removeRepository(compositeSite); >+ if (getMetadataRepositoryManager().contains(compositeSite)) >+ getMetadataRepositoryManager().removeRepository(compositeSite); >+ >+ ICompositeRepository artifact = null; >+ ICompositeRepository metadata = null; >+ try { >+ artifact = (ICompositeRepository) getArtifactRepositoryManager().loadRepository(compositeSite, null); >+ metadata = (ICompositeRepository) getMetadataRepositoryManager().loadRepository(compositeSite, null); >+ } catch (ProvisionException e) { >+ fail("Failed to load repositories", e); >+ } >+ assertTrue("Artifact Repository contains children", artifact.getChildren().isEmpty()); >+ assertTrue("Metadata Repository contains children", metadata.getChildren().isEmpty()); >+ } >+ >+ /* >+ * Test adding a child to an existing metadata repository >+ */ >+ public void testAddChildToExistingMetadataRepository() { >+ // Create repository >+ createCompositeRepository(TYPE_METADATA); >+ // Create the modify repository task >+ AntTaskElement modify = createCompositeRepositoryTaskElement(TYPE_METADATA); >+ addTask(modify); >+ >+ // Create the Add element >+ AntTaskElement add = new AntTaskElement(ADD_ELEMENT); >+ add.addElement(getRepositoryElement(childSite, TYPE_METADATA)); >+ modify.addElement(add); >+ >+ // Run the task >+ runAntTask(); >+ >+ CompositeMetadataRepository repo = (CompositeMetadataRepository) getCompositeRepository(TYPE_METADATA); >+ assertTrue("Repository does not contain child", repo.getChildren().contains(childSite)); >+ } >+ >+ /* >+ * Test adding a child to both types of repositories (which already exist) >+ */ >+ public void testAddChildToExistingRepositories() { >+ // Create repository >+ createCompositeRepository(null); >+ // Create the modify repository task >+ AntTaskElement modify = createCompositeRepositoryTaskElement(null); >+ addTask(modify); >+ >+ // Create the Add element >+ modify.addElement(createAddElement(null, new URI[] {childSite})); >+ >+ // Run the task >+ runAntTask(); >+ >+ CompositeArtifactRepository artifactRepo = (CompositeArtifactRepository) getCompositeRepository(TYPE_ARTIFACT); >+ assertTrue("Repository does not contain child", artifactRepo.getChildren().contains(childSite)); >+ >+ CompositeMetadataRepository metadataRepo = (CompositeMetadataRepository) getCompositeRepository(TYPE_METADATA); >+ assertTrue("Repository does not contain child", metadataRepo.getChildren().contains(childSite)); >+ } >+ >+ /* >+ * Test the ability to remove all children >+ */ >+ public void testRemoveAllChildren() { >+ // Create repository >+ ICompositeRepository parent = createCompositeRepository(TYPE_ARTIFACT); >+ parent.addChild(childSite); >+ >+ // Create the modify repository task >+ AntTaskElement modify = new AntTaskElement("p2.composite.repository"); >+ AntTaskElement destination = getRepositoryElement(compositeSite, TYPE_ARTIFACT); >+ destination.addAttribute("append", String.valueOf(false)); >+ modify.addElement(destination); >+ addTask(modify); >+ >+ // Run the task >+ runAntTask(); >+ >+ CompositeArtifactRepository artifactRepo = (CompositeArtifactRepository) getCompositeRepository(TYPE_ARTIFACT); >+ assertTrue("Children not removed", artifactRepo.getChildren().isEmpty()); >+ >+ } >+ >+ /* >+ * Test the removal of specified children >+ */ >+ public void testRemoveChild() { >+ ICompositeRepository repo = createCompositeRepository(TYPE_ARTIFACT); >+ try { >+ getArtifactRepositoryManager().loadRepository(childSite, null); >+ getArtifactRepositoryManager().createRepository(childSite2, "Child site", IArtifactRepositoryManager.TYPE_COMPOSITE_REPOSITORY, null); >+ >+ repo.addChild(childSite); >+ repo.addChild(childSite2); >+ } catch (ProvisionException e) { >+ fail("Failed to create child repositories"); >+ } >+ getArtifactRepositoryManager().removeRepository(compositeSite); >+ >+ AntTaskElement modify = createCompositeRepositoryTaskElement(TYPE_ARTIFACT); >+ modify.addElement(createRemoveElement(TYPE_ARTIFACT, new URI[] {childSite})); >+ addTask(modify); >+ >+ runAntTask(); >+ >+ repo = getCompositeRepository(TYPE_ARTIFACT); >+ >+ assertFalse(repo.getChildren().contains(childSite)); >+ assertTrue(repo.getChildren().contains(childSite2)); >+ } >+ >+ /* >+ * Test creating a CompositeArtifactRepository >+ */ >+ public void testCreateCompositeArtifactRepository() throws Exception { >+ // Create Composite Repository Task >+ AntTaskElement createCompositeTask = createCompositeRepositoryTaskElement(TYPE_ARTIFACT); >+ addTask(createCompositeTask); >+ >+ runAntTask(); >+ >+ assertTrue(getArtifactRepositoryManager().contains(compositeSite)); >+ assertTrue(getArtifactRepositoryManager().loadRepository(compositeSite, null) instanceof CompositeArtifactRepository); >+ assertFalse("Metadata repository does not exists", getMetadataRepositoryManager().contains(compositeSite)); >+ } >+ >+ /* >+ * Test creating a CompositeMetadataRepository >+ */ >+ public void testCreateCompositeMetadataRepository() throws Exception { >+ // Create Composite Repository Task >+ AntTaskElement createCompositeTask = createCompositeRepositoryTaskElement(TYPE_METADATA); >+ addTask(createCompositeTask); >+ >+ runAntTask(); >+ >+ assertTrue("Metadata repository does not exists", getMetadataRepositoryManager().contains(compositeSite)); >+ assertTrue("Metadata repository is not a CompositeRepository", getMetadataRepositoryManager().loadRepository(compositeSite, null) instanceof CompositeMetadataRepository); >+ assertFalse("Artifact repository also exists", getArtifactRepositoryManager().contains(compositeSite)); >+ } >+ >+ /* >+ * Tests the ability to create both Artifact & Metadata repositories at once. >+ */ >+ public void testCreateCombinedCompositeRepository() throws Exception { >+ // Create Composite Repository Task >+ AntTaskElement createCompositeTask = createCompositeRepositoryTaskElement(null); >+ addTask(createCompositeTask); >+ >+ runAntTask(); >+ >+ assertTrue("Metadata repository does not exists", getMetadataRepositoryManager().contains(compositeSite)); >+ assertTrue("Artifact repository does not exists", getArtifactRepositoryManager().contains(compositeSite)); >+ assertTrue("Metadata repository is not a CompositeRepository", getMetadataRepositoryManager().loadRepository(compositeSite, null) instanceof CompositeMetadataRepository); >+ assertTrue("Artifact repository is not a CompositeRepository", getArtifactRepositoryManager().loadRepository(compositeSite, null) instanceof CompositeArtifactRepository); >+ } >+ >+ /* >+ * Test that failOnExists attribute is honoured >+ */ >+ public void testFailOnExists() throws Exception { >+ // Create Composite Repository Task >+ AntTaskElement createCompositeTask = createCompositeRepositoryTaskElement(TYPE_ARTIFACT); >+ addTask(createCompositeTask); >+ runAntTask(); >+ >+ // Set failOnExists >+ createCompositeTask.addAttributes(new String[] {"failOnExists", String.valueOf(true)}); >+ >+ Throwable exception = null; >+ try { >+ runAntTaskWithExceptions(); >+ } catch (CoreException e) { >+ exception = rootCause(e); >+ } >+ if (!exception.getMessage().contains("exists")) >+ fail("Unexpected exception: ", exception); >+ } >+ >+ /* >+ * Test that not-compressed attribute is honoured >+ */ >+ public void testNotCompressed() throws Exception { >+ // Create Composite Repository Task >+ AntTaskElement createCompositeTask = createCompositeRepositoryTaskElement(TYPE_ARTIFACT); >+ addTask(createCompositeTask); >+ // Set the compressed attribute to false >+ ((AntTaskElement) createCompositeTask.elements.get(0)).addAttributes(new String[] {"compressed", String.valueOf(false)}); >+ runAntTask(); >+ >+ ICompositeRepository repo = getCompositeRepository(TYPE_ARTIFACT); >+ assertTrue(repo instanceof CompositeArtifactRepository); >+ assertFalse("The repository is compressed", Boolean.valueOf((String) repo.getProperties().get(IRepository.PROP_COMPRESSED))); >+ } >+ >+ /* >+ * Test that the name is properly set on a newly created repository >+ */ >+ public void testName() { >+ String repoName = "My Test Repository"; >+ // Create Composite Repository Task >+ AntTaskElement createCompositeTask = createCompositeRepositoryTaskElement(TYPE_ARTIFACT); >+ addTask(createCompositeTask); >+ // Set the repository name >+ ((AntTaskElement) createCompositeTask.elements.get(0)).addAttributes(new String[] {"name", repoName}); >+ >+ runAntTask(); >+ >+ try { >+ IArtifactRepository repo = getArtifactRepositoryManager().loadRepository(compositeSite, null); >+ assertTrue(repo instanceof CompositeArtifactRepository); >+ assertEquals(repoName, repo.getName()); >+ } catch (ProvisionException e) { >+ fail("Failed to load repository", e); >+ } >+ } >+ >+ /* >+ * Test adding a child to a new artifact repository >+ */ >+ public void testAddChildToNewArtifactRepository() { >+ // Create Composite Repository Task >+ AntTaskElement createCompositeTask = createCompositeRepositoryTaskElement(TYPE_ARTIFACT); >+ addTask(createCompositeTask); >+ >+ // Create add element >+ AntTaskElement addElement = new AntTaskElement("add"); >+ // Add a repository >+ addElement.addElement(getRepositoryElement(childSite, TYPE_ARTIFACT)); >+ createCompositeTask.addElement(addElement); >+ >+ runAntTask(); >+ >+ try { >+ CompositeArtifactRepository repo = (CompositeArtifactRepository) getArtifactRepositoryManager().loadRepository(compositeSite, null); >+ assertTrue(repo.getChildren().contains(childSite)); >+ assertEquals("More than one child present", 1, repo.getChildren().size()); >+ } catch (ProvisionException e) { >+ fail("Failed to load repository", e); >+ } >+ } >+ >+ /* >+ * Test adding a child to a new metadata repository >+ */ >+ public void testAddChildToNewMetadataRepository() { >+ // Create Composite Repository Task >+ AntTaskElement createCompositeTask = createCompositeRepositoryTaskElement(TYPE_METADATA); >+ addTask(createCompositeTask); >+ >+ // Create add element >+ AntTaskElement addElement = new AntTaskElement("add"); >+ // Add a repository >+ addElement.addElement(getRepositoryElement(childSite, TYPE_METADATA)); >+ createCompositeTask.addElement(addElement); >+ >+ runAntTask(); >+ >+ try { >+ ICompositeRepository repo = (ICompositeRepository) getMetadataRepositoryManager().loadRepository(compositeSite, null); >+ assertTrue(repo.getChildren().contains(childSite)); >+ assertEquals("More than one child present", 1, repo.getChildren().size()); >+ } catch (ProvisionException e) { >+ fail("Failed to load repository", e); >+ } >+ } >+ >+ /* >+ * Test how the task behaves with an invalid location >+ */ >+ public void testInvalidLocation() throws Exception { >+ URI location = URIUtil.fromString("scheme:/location"); >+ AntTaskElement createCompositeTask = new AntTaskElement("p2.composite.repository"); >+ createCompositeTask.addElement(getRepositoryElement(location, TYPE_ARTIFACT)); >+ addTask(createCompositeTask); >+ >+ Exception exception = null; >+ try { >+ runAntTaskWithExceptions(); >+ } catch (CoreException e) { >+ exception = e; >+ if (!(rootCause(e) instanceof MalformedURLException)) >+ fail("Expected MalformedURLException.", e); >+ else { >+ try { >+ getArtifactRepositoryManager().loadRepository(location, null); >+ fail("Repository with invalid location loaded."); >+ } catch (ProvisionException e2) { >+ // This is a success >+ } >+ } >+ } >+ if (exception == null) >+ fail("No exception thrown"); >+ } >+ >+ /* >+ * Get the composite repository at the default location >+ */ >+ protected ICompositeRepository getCompositeRepository(String type) { >+ try { >+ if (type == TYPE_ARTIFACT) { >+ return (ICompositeRepository) getArtifactRepositoryManager().loadRepository(compositeSite, null); >+ } else if (type == TYPE_METADATA) >+ return (ICompositeRepository) getMetadataRepositoryManager().loadRepository(compositeSite, null); >+ else >+ fail("No type specified"); >+ } catch (ProvisionException e) { >+ fail("Failed to load repository", e); >+ } catch (ClassCastException e) { >+ fail("Repository is not composite", e); >+ } >+ // Will not occur >+ return null; >+ } >+ >+ /* >+ * Create an "remove" AntTaskElement for the specified addresses >+ */ >+ protected AntTaskElement createRemoveElement(String type, URI[] addresses) { >+ AntTaskElement add = new AntTaskElement(REMOVE_ELEMENT); >+ for (int i = 0; i < addresses.length; i++) >+ add.addElement(getRepositoryElement(addresses[i], type)); >+ return add; >+ } >+ >+ /* >+ * Create an "add" AntTaskElement for the specified addresses >+ */ >+ protected AntTaskElement createAddElement(String type, URI[] addresses) { >+ AntTaskElement add = new AntTaskElement(ADD_ELEMENT); >+ for (int i = 0; i < addresses.length; i++) >+ add.addElement(getRepositoryElement(addresses[i], type)); >+ return add; >+ } >+ >+ /* >+ * Create an AntTaskElement representing a p2 composite repository task with the default repo location specified >+ */ >+ protected AntTaskElement createCompositeRepositoryTaskElement(String type) { >+ AntTaskElement compositeTask = new AntTaskElement("p2.composite.repository"); >+ compositeTask.addElement(getRepositoryElement(compositeSite, type)); >+ >+ return compositeTask; >+ } >+ >+ /* >+ * Create a composite repository at the default location of the specified type(s) >+ */ >+ protected ICompositeRepository createCompositeRepository(String type) { >+ ICompositeRepository repo = null; >+ try { >+ if (TYPE_ARTIFACT.equals(type) || type == null) { >+ repo = (ICompositeRepository) RepositoryHelper.validDestinationRepository(getArtifactRepositoryManager().createRepository(compositeSite, "Test Composite Repo", IArtifactRepositoryManager.TYPE_COMPOSITE_REPOSITORY, null)); >+ } >+ if (TYPE_METADATA.equals(type) || type == null) { >+ repo = (ICompositeRepository) RepositoryHelper.validDestinationRepository(getMetadataRepositoryManager().createRepository(compositeSite, "Test Composite Repo", IMetadataRepositoryManager.TYPE_COMPOSITE_REPOSITORY, null)); >+ } >+ } catch (ProvisionException e) { >+ fail("Failed to create composite repository", e); >+ } catch (IllegalStateException e) { >+ fail("failed to create writeable composite repository", e); >+ } >+ return repo; >+ } >+} >Index: src/org/eclipse/equinox/p2/tests/ant/AllTests.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/tests/ant/AllTests.java >diff -N src/org/eclipse/equinox/p2/tests/ant/AllTests.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/tests/ant/AllTests.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,27 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.equinox.p2.tests.ant; >+ >+import junit.framework.*; >+ >+/** >+ * Performs all automated artifact repository tests. >+ */ >+public class AllTests extends TestCase { >+ >+ public static Test suite() { >+ TestSuite suite = new TestSuite(AllTests.class.getName()); >+ suite.addTestSuite(CompositeRepositoryTaskTest.class); >+ suite.addTestSuite(MirrorTaskTest.class); >+ return suite; >+ } >+ >+} >\ No newline at end of file >Index: src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java >diff -N src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/tests/mirror/NewMirrorApplicationArtifactTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,1467 @@ >+/******************************************************************************* >+ * Copyright (c) 2008, 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.equinox.p2.tests.mirror; >+ >+import java.io.*; >+import java.net.MalformedURLException; >+import java.net.URI; >+import java.util.*; >+import org.eclipse.core.runtime.*; >+import org.eclipse.equinox.internal.p2.artifact.processors.md5.Messages; >+import org.eclipse.equinox.internal.p2.artifact.repository.*; >+import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository; >+import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties; >+import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; >+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*; >+import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; >+import org.eclipse.equinox.internal.provisional.p2.core.Version; >+import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; >+import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; >+import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication; >+import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor; >+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest; >+import org.eclipse.equinox.p2.tests.TestActivator; >+import org.eclipse.equinox.spi.p2.publisher.PublisherHelper; >+import org.eclipse.osgi.framework.log.FrameworkLog; >+import org.eclipse.osgi.util.NLS; >+ >+/* >+ * Modified from ArtifactMirrorApplicationTest >+ */ >+public class NewMirrorApplicationArtifactTest extends AbstractProvisioningTest { >+ protected File destRepoLocation; >+ protected File sourceRepoLocation; //helloworldfeature >+ protected File sourceRepo2Location; //anotherfeature >+ protected File sourceRepo3Location; //helloworldfeature + yetanotherfeature >+ protected File sourceRepo4Location; //helloworldfeature v1.0.1 >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.equinox.p2.tests.AbstractProvisioningTest#setUp() >+ */ >+ protected void setUp() throws Exception { >+ super.setUp(); >+ //load all the repositories >+ sourceRepoLocation = getTestData("0.0", "/testData/mirror/mirrorSourceRepo1 with space"); >+ sourceRepo2Location = getTestData("0.1", "/testData/mirror/mirrorSourceRepo2"); >+ sourceRepo3Location = getTestData("0.2", "/testData/mirror/mirrorSourceRepo3"); >+ sourceRepo4Location = getTestData("0.3", "/testData/mirror/mirrorSourceRepo4"); >+ >+ //create destination location >+ destRepoLocation = new File(getTempFolder(), "BasicMirrorApplicationTest"); >+ delete(destRepoLocation); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.equinox.p2.tests.AbstractProvisioningTest#tearDown() >+ */ >+ protected void tearDown() throws Exception { >+ //remove all the repositories >+ getArtifactRepositoryManager().removeRepository(destRepoLocation.toURI()); >+ getArtifactRepositoryManager().removeRepository(sourceRepoLocation.toURI()); >+ getArtifactRepositoryManager().removeRepository(sourceRepo2Location.toURI()); >+ getArtifactRepositoryManager().removeRepository(sourceRepo3Location.toURI()); >+ getArtifactRepositoryManager().removeRepository(sourceRepo4Location.toURI()); >+ //delete the destination location (no left over files for the next test) >+ delete(destRepoLocation); >+ super.tearDown(); >+ } >+ >+ private void basicRunMirrorApplication(String message, URI source, URI destination, Boolean append, Boolean formatDestination, String destName) throws Exception { >+ MirrorApplication app = new MirrorApplication(); >+ >+ if (destination != null) { >+ RepositoryDescriptor dest = null; >+ if (formatDestination != null && formatDestination) >+ dest = createRepositoryDescriptor(destination, append, source, destName); >+ else >+ dest = createRepositoryDescriptor(destination, append, null, destName); >+ app.addDestination(dest); >+ } >+ >+ if (source != null) { >+ RepositoryDescriptor src = createRepositoryDescriptor(source, null, null, null); >+ app.addSource(src); >+ } >+ app.run(null); >+ } >+ >+ private void basicRunMirrorApplication(String message, URI source, URI destination, Boolean append, Boolean formatDestination) throws Exception { >+ basicRunMirrorApplication(message, source, destination, append, formatDestination, null); >+ } >+ >+ private void basicRunMirrorApplication(String message, URI source, URI destination) throws Exception { >+ basicRunMirrorApplication(message, source, destination, null, null, null); >+ } >+ >+ private RepositoryDescriptor createRepositoryDescriptor(URI location, Boolean append, URI format, String name) { >+ RepositoryDescriptor descriptor = new RepositoryDescriptor(); >+ descriptor.setLocation(location); >+ descriptor.setKind("artifact"); >+ if (append != null) >+ descriptor.setAppend(append); >+ if (format != null) >+ descriptor.setFormat(format); >+ if (name != null) >+ descriptor.setName(name); >+ return descriptor; >+ } >+ >+ /** >+ * just a wrapper method for compatibility >+ */ >+ private void runMirrorApplication(String message, File source, File destination, boolean append) { >+ try { >+ basicRunMirrorApplication(message, source.toURI(), destination.toURI(), append, false); >+ } catch (Exception e) { >+ fail(message, e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to an empty repository >+ * Source contains A, B >+ * Target contains >+ */ >+ private void artifactMirrorToEmpty(String message, boolean append, boolean format) { >+ try { >+ //destination repo is created blank >+ basicRunMirrorApplication(message, sourceRepoLocation.toURI(), destRepoLocation.toURI(), append, format); >+ } catch (Exception e) { >+ fail(message, e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to a repository populated with non-duplicate entries >+ * Source contains A, B >+ * Target contains C, D >+ */ >+ private void artifactMirrorToPopulated(String message, boolean append) { >+ //Setup: populate destination with non-duplicate artifacts >+ runMirrorApplication(message + ".0", sourceRepo2Location, destRepoLocation, false); //value of append should not matter >+ >+ try { >+ //Setup ensure setup completes successfully >+ assertContentEquals(message + ".1", getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail(message + ".2", e); >+ } >+ >+ //mirror test data >+ runMirrorApplication(message + ".4", sourceRepoLocation, destRepoLocation, append); >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to a repository populated with exact duplicate data >+ * Source contains A, B >+ * Target contains A, B >+ */ >+ private void artifactMirrorToFullDuplicate(String message, boolean append) { >+ //Setup: populate destination with duplicate artifacts >+ runMirrorApplication(message + ".0", sourceRepoLocation, destRepoLocation, false); //value of append should not matter >+ >+ try { >+ //Setup: verify contents >+ assertContentEquals(message + ".1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail(message + ".2", e); >+ } >+ >+ //mirror test data >+ runMirrorApplication(message + ".4", sourceRepoLocation, destRepoLocation, append); >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to a repository populated with partially duplicate data >+ * Source contains A, B, C, D >+ * Target contains A, B >+ */ >+ private void artifactMirrorToPartialDuplicate(String message, boolean append) { >+ //Setup: populate destination with duplicate artifacts >+ runMirrorApplication(message + ".0", sourceRepoLocation, destRepoLocation, false); >+ >+ try { >+ //Setup: verify contents >+ assertContentEquals(message + ".1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail(message + ".2", e); >+ } >+ >+ //mirror test data >+ runMirrorApplication(message + ".4", sourceRepo3Location, destRepoLocation, append); >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to a repository populated with both full duplicate and non-duplicate data >+ * Source contains A, B >+ * Target contains A, B, C, D >+ */ >+ private void artifactMirrorToPopulatedWithFullDuplicate(String message, boolean append) { >+ //Setup: populate destination with non-duplicate artifacts >+ runMirrorApplication(message + ".0", sourceRepo3Location, destRepoLocation, false); //value of append should not matter >+ >+ try { >+ //Setup: verify >+ assertContentEquals(message + ".1", getArtifactRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail(message + ".2", e); >+ } >+ >+ //mirror duplicate data >+ runMirrorApplication(message + ".4", sourceRepoLocation, destRepoLocation, append); >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to a repository populated with both partial duplicate and non-duplicate data >+ * Source contains A, B, C, D >+ * Target contains A, B, E, F >+ */ >+ private void artifactMirrorToPopulatedWithPartialDuplicate(String message, boolean append) { >+ //Setup: populate destination with non-duplicate artifacts >+ runMirrorApplication(message + ".0", sourceRepo2Location, destRepoLocation, false); //value of append should not matter >+ >+ try { >+ //Setup: verify >+ assertContentEquals(message + ".1", getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail(message + ".2", e); >+ } >+ >+ //Setup: populate destination with duplicate artifacts >+ runMirrorApplication(message + ".4", sourceRepoLocation, destRepoLocation, true); >+ >+ try { >+ //Setup: verify >+ assertContains(message + ".5", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ assertContains(message + ".6", getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail(message + ".7", e); >+ } >+ >+ //mirror duplicate data >+ runMirrorApplication(message + ".9", sourceRepo3Location, destRepoLocation, append); >+ } >+ >+ /** >+ * Tests mirroring all artifacts from an empty repository >+ * Source contains >+ */ >+ private File artifactMirrorEmpty(String message, boolean append) { >+ //Setup: Create an empty repository >+ File emptyRepository = new File(getTempFolder(), getUniqueString()); >+ //Setup: remove repository if it exists >+ getArtifactRepositoryManager().removeRepository(emptyRepository.toURI()); >+ //Setup: delete any data that may be in the folder >+ delete(emptyRepository); >+ try { >+ getArtifactRepositoryManager().createRepository(emptyRepository.toURI(), "Empty Repository", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); >+ } catch (ProvisionException e) { >+ fail(message + ".1", e); >+ } >+ >+ runMirrorApplication(message + ".0", emptyRepository, destRepoLocation, append); >+ return emptyRepository; //return the repository for use in verification >+ } >+ >+ /** >+ * Tests mirroring all artifacts from an empty repository >+ * Source contains >+ */ >+ private File artifactMirrorEmptyToPopulated(String message, boolean append) { >+ //Setup: Populate the repository >+ runMirrorApplication(message + ".0", sourceRepoLocation, destRepoLocation, false); >+ >+ return artifactMirrorEmpty(message + ".1", append); //create the empty repository, perform the mirror, pass the result back >+ } >+ >+ /** >+ * Runs mirror app on source with missing artifact with "-ignoreErrors" >+ */ >+ private void mirrorWithError(boolean verbose) { >+ File errorSourceLocation = getTestData("loading error data", "testData/mirror/mirrorErrorSourceRepo"); >+ //repo contains an artifact entry for a file that does not exist on disk. this should throw a file not found exception >+ try { >+ MirrorApplication app = new MirrorApplication(); >+ app.addSource(createRepositoryDescriptor(errorSourceLocation.toURI(), null, null, null)); >+ app.addDestination(createRepositoryDescriptor(destRepoLocation.toURI(), null, null, null)); >+ //Set ignoreErrors flag. Set verbose flag if verbose == true >+ app.setVerbose(verbose); >+ app.setIgnoreErrors(true); >+ //run the mirror application >+ app.run(null); >+ } catch (Exception e) { >+ fail("Running mirror application with errored source failed", e); >+ } >+ } >+ >+ /** >+ * ensures that all files with entries in the repo have corresponding files on disk. >+ * Not Biconditional. >+ */ >+ private void assertFileSizes(String message, SimpleArtifactRepository expected, SimpleArtifactRepository actual) { >+ IArtifactKey[] expectedKeys = expected.getArtifactKeys(); >+ >+ for (int i = 0; i < expectedKeys.length; i++) { >+ IArtifactDescriptor[] expectedDescriptors = expected.getArtifactDescriptors(expectedKeys[i]); >+ IArtifactDescriptor[] actualDescriptors = actual.getArtifactDescriptors(expectedKeys[i]); >+ >+ if (expectedDescriptors == null || actualDescriptors == null) >+ if (!(expectedDescriptors == null && actualDescriptors == null)) >+ fail(message + " missing key " + expectedKeys[i]); >+ >+ top: for (int j = 0; j < expectedDescriptors.length; j++) { >+ for (int k = 0; k < actualDescriptors.length; k++) { >+ if (Arrays.equals(expectedDescriptors[j].getProcessingSteps(), actualDescriptors[k].getProcessingSteps())) { >+ File expectedFile = expected.getArtifactFile(expectedDescriptors[j]); >+ File actualFile = actual.getArtifactFile(actualDescriptors[k]); >+ if (expectedFile == null || actualFile == null) >+ fail(message + " descriptor mismatch"); >+ if (!(expectedFile.exists() && actualFile.exists())) >+ fail(message + " file does not exist"); >+ assertTrue(expectedFile.length() == actualFile.length()); >+ continue top; >+ } >+ } >+ fail(message + "Missing expected descriptor" + expectedDescriptors[j]); >+ } >+ } >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to an empty repository >+ * Source contains A, B >+ * Target contains >+ * Expected is A, B >+ */ >+ public void testArtifactMirrorToEmpty() { >+ artifactMirrorToEmpty("1.0", true, false); // run the test with append set to true >+ >+ try { >+ //verify destination's content >+ assertContentEquals("1.1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("1.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to an empty repository with "-writeMode clean" >+ * Source contains A, B >+ * Target contains >+ * Expected is A, B >+ */ >+ public void testArtifactMirrorToEmptyWithClean() { >+ artifactMirrorToEmpty("2.0", false, false); >+ >+ try { >+ //verify destination's content >+ assertContentEquals("2.1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("2.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to a repository populated with exact duplicate data >+ * Source contains A, B >+ * Target contains A, B >+ * Expected is A, B >+ */ >+ public void testArtifactMirrorToFullDuplicate() { >+ artifactMirrorToFullDuplicate("3.0", true); //run the test with append set to true >+ >+ try { >+ //verify destination's content >+ assertContentEquals("3.1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("3.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to a repository populated with exact duplicate data with "-writeMode clean" >+ * Source contains A, B >+ * Target contains A, B >+ * Expected is A, B >+ */ >+ public void testArtifactMirrorToFullDuplicateWithClean() { >+ artifactMirrorToFullDuplicate("4.0", false); >+ >+ try { >+ //verify destination's content >+ assertContentEquals("4.1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("4.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to a repository populated with non-duplicate entries >+ * Source contains A, B >+ * Target contains C, D >+ * Expected is A, B, C, D >+ */ >+ public void testArtifactMirrorToPopulated() { >+ artifactMirrorToPopulated("5.0", true); //run the test with append set to true >+ >+ try { >+ //verify destination's content >+ assertContains("5.1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ assertContains("5.2", getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ //checks that the destination has the correct number of keys (no extras) >+ assertEquals("5.3", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null).getArtifactKeys().length + getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null).getArtifactKeys().length, getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null).getArtifactKeys().length); >+ } catch (ProvisionException e) { >+ fail("5.4", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to a repository populated with non-duplicate entries with "-writeMode clean" >+ * Source contains A, B >+ * Target contains C, D >+ * Expected is A, B >+ */ >+ public void testArtifactMirrorToPopulatedWithClean() { >+ artifactMirrorToPopulated("6.0", false); >+ >+ try { >+ //verify destination's content >+ assertContentEquals("6.1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("6.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to a repository populated with partially duplicate data >+ * Source contains A, B, C, D >+ * Target contains A, B >+ * Expected is A, B, C, D >+ */ >+ public void testArtifactMirrorToPartialDuplicate() { >+ artifactMirrorToPartialDuplicate("7.0", true); //run the test with append set to true >+ >+ try { >+ //verify destination's content >+ assertContentEquals("7.1", getArtifactRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("7.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to a repository populated with partially duplicate data with "-writeMode clean" >+ * Source contains A, B, C, D >+ * Target contains A, B >+ * Expected is A, B, C, D >+ */ >+ public void testArtifactMirrorToPartialDuplicateWithClean() { >+ artifactMirrorToPartialDuplicate("8.0", false); >+ >+ try { >+ //verify destination's content >+ assertContentEquals("8.1", getArtifactRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("8.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to a repository populated with both full duplicate and non-duplicate data >+ * Source contains A, B >+ * Target contains A, B, C, D >+ * Expected is A, B, C, D >+ */ >+ public void testArtifactMirrorToPopulatedWithFullDuplicate() { >+ artifactMirrorToPopulatedWithFullDuplicate("9.0", true); //run the test with append set to true >+ >+ try { >+ //verify destination's content >+ assertContentEquals("9.1", getArtifactRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("9.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to a repository populated with both full duplicate and non-duplicate data with "-writeMode clean" >+ * Source contains A, B >+ * Target contains A, B, C, D >+ * Expected is A, B >+ */ >+ public void testArtifactMirrorToPopulatedWithFullDuplicateWithClean() { >+ artifactMirrorToPopulatedWithFullDuplicate("10.0", false); >+ >+ try { >+ //verify destination's content >+ assertContentEquals("10.1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("10.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to a repository populated with both partial duplicate and non-duplicate data >+ * Source contains A, B, C, D >+ * Target contains A, B, E, F >+ * Expected is A, B, C, D, E, F >+ */ >+ public void testArtifactMirrorToPopulatedWithPartialDuplicate() { >+ artifactMirrorToPopulatedWithPartialDuplicate("11.0", true); //run the test with append set to true >+ >+ try { >+ //verify destination's content >+ assertContains("11.1", getArtifactRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ assertContains("11.2", getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ //checks that the destination has the correct number of keys (no extras) >+ assertEquals("11.3", getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null).getArtifactKeys().length + getArtifactRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null).getArtifactKeys().length, getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null).getArtifactKeys().length); >+ } catch (ProvisionException e) { >+ fail("11.4", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring all artifacts in a repository to a repository populated with both partial duplicate and non-duplicate data with "-writeMode clean" >+ * Source contains A, B, C, D >+ * Target contains A, B, E, F >+ * Expected is A, B, C, D >+ */ >+ public void testArtifactMirrorToPopulatedWithPartialDuplicateWithClean() { >+ artifactMirrorToPopulatedWithPartialDuplicate("12.0", false); >+ >+ try { >+ //verify destination's content >+ assertContentEquals("12.1", getArtifactRepositoryManager().loadRepository(sourceRepo3Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("12.2", e); >+ } >+ } >+ >+ /** >+ * Tests MirrorApplication's behaviour when given an invalid source repository >+ */ >+ public void testArtifactMirrorFromInvalid() { >+ File invalidRepository = new File(getTempFolder(), getUniqueString()); >+ delete(invalidRepository); >+ >+ try { >+ basicRunMirrorApplication("13.1", invalidRepository.toURI(), destRepoLocation.toURI(), true, false); >+ //we expect a provision exception to be thrown. We should never get here. >+ fail("13.0 ProvisionExpection not thrown"); >+ } catch (ProvisionException e) { >+ return; //correct type of exception has been thrown >+ } catch (Exception e) { >+ fail("13.2", e); >+ } >+ } >+ >+ /** >+ * Tests MirrorApplication's behaviour when given an invalid destination repository >+ */ >+ public void testArtifactMirrorToInvalid() { >+ URI invalidDestRepository = null; >+ try { >+ //Setup: create a URI pointing to an unmodifiable place >+ invalidDestRepository = new URI("http://foobar.com/abcdefg"); >+ >+ //run the application with the modifiable destination >+ basicRunMirrorApplication("14.1", sourceRepoLocation.toURI(), invalidDestRepository, true, false); >+ //we're expecting an UnsupportedOperationException so we should never get here >+ fail("14.0 UnsupportedOperationException not thrown"); >+ } catch (ProvisionException e) { >+ assertEquals("Unexpected error message", NLS.bind(org.eclipse.equinox.p2.internal.repository.tools.Messages.exception_invalidDestination, URIUtil.toUnencodedString(invalidDestRepository)), e.getMessage()); >+ return; //correct type of exception has been thrown >+ } catch (Exception e) { >+ fail("14.2", e); >+ } finally { >+ if (invalidDestRepository != null) >+ getArtifactRepositoryManager().removeRepository(invalidDestRepository); >+ } >+ } >+ >+ /** >+ * Tests MirrorApplication's behaviour when given both an invalid source and an invalid destination repository >+ */ >+ public void testArtifactMirrorBothInvalid() { >+ //Setup: create a file that is not a valid repository >+ File invalidRepository = new File(getTempFolder(), getUniqueString()); >+ //Setup: delete any leftover data >+ delete(invalidRepository); >+ >+ try { >+ //Setup: create a URI pointing to an unmodifiable place >+ URI invalidDestRepository = new URI("http://foobar.com/abcdefg"); >+ basicRunMirrorApplication("15.1", invalidRepository.toURI(), invalidDestRepository, true, false); >+ //We expect the ProvisionException to be thrown >+ fail("15.0 ProvisionException not thrown"); >+ } catch (ProvisionException e) { >+ return; //correct type of exception was thrown >+ } catch (Exception e) { >+ fail("15.2", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring an empty repository to another empty repository >+ * Source contains >+ * Target contains >+ * Expected is >+ */ >+ public void testArtifactMirrorEmptyToEmpty() { >+ File emptyRepository = artifactMirrorEmpty("16.0", true); >+ >+ try { >+ //verify destination's content >+ assertContentEquals("16.1", getArtifactRepositoryManager().loadRepository(emptyRepository.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("16.2", e); >+ } >+ >+ //remove the emptyRepository >+ getArtifactRepositoryManager().removeRepository(emptyRepository.toURI()); >+ //delete any left over data >+ delete(emptyRepository); >+ } >+ >+ /** >+ * Tests mirroring an empty repository to a populated repository >+ * Source contains >+ * Target contains A, B >+ * Expected is A, B >+ */ >+ public void testArtifactMirrorEmptyToPopulated() { >+ File emptyRepository = artifactMirrorEmptyToPopulated("17.0", true); >+ >+ try { >+ //verify destination's content >+ assertContains("17.1", getArtifactRepositoryManager().loadRepository(emptyRepository.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ assertContentEquals("17.2", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("17.3", e); >+ } >+ >+ //remove the empty repository >+ getArtifactRepositoryManager().removeRepository(emptyRepository.toURI()); >+ //remove any leftover data >+ delete(emptyRepository); >+ } >+ >+ /** >+ * Tests mirroring an empty repository to a populated repository with "-writeMode clean" >+ * Source contains >+ * Target contains A, B >+ * Expected is >+ */ >+ public void testArtifactMirrorEmptyToPopulatedWithClean() { >+ File emptyRepository = artifactMirrorEmptyToPopulated("18.0", false); >+ >+ try { >+ //verify destination's content >+ assertContentEquals("18.1", getArtifactRepositoryManager().loadRepository(emptyRepository.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("18.2", e); >+ } >+ >+ //remove the empty repository >+ getArtifactRepositoryManager().removeRepository(emptyRepository.toURI()); >+ //delete any leftover data >+ delete(emptyRepository); >+ } >+ >+ /** >+ * Tests mirroring a repository to itself >+ * Source contains A, B >+ * Target contains A, B >+ * Expected is A, B >+ */ >+ public void testArtifactMirrorSourceIsDestination() { >+ //Setup: Populate the repository >+ runMirrorApplication("19.0", sourceRepoLocation, destRepoLocation, false); >+ >+ //run the application with the source and destination specified to the same place >+ runMirrorApplication("19.1", destRepoLocation, destRepoLocation, true); >+ >+ try { >+ //verify destination's content >+ assertContentEquals("19.2", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("19.3", e); >+ } >+ } >+ >+ /** >+ * Tests mirroring a repository with a different version of the same package >+ * Source contains A, B (v1.0.1) >+ * Target contains A, B (v1.0.0) >+ * Expected is A, B (v1.0.0) and A, B (v1.0.1) >+ */ >+ public void testArtifactMirrorDifferentVersions() { >+ //Setup: Populate the repository >+ runMirrorApplication("20.0", sourceRepoLocation, destRepoLocation, false); >+ >+ //run the application with the source and destination specified to the same place >+ runMirrorApplication("20.1", sourceRepo4Location, destRepoLocation, true); >+ >+ try { >+ //verify destination's content >+ assertContains("20.2", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ assertContains("20.3", getArtifactRepositoryManager().loadRepository(sourceRepo4Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ //checks that the destination has the correct number of keys (no extras) >+ assertEquals("20.4", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null).getArtifactKeys().length + getArtifactRepositoryManager().loadRepository(sourceRepo4Location.toURI(), null).getArtifactKeys().length, getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null).getArtifactKeys().length); >+ } catch (ProvisionException e) { >+ fail("20.5", e); >+ } >+ } >+ >+ /** >+ * Tests how mirror application handles an unspecified source >+ */ >+ public void testArtifactMirrorNullSource() { >+ try { >+ basicRunMirrorApplication("21.1", null, destRepoLocation.toURI()); >+ //We expect the ProvisionException to be thrown >+ fail("21.3 ProvisionException not thrown"); >+ } catch (ProvisionException e) { >+ return; //expected type of exception has been thrown >+ } catch (Exception e) { >+ fail("21.2", e); >+ } >+ } >+ >+ /** >+ * Tests how mirror application handles an unspecified destination >+ */ >+ public void testArtifactMirrorNullDestination() { >+ try { >+ basicRunMirrorApplication("22.1", sourceRepoLocation.toURI(), null); >+ //We expect the ProvisionException to be thrown >+ fail("22.3 ProvisionException not thrown"); >+ } catch (ProvisionException e) { >+ return; //expected type of exception has been thrown >+ } catch (Exception e) { >+ fail("22.2", e); >+ } >+ } >+ >+ /** >+ * Tests how mirror application handles both an unspecified source and an unspecified destination >+ */ >+ public void testArtifactMirrorNullBoth() { >+ try { >+ basicRunMirrorApplication("23.0", null, null); >+ //We expect the ProvisionException to be thrown >+ fail("23.2 ProvisionException not thrown"); >+ } catch (ProvisionException e) { >+ return; //expected type of exception has been thrown >+ } catch (Exception e) { >+ fail("23.1", e); >+ } >+ } >+ >+ /** >+ * Ensures that a repository created by the mirror application is a copy of the source >+ */ >+ public void testNewArtifactRepoProperties() { >+ //run mirror application with source not preexisting >+ artifactMirrorToEmpty("24.0", true, true); >+ >+ try { >+ IArtifactRepository sourceRepository = getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null); >+ IArtifactRepository destinationRepository = getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null); >+ assertEquals("24.1", sourceRepository.getName(), destinationRepository.getName()); >+ assertRepositoryProperties("24.2", sourceRepository.getProperties(), destinationRepository.getProperties()); >+ } catch (ProvisionException e) { >+ fail("24.3", e); >+ } >+ } >+ >+ /** >+ * Ensures that a repository created before the mirror application is run does not have its properties changed >+ */ >+ public void testExistingArtifactRepoProperties() { >+ //Setup: create the destination >+ String name = "Destination Name"; >+ Map properties = null; //default properties >+ try { >+ //create the repository and get the resulting properties >+ properties = getArtifactRepositoryManager().createRepository(destRepoLocation.toURI(), name, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties).getProperties(); >+ } catch (ProvisionException e) { >+ fail("25.0", e); >+ } >+ >+ //run the mirror application >+ artifactMirrorToEmpty("25.2", true, false); >+ >+ try { >+ IArtifactRepository repository = getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null); >+ assertEquals("25.3", name, repository.getName()); >+ assertRepositoryProperties("25.4", properties, repository.getProperties()); >+ } catch (ProvisionException e) { >+ fail("25.5", e); >+ } >+ } >+ >+ /** >+ * * Ensures that a repository created by the mirror application has specified name >+ * For Bug 256909 >+ */ >+ public void testNewArtifactRepoWithNewName() { >+ String name = "Bug 256909 test - new"; >+ try { >+ basicRunMirrorApplication("Bug 256909 Test", sourceRepoLocation.toURI(), destRepoLocation.toURI(), true, false, name); >+ } catch (MalformedURLException e) { >+ fail("Error creating URLs for Source/Detination", e); >+ } catch (Exception e) { >+ fail("Error running mirror application", e); >+ } >+ >+ try { >+ assertEquals("Assert name was set correct", name, getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null).getName()); >+ } catch (ProvisionException e) { >+ fail("Cannot obtain destination", e); >+ } >+ } >+ >+ /** >+ * Ensures that an existing destination used by the mirror application is given specified name >+ * For Bug 256909 >+ */ >+ public void testExistingArtifactRepoWithNewName() { >+ String oldName = "The original naem for Bug 256909 test - existing"; >+ String newName = "Bug 256909 test - existing"; >+ //Setup create the repository >+ IArtifactRepository destinationRepo = null; >+ try { >+ destinationRepo = getArtifactRepositoryManager().createRepository(destRepoLocation.toURI(), oldName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); >+ } catch (ProvisionException e) { >+ fail("Error creating repo at destination", e); >+ } >+ assertEquals("Assert name is set correctly before mirror", oldName, destinationRepo.getName()); >+ >+ try { >+ MirrorApplication app = new MirrorApplication(); >+ app.addSource(createRepositoryDescriptor(sourceRepoLocation.toURI(), null, null, null)); >+ app.addDestination(createRepositoryDescriptor(destRepoLocation.toURI(), null, null, newName)); >+ //run the mirror application >+ app.run(null); >+ >+ } catch (Exception e) { >+ fail("Error running mirror application", e); >+ } >+ >+ try { >+ assertEquals("Assert name is set correctly after mirror", newName, getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null).getName()); >+ } catch (ProvisionException e) { >+ fail("Error loading destination", e); >+ } >+ } >+ >+ /** >+ * Verifies that the mirror application copies files (including packed files) correctly >+ */ >+ public void testArtifactFileCopying() { >+ //Setup: load the repository containing packed data >+ File packedRepoLocation = getTestData("26.0", "/testData/mirror/mirrorPackedRepo"); >+ >+ try { >+ basicRunMirrorApplication("26.1", packedRepoLocation.toURI(), destRepoLocation.toURI(), false, false); >+ } catch (Exception e) { >+ fail("26.3", e); >+ } >+ >+ try { >+ //Verify Contents >+ assertContentEquals("26.4", getArtifactRepositoryManager().loadRepository(packedRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ //Verify files on disk >+ assertFileSizes("26.5", (SimpleArtifactRepository) getArtifactRepositoryManager().loadRepository(packedRepoLocation.toURI(), null), (SimpleArtifactRepository) getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("26.6", e); >+ } >+ } >+ >+ /** >+ * Verifies that the mirror application executes processing steps correctly >+ */ >+ public void testArtifactProcessingSteps() { >+ //Setup: load the repository containing packed data >+ File packedRepoLocation = getTestData("27.0", "/testData/mirror/mirrorPackedRepo"); >+ IArtifactRepository packedRepo = null; >+ IArtifactRepository destinationRepo = null; >+ >+ try { >+ packedRepo = getArtifactRepositoryManager().loadRepository(packedRepoLocation.toURI(), null); >+ destinationRepo = getArtifactRepositoryManager().createRepository(destRepoLocation.toURI(), "Test Repo", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); >+ } catch (ProvisionException e1) { >+ fail(""); >+ } >+ >+ IArtifactKey[] keys = packedRepo.getArtifactKeys(); >+ >+ for (int i = 0; i < keys.length; i++) { >+ IArtifactDescriptor[] srcDescriptors = packedRepo.getArtifactDescriptors(keys[i]); >+ >+ for (int j = 0; j < srcDescriptors.length; j++) { >+ if (!(srcDescriptors[j].getProperty(IArtifactDescriptor.FORMAT) == null) && srcDescriptors[j].getProperty(IArtifactDescriptor.FORMAT).equals("packed")) { >+ //if we have a packed artifact >+ IArtifactDescriptor newDescriptor = new ArtifactDescriptor(keys[i]); >+ Map properties = new OrderedProperties(); >+ properties.putAll(srcDescriptors[j].getProperties()); >+ properties.remove(IArtifactDescriptor.FORMAT); >+ ((ArtifactDescriptor) newDescriptor).addProperties(properties); >+ //create appropriate descriptor >+ try { >+ OutputStream repositoryStream = null; >+ try { >+ //System.out.println("Mirroring: " + srcDescriptors[j].getArtifactKey() + " (Descriptor: " + srcDescriptors[j] + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ >+ repositoryStream = destinationRepo.getOutputStream(newDescriptor); >+ if (repositoryStream == null) >+ return; >+ // TODO Is that ok to ignore the result? >+ //TODO MAKE THIS WORK PROPERLY >+ packedRepo.getArtifact(srcDescriptors[j], repositoryStream, new NullProgressMonitor()); >+ } finally { >+ if (repositoryStream != null) >+ repositoryStream.close(); >+ } >+ } catch (ProvisionException e) { >+ fail("27.1", e); >+ } catch (IOException e) { >+ fail("27.2", e); >+ } >+ //corresponding key should now be in the destination >+ IArtifactDescriptor[] destDescriptors = destinationRepo.getArtifactDescriptors(keys[i]); >+ boolean canonicalFound = false; >+ for (int l = 0; !canonicalFound && (l < destDescriptors.length); l++) { >+ //No processing steps mean item is canonical >+ if (destDescriptors[l].getProcessingSteps().length == 0) >+ canonicalFound = true; >+ } >+ if (!canonicalFound) >+ fail("27.3 no canonical found for " + keys[i].toString()); >+ >+ //ensure the canonical matches that in the expected >+ assertFileSizes("27.3", (SimpleArtifactRepository) destinationRepo, (SimpleArtifactRepository) packedRepo); >+ } >+ } >+ } >+ } >+ >+ //for Bug 235683 >+ public void testMirrorCompressedSource() { >+ File compressedSource = getTestData("0", "/testData/mirror/mirrorCompressedRepo"); >+ >+ //Setup: get the artifacts.jar file >+ File compressedArtifactsXML = new File(compressedSource.getAbsoluteFile() + "/artifacts.jar"); >+ //Setup: make sure artifacts.jar exists >+ assertTrue("1", compressedArtifactsXML.exists()); >+ >+ try { >+ basicRunMirrorApplication("2", compressedSource.toURI(), destRepoLocation.toURI(), false, false); >+ } catch (MalformedURLException e) { >+ fail("3", e); >+ } catch (Exception e) { >+ fail("4", e); >+ } >+ >+ //get the artifacts.jar file >+ File destArtifactsXML = new File(destRepoLocation.getAbsolutePath() + "/artifacts.jar"); >+ //make sure artifacts.jar exists >+ assertTrue("5", destArtifactsXML.exists()); >+ } >+ >+ //for Bug 235683 >+ public void testMirrorCompressedSourcetoUncompressedDestination() { >+ File compressedSource = getTestData("0", "/testData/mirror/mirrorCompressedRepo"); >+ >+ //Setup: get the artifacts.jar file >+ File compressedArtifactsXML = new File(compressedSource.getAbsoluteFile() + "/artifacts.jar"); >+ //Setup: make sure artifacts.jar exists >+ assertTrue("1", compressedArtifactsXML.exists()); >+ >+ //Setup: create the destination >+ try { >+ String name = "Destination Name " + destRepoLocation; >+ getArtifactRepositoryManager().createRepository(destRepoLocation.toURI(), name, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); >+ } catch (ProvisionException e) { >+ fail("2", e); >+ } >+ >+ assertTrue("2.1", new File(destRepoLocation, "artifacts.xml").exists()); >+ try { >+ basicRunMirrorApplication("3", compressedSource.toURI(), destRepoLocation.toURI(), false, false); >+ } catch (MalformedURLException e) { >+ fail("4", e); >+ } catch (Exception e) { >+ fail("5", e); >+ } >+ >+ //get the artifacts.jar file >+ File destArtifactsXML = new File(destRepoLocation.getAbsolutePath() + "/artifacts.jar"); >+ //make sure artifacts.jar does not exist >+ assertFalse("6", destArtifactsXML.exists()); >+ //get the artifacts.xml file >+ destArtifactsXML = new File(destRepoLocation.getAbsolutePath() + "/artifacts.xml"); >+ //make sure artifacts.xml exists >+ assertTrue("7", destArtifactsXML.exists()); >+ } >+ >+ //for Bug 235683 >+ public void testMirrorUncompressedSourceToCompressedDestination() { >+ File uncompressedSource = getTestData("0", "/testData/mirror/mirrorPackedRepo"); >+ >+ //Setup: get the artifacts.xml file >+ File artifactsXML = new File(uncompressedSource.getAbsoluteFile() + "/artifacts.xml"); >+ //Setup: make sure artifacts.xml exists >+ assertTrue("1", artifactsXML.exists()); >+ >+ //Setup: create the destination >+ try { >+ String name = "Destination Name " + destRepoLocation; >+ Map property = new HashMap(); >+ property.put(IRepository.PROP_COMPRESSED, "true"); >+ getArtifactRepositoryManager().createRepository(destRepoLocation.toURI(), name, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, property); >+ } catch (ProvisionException e) { >+ fail("2", e); >+ } >+ >+ assertTrue("2.1", new File(destRepoLocation, "artifacts.jar").exists()); >+ try { >+ basicRunMirrorApplication("3", uncompressedSource.toURI(), destRepoLocation.toURI(), false, false); >+ } catch (MalformedURLException e) { >+ fail("4", e); >+ } catch (Exception e) { >+ fail("5", e); >+ } >+ >+ //get the artifacts.jar file >+ File destArtifactsXML = new File(destRepoLocation.getAbsolutePath() + "/artifacts.jar"); >+ //make sure artifacts.jar does exist >+ assertTrue("6", destArtifactsXML.exists()); >+ //get the artifacts.xml file >+ destArtifactsXML = new File(destRepoLocation.getAbsolutePath() + "/artifacts.xml"); >+ //make sure artifacts.xml does not exist >+ assertFalse("7", destArtifactsXML.exists()); >+ } >+ >+ public void testMirrorApplicationWithCompositeSource() { >+ //Setup Make composite repository >+ File repoLocation = new File(getTempFolder(), "CompositeArtifactMirrorTest"); >+ AbstractProvisioningTest.delete(repoLocation); >+ IArtifactRepository repo = null; >+ try { >+ repo = getArtifactRepositoryManager().createRepository(repoLocation.toURI(), "artifact name", IArtifactRepositoryManager.TYPE_COMPOSITE_REPOSITORY, null); >+ } catch (ProvisionException e) { >+ fail("Could not create repository"); >+ } >+ //ensure proper type of repository has been created >+ if (!(repo instanceof CompositeArtifactRepository)) >+ fail("Repository is not a CompositeArtifactRepository"); >+ //Populate source >+ File child1 = getTestData("1", "/testData/mirror/mirrorSourceRepo1 with space"); >+ File child2 = getTestData("2", "/testData/mirror/mirrorSourceRepo2"); >+ ((CompositeArtifactRepository) repo).addChild(child1.toURI()); >+ ((CompositeArtifactRepository) repo).addChild(child2.toURI()); >+ >+ runMirrorApplication("Mirroring from Composite Source", repoLocation, destRepoLocation, false); >+ >+ try { >+ assertContentEquals("Verifying contents", repo, getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ >+ //Verify that result is the same as mirroring from the 2 repositories separately >+ assertContains("3", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ assertContains("4", getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ //checks that the destination has the correct number of keys (no extras) >+ assertEquals("5", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null).getArtifactKeys().length + getArtifactRepositoryManager().loadRepository(sourceRepo2Location.toURI(), null).getArtifactKeys().length, getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null).getArtifactKeys().length); >+ } catch (ProvisionException e) { >+ fail("Could not load destination", e); >+ } >+ } >+ >+ //for Bug 250527 >+ public void testIgnoreErrorsArgument() { >+ //Error prints to stderr, redirect that to a file >+ PrintStream oldErr = System.err; >+ PrintStream newErr = null; >+ try { >+ destRepoLocation.mkdir(); >+ newErr = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.err"))); >+ } catch (FileNotFoundException e) { >+ fail("Error redirecting outputs", e); >+ } >+ System.setErr(newErr); >+ >+ //run test without verbose >+ mirrorWithError(false); >+ >+ System.setErr(oldErr); >+ newErr.close(); >+ >+ try { >+ assertEquals("Verifying correct number of Keys", 1, getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null).getArtifactKeys().length); >+ //Because only 1 of the artifacts exists on disk, the number of artifacts in the destination should only be 1. >+ //Order in which mirror application mirrors artifacts is random. >+ } catch (ProvisionException e) { >+ fail("Error laoding destiantion repo", e); >+ } >+ } >+ >+ public void testCompareUsingMD5Comparator() { >+ //Setup create descriptors with different md5 values >+ IArtifactKey dupKey = PublisherHelper.createBinaryArtifactKey("testKeyId", new Version("1.2.3")); >+ File artifact1 = getTestData("0.0", "/testData/mirror/mirrorSourceRepo1 with space/artifacts.xml"); >+ File artifact2 = getTestData("0.0", "/testData/mirror/mirrorSourceRepo2/artifacts.xml"); >+ IArtifactDescriptor descriptor1 = PublisherHelper.createArtifactDescriptor(dupKey, artifact1); >+ IArtifactDescriptor descriptor2 = PublisherHelper.createArtifactDescriptor(dupKey, artifact2); >+ >+ assertEquals("Ensuring Descriptors are the same", descriptor1, descriptor2); >+ assertNotSame("Ensuring MD5 values are different", descriptor1.getProperty(IArtifactDescriptor.DOWNLOAD_MD5), descriptor2.getProperty(IArtifactDescriptor.DOWNLOAD_MD5)); >+ >+ //Setup make repositories >+ File repo1Location = getTestFolder(getUniqueString()); >+ File repo2Location = getTestFolder(getUniqueString()); >+ IArtifactRepository repo1 = null; >+ IArtifactRepository repo2 = null; >+ try { >+ repo1 = getArtifactRepositoryManager().createRepository(repo1Location.toURI(), "Repo 1", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); >+ repo1.addDescriptor(descriptor1); >+ repo2 = getArtifactRepositoryManager().createRepository(repo2Location.toURI(), "Repo 2", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); >+ repo2.addDescriptor(descriptor2); >+ } catch (ProvisionException e) { >+ fail("Error creating repositories", e); >+ } >+ >+ //Comparator prints to stderr, redirect that to a file >+ PrintStream oldErr = System.err; >+ PrintStream newErr = null; >+ PrintStream oldOut = System.out; >+ PrintStream newOut = null; >+ try { >+ newErr = new PrintStream(new FileOutputStream(new File(repo2Location, "sys.err"))); >+ newOut = new PrintStream(new FileOutputStream(new File(repo2Location, "sys.out"))); >+ } catch (FileNotFoundException e) { >+ fail("Error redirecting outputs", e); >+ } >+ System.setErr(newErr); >+ System.setOut(newOut); >+ MirrorApplication app = null; >+ try { >+ app = new MirrorApplication(); >+ app.addSource(createRepositoryDescriptor(repo1Location.toURI(), null, null, null)); >+ app.addDestination(createRepositoryDescriptor(repo2Location.toURI(), null, null, null)); >+ app.setVerbose(true); >+ //Set compare flag. >+ app.setCompare(true); >+ //run the mirror application >+ app.run(null); >+ } catch (Exception e) { >+ fail("Running mirror application with duplicate descriptors with different md5 values failed", e); >+ } >+ System.setErr(oldErr); >+ newErr.close(); >+ System.setOut(oldOut); >+ newOut.close(); >+ >+ IArtifactDescriptor[] destDescriptors = repo2.getArtifactDescriptors(descriptor2.getArtifactKey()); >+ assertEquals("Ensuring destination has correct number of descriptors", 1, destDescriptors.length); >+ assertEquals("Ensuring proper descriptor exists in destination", descriptor2.getProperty(IArtifactDescriptor.DOWNLOAD_MD5), destDescriptors[0].getProperty(IArtifactDescriptor.DOWNLOAD_MD5)); >+ String msg = NLS.bind(Messages.warning_differentMD5, new Object[] {URIUtil.toUnencodedString(repo1.getLocation()), URIUtil.toUnencodedString(repo2.getLocation()), descriptor1}); >+ try { >+ assertLogContainsLine(TestActivator.getLogFile(), msg); >+ } catch (Exception e) { >+ fail("error verifying output", e); >+ } >+ } >+ >+ public void testBaselineCompareUsingMD5Comparator() { >+ //Setup create descriptors with different md5 values >+ IArtifactKey dupKey = PublisherHelper.createBinaryArtifactKey("testKeyId", new Version("1.2.3")); >+ File artifact1 = getTestData("0.0", "/testData/mirror/mirrorSourceRepo1 with space/content.xml"); >+ File artifact2 = getTestData("0.0", "/testData/mirror/mirrorSourceRepo2/content.xml"); >+ >+ //Setup Copy the file to the baseline >+ File repoLocation = getTestFolder(getUniqueString()); >+ File baselineLocation = getTestFolder(getUniqueString()); >+ File baselineBinaryDirectory = new File(baselineLocation, "binary"); >+ baselineBinaryDirectory.mkdir(); >+ File baselineContentLocation = new File(baselineBinaryDirectory, "testKeyId_1.2.3"); >+ AbstractProvisioningTest.copy("Copying File to baseline", artifact2, baselineContentLocation); >+ >+ IArtifactDescriptor descriptor1 = PublisherHelper.createArtifactDescriptor(dupKey, artifact1); >+ IArtifactDescriptor descriptor2 = PublisherHelper.createArtifactDescriptor(dupKey, baselineContentLocation); >+ >+ assertEquals("Ensuring Descriptors are the same", descriptor1, descriptor2); >+ assertNotSame("Ensuring MD5 values are different", descriptor1.getProperty(IArtifactDescriptor.DOWNLOAD_MD5), descriptor2.getProperty(IArtifactDescriptor.DOWNLOAD_MD5)); >+ >+ //Setup make repositories >+ IArtifactRepository repo = null; >+ IArtifactRepository baseline = null; >+ try { >+ repo = getArtifactRepositoryManager().createRepository(repoLocation.toURI(), "Repo 1", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); >+ repo.addDescriptor(descriptor1); >+ baseline = getArtifactRepositoryManager().createRepository(baselineLocation.toURI(), "Repo 2", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); >+ baseline.addDescriptor(descriptor2); >+ } catch (ProvisionException e) { >+ fail("Error creating repositories", e); >+ } >+ >+ //Comparator prints to stderr, redirect that to a file >+ PrintStream oldErr = System.err; >+ PrintStream newErr = null; >+ PrintStream oldOut = System.out; >+ PrintStream newOut = null; >+ try { >+ destRepoLocation.mkdir(); >+ newErr = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.err"))); >+ newOut = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.out"))); >+ } catch (FileNotFoundException e) { >+ fail("Error redirecting outputs", e); >+ } >+ System.setErr(newErr); >+ System.setOut(newOut); >+ MirrorApplication app = null; >+ try { >+ app = new MirrorApplication(); >+ app.addSource(createRepositoryDescriptor(repoLocation.toURI(), null, null, null)); >+ app.addDestination(createRepositoryDescriptor(destRepoLocation.toURI(), null, null, null)); >+ //Set baseline >+ app.setBaseline(baselineLocation.toURI()); >+ app.setVerbose(true); >+ //Set compare flag. >+ app.setCompare(true); >+ //run the mirror application >+ app.run(null); >+ } catch (Exception e) { >+ fail("Running mirror application with baseline compare", e); >+ } >+ System.setErr(oldErr); >+ newErr.close(); >+ System.setOut(oldOut); >+ newOut.close(); >+ >+ IArtifactRepository destination = null; >+ try { >+ destination = getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null); >+ } catch (ProvisionException e) { >+ fail("Error loading destination", e); >+ } >+ >+ IArtifactDescriptor[] destDescriptors = destination.getArtifactDescriptors(descriptor2.getArtifactKey()); >+ assertEquals("Ensuring destination has correct number of descriptors", 1, destDescriptors.length); >+ assertEquals("Ensuring destination contains the descriptor from the baseline", descriptor2.getProperty(IArtifactDescriptor.DOWNLOAD_MD5), destDescriptors[0].getProperty(IArtifactDescriptor.DOWNLOAD_MD5)); >+ String msg = NLS.bind(Messages.warning_differentMD5, new Object[] {URIUtil.toUnencodedString(baseline.getLocation()), URIUtil.toUnencodedString(repo.getLocation()), descriptor1}); >+ try { >+ assertLogContainsLine(TestActivator.getLogFile(), msg); >+ } catch (Exception e) { >+ fail("error verifying output", e); >+ } >+ } >+ >+ //for Bug 259111 >+ public void testDownloadRetry() { >+ //repository that is known to force a retry >+ class TestRetryArtifactRepository extends SimpleArtifactRepository { >+ public boolean firstAttempt = true; >+ IArtifactRepository source; >+ >+ public TestRetryArtifactRepository(String repositoryName, URI location, URI srcLocation, Map properties, IArtifactRepositoryManager manager) { >+ super(repositoryName, location, properties); >+ >+ //initialize >+ try { >+ source = manager.loadRepository(srcLocation, null); >+ } catch (ProvisionException e) { >+ fail("Unable to load source for wrapping", e); >+ } >+ manager.removeRepository(srcLocation); >+ } >+ >+ public synchronized IArtifactKey[] getArtifactKeys() { >+ return source.getArtifactKeys(); >+ } >+ >+ public synchronized IArtifactDescriptor[] getArtifactDescriptors(IArtifactKey key) { >+ return source.getArtifactDescriptors(key); >+ } >+ >+ public IStatus getRawArtifact(IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) { >+ if (firstAttempt) { >+ firstAttempt = false; >+ return new Status(IStatus.ERROR, Activator.ID, IArtifactRepository.CODE_RETRY, "Forcing Retry", new ProvisionException("Forcing retry")); >+ } >+ >+ return source.getRawArtifact(descriptor, destination, monitor); >+ } >+ >+ public synchronized boolean contains(IArtifactDescriptor descriptor) { >+ return source.contains(descriptor); >+ } >+ } >+ >+ //set up test repository >+ File retryRepoLoaction = new File(getTempFolder(), "259111 Repo"); >+ IArtifactRepository retryRepo = new TestRetryArtifactRepository("Test Repo", retryRepoLoaction.toURI(), sourceRepoLocation.toURI(), null, getArtifactRepositoryManager()); >+ ((ArtifactRepositoryManager) getArtifactRepositoryManager()).addRepository(retryRepo); >+ >+ try { >+ basicRunMirrorApplication("Forcing Retry", retryRepo.getLocation(), destRepoLocation.toURI()); >+ } catch (MalformedURLException e) { >+ fail("Error creating arguments", e); >+ } catch (Exception e) { >+ fail("Error while running Mirror Application and forcing retry", e); >+ } >+ >+ //ensure error was resulted >+ assertFalse(((TestRetryArtifactRepository) retryRepo).firstAttempt); >+ try { >+ //verify destination's content >+ assertContentEquals("Verifying content", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (ProvisionException e) { >+ fail("Failure while verifying destination", e); >+ } >+ } >+ >+ //for Bug 259112 >+ public void testErrorLoggingNoVerbose() { >+ //initialize log file >+ FrameworkLog log = (FrameworkLog) ServiceHelper.getService(Activator.getContext(), FrameworkLog.class.getName()); >+ assertNotNull("Assert log file is not null", log); >+ assertTrue("Clearing log file", log.getFile().delete()); >+ >+ //Comparator prints to stderr, redirect that to a file >+ PrintStream oldErr = System.err; >+ PrintStream newErr = null; >+ try { >+ destRepoLocation.mkdir(); >+ newErr = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.err"))); >+ } catch (FileNotFoundException e) { >+ fail("Error redirecting outputs", e); >+ } >+ System.setErr(newErr); >+ >+ //run test without verbose resulting in error >+ mirrorWithError(false); >+ >+ System.setErr(oldErr); >+ newErr.close(); >+ >+ //verify log >+ try { >+ String[] parts = new String[] {"java.io.FileNotFoundException: ", "helloworld_1.0.0.jar"}; >+ assertLogContainsLine(log.getFile(), parts); >+ } catch (Exception e) { >+ fail("error verifying output", e); >+ } >+ >+ //run without verbose >+ artifactMirrorToFullDuplicate("Generating INFO entries", true); >+ >+ IArtifactRepository sourceRepository = null; >+ try { >+ sourceRepository = getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null); >+ } catch (ProvisionException e) { >+ fail("Error loading source repository for verification", e); >+ } >+ >+ try { >+ //Mirroring full duplicate, so any key will do. >+ IArtifactDescriptor[] descriptors = sourceRepository.getArtifactDescriptors(sourceRepository.getArtifactKeys()[0]); >+ //Mirroring full duplicate, so any descriptor will do. >+ String message = NLS.bind(org.eclipse.equinox.internal.p2.artifact.repository.Messages.mirror_alreadyExists, descriptors[0], destRepoLocation.toURI()); >+ assertLogDoesNotContainLine(log.getFile(), message); >+ } catch (Exception e) { >+ fail("Error verifying log", e); >+ } >+ } >+ >+ //for Bug 259112 >+ public void testErrorLoggingWithVerbose() { >+ //initialize log file >+ FrameworkLog log = (FrameworkLog) ServiceHelper.getService(Activator.getContext(), FrameworkLog.class.getName()); >+ assertNotNull("Assert log file is not null", log); >+ assertTrue("Clearing log file", log.getFile().exists() && log.getFile().delete()); >+ >+ //Comparator prints to stdout, redirect that to a file >+ PrintStream oldOut = System.out; >+ PrintStream newOut = null; >+ PrintStream oldErr = System.err; >+ PrintStream newErr = null; >+ try { >+ destRepoLocation.mkdir(); >+ newOut = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.out"))); >+ newErr = new PrintStream(new FileOutputStream(new File(destRepoLocation, "sys.err"))); >+ } catch (FileNotFoundException e) { >+ fail("Error redirecting output", e); >+ } >+ System.setOut(newOut); >+ System.setErr(newErr); >+ >+ //run test with verbose, results in error >+ mirrorWithError(true); >+ >+ //verify log >+ try { >+ String[] parts = new String[] {"java.io.FileNotFoundException: ", "helloworld_1.0.0.jar"}; >+ assertLogContainsLine(log.getFile(), parts); >+ } catch (Exception e) { >+ fail("error verifying output", e); >+ } >+ >+ //run with verbose >+ //populate destination with duplicate artifacts. We assume this works >+ runMirrorApplication("Initializing Destiantion", sourceRepoLocation, destRepoLocation, false); //value of append should not matter >+ >+ try { >+ MirrorApplication app = new MirrorApplication(); >+ app.addSource(createRepositoryDescriptor(sourceRepoLocation.toURI(), null, null, null)); >+ app.addDestination(createRepositoryDescriptor(destRepoLocation.toURI(), null, null, null)); >+ //set the arguments with verbose >+ app.setVerbose(true); >+ //run the mirror application >+ app.run(null); >+ } catch (Exception e) { >+ fail("Error running mirror application to generate INFO items", e); >+ } >+ >+ System.setOut(oldOut); >+ newOut.close(); >+ System.setErr(oldErr); >+ newErr.close(); >+ >+ IArtifactRepository sourceRepository = null; >+ try { >+ sourceRepository = getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null); >+ } catch (ProvisionException e) { >+ fail("Error loading source repository for verification", e); >+ } >+ >+ try { >+ //Mirroring full duplicate, so any key will do. >+ IArtifactDescriptor[] descriptors = sourceRepository.getArtifactDescriptors(sourceRepository.getArtifactKeys()[0]); >+ //Mirroring full duplicate, so any descriptor will do. >+ String message = NLS.bind(org.eclipse.equinox.internal.p2.artifact.repository.Messages.mirror_alreadyExists, descriptors[0], destRepoLocation.toURI()); >+ assertLogContainsLine(log.getFile(), message); >+ } catch (Exception e) { >+ fail("Error verifying log", e); >+ } >+ } >+ >+ /** >+ * Test how the mirror application handles a repository specified as a local path >+ */ >+ public void testArtifactMirrorNonURIDest() { >+ try { >+ basicRunMirrorApplication("Mirroring", sourceRepoLocation.toURI(), destRepoLocation.toURI()); >+ assertContentEquals("2.1", getArtifactRepositoryManager().loadRepository(sourceRepoLocation.toURI(), null), getArtifactRepositoryManager().loadRepository(destRepoLocation.toURI(), null)); >+ } catch (Exception e) { >+ fail("Error mirroring", e); >+ } >+ } >+} >\ No newline at end of file >Index: src/org/eclipse/equinox/p2/tests/AbstractAntProvisioningTest.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/tests/AbstractAntProvisioningTest.java >diff -N src/org/eclipse/equinox/p2/tests/AbstractAntProvisioningTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/tests/AbstractAntProvisioningTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,263 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.equinox.p2.tests; >+ >+import java.io.File; >+import java.io.FileOutputStream; >+import java.net.URI; >+import java.util.*; >+import org.eclipse.ant.core.AntRunner; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.URIUtil; >+import org.eclipse.equinox.internal.p2.metadata.InstallableUnit; >+import org.eclipse.equinox.internal.p2.persistence.XMLWriter; >+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; >+import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; >+import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; >+import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery; >+import org.eclipse.equinox.internal.provisional.p2.query.Collector; >+import org.eclipse.equinox.internal.provisional.p2.query.IQueryable; >+ >+public class AbstractAntProvisioningTest extends AbstractProvisioningTest { >+ protected static final String TYPE_ARTIFACT = "A"; >+ protected static final String TYPE_METADATA = "M"; >+ protected static final String TYPE_BOTH = null; >+ >+ private static final String TARGET = "target"; >+ private static final String ROOT = "project"; >+ private static final String NAME = "name"; >+ private static final String DEFAULT_TARGET = "default"; >+ private static final String DEFAULT_NAME = "default"; >+ >+ AntTaskElement root, target; >+ File buildScript, logLocation; >+ >+ public void setUp() throws Exception { >+ super.setUp(); >+ buildScript = new File(getTempFolder(), getUniqueString()); >+ logLocation = new File(getTempFolder(), getUniqueString()); >+ createBuildScript(); >+ } >+ >+ public void tearDown() throws Exception { >+ // Delete the build script >+ delete(buildScript.getParentFile()); >+ delete(logLocation.getParentFile()); >+ super.tearDown(); >+ } >+ >+ /* >+ * Run the specified buildscript >+ */ >+ protected void runAntTask(File buildFile) { >+ try { >+ runAntTaskWithExceptions(buildFile); >+ } catch (CoreException e) { >+ fail(rootCause(e)); >+ } >+ } >+ >+ private void runAntTaskWithExceptions(File buildFile) throws CoreException { >+ AntRunner ant = new AntRunner(); >+ ant.setArguments("-logfile \"" + logLocation + "\""); >+ ant.setBuildFileLocation(buildFile.getAbsolutePath()); >+ ant.addBuildLogger("org.apache.tools.ant.XmlLogger"); >+ ant.run(); >+ } >+ >+ /* >+ * Run the build script described programmatically >+ */ >+ protected void runAntTask() { >+ try { >+ runAntTaskWithExceptions(); >+ } catch (CoreException e) { >+ fail(rootCause(e)); >+ } >+ } >+ >+ protected void runAntTaskWithExceptions() throws CoreException { >+ try { >+ writeBuildScript(); >+ } catch (Exception e) { >+ fail("Error writing build script", e); >+ } >+ runAntTaskWithExceptions(buildScript); >+ } >+ >+ /* >+ * Adds an Ant Task to the build script >+ */ >+ protected void addTask(AntTaskElement task) { >+ target.addElement(task); >+ } >+ >+ /* >+ * Create and return an repository element for this address and type >+ */ >+ protected AntTaskElement getRepositoryElement(URI address, String kind) { >+ return getRepositoryElement(address, kind, null, null, null, null); >+ } >+ >+ protected AntTaskElement getRepositoryElement(URI address, String kind, String name, String format, Boolean compressed, Boolean append) { >+ AntTaskElement repo = new AntTaskElement("repository"); >+ repo.addAttributes(new String[] {"location", URIUtil.toUnencodedString(address)}); >+ if (kind != null) >+ repo.addAttributes(new String[] {"kind", kind}); >+ if (name != null) >+ repo.addAttributes(new String[] {"name", name}); >+ if (format != null) >+ repo.addAttributes(new String[] {"format", format}); >+ if (compressed != null) >+ repo.addAttributes(new String[] {"compressed", compressed.toString()}); >+ if (append != null) >+ repo.addAttributes(new String[] {"append", append.toString()}); >+ return repo; >+ } >+ >+ /* >+ * Create the base elements of the build script >+ */ >+ private void createBuildScript() { >+ root = new AntTaskElement(ROOT); >+ root.addAttributes(new String[] {NAME, ROOT, DEFAULT_TARGET, DEFAULT_NAME}); >+ target = new AntTaskElement(TARGET); >+ target.addAttributes(new String[] {NAME, DEFAULT_NAME}); >+ root.addElement(target); >+ } >+ >+ /* >+ * Write the build script to disk >+ */ >+ private void writeBuildScript() throws Exception { >+ FileOutputStream outputStream = null; >+ try { >+ outputStream = new FileOutputStream(buildScript); >+ XMLWriter writer = new XMLWriter(outputStream, null); >+ writeElement(writer, root); >+ writer.flush(); >+ } finally { >+ if (outputStream != null) >+ outputStream.close(); >+ } >+ } >+ >+ /* >+ * Write an element to the buildscript >+ */ >+ private void writeElement(XMLWriter writer, AntTaskElement task) { >+ // Properties ought to occur in key-value pairs >+ assertTrue("Task " + task + " should have an even number of properties", (task.attributes.size() % 2) == 0); >+ >+ // Start tag >+ writer.start(task.name); >+ >+ // write properties >+ for (Iterator iter = task.attributes.iterator(); iter.hasNext();) >+ writer.attribute((String) iter.next(), (String) iter.next()); >+ >+ // write sub elements if applicable >+ for (Iterator iter = task.elements.iterator(); iter.hasNext();) >+ writeElement(writer, (AntTaskElement) iter.next()); >+ >+ // close tag >+ writer.end(); >+ } >+ >+ // Class which can be used to represent elements in a task >+ protected class AntTaskElement { >+ public String name; >+ public List attributes = new ArrayList(); >+ public List elements = new ArrayList(); >+ >+ public AntTaskElement(String name) { >+ this.name = name; >+ } >+ >+ public void addAttribute(String attribute, String value) { >+ attributes.add(attribute); >+ attributes.add(value); >+ } >+ >+ public void addAttributes(String[] propertyArray) { >+ attributes.addAll(Arrays.asList(propertyArray)); >+ } >+ >+ public void addElement(AntTaskElement element) { >+ elements.add(element); >+ } >+ >+ public String toString() { >+ return name; >+ } >+ } >+ >+ protected static Throwable rootCause(Throwable e) { >+ if (e.getCause() != null) >+ return rootCause(e.getCause()); >+ return e; >+ } >+ >+ protected static void fail(Throwable e) { >+ fail("An exception occurred while running the task", e); >+ } >+ >+ protected void assertLogContains(String content) { >+ try { >+ assertLogContainsLine(logLocation, content); >+ } catch (Exception e) { >+ fail("Error asserting log contents.", e); >+ } >+ } >+ >+ protected static void assertIUContentEquals(String message, IQueryable source, IQueryable destination) { >+ assertContains(message, source, destination); >+ assertContains(message, destination, source); >+ } >+ >+ protected static void assertArtifactKeyContentEquals(String message, Collector ius, URI artifactRepositoryLocation) { >+ try { >+ IArtifactRepository repo = getArtifactRepositoryManager().loadRepository(artifactRepositoryLocation, null); >+ List fromIUs = getArtifactKeys(ius); >+ List fromRepo = Arrays.asList(repo.getArtifactKeys()); >+ assertContains(message, fromIUs, fromRepo); >+ assertContains(message, fromRepo, fromIUs); >+ } catch (ProvisionException e) { >+ fail("Failed to load repository", e); >+ } >+ >+ } >+ >+ protected static void assertContains(String message, IQueryable source, IQueryable destination) { >+ Collector sourceCollector = source.query(InstallableUnitQuery.ANY, new Collector(), null); >+ Iterator it = sourceCollector.iterator(); >+ >+ while (it.hasNext()) { >+ IInstallableUnit sourceIU = (IInstallableUnit) it.next(); >+ Collector destinationCollector = destination.query(new InstallableUnitQuery(sourceIU.getId(), sourceIU.getVersion()), new Collector(), null); >+ assertEquals(message, 1, destinationCollector.size()); >+ assertTrue(message, sourceIU.equals(destinationCollector.iterator().next())); >+ } >+ } >+ >+ protected static void assertContains(String message, List fromIUs, List fromRepo) { >+ for (Iterator iter = fromIUs.iterator(); iter.hasNext();) >+ assertTrue(message, fromRepo.contains(iter.next())); >+ } >+ >+ protected static List getArtifactKeys(Collector ius) { >+ List keys = new ArrayList(ius.size()); >+ >+ for (Iterator iter = ius.iterator(); iter.hasNext();) >+ keys.addAll(Arrays.asList(((InstallableUnit) iter.next()).getArtifacts())); >+ return keys; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 265550
:
126782
|
127893
|
127894
|
128031
|
131327
|
131450
|
131810
|
131811
|
132255
|
132298
|
132421
|
132422
|
132782
| 132783 |
132785
|
132929