Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 299533 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/equinox/internal/p2/metadata/generator/features/SiteFeature.java (-22 / +65 lines)
Lines 46-75 Link Here
46
	 * Return false if one of them is null
46
	 * Return false if one of them is null
47
	 */
47
	 */
48
	public static boolean sameURL(URL url1, URL url2) {
48
	public static boolean sameURL(URL url1, URL url2) {
49
50
		if (url1 == null || url2 == null)
51
			return false;
52
		if (url1 == url2)
49
		if (url1 == url2)
53
			return true;
50
			return true;
54
		if (url1.equals(url2))
51
		if (url1 == null ^ url2 == null)
55
			return true;
52
			return false;
56
53
57
		// check if URL are file: URL as we may
54
		// check if URL are file: URL as we may
58
		// have 2 URL pointing to the same featureReference
55
		// have 2 URL pointing to the same featureReference
59
		// but with different representation
56
		// but with different representation
60
		// (i.e. file:/C;/ and file:C:/)
57
		// (i.e. file:/C;/ and file:C:/)
61
		if (!"file".equalsIgnoreCase(url1.getProtocol())) //$NON-NLS-1$
58
		final boolean isFile1 = "file".equalsIgnoreCase(url1.getProtocol());//$NON-NLS-1$
62
			return false;
59
		final boolean isFile2 = "file".equalsIgnoreCase(url2.getProtocol());//$NON-NLS-1$
63
		if (!"file".equalsIgnoreCase(url2.getProtocol())) //$NON-NLS-1$
60
		if (isFile1 && isFile2) {
64
			return false;
61
			File file1 = new File(url1.getFile());
65
62
			File file2 = new File(url2.getFile());
66
		File file1 = new File(url1.getFile());
63
			return file1.equals(file2);
67
		File file2 = new File(url2.getFile());
64
		}
68
65
		// URL1 xor URL2 is a file, return false. (They either both need to be files, or neither)
69
		if (file1 == null)
66
		if (isFile1 ^ isFile2)
70
			return false;
67
			return false;
68
		return getExternalForm(url1).equals(getExternalForm(url2));
69
	}
71
70
72
		return (file1.equals(file2));
71
	/**
72
	 * Gets the external form of this URL. In particular, it trims any white space, 
73
	 * removes a trailing slash and creates a lower case string.
74
	 */
75
	private static String getExternalForm(URL url) {
76
		String externalForm = url.toExternalForm();
77
		if (externalForm == null)
78
			return ""; //$NON-NLS-1$
79
		externalForm = externalForm.trim();
80
		if (externalForm.endsWith("/")) { //$NON-NLS-1$
81
			// Remove the trailing slash
82
			externalForm = externalForm.substring(0, externalForm.length() - 1);
83
		}
84
		return externalForm.toLowerCase();
73
	}
85
	}
74
86
75
	/**
87
	/**
Lines 114-131 Link Here
114
	 * <code>false</code> otherwise
126
	 * <code>false</code> otherwise
115
	 */
127
	 */
116
	public boolean equals(Object object) {
128
	public boolean equals(Object object) {
117
118
		if (object == null)
129
		if (object == null)
119
			return false;
130
			return false;
120
		if (getURL() == null)
121
			return false;
122
123
		if (!(object instanceof SiteFeature))
131
		if (!(object instanceof SiteFeature))
124
			return false;
132
			return false;
133
		SiteFeature that = (SiteFeature) object;
134
		if (this.featureId == null) {
135
			if (that.featureId != null)
136
				return false;
137
		} else if (!this.featureId.equals(that.featureId))
138
			return false;
139
		if (this.featureVersion == null) {
140
			if (that.featureVersion != null)
141
				return false;
142
		} else if (!this.featureVersion.equals(that.featureVersion))
143
			return false;
144
		if (this.label == null) {
145
			if (that.label != null)
146
				return false;
147
		} else if (!this.label.equals(that.label))
148
			return false;
149
		return sameURL(this.getURL(), that.getURL());
150
	}
125
151
126
		SiteFeature f = (SiteFeature) object;
152
	/* (non-Javadoc)
127
153
	 * @see java.lang.Object#hashCode()
128
		return sameURL(getURL(), f.getURL());
154
	 */
155
	public int hashCode() {
156
		final int prime = 31;
157
		int result = 1;
158
		result = prime * result + (featureId == null ? 0 : featureId.hashCode());
159
		result = prime * result + (featureVersion == null ? 0 : featureVersion.hashCode());
160
		if (this.getURL() == null)
161
			return result;
162
163
		if ("file".equalsIgnoreCase(getURL().getProtocol())) {//$NON-NLS-1$ 
164
			// If the URL is a file, then create the HashCode from the file
165
			File f = new File(getURL().getFile());
166
			if (f != null)
167
				result = prime * result + f.hashCode();
168
		} else
169
			// Otherwise create it from the External form of the URL (in lower case)
170
			result = prime * result + getExternalForm(this.getURL()).hashCode();
171
		return result;
129
	}
172
	}
130
173
131
	/**
174
	/**
(-)src/org/eclipse/equinox/p2/tests/updatesite/UpdateSiteTest.java (+32 lines)
Lines 18-23 Link Here
18
import org.eclipse.core.runtime.IStatus;
18
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.NullProgressMonitor;
19
import org.eclipse.core.runtime.NullProgressMonitor;
20
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
20
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
21
import org.eclipse.equinox.internal.p2.metadata.generator.features.SiteFeature;
21
import org.eclipse.equinox.internal.p2.updatesite.UpdateSite;
22
import org.eclipse.equinox.internal.p2.updatesite.UpdateSite;
22
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
23
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository;
23
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
24
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
Lines 481-486 Link Here
481
		}
482
		}
482
	}
483
	}
483
484
485
	public void testSiteFeatureFileURL() {
486
		SiteFeature a = new SiteFeature();
487
		SiteFeature b = new SiteFeature();
488
		assertEquals("1.0", a, b);
489
		a.setURLString("file:/c:/foo");
490
		b.setURLString("file:/c:/FOO");
491
		if (a.equals(b))
492
			assertEquals("1.1", a.hashCode(), b.hashCode());
493
		a.setURLString("FILE:/c:/foo");
494
		b.setURLString("file:/c:/FOO");
495
		if (a.equals(b))
496
			assertEquals("1.2", a.hashCode(), b.hashCode());
497
		a.setURLString("HTTP://example.com");
498
		b.setURLString("HTtP://example.com");
499
		if (a.equals(b))
500
			assertEquals("1.3", a.hashCode(), b.hashCode());
501
		a.setURLString("HTTP://eXaMpLe.com");
502
		b.setURLString("HTtP://example.com");
503
		if (a.equals(b))
504
			assertEquals("1.4", a.hashCode(), b.hashCode());
505
		a.setURLString("HTTP://eXaMpLe.com/");
506
		b.setURLString("HTtP://example.com");
507
		assertEquals(a, b);
508
		if (a.equals(b))
509
			assertEquals("1.5", a.hashCode(), b.hashCode());
510
		a.setURLString("http://localhost");
511
		b.setURLString("http://127.0.0.1");
512
		if (a.equals(b))
513
			assertEquals("1.6", a.hashCode(), b.hashCode());
514
	}
515
484
	public void testMirrors() {
516
	public void testMirrors() {
485
		// TODO test the case where the site.xml points to a mirror location
517
		// TODO test the case where the site.xml points to a mirror location
486
	}
518
	}

Return to bug 299533