Search in sources :

Example 66 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project linuxtools by eclipse.

the class PrepareChangeLogAction method outputMultipleEntryChangeLog.

private void outputMultipleEntryChangeLog(PatchFile pf, String[] functionGuess) {
    String defaultContent = null;
    if (pf.isNewfile())
        // $NON-NLS-1$
        defaultContent = Messages.getString("ChangeLog.NewFile");
    else if (pf.isRemovedFile())
        // $NON-NLS-1$
        defaultContent = Messages.getString("ChangeLog.RemovedFile");
    IPath entryPath = pf.getPath();
    String entryFileName = entryPath.toOSString();
    ChangeLogWriter clw = new ChangeLogWriter();
    // load settings from extensions + user pref.
    loadPreferences();
    // get file path from target file
    clw.setEntryFilePath(entryPath.toOSString());
    if (defaultContent != null)
        clw.setDefaultContent(defaultContent);
    // err check. do nothing if no file is being open/edited
    if (clw.getEntryFilePath() == "") {
        return;
    }
    // Check if formatter is internal or inline..if inline, use the
    // current active editor part, otherwise, we must find the external
    // ChangeLog file.
    IEditorPart changelog = null;
    // Before accessing the getFormatterConfigElement, the getFormatContibutor
    // method must be called to initialize.
    extensionManager.getFormatterContributor(clw.getEntryFilePath(), pref_Formatter);
    IConfigurationElement formatterConfigElement = extensionManager.getFormatterConfigElement();
    if (// $NON-NLS-1$
    formatterConfigElement.getAttribute("inFile").equalsIgnoreCase("true")) {
        // $NON-NLS-1$
        try {
            changelog = openEditor((IFile) pf.getResource());
            clw.setFormatter(extensionManager.getFormatterContributor(clw.getEntryFilePath(), pref_Formatter));
        } catch (Exception e) {
        // do nothing changelog will be null
        }
    } else {
        // external changelog
        // get formatter
        clw.setFormatter(extensionManager.getFormatterContributor(entryFileName, pref_Formatter));
        if (pf.isRemovedFile())
            changelog = getChangelogForRemovePath(entryPath);
        else
            changelog = getChangelog(entryFileName);
        // one.
        if (createChangeLog && changelog == null)
            changelog = askChangeLogLocation(entryPath.toOSString());
        if (changelog == null) {
            createChangeLog = false;
            return;
        }
    }
    if ((changelog instanceof ChangeLogEditor) && (!this.newEntryWritten)) {
        ChangeLogEditor editor = (ChangeLogEditor) changelog;
        // saving), treat it as a change log modification
        if (editor.isDirty())
            this.changeLogModified = true;
        editor.setForceNewLogEntry(!this.changeLogModified);
        this.newEntryWritten = true;
    }
    // select changelog
    clw.setChangelog(changelog);
    // write to changelog
    IFormatterChangeLogContrib formatter = clw.getFormatter();
    clw.setDateLine(formatter.formatDateLine(pref_AuthorName, pref_AuthorEmail));
    clw.setChangelogLocation(getDocumentLocation(clw.getChangelog(), true));
    // print multiple changelog entries with different
    // function guess names.  We default to an empty guessed name
    // if we have zero function guess names.
    int numFuncs = 0;
    // $NON-NLS-1$
    clw.setGuessedFName("");
    if (functionGuess.length > 0) {
        for (String guess : functionGuess) {
            if (!guess.trim().equals("")) {
                // $NON-NLS-1$
                ++numFuncs;
                clw.setGuessedFName(guess);
                clw.writeChangeLog();
            }
        }
    }
    // function guesses.
    if (numFuncs == 0) {
        clw.writeChangeLog();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ChangeLogEditor(org.eclipse.linuxtools.internal.changelog.core.editors.ChangeLogEditor) ChangeLogWriter(org.eclipse.linuxtools.internal.changelog.core.ChangeLogWriter) IFormatterChangeLogContrib(org.eclipse.linuxtools.changelog.core.IFormatterChangeLogContrib) IEditorPart(org.eclipse.ui.IEditorPart) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeamException(org.eclipse.team.core.TeamException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 67 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project linuxtools by eclipse.

the class ChangeLogDocumentSetupParticipant method setup.

@Override
public void setup(IDocument document) {
    IExtensionPoint editorExtensions = null;
    IEditorChangeLogContrib editorContrib = null;
    // get editor which is stored in preference.
    IPreferenceStore store = ChangelogPlugin.getDefault().getPreferenceStore();
    String pref_Editor = store.getString(// $NON-NLS-1$
    "IChangeLogConstants.DEFAULT_EDITOR");
    editorExtensions = Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.linuxtools.changelog.core", // $NON-NLS-1$ //$NON-NLS-2$
    "editorContribution");
    if (editorExtensions != null) {
        IConfigurationElement[] elements = editorExtensions.getConfigurationElements();
        for (int i = 0; i < elements.length; i++) {
            if (// $NON-NLS-1$
            elements[i].getName().equals("editor") && (elements[i].getAttribute("name").equals(pref_Editor))) {
                try {
                    // If editor has a special setup routine, use it.
                    IConfigurationElement bob = elements[i];
                    editorContrib = (IEditorChangeLogContrib) bob.createExecutableExtension(// $NON-NLS-1$
                    "class");
                    editorContrib.setup(document);
                } catch (CoreException e) {
                    ChangelogPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e));
                }
            }
        }
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IEditorChangeLogContrib(org.eclipse.linuxtools.changelog.core.IEditorChangeLogContrib) CoreException(org.eclipse.core.runtime.CoreException) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint)

Example 68 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project knime-core by knime.

the class RepositoryManager method readMetanodes.

private void readMetanodes(final IProgressMonitor monitor) {
    // iterate over the meta node config elements
    // and create meta node templates
    IExtension[] metanodeExtensions = getExtensions(ID_META_NODE);
    for (IExtension mnExt : metanodeExtensions) {
        IConfigurationElement[] mnConfigElems = mnExt.getConfigurationElements();
        for (IConfigurationElement mnConfig : mnConfigElems) {
            if (monitor.isCanceled()) {
                return;
            }
            try {
                MetaNodeTemplate metaNode = RepositoryFactory.createMetaNode(mnConfig);
                LOGGER.debug("Found meta node definition '" + metaNode.getID() + "': " + metaNode.getName());
                for (Listener l : m_loadListeners) {
                    l.newMetanode(m_root, metaNode);
                }
                IContainerObject parentContainer = m_root.findContainer(metaNode.getCategoryPath());
                // append the node to the repository root.
                if (parentContainer == null) {
                    LOGGER.warn("Invalid category-path for node " + "contribution: '" + metaNode.getCategoryPath() + "' - adding to root instead");
                    m_root.addChild(metaNode);
                } else {
                    // everything is fine, add the node to its parent
                    // category
                    parentContainer.addChild(metaNode);
                }
            } catch (Throwable t) {
                String message = "MetaNode " + mnConfig.getAttribute("id") + "' from plugin '" + mnConfig.getNamespaceIdentifier() + "' could not be created: " + t.getMessage();
                Bundle bundle = Platform.getBundle(mnConfig.getNamespaceIdentifier());
                if ((bundle == null) || (bundle.getState() != Bundle.ACTIVE)) {
                    // if the plugin is null, the plugin could not
                    // be activated maybe due to a not
                    // activateable plugin
                    // (plugin class cannot be found)
                    message = message + " The corresponding plugin " + "bundle could not be activated!";
                }
                LOGGER.error(message, t);
            }
        }
    }
}
Also used : MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) IExtension(org.eclipse.core.runtime.IExtension) Bundle(org.osgi.framework.Bundle) IContainerObject(org.knime.workbench.repository.model.IContainerObject) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 69 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project knime-core by knime.

