Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 265550 | Differences between
and this patch

Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 6-11 Link Here
6
Bundle-Localization: plugin
6
Bundle-Localization: plugin
7
Bundle-Version: 1.1.0.qualifier
7
Bundle-Version: 1.1.0.qualifier
8
Import-Package: javax.xml.parsers,
8
Import-Package: javax.xml.parsers,
9
 org.eclipse.ant.core,
9
 org.eclipse.equinox.internal.p2.artifact.mirror,
10
 org.eclipse.equinox.internal.p2.artifact.mirror,
10
 org.eclipse.equinox.internal.p2.artifact.processors.md5,
11
 org.eclipse.equinox.internal.p2.artifact.processors.md5,
11
 org.eclipse.equinox.internal.p2.artifact.processors.pack200,
12
 org.eclipse.equinox.internal.p2.artifact.processors.pack200,
Lines 38-44 Link Here
38
 org.eclipse.equinox.internal.provisional.p2.core,
39
 org.eclipse.equinox.internal.provisional.p2.core,
39
 org.eclipse.equinox.internal.provisional.p2.core.eventbus,
40
 org.eclipse.equinox.internal.provisional.p2.core.eventbus,
40
 org.eclipse.equinox.internal.provisional.p2.core.location,
41
 org.eclipse.equinox.internal.provisional.p2.core.location,
41
 org.eclipse.equinox.internal.provisional.p2.repository,
42
 org.eclipse.equinox.internal.provisional.p2.director,
42
 org.eclipse.equinox.internal.provisional.p2.director,
43
 org.eclipse.equinox.internal.provisional.p2.directorywatcher,
43
 org.eclipse.equinox.internal.provisional.p2.directorywatcher,
44
 org.eclipse.equinox.internal.provisional.p2.engine,
44
 org.eclipse.equinox.internal.provisional.p2.engine,
Lines 47-52 Link Here
47
 org.eclipse.equinox.internal.provisional.p2.metadata.query,
47
 org.eclipse.equinox.internal.provisional.p2.metadata.query,
48
 org.eclipse.equinox.internal.provisional.p2.metadata.repository,
48
 org.eclipse.equinox.internal.provisional.p2.metadata.repository,
49
 org.eclipse.equinox.internal.provisional.p2.query,
49
 org.eclipse.equinox.internal.provisional.p2.query,
50
 org.eclipse.equinox.internal.provisional.p2.repository,
50
 org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository,
51
 org.eclipse.equinox.internal.provisional.spi.p2.artifact.repository,
51
 org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository,
52
 org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository,
52
 org.eclipse.equinox.internal.provisional.spi.p2.repository,
53
 org.eclipse.equinox.internal.provisional.spi.p2.repository,
