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 264389 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java (-3 / +24 lines)
Lines 39-44 Link Here
39
	private SiteCategory defaultCategory;
39
	private SiteCategory defaultCategory;
40
	private HashSet defaultCategorySet;
40
	private HashSet defaultCategorySet;
41
	private URI location;
41
	private URI location;
42
	private String categoryQualifier = null;
42
43
43
	public SiteXMLAction(URI location) {
44
	public SiteXMLAction(URI location) {
44
		this.location = location;
45
		this.location = location;
Lines 48-53 Link Here
48
		this.updateSite = updateSite;
49
		this.updateSite = updateSite;
49
	}
50
	}
50
51
52
	/**
53
	 * Sets the qualifier that will be prepended to the front of category names
54
	 */
55
	public void setCategoryQualifier(String categoryQualifier) {
56
		this.categoryQualifier = categoryQualifier;
57
	}
58
51
	private void initialize() {
59
	private void initialize() {
52
		if (defaultCategory != null)
60
		if (defaultCategory != null)
53
			return;
61
			return;
Lines 236-242 Link Here
236
	protected void generateCategoryIUs(Map categoriesToFeatures, IPublisherResult result) {
244
	protected void generateCategoryIUs(Map categoriesToFeatures, IPublisherResult result) {
237
		for (Iterator it = categoriesToFeatures.keySet().iterator(); it.hasNext();) {
245
		for (Iterator it = categoriesToFeatures.keySet().iterator(); it.hasNext();) {
238
			SiteCategory category = (SiteCategory) it.next();
246
			SiteCategory category = (SiteCategory) it.next();
239
			result.addIU(createCategoryIU(category, (Set) categoriesToFeatures.get(category), null), IPublisherResult.NON_ROOT);
247
			String qualifier = createQualifier();
248
			result.addIU(createCategoryIU(category, (Set) categoriesToFeatures.get(category), null, qualifier), IPublisherResult.NON_ROOT);
240
		}
249
		}
241
	}
250
	}
242
251
Lines 247-256 Link Here
247
	 * @param parentCategory The parent category, or <code>null</code>
256
	 * @param parentCategory The parent category, or <code>null</code>
248
	 * @return an IU representing the category
257
	 * @return an IU representing the category
249
	 */
258
	 */
250
	public static IInstallableUnit createCategoryIU(SiteCategory category, Set featureIUs, IInstallableUnit parentCategory) {
259
	public static IInstallableUnit createCategoryIU(SiteCategory category, Set featureIUs, IInstallableUnit parentCategory, String categoryQualifier) {
251
		InstallableUnitDescription cat = new MetadataFactory.InstallableUnitDescription();
260
		InstallableUnitDescription cat = new MetadataFactory.InstallableUnitDescription();
252
		cat.setSingleton(true);
261
		cat.setSingleton(true);
253
		String categoryId = category.getName();
262
		String categoryId = categoryQualifier + category.getName();
254
		cat.setId(categoryId);
263
		cat.setId(categoryId);
255
		cat.setVersion(Version.emptyVersion);
264
		cat.setVersion(Version.emptyVersion);
256
		cat.setProperty(IInstallableUnit.PROP_NAME, category.getLabel());
265
		cat.setProperty(IInstallableUnit.PROP_NAME, category.getLabel());
Lines 293-296 Link Here
293
		return MetadataFactory.createInstallableUnit(cat);
302
		return MetadataFactory.createInstallableUnit(cat);
294
	}
303
	}
295
304
305
	/**
306
	 * Creates a qualifier that can be prepended to a category to the category is unique
307
	 * between multiple repositories
308
	 */
309
	private String createQualifier() {
310
		if (categoryQualifier != null)
311
			return categoryQualifier;
312
		if (updateSite != null)
313
			return URIUtil.toUnencodedString(updateSite.getLocation()) + "."; //$NON-NLS-1$
314
		return ""; //$NON-NLS-1$
315
	}
316
296
}
317
}
(-)src/org/eclipse/equinox/internal/p2/updatesite/RemoteUpdateSiteAction.java (-17 / +1 lines)
Lines 10-17 Link Here
10
 ******************************************************************************/
10
 ******************************************************************************/
11
package org.eclipse.equinox.internal.p2.updatesite;
11
package org.eclipse.equinox.internal.p2.updatesite;
12
12
13
import java.net.URI;
14
import java.net.URISyntaxException;
15
import java.util.ArrayList;
13
import java.util.ArrayList;
16
import org.eclipse.core.runtime.*;
14
import org.eclipse.core.runtime.*;
17
import org.eclipse.equinox.p2.publisher.*;
15
import org.eclipse.equinox.p2.publisher.*;
Lines 30-39 Link Here
30
		this.updateSite = updateSite;
