Search in sources :

Example 51 with IConfigurationElement

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

the class ProviderFramework method getOrderedConfigElements.

/**
 * Get launch providers for a given type and order them with regards to highest priority first.
 *
 * @param type Type of launch providers requested.
 * @return Array of launch provider configuration elements in prioritized order
 * @since 1.2
 */
public static ArrayList<IConfigurationElement> getOrderedConfigElements(String type) {
    IConfigurationElement[] configs = getConfigurationElements();
    ArrayList<IConfigurationElement> configList = new ArrayList<>();
    for (IConfigurationElement config : configs) {
        if (config.getName().equals("provider")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            String currentType = config.getAttribute("type");
            if (currentType != null && currentType.equals(type)) {
                // $NON-NLS-1$
                String priority = config.getAttribute("priority");
                if (priority != null) {
                    try {
                        Integer.parseInt(priority);
                        configList.add(config);
                    } catch (NumberFormatException e) {
                    // continue
                    }
                }
            }
        }
    }
    Collections.sort(configList, (c1, c2) -> {
        int p1, p2;
        // lowest priority.
        try {
            // $NON-NLS-1$
            p1 = Integer.parseInt(c1.getAttribute("priority"));
            if (p1 <= 0) {
                return 1;
            }
        } catch (NumberFormatException e1) {
            return 1;
        }
        try {
            // $NON-NLS-1$
            p2 = Integer.parseInt(c2.getAttribute("priority"));
            if (p2 <= 0) {
                return -1;
            }
        } catch (NumberFormatException e2) {
            return -1;
        }
        return p1 < p2 ? -1 : 1;
    });
    return configList;
}
Also used : ArrayList(java.util.ArrayList) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint)

Example 52 with IConfigurationElement

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

the class ProviderFramework method getAllProviderNames.

/**
 * Get map of all pairs of names and IDs of profiling providers. This
 * looks through extensions of the extension point
 * <code>org.eclipse.linuxtools.profiling.launch.launchProvider</code>.
 *
 * @return A <code>SortedMap<String, String></code> of all pairs of names and IDs
 * of profiling providers.
 * @since 2.0
 */
public static SortedMap<String, String> getAllProviderNames() {
    SortedMap<String, String> ret = new TreeMap<>();
    IConfigurationElement[] configs = getConfigurationElements();
    for (IConfigurationElement config : configs) {
        if (config.getName().equals("provider")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            String currentId = config.getAttribute("id");
            // $NON-NLS-1$
            String currentName = config.getAttribute("name");
            if (currentName != null && currentId != null) {
                ret.put(currentName, currentId);
            }
        }
    }
    return ret;
}
Also used : TreeMap(java.util.TreeMap) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 53 with IConfigurationElement

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

the class ProviderFramework method getProviderCategories.

/**
 * Get all the profiling categories. This looks through extensions of
 * the extension point <code>org.eclipse.linuxtools.profiling.launch.launchProvider</code>
 * and stores the different categories found.
 *
 * @return A <code>String []</code> of all profiling categories.
 * @since 2.0
 */
public static String[] getProviderCategories() {
    Set<String> ret = new TreeSet<>();
    IConfigurationElement[] configs = getConfigurationElements();
    for (IConfigurationElement config : configs) {
        if (config.getName().equals("provider")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            String currentType = config.getAttribute("type");
            if (currentType != null) {
                ret.add(currentType);
            }
        }
    }
    return ret.toArray(new String[] {});
}
Also used : TreeSet(java.util.TreeSet) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 54 with IConfigurationElement

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

the class ProviderFramework method getTabGroupProviderFromId.

/**
 * Get a profiling tab that is associated with the specified id.
 * This looks through extensions of the extension point
 * <code>org.eclipse.linuxtools.profiling.launch.launchProvider</code> that have a
 * specific id.
 *
 * @param id A unique identifier
 * @return a tab that implements <code>ProfileLaunchConfigurationTabGroup</code>
 * and provides the necessary profiling type, or <code>null</code> if none could be found.
 * @since 2.0
 */
public static ProfileLaunchConfigurationTabGroup getTabGroupProviderFromId(String id) {
    IConfigurationElement[] configs = getConfigurationElements();
    for (IConfigurationElement config : configs) {
        if (config.getName().equals("provider")) {
            // $NON-NLS-1$
            // $NON-NLS-1$
            String currentId = config.getAttribute("id");
            // $NON-NLS-1$
            String tabgroup = config.getAttribute("tabgroup");
            if (currentId != null && tabgroup != null && currentId.equals(id)) {
                try {
                    Object obj = config.createExecutableExtension(// $NON-NLS-1$
                    "tabgroup");
                    if (obj instanceof ProfileLaunchConfigurationTabGroup) {
                        return (ProfileLaunchConfigurationTabGroup) obj;
                    }
                } catch (CoreException e) {
                // continue, perhaps another configuration will succeed
                }
            }
        }
    }
    return null;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ProfileLaunchConfigurationTabGroup(org.eclipse.linuxtools.profiling.launch.ProfileLaunchConfigurationTabGroup) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 55 with IConfigurationElement

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

the class STBinutilsFactoryManager method getBinutilsFactoryImpl.

/**
 * Try to find an extension point matching the given cpu; Then test availability of the tools. If no match, return
 * default binutils factory
 * @param cpu The cpu identifier.
 * @return The factory.
 */
private static ISTBinutilsFactory getBinutilsFactoryImpl(String cpu) {
    try {
        IExtensionRegistry reg = Platform.getExtensionRegistry();
        // $NON-NLS-1$
        IExtensionPoint ep = reg.getExtensionPoint("org.eclipse.linuxtools.binutils.crossCompilerBinutils");
        IExtension[] exts = ep.getExtensions();
        for (IExtension extension : exts) {
            IConfigurationElement[] elems = extension.getConfigurationElements();
            for (IConfigurationElement configurationElement : elems) {
                // $NON-NLS-1$
                String s = configurationElement.getAttribute("CPU");
                if (cpu.equals(s)) {
                    ISTBinutilsFactory factory = (ISTBinutilsFactory) configurationElement.createExecutableExtension(// $NON-NLS-1$
                    "binutilsFactory");
                    if (factory.testAvailability())
                        return factory;
                }
            }
        }
    } catch (CoreException e) {
        Activator.getDefault().getLog().log(e.getStatus());
    }
    if (defaultFactory == null) {
        defaultFactory = new DefaultBinutilsFactory();
    }
    return defaultFactory;
}
Also used : IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) IExtension(org.eclipse.core.runtime.IExtension) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

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