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