Search in sources :

Example 11 with IDynamicPlugin

use of org.talend.core.runtime.dynamic.IDynamicPlugin in project tbd-studio-se by Talend.

the class DynamicDistributionDetailsForm method initData.

private void initData() {
    try {
        DynamicDistributionSetupData dynConfigData = getDynamicDistributionSetupData();
        IDynamicPlugin originPlugin = dynConfigData.getDynamicPlugin();
        if (originPlugin == originPluginCache) {
            return;
        }
        originPluginCache = originPlugin;
        newDynamicPluginCache = DynamicFactory.getInstance().createPluginFromJson(originPluginCache.toXmlJson().toString());
        IDynamicPluginConfiguration pluginConfiguration = newDynamicPluginCache.getPluginConfiguration();
        String name = (String) pluginConfiguration.getAttribute(DynamicConstants.ATTR_USER_INPUTED_NAME);
        if (StringUtils.isEmpty(name)) {
            name = pluginConfiguration.getName();
        }
        nameCache = name;
        dynamicConfigNameText.setText(name);
        initTableViewData(newDynamicPluginCache);
    } catch (Exception e) {
        ExceptionHandler.process(e);
        String message = e.getMessage();
        if (StringUtils.isEmpty(message)) {
            // $NON-NLS-1$
            message = Messages.getString("ExceptionDialog.message.empty");
        }
        // $NON-NLS-1$
        ExceptionMessageDialog.openError(getShell(), Messages.getString("ExceptionDialog.title"), message, e);
    }
}
Also used : IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) DynamicDistributionSetupData(org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 12 with IDynamicPlugin

use of org.talend.core.runtime.dynamic.IDynamicPlugin in project tbd-studio-se by Talend.

the class DynamicDistributionPreferenceForm method refreshVersionList.

private void refreshVersionList(IDynamicMonitor monitor) {
    try {
        IStructuredSelection selection = (IStructuredSelection) distributionCombo.getSelection();
        if (selection != null) {
            String selectedObject = (String) selection.getFirstElement();
            if (selectedObject != null) {
                IDynamicDistributionsGroup dynDistriGroup = DynamicDistributionManager.getInstance().getDynamicDistributionGroup(selectedObject);
                if (dynDistriGroup == null) {
                    throw new Exception(// $NON-NLS-1$
                    Messages.getString(// $NON-NLS-1$
                    "DynamicDistributionPreferenceForm.exception.noDistributionGroupFound", dynDistriGroup));
                }
                List<IDynamicPlugin> dynamicPlugins = new LinkedList<>();
                List<IDynamicPlugin> allBuiltinDynamicPlugins = dynDistriGroup.getAllBuiltinDynamicPlugins(monitor);
                if (allBuiltinDynamicPlugins != null && !allBuiltinDynamicPlugins.isEmpty()) {
                    dynamicPlugins.addAll(allBuiltinDynamicPlugins);
                }
                List<IDynamicPlugin> allUsersDynamicPlugins = DynamicDistributionManager.getInstance().getAllUsersDynamicPlugins(monitor);
                if (allUsersDynamicPlugins != null && !allUsersDynamicPlugins.isEmpty()) {
                    List<IDynamicPlugin> tempDynamicPlugins = dynDistriGroup.filterDynamicPlugins(allUsersDynamicPlugins, monitor);
                    if (tempDynamicPlugins != null && !tempDynamicPlugins.isEmpty()) {
                        dynamicPlugins.addAll(tempDynamicPlugins);
                    }
                }
                Collections.sort(dynamicPlugins, Collections.reverseOrder(new DynamicPluginComparator()));
                versionCombo.setInput(dynamicPlugins);
                if (!dynamicPlugins.isEmpty()) {
                    versionCombo.setSelection(new StructuredSelection(dynamicPlugins.get(0)));
                }
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : IDynamicDistributionsGroup(org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup) IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DynamicPluginComparator(org.talend.hadoop.distribution.dynamic.comparator.DynamicPluginComparator) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) LinkedList(java.util.LinkedList)

Example 13 with IDynamicPlugin

use of org.talend.core.runtime.dynamic.IDynamicPlugin in project tbd-studio-se by Talend.

the class AbstractDynamicDistribution method getAllBuiltinDynamicPlugins.

@Override
public List<IDynamicPlugin> getAllBuiltinDynamicPlugins(IDynamicMonitor monitor) throws Exception {
    if (builtinPluginsCache != null) {
        return builtinPluginsCache;
    }
    List<IDynamicPlugin> dynamicPlugins = new ArrayList<>();
    Bundle bundle = getBundle();
    Enumeration<URL> entries = bundle.findEntries(getBuiltinFolderPath(), null, true);
    if (entries != null) {
        String curProjTechName = null;
        Project curProject = ProjectManager.getInstance().getCurrentProject();
        if (curProject != null) {
            curProjTechName = curProject.getTechnicalLabel();
        }
        while (entries.hasMoreElements()) {
            try {
                URL curUrl = entries.nextElement();
                if (curUrl != null) {
                    String builtinDistributionPath = FileLocator.toFileURL(curUrl).getPath();
                    String jsonContent = DynamicServiceUtil.readFile(new File(builtinDistributionPath));
                    IDynamicPlugin dynamicPlugin = DynamicFactory.getInstance().createPluginFromJson(jsonContent);
                    IDynamicPluginConfiguration pluginConfiguration = dynamicPlugin.getPluginConfiguration();
                    // pluginConfiguration.setAttribute(DynamicDistriConfigAdapter.ATTR_FILE_PATH,
                    // builtinDistributionPath);
                    pluginConfiguration.setAttribute(DynamicConstants.ATTR_IS_BUILTIN, Boolean.TRUE.toString());
                    pluginConfiguration.setAttribute(DynamicConstants.ATTR_PROJECT_TECHNICAL_NAME, curProjTechName);
                    dynamicPlugins.add(dynamicPlugin);
                }
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
    }
    builtinPluginsCache = dynamicPlugins;
    return builtinPluginsCache;
}
Also used : Project(org.talend.core.model.general.Project) IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) File(java.io.File) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration) URL(java.net.URL)

Example 14 with IDynamicPlugin

use of org.talend.core.runtime.dynamic.IDynamicPlugin in project tbd-studio-se by Talend.

the class AbstractDynamicDistribution method buildDynamicPlugin.

@Override
public IDynamicPlugin buildDynamicPlugin(IDynamicMonitor monitor, DynamicConfiguration configuration) throws Exception {
    String distribution = configuration.getDistribution();
    if (!StringUtils.equals(getDistributionName(), distribution)) {
        throw new Exception("only support to build dynamic plugin of " + getDistributionName() + " instead of " + distribution);
    }
    String version = configuration.getVersion();
    TemplateBean bestTemplateBean = getCompatibleTemplate(monitor, version);
    // normally bestTemplateBean can't be null here
    DynamicTemplateAdapter templateAdapter = new DynamicTemplateAdapter(bestTemplateBean, configuration);
    templateAdapter.adapt(monitor);
    IDynamicPlugin dynamicPlugin = templateAdapter.getDynamicPlugin();
    return dynamicPlugin;
}
Also used : IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) TemplateBean(org.talend.hadoop.distribution.dynamic.bean.TemplateBean) DynamicTemplateAdapter(org.talend.hadoop.distribution.dynamic.adapter.DynamicTemplateAdapter)

Example 15 with IDynamicPlugin

use of org.talend.core.runtime.dynamic.IDynamicPlugin in project tbd-studio-se by Talend.

the class AbstractDynamicDistribution method register.

@Override
public void register(IDynamicPlugin dynamicPlugin, IDynamicMonitor monitor) throws Exception {
    DynamicDistributionManager dynamicDistributionManager = DynamicDistributionManager.getInstance();
    IDynamicPlugin copiedDynamicPlugin = DynamicFactory.getInstance().createPluginFromJson(dynamicPlugin.toXmlJson().toString());
    Project project = ProjectManager.getInstance().getProjectFromProjectTechLabel((String) copiedDynamicPlugin.getPluginConfiguration().getAttribute(DynamicConstants.ATTR_PROJECT_TECHNICAL_NAME));
    IDynamicDistributionPreference dynamicDistributionPreference = dynamicDistributionManager.getDynamicDistributionGroup(getDistributionName()).getDynamicDistributionPreference(project);
    Bundle bundle = getBundle();
    DynamicPluginAdapter pluginAdapter = new DynamicPluginAdapter(copiedDynamicPlugin, dynamicDistributionPreference, bundle);
    pluginAdapter.adapt();
    IDynamicPluginConfiguration pluginConfiguration = pluginAdapter.getPluginConfiguration();
    String id = pluginConfiguration.getId();
    try {
        IDynamicDistributionTemplate existingTemplate = registedDistribution.get(id);
        if (existingTemplate != null) {
            unloadDistribution(existingTemplate, true);
            DynamicPluginAdapter existingPluginAdapter = existingTemplate.getPluginAdapter();
            IDynamicPluginConfiguration existingPluginConfig = existingPluginAdapter.getPluginConfiguration();
            String existingProjectName = (String) existingPluginConfig.getAttribute(DynamicConstants.ATTR_PROJECT_TECHNICAL_NAME);
            ExceptionHandler.log("Dynamic distribution: " + existingProjectName + "/" + id + " already exists, unloaded the old one and reload the new one");
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    boolean isBuiltin = Boolean.parseBoolean((String) pluginConfiguration.getAttribute(DynamicConstants.ATTR_IS_BUILTIN));
    if (isBuiltin) {
        // $NON-NLS-1$
        pluginConfiguration.setName(Messages.getString("DynamicDistribution.name.builtin", pluginConfiguration.getName()));
    } else {
        Project currentProject = ProjectManager.getInstance().getCurrentProject();
        String curProjLabel = currentProject.getTechnicalLabel();
        String projLabel = (String) pluginConfiguration.getAttribute(DynamicConstants.ATTR_PROJECT_TECHNICAL_NAME);
        if (StringUtils.equals(curProjLabel, projLabel)) {
            // $NON-NLS-1$
            projLabel = Messages.getString("DynamicDistribution.name.current");
        }
        pluginConfiguration.setName(// $NON-NLS-1$
        Messages.getString(// $NON-NLS-1$
        "DynamicDistribution.name.project", // $NON-NLS-1$
        pluginConfiguration.getName(), projLabel));
    }
    IDynamicDistributionTemplate distributionTemplate = initTemplate(pluginAdapter, monitor);
    registedDistribution.put(pluginConfiguration.getId(), distributionTemplate);
    distributionTemplate.registOsgiServices();
    if (Boolean.getBoolean(PROP_LOAD_DYNAMIC_DISTRIBUTION_MODULE)) {
        distributionTemplate.registPluginExtensions();
    }
}
Also used : Project(org.talend.core.model.general.Project) IDynamicDistributionPreference(org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference) DynamicPluginAdapter(org.talend.hadoop.distribution.dynamic.adapter.DynamicPluginAdapter) IDynamicDistributionTemplate(org.talend.hadoop.distribution.dynamic.template.IDynamicDistributionTemplate) IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) Bundle(org.osgi.framework.Bundle) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)

Aggregations

IDynamicPlugin (org.talend.core.runtime.dynamic.IDynamicPlugin)25 IDynamicPluginConfiguration (org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)16 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 DummyDynamicMonitor (org.talend.designer.maven.aether.DummyDynamicMonitor)6 IDynamicMonitor (org.talend.designer.maven.aether.IDynamicMonitor)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 LinkedList (java.util.LinkedList)4 Project (org.talend.core.model.general.Project)4 DynamicPluginAdapter (org.talend.hadoop.distribution.dynamic.adapter.DynamicPluginAdapter)4 DynamicDistributionSetupData (org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData)4 File (java.io.File)3 LoginException (org.talend.commons.exception.LoginException)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 IDynamicDistributionsGroup (org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup)3 ArrayList (java.util.ArrayList)2 IProject (org.eclipse.core.resources.IProject)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 Bundle (org.osgi.framework.Bundle)2 DynamicPluginComparator (org.talend.hadoop.distribution.dynamic.comparator.DynamicPluginComparator)2 IDynamicDistributionPreference (org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference)2