Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2009-04-29 20:18:46 +0000
committerPascal Rapicault2009-04-29 20:18:46 +0000
commitd1530272e01fcaba3091cd9dc8227902e27ed6be (patch)
treed53c841f26596a0626297a4656371cd22df621a4 /bundles
parent2a5b06a2595ae120f04ab89b5bf34330309ba13c (diff)
downloadrt.equinox.p2-d1530272e01fcaba3091cd9dc8227902e27ed6be.tar.gz
rt.equinox.p2-d1530272e01fcaba3091cd9dc8227902e27ed6be.tar.xz
rt.equinox.p2-d1530272e01fcaba3091cd9dc8227902e27ed6be.zip
Bug 264110 - Input format consistency for application and tasks
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/CompositeRepositoryApplication.java12
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Messages.java8
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java14
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/SlicingOptions.java3
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/messages.properties10
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CompositeRepositoryTask.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/Repo2RunnableTask.java5
-rw-r--r--bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/SlicingOption.java22
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractAntProvisioningTest.java17
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/AllTests.java1
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java232
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/Repo2RunnableTaskTests.java131
13 files changed, 418 insertions, 43 deletions
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/CompositeRepositoryApplication.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/CompositeRepositoryApplication.java
index dd5fa9fe8..9f42dea80 100644
--- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/CompositeRepositoryApplication.java
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/CompositeRepositoryApplication.java
@@ -13,6 +13,7 @@ package org.eclipse.equinox.p2.internal.repository.tools;
import java.net.MalformedURLException;
import java.util.*;
import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
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;
@@ -27,13 +28,14 @@ public class CompositeRepositoryApplication extends AbstractApplication {
private List childrenToAdd = new ArrayList();
private List childrenToRemove = new ArrayList();
private boolean failOnExists = false;
+ private String comparatorID = null;
public IStatus run(IProgressMonitor monitor) throws ProvisionException {
try {
initializeRepos(new NullProgressMonitor());
// load repository
ICompositeRepository metadataRepo = (ICompositeRepository) destinationMetadataRepository;
- ICompositeRepository artifactRepo = (ICompositeRepository) destinationArtifactRepository;
+ CompositeArtifactRepository artifactRepo = (CompositeArtifactRepository) destinationArtifactRepository;
// Remove children from the Composite Repositories
for (Iterator iterator = childrenToRemove.iterator(); iterator.hasNext();) {
@@ -52,6 +54,10 @@ public class CompositeRepositoryApplication extends AbstractApplication {
if (child.isMetadata() && metadataRepo != null)
metadataRepo.addChild(child.getRepoLocation());
}
+
+ if (comparatorID != null)
+ if (!artifactRepo.validate(comparatorID))
+ return new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.CompositeRepositoryApplication_failedComparator, comparatorID));
return Status.OK_STATUS;
} finally {
finalizeRepositories();
@@ -170,4 +176,8 @@ public class CompositeRepositoryApplication extends AbstractApplication {
if (desc.isCompressed() && !repository.getProperties().containsKey(IRepository.PROP_COMPRESSED))
repository.setProperty(IRepository.PROP_COMPRESSED, String.valueOf(true));
}
+
+ public void setComparator(String value) {
+ comparatorID = value;
+ }
}
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Messages.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Messages.java
index 43ba46ae0..1ec043a93 100644
--- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Messages.java
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/Messages.java
@@ -38,8 +38,13 @@ public class Messages extends NLS {
public static String unable_to_start_exemplarysetup;
public static String unknown_repository_type;
+ public static String MirrorApplication_artifactDestinationNoSource;
+ public static String MirrorApplication_metadataDestinationNoSource;
+ public static String MirrorApplication_missingIU;
+ public static String MirrorApplication_missingSourceForIUs;
public static String MirrorApplication_no_IUs;
public static String MirrorApplication_set_source_repositories;
+ public static String MirrorApplication_validateAndMirrorProblems;
public static String ProcessRepo_location_not_url;
public static String ProcessRepo_must_be_local;
@@ -47,6 +52,9 @@ public class Messages extends NLS {
public static String SlicingOption_invalid_platform;
public static String exception_invalidDestination;
public static String exception_invalidSource;
+ public static String CompositeRepositoryApplication_failedComparator;
+ public static String Repo2RunnableTask_errorTransforming;
+ public static String SlicingOption_invalidFilterFormat;
static {
// initialize resource bundles
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java
index 0193221f0..d02cda7f1 100644
--- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java
@@ -55,10 +55,10 @@ public class MirrorApplication extends AbstractApplication {
public IStatus run(IProgressMonitor monitor) throws ProvisionException {
IStatus mirrorStatus = Status.OK_STATUS;
try {
- validate();
initializeRepos(new NullProgressMonitor());
- initializeIUs();
initializeLogs();
+ validate();
+ initializeIUs();
IQueryable slice = slice(new NullProgressMonitor());
if (destinationArtifactRepository != null) {
mirrorStatus = mirrorArtifacts(slice, new NullProgressMonitor());
@@ -77,6 +77,7 @@ public class MirrorApplication extends AbstractApplication {
}
private IStatus mirrorArtifacts(IQueryable slice, IProgressMonitor monitor) throws ProvisionException {
+ // Obtain ArtifactKeys from IUs
Collector ius = slice.query(InstallableUnitQuery.ANY, new Collector(), monitor);
ArrayList keys = new ArrayList(ius.size());
for (Iterator iterator = ius.iterator(); iterator.hasNext();) {
@@ -129,6 +130,10 @@ public class MirrorApplication extends AbstractApplication {
private void validate() throws ProvisionException {
if (sourceRepositories.isEmpty())
throw new ProvisionException(Messages.MirrorApplication_set_source_repositories);
+ if (!hasArtifactSources() && destinationArtifactRepository != null)
+ throw new ProvisionException(Messages.MirrorApplication_artifactDestinationNoSource);
+ if (!hasMetadataSources() && destinationMetadataRepository != null)
+ throw new ProvisionException(Messages.MirrorApplication_metadataDestinationNoSource);
}
/*
@@ -145,11 +150,8 @@ public class MirrorApplication extends AbstractApplication {
sourceIUs.add(iu);
}
- if (collector.size() == 0 && destinationMetadataRepository != null) {
+ if (collector.size() == 0 && destinationMetadataRepository != null)
throw new ProvisionException(Messages.MirrorApplication_no_IUs);
- }
- } else {
- //TODO Check that the IU is in repo
}
}
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/SlicingOptions.java b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/SlicingOptions.java
index 94e52f2a4..a016e26e8 100644
--- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/SlicingOptions.java
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/SlicingOptions.java
@@ -11,6 +11,7 @@
package org.eclipse.equinox.p2.internal.repository.tools;
import java.util.Dictionary;
+import java.util.Properties;
public class SlicingOptions {
private boolean includeOptionalDependencies = true;
@@ -53,6 +54,8 @@ public class SlicingOptions {
}
public Dictionary getFilter() {
+ if (filter == null)
+ filter = new Properties();
return filter;
}
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/messages.properties b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/messages.properties
index 14cc86475..0363e9ce9 100644
--- a/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/messages.properties
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/messages.properties
@@ -14,6 +14,7 @@ AbstractRepositoryTask_unableToFind=Unable to find: {0}
CompositeRepository_composite_repository_exists=Composite repository already exists at location: {0}
CompositeRepository_default_artifactRepo_name=Composite Artifact Repository
CompositeRepository_default_metadataRepo_name=Composite Artifact Repository
+CompositeRepositoryApplication_failedComparator=Artifact repository failed test with comparator: {0}
no_artifactRepo_manager=Unable to acquire artifact repository manager service.
no_metadataRepo_manager=Unable to acquire metadata repository manager service.
@@ -23,12 +24,18 @@ unable_to_process_uri=Unable to process as URI: {0}
unable_to_start_exemplarysetup=Unable to start exemplarysetup bundle.
unknown_repository_type=Repository is of an unknown type: {0}
+MirrorApplication_artifactDestinationNoSource=Destination artifact repository specified without a corresponding source artifact repository.
+MirrorApplication_metadataDestinationNoSource=Destination metadata repository specified without a corresponding source metadata repository.
+MirrorApplication_missingIU=Missing: {0}
+MirrorApplication_missingSourceForIUs=Unable to locate source repository for IUs
MirrorApplication_no_IUs=No IUs specified and no IUs obtained from metadata repositories.
MirrorApplication_set_source_repositories=Need to set the source repository location(s).
+MirrorApplication_validateAndMirrorProblems=Problems occurred during validation and mirroring
ProcessRepo_location_not_url=Repository location {0} must be a URL.
ProcessRepo_must_be_local=Repository must be local: {0}
SlicingOption_invalid_platform=Invalid platform filter format: {0}.
+SlicingOption_invalidFilterFormat=Invalid filter format: {0}
exception_destinationNotModifiable = The destination repository must be modifiable: {0}.
exception_invalidDestination=Invalid destination repository location: {0}.
exception_invalidSource=Invalid source repository location: {0}.
@@ -37,4 +44,5 @@ exception_notLocalFileRepo= {0} is not a local file based repository.
exception_noEngineService=Unable to acquire engine service.
exception_needIUsOrNonEmptyRepo=Need to specify either a non-empty source metadata repository or a valid list of IUs.
exception_needDestinationRepo=Need to set the destination artifact repository location.
-exception_onlyOneComparator=Only one comparator should be defined. \ No newline at end of file
+exception_onlyOneComparator=Only one comparator should be defined.
+Repo2RunnableTask_errorTransforming=Error occurred while transforming repository. \ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CompositeRepositoryTask.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CompositeRepositoryTask.java
index ec674dcc4..f1e8e9e9c 100644
--- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CompositeRepositoryTask.java
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CompositeRepositoryTask.java
@@ -62,4 +62,8 @@ public class CompositeRepositoryTask extends AbstractRepositoryTask {
public void setFailOnExists(boolean value) {
((CompositeRepositoryApplication) application).setFailOnExists(value);
}
+
+ public void setValidate(String value) {
+ ((CompositeRepositoryApplication) application).setComparator(value);
+ }
}
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java
index 5fdb90312..8be3de90d 100644
--- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/IUDescription.java
@@ -95,7 +95,7 @@ public class IUDescription extends DataType {
queries.add(new InstallableUnitQuery(id));
queries.add(new LatestIUVersionQuery());
} else {
- Version iuVersion = new Version(version);
+ Version iuVersion = Version.parseVersion(version);
queries.add(new InstallableUnitQuery(id, iuVersion));
}
}
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/Repo2RunnableTask.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/Repo2RunnableTask.java
index d3fb10cdb..5d03cb48d 100644
--- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/Repo2RunnableTask.java
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/Repo2RunnableTask.java
@@ -14,6 +14,7 @@ import java.util.List;
import org.apache.tools.ant.BuildException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
+import org.eclipse.equinox.p2.internal.repository.tools.Messages;
import org.eclipse.equinox.p2.internal.repository.tools.Repo2Runnable;
/**
@@ -45,13 +46,13 @@ public class Repo2RunnableTask extends AbstractRepositoryTask {
application.initializeRepos(null);
List ius = prepareIUs();
if ((ius == null || ius.size() == 0) && !(application.hasArtifactSources() || application.hasMetadataSources()))
- throw new BuildException("Need to specify either a non-empty source metadata repository or a valid list of IUs.");
+ throw new BuildException(Messages.exception_needIUsOrNonEmptyRepo);
application.setSourceIUs(ius);
IStatus result = application.run(null);
if (result.matches(IStatus.ERROR))
throw new ProvisionException(result);
} catch (ProvisionException e) {
- throw new BuildException("Error occurred while transforming repository.", e);
+ throw new BuildException(Messages.Repo2RunnableTask_errorTransforming, e);
}
}
}
diff --git a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/SlicingOption.java b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/SlicingOption.java
index c7ff268f6..79b79ae30 100644
--- a/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/SlicingOption.java
+++ b/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/SlicingOption.java
@@ -10,7 +10,8 @@
*******************************************************************************/
package org.eclipse.equinox.p2.internal.repository.tools.tasks;
-import java.util.*;
+import java.util.Dictionary;
+import java.util.StringTokenizer;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.eclipse.equinox.p2.internal.repository.tools.Messages;
@@ -56,8 +57,6 @@ public class SlicingOption extends Task {
if (tok.countTokens() != 3)
throw new BuildException(NLS.bind(Messages.SlicingOption_invalid_platform, platformFilter));
Dictionary filter = options.getFilter();
- if (filter == null)
- filter = new Properties();
filter.put("osgi.os", tok.nextToken().trim()); //$NON-NLS-1$
filter.put("osgi.ws", tok.nextToken().trim()); //$NON-NLS-1$
filter.put("osgi.arch", tok.nextToken().trim()); //$NON-NLS-1$
@@ -70,12 +69,25 @@ public class SlicingOption extends Task {
public void setIncludeFeatures(boolean includeFeatures) {
Dictionary filter = options.getFilter();
- if (filter == null)
- filter = new Properties();
filter.put("org.eclipse.update.install.features", String.valueOf(includeFeatures)); //$NON-NLS-1$
options.setFilter(filter);
}
+ public void setFilter(String filterString) {
+ if (filterString == null || filterString.trim().equals("")) //$NON-NLS-1$
+ return;
+ Dictionary filter = options.getFilter();
+ StringTokenizer tok = new StringTokenizer(filterString, ","); //$NON-NLS-1$
+ while (tok.hasMoreTokens()) {
+ String rule = tok.nextToken().trim();
+ int eqIndex = rule.indexOf('=');
+ if (eqIndex == -1)
+ throw new BuildException(NLS.bind(Messages.SlicingOption_invalidFilterFormat, rule));
+ filter.put(rule.substring(0, eqIndex), rule.substring(eqIndex + 1));
+ }
+ options.setFilter(filter);
+ }
+
/**
* Set this property to true if only strict dependencies must be followed. A strict dependency is defined by a version range only including one version (e.g. [1.0.0.v2009, 1.0.0.v2009])
* The default value is false.
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractAntProvisioningTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractAntProvisioningTest.java
index 8cb4a2353..e5244b825 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractAntProvisioningTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/AbstractAntProvisioningTest.java
@@ -124,6 +124,23 @@ public class AbstractAntProvisioningTest extends AbstractProvisioningTest {
}
/*
+ * Create an element from the specified information
+ */
+ protected AntTaskElement createIUElement(IInstallableUnit iu) {
+ return createIUElement(iu.getId(), iu.getVersion().toString());
+ }
+
+ /*
+ * Create an element from the specified information
+ */
+ protected AntTaskElement createIUElement(String id, String version) {
+ AntTaskElement iuElement = new AntTaskElement("iu");
+ iuElement.addAttribute("id", id);
+ iuElement.addAttribute("version", version);
+ return iuElement;
+ }
+
+ /*
* Create the base elements of the build script
*/
private void createBuildScript() {
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/AllTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/AllTests.java
index f0f81bc0b..94689ddef 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/AllTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/AllTests.java
@@ -21,6 +21,7 @@ public class AllTests extends TestCase {
TestSuite suite = new TestSuite(AllTests.class.getName());
suite.addTestSuite(CompositeRepositoryTaskTest.class);
suite.addTestSuite(MirrorTaskTest.class);
+ suite.addTestSuite(Repo2RunnableTaskTests.class);
return suite;
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java
index 7bdebfda4..784be871c 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java
@@ -137,9 +137,32 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest {
}
/*
+ * Test what occurs with a missing IU
+ */
+ public void testMirrorMissingIU() {
+ String id = "My_Missing_IU";
+ String version = "1.0.0";
+ String iu = "Installable Unit [ id=" + id + " version=" + version + " ]";
+
+ AntTaskElement mirror = createMirrorTask(TYPE_BOTH);
+ mirror.addElement(createSourceElement(sourceRepo2, sourceRepo2));
+ mirror.addElement(createIUElement(id, version));
+ Exception exception = null;
+ try {
+ runAntTaskWithExceptions();
+ } catch (CoreException e) {
+ exception = e;
+ }
+ if (exception == null)
+ fail("No Exception was thrown");
+
+ assertEquals("Unexpected message", NLS.bind(org.eclipse.equinox.p2.internal.repository.tools.Messages.AbstractRepositoryTask_unableToFind, iu), rootCause(exception).getMessage());
+ }
+
+ /*
* Test that the proper exception is thrown when no IU is provided
*/
- public void testMirrorNoIUNoRepo() {
+ public void testMirrorMetadataDestinationWithoutSource() {
AntTaskElement mirror = createMirrorTask(TYPE_BOTH);
mirror.addElement(createSourceElement(sourceRepo2, null));
@@ -151,9 +174,27 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest {
}
if (exception == null)
fail("No exception thrown");
- if (!(rootCause(exception) instanceof ProvisionException) && !rootCause(exception).getMessage().contains("No IUs"))
+ if (!(rootCause(exception) instanceof ProvisionException && rootCause(exception).getMessage().equals(org.eclipse.equinox.p2.internal.repository.tools.Messages.MirrorApplication_metadataDestinationNoSource)))
fail("Exception is of an unexpected type or message", rootCause(exception));
+ }
+
+ /*
+ * Test that the proper exception is thrown when no IU is provided
+ */
+ public void testMirrorArtifactDestinationWithoutSource() {
+ AntTaskElement mirror = createMirrorTask(TYPE_BOTH);
+ mirror.addElement(createSourceElement(null, sourceRepo2));
+ 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(org.eclipse.equinox.p2.internal.repository.tools.Messages.MirrorApplication_artifactDestinationNoSource))
+ fail("Exception is of an unexpected type or message", rootCause(exception));
}
/*
@@ -201,6 +242,33 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest {
}
/*
+ * Test the behavior when a valid path is provided as source, but no repository is present at the location
+ */
+ public void testMirrorWithNoRepositoryAtSource() {
+ URI location = getTempFolder().toURI();
+ try {
+ 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("No repository found at {0}.", location).equals(exception.getMessage()));
+ } finally {
+ delete(new File(location));
+ }
+ }
+
+ /*
* Test the handling of invalid destinations with the mirror task
*/
public void testMirrorWithInvalidSource() throws URISyntaxException {
@@ -239,8 +307,8 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest {
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()));
+ mirror.addElement(createSlicingOption(null, null, true, null, "win32,win32,x86", null));
+ mirror.addElement(createIUElement(iu));
runAntTask();
@@ -269,8 +337,8 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest {
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()));
+ mirror.addElement(createSlicingOption(null, false, null, null, null, null));
+ mirror.addElement(createIUElement(iu));
runAntTask();
@@ -297,8 +365,8 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest {
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()));
+ mirror.addElement(createSlicingOption(false, null, null, null, "win32,win32,x86", null));
+ mirror.addElement(createIUElement(iu));
runAntTask();
@@ -314,6 +382,34 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest {
}
}
+ public void testSlicingFilter() {
+ 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", "org.eclipse.update.install.features=false"));
+ mirror.addElement(createIUElement(iu));
+
+ runAntTask();
+
+ Properties p = getSliceProperties();
+ PermissiveSlicer slicer = new PermissiveSlicer(repo, p, true, true, true, false, 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
*/
@@ -329,8 +425,8 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest {
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()));
+ mirror.addElement(createSlicingOption(null, null, null, null, "win32,win32,x86", null));
+ mirror.addElement(createIUElement(iu));
runAntTask();
@@ -362,8 +458,8 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest {
// 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()));
+ mirror.addElement(createSlicingOption(null, null, null, false, "win32,win32,x86", null));
+ mirror.addElement(createIUElement(iu));
runAntTask();
@@ -381,7 +477,7 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest {
/*
* Tests the results of a slice are used to mirror artifacts
*/
- public void testSlicingArtifactsMirrored() {
+ public void testSlicingMetadataAndArtifactsMirrored() {
IMetadataRepository repo = null;
try {
repo = loadMetadataRepository(sliceArtifactRepo);
@@ -394,8 +490,8 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest {
// 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()));
+ mirror.addElement(createSlicingOption(null, null, null, false, "win32,win32,x86", null));
+ mirror.addElement(createIUElement(iu));
runAntTask();
@@ -415,12 +511,101 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest {
}
/*
+ * Test the ability to slice an IU and mirror only the artifacts
+ */
+ public void testMirrorSlicedIUtoArtifact() {
+ 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_ARTIFACT);
+ mirror.addElement(createSourceElement(sliceArtifactRepo, sliceArtifactRepo));
+ mirror.addElement(createSlicingOption(null, null, null, false, "win32,win32,x86", null));
+ mirror.addElement(createIUElement(iu));
+
+ runAntTask();
+
+ Properties p = getSliceProperties();
+ PermissiveSlicer slicer = new PermissiveSlicer(repo, p, true, true, true, false, false);
+ IQueryable result = slicer.slice(new IInstallableUnit[] {iu}, new NullProgressMonitor());
+
+ assertEquals("Different number of ArtifactKeys", getArtifactKeyCount(result.query(InstallableUnitQuery.ANY, new Collector(), new NullProgressMonitor())), getArtifactKeyCount(destinationRepo));
+ assertArtifactKeyContentEquals("Different ArtifactKeys", result.query(InstallableUnitQuery.ANY, new Collector(), new NullProgressMonitor()), destinationRepo);
+ }
+
+ /*
+ * Test the ability to slice an IU and mirror only the artifacts
+ */
+ public void testMirrorSlicedMultipleIUsToArtifact() {
+ 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();
+
+ c = repo.query(new InstallableUnitQuery("RCP_Browser_Example.feature.group"), new Collector(), new NullProgressMonitor());
+ IInstallableUnit iu2 = (IInstallableUnit) c.iterator().next();
+
+ // Create task
+ AntTaskElement mirror = createMirrorTask(TYPE_ARTIFACT);
+ mirror.addElement(createSourceElement(sliceArtifactRepo, sliceArtifactRepo));
+ mirror.addElement(createSlicingOption(null, null, null, false, "win32,win32,x86", null));
+ mirror.addElement(createIUElement(iu));
+ mirror.addElement(createIUElement(iu2));
+
+ runAntTask();
+
+ Properties p = getSliceProperties();
+ PermissiveSlicer slicer = new PermissiveSlicer(repo, p, true, true, true, false, false);
+ IQueryable result = slicer.slice(new IInstallableUnit[] {iu, iu2}, new NullProgressMonitor());
+
+ assertEquals("Different number of ArtifactKeys", getArtifactKeyCount(result.query(InstallableUnitQuery.ANY, new Collector(), new NullProgressMonitor())), getArtifactKeyCount(destinationRepo));
+ assertArtifactKeyContentEquals("Different ArtifactKeys", result.query(InstallableUnitQuery.ANY, new Collector(), new NullProgressMonitor()), destinationRepo);
+ }
+
+ /*
+ * Test the ability to slice an IU and mirror only the artifacts
+ */
+ public void testMirrorIUtoArtifact() {
+ IMetadataRepository repo = null;
+ try {
+ repo = loadMetadataRepository(sliceArtifactRepo);
+ } catch (ProvisionException e) {
+ fail("Loading repository failed", e);
+ }
+ Collector c = repo.query(new InstallableUnitQuery("org.eclipse.ui.examples.readmetool"), new Collector(), new NullProgressMonitor());
+ IInstallableUnit iu = (IInstallableUnit) c.iterator().next();
+
+ // Create task
+ AntTaskElement mirror = createMirrorTask(TYPE_ARTIFACT);
+ mirror.addElement(createSourceElement(sliceArtifactRepo, sliceArtifactRepo));
+ mirror.addElement(createIUElement(iu));
+
+ runAntTask();
+
+ Collector collector = new Collector();
+ collector.accept(iu);
+
+ assertEquals("Different number of ArtifactKeys", getArtifactKeyCount(collector), getArtifactKeyCount(destinationRepo));
+ assertArtifactKeyContentEquals("Different ArtifactKeys", collector, destinationRepo);
+ }
+
+ /*
* 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"));
+ mirror.addElement(createSlicingOption(null, null, null, null, "win32,win32,x86", null));
Exception exception = null;
try {
@@ -529,7 +714,7 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest {
return p;
}
- protected AntTaskElement createSlicingOption(Boolean includeOptional, Boolean includeNonGreedy, Boolean followStrict, Boolean includeFeatures, String platformFilter) {
+ protected AntTaskElement createSlicingOption(Boolean includeOptional, Boolean includeNonGreedy, Boolean followStrict, Boolean includeFeatures, String platformFilter, String filter) {
AntTaskElement slicing = new AntTaskElement("slicingoptions");
if (followStrict != null)
slicing.addAttribute("followstrict", followStrict.toString());
@@ -541,6 +726,8 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest {
slicing.addAttribute("includeoptional", includeOptional.toString());
if (platformFilter != null)
slicing.addAttribute("platformfilter", platformFilter);
+ if (filter != null)
+ slicing.addAttribute("filter", filter);
return slicing;
}
@@ -619,20 +806,11 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest {
for (Iterator iter = collector.iterator(); iter.hasNext();) {
IInstallableUnit iu = (IInstallableUnit) iter.next();
- parent.addElement(createIUElement(iu.getId(), iu.getVersion().toString()));
+ parent.addElement(createIUElement(iu));
}
}
/*
- * 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) {
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/Repo2RunnableTaskTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/Repo2RunnableTaskTests.java
new file mode 100644
index 000000000..a04e637f0
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/Repo2RunnableTaskTests.java
@@ -0,0 +1,131 @@
+package org.eclipse.equinox.p2.tests.ant;
+
+import java.io.File;
+import java.net.URI;
+import java.util.Collection;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor;
+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.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.query.Collector;
+import org.eclipse.equinox.p2.tests.AbstractAntProvisioningTest;
+
+public class Repo2RunnableTaskTests extends AbstractAntProvisioningTest {
+
+ private URI destination, source;
+
+ public void setUp() throws Exception {
+ source = getTestData("Error loading data", "testData/mirror/mirrorSourceRepo1 with space").toURI();
+ destination = getTempFolder().toURI();
+ super.setUp();
+ }
+
+ public void tearDown() throws Exception {
+ getArtifactRepositoryManager().removeRepository(source);
+ getMetadataRepositoryManager().removeRepository(source);
+ getArtifactRepositoryManager().removeRepository(destination);
+ getMetadataRepositoryManager().removeRepository(destination);
+ delete(new File(destination));
+ super.tearDown();
+ }
+
+ /*
+ * Test the Repo2RunnableTask functions as expected on a simple repository
+ */
+ public void testRepo2Runnable() {
+ createRepo2RunnableTaskElement(TYPE_BOTH);
+
+ runAntTask();
+ assertEquals("Number of artifact keys differs", getArtifactKeyCount(source), getArtifactKeyCount(destination));
+ assertTrue("Unexpected format", expectedFormat(destination));
+ }
+
+ /*
+ * Test that when an IU is specified that it is used
+ */
+ public void testRepo2RunnableSpecifiedIU() {
+ IInstallableUnit iu = null;
+ try {
+ IMetadataRepository repo = getMetadataRepositoryManager().loadRepository(source, new NullProgressMonitor());
+ Collection ius = repo.query(new InstallableUnitQuery("helloworldfeature.feature.jar"), new Collector(), new NullProgressMonitor()).toCollection();
+ assertEquals("Expected number of IUs", 1, ius.size());
+ iu = (IInstallableUnit) ius.iterator().next();
+ } catch (ProvisionException e) {
+ fail("Failed to obtain iu", e);
+ }
+ AntTaskElement task = createRepo2RunnableTaskElement(TYPE_BOTH);
+ task.addElement(createIUElement(iu));
+
+ runAntTask();
+ assertEquals("Number of artifact keys differs", iu.getArtifacts().length, getArtifactKeyCount(destination));
+ assertTrue("Unexpected format", expectedFormat(destination));
+ }
+
+ /*
+ * Ensure that the output repository is of the expected type
+ */
+ protected boolean expectedFormat(URI location) {
+ IArtifactRepository repo = null;
+ try {
+ repo = getArtifactRepositoryManager().loadRepository(location, new NullProgressMonitor());
+ } catch (ProvisionException e) {
+ fail("Failed to load repository", e);
+ }
+ IArtifactKey[] keys = repo.getArtifactKeys();
+ for (int i = 0; i < keys.length; i++) {
+ IArtifactKey key = keys[i];
+ IArtifactDescriptor[] descriptors = repo.getArtifactDescriptors(key);
+ for (int n = 0; n < descriptors.length; n++) {
+ IArtifactDescriptor desc = descriptors[n];
+ // Features should be unzipped, others should not be.
+ boolean isFolder = desc.getProperty("artifact.folder") != null ? Boolean.valueOf(desc.getProperty("artifact.folder")) : false;
+ if (key.getClassifier().equals(""))
+ assertTrue(desc + " is not a folder", isFolder);
+ else
+ assertFalse(desc + " is a folder", isFolder);
+ // Artifacts should not be packed
+ assertTrue("Artifact is still packed", !"packed".equals(desc.getProperty("format")));
+ }
+ }
+ return true;
+ }
+
+ /*
+ * Count the number of ArtifactKeys in the repository at the given location
+ */
+ protected int getArtifactKeyCount(URI location) {
+ try {
+ return getArtifactRepositoryManager().loadRepository(location, new NullProgressMonitor()).getArtifactKeys().length;
+ } catch (ProvisionException e) {
+ fail("Failed to count keys in repository", e);
+ return -1;
+ }
+ }
+
+ /*
+ * Create a simple AntTaskElement for the Repo2RunnableTask
+ */
+ protected AntTaskElement createRepo2RunnableTaskElement() {
+ AntTaskElement task = new AntTaskElement("p2.repo2runnable");
+ addTask(task);
+ return task;
+ }
+
+ /*
+ * Create an AntTaskElement for the Repo2Runnabletask populated with the default source & destination
+ */
+ protected AntTaskElement createRepo2RunnableTaskElement(String type) {
+ AntTaskElement task = createRepo2RunnableTaskElement();
+ task.addElement(getRepositoryElement(destination, type));
+
+ AntTaskElement sourceElement = new AntTaskElement("source");
+ sourceElement.addElement(getRepositoryElement(source, type));
+ task.addElement(sourceElement);
+
+ return task;
+ }
+}

Back to the top