Lines 10-29
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.equinox.p2.internal.repository.tools; |
11 |
package org.eclipse.equinox.p2.internal.repository.tools; |
12 |
|
12 |
|
13 |
import org.eclipse.equinox.internal.provisional.p2.repository.IRepository; |
|
|
14 |
import org.eclipse.equinox.internal.provisional.p2.repository.IRepositoryManager; |
15 |
|
16 |
import java.net.URI; |
13 |
import java.net.URI; |
17 |
import java.net.URISyntaxException; |
14 |
import java.net.URISyntaxException; |
18 |
import java.util.*; |
15 |
import java.util.*; |
19 |
import org.eclipse.core.runtime.*; |
16 |
import org.eclipse.core.runtime.*; |
20 |
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository; |
17 |
import org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository; |
21 |
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository; |
18 |
import org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository; |
|
|
19 |
import org.eclipse.equinox.internal.p2.repository.helpers.RepositoryHelper; |
22 |
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; |
20 |
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepository; |
23 |
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; |
21 |
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager; |
24 |
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; |
22 |
import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; |
25 |
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; |
23 |
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepository; |
26 |
import org.eclipse.equinox.internal.provisional.p2.metadata.repository.IMetadataRepositoryManager; |
24 |
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.IRepositoryManager; |
27 |
import org.eclipse.osgi.util.NLS; |
27 |
|
28 |
|
28 |
public abstract class AbstractApplication { |
29 |
public abstract class AbstractApplication { |
29 |
|
30 |
|
Lines 82-107
Link Here
|
82 |
public void initializeRepos(IProgressMonitor progress) throws ProvisionException { |
83 |
public void initializeRepos(IProgressMonitor progress) throws ProvisionException { |
83 |
IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager(); |
84 |
IArtifactRepositoryManager artifactRepositoryManager = Activator.getArtifactRepositoryManager(); |
84 |
if (sourceArtifactRepositories != null && !sourceArtifactRepositories.isEmpty()) { |
85 |
if (sourceArtifactRepositories != null && !sourceArtifactRepositories.isEmpty()) { |
85 |
for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();) { |
86 |
for (Iterator iter = sourceArtifactRepositories.iterator(); iter.hasNext();) |
86 |
URI repoLocation = (URI) iter.next(); |
87 |
loadArtifactRepo((URI) iter.next(), artifactRepositoryManager, progress); |
|
|
88 |
} |
89 |
|
90 |
IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager(); |
91 |
if (sourceMetadataRepositories != null && !sourceMetadataRepositories.isEmpty()) { |
92 |
for (Iterator iter = sourceMetadataRepositories.iterator(); iter.hasNext();) |
93 |
loadMetadataRepo((URI) iter.next(), metadataRepositoryManager, progress); |
94 |
} |
95 |
|
96 |
processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager); |
97 |
} |
98 |
|
99 |
private void loadArtifactRepo(URI repoLocation, IArtifactRepositoryManager artifactRepositoryManager, IProgressMonitor progress) throws ProvisionException { |
100 |
try { |
101 |
if (!artifactRepositoryManager.contains(repoLocation)) |
102 |
artifactReposToRemove.add(repoLocation); |
103 |
artifactRepositoryManager.loadRepository(repoLocation, 0, progress); |
104 |
} catch (ProvisionException e) { |
105 |
// Wasn't added, remove from the list |
106 |
artifactReposToRemove.remove(repoLocation); |
107 |
try { |
108 |
// Attempt to help the user |
109 |
repoLocation = RepositoryHelper.fileURIHelper(repoLocation); |
87 |
if (!artifactRepositoryManager.contains(repoLocation)) |
110 |
if (!artifactRepositoryManager.contains(repoLocation)) |
88 |
artifactReposToRemove.add(repoLocation); |
111 |
artifactReposToRemove.add(repoLocation); |
89 |
artifactRepositoryManager.loadRepository(repoLocation, 0, progress); |
112 |
artifactRepositoryManager.loadRepository(repoLocation, 0, progress); |
|
|
113 |
} catch (ProvisionException e2) { |
114 |
throw e; |
90 |
} |
115 |
} |
91 |
} |
116 |
} |
|
|
117 |
} |
92 |
|
118 |
|
93 |
IMetadataRepositoryManager metadataRepositoryManager = Activator.getMetadataRepositoryManager(); |
119 |
private void loadMetadataRepo(URI repoLocation, IMetadataRepositoryManager metadataRepositoryManager, IProgressMonitor progress) throws ProvisionException { |
94 |
if (sourceMetadataRepositories != null && !sourceMetadataRepositories.isEmpty()) { |
120 |
// If the repository is unknown it should be removed before exiting |
95 |
for (Iterator iter = sourceMetadataRepositories.iterator(); iter.hasNext();) { |
121 |
try { |
96 |
URI repoLocation = (URI) iter.next(); |
122 |
if (!metadataRepositoryManager.contains(repoLocation)) |
|
|
123 |
metadataReposToRemove.add(repoLocation); |
124 |
metadataRepositoryManager.loadRepository(repoLocation, 0, progress); |
125 |
} catch (ProvisionException e) { |
126 |
// Wasn't added, remove from the list |
127 |
metadataReposToRemove.remove(repoLocation); |
128 |
try { |
129 |
// Attempt to help the user by modifying the URI |
130 |
repoLocation = RepositoryHelper.fileURIHelper(repoLocation); |
97 |
if (!metadataRepositoryManager.contains(repoLocation)) |
131 |
if (!metadataRepositoryManager.contains(repoLocation)) |
98 |
metadataReposToRemove.add(repoLocation); |
132 |
metadataReposToRemove.add(repoLocation); |
99 |
metadataRepositoryManager.loadRepository(repoLocation, 0, progress); |
133 |
metadataRepositoryManager.loadRepository(repoLocation, 0, progress); |
|
|
134 |
} catch (ProvisionException e2) { |
135 |
// Throw original exception to avoid confusion |
136 |
throw e; |
100 |
} |
137 |
} |
101 |
} |
138 |
} |
102 |
|
|
|
103 |
processDestinationRepos(artifactRepositoryManager, metadataRepositoryManager); |
104 |
|
105 |
} |
139 |
} |
106 |
|
140 |
|
107 |
private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException { |
141 |
private void processDestinationRepos(IArtifactRepositoryManager artifactRepositoryManager, IMetadataRepositoryManager metadataRepositoryManager) throws ProvisionException { |
Lines 110-117
Link Here
|
110 |
} |
144 |
} |
111 |
RepositoryDescriptor artifactRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_ARTIFACT ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1)); |
145 |
RepositoryDescriptor artifactRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_ARTIFACT ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1)); |
112 |
RepositoryDescriptor metadataRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_METADATA ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1)); |
146 |
RepositoryDescriptor metadataRepoDescriptor = ((RepositoryDescriptor) destinationRepos.get(0)).getKind() == IRepository.TYPE_METADATA ? ((RepositoryDescriptor) destinationRepos.get(0)) : ((RepositoryDescriptor) destinationRepos.get(1)); |
113 |
destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager); |
147 |
|
114 |
destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager); |
148 |
try { |
|
|
149 |
destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager); |
150 |
} catch (ProvisionException e) { |
151 |
try { |
152 |
// Assist the user with the URI |
153 |
artifactRepoDescriptor.setLocation(RepositoryHelper.fileURIHelper(artifactRepoDescriptor.getRepoLocation())); |
154 |
destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager); |
155 |
} catch (Exception e2) { |
156 |
throw e; |
157 |
} |
158 |
} catch (UnsupportedOperationException e) { |
159 |
try { |
160 |
// Assist the user with the URI |
161 |
artifactRepoDescriptor.setLocation(RepositoryHelper.fileURIHelper(artifactRepoDescriptor.getRepoLocation())); |
162 |
destinationArtifactRepository = initializeDestination(artifactRepoDescriptor, artifactRepositoryManager); |
163 |
} catch (Exception e2) { |
164 |
throw e; |
165 |
} |
166 |
} |
167 |
|
168 |
try { |
169 |
destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager); |
170 |
} catch (ProvisionException e) { |
171 |
try { |
172 |
// Assist the user with the URI |
173 |
metadataRepoDescriptor.setLocation(RepositoryHelper.fileURIHelper(metadataRepoDescriptor.getRepoLocation())); |
174 |
destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager); |
175 |
} catch (Exception e2) { |
176 |
throw e; |
177 |
} |
178 |
} catch (UnsupportedOperationException e) { |
179 |
try { |
180 |
// Assist the user with the URI |
181 |
metadataRepoDescriptor.setLocation(RepositoryHelper.fileURIHelper(metadataRepoDescriptor.getRepoLocation())); |
182 |
destinationMetadataRepository = initializeDestination(metadataRepoDescriptor, metadataRepositoryManager); |
183 |
} catch (Exception e2) { |
184 |
throw e; |
185 |
} |
186 |
} |
115 |
} |
187 |
} |
116 |
|
188 |
|
117 |
private IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException { |
189 |
private IMetadataRepository initializeDestination(RepositoryDescriptor toInit, IMetadataRepositoryManager mgr) throws ProvisionException { |
Lines 142-147
Link Here
|
142 |
//This code assumes source has been successfully loaded before this point |
214 |
//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. |
215 |
//No existing repository; create a new repository at destinationLocation but with source's attributes. |
144 |
IMetadataRepository result = mgr.createRepository(toInit.getRepoLocation(), toInit.getName() != null ? toInit.getName() : (source != null ? source.getName() : toInit.getRepoLocation().toString()), IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, source != null ? source.getProperties() : null); |
216 |
IMetadataRepository result = mgr.createRepository(toInit.getRepoLocation(), toInit.getName() != null ? toInit.getName() : (source != null ? source.getName() : toInit.getRepoLocation().toString()), IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, source != null ? source.getProperties() : null); |
|
|
217 |
// Ensure destination is modifiable |
218 |
if (!result.isModifiable()) |
219 |
throw new IllegalStateException(NLS.bind(Messages.Mirroring_DestinationNotModifiable, toInit.getRepoLocation())); |
145 |
if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED)) |
220 |
if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED)) |
146 |
result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$ |
221 |
result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$ |
147 |
return result; |
222 |
return result; |
Lines 175-180
Link Here
|
175 |
//No existing repository; create a new repository at destinationLocation but with source's attributes. |
250 |
//No existing repository; create a new repository at destinationLocation but with source's attributes. |
176 |
// TODO for now create a Simple repo by default. |
251 |
// TODO for now create a Simple repo by default. |
177 |
IArtifactRepository result = mgr.createRepository(toInit.getRepoLocation(), toInit.getName() != null ? toInit.getName() : (source != null ? source.getName() : toInit.getRepoLocation().toString()), IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, source != null ? source.getProperties() : null); |
252 |
IArtifactRepository result = mgr.createRepository(toInit.getRepoLocation(), toInit.getName() != null ? toInit.getName() : (source != null ? source.getName() : toInit.getRepoLocation().toString()), IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, source != null ? source.getProperties() : null); |
|
|
253 |
|
254 |
// Ensure destination is modifiable |
255 |
if (!result.isModifiable()) |
256 |
throw new IllegalStateException(NLS.bind(Messages.Mirroring_DestinationNotModifiable, toInit.getRepoLocation())); |
257 |
|
178 |
if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED)) |
258 |
if (toInit.isCompressed() && !result.getProperties().containsKey(IRepository.PROP_COMPRESSED)) |
179 |
result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$ |
259 |
result.setProperty(IRepository.PROP_COMPRESSED, "true"); //$NON-NLS-1$ |
180 |
return result; |
260 |
return result; |