Skip to main content
summaryrefslogtreecommitdiffstats
blob: efffa66678b51e6a9138513013d9f5781fd207eb (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
/*******************************************************************************
 * Copyright (c) 2009, 2017 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.tests;

import java.net.URI;
import java.util.Map;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.spi.MetadataRepositoryFactory;

/**
 * A repository factory that always throws exceptions. The "fail" flag must be set to
 * cause this factory to start throwing exceptions.
 */
public class FailingMetadataRepositoryFactory extends MetadataRepositoryFactory {
	public static boolean FAIL = false;

	@Override
	public IMetadataRepository create(URI location, String name, String type, Map<String, String> properties) throws ProvisionException {
		if (FAIL)
			throw new RuntimeException("Exception thrown deliberately as part of test");
		throw new ProvisionException(new Status(IStatus.ERROR, TestActivator.PI_PROV_TESTS, ProvisionException.REPOSITORY_NOT_FOUND, "", null));
	}

	@Override
	public IMetadataRepository load(URI location, int flags, IProgressMonitor monitor) throws ProvisionException {
		if (FAIL)
			throw new RuntimeException("Exception thrown deliberately as part of test");
		throw new ProvisionException(new Status(IStatus.ERROR, TestActivator.PI_PROV_TESTS, ProvisionException.REPOSITORY_NOT_FOUND, "", null));
	}

}

Back to the top