(-)src/org/eclipse/equinox/p2/tests/ant/CreateCompositeRepositoryTaskTest.java (+177 lines)
Added Link Here
1
package org.eclipse.equinox.p2.tests.ant;
2
3
import java.io.File;
4
import java.net.URI;
5
import org.eclipse.core.runtime.CoreException;
6
import org.eclipse.core.runtime.URIUtil;
7
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
8
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository;
9
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
10
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
11
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
12
import org.eclipse.equinox.p2.tests.AbstractAntProvisioningTest;
13
14
public class CreateCompositeRepositoryTaskTest extends AbstractAntProvisioningTest {
15
	private URI compositeSite;
16
	private static URI HTTP_SITE;
17
18
	public void setUp() throws Exception {
19
		super.setUp();
20
		// Get a random location to create a repository
21
		compositeSite = (new File(getTempFolder(), getUniqueString())).toURI();
22
		HTTP_SITE = new URI("http://download.eclipse.org/eclipse/updates/3.4/");
23
	}
24
25
	public void tearDown() throws Exception {
26
		// Remove repository manager references
27
		getArtifactRepositoryManager().removeRepository(compositeSite);
28
		getMetadataRepositoryManager().removeRepository(compositeSite);
29
		// Cleanup disk
30
		delete(new File(compositeSite));
31
		super.tearDown();
32
	}
33
34
	public void testCreateCompositeArtifactRepository() throws Exception {
35
		// Create Composite Repository Task
36
		AntTaskElement createCompositeTask = getCreateCompositeTask(TYPE_ARTIFACT);
37
		addTask(createCompositeTask);
38
39
		runAntTask();
40
41
		assertTrue(getArtifactRepositoryManager().contains(compositeSite));
42
		assertTrue(getArtifactRepositoryManager().loadRepository(compositeSite, null) instanceof CompositeArtifactRepository);
43
	}
44
45
	public void testCreateCompositeMetadataRepository() throws Exception {
46
		// Create Composite Repository Task
47
		AntTaskElement createCompositeTask = getCreateCompositeTask(TYPE_METADATA);
48
		addTask(createCompositeTask);
49
50
		runAntTask();
51
52
		assertTrue(getMetadataRepositoryManager().contains(compositeSite));
53
		assertTrue(getMetadataRepositoryManager().loadRepository(compositeSite, null) instanceof CompositeMetadataRepository);
54
	}
55
56
	public void testCreateCombinedCompositeRepository() throws Exception {
57
		// Create Composite Repository Task
58
		AntTaskElement createCompositeTask = getCreateCompositeTask(null);
59
		addTask(createCompositeTask);
60
61
		runAntTask();
62
63
		assertTrue(getMetadataRepositoryManager().contains(compositeSite));
64
		assertTrue(getArtifactRepositoryManager().contains(compositeSite));
65
		assertTrue(getMetadataRepositoryManager().loadRepository(compositeSite, null) instanceof CompositeMetadataRepository);
66
		assertTrue(getArtifactRepositoryManager().loadRepository(compositeSite, null) instanceof CompositeArtifactRepository);
67
	}
68
69
	public void testFailOnExists() throws Exception {
70
		// Create Composite Repository Task
71
		AntTaskElement createCompositeTask = getCreateCompositeTask(TYPE_ARTIFACT);
72
		addTask(createCompositeTask);
73
		runAntTask();
74
75
		// Set failOnExists
76
		createCompositeTask.addAttributes(new String[] {"failOnExists", String.valueOf(true)});
77
78
		Throwable exception = null;
79
		try {
80
			runAntTaskWithExceptions();
81
		} catch (CoreException e) {
82
			exception = rootCause(e);
83
		}
84
		if (!exception.getMessage().contains("exists"))
85
			fail("Unexpected exception: ", exception);
86
	}
87
88
	public void testNotCompressed() throws Exception {
89
		// Create Composite Repository Task
90
		AntTaskElement createCompositeTask = getCreateCompositeTask(TYPE_ARTIFACT);
91
		addTask(createCompositeTask);
92
		// Set the compressed attribute to false
93
		((AntTaskElement) createCompositeTask.elements.get(0)).addAttributes(new String[] {"compressed", String.valueOf(false)});
94
		runAntTask();
95
96
		try {
97
			IArtifactRepository repo = getArtifactRepositoryManager().loadRepository(compositeSite, null);
98
			assertTrue(repo instanceof CompositeArtifactRepository);
99
			assertFalse("The repository is compressed", Boolean.valueOf((String) repo.getProperties().get(IRepository.PROP_COMPRESSED)));
100
		} catch (ProvisionException e) {
101
			fail("Failed to load repository", e);
102
		}
103
	}
104
105
	public void testName() {
106
		String repoName = "My Test Repository";
107
		// Create Composite Repository Task
108
		AntTaskElement createCompositeTask = getCreateCompositeTask(TYPE_ARTIFACT);
109
		addTask(createCompositeTask);
110
		// Set the repository name
111
		((AntTaskElement) createCompositeTask.elements.get(0)).addAttributes(new String[] {"name", repoName});
112
113
		runAntTask();
114
115
		try {
116
			IArtifactRepository repo = getArtifactRepositoryManager().loadRepository(compositeSite, null);
117
			assertTrue(repo instanceof CompositeArtifactRepository);
118
			assertEquals(repoName, repo.getName());
119
		} catch (ProvisionException e) {
120
			fail("Failed to load repository", e);
121
		}
122
	}
123
124
	public void testAddChild() {
125
		// Create Composite Repository Task
126
		AntTaskElement createCompositeTask = getCreateCompositeTask(TYPE_ARTIFACT);
127
		addTask(createCompositeTask);
128
129
		// Create add element
130
		AntTaskElement addElement = new AntTaskElement("add");
131
		// Add a repository
132
		addElement.addElement(getRepositoryElement(HTTP_SITE, TYPE_ARTIFACT));
133
		createCompositeTask.addElement(addElement);
134
135
		runAntTask();
136
137
		try {
138
			CompositeArtifactRepository repo = (CompositeArtifactRepository) getArtifactRepositoryManager().loadRepository(compositeSite, null);
139
			assertTrue(repo.getChildren().contains(HTTP_SITE));
140
		} catch (ProvisionException e) {
141
			fail("Failed to load repository", e);
142
		}
143
	}
144
145
	public void testInvalidLocation() throws Exception {
146
		URI location = URIUtil.fromString("scheme:/location");
147
		AntTaskElement createCompositeTask = new AntTaskElement("p2.create.composite.repository");
148
		createCompositeTask.addElement(getRepositoryElement(location, TYPE_ARTIFACT));
149
		addTask(createCompositeTask);
150
151
		Exception exception = null;
152
		try {
153
			runAntTaskWithExceptions();
154
		} catch (CoreException e) {
155
			exception = e;
156
			if (!(rootCause(e) instanceof IllegalStateException))
157
				fail("Expected IllegalStateException.", e);
158
			else {
159
				try {
160
					getArtifactRepositoryManager().loadRepository(location, null);
161
					fail("Repository with invalid location loaded.");
162
				} catch (ProvisionException e2) {
163
					// This is a success
164
				}
165
			}
166
		}
167
		if (exception == null)
168
			fail("No exception thrown");
169
170
	}
171
172
	private AntTaskElement getCreateCompositeTask(String type) {
173
		AntTaskElement createCompositeTask = new AntTaskElement("p2.create.composite.repository");
174
		createCompositeTask.addElement(getRepositoryElement(compositeSite, type));
175
		return createCompositeTask;
176
	}
177
}
(-)src/org/eclipse/equinox/p2/tests/AbstractAntProvisioningTest.java (+202 lines)
Added Link Here
1
package org.eclipse.equinox.p2.tests;
2
3
import java.io.File;
4
import java.io.FileOutputStream;
5
import java.net.URI;
6
import java.util.*;
7
import org.eclipse.ant.core.AntRunner;
8
import org.eclipse.core.runtime.CoreException;
9
import org.eclipse.core.runtime.URIUtil;
10
import org.eclipse.equinox.internal.p2.persistence.XMLWriter;
11
12
public class AbstractAntProvisioningTest extends AbstractProvisioningTest {
13
	protected static final String TYPE_ARTIFACT = "A";
14
	protected static final String TYPE_METADATA = "M";
15
16
	private static final String TARGET = "target";
17
	private static final String ROOT = "project";
18
	private static final String NAME = "name";
19
	private static final String DEFAULT_TARGET = "default";
20
	private static final String DEFAULT_NAME = "default";
21
22
	AntTaskElement root, target;
23
	File buildScript, logLocation;
24
25
	public void setUp() throws Exception {
26
		super.setUp();
27
		buildScript = new File(getTempFolder(), getUniqueString());
28
		logLocation = new File(getTempFolder(), getUniqueString());
29
		createBuildScript();
30
	}
31
32
	public void tearDown() throws Exception {
33
		// Delete the build script
34
		delete(buildScript.getParentFile());
35
		delete(logLocation.getParentFile());
36
		super.tearDown();
37
	}
38
39
	/*
40
	 * Run the specified buildscript
41
	 */
42
	protected void runAntTask(File buildFile) {
43
		try {
44
			runAntTaskWithExceptions(buildFile);
45
		} catch (CoreException e) {
46
			fail(rootCause(e));
47
		}
48
	}
49
50
	private void runAntTaskWithExceptions(File buildFile) throws CoreException {
51
		AntRunner ant = new AntRunner();
52
		ant.setArguments("-logfile \"" + logLocation + "\"");
53
		ant.setBuildFileLocation(buildFile.getAbsolutePath());
54
		ant.addBuildLogger("org.apache.tools.ant.XmlLogger");
55
		ant.run();
56
	}
57
58
	/*
59
	 * Run the build script described programmatically
60
	 */
61
	protected void runAntTask() {
62
		try {
63
			runAntTaskWithExceptions();
64
		} catch (CoreException e) {
65
			fail(rootCause(e));
66
		}
67
	}
68
69
	protected void runAntTaskWithExceptions() throws CoreException {
70
		try {
71
			writeBuildScript();
72
		} catch (Exception e) {
73
			fail("Error writing build script", e);
74
		}
75
		runAntTaskWithExceptions(buildScript);
76
	}
77
78
	/*
79
	 * Adds an Ant Task to the build script
80
	 */
81
	protected void addTask(AntTaskElement task) {
82
		target.addElement(task);
83
	}
84
85
	/*
86
	 * Create and return an repository element for this address and type
87
	 */
88
	protected AntTaskElement getRepositoryElement(URI address, String kind) {
89
		return getRepositoryElement(address, kind, null, null, null, null);
90
	}
91
92
	protected AntTaskElement getRepositoryElement(URI address, String kind, String name, String format, Boolean compressed, Boolean append) {
93
		AntTaskElement repo = new AntTaskElement("repository");
94
		repo.addAttributes(new String[] {"location", URIUtil.toUnencodedString(address)});
95
		if (kind != null)
96
			repo.addAttributes(new String[] {"kind", kind});
97
		if (name != null)
98
			repo.addAttributes(new String[] {"name", name});
99
		if (format != null)
100
			repo.addAttributes(new String[] {"format", format});
101
		if (compressed != null)
102
			repo.addAttributes(new String[] {"compressed", compressed.toString()});
103
		if (append != null)
104
			repo.addAttributes(new String[] {"append", append.toString()});
105
		return repo;
106
	}
107
108
	/*
109
	 * Create the base elements of the build script
110
	 */
111
	private void createBuildScript() {
112
		root = new AntTaskElement(ROOT);
113
		root.addAttributes(new String[] {NAME, ROOT, DEFAULT_TARGET, DEFAULT_NAME});
114
		target = new AntTaskElement(TARGET);
115
		target.addAttributes(new String[] {NAME, DEFAULT_NAME});
116
		root.addElement(target);
117
	}
118
119
	/*
120
	 * Write the build script to disk
121
	 */
122
	private void writeBuildScript() throws Exception {
123
		FileOutputStream outputStream = null;
124
		try {
125
			outputStream = new FileOutputStream(buildScript);
126
			XMLWriter writer = new XMLWriter(outputStream, null);
127
			writeElement(writer, root);
128
			writer.flush();
129
		} finally {
130
			if (outputStream != null)
131
				outputStream.close();
132
		}
133
	}
134
135
	/*
136
	 * Write an element to the buildscript
137
	 */
138
	private void writeElement(XMLWriter writer, AntTaskElement task) {
139
		// Properties ought to occur in key-value pairs 
140
		assertTrue("Task " + task + " should have an even number of properties", (task.attributes.size() % 2) == 0);
141
142
		// Start tag
143
		writer.start(task.name);
144
145
		// write properties
146
		for (Iterator iter = task.attributes.iterator(); iter.hasNext();)
147
			writer.attribute((String) iter.next(), (String) iter.next());
148
149
		// write sub elements if applicable
150
		for (Iterator iter = task.elements.iterator(); iter.hasNext();)
151
			writeElement(writer, (AntTaskElement) iter.next());
152
153
		// close tag
154
		writer.end();
155
	}
156
157
	// Class which can be used to represent elements in a task
158
	protected class AntTaskElement {
159
		public String name;
160
		public List attributes = new ArrayList();
161
		public List elements = new ArrayList();
162
163
		public AntTaskElement(String name) {
164
			this.name = name;
165
		}
166
167
		public void addAttribute(String attribute, String value) {
168
			attributes.add(attribute);
169
			attributes.add(value);
170
		}
171
172
		public void addAttributes(String[] propertyArray) {
173
			attributes.addAll(Arrays.asList(propertyArray));
174
		}
175
176
		public void addElement(AntTaskElement element) {
177
			elements.add(element);
178
		}
179
180
		public String toString() {
181
			return name;
182
		}
183
	}
184
185
	protected static Throwable rootCause(Throwable e) {
186
		if (e.getCause() != null)
187
			return rootCause(e.getCause());
188
		return e;
189
	}
190
191
	protected static void fail(Throwable e) {
192
		fail("An exception occurred while running the task", e);
193
	}
194
195
	protected void assertLogContains(String content) {
196
		try {
197
			assertLogContainsLine(logLocation, content);
198
		} catch (Exception e) {
199
			fail("Error asserting log contents.", e);
200
		}
201
	}
202
}
(-)src/org/eclipse/equinox/p2/tests/ant/ModifyCompositeRepositoryTaskTest.java (+189 lines)
Added Link Here
1
package org.eclipse.equinox.p2.tests.ant;
2
3
import java.io.File;
4
import java.net.URI;
5
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
6
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository;
7
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
8
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
9
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
10
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
11
import org.eclipse.equinox.internal.provisional.p2.repository.ICompositeRepository;
12
import org.eclipse.equinox.p2.tests.AbstractAntProvisioningTest;
13
14
public class ModifyCompositeRepositoryTaskTest extends AbstractAntProvisioningTest {
15
	private static final String ADD_ELEMENT = "add";
16
	private static final String REMOVE_ELEMENT = "remove";
17
	private URI compositeSite;
18
	private static URI HTTP_SITE;
19
20
	public void setUp() throws Exception {
21
		super.setUp();
22
		// Get a random location to create a repository
23
		compositeSite = (new File(getTempFolder(), getUniqueString())).toURI();
24
		HTTP_SITE = new URI("http://download.eclipse.org/eclipse/updates/3.4/");
25
	}
26
27
	public void tearDown() throws Exception {
28
		// Remove repository manager references
29
		getArtifactRepositoryManager().removeRepository(compositeSite);
30
		getMetadataRepositoryManager().removeRepository(compositeSite);
31
		// Cleanup disk
32
		delete(new File(compositeSite));
33
		super.tearDown();
34
	}
35
36
	public void testAddChildArtifact() throws Exception {
37
		// Create repository
38
		createCompositeRepository(TYPE_ARTIFACT);
39
		// Create the modify repository task
40
		AntTaskElement modify = createModifyElement(TYPE_ARTIFACT);
41
		addTask(modify);
42
43
		// Create the Add element
44
		AntTaskElement add = new AntTaskElement(ADD_ELEMENT);
45
		add.addElement(getRepositoryElement(HTTP_SITE, TYPE_ARTIFACT));
46
		modify.addElement(add);
47
48
		// Run the task
49
		runAntTask();
50
51
		CompositeArtifactRepository repo = (CompositeArtifactRepository) getCompositeRepository(TYPE_ARTIFACT);
52
		assertTrue("Repository does not contain child", repo.getChildren().contains(HTTP_SITE));
53
	}
54
55
	public void testAddChildMetadata() {
56
		// Create repository
57
		createCompositeRepository(TYPE_METADATA);
58
		// Create the modify repository task
59
		AntTaskElement modify = createModifyElement(TYPE_METADATA);
60
		addTask(modify);
61
62
		// Create the Add element
63
		AntTaskElement add = new AntTaskElement(ADD_ELEMENT);
64
		add.addElement(getRepositoryElement(HTTP_SITE, TYPE_METADATA));
65
		modify.addElement(add);
66
67
		// Run the task
68
		runAntTask();
69
70
		CompositeMetadataRepository repo = (CompositeMetadataRepository) getCompositeRepository(TYPE_METADATA);
71
		assertTrue("Repository does not contain child", repo.getChildren().contains(HTTP_SITE));
72
	}
73
74
	public void testAddChildBoth() {
75
		// Create repository
76
		createCompositeRepository(null);
77
		// Create the modify repository task
78
		AntTaskElement modify = createModifyElement(null);
79
		addTask(modify);
80
81
		// Create the Add element
82
		AntTaskElement add = createAddElement(null, new URI[] {HTTP_SITE});
83
		modify.addElement(add);
84
85
		// Run the task
86
		runAntTask();
87
88
		CompositeArtifactRepository artifactRepo = (CompositeArtifactRepository) getCompositeRepository(TYPE_ARTIFACT);
89
		assertTrue("Repository does not contain child", artifactRepo.getChildren().contains(HTTP_SITE));
90
91
		CompositeMetadataRepository metadataRepo = (CompositeMetadataRepository) getCompositeRepository(TYPE_METADATA);
92
		assertTrue("Repository does not contain child", metadataRepo.getChildren().contains(HTTP_SITE));
93
	}
94
95
	public void testRemoveAllChildren() {
96
		// Create repository
97
		ICompositeRepository parent = createCompositeRepository(TYPE_ARTIFACT);
98
		parent.addChild(HTTP_SITE);
99
100
		// Create the modify repository task
101
		AntTaskElement modify = createModifyElement(TYPE_ARTIFACT);
102
		addTask(modify);
103
		((AntTaskElement) modify.elements.get(0)).addAttributes(new String[] {"append", String.valueOf(false)});
104
105
		// Run the task
106
		runAntTask();
107
108
		CompositeArtifactRepository artifactRepo = (CompositeArtifactRepository) getCompositeRepository(TYPE_ARTIFACT);
109
		assertTrue("Children not removed", artifactRepo.getChildren().isEmpty());
110
111
	}
112
113
	public void testRemoveChild() {
114
		createCompositeRepository(TYPE_ARTIFACT);
115
		AntTaskElement modify = createModifyElement(TYPE_ARTIFACT);
116
		addTask(modify);
117
118
		AntTaskElement add = createAddElement(TYPE_ARTIFACT, new URI[] {HTTP_SITE});
119
		modify.addElement(add);
120
121
		modify = createModifyElement(TYPE_ARTIFACT);
122
		addTask(modify);
123
		AntTaskElement remove = createRemoveElement(TYPE_ARTIFACT, new URI[] {HTTP_SITE});
124
		modify.addElement(remove);
125
126
		runAntTask();
127
128
		CompositeArtifactRepository repo = (CompositeArtifactRepository) getCompositeRepository(TYPE_ARTIFACT);
129
		assertFalse(repo.getChildren().contains(HTTP_SITE));
130
	}
131
132
	protected ICompositeRepository getCompositeRepository(String type) {
133
		try {
134
			if (type == TYPE_ARTIFACT) {
135
				return (ICompositeRepository) getArtifactRepositoryManager().loadRepository(compositeSite, null);
136
			} else if (type == TYPE_METADATA)
137
				return (ICompositeRepository) getMetadataRepositoryManager().loadRepository(compositeSite, null);
138
			else
139
				fail("No type specified");
140
		} catch (ProvisionException e) {
141
			fail("Failed to load repository", e);
142
		} catch (ClassCastException e) {
143
			fail("Repository is not composite", e);
144
		}
145
		// Will not occur
146
		return null;
147
	}
148
149
	protected AntTaskElement createRemoveElement(String type, URI[] addresses) {
150
		AntTaskElement add = new AntTaskElement(REMOVE_ELEMENT);
151
		for (int i = 0; i < addresses.length; i++)
152
			add.addElement(getRepositoryElement(addresses[i], type));
153
		return add;
154
	}
155
156
	protected AntTaskElement createAddElement(String type, URI[] addresses) {
157
		AntTaskElement add = new AntTaskElement(ADD_ELEMENT);
158
		for (int i = 0; i < addresses.length; i++)
159
			add.addElement(getRepositoryElement(addresses[i], type));
160
		return add;
161
	}
162
163
	protected AntTaskElement createModifyElement(String type) {
164
		AntTaskElement modifyCompositeTask = new AntTaskElement("p2.modify.composite.repository.children");
165
		modifyCompositeTask.addElement(getRepositoryElement(compositeSite, type));
166
167
		return modifyCompositeTask;
168
	}
169
170
	protected ICompositeRepository createCompositeRepository(String type) {
171
		ICompositeRepository repo = null;
172
		try {
173
			if (TYPE_ARTIFACT.equals(type) || type == null) {
174
				repo = (ICompositeRepository) RepositoryHelper.validDestinationRepository(getArtifactRepositoryManager().createRepository(compositeSite, "Test Composite Repo", IArtifactRepositoryManager.TYPE_COMPOSITE_REPOSITORY, null));
175
			}
176
			if (TYPE_METADATA.equals(type) || type == null) {
177
				repo = (ICompositeRepository) RepositoryHelper.validDestinationRepository(getMetadataRepositoryManager().createRepository(compositeSite, "Test Composite Repo", IMetadataRepositoryManager.TYPE_COMPOSITE_REPOSITORY, null));
178
			}
179
		} catch (ProvisionException e) {
180
			fail("Failed to create composite repository", e);
181
		} catch (IllegalStateException e) {
182
			fail("failed to create writeable composite repository", e);
183
		}
184
		return repo;
185
		/*AntTaskElement createCompositeTask = new AntTaskElement("p2.create.composite.repository");
186
		createCompositeTask.addElement(getRepositoryElement(compositeSite, type));
187
		addTask(createCompositeTask);*/
188
	}
189
}
(-)src/org/eclipse/equinox/p2/tests/ant/AllTests.java (+28 lines)
Added Link Here
1
/*******************************************************************************
2
 *  Copyright (c) 2007, 2009 IBM Corporation and others.
3
 *  All rights reserved. This program and the accompanying materials
4
 *  are made available under the terms of the Eclipse Public License v1.0
5
 *  which accompanies this distribution, and is available at
6
 *  http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 *  Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.tests.ant;
12
13
import junit.framework.*;
14
15
/**
16
 * Performs all automated artifact repository tests.
17
 */
