use of org.talend.core.runtime.dynamic.IDynamicPluginConfiguration in project tbd-studio-se by Talend.
the class AbstractDynamicDistributionsGroup method unregister.
@Override
public void unregister(IDynamicPlugin dynamicPlugin, IDynamicMonitor monitor, boolean reloadLibCache) throws Exception {
boolean unregisted = false;
IDynamicPluginConfiguration pluginConfiguration = dynamicPlugin.getPluginConfiguration();
String templateId = pluginConfiguration.getTemplateId();
IDynamicDistribution dynamicDistribution = getDynamicDistributionForId(templateId, monitor);
if (dynamicDistribution != null) {
dynamicDistribution.unregister(dynamicPlugin, monitor, reloadLibCache);
unregisted = true;
}
if (!unregisted) {
throw new Exception("No dynamic distribution serivce found for " + pluginConfiguration.getTemplateId());
}
}
use of org.talend.core.runtime.dynamic.IDynamicPluginConfiguration in project tbd-studio-se by Talend.
the class DynamicTemplateAdapter method adapt.
public void adapt(IDynamicMonitor monitor) throws Exception {
DynamicDistributionUtils.checkCancelOrNot(monitor);
resolve();
TemplateBean templateBean = getTemplateBean();
DynamicConfiguration configuration = getConfiguration();
// use id instead of version
templateBean.setDynamicVersion(configuration.getId());
DynamicDistributionManager dynamicDistributionManager = DynamicDistributionManager.getInstance();
IDependencyResolver dependencyResolver = dynamicDistributionManager.getDependencyResolver(configuration);
dynamicPlugin = DynamicFactory.getInstance().createDynamicPlugin();
distriConfigAdapter = new DynamicDistribConfigAdapter(templateBean, configuration);
IDynamicPluginConfiguration pluginConfiguration = distriConfigAdapter.adapt(monitor);
dynamicPlugin.setPluginConfiguration(pluginConfiguration);
moduleBeanAdapterMap = new HashMap<>();
moduleGroupBeanAdapterMap = new HashMap<>();
DynamicLibraryNeededExtensionAdaper libNeededExtAdapter = new DynamicLibraryNeededExtensionAdaper(templateBean, configuration, dependencyResolver, moduleBeanAdapterMap, moduleGroupBeanAdapterMap);
libNeededExtAdapter.enableMultiThread(!Boolean.getBoolean(PROPERTY_DISABLE_MULTI_THTREAD));
IDynamicExtension dynamicLibNeededExtension = libNeededExtAdapter.adapt(monitor);
dynamicPlugin.addExtension(dynamicLibNeededExtension);
DynamicClassLoaderExtensionAdaper clsLoaderAdapter = new DynamicClassLoaderExtensionAdaper(templateBean, configuration, moduleGroupBeanAdapterMap);
IDynamicExtension dynamicClsLoaderExtension = clsLoaderAdapter.adapt(monitor);
dynamicPlugin.addExtension(dynamicClsLoaderExtension);
}
use of org.talend.core.runtime.dynamic.IDynamicPluginConfiguration 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();
}
}
use of org.talend.core.runtime.dynamic.IDynamicPluginConfiguration in project tbd-studio-se by Talend.
the class DynamicDistributionManager method getAllUsersDynamicPluginsForProject.
public List<IDynamicPlugin> getAllUsersDynamicPluginsForProject(Project project, IDynamicMonitor monitor) throws Exception {
IProject eProject = ResourceUtils.getProject(project);
IFolder usersFolder = ResourceUtils.getFolder(eProject, getUserStoragePath(), false);
if (usersFolder == null || !usersFolder.exists()) {
return null;
}
List<IDynamicPlugin> dynamicPlugins = new ArrayList<>();
String absoluteFolderPath = usersFolder.getLocation().toPortableString();
File folder = new File(absoluteFolderPath);
List<String> files = getAllFiles(folder);
if (files != null && 0 < files.size()) {
String projTechName = project.getTechnicalLabel();
for (String absolutePath : files) {
try {
String jsonContent = DynamicServiceUtil.readFile(new File(absolutePath));
IDynamicPlugin dynamicPlugin = DynamicFactory.getInstance().createPluginFromJson(jsonContent);
IDynamicPluginConfiguration pluginConfiguration = dynamicPlugin.getPluginConfiguration();
pluginConfiguration.setAttribute(DynamicConstants.ATTR_FILE_PATH, absolutePath);
pluginConfiguration.setAttribute(DynamicConstants.ATTR_IS_BUILTIN, Boolean.FALSE.toString());
pluginConfiguration.setAttribute(DynamicConstants.ATTR_PROJECT_TECHNICAL_NAME, projTechName);
dynamicPlugins.add(dynamicPlugin);
} catch (Exception e) {
ExceptionHandler.process(e);
}
}
}
return dynamicPlugins;
}
use of org.talend.core.runtime.dynamic.IDynamicPluginConfiguration in project tbd-studio-se by Talend.
the class DynamicDistributionManager method saveUsersDynamicPlugin.
public void saveUsersDynamicPlugin(IDynamicPlugin dynamicPlugin, IDynamicMonitor monitor) throws Exception {
IDynamicPluginConfiguration pluginConfiguration = dynamicPlugin.getPluginConfiguration();
Object obj = pluginConfiguration.getAttribute(DynamicConstants.ATTR_FILE_PATH);
try {
String filePath = (String) obj;
if (StringUtils.isEmpty(filePath)) {
IProject eProject = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
IFolder usersFolder = ResourceUtils.getFolder(eProject, getUserStoragePath(), false);
if (usersFolder == null || !usersFolder.exists()) {
ResourceUtils.createFolder(usersFolder);
}
String folderPath = usersFolder.getLocation().toPortableString();
String fileName = pluginConfiguration.getId();
// $NON-NLS-1$ //$NON-NLS-2$
filePath = folderPath + "/" + fileName + "." + DISTRIBUTION_FILE_EXTENSION;
}
saveUsersDynamicPlugin(dynamicPlugin, filePath, monitor);
} finally {
// nothing to do
}
}
Aggregations