Search in sources :

Example 1 with AbstractComponentsProvider

use of org.talend.core.model.components.AbstractComponentsProvider in project tdi-studio-se by Talend.

the class ComponentsFactory method init.

private void init(boolean duringLogon) {
    // not used anymore
    removeOldComponentsUserFolder();
    long startTime = System.currentTimeMillis();
    // TimeMeasure.display = true;
    // TimeMeasure.displaySteps = true;
    // TimeMeasure.measureActive = true;
    // TimeMeasure.begin("initComponents");
    componentList = Collections.synchronizedSet(new HashSet<IComponent>());
    customComponentList = new HashSet<IComponent>();
    skeletonList = new ArrayList<String>();
    userComponentList = new HashSet<IComponent>();
    String installLocation = new Path(Platform.getConfigurationLocation().getURL().getPath()).toFile().getAbsolutePath();
    componentToProviderMap = new HashMap<IComponent, AbstractComponentsProvider>();
    boolean isNeedClean = !cleanDone && TalendCacheUtils.isSetCleanComponentCache();
    // only check this parameter one time, or it will reinitialize things all the time...
    cleanDone = true;
    isCreated = hasComponentFile(installLocation) && !isNeedClean;
    ComponentsCache cache = ComponentManager.getComponentCache();
    try {
        if (isCreated) {
            // it avoids to reload from disk again even more for commandline at each logon, since it's no use.
            if (cache.getComponentEntryMap().isEmpty()) {
                ComponentsCache loadCache = loadComponentResource(installLocation);
                cache.getComponentEntryMap().putAll(loadCache.getComponentEntryMap());
            }
        } else {
            cache.getComponentEntryMap().clear();
        }
    } catch (IOException e) {
        ExceptionHandler.process(e);
        cache.getComponentEntryMap().clear();
        isCreated = false;
    }
    loadComponentsFromComponentsProviderExtension();
    // TimeMeasure.step("initComponents", "loadComponentsFromProvider");
    // 2.Load Component from extension point: component_definition
    loadComponentsFromExtensions();
    // TimeMeasure.step("initComponents", "loadComponentsFromExtension[joblets?]");
    // will save only if needed.
    ComponentManager.saveResource();
    // init component name map, used to pick specified component immediately
    initComponentNameMap();
    // TimeMeasure.step("initComponents", "createCache");
    //$NON-NLS-1$ //$NON-NLS-2$
    log.debug(componentList.size() + " components loaded in " + (System.currentTimeMillis() - startTime) + " ms");
// TimeMeasure.end("initComponents");
// TimeMeasure.display = false;
// TimeMeasure.displaySteps = false;
// TimeMeasure.measureActive = false;
}
Also used : Path(org.eclipse.core.runtime.Path) ComponentBundleToPath(org.talend.designer.core.model.components.ComponentBundleToPath) AbstractComponentsProvider(org.talend.core.model.components.AbstractComponentsProvider) IComponent(org.talend.core.model.components.IComponent) IOException(java.io.IOException) ComponentsCache(org.talend.core.model.component_cache.ComponentsCache) HashSet(java.util.HashSet)

Example 2 with AbstractComponentsProvider

use of org.talend.core.model.components.AbstractComponentsProvider in project tdi-studio-se by Talend.

the class ComponentsFactory method getComponentResourceBundle.

private ResourceBundle getComponentResourceBundle(IComponent currentComp, String source, String cachedPathSource, AbstractComponentsProvider provider) {
    try {
        AbstractComponentsProvider currentProvider = provider;
        if (currentProvider == null) {
            ComponentsProviderManager componentsProviderManager = ComponentsProviderManager.getInstance();
            Collection<AbstractComponentsProvider> providers = componentsProviderManager.getProviders();
            for (AbstractComponentsProvider curProvider : providers) {
                String path = new Path(curProvider.getInstallationFolder().toString()).toPortableString();
                if (source.startsWith(path)) {
                    // fix for TDI-19889 and TDI-20507 to get the correct component provider
                    if (cachedPathSource != null) {
                        if (path.contains(cachedPathSource)) {
                            currentProvider = curProvider;
                            break;
                        }
                    } else {
                        currentProvider = curProvider;
                        break;
                    }
                }
            }
        }
        String installPath = currentProvider.getInstallationFolder().toString();
        String label = ComponentFilesNaming.getInstance().getBundleName(currentComp.getName(), installPath.substring(installPath.lastIndexOf(IComponentsFactory.COMPONENTS_INNER_FOLDER)));
        if (currentProvider.isUseLocalProvider()) {
            // if the component use local provider as storage (for user / ecosystem components)
            // then get the bundle resource from the current main component provider.
            // note: code here to review later, service like this shouldn't be used...
            ResourceBundle bundle = null;
            IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
            if (brandingService.isPoweredOnlyCamel()) {
                bundle = currentProvider.getResourceBundle(label);
            } else {
                ITisLocalProviderService service = (ITisLocalProviderService) GlobalServiceRegister.getDefault().getService(ITisLocalProviderService.class);
                bundle = service.getResourceBundle(label);
            }
            return bundle;
        } else {
            ResourceBundle bundle = ResourceBundle.getBundle(label, Locale.getDefault(), new ResClassLoader(currentProvider.getClass().getClassLoader()));
            return bundle;
        }
    } catch (IOException e) {
        ExceptionHandler.process(e);
    }
    return null;
}
Also used : AbstractComponentsProvider(org.talend.core.model.components.AbstractComponentsProvider) Path(org.eclipse.core.runtime.Path) ComponentBundleToPath(org.talend.designer.core.model.components.ComponentBundleToPath) ResClassLoader(org.talend.designer.core.ITisLocalProviderService.ResClassLoader) ITisLocalProviderService(org.talend.designer.core.ITisLocalProviderService) ResourceBundle(java.util.ResourceBundle) IBrandingService(org.talend.core.ui.branding.IBrandingService) IOException(java.io.IOException)