18
public class AllTests extends TestCase {
19
20
	public static Test suite() {
21
		TestSuite suite = new TestSuite(AllTests.class.getName());
22
		suite.addTestSuite(CreateCompositeRepositoryTaskTest.class);
23
		suite.addTestSuite(MirrorTaskTest.class);
24
		suite.addTestSuite(ModifyCompositeRepositoryTaskTest.class);
25
		return suite;
26
	}
27
28
}
(-)src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java (+274 lines)
Added Link Here
1
package org.eclipse.equinox.p2.tests.ant;
2
3
import java.io.*;
4
import java.net.URI;
5
import java.util.Iterator;
6
import org.eclipse.core.runtime.CoreException;
7
import org.eclipse.core.runtime.URIUtil;
8
import org.eclipse.equinox.internal.p2.metadata.InstallableUnit;
9
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.*;
10
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
11
import org.eclipse.equinox.internal.provisional.p2.core.Version;
12
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
13
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
14
import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
15
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
16
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
17
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
18
import org.eclipse.equinox.p2.tests.AbstractAntProvisioningTest;
19
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
20
import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;
21
import org.eclipse.osgi.util.NLS;
22
23
public class MirrorTaskTest extends AbstractAntProvisioningTest {
24
	private URI destinationRepo;
25
	private URI sourceRepo2;
26
27
	public void setUp() throws Exception {
28
		super.setUp();
29
		// Get a random location to create a repository
30
		destinationRepo = (new File(getTempFolder(), getUniqueString())).toURI();
31
		sourceRepo2 = getTestData("loading error data", "testData/mirror/mirrorSourceRepo2").toURI();
32
	}
33
34
	public void tearDown() throws Exception {
35
		// Remove repository manager references
36
		getArtifactRepositoryManager().removeRepository(destinationRepo);
37
		getMetadataRepositoryManager().removeRepository(destinationRepo);
38
		getArtifactRepositoryManager().removeRepository(sourceRepo2);
39
		getMetadataRepositoryManager().removeRepository(sourceRepo2);
40
		// Cleanup disk
41
		delete(new File(destinationRepo));
42
		super.tearDown();
43
	}
44
45
	/*
46
	 * Test that all IUs can be mirrored
47
	 */
48
	public void testMirrorAllIUSpecified() throws ProvisionException {
49
		AntTaskElement mirror = createMirrorTask();
50
		mirror.addElement(createSourceElement(sourceRepo2, sourceRepo2));
51
		addAllIUs(mirror, getMetadataRepositoryManager().loadRepository(sourceRepo2, null));
52
		runAntTask();
53
54
		try {
55
			assertEquals("Different number of Artifact Keys", getArtifactKeyCount(sourceRepo2), getArtifactKeyCount(destinationRepo));
56
			assertEquals("Different number of IUs", getIUCount(sourceRepo2), getIUCount(destinationRepo));
57
		} catch (ProvisionException e) {
58
			fail("Failed to load Repository", e);
59
		}
60
	}
61
62
	/*
63
	 * Test that we only mirror specified IUs & Artifacts
64
	 */
65
	public void testMirrorSomeIUSpecified() {
66
		AntTaskElement mirror = createMirrorTask();
67
		mirror.addElement(createSourceElement(sourceRepo2, sourceRepo2));
68
		mirror.addElement(createIUElement("anotherplugin", "1.0.0"));
69
70
		runAntTask();
71
72
		try {
73
			assertEquals("Wrong number of Artifact Keys", 1, getArtifactKeyCount(destinationRepo));
74
			assertEquals("Wrong number of IUs", 1, getIUCount(destinationRepo));
75
		} catch (ProvisionException e) {
76
			fail("Failed to load Repository", e);
77
		}
78
	}
79
80
	/*
81
	 * Test that the proper exception is thrown when no IU is provided
82
	 */
83
	public void testMirrorNoIUNoRepo() {
84
		AntTaskElement mirror = createMirrorTask();
85
		mirror.addElement(createSourceElement(sourceRepo2, null));
86
87
		Exception exception = null;
88
		try {
89
			runAntTaskWithExceptions();
90
		} catch (CoreException e) {
91
			exception = e;
92
		}
93
		if (exception == null)
94
			fail("No exception thrown");
95
		if (!(rootCause(exception) instanceof ProvisionException) && !rootCause(exception).getMessage().contains("No IUs"))
96
			fail("Exception is of an unexpected type or message", rootCause(exception));
97
98
	}
99
100
	/*
101
	 * Test that all IUs are mirrored when none are specified
102
	 */
103
	public void testMirrorNoIUSpecified() {
104
		AntTaskElement mirror = createMirrorTask();
105
		mirror.addElement(createSourceElement(sourceRepo2, sourceRepo2));
106
107
		runAntTask();
108
109
		try {
110
			assertEquals("Different number of Artifact Keys", getArtifactKeyCount(sourceRepo2), getArtifactKeyCount(destinationRepo));
111
			assertEquals("Different number of IUs", getIUCount(sourceRepo2), getIUCount(destinationRepo));
112
		} catch (ProvisionException e) {
113
			fail("Failed to load Repository", e);
114
		}
115
	}
116
117
	/*
118
	 * 
119
	 */
120
	public void testBaselineCompareUsingMD5Comparator() {
121
		//Setup create descriptors with different md5 values
122
		IArtifactKey dupKey = PublisherHelper.createBinaryArtifactKey("testKeyId", new Version("1.2.3"));
123
		File artifact1 = getTestData("0.0", "/testData/mirror/mirrorSourceRepo1 with space/content.xml");
124
		File artifact2 = getTestData("0.0", "/testData/mirror/mirrorSourceRepo2/content.xml");
125
126
		//Setup Copy the file to the baseline
127
		File repoLocation = getTestFolder(getUniqueString());
128
		File baselineLocation = getTestFolder(getUniqueString());
129
		File baselineBinaryDirectory = new File(baselineLocation, "binary");
130
		baselineBinaryDirectory.mkdir();
131
		File baselineContentLocation = new File(baselineBinaryDirectory, "testKeyId_1.2.3");
132
		AbstractProvisioningTest.copy("Copying File to baseline", artifact2, baselineContentLocation);
133
134
		IArtifactDescriptor descriptor1 = PublisherHelper.createArtifactDescriptor(dupKey, artifact1);
135
		IArtifactDescriptor descriptor2 = PublisherHelper.createArtifactDescriptor(dupKey, baselineContentLocation);
136
137
		assertEquals("Ensuring Descriptors are the same", descriptor1, descriptor2);
138
		assertNotSame("Ensuring MD5 values are different", descriptor1.getProperty(IArtifactDescriptor.DOWNLOAD_MD5), descriptor2.getProperty(IArtifactDescriptor.DOWNLOAD_MD5));
139
140
		//Setup make repositories
141
		IArtifactRepository repo = null;
142
		IArtifactRepository baseline = null;
143
		try {
144
			repo = createAndAddIU(repoLocation.toURI(), descriptor1);
145
			baseline = createAndAddIU(baselineLocation.toURI(), descriptor2);
146
		} catch (ProvisionException e) {
147
			fail("Error creating repositories", e);
148
		}
149
150
		//Comparator prints to stderr, redirect that to a file
151
		PrintStream oldErr = System.err;
152
		PrintStream newErr = null;
153
		PrintStream oldOut = System.out;
154
		PrintStream newOut = null;
155
		try {
156
			(new File(destinationRepo)).mkdir();
157
			newErr = new PrintStream(new FileOutputStream(new File(new File(destinationRepo), "sys.err")));
158
			newOut = new PrintStream(new FileOutputStream(new File(new File(destinationRepo), "sys.out")));
159
		} catch (FileNotFoundException e) {
160
			fail("Error redirecting outputs", e);
161
		}
162
163
		try {
164
			System.setErr(newErr);
165
			System.setOut(newOut);
166
167
			AntTaskElement mirror = createMirrorTask();
168
			mirror.addElement(createSourceElement(repoLocation.toURI(), repoLocation.toURI()));
169
			mirror.addAttribute("baseline", URIUtil.toUnencodedString(baselineLocation.toURI()));
170
			mirror.addAttribute("verbose", String.valueOf(true));
171
			mirror.addAttribute("compare", String.valueOf(true));
172
173
			runAntTaskWithExceptions();
174
			//Set compareAgaist
175
			//String[] args = new String[] {"-source", repoLocation.toURL().toExternalForm(), "-destination", destinationRepo.toURL().toExternalForm(), "-compareAgainst", baselineLocation.toURL().toExternalForm(), "-verbose", "-compare"};
176
			//run the mirror application
177
			//runMirrorApplication("Running with baseline compare", args);
178
		} catch (Exception e) {
179
			fail("Running mirror application with baseline compare", rootCause(e));
180
		} finally {
181
			System.setErr(oldErr);
182
			newErr.close();
183
			System.setOut(oldOut);
184
			newOut.close();
185
		}
186
187
		IArtifactRepository destination = null;
188
		try {
189
			destination = getArtifactRepositoryManager().loadRepository(destinationRepo, null);
190
		} catch (ProvisionException e) {
191
			fail("Error loading destination", e);
192
		}
193
194
		IArtifactDescriptor[] destDescriptors = destination.getArtifactDescriptors(descriptor2.getArtifactKey());
195
		assertEquals("Ensuring destination has correct number of descriptors", 1, destDescriptors.length);
196
		assertEquals("Ensuring destination contains the descriptor from the baseline", descriptor2.getProperty(IArtifactDescriptor.DOWNLOAD_MD5), destDescriptors[0].getProperty(IArtifactDescriptor.DOWNLOAD_MD5));
197
		String msg = NLS.bind("have different MD5 sums for {2}", new Object[] {baseline, repo, descriptor1});
198
		assertLogContains(msg);
199
	}
200
201
	/*
202
	 * Create an IU for a descriptor and the IU+descriptor to the specified repo
203
	 */
204
	protected IArtifactRepository createAndAddIU(URI repoLocation, IArtifactDescriptor descriptor) throws ProvisionException {
205
		IArtifactRepository artifactRepo = getArtifactRepositoryManager().createRepository(repoLocation, "Repo 1", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null);
206
		artifactRepo.addDescriptor(descriptor);
207
208
		IMetadataRepository metaRepo = getMetadataRepositoryManager().createRepository(repoLocation, "Repo", IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null);
209
		InstallableUnit iu = new InstallableUnit();
210
		iu.setId(descriptor.getArtifactKey().getId() + "IU");
211
		iu.setVersion(descriptor.getArtifactKey().getVersion());
212
		iu.setArtifacts(new IArtifactKey[] {descriptor.getArtifactKey()});
213
		metaRepo.addInstallableUnits(new IInstallableUnit[] {iu});
214
215
		return artifactRepo;
216
	}
217
218
	/*
219
	 * Get the number of artifact keys in a repository
220
	 */
221
	protected int getArtifactKeyCount(URI location) throws ProvisionException {
222
		return getArtifactRepositoryManager().loadRepository(location, null).getArtifactKeys().length;
223
	}
224
225
	/*
226
	 * Get the number of IUs in a repository
227
	 */
228
	protected int getIUCount(URI location) throws ProvisionException {
229
		return getMetadataRepositoryManager().loadRepository(location, null).query(InstallableUnitQuery.ANY, new Collector(), null).size();
230
	}
231
232
	/*
233
	 * Add all IUs to the parent element
234
	 */
235
	protected void addAllIUs(AntTaskElement parent, IMetadataRepository repo) {
236
		Collector collector = repo.query(InstallableUnitQuery.ANY, new Collector(), null);
237
238
		for (Iterator iter = collector.iterator(); iter.hasNext();) {
239
			IInstallableUnit iu = (IInstallableUnit) iter.next();
240
			parent.addElement(createIUElement(iu.getId(), iu.getVersion().toString()));
241
		}
242
	}
243
244
	/*
245
	 * Create an element from the specified information
246
	 */
247
	protected AntTaskElement createIUElement(String id, String version) {
248
		AntTaskElement iu = new AntTaskElement("iu");
249
		iu.addAttributes(new String[] {"id", id, "version", version});
250
		return iu;
251
	}
252
253
	/*
254
	 * Create the base mirror task & add it to the script
255
	 */
256
	protected AntTaskElement createMirrorTask() {
257
		AntTaskElement mirror = new AntTaskElement("p2.mirror");
258
		mirror.addElement(getRepositoryElement(destinationRepo, null));
259
		addTask(mirror);
260
		return mirror;
261
	}
262
263
	/*
264
	 * Create a source element with the specified repositories
265
	 */
266
	protected AntTaskElement createSourceElement(URI artifact, URI metadata) {
267
		AntTaskElement source = new AntTaskElement("source");
268
		if (artifact != null)
269
			source.addElement(getRepositoryElement(artifact, AbstractAntProvisioningTest.TYPE_ARTIFACT));
270
		if (metadata != null)
271
			source.addElement(getRepositoryElement(metadata, AbstractAntProvisioningTest.TYPE_METADATA));
272
		return source;
273
	}
274
}
(-)src/org/eclipse/equinox/p2/internal/repository/tools/RepositoryDescriptor.java (-4 / +6 lines)
Lines 10-27 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.internal.repository.tools;
11
package org.eclipse.equinox.p2.internal.repository.tools;
12
12
13
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
14
15
import java.net.URI;
13
import java.net.URI;
14
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
15
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
16
16
17
public class RepositoryDescriptor {
17
public class RepositoryDescriptor {
18
18
19
	public static final int TYPE_BOTH = -1;
20
19
	private boolean compressed = true;
21
	private boolean compressed = true;
20
	private boolean append = true;
22
	private boolean append = true;
21
	private String name = null;
23
	private String name = null;
22
	private URI location = null;
24
	private URI location = null;
23
	private String format = null;
25
	private String format = null;
24
	private int kind;
26
	private int kind = TYPE_BOTH;
25
27
26
	public void setCompressed(boolean compress) {
28
	public void setCompressed(boolean compress) {
27
		compressed = compress;
29
		compressed = compress;
Lines 32-38 Link Here
32
	}
34
	}
33
35
34
	public void setLocation(URI repoLocation) {
36
	public void setLocation(URI repoLocation) {
35
		location = repoLocation;
37
		location = RepositoryHelper.localRepoURIHelper(repoLocation);
36
	}
38
	}
37
39
38
	public void setFormat(String format) {
40
	public void setFormat(String format) {
(-)src/org/eclipse/equinox/p2/internal/repository/tools/MirrorApplication.java (-11 / +109 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.internal.repository.tools;
11
package org.eclipse.equinox.p2.internal.repository.tools;
12
12
13
import java.net.URI;
13
import java.util.ArrayList;
14
import java.util.ArrayList;
14
import java.util.Iterator;
15
import java.util.Iterator;
15
import org.eclipse.core.runtime.*;
16
import org.eclipse.core.runtime.*;
Lines 17-54 Link Here
17
import org.eclipse.equinox.app.IApplicationContext;
18
import org.eclipse.equinox.app.IApplicationContext;
18
import org.eclipse.equinox.internal.p2.artifact.mirror.Mirroring;
19
import org.eclipse.equinox.internal.p2.artifact.mirror.Mirroring;
19
import org.eclipse.equinox.internal.p2.director.PermissiveSlicer;
20
import org.eclipse.equinox.internal.p2.director.PermissiveSlicer;
21
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
22
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
20
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
23
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
21
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
24
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
22
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
25
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
23
import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
26
import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
27
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
24
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
28
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
25
import org.eclipse.equinox.internal.provisional.p2.query.IQueryable;
29
import org.eclipse.equinox.internal.provisional.p2.query.IQueryable;
30
import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager;
26
31
27
public class MirrorApplication extends AbstractApplication {
32
public class MirrorApplication extends AbstractApplication {
28
	protected SlicingOptions slicingOptions = new SlicingOptions();
33
	protected SlicingOptions slicingOptions = new SlicingOptions();
29
34
35
	private URI baseline;
36
	//private URI baseline;
37
	private String comparatorID;
38
	private boolean compare = false;
39
	private boolean failOnError = true;
40
	private boolean raw = true;
41
	private boolean verbose = false;
42
30
	public Object start(IApplicationContext context) throws Exception {
43
	public Object start(IApplicationContext context) throws Exception {
31
		run(null);
44
		run(null);
32
		return IApplication.EXIT_OK;
45
		return IApplication.EXIT_OK;
33
	}
46
	}
34
47
35
	public IStatus run(IProgressMonitor monitor) throws ProvisionException {
48
	public IStatus run(IProgressMonitor monitor) throws ProvisionException {
49
		IStatus mirrorStatus = null;
36
		try {
50
		try {
37
			validate();
51
			validate();
38
			initializeRepos(new NullProgressMonitor());
52
			initializeRepos(new NullProgressMonitor());
53
			intializeIUs();
39
			IQueryable slice = slice(new NullProgressMonitor());
54
			IQueryable slice = slice(new NullProgressMonitor());
40
			IStatus mirrorStatus = mirrorArtifacts(slice, new NullProgressMonitor());
55
			if (destinationArtifactRepository != null) {
41
			if (mirrorStatus.getSeverity() == IStatus.ERROR) {
56
				mirrorStatus = mirrorArtifacts(slice, new NullProgressMonitor());
42
				return mirrorStatus;
57
				if (mirrorStatus.getSeverity() == IStatus.ERROR) {
58
					return mirrorStatus;
59
				}
43
			}
60
			}
44
			mirrorMetadata(slice, new NullProgressMonitor());
61
			if (destinationMetadataRepository != null)
62
				mirrorMetadata(slice, new NullProgressMonitor());
45
		} finally {
63
		} finally {
46
			finalizeRepositories();
64
			finalizeRepositories();
47
		}
65
		}
48
		return Status.OK_STATUS;
66
		if (mirrorStatus.isOK())
67
			return Status.OK_STATUS;
68
		return mirrorStatus;
49
	}
69
	}
50
70
51
	private IStatus mirrorArtifacts(IQueryable slice, IProgressMonitor monitor) {
71
	private IStatus mirrorArtifacts(IQueryable slice, IProgressMonitor monitor) throws ProvisionException {
52
		Collector ius = slice.query(InstallableUnitQuery.ANY, new Collector(), monitor);
72
		Collector ius = slice.query(InstallableUnitQuery.ANY, new Collector(), monitor);
53
		ArrayList keys = new ArrayList(ius.size());
73
		ArrayList keys = new ArrayList(ius.size());
54
		for (Iterator iterator = ius.iterator(); iterator.hasNext();) {
74
		for (Iterator iterator = ius.iterator(); iterator.hasNext();) {
Lines 58-66 Link Here
58
				keys.add(iuKeys[i]);
78
				keys.add(iuKeys[i]);
59
			}
79
			}
60
		}
80
		}
61
		Mirroring mirror = new Mirroring(getCompositeArtifactRepository(), destinationArtifactRepository, true);
81
		Mirroring mirror = new Mirroring(getCompositeArtifactRepository(), destinationArtifactRepository, raw);
82
83
		mirror.setCompare(compare);
84
		mirror.setComparatorId(comparatorID);
85
		mirror.setBaseline(initializeBaseline());
62
		mirror.setArtifactKeys((IArtifactKey[]) keys.toArray(new IArtifactKey[keys.size()]));
86
		mirror.setArtifactKeys((IArtifactKey[]) keys.toArray(new IArtifactKey[keys.size()]));
63
		return mirror.run(true, false);
87
88
		return mirror.run(failOnError, verbose);
89
	}
90
91
	private IArtifactRepository initializeBaseline() throws ProvisionException {
92
		if (baseline == null)
93
			return null;
94
		IArtifactRepositoryManager mgr = Activator.getArtifactRepositoryManager();
95
96
		if (!mgr.contains(baseline))
97
			artifactReposToRemove.add(baseline);
98
		return mgr.loadRepository(baseline, IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
64
	}
99
	}
65
100
66
	private void mirrorMetadata(IQueryable slice, IProgressMonitor monitor) {
101
	private void mirrorMetadata(IQueryable slice, IProgressMonitor monitor) {
Lines 77-85 Link Here
77
	private void validate() throws ProvisionException {
112
	private void validate() throws ProvisionException {
78
		if (sourceMetadataRepositories == null)
113
		if (sourceMetadataRepositories == null)
79
			throw new ProvisionException("Need to set the source metadata repository location.");
114
			throw new ProvisionException("Need to set the source metadata repository location.");
80
		if (sourceIUs == null)
115
	}
81
			throw new ProvisionException("Mirroring root needs to be specified.");
116
82
		//TODO Check that the IU is in repo
117
	/*
118
	 * If no IUs have been specified we want to mirror them all
119
	 */
120
	private void intializeIUs() throws ProvisionException {
121
		if (sourceIUs == null || sourceIUs.isEmpty()) {
122
			sourceIUs = new ArrayList();
123
			IMetadataRepository metadataRepo = getCompositeMetadataRepository();
124
			Collector collector = metadataRepo.query(InstallableUnitQuery.ANY, new Collector(), null);
125
126
			for (Iterator iter = collector.iterator(); iter.hasNext();) {
127
				IInstallableUnit iu = (IInstallableUnit) iter.next();
128
				sourceIUs.add(iu);
129
			}
130
131
			if (collector.size() == 0) {
132
				throw new ProvisionException("No IUs specified and no IUs obtained from metadata repositories.");
133
			}
134
		} else {
135
			//TODO Check that the IU is in repo
136
		}
83
	}
137
	}
84
138
85
	private IQueryable slice(IProgressMonitor monitor) {
139
	private IQueryable slice(IProgressMonitor monitor) {
Lines 92-95 Link Here
92
	public void setSlicingOptions(SlicingOptions options) {
146
	public void setSlicingOptions(SlicingOptions options) {
93
		slicingOptions = options;
147
		slicingOptions = options;
94
	}
148
	}
149
150
	/*
151
	 * Set the location of the baseline repository. (used in comparison)
152
	 */
153
	public void setBaseline(URI baseline) {
154
		this.baseline = baseline;
155
		compare = true;
156
	}
157
158
	/*
159
	 * Set the identifier of the comparator to use.
160
	 */
161
	public void setComparatorID(String value) {
162
		comparatorID = value;
163
		compare = true;
164
	}
165
166
	/*
167
	 * Set whether or not the application should be calling a comparator when mirroring.
168
	 */
169
	public void setCompare(boolean value) {
170
		compare = value;
171
	}
172
173
	/*
174
	 * Set whether or not we should ignore errors when running the mirror application.
175
	 */
176
	public void setIgnoreErrors(boolean value) {
177
		failOnError = !value;
178
	}
179
180
	/*
181
	 * Set whether or not the the artifacts are raw.
182
	 */
183
	public void setRaw(boolean value) {
184
		raw = value;
185
	}
186
187
	/*
188
	 * Set whether or not the mirror application should be run in verbose mode.
189
	 */
190
	public void setVerbose(boolean value) {
191
		verbose = value;
192
	}
95
}
193
}
(-)src/org/eclipse/equinox/p2/internal/repository/tools/AbstractApplication.java (-20 / +63 lines)
Lines 10-18 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.internal.repository.tools;
11
package org.eclipse.equinox.p2.internal.repository.tools;
12
12
13
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
14
import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager;
15
16
import java.net.URI;
13
import java.net.URI;
17
import java.net.URISyntaxException;
14
import java.net.URISyntaxException;
18
import java.util.*;
15
import java.util.*;
Lines 24-34 Link Here
24
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
21
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
25
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
22
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
26
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
23
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
24
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
25
import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager;
27
26
28
public abstract class AbstractApplication {
27
public abstract class AbstractApplication {
29
28
29
	protected boolean removeUnknownRepositories = true;
30
30
	protected List sourceArtifactRepositories = new ArrayList();
31
	protected List sourceArtifactRepositories = new ArrayList();
31
	protected List sourceMetadataRepositories = new ArrayList();
32
	protected List sourceMetadataRepositories = new ArrayList();
33
	protected List sourceRepositories = new ArrayList();
32
	protected List artifactReposToRemove = new ArrayList();
34
	protected List artifactReposToRemove = new ArrayList();
33
	protected List metadataReposToRemove = new ArrayList();
35
	protected List metadataReposToRemove = new ArrayList();
34
	protected List sourceIUs = new ArrayList();
36
	protected List sourceIUs = new ArrayList();
Lines 71-85 Link Here
71
	}
73
	}
72
74
73
	protected void finalizeRepositories() throws ProvisionException {
75
	protected void finalizeRepositories() throws ProvisionException {
74
		IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
76
		if (removeUnknownRepositories) {
75
		for (Iterator iter = artifactReposToRemove.iterator(); iter.hasNext();)
77
			IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
76
			artifactRepositoryManager.removeRepository((URI) iter.next());
78
			for (Iterator iter = artifactReposToRemove.iterator(); iter.hasNext();)
77
		IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager();
79
				artifactRepositoryManager.removeRepository((URI) iter.next());
78
		for (Iterator iter = metadataReposToRemove.iterator(); iter.hasNext();)
80
			IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager();
79
			metadataRepositoryManager.removeRepository((URI) iter.next());
81
			for (Iterator iter = metadataReposToRemove.iterator(); iter.hasNext();)
82
				metadataRepositoryManager.removeRepository((URI) iter.next());
83
		}
80
	}
84
	}
81
85
82
	public void initializeRepos(IProgressMonitor progress) throws ProvisionException {
86
	public void initializeRepos(IProgressMonitor progress) throws ProvisionException {
87
		for (Iterator iter = sourceRepositories.iterator(); iter.hasNext();) {
88
			RepositoryDescriptor repo = (RepositoryDescriptor) iter.next();
89
			if (repo.getKind() == IRepository.TYPE_ARTIFACT) {
90
				sourceArtifactRepositories.add(repo.getRepoLocation());
91
			} else if (repo.getKind() == IRepository.TYPE_METADATA) {
92
				sourceMetadataRepositories.add(repo.getRepoLocation());
93
			} else if (repo.getKind() == RepositoryDescriptor.TYPE_BOTH) {
94
				sourceArtifactRepositories.add(repo.getRepoLocation());
95
				sourceMetadataRepositories.add(repo.getRepoLocation());
96
			} else
97
				throw new ProvisionException("Repository of unknown type: " + repo.getRepoLocation());
98
99
		}
83
		IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
100
		IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager();
84
		if (sourceArtifactRepositories != null && !sourceArtifactRepositories.isEmpty()) {
101
		if (sourceArtifactRepositories != null && !sourceArtifactRepositories.isEmpty()) {
85
			for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();) {
102
			for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();) {
Lines 101-128 Link Here
101
		}
118
		}
102
119
103
		processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager);
120
		processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager);
104
105
	}
121
	}
106
122
107
	private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException {
123
	private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException {
108
		if (destinationRepos.size() != 2) {
124
		RepositoryDescriptor artifactRepoDescriptor = null;
109
			throw new ProvisionException("Too many or too few destination repositories.");
125
		RepositoryDescriptor metadataRepoDescriptor = null;
126
127
		Iterator iter = destinationRepos.iterator();
128
		while (iter.hasNext() && (artifactRepoDescriptor == null || metadataRepoDescriptor == null)) {
129
			RepositoryDescriptor repo = (RepositoryDescriptor) iter.next();
130
			int kind = repo.getKind();
131
			if (kind == IRepository.TYPE_ARTIFACT && artifactRepoDescriptor == null)
132
				artifactRepoDescriptor = repo;
133
			else if (kind == IRepository.TYPE_METADATA && metadataRepoDescriptor == null)
134
				metadataRepoDescriptor = repo;
135
			else if (kind == RepositoryDescriptor.TYPE_BOTH) {
136
				if (artifactRepoDescriptor == null)
137
					artifactRepoDescriptor = repo;
138
				if (metadataRepoDescriptor == null)
139
					metadataRepoDescriptor = repo;
140
			}
110
		}
141
		}
111
		RepositoryDescriptor artifactRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_ARTIFACT ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1));
142
112
		RepositoryDescriptor metadataRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_METADATA ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1));
143
		if (artifactRepoDescriptor != null)
113
		destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager);
144
			destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager);
114
		destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager);
145
		if (metadataRepoDescriptor != null)
146
			destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager);
