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 131327 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]
Repository Ant Tasks & Tests
NewTasks.patch (text/plain), 92.31 KB, created by
Matthew Piggott
on 2009-04-08 15:18:13 EDT
(
hide
)
Description:
Repository Ant Tasks & Tests
Filename:
MIME Type:
Creator:
Matthew Piggott
Created:
2009-04-08 15:18:13 EDT
Size:
92.31 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.equinox.p2.tests >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.59 >diff -u -r1.59 MANIFEST.MF >--- META-INF/MANIFEST.MF 30 Mar 2009 01:48:52 -0000 1.59 >+++ META-INF/MANIFEST.MF 8 Apr 2009 19:17:47 -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.equinox.internal.p2.artifact.mirror, > org.eclipse.equinox.internal.p2.artifact.processors.md5, > org.eclipse.equinox.internal.p2.artifact.processors.pack200, >@@ -38,7 +39,6 @@ > org.eclipse.equinox.internal.provisional.p2.core, > org.eclipse.equinox.internal.provisional.p2.core.eventbus, > org.eclipse.equinox.internal.provisional.p2.core.location, >- org.eclipse.equinox.internal.provisional.p2.repository, > org.eclipse.equinox.internal.provisional.p2.director, > org.eclipse.equinox.internal.provisional.p2.directorywatcher, > org.eclipse.equinox.internal.provisional.p2.engine, >@@ -47,6 +47,7 @@ > org.eclipse.equinox.internal.provisional.p2.metadata.query, > org.eclipse.equinox.internal.provisional.p2.metadata.repository, > org.eclipse.equinox.internal.provisional.p2.query, >+ org.eclipse.equinox.internal.provisional.p2.repository, > 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, >Index: src/org/eclipse/equinox/p2/tests/ant/CreateCompositeRepositoryTaskTest.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/tests/ant/CreateCompositeRepositoryTaskTest.java >diff -N src/org/eclipse/equinox/p2/tests/ant/CreateCompositeRepositoryTaskTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/tests/ant/CreateCompositeRepositoryTaskTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,177 @@ >+package org.eclipse.equinox.p2.tests.ant; >+ >+import java.io.File; >+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.provisional.p2.artifact.repository.IArtifactRepository; >+import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; >+import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; >+import org.eclipse.equinox.p2.tests.AbstractAntProvisioningTest; >+ >+public class CreateCompositeRepositoryTaskTest extends AbstractAntProvisioningTest { >+ private URI compositeSite; >+ private static URI HTTP_SITE; >+ >+ public void setUp() throws Exception { >+ super.setUp(); >+ // Get a random location to create a repository >+ compositeSite = (new File(getTempFolder(), getUniqueString())).toURI(); >+ HTTP_SITE = new URI("http://download.eclipse.org/eclipse/updates/3.4/"); >+ } >+ >+ public void tearDown() throws Exception { >+ // Remove repository manager references >+ getArtifactRepositoryManager().removeRepository(compositeSite); >+ getMetadataRepositoryManager().removeRepository(compositeSite); >+ // Cleanup disk >+ delete(new File(compositeSite)); >+ super.tearDown(); >+ } >+ >+ public void testCreateCompositeArtifactRepository() throws Exception { >+ // Create Composite Repository Task >+ AntTaskElement createCompositeTask = getCreateCompositeTask(TYPE_ARTIFACT); >+ addTask(createCompositeTask); >+ >+ runAntTask(); >+ >+ assertTrue(getArtifactRepositoryManager().contains(compositeSite)); >+ assertTrue(getArtifactRepositoryManager().loadRepository(compositeSite, null) instanceof CompositeArtifactRepository); >+ } >+ >+ public void testCreateCompositeMetadataRepository() throws Exception { >+ // Create Composite Repository Task >+ AntTaskElement createCompositeTask = getCreateCompositeTask(TYPE_METADATA); >+ addTask(createCompositeTask); >+ >+ runAntTask(); >+ >+ assertTrue(getMetadataRepositoryManager().contains(compositeSite)); >+ assertTrue(getMetadataRepositoryManager().loadRepository(compositeSite, null) instanceof CompositeMetadataRepository); >+ } >+ >+ public void testCreateCombinedCompositeRepository() throws Exception { >+ // Create Composite Repository Task >+ AntTaskElement createCompositeTask = getCreateCompositeTask(null); >+ addTask(createCompositeTask); >+ >+ runAntTask(); >+ >+ assertTrue(getMetadataRepositoryManager().contains(compositeSite)); >+ assertTrue(getArtifactRepositoryManager().contains(compositeSite)); >+ assertTrue(getMetadataRepositoryManager().loadRepository(compositeSite, null) instanceof CompositeMetadataRepository); >+ assertTrue(getArtifactRepositoryManager().loadRepository(compositeSite, null) instanceof CompositeArtifactRepository); >+ } >+ >+ public void testFailOnExists() throws Exception { >+ // Create Composite Repository Task >+ AntTaskElement createCompositeTask = getCreateCompositeTask(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); >+ } >+ >+ public void testNotCompressed() throws Exception { >+ // Create Composite Repository Task >+ AntTaskElement createCompositeTask = getCreateCompositeTask(TYPE_ARTIFACT); >+ addTask(createCompositeTask); >+ // Set the compressed attribute to false >+ ((AntTaskElement) createCompositeTask.elements.get(0)).addAttributes(new String[] {"compressed", String.valueOf(false)}); >+ runAntTask(); >+ >+ try { >+ IArtifactRepository repo = getArtifactRepositoryManager().loadRepository(compositeSite, null); >+ assertTrue(repo instanceof CompositeArtifactRepository); >+ assertFalse("The repository is compressed", Boolean.valueOf((String) repo.getProperties().get(IRepository.PROP_COMPRESSED))); >+ } catch (ProvisionException e) { >+ fail("Failed to load repository", e); >+ } >+ } >+ >+ public void testName() { >+ String repoName = "My Test Repository"; >+ // Create Composite Repository Task >+ AntTaskElement createCompositeTask = getCreateCompositeTask(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); >+ } >+ } >+ >+ public void testAddChild() { >+ // Create Composite Repository Task >+ AntTaskElement createCompositeTask = getCreateCompositeTask(TYPE_ARTIFACT); >+ addTask(createCompositeTask); >+ >+ // Create add element >+ AntTaskElement addElement = new AntTaskElement("add"); >+ // Add a repository >+ addElement.addElement(getRepositoryElement(HTTP_SITE, TYPE_ARTIFACT)); >+ createCompositeTask.addElement(addElement); >+ >+ runAntTask(); >+ >+ try { >+ CompositeArtifactRepository repo = (CompositeArtifactRepository) getArtifactRepositoryManager().loadRepository(compositeSite, null); >+ assertTrue(repo.getChildren().contains(HTTP_SITE)); >+ } catch (ProvisionException e) { >+ fail("Failed to load repository", e); >+ } >+ } >+ >+ public void testInvalidLocation() throws Exception { >+ URI location = URIUtil.fromString("scheme:/location"); >+ AntTaskElement createCompositeTask = new AntTaskElement("p2.create.composite.repository"); >+ createCompositeTask.addElement(getRepositoryElement(location, TYPE_ARTIFACT)); >+ addTask(createCompositeTask); >+ >+ Exception exception = null; >+ try { >+ runAntTaskWithExceptions(); >+ } catch (CoreException e) { >+ exception = e; >+ if (!(rootCause(e) instanceof IllegalStateException)) >+ fail("Expected IllegalStateException.", 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"); >+ >+ } >+ >+ private AntTaskElement getCreateCompositeTask(String type) { >+ AntTaskElement createCompositeTask = new AntTaskElement("p2.create.composite.repository"); >+ createCompositeTask.addElement(getRepositoryElement(compositeSite, type)); >+ return createCompositeTask; >+ } >+} >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,202 @@ >+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.persistence.XMLWriter; >+ >+public class AbstractAntProvisioningTest extends AbstractProvisioningTest { >+ protected static final String TYPE_ARTIFACT = "A"; >+ protected static final String TYPE_METADATA = "M"; >+ >+ 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); >+ } >+ } >+} >Index: src/org/eclipse/equinox/p2/tests/ant/ModifyCompositeRepositoryTaskTest.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/tests/ant/ModifyCompositeRepositoryTaskTest.java >diff -N src/org/eclipse/equinox/p2/tests/ant/ModifyCompositeRepositoryTaskTest.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/tests/ant/ModifyCompositeRepositoryTaskTest.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,189 @@ >+package org.eclipse.equinox.p2.tests.ant; >+ >+import java.io.File; >+import java.net.URI; >+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.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.p2.tests.AbstractAntProvisioningTest; >+ >+public class ModifyCompositeRepositoryTaskTest extends AbstractAntProvisioningTest { >+ private static final String ADD_ELEMENT = "add"; >+ private static final String REMOVE_ELEMENT = "remove"; >+ private URI compositeSite; >+ private static URI HTTP_SITE; >+ >+ public void setUp() throws Exception { >+ super.setUp(); >+ // Get a random location to create a repository >+ compositeSite = (new File(getTempFolder(), getUniqueString())).toURI(); >+ HTTP_SITE = new URI("http://download.eclipse.org/eclipse/updates/3.4/"); >+ } >+ >+ public void tearDown() throws Exception { >+ // Remove repository manager references >+ getArtifactRepositoryManager().removeRepository(compositeSite); >+ getMetadataRepositoryManager().removeRepository(compositeSite); >+ // Cleanup disk >+ delete(new File(compositeSite)); >+ super.tearDown(); >+ } >+ >+ public void testAddChildArtifact() throws Exception { >+ // Create repository >+ createCompositeRepository(TYPE_ARTIFACT); >+ // Create the modify repository task >+ AntTaskElement modify = createModifyElement(TYPE_ARTIFACT); >+ addTask(modify); >+ >+ // Create the Add element >+ AntTaskElement add = new AntTaskElement(ADD_ELEMENT); >+ add.addElement(getRepositoryElement(HTTP_SITE, TYPE_ARTIFACT)); >+ modify.addElement(add); >+ >+ // Run the task >+ runAntTask(); >+ >+ CompositeArtifactRepository repo = (CompositeArtifactRepository) getCompositeRepository(TYPE_ARTIFACT); >+ assertTrue("Repository does not contain child", repo.getChildren().contains(HTTP_SITE)); >+ } >+ >+ public void testAddChildMetadata() { >+ // Create repository >+ createCompositeRepository(TYPE_METADATA); >+ // Create the modify repository task >+ AntTaskElement modify = createModifyElement(TYPE_METADATA); >+ addTask(modify); >+ >+ // Create the Add element >+ AntTaskElement add = new AntTaskElement(ADD_ELEMENT); >+ add.addElement(getRepositoryElement(HTTP_SITE, TYPE_METADATA)); >+ modify.addElement(add); >+ >+ // Run the task >+ runAntTask(); >+ >+ CompositeMetadataRepository repo = (CompositeMetadataRepository) getCompositeRepository(TYPE_METADATA); >+ assertTrue("Repository does not contain child", repo.getChildren().contains(HTTP_SITE)); >+ } >+ >+ public void testAddChildBoth() { >+ // Create repository >+ createCompositeRepository(null); >+ // Create the modify repository task >+ AntTaskElement modify = createModifyElement(null); >+ addTask(modify); >+ >+ // Create the Add element >+ AntTaskElement add = createAddElement(null, new URI[] {HTTP_SITE}); >+ modify.addElement(add); >+ >+ // Run the task >+ runAntTask(); >+ >+ CompositeArtifactRepository artifactRepo = (CompositeArtifactRepository) getCompositeRepository(TYPE_ARTIFACT); >+ assertTrue("Repository does not contain child", artifactRepo.getChildren().contains(HTTP_SITE)); >+ >+ CompositeMetadataRepository metadataRepo = (CompositeMetadataRepository) getCompositeRepository(TYPE_METADATA); >+ assertTrue("Repository does not contain child", metadataRepo.getChildren().contains(HTTP_SITE)); >+ } >+ >+ public void testRemoveAllChildren() { >+ // Create repository >+ ICompositeRepository parent = createCompositeRepository(TYPE_ARTIFACT); >+ parent.addChild(HTTP_SITE); >+ >+ // Create the modify repository task >+ AntTaskElement modify = createModifyElement(TYPE_ARTIFACT); >+ addTask(modify); >+ ((AntTaskElement) modify.elements.get(0)).addAttributes(new String[] {"append", String.valueOf(false)}); >+ >+ // Run the task >+ runAntTask(); >+ >+ CompositeArtifactRepository artifactRepo = (CompositeArtifactRepository) getCompositeRepository(TYPE_ARTIFACT); >+ assertTrue("Children not removed", artifactRepo.getChildren().isEmpty()); >+ >+ } >+ >+ public void testRemoveChild() { >+ createCompositeRepository(TYPE_ARTIFACT); >+ AntTaskElement modify = createModifyElement(TYPE_ARTIFACT); >+ addTask(modify); >+ >+ AntTaskElement add = createAddElement(TYPE_ARTIFACT, new URI[] {HTTP_SITE}); >+ modify.addElement(add); >+ >+ modify = createModifyElement(TYPE_ARTIFACT); >+ addTask(modify); >+ AntTaskElement remove = createRemoveElement(TYPE_ARTIFACT, new URI[] {HTTP_SITE}); >+ modify.addElement(remove); >+ >+ runAntTask(); >+ >+ CompositeArtifactRepository repo = (CompositeArtifactRepository) getCompositeRepository(TYPE_ARTIFACT); >+ assertFalse(repo.getChildren().contains(HTTP_SITE)); >+ } >+ >+ 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; >+ } >+ >+ 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; >+ } >+ >+ 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; >+ } >+ >+ protected AntTaskElement createModifyElement(String type) { >+ AntTaskElement modifyCompositeTask = new AntTaskElement("p2.modify.composite.repository.children"); >+ modifyCompositeTask.addElement(getRepositoryElement(compositeSite, type)); >+ >+ return modifyCompositeTask; >+ } >+ >+ 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; >+ /*AntTaskElement createCompositeTask = new AntTaskElement("p2.create.composite.repository"); >+ createCompositeTask.addElement(getRepositoryElement(compositeSite, type)); >+ addTask(createCompositeTask);*/ >+ } >+} >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,28 @@ >+/******************************************************************************* >+ * Copyright (c) 2007, 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(CreateCompositeRepositoryTaskTest.class); >+ suite.addTestSuite(MirrorTaskTest.class); >+ suite.addTestSuite(ModifyCompositeRepositoryTaskTest.class); >+ return suite; >+ } >+ >+} >\ No newline at end of file >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,274 @@ >+package org.eclipse.equinox.p2.tests.ant; >+ >+import java.io.*; >+import java.net.URI; >+import java.util.Iterator; >+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.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.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 URI destinationRepo; >+ private URI sourceRepo2; >+ >+ public void setUp() throws Exception { >+ super.setUp(); >+ // Get a random location to create a repository >+ destinationRepo = (new File(getTempFolder(), getUniqueString())).toURI(); >+ sourceRepo2 = getTestData("loading error data", "testData/mirror/mirrorSourceRepo2").toURI(); >+ } >+ >+ public void tearDown() throws Exception { >+ // Remove repository manager references >+ getArtifactRepositoryManager().removeRepository(destinationRepo); >+ getMetadataRepositoryManager().removeRepository(destinationRepo); >+ getArtifactRepositoryManager().removeRepository(sourceRepo2); >+ getMetadataRepositoryManager().removeRepository(sourceRepo2); >+ // Cleanup disk >+ delete(new File(destinationRepo)); >+ super.tearDown(); >+ } >+ >+ /* >+ * Test that all IUs can be mirrored >+ */ >+ public void testMirrorAllIUSpecified() throws ProvisionException { >+ AntTaskElement mirror = createMirrorTask(); >+ mirror.addElement(createSourceElement(sourceRepo2, sourceRepo2)); >+ addAllIUs(mirror, getMetadataRepositoryManager().loadRepository(sourceRepo2, null)); >+ runAntTask(); >+ >+ try { >+ assertEquals("Different number of Artifact Keys", getArtifactKeyCount(sourceRepo2), getArtifactKeyCount(destinationRepo)); >+ assertEquals("Different number of IUs", getIUCount(sourceRepo2), getIUCount(destinationRepo)); >+ } catch (ProvisionException e) { >+ fail("Failed to load Repository", e); >+ } >+ } >+ >+ /* >+ * Test that we only mirror specified IUs & Artifacts >+ */ >+ public void testMirrorSomeIUSpecified() { >+ AntTaskElement mirror = createMirrorTask(); >+ mirror.addElement(createSourceElement(sourceRepo2, sourceRepo2)); >+ mirror.addElement(createIUElement("anotherplugin", "1.0.0")); >+ >+ runAntTask(); >+ >+ try { >+ assertEquals("Wrong number of Artifact Keys", 1, getArtifactKeyCount(destinationRepo)); >+ assertEquals("Wrong number of IUs", 1, getIUCount(destinationRepo)); >+ } catch (ProvisionException e) { >+ fail("Failed to load Repository", e); >+ } >+ } >+ >+ /* >+ * Test that the proper exception is thrown when no IU is provided >+ */ >+ public void testMirrorNoIUNoRepo() { >+ AntTaskElement mirror = createMirrorTask(); >+ 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(); >+ mirror.addElement(createSourceElement(sourceRepo2, sourceRepo2)); >+ >+ runAntTask(); >+ >+ try { >+ assertEquals("Different number of Artifact Keys", getArtifactKeyCount(sourceRepo2), getArtifactKeyCount(destinationRepo)); >+ assertEquals("Different number of IUs", getIUCount(sourceRepo2), getIUCount(destinationRepo)); >+ } catch (ProvisionException e) { >+ fail("Failed to load Repository", 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 = createAndAddIU(repoLocation.toURI(), descriptor1); >+ baseline = createAndAddIU(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); >+ >+ AntTaskElement mirror = createMirrorTask(); >+ mirror.addElement(createSourceElement(repoLocation.toURI(), repoLocation.toURI())); >+ mirror.addAttribute("baseline", URIUtil.toUnencodedString(baselineLocation.toURI())); >+ mirror.addAttribute("verbose", String.valueOf(true)); >+ mirror.addAttribute("compare", String.valueOf(true)); >+ >+ runAntTaskWithExceptions(); >+ //Set compareAgaist >+ //String[] args = new String[] {"-source", repoLocation.toURL().toExternalForm(), "-destination", destinationRepo.toURL().toExternalForm(), "-compareAgainst", baselineLocation.toURL().toExternalForm(), "-verbose", "-compare"}; >+ //run the mirror application >+ //runMirrorApplication("Running with baseline compare", args); >+ } 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("have different MD5 sums for {2}", new Object[] {baseline, repo, descriptor1}); >+ assertLogContains(msg); >+ } >+ >+ /* >+ * Create an IU for a descriptor and the IU+descriptor to the specified repo >+ */ >+ protected IArtifactRepository createAndAddIU(URI repoLocation, IArtifactDescriptor descriptor) throws ProvisionException { >+ IArtifactRepository artifactRepo = getArtifactRepositoryManager().createRepository(repoLocation, "Repo 1", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); >+ artifactRepo.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 artifactRepo; >+ } >+ >+ /* >+ * Get the number of artifact keys in a repository >+ */ >+ protected int getArtifactKeyCount(URI location) throws ProvisionException { >+ return getArtifactRepositoryManager().loadRepository(location, null).getArtifactKeys().length; >+ } >+ >+ /* >+ * Get the number of IUs in a repository >+ */ >+ protected int getIUCount(URI location) throws ProvisionException { >+ return getMetadataRepositoryManager().loadRepository(location, null).query(InstallableUnitQuery.ANY, new Collector(), null).size(); >+ } >+ >+ /* >+ * 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() { >+ AntTaskElement mirror = new AntTaskElement("p2.mirror"); >+ mirror.addElement(getRepositoryElement(destinationRepo, null)); >+ 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; >+ } >+} >#P org.eclipse.equinox.p2.repository.tools >Index: src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor.java,v >retrieving revision 1.3 >diff -u -r1.3 RepositoryDescriptor.java >--- src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor.java 30 Mar 2009 01:49:17 -0000 1.3 >+++ src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor.java 8 Apr 2009 19:17:49 -0000 >@@ -10,18 +10,20 @@ > *******************************************************************************/ > package org.eclipse.equinox.p2.internal.repository.tools; > >-import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; >- > import java.net.URI; >+import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; >+import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; > > public class RepositoryDescriptor { > >+ public static final int TYPE_BOTH = -1; >+ > private boolean compressed = true; > private boolean append = true; > private String name = null; > private URI location = null; > private String format = null; >- private int kind; >+ private int kind = TYPE_BOTH; > > public void setCompressed(boolean compress) { > compressed = compress; >@@ -32,7 +34,7 @@ > } > > public void setLocation(URI repoLocation) { >- location = repoLocation; >+ location = RepositoryHelper.localRepoURIHelper(repoLocation); > } > > public void setFormat(String format) { >Index: src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java,v >retrieving revision 1.4 >diff -u -r1.4 MirrorApplication.java >--- src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java 22 Feb 2009 20:00:30 -0000 1.4 >+++ src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java 8 Apr 2009 19:17:49 -0000 >@@ -10,6 +10,7 @@ > *******************************************************************************/ > package org.eclipse.equinox.p2.internal.repository.tools; > >+import java.net.URI; > import java.util.ArrayList; > import java.util.Iterator; > import org.eclipse.core.runtime.*; >@@ -17,38 +18,57 @@ > import org.eclipse.equinox.app.IApplicationContext; > import org.eclipse.equinox.internal.p2.artifact.mirror.Mirroring; > import org.eclipse.equinox.internal.p2.director.PermissiveSlicer; >+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.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.internal.provisional.p2.query.IQueryable; >+import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager; > > public class MirrorApplication extends AbstractApplication { > protected SlicingOptions slicingOptions = new SlicingOptions(); > >+ private URI baseline; >+ //private URI baseline; >+ private String comparatorID; >+ private boolean compare = false; >+ private boolean failOnError = true; >+ private boolean raw = true; >+ private boolean verbose = false; >+ > public Object start(IApplicationContext context) throws Exception { > run(null); > return IApplication.EXIT_OK; > } > > public IStatus run(IProgressMonitor monitor) throws ProvisionException { >+ IStatus mirrorStatus = null; > try { > validate(); > initializeRepos(new NullProgressMonitor()); >+ intializeIUs(); > IQueryable slice = slice(new NullProgressMonitor()); >- IStatus mirrorStatus = mirrorArtifacts(slice, new NullProgressMonitor()); >- if (mirrorStatus.getSeverity() == IStatus.ERROR) { >- return mirrorStatus; >+ if (destinationArtifactRepository != null) { >+ mirrorStatus = mirrorArtifacts(slice, new NullProgressMonitor()); >+ if (mirrorStatus.getSeverity() == IStatus.ERROR) { >+ return mirrorStatus; >+ } > } >- mirrorMetadata(slice, new NullProgressMonitor()); >+ if (destinationMetadataRepository != null) >+ mirrorMetadata(slice, new NullProgressMonitor()); > } finally { > finalizeRepositories(); > } >- return Status.OK_STATUS; >+ if (mirrorStatus.isOK()) >+ return Status.OK_STATUS; >+ return mirrorStatus; > } > >- private IStatus mirrorArtifacts(IQueryable slice, IProgressMonitor monitor) { >+ private IStatus mirrorArtifacts(IQueryable slice, IProgressMonitor monitor) throws ProvisionException { > Collector ius = slice.query(InstallableUnitQuery.ANY, new Collector(), monitor); > ArrayList keys = new ArrayList(ius.size()); > for (Iterator iterator = ius.iterator(); iterator.hasNext();) { >@@ -58,9 +78,24 @@ > keys.add(iuKeys[i]); > } > } >- Mirroring mirror = new Mirroring(getCompositeArtifactRepository(), destinationArtifactRepository, true); >+ Mirroring mirror = new Mirroring(getCompositeArtifactRepository(), destinationArtifactRepository, raw); >+ >+ mirror.setCompare(compare); >+ mirror.setComparatorId(comparatorID); >+ mirror.setBaseline(initializeBaseline()); > mirror.setArtifactKeys((IArtifactKey[]) keys.toArray(new IArtifactKey[keys.size()])); >- return mirror.run(true, false); >+ >+ return mirror.run(failOnError, verbose); >+ } >+ >+ private IArtifactRepository initializeBaseline() throws ProvisionException { >+ if (baseline == null) >+ return null; >+ IArtifactRepositoryManager mgr = Activator.getArtifactRepositoryManager(); >+ >+ if (!mgr.contains(baseline)) >+ artifactReposToRemove.add(baseline); >+ return mgr.loadRepository(baseline, IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null); > } > > private void mirrorMetadata(IQueryable slice, IProgressMonitor monitor) { >@@ -77,9 +112,28 @@ > private void validate() throws ProvisionException { > if (sourceMetadataRepositories == null) > throw new ProvisionException("Need to set the source metadata repository location."); >- if (sourceIUs == null) >- throw new ProvisionException("Mirroring root needs to be specified."); >- //TODO Check that the IU is in repo >+ } >+ >+ /* >+ * If no IUs have been specified we want to mirror them all >+ */ >+ private void intializeIUs() throws ProvisionException { >+ if (sourceIUs == null || sourceIUs.isEmpty()) { >+ sourceIUs = new ArrayList(); >+ IMetadataRepository metadataRepo = getCompositeMetadataRepository(); >+ Collector collector = metadataRepo.query(InstallableUnitQuery.ANY, new Collector(), null); >+ >+ for (Iterator iter = collector.iterator(); iter.hasNext();) { >+ IInstallableUnit iu = (IInstallableUnit) iter.next(); >+ sourceIUs.add(iu); >+ } >+ >+ if (collector.size() == 0) { >+ throw new ProvisionException("No IUs specified and no IUs obtained from metadata repositories."); >+ } >+ } else { >+ //TODO Check that the IU is in repo >+ } > } > > private IQueryable slice(IProgressMonitor monitor) { >@@ -92,4 +146,48 @@ > public void setSlicingOptions(SlicingOptions options) { > slicingOptions = options; > } >+ >+ /* >+ * Set the location of the baseline repository. (used in comparison) >+ */ >+ public void setBaseline(URI baseline) { >+ this.baseline = baseline; >+ compare = true; >+ } >+ >+ /* >+ * Set the identifier of the comparator to use. >+ */ >+ public void setComparatorID(String value) { >+ comparatorID = value; >+ compare = true; >+ } >+ >+ /* >+ * Set whether or not the application should be calling a comparator when mirroring. >+ */ >+ public void setCompare(boolean value) { >+ compare = value; >+ } >+ >+ /* >+ * Set whether or not we should ignore errors when running the mirror application. >+ */ >+ public void setIgnoreErrors(boolean value) { >+ failOnError = !value; >+ } >+ >+ /* >+ * Set whether or not the the artifacts are raw. >+ */ >+ public void setRaw(boolean value) { >+ raw = value; >+ } >+ >+ /* >+ * Set whether or not the mirror application should be run in verbose mode. >+ */ >+ public void setVerbose(boolean value) { >+ verbose = value; >+ } > } >Index: src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.repository.tools/src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java,v >retrieving revision 1.6 >diff -u -r1.6 AbstractApplication.java >--- src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java 30 Mar 2009 01:49:17 -0000 1.6 >+++ src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java 8 Apr 2009 19:17:48 -0000 >@@ -10,9 +10,6 @@ > *******************************************************************************/ > package org.eclipse.equinox.p2.internal.repository.tools; > >-import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; >-import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager; >- > import java.net.URI; > import java.net.URISyntaxException; > import java.util.*; >@@ -24,11 +21,16 @@ > import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; > 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.repository.IRepository; >+import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager; > > public abstract class AbstractApplication { > >+ protected boolean removeUnknownRepositories = true; >+ > protected List sourceArtifactRepositories = new ArrayList(); > protected List sourceMetadataRepositories = new ArrayList(); >+ protected List sourceRepositories = new ArrayList(); > protected List artifactReposToRemove = new ArrayList(); > protected List metadataReposToRemove = new ArrayList(); > protected List sourceIUs = new ArrayList(); >@@ -71,15 +73,30 @@ > } > > protected void finalizeRepositories() throws ProvisionException { >- IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager(); >- for (Iterator iter = artifactReposToRemove.iterator(); iter.hasNext();) >- artifactRepositoryManager.removeRepository((URI) iter.next()); >- IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager(); >- for (Iterator iter = metadataReposToRemove.iterator(); iter.hasNext();) >- metadataRepositoryManager.removeRepository((URI) iter.next()); >+ if (removeUnknownRepositories) { >+ IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager(); >+ for (Iterator iter = artifactReposToRemove.iterator(); iter.hasNext();) >+ artifactRepositoryManager.removeRepository((URI) iter.next()); >+ IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager(); >+ for (Iterator iter = metadataReposToRemove.iterator(); iter.hasNext();) >+ metadataRepositoryManager.removeRepository((URI) iter.next()); >+ } > } > > public void initializeRepos(IProgressMonitor progress) throws ProvisionException { >+ for (Iterator iter = sourceRepositories.iterator(); iter.hasNext();) { >+ RepositoryDescriptor repo = (RepositoryDescriptor) iter.next(); >+ if (repo.getKind() == IRepository.TYPE_ARTIFACT) { >+ sourceArtifactRepositories.add(repo.getRepoLocation()); >+ } else if (repo.getKind() == IRepository.TYPE_METADATA) { >+ sourceMetadataRepositories.add(repo.getRepoLocation()); >+ } else if (repo.getKind() == RepositoryDescriptor.TYPE_BOTH) { >+ sourceArtifactRepositories.add(repo.getRepoLocation()); >+ sourceMetadataRepositories.add(repo.getRepoLocation()); >+ } else >+ throw new ProvisionException("Repository of unknown type: " + repo.getRepoLocation()); >+ >+ } > IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager(); > if (sourceArtifactRepositories != null && !sourceArtifactRepositories.isEmpty()) { > for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();) { >@@ -101,28 +118,48 @@ > } > > processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager); >- > } > > private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException { >- if (destinationRepos.size() != 2) { >- throw new ProvisionException("Too many or too few destination repositories."); >+ RepositoryDescriptor artifactRepoDescriptor = null; >+ RepositoryDescriptor metadataRepoDescriptor = null; >+ >+ Iterator iter = destinationRepos.iterator(); >+ while (iter.hasNext() && (artifactRepoDescriptor == null || metadataRepoDescriptor == null)) { >+ RepositoryDescriptor repo = (RepositoryDescriptor) iter.next(); >+ int kind = repo.getKind(); >+ if (kind == IRepository.TYPE_ARTIFACT && artifactRepoDescriptor == null) >+ artifactRepoDescriptor = repo; >+ else if (kind == IRepository.TYPE_METADATA && metadataRepoDescriptor == null) >+ metadataRepoDescriptor = repo; >+ else if (kind == RepositoryDescriptor.TYPE_BOTH) { >+ if (artifactRepoDescriptor == null) >+ artifactRepoDescriptor = repo; >+ if (metadataRepoDescriptor == null) >+ metadataRepoDescriptor = repo; >+ } > } >- RepositoryDescriptor artifactRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_ARTIFACT ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1)); >- RepositoryDescriptor metadataRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_METADATA ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1)); >- destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager); >- destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager); >+ >+ if (artifactRepoDescriptor != null) >+ destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager); >+ if (metadataRepoDescriptor != null) >+ destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager); >+ >+ if (destinationMetadataRepository == null && destinationArtifactRepository == null) >+ throw new ProvisionException("Unable to locate a valid destiation repository."); > } > > private IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException { > try { >- if (mgr.contains(toInit.getRepoLocation())) >+ if (!mgr.contains(toInit.getRepoLocation())) > metadataReposToRemove.add(toInit.getRepoLocation()); > IMetadataRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null); > if (repository != null && repository.isModifiable()) { > if (toInit.getName() != null) > repository.setName(toInit.getName()); >- if (!toInit.isAppend()) >+ if (repository instanceof CompositeMetadataRepository && !toInit.isAppend()) >+ ((CompositeMetadataRepository) repository).removeAllChildren(); >+ else if (!toInit.isAppend()) > repository.removeAll(); > return repository; > } >@@ -149,13 +186,15 @@ > > private IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) throws ProvisionException { > try { >- if (mgr.contains(toInit.getRepoLocation())) >+ if (!mgr.contains(toInit.getRepoLocation())) > artifactReposToRemove.add(toInit.getRepoLocation()); > IArtifactRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null); > if (repository != null && repository.isModifiable()) { > if (toInit.getName() != null) > repository.setName(toInit.getName()); >- if (!toInit.isAppend()) >+ if (repository instanceof CompositeArtifactRepository && !toInit.isAppend()) >+ ((CompositeArtifactRepository) repository).removeAllChildren(); >+ else if (!toInit.isAppend()) > repository.removeAll(); > return repository; > } >@@ -213,4 +252,8 @@ > public void addDestination(RepositoryDescriptor descriptor) { > destinationRepos.add(descriptor); > } >+ >+ public void addSource(RepositoryDescriptor repo) { >+ sourceRepositories.add(repo); >+ } > } >\ No newline at end of file >Index: src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AbstractRepositoryTask.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AbstractRepositoryTask.java,v >retrieving revision 1.4 >diff -u -r1.4 AbstractRepositoryTask.java >--- src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AbstractRepositoryTask.java 7 Apr 2009 21:58:38 -0000 1.4 >+++ src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AbstractRepositoryTask.java 8 Apr 2009 19:17:49 -0000 >@@ -12,12 +12,10 @@ > > import java.io.File; > import java.net.URI; >-import java.net.URISyntaxException; > import java.util.*; > import org.apache.tools.ant.*; > import org.apache.tools.ant.types.FileSet; >-import org.eclipse.core.runtime.Path; >-import org.eclipse.core.runtime.URIUtil; >+import org.eclipse.core.runtime.*; > import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; > import org.eclipse.equinox.internal.provisional.p2.query.Collector; > import org.eclipse.equinox.internal.provisional.p2.query.Query; >@@ -29,15 +27,6 @@ > protected List sourceRepos = new ArrayList(); > protected List destinations = new ArrayList(); > >- /* >- * Create a special file set since the user specified a "source" sub-element. >- */ >- public FileSet createSource() { >- MyFileSet set = new MyFileSet(); >- sourceRepos.add(set); >- return set; >- } >- > protected void addMetadataSourceRepository(URI repoLocation) { > application.addSourceMetadataRepository(repoLocation); > } >@@ -82,7 +71,10 @@ > destinations.add(artifact); > } > >- public DestinationRepository createDestination() { >+ /* >+ * Add a repository to mirror into >+ */ >+ public DestinationRepository createRepository() { > DestinationRepository destination = new DestinationRepository(); > destinations.add(destination); > application.addDestination(destination.getDescriptor()); >@@ -90,17 +82,18 @@ > } > > /* >- * New FileSet subclass which adds an optional "location" attribute. >+ * Add source repositories to mirror from > */ >- public class MyFileSet extends FileSet { >- String location; >- >- public MyFileSet() { >- super(); >+ public void addConfiguredSource(RepositoryList sourceList) { >+ for (Iterator iter = sourceList.getRepositoryList().iterator(); iter.hasNext();) { >+ DestinationRepository repo = (DestinationRepository) iter.next(); >+ application.addSource(repo.getDescriptor()); > } > >- public void setLocation(String value) { >- this.location = value; >+ for (Iterator iter = sourceList.getFileSetList().iterator(); iter.hasNext();) { >+ FileSet fileSet = (FileSet) iter.next(); >+ sourceRepos.add(fileSet); >+ // Added to the application later through prepareSourceRepos > } > } > >@@ -112,33 +105,32 @@ > if (sourceRepos == null || sourceRepos.isEmpty()) > return; > for (Iterator iter = sourceRepos.iterator(); iter.hasNext();) { >- Object next = iter.next(); >- if (next instanceof MyFileSet) { >- MyFileSet fileset = (MyFileSet) next; >- // determine if the user set a "location" attribute or used a fileset >- if (fileset.location == null) { >- DirectoryScanner scanner = fileset.getDirectoryScanner(getProject()); >- String[][] elements = new String[][] {scanner.getIncludedDirectories(), scanner.getIncludedFiles()}; >- for (int i = 0; i < 2; i++) { >- for (int j = 0; j < elements[i].length; j++) { >- File file = new File(fileset.getDir(), elements[i][j]); >- URI uri = file.toURI(); >- >- if (file.isFile() && file.getName().endsWith(".zip")) { //$NON-NLS-1$ >- try { >- uri = new URI("jar:" + uri.toString() + "!/"); //$NON-NLS-1$ //$NON-NLS-2$ >- } catch (URISyntaxException e) { >- //? >- continue; >- } >- } >+ RepositoryFileSet fileset = (RepositoryFileSet) iter.next(); >+ >+ DirectoryScanner scanner = fileset.getDirectoryScanner(getProject()); >+ String[][] elements = new String[][] {scanner.getIncludedDirectories(), scanner.getIncludedFiles()}; >+ for (int i = 0; i < 2; i++) { >+ for (int j = 0; j < elements[i].length; j++) { >+ File file = new File(fileset.getDir(), elements[i][j]); >+ URI uri = file.toURI(); >+ >+ if (file.isFile() && file.getName().endsWith(".zip")) { //$NON-NLS-1$ >+ uri = URIUtil.toJarURI(uri, null); >+ } >+ switch (fileset.getKind()) { >+ case RepositoryFileSet.TYPE_BOTH : >+ application.addSourceArtifactRepository(uri); >+ application.addSourceMetadataRepository(uri); >+ break; >+ case RepositoryFileSet.TYPE_ARTIFACT : > application.addSourceArtifactRepository(uri); >+ break; >+ case RepositoryFileSet.TYPE_METADATA : > application.addSourceMetadataRepository(uri); >- } >+ break; >+ default : >+ throw new BuildException("Unknown repository type for: " + uri); > } >- } else { >- application.addSourceArtifactRepository(fileset.location); >- application.addSourceMetadataRepository(fileset.location); > } > } > } >@@ -163,4 +155,12 @@ > } > return result; > } >+ >+ protected void log(IStatus status) { >+ try { >+ (new AntMirrorLog(this)).log(status); >+ } catch (NoSuchMethodException e) { >+ // Shouldn't occur >+ } >+ } > } >Index: src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorTask.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.repository.tools/src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorTask.java,v >retrieving revision 1.3 >diff -u -r1.3 MirrorTask.java >--- src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorTask.java 22 Feb 2009 20:00:30 -0000 1.3 >+++ src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorTask.java 8 Apr 2009 19:17:49 -0000 >@@ -10,9 +10,11 @@ > *******************************************************************************/ > package org.eclipse.equinox.p2.internal.repository.tools.tasks; > >+import java.net.URISyntaxException; > import java.util.List; > import org.apache.tools.ant.BuildException; > import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.URIUtil; > import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; > import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication; > >@@ -27,13 +29,12 @@ > prepareSourceRepos(); > application.initializeRepos(null); > List ius = prepareIUs(); >- if (ius == null || ius.size() == 0) >- throw new BuildException("Need to specify one or more IUs to mirror."); > application.setSourceIUs(ius); > IStatus result = application.run(null); > if (result.matches(IStatus.ERROR)) { > throw new BuildException(TaskHelper.statusToString(result, null).toString()); >- } >+ } else if (!result.isOK()) >+ log(result); > } catch (ProvisionException e) { > throw new BuildException(e); > } >@@ -44,4 +45,50 @@ > ((MirrorApplication) application).setSlicingOptions(options.getOptions()); > return options; > } >+ >+ /* >+ * Set the location of the baseline repository. (used in comparison) >+ */ >+ public void setBaseline(String value) { >+ try { >+ ((MirrorApplication) application).setBaseline(URIUtil.fromString(value)); >+ } catch (URISyntaxException e) { >+ throw new BuildException(e); >+ } >+ } >+ >+ /* >+ * Set the identifier of the comparator to use. >+ */ >+ public void setComparatorID(String value) { >+ ((MirrorApplication) application).setComparatorID(value); >+ } >+ >+ /* >+ * Set whether or not the application should be calling a comparator when mirroring. >+ */ >+ public void setCompare(boolean value) { >+ ((MirrorApplication) application).setCompare(value); >+ } >+ >+ /* >+ * Set whether or not we should ignore errors when running the mirror application. >+ */ >+ public void setIgnoreErrors(boolean value) { >+ ((MirrorApplication) application).setIgnoreErrors(value); >+ } >+ >+ /* >+ * Set whether or not the the artifacts are raw. >+ */ >+ public void setRaw(boolean value) { >+ ((MirrorApplication) application).setRaw(value); >+ } >+ >+ /* >+ * Set whether or not the mirror application should be run in verbose mode. >+ */ >+ public void setVerbose(boolean value) { >+ ((MirrorApplication) application).setVerbose(value); >+ } > } >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.repository.tools/plugin.xml,v >retrieving revision 1.4 >diff -u -r1.4 plugin.xml >--- plugin.xml 23 Feb 2009 16:55:10 -0000 1.4 >+++ plugin.xml 8 Apr 2009 19:17:48 -0000 >@@ -15,6 +15,18 @@ > library="lib/repository-tools-ant.jar" > name="p2.mirror"> > </antTask> >+ >+ <antTask >+ class="org.eclipse.equinox.p2.internal.repository.tools.tasks.ModifyRepositoryChildrenTask" >+ library="lib/repository-tools-ant.jar" >+ name="p2.modify.composite.repository.children"> >+ </antTask> >+ >+ <antTask >+ class="org.eclipse.equinox.p2.internal.repository.tools.tasks.CreateCompositeRepositoryTask" >+ library="lib/repository-tools-ant.jar" >+ name="p2.create.composite.repository"> >+ </antTask> > > <antTask > library="lib/repository-tools-ant.jar" >Index: src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AntMirrorLog.java >=================================================================== >RCS file: src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AntMirrorLog.java >diff -N src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AntMirrorLog.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AntMirrorLog.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,104 @@ >+/******************************************************************************* >+ * 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.internal.repository.tools.tasks; >+ >+import java.lang.reflect.InvocationTargetException; >+import java.lang.reflect.Method; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.equinox.internal.p2.artifact.repository.Messages; >+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor; >+ >+public class AntMirrorLog { >+ >+ private boolean consoleMessage = false; >+ private Method log; >+ private Object task; >+ >+ public AntMirrorLog(Object task) throws NoSuchMethodException { >+ this.task = task; >+ try { >+ log = task.getClass().getMethod("log", new Class[] {String.class, int.class}); //$NON-NLS-1$ >+ } catch (SecurityException e) { >+ exceptionOccurred(null, e); >+ } >+ } >+ >+ public void log(IArtifactDescriptor descriptor, IStatus status) { >+ log(descriptor.toString(), status.getSeverity()); >+ log(status); >+ } >+ >+ public void log(IStatus status) { >+ int severity = status.getSeverity(); >+ // Log the status message >+ log(status.getMessage(), severity); >+ // Log the exception if applicable >+ if (status.getException() != null) >+ log(status.getException().getMessage(), severity); >+ >+ // Log any children of this status >+ IStatus[] nestedStatus = status.getChildren(); >+ if (nestedStatus != null) >+ for (int i = 0; i < nestedStatus.length; i++) >+ log(nestedStatus[i]); >+ } >+ >+ public void close() { >+ // nothing to do here >+ } >+ >+ /* >+ * Log a message to the Ant Task >+ */ >+ private void log(String message, int statusSeverity) { >+ try { >+ log.invoke(task, new Object[] {message, new Integer(mapLogLevels(statusSeverity))}); >+ } catch (IllegalArgumentException e) { >+ exceptionOccurred(message, e); >+ } catch (IllegalAccessException e) { >+ exceptionOccurred(message, e); >+ } catch (InvocationTargetException e) { >+ exceptionOccurred(message, e); >+ } >+ } >+ >+ /* >+ * Show an error message if this the first time, and print status messages. >+ */ >+ private void exceptionOccurred(String message, Exception e) { >+ if (!consoleMessage) { >+ System.err.println(Messages.MirrorLog_Exception_Occurred); >+ e.printStackTrace(System.err); >+ System.err.println(Messages.MirrorLog_Console_Log); >+ consoleMessage = true; >+ } >+ if (message != null) >+ System.out.println(message); >+ } >+ >+ /** >+ * Copied from AntLogAdapter in pde build. >+ */ >+ private int mapLogLevels(int iStatusLevel) { >+ switch (iStatusLevel) { >+ case IStatus.ERROR : >+ return 0; >+ case IStatus.OK : >+ return 2; >+ case IStatus.INFO : >+ return 2; >+ case IStatus.WARNING : >+ return 1; >+ default : >+ return 1; >+ } >+ } >+} >Index: src/org/eclipse/equinox/p2/internal/repository/tools/ModifyCompositeRepositoryApplication.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/internal/repository/tools/ModifyCompositeRepositoryApplication.java >diff -N src/org/eclipse/equinox/p2/internal/repository/tools/ModifyCompositeRepositoryApplication.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/internal/repository/tools/ModifyCompositeRepositoryApplication.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,74 @@ >+/******************************************************************************* >+ * 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.internal.repository.tools; >+ >+import java.util.*; >+import org.eclipse.core.runtime.*; >+import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository; >+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.repository.IRepository; >+ >+public class ModifyCompositeRepositoryApplication extends AbstractApplication { >+ private List childrenToAdd = new ArrayList(); >+ private List childrenToRemove = new ArrayList(); >+ >+ public IStatus run(IProgressMonitor monitor) throws ProvisionException { >+ >+ try { >+ initializeRepos(new NullProgressMonitor()); >+ // load repository >+ CompositeMetadataRepository metadataRepo = (CompositeMetadataRepository) destinationMetadataRepository; >+ CompositeArtifactRepository artifactRepo = (CompositeArtifactRepository) destinationArtifactRepository; >+ >+ // Remove children from the Composite Repositories >+ for (Iterator iterator = childrenToRemove.iterator(); iterator.hasNext();) { >+ RepositoryDescriptor child = (RepositoryDescriptor) iterator.next(); >+ if (child.getKind() == IRepository.TYPE_ARTIFACT) >+ artifactRepo.removeChild(child.getRepoLocation()); >+ else if (child.getKind() == IRepository.TYPE_METADATA) >+ metadataRepo.removeChild(child.getRepoLocation()); >+ else if (child.getKind() == RepositoryDescriptor.TYPE_BOTH) { >+ artifactRepo.removeChild(child.getRepoLocation()); >+ metadataRepo.removeChild(child.getRepoLocation()); >+ } >+ } >+ >+ // Add children to the Composite Repositories >+ for (Iterator iterator = childrenToAdd.iterator(); iterator.hasNext();) { >+ RepositoryDescriptor child = (RepositoryDescriptor) iterator.next(); >+ if (child.getKind() == IRepository.TYPE_ARTIFACT) >+ artifactRepo.addChild(child.getRepoLocation()); >+ else if (child.getKind() == IRepository.TYPE_METADATA) >+ metadataRepo.addChild(child.getRepoLocation()); >+ else if (child.getKind() == RepositoryDescriptor.TYPE_BOTH) { >+ artifactRepo.addChild(child.getRepoLocation()); >+ metadataRepo.addChild(child.getRepoLocation()); >+ } >+ } >+ return Status.OK_STATUS; >+ } finally { >+ finalizeRepositories(); >+ } >+ } >+ >+ public void setRemoveUnknownRepositories(boolean value) { >+ removeUnknownRepositories = value; >+ } >+ >+ public void addChild(RepositoryDescriptor child) { >+ childrenToAdd.add(child); >+ } >+ >+ public void removeChild(RepositoryDescriptor child) { >+ childrenToRemove.add(child); >+ } >+} >Index: src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CreateCompositeRepositoryTask.java >=================================================================== >RCS file: src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CreateCompositeRepositoryTask.java >diff -N src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CreateCompositeRepositoryTask.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CreateCompositeRepositoryTask.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,69 @@ >+package org.eclipse.equinox.p2.internal.repository.tools.tasks; >+ >+import java.util.Iterator; >+import org.apache.tools.ant.BuildException; >+import org.apache.tools.ant.Task; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; >+import org.eclipse.equinox.p2.internal.repository.tools.CreateCompositeRepositoryApplication; >+import org.eclipse.equinox.p2.internal.repository.tools.ModifyCompositeRepositoryApplication; >+ >+public class CreateCompositeRepositoryTask extends Task { >+ CreateCompositeRepositoryApplication createApp; >+ ModifyCompositeRepositoryApplication modifyApp; >+ boolean add = false; >+ >+ public CreateCompositeRepositoryTask() { >+ createApp = new CreateCompositeRepositoryApplication(); >+ modifyApp = new ModifyCompositeRepositoryApplication(); >+ modifyApp.setRemoveUnknownRepositories(false); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.tools.ant.Task#execute() >+ */ >+ public void execute() throws BuildException { >+ try { >+ IStatus result = createApp.run(null); >+ if (result.matches(IStatus.ERROR)) { >+ throw new BuildException(TaskHelper.statusToString(result, null).toString()); >+ } >+ if (add) { >+ result = modifyApp.run(null); >+ if (result.matches(IStatus.ERROR)) { >+ throw new BuildException(TaskHelper.statusToString(result, null).toString()); >+ } >+ } >+ } catch (ProvisionException e) { >+ throw new BuildException(e); >+ } >+ } >+ >+ /* >+ * Add a repository to create >+ */ >+ public DestinationRepository createRepository() { >+ DestinationRepository repo = new DestinationRepository(); >+ createApp.addRepository(repo.getDescriptor()); >+ modifyApp.addDestination(repo.getDescriptor()); >+ return repo; >+ } >+ >+ /* >+ * Set whether the task should fail if the repository already exists >+ */ >+ public void setFailOnExists(boolean value) { >+ createApp.setFailOnExists(value); >+ } >+ >+ /* >+ * Add a list of child repositories to add to the newly created repository >+ */ >+ public void addConfiguredAdd(RepositoryList addList) { >+ add = true; >+ for (Iterator iter = addList.getRepositoryList().iterator(); iter.hasNext();) { >+ DestinationRepository repo = (DestinationRepository) iter.next(); >+ modifyApp.addChild(repo.getDescriptor()); >+ } >+ } >+} >Index: src/org/eclipse/equinox/p2/internal/repository/tools/CreateCompositeRepositoryApplication.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/internal/repository/tools/CreateCompositeRepositoryApplication.java >diff -N src/org/eclipse/equinox/p2/internal/repository/tools/CreateCompositeRepositoryApplication.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/internal/repository/tools/CreateCompositeRepositoryApplication.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,172 @@ >+package org.eclipse.equinox.p2.internal.repository.tools; >+ >+import java.net.URISyntaxException; >+import java.util.*; >+import org.apache.tools.ant.BuildException; >+import org.eclipse.core.runtime.*; >+import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository; >+import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; >+import org.eclipse.equinox.internal.p2.metadata.repository.Activator; >+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.IMetadataRepository; >+import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; >+import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; >+ >+public class CreateCompositeRepositoryApplication { >+ >+ private String artifactName = "Composite Artifact Repository"; >+ private String metadataName = "Composite Artifact Repository"; >+ private List repositories = new ArrayList(); >+ private boolean failOnExists = false; >+ private IArtifactRepositoryManager artifactManager; >+ private IMetadataRepositoryManager metadataManager; >+ >+ public IStatus run(IProgressMonitor monitor) throws ProvisionException { >+ >+ MultiStatus status = new MultiStatus(Activator.ID, 0, "", null); //$NON-NLS-1$ >+ status.add(Status.OK_STATUS); >+ for (Iterator iterator = repositories.iterator(); iterator.hasNext();) >+ status.add(createRepository((RepositoryDescriptor) iterator.next())); >+ >+ return status; >+ } >+ >+ public void addRepository(RepositoryDescriptor repo) { >+ repositories.add(repo); >+ } >+ >+ public void setFailOnExists(boolean value) { >+ failOnExists = value; >+ } >+ >+ private IStatus createRepository(RepositoryDescriptor repo) throws ProvisionException { >+ try { >+ if (repo.getKind() == IRepository.TYPE_ARTIFACT) >+ return createArtifactRepository(repo); >+ else if (repo.getKind() == IRepository.TYPE_METADATA) >+ return createMetadataRepository(repo); >+ else if (repo.getKind() == RepositoryDescriptor.TYPE_BOTH) { >+ MultiStatus status = new MultiStatus(Activator.ID, 0, "", null); //$NON-NLS-1$ >+ status.add(createArtifactRepository(repo)); >+ status.add(createMetadataRepository(repo)); >+ return status; >+ } else >+ throw new ProvisionException("Repository is of an unknown kind: " + repo.getRepoLocation()); >+ } catch (IllegalStateException e) { >+ throw new ProvisionException(e.getMessage(), e); >+ } >+ } >+ >+ private IStatus createArtifactRepository(RepositoryDescriptor repo) throws ProvisionException { >+ if (artifactManager == null) { >+ artifactManager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName()); >+ if (artifactManager == null) >+ throw new ProvisionException("Unable to obtain metadata repository manager."); >+ } >+ >+ boolean repoKnown = artifactManager.contains(repo.getRepoLocation()); >+ >+ // remove the repo first. >+ artifactManager.removeRepository(repo.getRepoLocation()); >+ >+ // first try and load to see if one already exists at that location. >+ // if we have an already existing repository at that location, then throw an error >+ // if the user told us to >+ try { >+ IArtifactRepository repository = artifactManager.loadRepository(repo.getRepoLocation(), null); >+ if (repository instanceof CompositeArtifactRepository) { >+ if (failOnExists) >+ throw new BuildException("Composite repository already exists at location: " + repo.getRepoLocation()); >+ return new Status(IStatus.INFO, Activator.ID, "Composite repository already exists at location: " + repo.getRepoLocation()); >+ } else { >+ // we have a non-composite repo at this location. that is ok because we can co-exist. >+ } >+ } catch (ProvisionException e) { >+ // re-throw the exception if we got anything other than "repo not found" >+ if (e.getStatus().getCode() != ProvisionException.REPOSITORY_NOT_FOUND) >+ throw e; >+ } >+ >+ IArtifactRepository source = null; >+ try { >+ if (repo.getFormat() != null) >+ source = artifactManager.loadRepository(URIUtil.fromString(repo.getFormat()), 0, null); >+ } catch (ProvisionException e) { >+ //Ignore. >+ } catch (URISyntaxException e) { >+ //Ignore >+ } >+ //This code assumes source has been successfully loaded before this point >+ //No existing repository; create a new repository at destinationLocation but with source's attributes. >+ // TODO for now create a Simple repo by default. >+ >+ try { >+ IArtifactRepository result = null; >+ result = (IArtifactRepository) RepositoryHelper.validDestinationRepository(artifactManager.createRepository(repo.getRepoLocation(), repo.getName() != null ? repo.getName() : (source != null ? source.getName() : artifactName), IArtifactRepositoryManager.TYPE_COMPOSITE_REPOSITORY, source != null ? source.getProperties() : null)); >+ >+ if (repo.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED)) >+ result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$ >+ } catch (IllegalStateException e) { >+ artifactManager.removeRepository(repo.getRepoLocation()); >+ throw e; >+ } >+ return Status.OK_STATUS; >+ } >+ >+ private IStatus createMetadataRepository(RepositoryDescriptor repo) throws ProvisionException { >+ if (metadataManager == null) { >+ metadataManager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.class.getName()); >+ if (metadataManager == null) >+ throw new ProvisionException("Unable to obtain metadata repository manager."); >+ } >+ >+ boolean repoKnown = metadataManager.contains(repo.getRepoLocation()); >+ // remove the repo first. >+ metadataManager.removeRepository(repo.getRepoLocation()); >+ >+ // first try and load to see if one already exists at that location. >+ // if we have an already existing repository at that location, then throw an error >+ // if the user told us to >+ try { >+ IMetadataRepository repository = metadataManager.loadRepository(repo.getRepoLocation(), null); >+ if (repository instanceof CompositeMetadataRepository) { >+ if (failOnExists) >+ throw new BuildException("Composite repository already exists at location: " + repo.getRepoLocation()); >+ RepositoryHelper.validDestinationRepository(repository); >+ return new Status(IStatus.INFO, Activator.ID, "Composite repository already exists at location: " + repo.getRepoLocation()); >+ } else { >+ // we have a non-composite repo at this location. that is ok because we can co-exist. >+ } >+ } catch (ProvisionException e) { >+ // re-throw the exception if we got anything other than "repo not found" >+ if (e.getStatus().getCode() != ProvisionException.REPOSITORY_NOT_FOUND) >+ throw e; >+ } >+ >+ IMetadataRepository source = null; >+ try { >+ if (repo.getFormat() != null) >+ source = metadataManager.loadRepository(URIUtil.fromString(repo.getFormat()), 0, null); >+ } catch (ProvisionException e) { >+ //Ignore. >+ } catch (URISyntaxException e) { >+ //Ignore >+ } >+ //This code assumes source has been successfully loaded before this point >+ //No existing repository; create a new repository at destinationLocation but with source's attributes. >+ try { >+ IMetadataRepository result = (IMetadataRepository) RepositoryHelper.validDestinationRepository(metadataManager.createRepository(repo.getRepoLocation(), repo.getName() != null ? repo.getName() : (source != null ? source.getName() : metadataName), IMetadataRepositoryManager.TYPE_COMPOSITE_REPOSITORY, source != null ? source.getProperties() : null)); >+ if (repo.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED)) >+ result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$ >+ } catch (IllegalStateException e) { >+ metadataManager.removeRepository(repo.getRepoLocation()); >+ throw e; >+ } >+ >+ return Status.OK_STATUS; >+ } >+} >Index: src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryFileSet.java >=================================================================== >RCS file: src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryFileSet.java >diff -N src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryFileSet.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryFileSet.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,26 @@ >+package org.eclipse.equinox.p2.internal.repository.tools.tasks; >+ >+import org.apache.tools.ant.types.FileSet; >+import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; >+import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor; >+ >+public class RepositoryFileSet extends FileSet { >+ public final static int TYPE_BOTH = RepositoryDescriptor.TYPE_BOTH; >+ public final static int TYPE_ARTIFACT = IRepository.TYPE_ARTIFACT; >+ public final static int TYPE_METADATA = IRepository.TYPE_METADATA; >+ >+ int kind = TYPE_BOTH; >+ >+ public void setKind(String repoKind) { >+ if (repoKind.startsWith("m") || repoKind.startsWith("M")) //$NON-NLS-1$//$NON-NLS-2$ >+ kind = IRepository.TYPE_METADATA; >+ >+ if (repoKind.startsWith("a") || repoKind.startsWith("A")) //$NON-NLS-1$//$NON-NLS-2$ >+ kind = IRepository.TYPE_ARTIFACT; >+ } >+ >+ public int getKind() { >+ return kind; >+ } >+ >+} >Index: src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryList.java >=================================================================== >RCS file: src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryList.java >diff -N src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryList.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryList.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,40 @@ >+/******************************************************************************* >+ * 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.internal.repository.tools.tasks; >+ >+import java.util.ArrayList; >+import java.util.List; >+import org.apache.tools.ant.types.DataType; >+ >+public class RepositoryList extends DataType { >+ List repositories = new ArrayList(); >+ List sourceFileSets = new ArrayList(); >+ >+ public DestinationRepository createRepository() { >+ DestinationRepository repo = new DestinationRepository(); >+ repositories.add(repo); >+ return repo; >+ } >+ >+ public RepositoryFileSet createFileSet() { >+ RepositoryFileSet fileSet = new RepositoryFileSet(); >+ sourceFileSets.add(fileSet); >+ return fileSet; >+ } >+ >+ public List getRepositoryList() { >+ return repositories; >+ } >+ >+ public List getFileSetList() { >+ return sourceFileSets; >+ } >+} >Index: src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/ModifyRepositoryChildrenTask.java >=================================================================== >RCS file: src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/ModifyRepositoryChildrenTask.java >diff -N src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/ModifyRepositoryChildrenTask.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/ModifyRepositoryChildrenTask.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,58 @@ >+/******************************************************************************* >+ * 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.internal.repository.tools.tasks; >+ >+import java.util.Iterator; >+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.ModifyCompositeRepositoryApplication; >+ >+public class ModifyRepositoryChildrenTask extends AbstractRepositoryTask { >+ >+ public ModifyRepositoryChildrenTask() { >+ application = new ModifyCompositeRepositoryApplication(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.apache.tools.ant.Task#execute() >+ */ >+ public void execute() throws BuildException { >+ try { >+ IStatus result = application.run(null); >+ if (result.matches(IStatus.ERROR)) { >+ throw new BuildException(TaskHelper.statusToString(result, null).toString()); >+ } >+ } catch (ProvisionException e) { >+ throw new BuildException(e); >+ } >+ } >+ >+ /* >+ * Add the listed repositories to the composite repository >+ */ >+ public void addConfiguredAdd(RepositoryList list) { >+ for (Iterator iter = list.getRepositoryList().iterator(); iter.hasNext();) { >+ DestinationRepository repo = (DestinationRepository) iter.next(); >+ ((ModifyCompositeRepositoryApplication) application).addChild(repo.getDescriptor()); >+ } >+ } >+ >+ /* >+ * Remove the listed repositories from the composite repository >+ */ >+ public void addConfiguredRemove(RepositoryList list) { >+ for (Iterator iter = list.getRepositoryList().iterator(); iter.hasNext();) { >+ DestinationRepository repo = (DestinationRepository) iter.next(); >+ ((ModifyCompositeRepositoryApplication) application).removeChild(repo.getDescriptor()); >+ } >+ } >+} >#P org.eclipse.equinox.p2.repository >Index: src/org/eclipse/equinox/internal/p2/repository/helpers/Messages.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/Messages.java,v >retrieving revision 1.2 >diff -u -r1.2 Messages.java >--- src/org/eclipse/equinox/internal/p2/repository/helpers/Messages.java 2 Apr 2009 13:49:52 -0000 1.2 >+++ src/org/eclipse/equinox/internal/p2/repository/helpers/Messages.java 8 Apr 2009 19:17:53 -0000 >@@ -31,5 +31,6 @@ > public static String repoMan_internalError; > public static String repoMan_notExists; > public static String repoMan_unknownType; >+ public static String DestinationNotModifiable; > > } >Index: src/org/eclipse/equinox/internal/p2/repository/helpers/messages.properties >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/messages.properties,v >retrieving revision 1.2 >diff -u -r1.2 messages.properties >--- src/org/eclipse/equinox/internal/p2/repository/helpers/messages.properties 2 Apr 2009 13:49:52 -0000 1.2 >+++ src/org/eclipse/equinox/internal/p2/repository/helpers/messages.properties 8 Apr 2009 19:17:53 -0000 >@@ -15,3 +15,4 @@ > repoMan_internalError=Internal error. > repoMan_notExists=No repository found at {0}. > repoMan_unknownType=Unknown repository type at {0}. >+DestinationNotModifiable=Destination repository is not modifiable: {0} >\ No newline at end of file >Index: src/org/eclipse/equinox/internal/p2/repository/helpers/RepositoryHelper.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/p2/repository/helpers/RepositoryHelper.java >diff -N src/org/eclipse/equinox/internal/p2/repository/helpers/RepositoryHelper.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/p2/repository/helpers/RepositoryHelper.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,51 @@ >+package org.eclipse.equinox.internal.p2.repository.helpers; >+ >+import java.io.File; >+import java.net.URI; >+import org.eclipse.core.runtime.URIUtil; >+import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; >+import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; >+import org.eclipse.osgi.util.NLS; >+ >+public class RepositoryHelper { >+ protected static final String FILE_SCHEME = "file"; //$NON-NLS-1$ >+ >+ /** >+ * If the provided URI can be interpreted as representing a local address (no schema, or one letter schema) >+ * but is missing the file schema, a new URI is created which represents the local file. >+ * >+ * @param location the URI to convert >+ * @return the converted URI, or the original >+ */ >+ public static URI localRepoURIHelper(URI location) { >+ if (location == null) >+ return null; >+ if (location.getScheme() == null) >+ // Probably a local path: /home/user/repo >+ location = (new File(location.getPath())).getAbsoluteFile().toURI(); >+ else if (location.getScheme().length() == 1) >+ // Probably a windows path: C:\repo >+ location = (new File(URIUtil.toUnencodedString(location))).toURI(); >+ else if (!FILE_SCHEME.equalsIgnoreCase(location.getScheme())) >+ // This else must occur last! >+ return location; >+ >+ // Zipped repository? >+ String lowerCase = location.toString().toLowerCase(); >+ if (lowerCase.endsWith(".jar") || lowerCase.endsWith(".zip")) //$NON-NLS-1$//$NON-NLS-2$ >+ return URIUtil.toJarURI(location, null); >+ return location; >+ } >+ >+ /** >+ * Determine if the repository could be used as a valid destination (eg, it is modifiable) >+ * @param repository the repository to test >+ * @return the repository >+ * @throws ProvisionException if the repository is not valid >+ */ >+ public static IRepository validDestinationRepository(IRepository repository) { >+ if (!repository.isModifiable()) >+ throw new IllegalStateException(NLS.bind(Messages.DestinationNotModifiable, repository.getLocation())); >+ return repository; >+ } >+}
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