|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2008, 2009 Code 9 and others. All rights reserved. This |
2 |
* Copyright (c) 2008, 2010 Code 9 and others. All rights reserved. This |
| 3 |
* program and the accompanying materials are made available under the terms of |
3 |
* program and the accompanying materials are made available under the terms of |
| 4 |
* the Eclipse Public License v1.0 which accompanies this distribution, and is |
4 |
* the Eclipse Public License v1.0 which accompanies this distribution, and is |
| 5 |
* available at http://www.eclipse.org/legal/epl-v10.html |
5 |
* available at http://www.eclipse.org/legal/epl-v10.html |
|
Lines 27-32
Link Here
|
| 27 |
|
27 |
|
| 28 |
public class Publisher { |
28 |
public class Publisher { |
| 29 |
static final public String PUBLISH_PACK_FILES_AS_SIBLINGS = "publishPackFilesAsSiblings"; //$NON-NLS-1$ |
29 |
static final public String PUBLISH_PACK_FILES_AS_SIBLINGS = "publishPackFilesAsSiblings"; //$NON-NLS-1$ |
|
|
30 |
private static final long SERVICE_TIMEOUT = 5000; |
| 30 |
|
31 |
|
| 31 |
private IPublisherInfo info; |
32 |
private IPublisherInfo info; |
| 32 |
private IPublisherResult results; |
33 |
private IPublisherResult results; |
|
Lines 56-62
Link Here
|
| 56 |
} |
57 |
} |
| 57 |
|
58 |
|
| 58 |
// the given repo location is not an existing repo so we have to create something |
59 |
// the given repo location is not an existing repo so we have to create something |
| 59 |
IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME); |
60 |
IMetadataRepositoryManager manager = getService(agent, IMetadataRepositoryManager.SERVICE_NAME); |
| 60 |
String repositoryName = name == null ? location + " - metadata" : name; //$NON-NLS-1$ |
61 |
String repositoryName = name == null ? location + " - metadata" : name; //$NON-NLS-1$ |
| 61 |
IMetadataRepository result = manager.createRepository(location, repositoryName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); |
62 |
IMetadataRepository result = manager.createRepository(location, repositoryName, IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); |
| 62 |
if (result != null) { |
63 |
if (result != null) { |
|
Lines 71-84
Link Here
|
| 71 |
|
72 |
|
| 72 |
/** |
73 |
/** |
| 73 |
* Load a metadata repository from the given location. |
74 |
* Load a metadata repository from the given location. |
| 74 |
* @param location the URI location of the repo |
75 |
* @param location the URI location of the repository |
| 75 |
* @param modifiable whether to ask the manager for a modifiable repository |
76 |
* @param modifiable whether to ask the manager for a modifiable repository |
| 76 |
* @param removeFromManager remove the loaded repository from the manager if it wasn't already loaded |
77 |
* @param removeFromManager remove the loaded repository from the manager if it wasn't already loaded |
| 77 |
* @return the loaded repository |
78 |
* @return the loaded repository |
| 78 |
* @throws ProvisionException |
79 |
* @throws ProvisionException |
| 79 |
*/ |
80 |
*/ |
| 80 |
public static IMetadataRepository loadMetadataRepository(IProvisioningAgent agent, URI location, boolean modifiable, boolean removeFromManager) throws ProvisionException { |
81 |
public static IMetadataRepository loadMetadataRepository(IProvisioningAgent agent, URI location, boolean modifiable, boolean removeFromManager) throws ProvisionException { |
| 81 |
IMetadataRepositoryManager manager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME); |
82 |
IMetadataRepositoryManager manager = getService(agent, IMetadataRepositoryManager.SERVICE_NAME); |
| 82 |
boolean existing = manager.contains(location); |
83 |
boolean existing = manager.contains(location); |
| 83 |
|
84 |
|
| 84 |
IMetadataRepository result = manager.loadRepository(location, modifiable ? IRepositoryManager.REPOSITORY_HINT_MODIFIABLE : 0, null); |
85 |
IMetadataRepository result = manager.loadRepository(location, modifiable ? IRepositoryManager.REPOSITORY_HINT_MODIFIABLE : 0, null); |
|
Lines 114-120
Link Here
|
| 114 |
//fall through and create a new repository |
115 |
//fall through and create a new repository |
| 115 |
} |
116 |
} |
| 116 |
|
117 |
|
| 117 |
IArtifactRepositoryManager manager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME); |
118 |
IArtifactRepositoryManager manager = getService(agent, IArtifactRepositoryManager.SERVICE_NAME); |
| 118 |
String repositoryName = name != null ? name : location + " - artifacts"; //$NON-NLS-1$ |
119 |
String repositoryName = name != null ? name : location + " - artifacts"; //$NON-NLS-1$ |
| 119 |
IArtifactRepository result = manager.createRepository(location, repositoryName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); |
120 |
IArtifactRepository result = manager.createRepository(location, repositoryName, IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, null); |
| 120 |
if (result != null) { |
121 |
if (result != null) { |
|
Lines 131-144
Link Here
|
| 131 |
|
132 |
|
| 132 |
/** |
133 |
/** |
| 133 |
* Load an artifact repository from the given location. |
134 |
* Load an artifact repository from the given location. |
| 134 |
* @param location the URI location of the repo |
135 |
* @param location the URI location of the repository |
| 135 |
* @param modifiable whether to ask the manager for a modifiable repository |
136 |
* @param modifiable whether to ask the manager for a modifiable repository |
| 136 |
* @param removeFromManager remove the loaded repository from the manager if it wasn't already loaded |
137 |
* @param removeFromManager remove the loaded repository from the manager if it wasn't already loaded |
| 137 |
* @return the loaded repository |
138 |
* @return the loaded repository |
| 138 |
* @throws ProvisionException |
139 |
* @throws ProvisionException |
| 139 |
*/ |
140 |
*/ |
| 140 |
public static IArtifactRepository loadArtifactRepository(IProvisioningAgent agent, URI location, boolean modifiable, boolean removeFromManager) throws ProvisionException { |
141 |
public static IArtifactRepository loadArtifactRepository(IProvisioningAgent agent, URI location, boolean modifiable, boolean removeFromManager) throws ProvisionException { |
| 141 |
IArtifactRepositoryManager manager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME); |
142 |
IArtifactRepositoryManager manager = getService(agent, IArtifactRepositoryManager.SERVICE_NAME); |
| 142 |
boolean existing = manager.contains(location); |
143 |
boolean existing = manager.contains(location); |
| 143 |
|
144 |
|
| 144 |
IArtifactRepository result = manager.loadRepository(location, modifiable ? IRepositoryManager.REPOSITORY_HINT_MODIFIABLE : 0, null); |
145 |
IArtifactRepository result = manager.loadRepository(location, modifiable ? IRepositoryManager.REPOSITORY_HINT_MODIFIABLE : 0, null); |
|
Lines 152-157
Link Here
|
| 152 |
results = new PublisherResult(); |
153 |
results = new PublisherResult(); |
| 153 |
} |
154 |
} |
| 154 |
|
155 |
|
|
|
156 |
/** |
| 157 |
* Obtains a service from the agent, waiting for a reasonable timeout period |
| 158 |
* if the service is not yet available. This method never returns <code>null</code>; |
| 159 |
* an exception is thrown if the service could not be obtained. |
| 160 |
* |
| 161 |
* @param <T> The type of the service to return |
| 162 |
* @param agent The agent to obtain the service from |
| 163 |
* @param serviceName The name of the service to obtain |
| 164 |
* @return The service instance |
| 165 |
*/ |
| 166 |
@SuppressWarnings("unchecked") |
| 167 |
protected static <T> T getService(IProvisioningAgent agent, String serviceName) { |
| 168 |
T service = (T) agent.getService(serviceName); |
| 169 |
if (service != null) |
| 170 |
return service; |
| 171 |
long start = System.currentTimeMillis(); |
| 172 |
do { |
| 173 |
try { |
| 174 |
Thread.sleep(100); |
| 175 |
} catch (InterruptedException e) { |
| 176 |
//ignore and keep waiting |
| 177 |
} |
| 178 |
service = (T) agent.getService(serviceName); |
| 179 |
if (service != null) |
| 180 |
return service; |
| 181 |
} while ((System.currentTimeMillis() - start) < SERVICE_TIMEOUT); |
| 182 |
//could not obtain the service |
| 183 |
throw new IllegalStateException("Unable to obtain required service: " + serviceName); //$NON-NLS-1$ |
| 184 |
} |
| 185 |
|
| 155 |
public Publisher(IPublisherInfo info, IPublisherResult results) { |
186 |
public Publisher(IPublisherInfo info, IPublisherResult results) { |
| 156 |
this.info = info; |
187 |
this.info = info; |
| 157 |
this.results = results; |
188 |
this.results = results; |