147
148
		if (destinationMetadataRepository == null && destinationArtifactRepository == null)
149
			throw new ProvisionException("Unable to locate a valid destiation repository.");
115
	}
150
	}
116
151
117
	private IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException {
152
	private IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException {
118
		try {
153
		try {
119
			if (mgr.contains(toInit.getRepoLocation()))
154
			if (!mgr.contains(toInit.getRepoLocation()))
120
				metadataReposToRemove.add(toInit.getRepoLocation());
155
				metadataReposToRemove.add(toInit.getRepoLocation());
121
			IMetadataRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
156
			IMetadataRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
122
			if (repository != null && repository.isModifiable()) {
157
			if (repository != null && repository.isModifiable()) {
123
				if (toInit.getName() != null)
158
				if (toInit.getName() != null)
124
					repository.setName(toInit.getName());
159
					repository.setName(toInit.getName());
125
				if (!toInit.isAppend())
160
				if (repository instanceof CompositeMetadataRepository && !toInit.isAppend())
161
					((CompositeMetadataRepository) repository).removeAllChildren();
162
				else if (!toInit.isAppend())
126
					repository.removeAll();
163
					repository.removeAll();
127
				return repository;
164
				return repository;
128
			}
165
			}
Lines 149-161 Link Here
149
186
150
	private IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) throws ProvisionException {
187
	private IArtifactRepository initializeDestination(RepositoryDescriptor toInit, IArtifactRepositoryManager mgr) throws ProvisionException {
151
		try {
188
		try {
152
			if (mgr.contains(toInit.getRepoLocation()))
189
			if (!mgr.contains(toInit.getRepoLocation()))
153
				artifactReposToRemove.add(toInit.getRepoLocation());
190
				artifactReposToRemove.add(toInit.getRepoLocation());
154
			IArtifactRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
191
			IArtifactRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null);
155
			if (repository != null && repository.isModifiable()) {
192
			if (repository != null && repository.isModifiable()) {
156
				if (toInit.getName() != null)
193
				if (toInit.getName() != null)
157
					repository.setName(toInit.getName());
194
					repository.setName(toInit.getName());
158
				if (!toInit.isAppend())
195
				if (repository instanceof CompositeArtifactRepository && !toInit.isAppend())
196
					((CompositeArtifactRepository) repository).removeAllChildren();
197
				else if (!toInit.isAppend())
159
					repository.removeAll();
198
					repository.removeAll();
160
				return repository;
199
				return repository;
161
			}
200
			}
Lines 213-216 Link Here
213
	public void addDestination(RepositoryDescriptor descriptor) {
252
	public void addDestination(RepositoryDescriptor descriptor) {
214
		destinationRepos.add(descriptor);
253
		destinationRepos.add(descriptor);
215
	}
254
	}
255
256
	public void addSource(RepositoryDescriptor repo) {
257
		sourceRepositories.add(repo);
258
	}
216
}
259
}
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AbstractRepositoryTask.java (-45 / +45 lines)
Lines 12-23 Link Here
12
12
13
import java.io.File;
13
import java.io.File;
14
import java.net.URI;
14
import java.net.URI;
15
import java.net.URISyntaxException;
16
import java.util.*;
15
import java.util.*;
17
import org.apache.tools.ant.*;
16
import org.apache.tools.ant.*;
18
import org.apache.tools.ant.types.FileSet;
17
import org.apache.tools.ant.types.FileSet;
19
import org.eclipse.core.runtime.Path;
18
import org.eclipse.core.runtime.*;
20
import org.eclipse.core.runtime.URIUtil;
21
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
19
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
22
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
20
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
23
import org.eclipse.equinox.internal.provisional.p2.query.Query;
21
import org.eclipse.equinox.internal.provisional.p2.query.Query;
Lines 29-43 Link Here
29
	protected List sourceRepos = new ArrayList();
27
	protected List sourceRepos = new ArrayList();
30
	protected List destinations = new ArrayList();
28
	protected List destinations = new ArrayList();
31
29
32
	/*
33
	  * Create a special file set since the user specified a "source" sub-element.
34
	  */
35
	public FileSet createSource() {
36
		MyFileSet set = new MyFileSet();
37
		sourceRepos.add(set);
38
		return set;
39
	}
40
41
	protected void addMetadataSourceRepository(URI repoLocation) {
30
	protected void addMetadataSourceRepository(URI repoLocation) {
42
		application.addSourceMetadataRepository(repoLocation);
31
		application.addSourceMetadataRepository(repoLocation);
43
	}
32
	}
Lines 82-88 Link Here
82
		destinations.add(artifact);
71
		destinations.add(artifact);
83
	}
72
	}
84
73
85
	public DestinationRepository createDestination() {
74
	/*
75
	 * Add a repository to mirror into
76
	 */
77
	public DestinationRepository createRepository() {
86
		DestinationRepository destination = new DestinationRepository();
78
		DestinationRepository destination = new DestinationRepository();
87
		destinations.add(destination);
79
		destinations.add(destination);
88
		application.addDestination(destination.getDescriptor());
80
		application.addDestination(destination.getDescriptor());
Lines 90-106 Link Here
90
	}
82
	}
91
83
92
	/*
84
	/*
93
	 * New FileSet subclass which adds an optional "location" attribute.
85
	 * Add source repositories to mirror from
94
	 */
86
	 */
95
	public class MyFileSet extends FileSet {
87
	public void addConfiguredSource(RepositoryList sourceList) {
96
		String location;
88
		for (Iterator iter = sourceList.getRepositoryList().iterator(); iter.hasNext();) {
97
89
			DestinationRepository repo = (DestinationRepository) iter.next();
98
		public MyFileSet() {
90
			application.addSource(repo.getDescriptor());
99
			super();
100
		}
91
		}
101
92
102
		public void setLocation(String value) {
93
		for (Iterator iter = sourceList.getFileSetList().iterator(); iter.hasNext();) {
103
			this.location = value;
94
			FileSet fileSet = (FileSet) iter.next();
95
			sourceRepos.add(fileSet);
96
			// Added to the application later through prepareSourceRepos
104
		}
97
		}
105
	}
98
	}
106
99
Lines 112-144 Link Here
112
		if (sourceRepos == null || sourceRepos.isEmpty())
105
		if (sourceRepos == null || sourceRepos.isEmpty())
113
			return;
106
			return;
114
		for (Iterator iter = sourceRepos.iterator(); iter.hasNext();) {
107
		for (Iterator iter = sourceRepos.iterator(); iter.hasNext();) {
115
			Object next = iter.next();
108
			RepositoryFileSet fileset = (RepositoryFileSet) iter.next();
116
			if (next instanceof MyFileSet) {
109
117
				MyFileSet fileset = (MyFileSet) next;
110
			DirectoryScanner scanner = fileset.getDirectoryScanner(getProject());
118
				// determine if the user set a "location" attribute or used a fileset
111
			String[][] elements = new String[][] {scanner.getIncludedDirectories(), scanner.getIncludedFiles()};
119
				if (fileset.location == null) {
112
			for (int i = 0; i < 2; i++) {
120
					DirectoryScanner scanner = fileset.getDirectoryScanner(getProject());
113
				for (int j = 0; j < elements[i].length; j++) {
121
					String[][] elements = new String[][] {scanner.getIncludedDirectories(), scanner.getIncludedFiles()};
114
					File file = new File(fileset.getDir(), elements[i][j]);
122
					for (int i = 0; i < 2; i++) {
115
					URI uri = file.toURI();
123
						for (int j = 0; j < elements[i].length; j++) {
116
124
							File file = new File(fileset.getDir(), elements[i][j]);
117
					if (file.isFile() && file.getName().endsWith(".zip")) { //$NON-NLS-1$
125
							URI uri = file.toURI();
118
						uri = URIUtil.toJarURI(uri, null);
126
119
					}
127
							if (file.isFile() && file.getName().endsWith(".zip")) { //$NON-NLS-1$
120
					switch (fileset.getKind()) {
128
								try {
121
						case RepositoryFileSet.TYPE_BOTH :
129
									uri = new URI("jar:" + uri.toString() + "!/"); //$NON-NLS-1$ //$NON-NLS-2$
122
							application.addSourceArtifactRepository(uri);
130
								} catch (URISyntaxException e) {
123
							application.addSourceMetadataRepository(uri);
131
									//?
124
							break;
132
									continue;
125
						case RepositoryFileSet.TYPE_ARTIFACT :
133
								}
134
							}
135
							application.addSourceArtifactRepository(uri);
126
							application.addSourceArtifactRepository(uri);
127
							break;
128
						case RepositoryFileSet.TYPE_METADATA :
136
							application.addSourceMetadataRepository(uri);
129
							application.addSourceMetadataRepository(uri);
137
						}
130
							break;
131
						default :
132
							throw new BuildException("Unknown repository type for: " + uri);
138
					}
133
					}
139
				} else {
140
					application.addSourceArtifactRepository(fileset.location);
141
					application.addSourceMetadataRepository(fileset.location);
142
				}
134
				}
143
			}
135
			}
144
		}
136
		}
Lines 163-166 Link Here
163
		}
155
		}