Example 3 with AbstractComponentsProvider

use of org.talend.core.model.components.AbstractComponentsProvider in project tdi-studio-se by Talend.

the class ComponentsProviderManager method loadComponentsProvidersFromExtension.

private void loadComponentsProvidersFromExtension() {
    if (providers == null) {
        providers = new ArrayList<AbstractComponentsProvider>();
        IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry();
        //$NON-NLS-1$
        IExtensionPoint extensionPoint = extensionRegistry.getExtensionPoint("org.talend.core.components_provider");
        IExtension[] extensions = extensionPoint.getExtensions();
        for (IExtension extension : extensions) {
            IConfigurationElement[] configurationElements = extension.getConfigurationElements();
            for (IConfigurationElement configurationElement : configurationElements) {
                //$NON-NLS-1$
                String id = configurationElement.getAttribute("id");
                //$NON-NLS-1$
                String folderName = configurationElement.getAttribute("folderName");
                String contributerName = configurationElement.getContributor().getName();
                IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
                if (!brandingService.isPoweredOnlyCamel() && id.equals("org.talend.designer.camel.components.localprovider.CamelLocalComponentsProvider")) {
                    folderName = "camel";
                }
                try {
                    AbstractComponentsProvider componentsProvider = (AbstractComponentsProvider) configurationElement.createExecutableExtension(//$NON-NLS-1$
                    "class");
                    componentsProvider.setId(id);
                    componentsProvider.setFolderName(folderName);
                    componentsProvider.setContributer(contributerName);
                    providers.add(componentsProvider);
                } catch (CoreException e) {
                    //$NON-NLS-1$
                    log.error(Messages.getString("ComponentsProviderManager.unableLoad") + id, e);
                }
            }
        }
    }
}
Also used : AbstractComponentsProvider(org.talend.core.model.components.AbstractComponentsProvider) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) CoreException(org.eclipse.core.runtime.CoreException) IExtension(org.eclipse.core.runtime.IExtension) IBrandingService(org.talend.core.ui.branding.IBrandingService) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 4 with AbstractComponentsProvider

use of org.talend.core.model.components.AbstractComponentsProvider in project tdi-studio-se by Talend.

the class ComponentsFactory method getComponentsProvidersFolder.

@Override
public Map<String, File> getComponentsProvidersFolder() {
    Map<String, File> list = new HashMap<String, File>();
    ComponentsProviderManager componentsProviderManager = ComponentsProviderManager.getInstance();
    for (AbstractComponentsProvider componentsProvider : componentsProviderManager.getProviders()) {
        try {
            // list.add(componentsProvider.getInstallationFolder());
            list.put(componentsProvider.getContributer(), componentsProvider.getInstallationFolder());
        } catch (IOException e) {
            ExceptionHandler.process(e);
            continue;
        }
    }
    return list;
}
Also used : AbstractComponentsProvider(org.talend.core.model.components.AbstractComponentsProvider) HashMap(java.util.HashMap) IOException(java.io.IOException) File(java.io.File)

Example 5 with AbstractComponentsProvider

use of org.talend.core.model.components.AbstractComponentsProvider in project tdi-studio-se by Talend.

the class ComponentsFactory method getComponentsProvidersInfo.

@Override
public List<ComponentProviderInfo> getComponentsProvidersInfo() {
    List<ComponentProviderInfo> list = new ArrayList<ComponentProviderInfo>();
    ComponentsProviderManager componentsProviderManager = ComponentsProviderManager.getInstance();
    for (AbstractComponentsProvider componentsProvider : componentsProviderManager.getProviders()) {
        try {
            ComponentProviderInfo info = new ComponentProviderInfo();
            info.setId(componentsProvider.getId());
            info.setContributer(componentsProvider.getContributer());
            info.setLocation(componentsProvider.getInstallationFolder().getAbsolutePath());
            list.add(info);
        } catch (IOException e) {
            ExceptionHandler.process(e);
            continue;
        }
    }
    return list;
}
Also used : AbstractComponentsProvider(org.talend.core.model.components.AbstractComponentsProvider) ComponentProviderInfo(org.talend.core.model.components.ComponentProviderInfo) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Aggregations

AbstractComponentsProvider (org.talend.core.model.components.AbstractComponentsProvider)7 IOException (java.io.IOException)4 IBrandingService (org.talend.core.ui.branding.IBrandingService)3 CoreException (org.eclipse.core.runtime.CoreException)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 IExtension (org.eclipse.core.runtime.IExtension)2 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)2 IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)2 Path (org.eclipse.core.runtime.Path)2 ComponentsCache (org.talend.core.model.component_cache.ComponentsCache)2 IComponent (org.talend.core.model.components.IComponent)2 ComponentBundleToPath (org.talend.designer.core.model.components.ComponentBundleToPath)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ResourceBundle (java.util.ResourceBundle)1 ComponentProviderInfo (org.talend.core.model.components.ComponentProviderInfo)1 ITisLocalProviderService (org.talend.designer.core.ITisLocalProviderService)1 ResClassLoader (org.talend.designer.core.ITisLocalProviderService.ResClassLoader)1