Skip to main content
summaryrefslogtreecommitdiffstats
blob: bcfbefa3415faf10aa310b6437706552902ba1da (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
/*******************************************************************************
 * Copyright (c) 2009, 2017 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.internal.p2.artifact.repository.simple;

import java.util.Map;
import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactDescriptor;

public class SimpleArtifactDescriptor extends ArtifactDescriptor {
	public static final String ARTIFACT_REFERENCE = "artifact.reference"; //$NON-NLS-1$

	protected Map<String, String> repositoryProperties = new OrderedProperties();

	public SimpleArtifactDescriptor(IArtifactKey key) {
		super(key);
	}

	public SimpleArtifactDescriptor(IArtifactDescriptor base) {
		super(base);
	}

	public String getRepositoryProperty(String propertyKey) {
		return repositoryProperties.get(propertyKey);
	}

	public void setRepositoryProperty(String key, String value) {
		if (value == null)
			repositoryProperties.remove(key);
		else
			repositoryProperties.put(key, value);
	}

	public void addRepositoryProperties(Map<String, String> additionalProperties) {
		repositoryProperties.putAll(additionalProperties);
	}

	/**
	 * Returns a read-only collection of the repository properties of the artifact descriptor.
	 * @return the repository properties of this artifact descriptor.
	 */
	public Map<String, String> getRepositoryProperties() {
		return OrderedProperties.unmodifiableProperties(repositoryProperties);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null || !(obj instanceof SimpleArtifactDescriptor))
			return false;

		SimpleArtifactDescriptor other = (SimpleArtifactDescriptor) obj;

		//Properties affecting SimpleArtifactRepository#getLocation
		String locationProperty = getRepositoryProperty(ARTIFACT_REFERENCE);
		String otherProperty = other.getRepositoryProperty(ARTIFACT_REFERENCE);
		// want not null and the same, or both null
		if (locationProperty != null ? !locationProperty.equals(otherProperty) : otherProperty != null)
			return false;

		return super.equals(obj);
	}

	@Override
	public int hashCode() {
		int superHash = super.hashCode();
		String ref = getRepositoryProperty(ARTIFACT_REFERENCE);
		if (ref != null)
			return 31 * superHash + ref.hashCode();
		return superHash;
	}
}

Back to the top