~ubuntu-branches/ubuntu/utopic/eclipse-linuxtools/utopic

« back to all changes in this revision

Viewing changes to profiling/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STBinutilsFactoryManager.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2014-05-12 18:11:40 UTC
  • mfrom: (3.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140512181140-w237r3vsah1tmybz
Tags: 2.2.1-1
* New upstream release.
* Refreshed d/patches.
* Removed eclipse-cdt-valgrind-remote package, all its functionality
  is now provided by eclipse-cdt-profiling-framework-remote.
* Added remove-license-feature.patch.
* Bump Standards-Version to 3.9.5.
* Enable eclipse-changelog package.
* Enable eclipse-rpm-editor package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import org.eclipse.core.runtime.Platform;
22
22
import org.eclipse.linuxtools.binutils.Activator;
23
23
 
24
 
 
25
24
/**
26
25
 * This class is on charge of managing "org.eclipse.linuxtools.binutils.crossCompilerBinutils" extension point.
 
26
 * 
27
27
 * @author Xavier Raynaud <xavier.raynaud@st.com>
28
 
 *
 
28
 * 
29
29
 */
30
30
public class STBinutilsFactoryManager {
31
31
 
32
 
        public static final STBinutilsFactoryManager sharedInstance = new STBinutilsFactoryManager();
33
 
        
34
 
        /**
35
 
         * Map of CPU/ISTBinutilsFactory
36
 
         */
37
 
        private final Map<String, ISTBinutilsFactory> map = new HashMap<String, ISTBinutilsFactory>();
38
 
        
39
 
        /**
40
 
         * Default factory
41
 
         */
42
 
        private DefaultBinutilsFactory defaultFactory;
43
 
        
44
 
        /**
45
 
         * Private constructor: this class is implemented as a Singleton
46
 
         */
47
 
        private STBinutilsFactoryManager() {
48
 
        }
49
 
 
50
 
        /**
51
 
         * Try to find an extension point matching the given cpu;
52
 
         * Then test availability of the tools.
53
 
         * If no match, return default binutils factory
54
 
         */
55
 
        private ISTBinutilsFactory getBinutilsFactoryImpl(String cpu) {
56
 
                try {
57
 
                        IExtensionRegistry reg = Platform.getExtensionRegistry();
58
 
                        IExtensionPoint ep = reg.getExtensionPoint("org.eclipse.linuxtools.binutils.crossCompilerBinutils");
59
 
                        IExtension[] exts = ep.getExtensions();
60
 
                        for (IExtension extension : exts) {
61
 
                                IConfigurationElement[] elems = extension.getConfigurationElements();
62
 
                                for (IConfigurationElement configurationElement : elems) {
63
 
                                        String s = configurationElement.getAttribute("CPU");
64
 
                                        if (cpu.equals(s)) {
65
 
                                                ISTBinutilsFactory factory = (ISTBinutilsFactory) configurationElement.createExecutableExtension("binutilsFactory");
66
 
                                                if (factory.testAvailability()) return factory;
67
 
                                        }
68
 
                                }
69
 
                        }
70
 
                } catch (CoreException e) {
71
 
                        Activator.getDefault().getLog().log(e.getStatus());
72
 
                }
73
 
                if (defaultFactory == null) defaultFactory = new DefaultBinutilsFactory();
74
 
                return defaultFactory;
75
 
        }
76
 
        
77
 
        /**
78
 
         * Get a ISTBinutilsFactory matching the given cpu id
79
 
         * Returns the default one if no match.
80
 
         */
81
 
        public ISTBinutilsFactory getBinutilsFactory(String cpu) {
82
 
                ISTBinutilsFactory factory = map.get(cpu);
83
 
                if (factory == null) {
84
 
                        factory = getBinutilsFactoryImpl(cpu);
85
 
                        map.put(cpu, factory);
86
 
                }
87
 
                return factory;
88
 
        }
89
 
        
 
32
    public static final STBinutilsFactoryManager sharedInstance = new STBinutilsFactoryManager();
 
33
 
 
34
    /**
 
35
     * Map of CPU/ISTBinutilsFactory
 
36
     */
 
37
    private final Map<String, ISTBinutilsFactory> map = new HashMap<String, ISTBinutilsFactory>();
 
38
 
 
39
    /**
 
40
     * Default factory
 
41
     */
 
42
    private DefaultBinutilsFactory defaultFactory;
 
43
 
 
44
    /**
 
45
     * Private constructor: this class is implemented as a Singleton
 
46
     */
 
47
    private STBinutilsFactoryManager() {
 
48
    }
 
49
 
 
50
    /**
 
51
     * Try to find an extension point matching the given cpu; Then test availability of the tools. If no match, return
 
52
     * default binutils factory
 
53
     */
 
54
    private ISTBinutilsFactory getBinutilsFactoryImpl(String cpu) {
 
55
        try {
 
56
            IExtensionRegistry reg = Platform.getExtensionRegistry();
 
57
            IExtensionPoint ep = reg.getExtensionPoint("org.eclipse.linuxtools.binutils.crossCompilerBinutils"); //$NON-NLS-1$
 
58
            IExtension[] exts = ep.getExtensions();
 
59
            for (IExtension extension : exts) {
 
60
                IConfigurationElement[] elems = extension.getConfigurationElements();
 
61
                for (IConfigurationElement configurationElement : elems) {
 
62
                    String s = configurationElement.getAttribute("CPU"); //$NON-NLS-1$
 
63
                    if (cpu.equals(s)) {
 
64
                        ISTBinutilsFactory factory = (ISTBinutilsFactory) configurationElement
 
65
                                .createExecutableExtension("binutilsFactory"); //$NON-NLS-1$
 
66
                        if (factory.testAvailability())
 
67
                            return factory;
 
68
                    }
 
69
                }
 
70
            }
 
71
        } catch (CoreException e) {
 
72
            Activator.getDefault().getLog().log(e.getStatus());
 
73
        }
 
74
        if (defaultFactory == null)
 
75
            defaultFactory = new DefaultBinutilsFactory();
 
76
        return defaultFactory;
 
77
    }
 
78
 
 
79
    /**
 
80
     * Get a ISTBinutilsFactory matching the given cpu id Returns the default one if no match.
 
81
     */
 
82
    public ISTBinutilsFactory getBinutilsFactory(String cpu) {
 
83
        ISTBinutilsFactory factory = map.get(cpu);
 
84
        if (factory == null) {
 
85
            factory = getBinutilsFactoryImpl(cpu);
 
86
            map.put(cpu, factory);
 
87
        }
 
88
        return factory;
 
89
    }
 
90
 
90
91
}