Skip to main content
summaryrefslogtreecommitdiffstats
blob: b3ca1632e40a5484cf2fcb407049ba9bc3bc9576 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*******************************************************************************
 * Copyright (c) 2009, 2017 EclipseSource and others. All rights reserved. This
 * program and the accompanying materials are made available under the terms of
 * the Eclipse Public License v1.0 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: 
 *   EclipseSource - initial API and implementation
 ******************************************************************************/
package org.eclipse.equinox.internal.p2.updatesite;

import java.net.URI;
import java.net.URISyntaxException;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.publisher.*;
import org.eclipse.equinox.p2.repository.IRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;

/**
 * <p>
 * This application categorizes the elements in a repo based on a category definition file.  The category definition
 * file is specified with <source>-categoryDefinition</source>
 * </p>
 */
public class CategoryPublisherApplication extends AbstractPublisherApplication {

	private String categoryQualifier = null;
	private URI categoryDefinition = null;

	public CategoryPublisherApplication() {
		// nothing todo
	}

	/*
	 * Check to see if an existing repository already has the "compressed" flag set
	 */
	@Override
	protected void initializeRepositories(PublisherInfo publisherInfo) throws ProvisionException {
		try {
			if (metadataLocation != null) {
				// Try to load the metadata repository. If it loads, check the "compressed" flag, and cache it.
				// If there are any errors loading it (i.e. it doesn't exist), just skip this step
				// If there are serious problems with the repository, the superclass initializeRepositories method
				// will handle it.
				IMetadataRepository result = Publisher.loadMetadataRepository(agent, metadataLocation, true, true);
				if (result != null) {
					Object property = result.getProperties().get(IRepository.PROP_COMPRESSED);
					if (property != null) {
						boolean compressProperty = Boolean.valueOf((String) property);
						this.compress = compressProperty || compress;
					}
				}
			}
		} catch (ProvisionException e) {
			//do nothing
		}
		super.initializeRepositories(publisherInfo);
	}

	@Override
	protected void processParameter(String arg, String parameter, PublisherInfo pinfo) throws URISyntaxException {
		super.processParameter(arg, parameter, pinfo);

		this.append = true; // Always append, otherwise we will end up with nothing

		if (arg.equalsIgnoreCase("-categoryQualifier")) //$NON-NLS-1$
			categoryQualifier = parameter;

		if (arg.equalsIgnoreCase("-categoryDefinition")) //$NON-NLS-1$
			categoryDefinition = URIUtil.fromString(parameter);

	}

	@Override
	protected IPublisherAction[] createActions() {
		return new IPublisherAction[] {new CategoryXMLAction(categoryDefinition, categoryQualifier)};
	}
}

Back to the top