28
		this.updateSite = updateSite;
31
	}
29
	}
32
30
33
	public RemoteUpdateSiteAction(String source) {
34
		this.source = source;
35
	}
36
37
	public IStatus perform(IPublisherInfo info, IPublisherResult results, IProgressMonitor monitor) {
31
	public IStatus perform(IPublisherInfo info, IPublisherResult results, IProgressMonitor monitor) {
38
		IPublisherAction[] actions = createActions();
32
		IPublisherAction[] actions = createActions();
39
		MultiStatus finalStatus = new MultiStatus(this.getClass().getName(), 0, NLS.bind(Messages.Error_Generation, source != null ? source : (updateSite != null ? updateSite.getLocation().toString() : "Unknown")), null); //$NON-NLS-1$
33
		MultiStatus finalStatus = new MultiStatus(this.getClass().getName(), 0, NLS.bind(Messages.Error_Generation, source != null ? source : (updateSite != null ? updateSite.getLocation().toString() : "Unknown")), null); //$NON-NLS-1$
Lines 55-70 Link Here
55
	}
49
	}
56
50
57
	private IPublisherAction createSiteXMLAction() {
51
	private IPublisherAction createSiteXMLAction() {
58
		if (updateSite != null)
52
		return new SiteXMLAction(updateSite);
59
			return new SiteXMLAction(updateSite);
60
		if (source != null) {
61
			try {
62
				return new SiteXMLAction(new URI(source + "/site.xml")); //$NON-NLS-1$
63
			} catch (URISyntaxException e) {
64
				// never happens
65
				return null;
66
			}
67
		}
68
		return null;
69
	}
53
	}
