use of org.springsource.ide.eclipse.commons.content.core.util.DescriptorReader in project eclipse-integration-commons by spring-projects.
the class ContentManager method read.
private void read(File file) throws CoreException {
DescriptorMatcher matcher = new DescriptorMatcher(this);
DescriptorReader reader = new DescriptorReader();
reader.read(file);
List<Descriptor> descriptors = reader.getDescriptors();
for (Descriptor descriptor : descriptors) {
if (!matcher.match(descriptor)) {
continue;
}
ContentItem item = itemById.get(descriptor.getId());
if (item == null) {
item = createItem(descriptor);
if (item != null) {
itemById.put(item.getId(), item);
}
}
if (item != null) {
if (descriptor.isLocal()) {
item.setLocalDescriptor(descriptor);
} else {
item.setRemoteDescriptor(descriptor);
}
}
}
}
use of org.springsource.ide.eclipse.commons.content.core.util.DescriptorReader in project eclipse-integration-commons by spring-projects.
the class ContentManager method refresh.
/**
* Refreshes the list of descriptors, and persists them in the state file.
* It then re-initialises all the content items.
* @param monitor
* @param shouldDownloadRemotes
* @param bundle optional. can be null
* @return
*/
public IStatus refresh(IProgressMonitor monitor, boolean shouldDownloadRemotes) {
File targetFile = getStateFile();
Assert.isNotNull(targetFile, "stateFile not initialized");
isRefreshing = true;
SubMonitor progress = SubMonitor.convert(monitor, 100);
try {
progress.beginTask("Refreshing", 200);
MultiStatus result = new MultiStatus(ContentPlugin.PLUGIN_ID, 0, "Results of template project refresh:", null);
DescriptorReader reader = new DescriptorReader();
if (shouldDownloadRemotes) {
markLocalTemplatesAsLocal(progress, result, reader);
for (String descriptorLocation : getRemoteDescriptorLocations()) {
// remote descriptor
try {
if (descriptorLocation != null && descriptorLocation.length() > 0) {
readFromUrl(reader, descriptorLocation, progress.newChild(70));
}
} catch (CoreException e) {
String message = NLS.bind("Error while downloading or parsing descriptors file ''{0}'':\n\n{1}", descriptorLocation, e);
result.add(new Status(IStatus.ERROR, ContentPlugin.PLUGIN_ID, message, e));
}
}
} else {
try {
reader.read(targetFile);
} catch (CoreException e) {
String message = NLS.bind("Failed to store updated descriptors to ''{0}''", targetFile.getAbsolutePath());
result.add(new Status(IStatus.ERROR, ContentPlugin.PLUGIN_ID, message, e));
}
markLocalTemplatesAsLocal(progress, result, reader);
}
// store on disk
try {
if (result.isOK()) {
reader.write(targetFile);
init();
}
} catch (CoreException e) {
String message = NLS.bind("Failed to store updated descriptors to ''{0}''", targetFile.getAbsolutePath());
result.add(new Status(IStatus.ERROR, ContentPlugin.PLUGIN_ID, message, e));
}
if (result.isOK()) {
isDirty = false;
}
return result;
} finally {
isRefreshing = false;
progress.done();
}
}
Aggregations