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();
}
}
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));
}
}
}
}
}
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);
}
}
}
}
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
}
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);
}
}
}
Aggregations