the class RepositoryManager method readNodes.

/**
 * @param isInExpertMode
 */
private void readNodes(final IProgressMonitor monitor) {
    // 
    // Second, process the contributed nodes
    // 
    IContainerObject uncategorized = m_root.findContainer("/uncategorized");
    if (uncategorized == null) {
        // this should never happen, but who knows...
        uncategorized = m_root;
    }
    Iterator<IConfigurationElement> it = Stream.of(RepositoryManager.getExtensions(ID_NODE)).flatMap(ext -> Stream.of(ext.getConfigurationElements())).filter(elem -> !"true".equalsIgnoreCase(elem.getAttribute("deprecated"))).iterator();
    while (it.hasNext()) {
        IConfigurationElement elem = it.next();
        if (monitor.isCanceled()) {
            return;
        }
        try {
            NodeTemplate node = RepositoryFactory.createNode(elem);
            LOGGER.debug("Found node extension '" + node.getID() + "': " + node.getName());
            for (Listener l : m_loadListeners) {
                l.newNode(m_root, node);
            }
            m_nodesById.put(node.getID(), node);
            String nodeName = node.getID();
            nodeName = nodeName.substring(nodeName.lastIndexOf('.') + 1);
            // Ask the root to lookup the category-container located at
            // the given path
            IContainerObject parentContainer = m_root.findContainer(node.getCategoryPath());
            // the node to the repository root.
            if (parentContainer == null) {
                LOGGER.coding("Unknown category for node " + node.getID() + " (plugin: " + node.getContributingPlugin() + "): " + node.getCategoryPath() + ". Node will be added to 'Uncategorized' instead");
                uncategorized.addChild(node);
            } else {
                String nodePluginId = elem.getNamespaceIdentifier();
                String categoryPluginId = parentContainer.getContributingPlugin();
                if (categoryPluginId == null) {
                    categoryPluginId = "";
                }
                int secondDotIndex = nodePluginId.indexOf('.', nodePluginId.indexOf('.') + 1);
                if (secondDotIndex == -1) {
                    secondDotIndex = 0;
                }
                if (!parentContainer.isLocked() || nodePluginId.equals(categoryPluginId) || nodePluginId.startsWith("org.knime.") || nodePluginId.startsWith("com.knime.") || nodePluginId.regionMatches(0, categoryPluginId, 0, secondDotIndex)) {
                    // container not locked, or node and category from same plug-in
                    // or the vendor is the same (comparing the first two parts of the plug-in ids)
                    parentContainer.addChild(node);
                } else {
                    LOGGER.coding("Locked category for node " + node.getID() + ": " + node.getCategoryPath() + ". Node will be added to 'Uncategorized' instead");
                    uncategorized.addChild(node);
                }
            }
        } catch (Throwable t) {
            String message = "Node " + elem.getAttribute("factory-class") + "' from plugin '" + elem.getNamespaceIdentifier() + "' could not be created: " + t.getMessage();
            Bundle bundle = Platform.getBundle(elem.getNamespaceIdentifier());
            if ((bundle == null) || (bundle.getState() != Bundle.ACTIVE)) {
                // if the plugin is null, the plugin could not
                // be activated maybe due to a not
                // activateable plugin (plugin class cannot be found)
                message += " The corresponding plugin " + "bundle could not be activated!";
            }
            LOGGER.error(message, t);
        }
    }
// for configuration elements
}
Also used : Arrays(java.util.Arrays) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) FileNativeNodeContainerPersistor(org.knime.core.node.workflow.FileNativeNodeContainerPersistor) Category(org.knime.workbench.repository.model.Category) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) NodeLogger(org.knime.core.node.NodeLogger) Map(java.util.Map) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) Root(org.knime.workbench.repository.model.Root) Bundle(org.osgi.framework.Bundle) IExtension(org.eclipse.core.runtime.IExtension) AbstractContainerObject(org.knime.workbench.repository.model.AbstractContainerObject) NodeFactory(org.knime.core.node.NodeFactory) Iterator(java.util.Iterator) Collection(java.util.Collection) NodeModel(org.knime.core.node.NodeModel) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IRepositoryObject(org.knime.workbench.repository.model.IRepositoryObject) IContainerObject(org.knime.workbench.repository.model.IContainerObject) List(java.util.List) NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) Stream(java.util.stream.Stream) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) DynamicNodeTemplate(org.knime.workbench.repository.model.DynamicNodeTemplate) Platform(org.eclipse.core.runtime.Platform) Comparator(java.util.Comparator) Collections(java.util.Collections) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) DynamicNodeTemplate(org.knime.workbench.repository.model.DynamicNodeTemplate) MetaNodeTemplate(org.knime.workbench.repository.model.MetaNodeTemplate) Bundle(org.osgi.framework.Bundle) IContainerObject(org.knime.workbench.repository.model.IContainerObject) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint)

