Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 78d214d5983620a18793c62c49418aae33bdf2b4 (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*******************************************************************************
 *  Copyright (c) 2007, 2011 IBM Corporation and others.
 *
 *  This program and the accompanying materials
 *  are made available under the terms of the Eclipse Public License 2.0
 *  which accompanies this distribution, and is available at
 *  https://www.eclipse.org/legal/epl-2.0/
 *
 *  SPDX-License-Identifier: EPL-2.0
 * 
 *  Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.p2.repository.metadata.spi;

import java.net.URI;
import java.util.Collection;
import java.util.Map;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.repository.Activator;
import org.eclipse.equinox.p2.core.IPool;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.repository.IRepositoryReference;
import org.eclipse.equinox.p2.repository.IRunnableWithProgress;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.spi.AbstractRepository;

/**
 * The common base class for all metadata repositories.
 * <p>
 * Clients may subclass this class.
 * <p>
 * @since 2.0
 */
public abstract class AbstractMetadataRepository extends AbstractRepository<IInstallableUnit> implements IMetadataRepository {

	/**
	 * A class that encapsulates the persisted state of a repository. This is used as a convenience
	 * when loading and storing repositories.
	 * @see AbstractMetadataRepository#initialize(RepositoryState)
	 */
	public static class RepositoryState {
		/**
		 * The persisted name of the repository.
		 */
		public String Name;
		/**
		 * The persisted type of the repository.
		 */
		public String Type;
		/**
		 * The persisted version of the repository.
		 */
		public Version Version;
		/**
		 * The persisted provider of the repository.
		 */
		public String Provider;
		/**
		 * The persisted description of the repository.
		 */
		public String Description;
		/**
		 * The persisted location of the repository.
		 */
		public URI Location;
		/**
		 * The persisted properties of the repository.
		 */
		public Map<String, String> Properties;
		/**
		 * The persisted set of installable units of the repository.
		 */
		public IInstallableUnit[] Units;
		/**
		 * The persisted array of repository references
		 */
		public IRepositoryReference[] Repositories;
	}

	/**
	 * Creates a new metadata repository that uses the provided agent.
	 * 
	 * @param agent the provisioning agent to be used by this repository
	 */
	public AbstractMetadataRepository(IProvisioningAgent agent) {
		super(agent, "noName", "noType", "noVersion", null, null, null, null); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
	}

	/**
	 * Initializes this class based on the provided previously persisted state
	 * 
	 * @param state the persisted repository state
	 */
	public abstract void initialize(RepositoryState state);

	/**
	 * Creates a new metadata repository with the provided repository information
	 * 
	 * @param agent the provisioning agent to be used by this repository
	 * @param name the repository name
	 * @param type the repository type
	 * @param version the repository version
	 * @param location the repository location
	 * @param description the repository description
	 * @param provider the repository provider
	 * @param properties the repository properties
	 */
	protected AbstractMetadataRepository(IProvisioningAgent agent, String name, String type, String version, URI location, String description, String provider, Map<String, String> properties) {
		super(agent, name, type, version, location, description, provider, properties);
	}

	@Override
	public void addInstallableUnits(Collection<IInstallableUnit> installableUnits) {
		assertModifiable();
	}

	@Override
	public void addReferences(Collection<? extends IRepositoryReference> references) {
		assertModifiable();
	}

	@Override
	public void removeAll() {
		assertModifiable();
	}

	@Override
	public boolean removeInstallableUnits(Collection<IInstallableUnit> installableUnits) {
		assertModifiable();
		return false;
	}

	@Override
	public IStatus executeBatch(IRunnableWithProgress runnable, IProgressMonitor monitor) {
		try {
			runnable.run(monitor);
		} catch (OperationCanceledException oce) {
			return new Status(IStatus.CANCEL, Activator.ID, oce.getMessage(), oce);
		} catch (Exception e) {
			return new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e);
		}
		return Status.OK_STATUS;
	}

	/**
	 * @since 2.1
	 */
	@Override
	public void compress(IPool<IInstallableUnit> iuPool) {
		// Default no-op.  Subclasses should override as appropriate
	}

}

Back to the top