164
		return result;
156
		return result;
165
	}
157
	}
158
159
	protected void log(IStatus status) {
160
		try {
161
			(new AntMirrorLog(this)).log(status);
162
		} catch (NoSuchMethodException e) {
163
			// Shouldn't occur
164
		}
165
	}
166
}
166
}
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/MirrorTask.java (-3 / +50 lines)
Lines 10-18 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.internal.repository.tools.tasks;
11
package org.eclipse.equinox.p2.internal.repository.tools.tasks;
12
12
13
import java.net.URISyntaxException;
13
import java.util.List;
14
import java.util.List;
14
import org.apache.tools.ant.BuildException;
15
import org.apache.tools.ant.BuildException;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.URIUtil;
16
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
18
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
17
import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication;
19
import org.eclipse.equinox.p2.internal.repository.tools.MirrorApplication;
18
20
Lines 27-39 Link Here
27
			prepareSourceRepos();
29
			prepareSourceRepos();
28
			application.initializeRepos(null);
30
			application.initializeRepos(null);
29
			List ius = prepareIUs();
31
			List ius = prepareIUs();
30
			if (ius == null || ius.size() == 0)
31
				throw new BuildException("Need to specify one or more IUs to mirror.");
32
			application.setSourceIUs(ius);
32
			application.setSourceIUs(ius);