Example 70 with IConfigurationElement

use of org.eclipse.core.runtime.IConfigurationElement in project knime-core by knime.

the class RepositoryManager method readCategories.

private void readCategories(final IProgressMonitor monitor) {
    // 
    // First, process the contributed categories
    // 
    IExtension[] categoryExtensions = getExtensions(ID_CATEGORY);
    ArrayList<IConfigurationElement> allElements = new ArrayList<IConfigurationElement>();
    for (IExtension ext : categoryExtensions) {
        // iterate through the config elements and create 'Category' objects
        IConfigurationElement[] elements = ext.getConfigurationElements();
        allElements.addAll(Arrays.asList(elements));
    }
    // remove duplicated categories
    removeDuplicatesFromCategories(allElements);
    // sort first by path-depth, so that everything is there in the
    // right order
    Collections.sort(allElements, new Comparator<IConfigurationElement>() {

        @Override
        public int compare(final IConfigurationElement o1, final IConfigurationElement o2) {
            String element1 = o1.getAttribute("path");
            String element2 = o2.getAttribute("path");
            if (element1 == element2) {
                return 0;
            } else if (element1 == null) {
                return -1;
            } else if (element2 == null) {
                return 1;
            } else if (element1.equals(element2)) {
                return 0;
            } else if ("/".equals(element1)) {
                return -1;
            } else if ("/".equals(element2)) {
                return 1;
            } else {
                int countSlashes1 = 0;
                for (int i = 0; i < element1.length(); i++) {
                    if (element1.charAt(i) == '/') {
                        countSlashes1++;
                    }
                }
                int countSlashes2 = 0;
                for (int i = 0; i < element2.length(); i++) {
                    if (element2.charAt(i) == '/') {
                        countSlashes2++;
                    }
                }
                return countSlashes1 - countSlashes2;
            }
        }
    });
    for (IConfigurationElement e : allElements) {
        if (monitor.isCanceled()) {
            return;
        }
        try {
            Category category = RepositoryFactory.createCategory(m_root, e);
            LOGGER.debug("Found category extension '" + category.getID() + "' on path '" + category.getPath() + "'");
            for (Listener l : m_loadListeners) {
                l.newCategory(m_root, category);
            }
        } catch (Exception ex) {
            String message = "Category '" + e.getAttribute("level-id") + "' from plugin '" + e.getDeclaringExtension().getNamespaceIdentifier() + "' could not be created in parent path '" + e.getAttribute("path") + "'.";
            LOGGER.error(message, ex);
        }
    }
}
Also used : Category(org.knime.workbench.repository.model.Category) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) IExtension(org.eclipse.core.runtime.IExtension)

Aggregations

IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)189 CoreException (org.eclipse.core.runtime.CoreException)75 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)64 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)50 ArrayList (java.util.ArrayList)39 IExtension (org.eclipse.core.runtime.IExtension)30 IStatus (org.eclipse.core.runtime.IStatus)24 Status (org.eclipse.core.runtime.Status)24 HashMap (java.util.HashMap)16 HashSet (java.util.HashSet)16 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)11 List (java.util.List)9 Map (java.util.Map)9 Platform (org.eclipse.core.runtime.Platform)9 File (java.io.File)8 Collection (java.util.Collection)8 Stream (java.util.stream.Stream)8 LinkedList (java.util.LinkedList)7 Optional (java.util.Optional)5 IFile (org.eclipse.core.resources.IFile)5