|
Lines 12-28
Link Here
|
| 12 |
|
12 |
|
| 13 |
import java.io.File; |
13 |
import java.io.File; |
| 14 |
import java.io.IOException; |
14 |
import java.io.IOException; |
|
|
15 |
import java.lang.reflect.Field; |
| 15 |
import java.net.URI; |
16 |
import java.net.URI; |
| 16 |
import java.net.URISyntaxException; |
17 |
import java.net.URISyntaxException; |
| 17 |
import junit.framework.Test; |
18 |
import junit.framework.Test; |
| 18 |
import junit.framework.TestSuite; |
19 |
import junit.framework.TestSuite; |
| 19 |
import org.eclipse.core.runtime.IStatus; |
20 |
import org.eclipse.core.runtime.IStatus; |
| 20 |
import org.eclipse.core.runtime.preferences.ConfigurationScope; |
21 |
import org.eclipse.core.runtime.preferences.IPreferencesService; |
| 21 |
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; |
22 |
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; |
|
|
23 |
import org.eclipse.equinox.internal.p2.engine.SimpleProfileRegistry; |
| 22 |
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; |
24 |
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; |
| 23 |
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; |
25 |
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; |
| 24 |
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; |
26 |
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; |
| 25 |
import org.eclipse.equinox.internal.provisional.p2.core.repository.*; |
27 |
import org.eclipse.equinox.internal.provisional.p2.core.repository.*; |
|
|
28 |
import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; |
| 29 |
import org.eclipse.equinox.internal.provisional.p2.engine.IProfileRegistry; |
| 26 |
import org.eclipse.equinox.p2.tests.*; |
30 |
import org.eclipse.equinox.p2.tests.*; |
| 27 |
import org.osgi.framework.BundleException; |
31 |
import org.osgi.framework.BundleException; |
| 28 |
import org.osgi.service.prefs.BackingStoreException; |
32 |
import org.osgi.service.prefs.BackingStoreException; |
|
Lines 99-104
Link Here
|
| 99 |
* file is being overwritten by an update operation, thus losing all repository state. |
103 |
* file is being overwritten by an update operation, thus losing all repository state. |
| 100 |
*/ |
104 |
*/ |
| 101 |
public void testLostArtifactRepositories() { |
105 |
public void testLostArtifactRepositories() { |
|
|
106 |
IProfile profile = getProfile(IProfileRegistry.SELF); |
| 107 |
if (profile == null) { |
| 108 |
if (System.getProperty("eclipse.p2.profile") == null) { |
| 109 |
SimpleProfileRegistry profileRegistry = (SimpleProfileRegistry) ServiceHelper.getService(TestActivator.getContext(), IProfileRegistry.class.getName()); |
| 110 |
try { |
| 111 |
Field selfField = SimpleProfileRegistry.class.getDeclaredField("self"); //$NON-NLS-1$ |
| 112 |
selfField.setAccessible(true); |
| 113 |
Object self = selfField.get(profileRegistry); |
| 114 |
if (self == null) |
| 115 |
selfField.set(profileRegistry, "agent"); |
| 116 |
} catch (Throwable t) { |
| 117 |
fail(); |
| 118 |
} |
| 119 |
} |
| 120 |
profile = createProfile(IProfileRegistry.SELF); |
| 121 |
} |
| 122 |
|
| 102 |
File site = getTestData("Repository", "/testData/artifactRepo/simple/"); |
123 |
File site = getTestData("Repository", "/testData/artifactRepo/simple/"); |
| 103 |
URI location = site.toURI(); |
124 |
URI location = site.toURI(); |
| 104 |
manager.addRepository(location); |
125 |
manager.addRepository(location); |
|
Lines 106-112
Link Here
|
| 106 |
|
127 |
|
| 107 |
//bash the repository preference file (don't try this at home, kids) |
128 |
//bash the repository preference file (don't try this at home, kids) |
| 108 |
final String REPO_BUNDLE = "org.eclipse.equinox.p2.artifact.repository"; |
129 |
final String REPO_BUNDLE = "org.eclipse.equinox.p2.artifact.repository"; |
| 109 |
Preferences prefs = new ConfigurationScope().getNode(REPO_BUNDLE).node("repositories"); |
130 |
IPreferencesService prefService = (IPreferencesService) ServiceHelper.getService(TestActivator.getContext(), IPreferencesService.class.getName()); |
|
|
131 |
Preferences prefs = prefService.getRootNode().node("/profile/_SELF_/" + REPO_BUNDLE + "/repositories"); //$NON-NLS-1$ //$NON-NLS-2$ |
| 110 |
try { |
132 |
try { |
| 111 |
String[] children = prefs.childrenNames(); |
133 |
String[] children = prefs.childrenNames(); |
| 112 |
for (int i = 0; i < children.length; i++) |
134 |
for (int i = 0; i < children.length; i++) |
|
Lines 127-132
Link Here
|
| 127 |
//everybody's happy again |
149 |
//everybody's happy again |
| 128 |
manager = (IArtifactRepositoryManager) ServiceHelper.getService(TestActivator.context, IArtifactRepositoryManager.class.getName()); |
150 |
manager = (IArtifactRepositoryManager) ServiceHelper.getService(TestActivator.context, IArtifactRepositoryManager.class.getName()); |
| 129 |
assertTrue("1.0", manager.contains(location)); |
151 |
assertTrue("1.0", manager.contains(location)); |
|
|
152 |
|
| 153 |
// Clean-up |
| 154 |
try { |
| 155 |
prefService.getRootNode().node("/profile/_SELF_").removeNode(); |
| 156 |
} catch (BackingStoreException e) { |
| 157 |
// Exception can be ignored as we're simply attempting to cleanup for other tests |
| 158 |
} |
| 159 |
|
| 160 |
if (System.getProperty("eclipse.p2.profile") == null) { |
| 161 |
SimpleProfileRegistry profileRegistry = (SimpleProfileRegistry) ServiceHelper.getService(TestActivator.getContext(), IProfileRegistry.class.getName()); |
| 162 |
try { |
| 163 |
Field selfField = SimpleProfileRegistry.class.getDeclaredField("self"); //$NON-NLS-1$ |
| 164 |
selfField.setAccessible(true); |
| 165 |
Object self = selfField.get(profileRegistry); |
| 166 |
if (self.equals("agent")) |
| 167 |
selfField.set(profileRegistry, null); |
| 168 |
} catch (Throwable t) { |
| 169 |
// ignore as we still want to continue tidying up |
| 170 |
} |
| 171 |
} |
| 130 |
} |
172 |
} |
| 131 |
|
173 |
|
| 132 |
public void testNickname() throws ProvisionException { |
174 |
public void testNickname() throws ProvisionException { |