|
Lines 13-19
Link Here
|
| 13 |
import java.net.URI; |
13 |
import java.net.URI; |
| 14 |
import java.net.URISyntaxException; |
14 |
import java.net.URISyntaxException; |
| 15 |
import java.util.*; |
15 |
import java.util.*; |
| 16 |
import org.eclipse.core.runtime.*; |
16 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
|
17 |
import org.eclipse.core.runtime.IStatus; |
| 17 |
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository; |
18 |
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository; |
| 18 |
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository; |
19 |
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository; |
| 19 |
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; |
20 |
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; |
|
Lines 22-32
Link Here
|
| 22 |
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; |
23 |
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; |
| 23 |
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; |
24 |
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; |
| 24 |
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; |
25 |
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; |
| 25 |
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; |
26 |
import org.eclipse.equinox.internal.provisional.p2.repository.*; |
| 26 |
import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager; |
27 |
import org.eclipse.osgi.util.NLS; |
| 27 |
|
28 |
|
| 28 |
public abstract class AbstractApplication { |
29 |
public abstract class AbstractApplication { |
|
|
30 |
protected boolean removeUnknownRepositories = true; |
| 29 |
|
31 |
|
|
|
32 |
protected List sourceRepositories = new ArrayList(); |
| 30 |
protected List sourceArtifactRepositories = new ArrayList(); |
33 |
protected List sourceArtifactRepositories = new ArrayList(); |
| 31 |
protected List sourceMetadataRepositories = new ArrayList(); |
34 |
protected List sourceMetadataRepositories = new ArrayList(); |
| 32 |
protected List artifactReposToRemove = new ArrayList(); |
35 |
protected List artifactReposToRemove = new ArrayList(); |
|
Lines 40-45
Link Here
|
| 40 |
private CompositeMetadataRepository compositeMetadataRepository = null; |
43 |
private CompositeMetadataRepository compositeMetadataRepository = null; |
| 41 |
private CompositeArtifactRepository compositeArtifactRepository = null; |
44 |
private CompositeArtifactRepository compositeArtifactRepository = null; |
| 42 |
|
45 |
|
|
|
46 |
/* |
| 47 |
* Add a source metadata repository |
| 48 |
*/ |
| 43 |
public void addSourceMetadataRepository(String location) { |
49 |
public void addSourceMetadataRepository(String location) { |
| 44 |
URI uri = Activator.getURI(location); |
50 |
URI uri = Activator.getURI(location); |
| 45 |
if (uri != null) |
51 |
if (uri != null) |
|
Lines 71-85
Link Here
|
| 71 |
} |
77 |
} |
| 72 |
|
78 |
|
| 73 |
protected void finalizeRepositories() throws ProvisionException { |
79 |
protected void finalizeRepositories() throws ProvisionException { |
| 74 |
IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager(); |
80 |
if (removeUnknownRepositories) { |
| 75 |
for (Iterator iter = artifactReposToRemove.iterator(); iter.hasNext();) |
81 |
IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager(); |
| 76 |
artifactRepositoryManager.removeRepository((URI) iter.next()); |
82 |
for (Iterator iter = artifactReposToRemove.iterator(); iter.hasNext();) |
| 77 |
IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager(); |
83 |
artifactRepositoryManager.removeRepository((URI) iter.next()); |
| 78 |
for (Iterator iter = metadataReposToRemove.iterator(); iter.hasNext();) |
84 |
IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager(); |
| 79 |
metadataRepositoryManager.removeRepository((URI) iter.next()); |
85 |
for (Iterator iter = metadataReposToRemove.iterator(); iter.hasNext();) |
|
|
86 |
metadataRepositoryManager.removeRepository((URI) iter.next()); |
| 87 |
} |
| 80 |
} |
88 |
} |
| 81 |
|
89 |
|
| 82 |
public void initializeRepos(IProgressMonitor progress) throws ProvisionException { |
90 |
public void initializeRepos(IProgressMonitor progress) throws ProvisionException { |
|
|
91 |
for (Iterator iter = sourceRepositories.iterator(); iter.hasNext();) { |
| 92 |
RepositoryDescriptor repo = (RepositoryDescriptor) iter.next(); |
| 93 |
if (repo.isBoth()) { |
| 94 |
sourceArtifactRepositories.add(repo.getRepoLocation()); |
| 95 |
sourceMetadataRepositories.add(repo.getRepoLocation()); |
| 96 |
} else if (repo.isArtifact()) |
| 97 |
sourceArtifactRepositories.add(repo.getRepoLocation()); |
| 98 |
else if (repo.isMetadata()) |
| 99 |
sourceMetadataRepositories.add(repo.getRepoLocation()); |
| 100 |
else |
| 101 |
throw new ProvisionException(NLS.bind(Messages.unknown_repository_type, repo.getRepoLocation())); |
| 102 |
} |
| 103 |
|
| 83 |
IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager(); |
104 |
IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager(); |
| 84 |
if (sourceArtifactRepositories != null && !sourceArtifactRepositories.isEmpty()) { |
105 |
if (sourceArtifactRepositories != null && !sourceArtifactRepositories.isEmpty()) { |
| 85 |
for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();) { |
106 |
for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();) { |
|
Lines 101-117
Link Here
|
| 101 |
} |
122 |
} |
| 102 |
|
123 |
|
| 103 |
processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager); |
124 |
processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager); |
| 104 |
|
|
|
| 105 |
} |
125 |
} |
| 106 |
|
126 |
|
| 107 |
private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException { |
127 |
private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException { |
| 108 |
if (destinationRepos.size() != 2) { |
128 |
RepositoryDescriptor artifactRepoDescriptor = null; |
| 109 |
throw new ProvisionException("Too many or too few destination repositories."); |
129 |
RepositoryDescriptor metadataRepoDescriptor = null; |
| 110 |
} |
130 |
|
| 111 |
RepositoryDescriptor artifactRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_ARTIFACT ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1)); |
131 |
Iterator iter = destinationRepos.iterator(); |
| 112 |
RepositoryDescriptor metadataRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_METADATA ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1)); |
132 |
while (iter.hasNext() && (artifactRepoDescriptor == null || metadataRepoDescriptor == null)) { |
| 113 |
destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager); |
133 |
RepositoryDescriptor repo = (RepositoryDescriptor) iter.next(); |
| 114 |
destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager); |
134 |
if (repo.isArtifact() && artifactRepoDescriptor == null) |
|
|
135 |
artifactRepoDescriptor = repo; |
| 136 |
if (repo.isMetadata() && metadataRepoDescriptor == null) |
| 137 |
metadataRepoDescriptor = repo; |
| 138 |
} |
| 139 |
|
| 140 |
if (artifactRepoDescriptor != null) |
| 141 |
destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager); |
| 142 |
if (metadataRepoDescriptor != null) |
| 143 |
destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager); |
| 144 |
|
| 145 |
if (destinationMetadataRepository == null && destinationArtifactRepository == null) |
| 146 |
throw new ProvisionException(Messages.AbstractApplication_no_valid_destinations); |
| 115 |
} |
147 |
} |
| 116 |
|
148 |
|
| 117 |
private IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException { |
149 |
private IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException { |
|
Lines 119-131
Link Here
|
| 119 |
if (!mgr.contains(toInit.getRepoLocation())) |
151 |
if (!mgr.contains(toInit.getRepoLocation())) |
| 120 |
metadataReposToRemove.add(toInit.getRepoLocation()); |
152 |
metadataReposToRemove.add(toInit.getRepoLocation()); |
| 121 |
IMetadataRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null); |
153 |
IMetadataRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null); |
| 122 |
if (repository != null && repository.isModifiable()) { |
154 |
if (initDestinationRepository(repository, toInit)) |
| 123 |
if (toInit.getName() != null) |
|
|
| 124 |
repository.setName(toInit.getName()); |
| 125 |
if (!toInit.isAppend()) |
| 126 |
repository.removeAll(); |
| 127 |
return repository; |
155 |
return repository; |
| 128 |
} |
|
|
| 129 |
} catch (ProvisionException e) { |
156 |
} catch (ProvisionException e) { |
| 130 |
//fall through and create a new repository below |
157 |
//fall through and create a new repository below |
| 131 |
} |
158 |
} |
|
Lines 133-143
Link Here
|
| 133 |
IMetadataRepository source = null; |
160 |
IMetadataRepository source = null; |
| 134 |
try { |
161 |
try { |
| 135 |
if (toInit.getFormat() != null) |
162 |
if (toInit.getFormat() != null) |
| 136 |
source = mgr.loadRepository(URIUtil.fromString(toInit.getFormat()), 0, null); |
163 |
source = mgr.loadRepository(toInit.getFormat(), 0, null); |
| 137 |
} catch (ProvisionException e) { |
164 |
} catch (ProvisionException e) { |
| 138 |
//Ignore. |
165 |
//Ignore. |
| 139 |
} catch (URISyntaxException e) { |
|
|
| 140 |
//Ignore |
| 141 |
} |
166 |
} |
| 142 |
//This code assumes source has been successfully loaded before this point |
167 |
//This code assumes source has been successfully loaded before this point |
| 143 |
//No existing repository; create a new repository at destinationLocation but with source's attributes. |
168 |
//No existing repository; create a new repository at destinationLocation but with source's attributes. |
|
Lines 152-175
Link Here
|
| 152 |
if (!mgr.contains(toInit.getRepoLocation())) |
177 |
if (!mgr.contains(toInit.getRepoLocation())) |
| 153 |
artifactReposToRemove.add(toInit.getRepoLocation()); |
178 |
artifactReposToRemove.add(toInit.getRepoLocation()); |
| 154 |
IArtifactRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null); |
179 |
IArtifactRepository repository = mgr.loadRepository(toInit.getRepoLocation(), IRepositoryManager.REPOSITORY_HINT_MODIFIABLE, null); |
| 155 |
if (repository != null && repository.isModifiable()) { |
180 |
if (initDestinationRepository(repository, toInit)) |
| 156 |
if (toInit.getName() != null) |
|
|
| 157 |
repository.setName(toInit.getName()); |
| 158 |
if (!toInit.isAppend()) |
| 159 |
repository.removeAll(); |
| 160 |
return repository; |
181 |
return repository; |
| 161 |
} |
|
|
| 162 |
} catch (ProvisionException e) { |
182 |
} catch (ProvisionException e) { |
| 163 |
//fall through and create a new repository below |
183 |
//fall through and create a new repository below |
| 164 |
} |
184 |
} |
| 165 |
IArtifactRepository source = null; |
185 |
IArtifactRepository source = null; |
| 166 |
try { |
186 |
try { |
| 167 |
if (toInit.getFormat() != null) |
187 |
if (toInit.getFormat() != null) |
| 168 |
source = mgr.loadRepository(URIUtil.fromString(toInit.getFormat()), 0, null); |
188 |
source = mgr.loadRepository(toInit.getFormat(), 0, null); |
| 169 |
} catch (ProvisionException e) { |
189 |
} catch (ProvisionException e) { |
| 170 |
//Ignore. |
190 |
//Ignore. |
| 171 |
} catch (URISyntaxException e) { |
|
|
| 172 |
//Ignore |
| 173 |
} |
191 |
} |
| 174 |
//This code assumes source has been successfully loaded before this point |
192 |
//This code assumes source has been successfully loaded before this point |
| 175 |
//No existing repository; create a new repository at destinationLocation but with source's attributes. |
193 |
//No existing repository; create a new repository at destinationLocation but with source's attributes. |
|
Lines 180-185
Link Here
|
| 180 |
return (IArtifactRepository) RepositoryHelper.validDestinationRepository(result); |
198 |
return (IArtifactRepository) RepositoryHelper.validDestinationRepository(result); |
| 181 |
} |
199 |
} |
| 182 |
|
200 |
|
|
|
201 |
private boolean initDestinationRepository(IRepository repository, RepositoryDescriptor descriptor) { |
| 202 |
if (repository != null && repository.isModifiable()) { |
| 203 |
if (descriptor.getName() != null) |
| 204 |
repository.setName(descriptor.getName()); |
| 205 |
if (repository instanceof ICompositeRepository && !descriptor.isAppend()) |
| 206 |
((ICompositeRepository) repository).removeAllChildren(); |
| 207 |
else if (repository instanceof IMetadataRepository && !descriptor.isAppend()) |
| 208 |
((IMetadataRepository) repository).removeAll(); |
| 209 |
else if (repository instanceof IArtifactRepository && !descriptor.isAppend()) |
| 210 |
((IArtifactRepository) repository).removeAll(); |
| 211 |
return true; |
| 212 |
} |
| 213 |
return false; |
| 214 |
} |
| 215 |
|
| 183 |
public IMetadataRepository getCompositeMetadataRepository() { |
216 |
public IMetadataRepository getCompositeMetadataRepository() { |
| 184 |
if (compositeMetadataRepository == null) { |
217 |
if (compositeMetadataRepository == null) { |
| 185 |
try { |
218 |
try { |
|
Lines 197-203
Link Here
|
| 197 |
public IArtifactRepository getCompositeArtifactRepository() { |
230 |
public IArtifactRepository getCompositeArtifactRepository() { |
| 198 |
if (compositeArtifactRepository == null) { |
231 |
if (compositeArtifactRepository == null) { |
| 199 |
try { |
232 |
try { |
| 200 |
compositeArtifactRepository = new CompositeArtifactRepository(new URI("memory:/composite"), "parent metadata repo", null);//$NON-NLS-1$ //$NON-NLS-2$ |
233 |
compositeArtifactRepository = new CompositeArtifactRepository(new URI("memory:/composite"), "parent artifact repo", null);//$NON-NLS-1$ //$NON-NLS-2$ |
| 201 |
} catch (URISyntaxException e) { |
234 |
} catch (URISyntaxException e) { |
| 202 |
//Can't happen |
235 |
//Can't happen |
| 203 |
} |
236 |
} |
|
Lines 213-216
Link Here
|
| 213 |
public void addDestination(RepositoryDescriptor descriptor) { |
246 |
public void addDestination(RepositoryDescriptor descriptor) { |
| 214 |
destinationRepos.add(descriptor); |
247 |
destinationRepos.add(descriptor); |
| 215 |
} |
248 |
} |
|
|
249 |
|
| 250 |
public void addSource(RepositoryDescriptor repo) { |
| 251 |
sourceRepositories.add(repo); |
| 252 |
} |
| 216 |
} |
253 |
} |