Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6dcc38b59fb922655070cfd90178e088cdf47ad0 (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
/*******************************************************************************
 * Copyright (c) 2007, 2018 compeople AG 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:
 * 	compeople AG (Stefan Liebig) - initial API and implementation
 * 	IBM Corporation - ongoing development
 *******************************************************************************/
package org.eclipse.equinox.internal.p2.artifact.processors;

import java.net.URI;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.artifact.optimizers.AbstractDeltaStep;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.repository.IRepositoryManager;
import org.eclipse.equinox.p2.repository.artifact.*;

/**
 * The <code>AbstractDeltaPatchStep</code> is an abstract processing step that
 * retrieves a local artifact repository containing the serialized/encoded
 * artifact key. It assumes that the artifact key is stored within the data
 * property of the processing step descriptor encoding the artifact key of the
 * base artifact.
 */
public abstract class AbstractDeltaProcessorStep extends AbstractDeltaStep {

	@Override
	public void initialize(IProvisioningAgent agent, IProcessingStepDescriptor descriptor,
			IArtifactDescriptor context) {
		super.initialize(agent, descriptor, context);
		if (!getStatus().isOK())
			return;
		fetchLocalArtifactRepository(agent);
	}

	/**
	 * Fetch a local artifact repository containing the fetched artifact key.
	 */
	private void fetchLocalArtifactRepository(IProvisioningAgent agent) {
		if (repository != null)
			return;
		IArtifactRepositoryManager repoMgr = (IArtifactRepositoryManager) agent
				.getService(IArtifactRepositoryManager.SERVICE_NAME);
		if (repoMgr == null) {
			setStatus(new Status(IStatus.ERROR, Activator.ID, "Could not get artifact repository manager."));
			return;
		}

		URI[] repositories = repoMgr.getKnownRepositories(IRepositoryManager.REPOSITORIES_LOCAL);
		for (URI repositorie : repositories) {
			try {
				IArtifactRepository currentRepo = repoMgr.loadRepository(repositorie, null);
				if (currentRepo.contains(key)) {
					repository = currentRepo;
					return;
				}
			} catch (ProvisionException e) {
				// just skip unreadable repositories
			}
		}
		setStatus(new Status(IStatus.ERROR, Activator.ID, "No repository available containing key " + key));
	}

}

Back to the top