Search in sources :

Example 1 with DescriptorReader

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);
            }
        }
    }
}
Also used : DescriptorMatcher(org.springsource.ide.eclipse.commons.internal.content.core.DescriptorMatcher) Descriptor(org.springsource.ide.eclipse.commons.content.core.util.Descriptor) DescriptorReader(org.springsource.ide.eclipse.commons.content.core.util.DescriptorReader)

Example 2 with DescriptorReader

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();
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) SubMonitor(org.eclipse.core.runtime.SubMonitor) MultiStatus(org.eclipse.core.runtime.MultiStatus) File(java.io.File) DescriptorReader(org.springsource.ide.eclipse.commons.content.core.util.DescriptorReader)

Aggregations

DescriptorReader (org.springsource.ide.eclipse.commons.content.core.util.DescriptorReader)2 File (java.io.File)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 Status (org.eclipse.core.runtime.Status)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 Descriptor (org.springsource.ide.eclipse.commons.content.core.util.Descriptor)1 DescriptorMatcher (org.springsource.ide.eclipse.commons.internal.content.core.DescriptorMatcher)1