70
}
54
}
(-)src/org/eclipse/equinox/internal/p2/updatesite/LocalUpdateSiteAction.java (-3 / +16 lines)
Lines 26-37 Link Here
26
public class LocalUpdateSiteAction implements IPublisherAction {
26
public class LocalUpdateSiteAction implements IPublisherAction {
27
	protected String source;
27
	protected String source;
28
	private UpdateSite updateSite;
28
	private UpdateSite updateSite;
29
	private String categoryQualifier;
29
30
30
	protected LocalUpdateSiteAction() {
31
	protected LocalUpdateSiteAction() {
32
		// empty
31
	}
33
	}
32
34
33
	public LocalUpdateSiteAction(String source) {
35
	/**
36
	 * Creates a local updatesite publisher action.
37
	 * @param source The location of the directory that contains the site.xml file
38
	 * @param categoryQualifier The qualifier to prepend to categories. This qualifier is used
39
	 * to ensure tha the category IDs are unique between update sites.
40
	 */
41
	public LocalUpdateSiteAction(String source, String categoryQualifier) {
34
		this.source = source;
42
		this.source = source;
43
		this.categoryQualifier = categoryQualifier;
35
	}
44
	}
36
45
37
	public LocalUpdateSiteAction(UpdateSite updateSite) {
46
	public LocalUpdateSiteAction(UpdateSite updateSite) {
Lines 64-71 Link Here
64
	private IPublisherAction createSiteXMLAction() {
73
	private IPublisherAction createSiteXMLAction() {
65
		if (updateSite != null)
74
		if (updateSite != null)
66
			return new SiteXMLAction(updateSite);
75
			return new SiteXMLAction(updateSite);
67
		if (source != null)
76
		if (source != null) {
68
			return new SiteXMLAction(new File(source, "site.xml").toURI()); //$NON-NLS-1$
77
			SiteXMLAction siteXmlAction = new SiteXMLAction(new File(source, "site.xml").toURI()); //$NON-NLS-1$
78
			if (categoryQualifier != null)
79
				siteXmlAction.setCategoryQualifier(categoryQualifier);
80
			return siteXmlAction;
81
		}
69
		return null;
82
		return null;
70
	}
83
	}
71
84
(-)src/org/eclipse/equinox/internal/p2/updatesite/UpdatesitePublisherApplication.java (-3 / +13 lines)
Lines 9-16 Link Here
9
 ******************************************************************************/
9
 ******************************************************************************/
10
package org.eclipse.equinox.internal.p2.updatesite;
10
package org.eclipse.equinox.internal.p2.updatesite;
11
11
12
import org.eclipse.equinox.p2.publisher.AbstractPublisherApplication;
12
import java.net.URISyntaxException;
13
import org.eclipse.equinox.p2.publisher.IPublisherAction;
13
import org.eclipse.equinox.p2.publisher.*;
14
14
15
/**
15
/**
16
 * <p>
16
 * <p>
Lines 20-30 Link Here
20
 */
20
 */
21
public class UpdatesitePublisherApplication extends AbstractPublisherApplication {
21
public class UpdatesitePublisherApplication extends AbstractPublisherApplication {
22
22
23
	private String categoryQualifier = null;
24
23
	public UpdatesitePublisherApplication() {
25
	public UpdatesitePublisherApplication() {
24
		// nothing todo
26
		// nothing todo
25
	}
27
	}
26
28
29
	protected void processParameter(String arg, String parameter, PublisherInfo pinfo) throws URISyntaxException {
30
		super.processParameter(arg, parameter, pinfo);
31
32
		if (arg.equalsIgnoreCase("-categoryQualifier")) //$NON-NLS-1$
33
			categoryQualifier = parameter;
34
35
	}
36
27
	protected IPublisherAction[] createActions() {
37
	protected IPublisherAction[] createActions() {
28
		return new IPublisherAction[] {new LocalUpdateSiteAction(source)};
38
		return new IPublisherAction[] {new LocalUpdateSiteAction(source, categoryQualifier)};
29
	}
39
	}
30
}
40
}
(-)src/org/eclipse/equinox/p2/tests/updatesite/AllTests.java (+1 lines)
Lines 21-26 Link Here
21
		TestSuite suite = new TestSuite(AllTests.class.getName());
21
		TestSuite suite = new TestSuite(AllTests.class.getName());
22
		suite.addTestSuite(SiteXMLActionTest.class);
22
		suite.addTestSuite(SiteXMLActionTest.class);
23
		suite.addTestSuite(UpdateSiteTest.class);
23
		suite.addTestSuite(UpdateSiteTest.class);
24
		suite.addTestSuite(LocalUpdatesiteTest.class);
24
		return suite;
25
		return suite;
25
	}
26
	}
26
27
(-)src/org/eclipse/equinox/p2/tests/updatesite/SiteXMLActionTest.java (-3 / +26 lines)
Lines 10-23 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.equinox.p2.tests.updatesite;
11
package org.eclipse.equinox.p2.tests.updatesite;
12
12
13
import java.io.File;
13
import java.net.URI;
14
import java.net.URI;
14
import java.util.Collection;
15
import java.util.Collection;
15
import java.util.Iterator;
16
import java.util.Iterator;
17
import org.eclipse.core.runtime.NullProgressMonitor;
18
import org.eclipse.core.runtime.URIUtil;
16
import org.eclipse.equinox.internal.p2.updatesite.SiteXMLAction;
19
import org.eclipse.equinox.internal.p2.updatesite.SiteXMLAction;
17
import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository;
20
import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepository;
18
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
21
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
22
import org.eclipse.equinox.internal.provisional.p2.metadata.query.IUPropertyQuery;
23
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
24
import org.eclipse.equinox.internal.provisional.p2.query.Query;
19
import org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository.RepositoryReference;
25
import org.eclipse.equinox.internal.provisional.spi.p2.metadata.repository.RepositoryReference;
20
import org.eclipse.equinox.p2.publisher.*;
26
import org.eclipse.equinox.p2.publisher.*;
27
import org.eclipse.equinox.p2.publisher.eclipse.FeaturesAction;
21
import org.eclipse.equinox.p2.tests.*;
28
import org.eclipse.equinox.p2.tests.*;
22
29
23
/**
30
/**
Lines 25-41 Link Here
25
 */
32
 */
26
public class SiteXMLActionTest extends AbstractProvisioningTest {
33
public class SiteXMLActionTest extends AbstractProvisioningTest {
27
	private TestMetadataRepository metadataRepository;
34
	private TestMetadataRepository metadataRepository;
35
	private IPublisherResult actionResult;
36
	private URI siteLocation;
28
37
29
	@Override
38
	@Override
30
	protected void setUp() throws Exception {
39
	protected void setUp() throws Exception {
31
		super.setUp();
40
		super.setUp();
32
		IPublisherResult result = new PublisherResult();
41
		actionResult = new PublisherResult();
33
		PublisherInfo info = new PublisherInfo();
42
		PublisherInfo info = new PublisherInfo();
34
		metadataRepository = new TestMetadataRepository(new IInstallableUnit[0]);
43
		metadataRepository = new TestMetadataRepository(new IInstallableUnit[0]);
35
		info.setMetadataRepository(metadataRepository);
44
		info.setMetadataRepository(metadataRepository);
36
		URI siteLocation = TestData.getFile("updatesite", "SiteXMLActionTest/site.xml").toURI();
45
		siteLocation = TestData.getFile("updatesite", "SiteXMLActionTest/site.xml").toURI();
46
		FeaturesAction featuresAction = new FeaturesAction(new File[] {TestData.getFile("updateSite", "SiteXMLActionTest")});
47
		featuresAction.perform(info, actionResult, new NullProgressMonitor());
48
37
		SiteXMLAction action = new SiteXMLAction(siteLocation);
49
		SiteXMLAction action = new SiteXMLAction(siteLocation);
38
		action.perform(info, result, getMonitor());
50
		action.perform(info, actionResult, getMonitor());
51
	}
52
53
	public void testQualifier() {
54
		Query categoryQuery = new IUPropertyQuery(IInstallableUnit.PROP_TYPE_CATEGORY, Boolean.toString(true));
55
		Collector results = actionResult.query(categoryQuery, new Collector(), new NullProgressMonitor());
56
		Iterator iter = results.iterator();
57
		while (iter.hasNext()) {
58
			IInstallableUnit unit = (IInstallableUnit) iter.next();
59
			assertTrue("1.0", unit.getId().startsWith(URIUtil.toUnencodedString(siteLocation)));
60
			assertEquals("2.0", "Test Category Label", unit.getProperty(IInstallableUnit.PROP_NAME));
61
		}
39
	}
62
	}
40
63
41
	/**
64
	/**
(-)src/org/eclipse/equinox/p2/tests/updatesite/LocalUpdatesiteTest.java (+63 lines)
Added Link Here
1
/******************************************************************************* 
2
* Copyright (c) 2009 EclipseSource and others. All rights reserved. This
3
* program and the accompanying materials are made available under the terms of
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
5
* available at http://www.eclipse.org/legal/epl-v10.html
6
*
7
* Contributors:
8
*   EclipseSource - initial API and implementation
9
******************************************************************************/
10
package org.eclipse.equinox.p2.tests.updatesite;
11
12
import java.io.File;
13
import java.io.IOException;
14
import java.util.Iterator;
15
import org.eclipse.core.runtime.NullProgressMonitor;
16
import org.eclipse.equinox.internal.p2.updatesite.UpdatesitePublisherApplication;
17
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException;
18
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
19
import org.eclipse.equinox.internal.provisional.p2.metadata.query.IUPropertyQuery;
20
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository;
21
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
22
import org.eclipse.equinox.internal.provisional.p2.query.Query;
23
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
24
import org.eclipse.equinox.p2.tests.TestData;
25
26
public class LocalUpdatesiteTest extends AbstractProvisioningTest {
27
	protected File repoLocation;
28
29
	protected void setUp() throws Exception {
30
		super.setUp();
31
		String tempDir = System.getProperty("java.io.tmpdir");
32
		repoLocation = new File(tempDir, "LocalMetadataRepositoryTest");
33
		AbstractProvisioningTest.delete(repoLocation);
34
		repoLocation.mkdir();
35
	}
36
37
	protected void tearDown() throws Exception {
38
		getMetadataRepositoryManager().removeRepository(repoLocation.toURI());
39
		delete(repoLocation);
40
		super.tearDown();
41
	}
42
43
	public void testCategoryQualifier() throws IOException, ProvisionException {
44
		Query categoryQuery = new IUPropertyQuery(IInstallableUnit.PROP_TYPE_CATEGORY, Boolean.toString(true));
45
		File siteSource = TestData.getFile("updatesite", "SiteXMLActionTest");
46
		UpdatesitePublisherApplication application = new UpdatesitePublisherApplication();
47
		try {
48
			application.run(new String[] {"-metadataRepository", repoLocation.toURI().toString(), "-source", siteSource.toString(), "-categoryQualifier", "fooQualifier"});
49
		} catch (Exception e) {
50
			fail("0.99");
51
		}
52
		IMetadataRepository repository = getMetadataRepositoryManager().loadRepository(repoLocation.toURI(), new NullProgressMonitor());
53
		Collector results = repository.query(categoryQuery, new Collector(), new NullProgressMonitor());
54
		assertEquals("1.0", 1, results.size());
55
		Iterator iter = results.iterator();
56
		while (iter.hasNext()) {
57
			IInstallableUnit unit = (IInstallableUnit) iter.next();
58
			assertTrue("2.0", unit.getId().startsWith("fooQualifier"));
59
			System.out.println(unit.getId());
60
			assertEquals("3.0", "Test Category Label", unit.getProperty(IInstallableUnit.PROP_NAME));
61
		}
62
	}
63
}

Return to bug 264389