33
			IStatus result = application.run(null);
33
			IStatus result = application.run(null);
34
			if (result.matches(IStatus.ERROR)) {
34
			if (result.matches(IStatus.ERROR)) {
35
				throw new BuildException(TaskHelper.statusToString(result, null).toString());
35
				throw new BuildException(TaskHelper.statusToString(result, null).toString());
36
			}
36
			} else if (!result.isOK())
37
				log(result);
37
		} catch (ProvisionException e) {
38
		} catch (ProvisionException e) {
38
			throw new BuildException(e);
39
			throw new BuildException(e);
39
		}
40
		}
Lines 44-47 Link Here
44
		((MirrorApplication) application).setSlicingOptions(options.getOptions());
45
		((MirrorApplication) application).setSlicingOptions(options.getOptions());
45
		return options;
46
		return options;
46
	}
47
	}
48
49
	/*
50
	 * Set the location of the baseline repository. (used in comparison)
51
	 */
52
	public void setBaseline(String value) {
53
		try {
54
			((MirrorApplication) application).setBaseline(URIUtil.fromString(value));
55
		} catch (URISyntaxException e) {
56
			throw new BuildException(e);
57
		}
58
	}
59
60
	/*
61
	 * Set the identifier of the comparator to use.
62
	 */
63
	public void setComparatorID(String value) {
64
		((MirrorApplication) application).setComparatorID(value);
65
	}
66
67
	/*
68
	 * Set whether or not the application should be calling a comparator when mirroring.
69
	 */
70
	public void setCompare(boolean value) {
71
		((MirrorApplication) application).setCompare(value);
72
	}
73
74
	/*
75
	 * Set whether or not we should ignore errors when running the mirror application.
76
	 */
77
	public void setIgnoreErrors(boolean value) {
78
		((MirrorApplication) application).setIgnoreErrors(value);
79
	}
80
81
	/*
82
	 * Set whether or not the the artifacts are raw.
83
	 */
84
	public void setRaw(boolean value) {
85
		((MirrorApplication) application).setRaw(value);
86
	}
87
88
	/*
89
	 * Set whether or not the mirror application should be run in verbose mode.
90
	 */
91
	public void setVerbose(boolean value) {
92
		((MirrorApplication) application).setVerbose(value);
93
	}
47
}
94
}
(-)plugin.xml (+12 lines)
Lines 15-20 Link Here
15
            library="lib/repository-tools-ant.jar"
15
            library="lib/repository-tools-ant.jar"
16
            name="p2.mirror">
16
            name="p2.mirror">
17
      </antTask>
17
      </antTask>
18
19
     <antTask
20
            class="org.eclipse.equinox.p2.internal.repository.tools.tasks.ModifyRepositoryChildrenTask"
21
            library="lib/repository-tools-ant.jar"
22
            name="p2.modify.composite.repository.children">
23
      </antTask>
24
25
     <antTask
26
            class="org.eclipse.equinox.p2.internal.repository.tools.tasks.CreateCompositeRepositoryTask"
27
            library="lib/repository-tools-ant.jar"
28
            name="p2.create.composite.repository">
29
      </antTask>
18
      
30
      
19
      <antTask
31
      <antTask
20
			library="lib/repository-tools-ant.jar"
