Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9b7b9a20f20e02dd61fce33e0d3ac543d686d5df (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
/*******************************************************************************
 * Copyright (C) 2009, Mykola Nikishov <mn@mn.com.ua>
 * Copyright (C) 2011, Robin Stocker <robin@nibor.org>
 *
 * 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:
 *     Manuel Doninger <manuel.doninger@googlemail.com>
 *******************************************************************************/
package org.eclipse.egit.core;

import java.net.URISyntaxException;
import java.util.regex.Pattern;

import org.eclipse.egit.core.internal.CoreText;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.osgi.util.NLS;

/**
 * ProjectReference for Team project sets
 */
public final class ProjectReference {

	private static final String DEFAULT_BRANCH = Constants.MASTER;

	/**
	 * the version of the reference string
	 */
	private String version;

	/**
	 * a relative path (from the repository root) to a project
	 */
	private String projectDir;

	/**
	 * <code>repository</code> parameter
	 */
	private URIish repository;

	/**
	 * the remote branch that will be checked out, see <code>--branch</code>
	 * option
	 */
	private String branch = DEFAULT_BRANCH;

	/**
	 * use this name instead of using the remote name origin to keep track
	 * of the upstream repository, see <code>--origin</code> option.
	 */
	private String origin = Constants.DEFAULT_REMOTE_NAME;

	static final String SEPARATOR = ","; //$NON-NLS-1$

	/**
	 * @param reference
	 * @throws URISyntaxException
	 * @throws IllegalArgumentException
	 */
	@SuppressWarnings("boxing")
	public ProjectReference(final String reference) throws URISyntaxException, IllegalArgumentException {
		final String[] tokens = reference.split(Pattern.quote(ProjectReference.SEPARATOR));
		if (tokens.length != 4)
			throw new IllegalArgumentException(NLS.bind(
					CoreText.ProjectReference_InvalidTokensCount, new Object[] {
							4, tokens.length, tokens }));

		this.version = tokens[0];
		this.repository = new URIish(tokens[1]);
		if (!"".equals(tokens[2])) //$NON-NLS-1$
			this.branch = tokens[2];
		this.projectDir = tokens[3];
	}

	/**
	 * @return <code>repository</code> parameter
	 */
	public URIish getRepository() {
		return repository;
	}

	/**
	 * @return the remote branch that will be checked out, see <code>--branch</code>
	 * option
	 */
	public String getBranch() {
		return branch;
	}

	/**
	 * @return name of the upstream repository
	 */
	public String getOrigin() {
		return origin;
	}

	/**
	 * @return a relative path (from the repository root) to a project
	 */
	public String getProjectDir() {
		return projectDir;
	}

	String getVersion() {
		return version;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((branch == null) ? 0 : branch.hashCode());
		result = prime * result
				+ ((projectDir == null) ? 0 : projectDir.hashCode());
		result = prime * result
				+ ((repository == null) ? 0 : repository.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof ProjectReference))
			return false;
		ProjectReference other = (ProjectReference) obj;
		if (branch == null) {
			if (other.branch != null)
				return false;
		} else if (!branch.equals(other.branch))
			return false;
		if (projectDir == null) {
			if (other.projectDir != null)
				return false;
		} else if (!projectDir.equals(other.projectDir))
			return false;
		if (repository == null) {
			if (other.repository != null)
				return false;
		} else if (!repository.equals(other.repository))
			return false;
		return true;
	}
}

Back to the top