Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 478f7fe10a0c1ce7ce9fcabebe34e9e65825d55c (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
/*******************************************************************************
 * Copyright (c) 2009 IBM Corporation 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:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.equinox.p2.internal.repository.tools;

import java.net.URI;
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository;
import org.eclipse.osgi.util.NLS;

public class RepositoryDescriptor {

	public static final int TYPE_BOTH = -1;
	public static final String KIND_ARTIFACT = "A"; //$NON-NLS-1$
	public static final String KIND_METADATA = "M"; //$NON-NLS-1$

	private boolean compressed = true;
	private boolean append = true;
	private String name = null;
	private URI location = null;
	private URI format = null;
	private int kind = TYPE_BOTH;
	private URI originalLocation = null;

	public void setCompressed(boolean compress) {
		compressed = compress;
	}

	public void setName(String repoName) {
		name = repoName;
	}

	public void setLocation(URI repoLocation) {
		originalLocation = repoLocation;
		location = RepositoryHelper.localRepoURIHelper(repoLocation);
	}

	public void setFormat(URI format) {
		this.format = RepositoryHelper.localRepoURIHelper(format);
	}

	public void setAppend(boolean appendMode) {
		append = appendMode;
	}

	public boolean isCompressed() {
		return compressed;
	}

	public boolean isAppend() {
		return append;
	}

	public String getName() {
		return name;
	}

	public URI getRepoLocation() {
		return location;
	}

	public URI getOriginalRepoLocation() {
		return originalLocation;
	}

	public URI getFormat() {
		return format;
	}

	public int getKind() {
		return kind;
	}

	public boolean isBoth() {
		return kind == TYPE_BOTH;
	}

	public boolean isArtifact() {
		return kind == TYPE_BOTH || kind == IRepository.TYPE_ARTIFACT;
	}

	public boolean isMetadata() {
		return kind == TYPE_BOTH || kind == IRepository.TYPE_METADATA;
	}

	public void setKind(String repoKind) {
		kind = determineKind(repoKind);
	}

	/*
	 * Determine the repository type
	 */
	public static int determineKind(String repoKind) {
		if (kindMatches(repoKind, KIND_METADATA))
			return IRepository.TYPE_METADATA;
		else if (kindMatches(repoKind, KIND_ARTIFACT))
			return IRepository.TYPE_ARTIFACT;

		throw new IllegalArgumentException(NLS.bind(Messages.unknown_repository_type, repoKind));
	}

	/*
	 * Determine if the repository kind matches the identifier kind
	 */
	public static boolean kindMatches(String repoKind, String kindIdentifier) {
		return repoKind.startsWith(kindIdentifier) || repoKind.startsWith(kindIdentifier.toLowerCase());
	}
}

Back to the top