32
			library="lib/repository-tools-ant.jar"
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/AntMirrorLog.java (+104 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.internal.repository.tools.tasks;
12
13
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.Method;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.equinox.internal.p2.artifact.repository.Messages;
17
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactDescriptor;
18
19
public class AntMirrorLog {
20
21
	private boolean consoleMessage = false;
22
	private Method log;
23
	private Object task;
24
25
	public AntMirrorLog(Object task) throws NoSuchMethodException {
26
		this.task = task;
27
		try {
28
			log = task.getClass().getMethod("log", new Class[] {String.class, int.class}); //$NON-NLS-1$
29
		} catch (SecurityException e) {
30
			exceptionOccurred(null, e);
31
		}
32
	}
33
34
	public void log(IArtifactDescriptor descriptor, IStatus status) {
35
		log(descriptor.toString(), status.getSeverity());
36
		log(status);
37
	}
38
39
	public void log(IStatus status) {
40
		int severity = status.getSeverity();
41
		// Log the status message
42
		log(status.getMessage(), severity);
43
		// Log the exception if applicable
44
		if (status.getException() != null)
45
			log(status.getException().getMessage(), severity);
46
47
		// Log any children of this status
48
		IStatus[] nestedStatus = status.getChildren();
49
		if (nestedStatus != null)
50
			for (int i = 0; i < nestedStatus.length; i++)
51
				log(nestedStatus[i]);
52
	}
53
54
	public void close() {
55
		// nothing to do here
56
	}
57
58
	/*
59
	 * Log a message to the Ant Task
60
	 */
61
	private void log(String message, int statusSeverity) {
62
		try {
63
			log.invoke(task, new Object[] {message, new Integer(mapLogLevels(statusSeverity))});
64
		} catch (IllegalArgumentException e) {
65
			exceptionOccurred(message, e);
66
		} catch (IllegalAccessException e) {
67
			exceptionOccurred(message, e);
68
		} catch (InvocationTargetException e) {
69
			exceptionOccurred(message, e);
70
		}
71
	}
72
73
	/*
74
	 * Show an error message if this the first time, and print status messages.
75
	 */
76
	private void exceptionOccurred(String message, Exception e) {
77
		if (!consoleMessage) {
78
			System.err.println(Messages.MirrorLog_Exception_Occurred);
79
			e.printStackTrace(System.err);
80
			System.err.println(Messages.MirrorLog_Console_Log);
81
			consoleMessage = true;
82
		}
83
		if (message != null)
84
			System.out.println(message);
85
	}
86
87
	/**
88
	 * Copied from AntLogAdapter in pde build.
89
	 */
90
	private int mapLogLevels(int iStatusLevel) {
91
		switch (iStatusLevel) {
92
			case IStatus.ERROR :
93
				return 0;
94
			case IStatus.OK :
95
				return 2;
96
			case IStatus.INFO :
97
				return 2;
98
			case IStatus.WARNING :
99
				return 1;
100
			default :
101
				return 1;
102
		}
103
	}
104
}
(-)src/org/eclipse/equinox/p2/internal/repository/tools/ModifyCompositeRepositoryApplication.java (+74 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.internal.repository.tools;
12
13
import java.util.*;
14
import org.eclipse.core.runtime.*;
15
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
16
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository;
17
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
18
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
19
20
public class ModifyCompositeRepositoryApplication extends AbstractApplication {
21
	private List childrenToAdd = new ArrayList();
22
	private List childrenToRemove = new ArrayList();
23
24
	public IStatus run(IProgressMonitor monitor) throws ProvisionException {
25
26
		try {
27
			initializeRepos(new NullProgressMonitor());
28
			// load repository
29
			CompositeMetadataRepository metadataRepo = (CompositeMetadataRepository) destinationMetadataRepository;
30
			CompositeArtifactRepository artifactRepo = (CompositeArtifactRepository) destinationArtifactRepository;
31
32
			// Remove children from the Composite Repositories
33
			for (Iterator iterator = childrenToRemove.iterator(); iterator.hasNext();) {
34
				RepositoryDescriptor child = (RepositoryDescriptor) iterator.next();
35
				if (child.getKind() == IRepository.TYPE_ARTIFACT)
36
					artifactRepo.removeChild(child.getRepoLocation());
37
				else if (child.getKind() == IRepository.TYPE_METADATA)
38
					metadataRepo.removeChild(child.getRepoLocation());
39
				else if (child.getKind() == RepositoryDescriptor.TYPE_BOTH) {
40
					artifactRepo.removeChild(child.getRepoLocation());
41
					metadataRepo.removeChild(child.getRepoLocation());
42
				}
43
			}
44
45
			// Add children to the Composite Repositories
46
			for (Iterator iterator = childrenToAdd.iterator(); iterator.hasNext();) {
47
				RepositoryDescriptor child = (RepositoryDescriptor) iterator.next();
48
				if (child.getKind() == IRepository.TYPE_ARTIFACT)
49
					artifactRepo.addChild(child.getRepoLocation());
50
				else if (child.getKind() == IRepository.TYPE_METADATA)
51
					metadataRepo.addChild(child.getRepoLocation());
52
				else if (child.getKind() == RepositoryDescriptor.TYPE_BOTH) {
53
					artifactRepo.addChild(child.getRepoLocation());
54
					metadataRepo.addChild(child.getRepoLocation());
55
				}
56
			}
57
			return Status.OK_STATUS;
58
		} finally {
59
			finalizeRepositories();
60
		}
61
	}
62
63
	public void setRemoveUnknownRepositories(boolean value) {
64
		removeUnknownRepositories = value;
65
	}
66
67
	public void addChild(RepositoryDescriptor child) {
68
		childrenToAdd.add(child);
69
	}
70
71
	public void removeChild(RepositoryDescriptor child) {
72
		childrenToRemove.add(child);
73
	}
74
}
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/CreateCompositeRepositoryTask.java (+69 lines)
Added Link Here
1
package org.eclipse.equinox.p2.internal.repository.tools.tasks;
2
3
import java.util.Iterator;
4
import org.apache.tools.ant.BuildException;
5
import org.apache.tools.ant.Task;
6
import org.eclipse.core.runtime.IStatus;
7
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
8
import org.eclipse.equinox.p2.internal.repository.tools.CreateCompositeRepositoryApplication;
9
import org.eclipse.equinox.p2.internal.repository.tools.ModifyCompositeRepositoryApplication;
10
11
public class CreateCompositeRepositoryTask extends Task {
12
	CreateCompositeRepositoryApplication createApp;
13
	ModifyCompositeRepositoryApplication modifyApp;
14
	boolean add = false;
15
16
	public CreateCompositeRepositoryTask() {
17
		createApp = new CreateCompositeRepositoryApplication();
18
		modifyApp = new ModifyCompositeRepositoryApplication();
19
		modifyApp.setRemoveUnknownRepositories(false);
20
	}
21
22
	/* (non-Javadoc)
23
	 * @see org.apache.tools.ant.Task#execute()
24
	 */
25
	public void execute() throws BuildException {
26
		try {
27
			IStatus result = createApp.run(null);
28
			if (result.matches(IStatus.ERROR)) {
29
				throw new BuildException(TaskHelper.statusToString(result, null).toString());
30
			}
31
			if (add) {
32
				result = modifyApp.run(null);
33
				if (result.matches(IStatus.ERROR)) {
34
					throw new BuildException(TaskHelper.statusToString(result, null).toString());
35
				}
36
			}
37
		} catch (ProvisionException e) {
38
			throw new BuildException(e);
39
		}
40
	}
41
42
	/*
43
	 * Add a repository to create
44
	 */
45
	public DestinationRepository createRepository() {
46
		DestinationRepository repo = new DestinationRepository();
47
		createApp.addRepository(repo.getDescriptor());
48
		modifyApp.addDestination(repo.getDescriptor());
49
		return repo;
50
	}
51
52
	/*
53
	 * Set whether the task should fail if the repository already exists
54
	 */
55
	public void setFailOnExists(boolean value) {
56
		createApp.setFailOnExists(value);
57
	}
58
59
	/*
60
	 * Add a list of child repositories to add to the newly created repository
61
	 */
62
	public void addConfiguredAdd(RepositoryList addList) {
63
		add = true;
64
		for (Iterator iter = addList.getRepositoryList().iterator(); iter.hasNext();) {
65
			DestinationRepository repo = (DestinationRepository) iter.next();
66
			modifyApp.addChild(repo.getDescriptor());
67
		}
68
	}
69
}
(-)src/org/eclipse/equinox/p2/internal/repository/tools/CreateCompositeRepositoryApplication.java (+172 lines)
Added Link Here
1
package org.eclipse.equinox.p2.internal.repository.tools;
2
3
import java.net.URISyntaxException;
4
import java.util.*;
5
import org.apache.tools.ant.BuildException;
6
import org.eclipse.core.runtime.*;
7
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository;
8
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
9
import org.eclipse.equinox.internal.p2.metadata.repository.Activator;
10
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository;
11
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
12
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
13
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
14
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
15
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
16
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager;
17
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
18
19
public class CreateCompositeRepositoryApplication {
20
21
	private String artifactName = "Composite Artifact Repository";
22
	private String metadataName = "Composite Artifact Repository";
23
	private List repositories = new ArrayList();
24
	private boolean failOnExists = false;
25
	private IArtifactRepositoryManager artifactManager;
26
	private IMetadataRepositoryManager metadataManager;
27
28
	public IStatus run(IProgressMonitor monitor) throws ProvisionException {
29
30
		MultiStatus status = new MultiStatus(Activator.ID, 0, "", null); //$NON-NLS-1$
31
		status.add(Status.OK_STATUS);
32
		for (Iterator iterator = repositories.iterator(); iterator.hasNext();)
33
			status.add(createRepository((RepositoryDescriptor) iterator.next()));
34
35
		return status;
36
	}
37
38
	public void addRepository(RepositoryDescriptor repo) {
39
		repositories.add(repo);
40
	}
41
42
	public void setFailOnExists(boolean value) {
43
		failOnExists = value;
44
	}
45
46
	private IStatus createRepository(RepositoryDescriptor repo) throws ProvisionException {
47
		try {
48
			if (repo.getKind() == IRepository.TYPE_ARTIFACT)
49
				return createArtifactRepository(repo);
50
			else if (repo.getKind() == IRepository.TYPE_METADATA)
51
				return createMetadataRepository(repo);
52
			else if (repo.getKind() == RepositoryDescriptor.TYPE_BOTH) {
53
				MultiStatus status = new MultiStatus(Activator.ID, 0, "", null); //$NON-NLS-1$
54
				status.add(createArtifactRepository(repo));
55
				status.add(createMetadataRepository(repo));
56
				return status;
57
			} else
58
				throw new ProvisionException("Repository is of an unknown kind: " + repo.getRepoLocation());
59
		} catch (IllegalStateException e) {
60
			throw new ProvisionException(e.getMessage(), e);
61
		}
62
	}
63
64
	private IStatus createArtifactRepository(RepositoryDescriptor repo) throws ProvisionException {
65
		if (artifactManager == null) {
66
			artifactManager = (IArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.class.getName());
67
			if (artifactManager == null)
68
				throw new ProvisionException("Unable to obtain metadata repository manager.");
69
		}
70
71
		boolean repoKnown = artifactManager.contains(repo.getRepoLocation());
72
73
		// remove the repo first.
74
		artifactManager.removeRepository(repo.getRepoLocation());
75
76
		// first try and load to see if one already exists at that location.
77
		// if we have an already existing repository at that location, then throw an error
78
		// if the user told us to
79
		try {
80
			IArtifactRepository repository = artifactManager.loadRepository(repo.getRepoLocation(), null);
81
			if (repository instanceof CompositeArtifactRepository) {
82
				if (failOnExists)
83
					throw new BuildException("Composite repository already exists at location: " + repo.getRepoLocation());
84
				return new Status(IStatus.INFO, Activator.ID, "Composite repository already exists at location: " + repo.getRepoLocation());
85
			} else {
86
				// we have a non-composite repo at this location. that is ok because we can co-exist.
87
			}
88
		} catch (ProvisionException e) {
89
			// re-throw the exception if we got anything other than "repo not found"
90
			if (e.getStatus().getCode() != ProvisionException.REPOSITORY_NOT_FOUND)
91
				throw e;
92
		}
93
94
		IArtifactRepository source = null;
95
		try {
96
			if (repo.getFormat() != null)
97
				source = artifactManager.loadRepository(URIUtil.fromString(repo.getFormat()), 0, null);
98
		} catch (ProvisionException e) {
99
			//Ignore.
100
		} catch (URISyntaxException e) {
101
			//Ignore
102
		}
103
		//This code assumes source has been successfully loaded before this point
104
		//No existing repository; create a new repository at destinationLocation but with source's attributes.
105
		// TODO for now create a Simple repo by default.
106
107
		try {
108
			IArtifactRepository result = null;
109
			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));
110
111
			if (repo.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED))
112
				result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$
113
		} catch (IllegalStateException e) {
114
			artifactManager.removeRepository(repo.getRepoLocation());
115
			throw e;
116
		}
117
		return Status.OK_STATUS;
118
	}
