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 231642
Collapse All | Expand All

(-)src/org/eclipse/equinox/p2/tests/artifact/repository/SimpleArtifactRepositoryTest.java (-12 / +28 lines)
Lines 27-32 Link Here
27
import org.eclipse.equinox.p2.tests.TestActivator;
27
import org.eclipse.equinox.p2.tests.TestActivator;
28
28
29
public class SimpleArtifactRepositoryTest extends TestCase {
29
public class SimpleArtifactRepositoryTest extends TestCase {
30
	//artifact repository to remove on tear down
31
	private File repositoryFile = null;
32
	private URL repositoryURL = null;
33
34
	protected void tearDown() throws Exception {
35
		super.tearDown();
36
		//repository location is not used by all tests
37
		if (repositoryURL != null) {
38
			getArtifactRepositoryManager().removeRepository(repositoryURL);
39
			repositoryURL = null;
40
		}
41
		if (repositoryFile != null) {
42
			delete(repositoryFile);
43
			repositoryFile = null;
44
		}
45
	}
30
46
31
	public void testGetActualLocation1() throws MalformedURLException {
47
	public void testGetActualLocation1() throws MalformedURLException {
32
		URL base = new URL("http://localhost/artifactRepository");
48
		URL base = new URL("http://localhost/artifactRepository");
Lines 65-83 Link Here
65
	public void testCompressedRepository() throws MalformedURLException, ProvisionException {
81
	public void testCompressedRepository() throws MalformedURLException, ProvisionException {
66
		IArtifactRepositoryManager artifactRepositoryManager = getArtifactRepositoryManager();
82
		IArtifactRepositoryManager artifactRepositoryManager = getArtifactRepositoryManager();
67
		String tempDir = System.getProperty("java.io.tmpdir");
83
		String tempDir = System.getProperty("java.io.tmpdir");
68
		File repoLocation = new File(tempDir, "SimpleArtifactRepositoryTest");
84
		repositoryFile = new File(tempDir, "SimpleArtifactRepositoryTest");
85
		delete(repositoryFile);
86
		repositoryURL = repositoryFile.toURL();
69
		Map properties = new HashMap();
87
		Map properties = new HashMap();
70
		properties.put(IRepository.PROP_COMPRESSED, "true");
88
		properties.put(IRepository.PROP_COMPRESSED, "true");
71
		IArtifactRepository repo = artifactRepositoryManager.createRepository(repoLocation.toURL(), "artifact name", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties);
89
		IArtifactRepository repo = artifactRepositoryManager.createRepository(repositoryURL, "artifact name", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties);
72
		artifactRepositoryManager.addRepository(repo.getLocation());
73
		EclipseInstallGeneratorInfoProvider provider = new EclipseInstallGeneratorInfoProvider();
90
		EclipseInstallGeneratorInfoProvider provider = new EclipseInstallGeneratorInfoProvider();
74
		provider.setArtifactRepository(repo);
91
		provider.setArtifactRepository(repo);
75
		provider.initialize(repoLocation);
92
		provider.initialize(repositoryFile);
76
		provider.setRootVersion("3.3");
93
		provider.setRootVersion("3.3");
77
		provider.setRootId("sdk");
94
		provider.setRootId("sdk");
78
		provider.setFlavor("tooling");
95
		provider.setFlavor("tooling");
79
		new Generator(provider).generate();
96
		new Generator(provider).generate();
80
		File files[] = repoLocation.listFiles();
97
		File files[] = repositoryFile.listFiles();
81
		boolean jarFilePresent = false;
98
		boolean jarFilePresent = false;
82
		boolean artifactFilePresent = false;
99
		boolean artifactFilePresent = false;
83
		for (int i = 0; i < files.length; i++) {
100
		for (int i = 0; i < files.length; i++) {
Lines 92-116 Link Here
92
			fail("Repository should create JAR for artifact.xml");
109
			fail("Repository should create JAR for artifact.xml");
93
		if (artifactFilePresent)
110
		if (artifactFilePresent)
94
			fail("Repository should not create artifact.xml");
111
			fail("Repository should not create artifact.xml");
95
		delete(repoLocation);
96
	}
112
	}
97
113
98
	public void testUncompressedRepository() throws MalformedURLException, ProvisionException {
114
	public void testUncompressedRepository() throws MalformedURLException, ProvisionException {
99
		IArtifactRepositoryManager artifactRepositoryManager = getArtifactRepositoryManager();
115
		IArtifactRepositoryManager artifactRepositoryManager = getArtifactRepositoryManager();
100
		String tempDir = System.getProperty("java.io.tmpdir");
116
		String tempDir = System.getProperty("java.io.tmpdir");
101
		File repoLocation = new File(tempDir, "SimpleArtifactRepositoryTest");
117
		repositoryFile = new File(tempDir, "SimpleArtifactRepositoryTest");
118
		delete(repositoryFile);
119
		repositoryURL = repositoryFile.toURL();
102
		Map properties = new HashMap();
120
		Map properties = new HashMap();
103
		properties.put(IRepository.PROP_COMPRESSED, "false");
121
		properties.put(IRepository.PROP_COMPRESSED, "false");
104
		IArtifactRepository repo = artifactRepositoryManager.createRepository(repoLocation.toURL(), "artifact name", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties);
122
		IArtifactRepository repo = artifactRepositoryManager.createRepository(repositoryURL, "artifact name", IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, properties);
105
		artifactRepositoryManager.addRepository(repo.getLocation());
106
		EclipseInstallGeneratorInfoProvider provider = new EclipseInstallGeneratorInfoProvider();
123
		EclipseInstallGeneratorInfoProvider provider = new EclipseInstallGeneratorInfoProvider();
107
		provider.setArtifactRepository(repo);
124
		provider.setArtifactRepository(repo);
108
		provider.initialize(repoLocation);
125
		provider.initialize(repositoryFile);
109
		provider.setRootVersion("3.3");
126
		provider.setRootVersion("3.3");
110
		provider.setRootId("sdk");
127
		provider.setRootId("sdk");
111
		provider.setFlavor("tooling");
128
		provider.setFlavor("tooling");
112
		new Generator(provider).generate();
129
		new Generator(provider).generate();
113
		File files[] = repoLocation.listFiles();
130
		File files[] = repositoryFile.listFiles();
114
		boolean jarFilePresent = false;
131
		boolean jarFilePresent = false;
115
		boolean artifactFilePresent = false;
132
		boolean artifactFilePresent = false;
116
		for (int i = 0; i < files.length; i++) {
133
		for (int i = 0; i < files.length; i++) {
Lines 125-131 Link Here
125
			fail("Repository should not create JAR for artifact.xml");
142
			fail("Repository should not create JAR for artifact.xml");
126
		if (!artifactFilePresent)
143
		if (!artifactFilePresent)
127
			fail("Repository should create artifact.xml");
144
			fail("Repository should create artifact.xml");
128
		delete(repoLocation);
129
	}
145
	}
130
146
131
	private boolean delete(File file) {
147
	private boolean delete(File file) {
(-)src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerTest.java (-2 / +2 lines)
Lines 166-178 Link Here
166
		// modify the last modified date to be older than the remote file
166
		// modify the last modified date to be older than the remote file
167
		cacheFile.setLastModified(0);
167
		cacheFile.setLastModified(0);
168
		// reload the repository and check that the cache was updated
168
		// reload the repository and check that the cache was updated
169
		manager.addRepository(repoLocation);
169
		manager.removeRepository(repoLocation);
170
		manager.loadRepository(repoLocation, null);
170
		manager.loadRepository(repoLocation, null);
171
		long lastModified = cacheFile.lastModified();
171
		long lastModified = cacheFile.lastModified();
172
		assertTrue(0 != lastModified);
172
		assertTrue(0 != lastModified);
173
173
174
		// reload the repository and check that the cache was not updated
174
		// reload the repository and check that the cache was not updated
175
		manager.addRepository(repoLocation);
175
		manager.removeRepository(repoLocation);
176
		manager.loadRepository(repoLocation, null);
176
		manager.loadRepository(repoLocation, null);
177
		assertEquals(lastModified, cacheFile.lastModified());
177
		assertEquals(lastModified, cacheFile.lastModified());
178
178
(-)src/org/eclipse/equinox/internal/p2/metadata/repository/MetadataRepositoryManager.java (+19 lines)
Lines 131-136 Link Here
131
		synchronized (repositoryLock) {
131
		synchronized (repositoryLock) {
132
			if (repositories == null)
132
			if (repositories == null)
133
				restoreRepositories();
133
				restoreRepositories();
134
			if (contains(location))
135
				return;
134
			added = repositories.put(getKey(location), info) == null;
136
			added = repositories.put(getKey(location), info) == null;
135
		}
137
		}
136
		// save the given repository in the preferences.
138
		// save the given repository in the preferences.
Lines 176-181 Link Here
176
		}
178
		}
177
	}
179
	}
178
180
181
	private boolean contains(URL location) {
182
		synchronized (repositoryLock) {
183
			if (repositories == null)
184
				restoreRepositories();
185
			String key = getKey(location);
186
			if (repositories.containsKey(key))
187
				return true;
188
			//try alternate key with different trailing slash
189
			int len = key.length();
190
			if (key.charAt(len - 1) == '_')
191
				key = key.substring(0, len - 1);
192
			else
193
				key = key + '_';
194
			return repositories.containsKey(key);
195
		}
196
	}
197
179
	/**
198
	/**
180
	 * Returns the executable extension, or <code>null</code> if there
199
	 * Returns the executable extension, or <code>null</code> if there
181
	 * was no corresponding extension, or an error occurred loading it
200
	 * was no corresponding extension, or an error occurred loading it
(-)src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java (+19 lines)
Lines 125-130 Link Here
125
		synchronized (repositoryLock) {
125
		synchronized (repositoryLock) {
126
			if (repositories == null)
126
			if (repositories == null)
127
				restoreRepositories();
127
				restoreRepositories();
128
			if (contains(location))
129
				return;
128
			added = repositories.put(getKey(location), info) == null;
130
			added = repositories.put(getKey(location), info) == null;
129
		}
131
		}
130
		// save the given repository in the preferences.
132
		// save the given repository in the preferences.
Lines 161-166 Link Here
161
		}
163
		}
162
	}
164
	}
163
165
166
	boolean contains(URL location) {
167
		synchronized (repositoryLock) {
168
			if (repositories == null)
169
				restoreRepositories();
170
			String key = getKey(location);
171
			if (repositories.containsKey(key))
172
				return true;
173
			//try alternate key with different trailing slash
174
			int len = key.length();
175
			if (key.charAt(len - 1) == '_')
176
				key = key.substring(0, len - 1);
177
			else
178
				key = key + '_';
179
			return repositories.containsKey(key);
180
		}
181
	}
182
164
	public IArtifactRequest createDownloadRequest(IArtifactKey key, IPath destination) {
183
	public IArtifactRequest createDownloadRequest(IArtifactKey key, IPath destination) {
165
		return new FileDownloadRequest(key, destination);
184
		return new FileDownloadRequest(key, destination);
166
	}
185
	}

Return to bug 231642