1 /*******************************************************************************
2  * Copyright (c) 2009, 2010 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.equinox.p2.internal.repository.tools;
15 
16 import java.net.URI;
17 import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper;
18 import org.eclipse.equinox.p2.repository.IRepository;
19 import org.eclipse.osgi.util.NLS;
20 
21 public class RepositoryDescriptor {
22 
23 	public static final int TYPE_BOTH = -1;
24 	public static final String KIND_ARTIFACT = "A"; //$NON-NLS-1$
25 	public static final String KIND_METADATA = "M"; //$NON-NLS-1$
26 
27 	private boolean compressed = true;
28 	private boolean append = true;
29 	private String name = null;
30 	private URI location = null;
31 	private URI format = null;
32 	private int kind = TYPE_BOTH;
33 	private URI originalLocation = null;
34 	private boolean optional = false;
35 	private String atomic = null;
36 
setCompressed(boolean compress)37 	public void setCompressed(boolean compress) {
38 		compressed = compress;
39 	}
40 
setName(String repoName)41 	public void setName(String repoName) {
42 		name = repoName;
43 	}
44 
setOptional(boolean optional)45 	public void setOptional(boolean optional) {
46 		this.optional = optional;
47 	}
48 
isOptional()49 	public boolean isOptional() {
50 		return optional;
51 	}
52 
setLocation(URI repoLocation)53 	public void setLocation(URI repoLocation) {
54 		originalLocation = repoLocation;
55 		location = RepositoryHelper.localRepoURIHelper(repoLocation);
56 	}
57 
setFormat(URI format)58 	public void setFormat(URI format) {
59 		this.format = RepositoryHelper.localRepoURIHelper(format);
60 	}
61 
setAppend(boolean appendMode)62 	public void setAppend(boolean appendMode) {
63 		append = appendMode;
64 	}
65 
isCompressed()66 	public boolean isCompressed() {
67 		return compressed;
68 	}
69 
isAppend()70 	public boolean isAppend() {
71 		return append;
72 	}
73 
getName()74 	public String getName() {
75 		return name;
76 	}
77 
getRepoLocation()78 	public URI getRepoLocation() {
79 		return location;
80 	}
81 
getOriginalRepoLocation()82 	public URI getOriginalRepoLocation() {
83 		return originalLocation;
84 	}
85 
getFormat()86 	public URI getFormat() {
87 		return format;
88 	}
89 
getKind()90 	public int getKind() {
91 		return kind;
92 	}
93 
isBoth()94 	public boolean isBoth() {
95 		return kind == TYPE_BOTH;
96 	}
97 
isArtifact()98 	public boolean isArtifact() {
99 		return kind == TYPE_BOTH || kind == IRepository.TYPE_ARTIFACT;
100 	}
101 
isMetadata()102 	public boolean isMetadata() {
103 		return kind == TYPE_BOTH || kind == IRepository.TYPE_METADATA;
104 	}
105 
setKind(String repoKind)106 	public void setKind(String repoKind) {
107 		kind = determineKind(repoKind);
108 	}
109 
setAtomic(String booleanForAtomic)110 	public void setAtomic(String booleanForAtomic) {
111 		atomic = booleanForAtomic;
112 	}
113 
getAtomic()114 	public String getAtomic() {
115 		return atomic;
116 	}
117 
118 	/*
119 	 * Determine the repository type
120 	 */
determineKind(String repoKind)121 	public static int determineKind(String repoKind) {
122 		if (kindMatches(repoKind, KIND_METADATA))
123 			return IRepository.TYPE_METADATA;
124 		else if (kindMatches(repoKind, KIND_ARTIFACT))
125 			return IRepository.TYPE_ARTIFACT;
126 
127 		throw new IllegalArgumentException(NLS.bind(Messages.unknown_repository_type, repoKind));
128 	}
129 
130 	/*
131 	 * Determine if the repository kind matches the identifier kind
132 	 */
kindMatches(String repoKind, String kindIdentifier)133 	public static boolean kindMatches(String repoKind, String kindIdentifier) {
134 		return repoKind.startsWith(kindIdentifier) || repoKind.startsWith(kindIdentifier.toLowerCase());
135 	}
136 }
137