119
120
	private IStatus createMetadataRepository(RepositoryDescriptor repo) throws ProvisionException {
121
		if (metadataManager == null) {
122
			metadataManager = (IMetadataRepositoryManager) ServiceHelper.getService(Activator.getContext(), IMetadataRepositoryManager.class.getName());
123
			if (metadataManager == null)
124
				throw new ProvisionException("Unable to obtain metadata repository manager.");
125
		}
126
127
		boolean repoKnown = metadataManager.contains(repo.getRepoLocation());
128
		// remove the repo first.
129
		metadataManager.removeRepository(repo.getRepoLocation());
130
131
		// first try and load to see if one already exists at that location.
132
		// if we have an already existing repository at that location, then throw an error
133
		// if the user told us to
134
		try {
135
			IMetadataRepository repository = metadataManager.loadRepository(repo.getRepoLocation(), null);
136
			if (repository instanceof CompositeMetadataRepository) {
137
				if (failOnExists)
138
					throw new BuildException("Composite repository already exists at location: " + repo.getRepoLocation());
139
				RepositoryHelper.validDestinationRepository(repository);
140
				return new Status(IStatus.INFO, Activator.ID, "Composite repository already exists at location: " + repo.getRepoLocation());
141
			} else {
142
				// we have a non-composite repo at this location. that is ok because we can co-exist.
143
			}
144
		} catch (ProvisionException e) {
145
			// re-throw the exception if we got anything other than "repo not found"
146
			if (e.getStatus().getCode() != ProvisionException.REPOSITORY_NOT_FOUND)
147
				throw e;
148
		}
149
150
		IMetadataRepository source = null;
151
		try {
152
			if (repo.getFormat() != null)
153
				source = metadataManager.loadRepository(URIUtil.fromString(repo.getFormat()), 0, null);
154
		} catch (ProvisionException e) {
155
			//Ignore.
156
		} catch (URISyntaxException e) {
157
			//Ignore
158
		}
159
		//This code assumes source has been successfully loaded before this point
160
		//No existing repository; create a new repository at destinationLocation but with source's attributes.
161
		try {
162
			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));
163
			if (repo.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED))
164
				result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$
165
		} catch (IllegalStateException e) {
166
			metadataManager.removeRepository(repo.getRepoLocation());
167
			throw e;
168
		}
169
170
		return Status.OK_STATUS;
171
	}
172
}
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryFileSet.java (+26 lines)
Added Link Here
1
package org.eclipse.equinox.p2.internal.repository.tools.tasks;
2
3
import org.apache.tools.ant.types.FileSet;
4
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
5
import org.eclipse.equinox.p2.internal.repository.tools.RepositoryDescriptor;
6
7
public class RepositoryFileSet extends FileSet {
8
	public final static int TYPE_BOTH = RepositoryDescriptor.TYPE_BOTH;
9
	public final static int TYPE_ARTIFACT = IRepository.TYPE_ARTIFACT;
10
	public final static int TYPE_METADATA = IRepository.TYPE_METADATA;
11
12
	int kind = TYPE_BOTH;
13
14
	public void setKind(String repoKind) {
15
		if (repoKind.startsWith("m") || repoKind.startsWith("M")) //$NON-NLS-1$//$NON-NLS-2$
16
			kind = IRepository.TYPE_METADATA;
17
18
		if (repoKind.startsWith("a") || repoKind.startsWith("A")) //$NON-NLS-1$//$NON-NLS-2$
19
			kind = IRepository.TYPE_ARTIFACT;
20
	}
21
22
	public int getKind() {
23
		return kind;
24
	}
25
26
}
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/RepositoryList.java (+40 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.internal.repository.tools.tasks;
12
13
import java.util.ArrayList;
14
import java.util.List;
15
import org.apache.tools.ant.types.DataType;
16
17
public class RepositoryList extends DataType {
18
	List repositories = new ArrayList();
19
	List sourceFileSets = new ArrayList();
20
21
	public DestinationRepository createRepository() {
22
		DestinationRepository repo = new DestinationRepository();
23
		repositories.add(repo);
24
		return repo;
25
	}
26
27
	public RepositoryFileSet createFileSet() {
28
		RepositoryFileSet fileSet = new RepositoryFileSet();
29
		sourceFileSets.add(fileSet);
30
		return fileSet;
31
	}
32
33
	public List getRepositoryList() {
34
		return repositories;
35
	}
36
37
	public List getFileSetList() {
38
		return sourceFileSets;
39
	}
40
}
(-)src_ant/org/eclipse/equinox/p2/internal/repository/tools/tasks/ModifyRepositoryChildrenTask.java (+58 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.internal.repository.tools.tasks;
12
13
import java.util.Iterator;
14
import org.apache.tools.ant.BuildException;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
17
import org.eclipse.equinox.p2.internal.repository.tools.ModifyCompositeRepositoryApplication;
18
19
public class ModifyRepositoryChildrenTask extends AbstractRepositoryTask {
20
21
	public ModifyRepositoryChildrenTask() {
22
		application = new ModifyCompositeRepositoryApplication();
23
	}
24
25
	/* (non-Javadoc)
26
	 * @see org.apache.tools.ant.Task#execute()
27
	 */
28
	public void execute() throws BuildException {
29
		try {
30
			IStatus result = application.run(null);
31
			if (result.matches(IStatus.ERROR)) {
32
				throw new BuildException(TaskHelper.statusToString(result, null).toString());
33
			}
34
		} catch (ProvisionException e) {
35
			throw new BuildException(e);
36
		}
37
	}
38
39
	/*
40
	 * Add the listed repositories to the composite repository
41
	 */
42
	public void addConfiguredAdd(RepositoryList list) {
43
		for (Iterator iter = list.getRepositoryList().iterator(); iter.hasNext();) {
44
			DestinationRepository repo = (DestinationRepository) iter.next();
45
			((ModifyCompositeRepositoryApplication) application).addChild(repo.getDescriptor());
46
		}
47
	}
48
49
	/*	
50
	 * Remove the listed repositories from the composite repository
51
	 */
52
	public void addConfiguredRemove(RepositoryList list) {
53
		for (Iterator iter = list.getRepositoryList().iterator(); iter.hasNext();) {
54
			DestinationRepository repo = (DestinationRepository) iter.next();
55
			((ModifyCompositeRepositoryApplication) application).removeChild(repo.getDescriptor());
56
		}
57
	}
58
}
(-)src/org/eclipse/equinox/internal/p2/repository/helpers/Messages.java (+1 lines)
Lines 31-35 Link Here
31
	public static String repoMan_internalError;
31
	public static String repoMan_internalError;
32
	public static String repoMan_notExists;
32
	public static String repoMan_notExists;
33
	public static String repoMan_unknownType;
33
	public static String repoMan_unknownType;
34
	public static String DestinationNotModifiable;
34
35
35
}
36
}
(-)src/org/eclipse/equinox/internal/p2/repository/helpers/messages.properties (+1 lines)
Lines 15-17 Link Here
15
repoMan_internalError=Internal error.
15
repoMan_internalError=Internal error.
16
repoMan_notExists=No repository found at {0}.
16
repoMan_notExists=No repository found at {0}.
17
repoMan_unknownType=Unknown repository type at {0}.
17
repoMan_unknownType=Unknown repository type at {0}.
18
DestinationNotModifiable=Destination repository is not modifiable: {0}
(-)src/org/eclipse/equinox/internal/p2/repository/helpers/RepositoryHelper.java (+51 lines)
Added Link Here
1
package org.eclipse.equinox.internal.p2.repository.helpers;
2
3
import java.io.File;
4
import java.net.URI;
5
import org.eclipse.core.runtime.URIUtil;
6
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
7
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
8
import org.eclipse.osgi.util.NLS;
9
10
public class RepositoryHelper {
11
	protected static final String FILE_SCHEME = "file"; //$NON-NLS-1$
12
13
	/**
14
	 * If the provided URI can be interpreted as representing a local address (no schema, or one letter schema) 
15
	 * but is missing the file schema, a new URI is created which represents the local file. 
16
	 * 
17
	 * @param location the URI to convert
18
	 * @return the converted URI, or the original
19
	 */
20
	public static URI localRepoURIHelper(URI location) {
21
		if (location == null)
22
			return null;
23
		if (location.getScheme() == null)
24
			// Probably a local path:  /home/user/repo
25
			location = (new File(location.getPath())).getAbsoluteFile().toURI();
26
		else if (location.getScheme().length() == 1)
27
			// Probably a windows path:  C:\repo
28
			location = (new File(URIUtil.toUnencodedString(location))).toURI();
29
		else if (!FILE_SCHEME.equalsIgnoreCase(location.getScheme()))
30
			// This else must occur last!
31
			return location;
32
33
		// Zipped repository?
34
		String lowerCase = location.toString().toLowerCase();
35
		if (lowerCase.endsWith(".jar") || lowerCase.endsWith(".zip")) //$NON-NLS-1$//$NON-NLS-2$
36
			return URIUtil.toJarURI(location, null);
37
		return location;
38
	}
39
40
	/**
41
	 * Determine if the repository could be used as a valid destination (eg, it is modifiable)
42
	 * @param repository the repository to test
43
	 * @return the repository
44
	 * @throws ProvisionException if the repository is not valid
45
	 */
46
	public static IRepository validDestinationRepository(IRepository repository) {
47
		if (!repository.isModifiable())
48
			throw new IllegalStateException(NLS.bind(Messages.DestinationNotModifiable, repository.getLocation()));
49
		return repository;
50
	}
51
}

Return to bug 265550