use of org.talend.core.runtime.dynamic.IDynamicPlugin 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.IDynamicPlugin in project tbd-studio-se by Talend.
the class DynamicDistributionManager method unregisterAllUsers.
public void unregisterAllUsers(IDynamicMonitor monitor, boolean cleanCache) throws Exception {
List<IDynamicPlugin> allUsersDynamicPlugins = getAllUsersDynamicPlugins(monitor);
if (allUsersDynamicPlugins == null || allUsersDynamicPlugins.isEmpty()) {
return;
}
List<IDynamicDistributionsGroup> dynDistriGroups = getDynamicDistributionsGroups();
if (dynDistriGroups == null || dynDistriGroups.isEmpty()) {
throw new Exception("No dynamic distribution group found.");
}
for (IDynamicPlugin dynamicPlugin : allUsersDynamicPlugins) {
boolean registed = false;
for (IDynamicDistributionsGroup dynDistriGroup : dynDistriGroups) {
try {
if (dynDistriGroup.canRegister(dynamicPlugin, monitor)) {
dynDistriGroup.unregister(dynamicPlugin, monitor, false);
registed = true;
}
} catch (Throwable e) {
ExceptionHandler.process(e);
}
}
if (!registed) {
ExceptionHandler.process(new Exception("Can't regist dynamic distribution: " + dynamicPlugin.getPluginConfiguration().getTemplateId()));
}
}
if (cleanCache) {
resetSystemCache();
}
}
use of org.talend.core.runtime.dynamic.IDynamicPlugin in project tbd-studio-se by Talend.
the class DynamicDistributionManager method registerAllUsers.
public void registerAllUsers(IDynamicMonitor monitor, boolean cleanCache) throws Exception {
isLoaded = true;
List<IDynamicPlugin> allUsersDynamicPlugins = getAllUsersDynamicPlugins(monitor);
if (allUsersDynamicPlugins == null || allUsersDynamicPlugins.isEmpty()) {
return;
}
List<IDynamicDistributionsGroup> dynDistriGroups = getDynamicDistributionsGroups();
if (dynDistriGroups == null || dynDistriGroups.isEmpty()) {
throw new Exception("No dynamic distribution group found.");
}
for (IDynamicPlugin dynamicPlugin : allUsersDynamicPlugins) {
boolean registed = false;
for (IDynamicDistributionsGroup dynDistriGroup : dynDistriGroups) {
try {
if (dynDistriGroup.canRegister(dynamicPlugin, monitor)) {
dynDistriGroup.register(dynamicPlugin, monitor);
registed = true;
}
} catch (Throwable e) {
ExceptionHandler.process(e);
}
}
if (!registed) {
ExceptionHandler.process(new Exception("Can't regist dynamic distribution: " + dynamicPlugin.getPluginConfiguration().getTemplateId()));
}
}
if (cleanCache) {
resetSystemCache();
}
}
use of org.talend.core.runtime.dynamic.IDynamicPlugin in project tbd-studio-se by Talend.
the class DynamicDistributionOptionForm method checkSelectExistingConfig.
private boolean checkSelectExistingConfig() {
if (!editExistingConfigBtn.getSelection()) {
return true;
}
IStructuredSelection selection = (IStructuredSelection) existingConfigsComboViewer.getSelection();
if (selection == null) {
// $NON-NLS-1$
String errorMessage = Messages.getString("DynamicDistributionOptionForm.importConfigText.check.existingConfig.empty");
showMessage(errorMessage, WizardPage.ERROR);
return false;
}
Object firstElement = selection.getFirstElement();
if (firstElement == null) {
// $NON-NLS-1$
String errorMessage = Messages.getString("DynamicDistributionOptionForm.importConfigText.check.existingConfig.empty");
showMessage(errorMessage, WizardPage.ERROR);
return false;
}
IDynamicPlugin dynamicPlugin = (IDynamicPlugin) firstElement;
existingConfigsComboViewer.getControl().setToolTipText(existingConfigsComboViewer.getCombo().getText());
getDynamicDistributionSetupData().setDynamicPlugin(dynamicPlugin);
IDynamicPluginConfiguration pluginConfiguration = dynamicPlugin.getPluginConfiguration();
boolean isBuiltin = isBuiltinDynamicConfiguration(dynamicPlugin);
boolean isInCurrentProject = isInCurrentProject(dynamicPlugin);
getDynamicDistributionSetupData().setReadonly(isBuiltin || !isInCurrentProject || isReadonly());
if (isBuiltin) {
String warnMessage = // $NON-NLS-1$
Messages.getString(// $NON-NLS-1$
"DynamicDistributionOptionForm.editExisting.builtin", pluginConfiguration.getName());
showMessage(warnMessage, WizardPage.WARNING);
}
if (!isInCurrentProject) {
String warnMessage = // $NON-NLS-1$
Messages.getString(// $NON-NLS-1$
"DynamicDistributionOptionForm.editExisting.notInCurrentProject", pluginConfiguration.getName(), pluginConfiguration.getAttribute(DynamicConstants.ATTR_PROJECT_TECHNICAL_NAME));
showMessage(warnMessage, WizardPage.WARNING);
}
return true;
}
use of org.talend.core.runtime.dynamic.IDynamicPlugin in project tbd-studio-se by Talend.
the class AbstractDynamicDistributionSetupForm method saveDynamicDistribution.
protected void saveDynamicDistribution(IDynamicPlugin dynamicPlugin, IDynamicDistributionsGroup dynDistrGroup, ActionType actionType, IDynamicMonitor dMonitor) throws Exception {
IDynamicPluginConfiguration pluginConfiguration = dynamicPlugin.getPluginConfiguration();
dMonitor.beginTask(// $NON-NLS-1$
Messages.getString("AbstractDynamicDistributionSetupForm.progress.saving", pluginConfiguration.getName()), IDynamicMonitor.UNKNOWN);
// step 1: clean unused modules
IDynamicDistributionPreference dynamicDistributionPreference = dynDistrGroup.getDynamicDistributionPreference(ProjectManager.getInstance().getCurrentProject());
DynamicPluginAdapter pluginAdapter = new DynamicPluginAdapter(dynamicPlugin, dynamicDistributionPreference, null);
pluginAdapter.cleanUnusedAndRefresh();
// step 2: save
final IDynamicPlugin fDynPlugin = pluginAdapter.getPlugin();
ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(new RepositoryWorkUnit<Boolean>(Messages.getString("AbstractDynamicDistributionSetupForm.repositoryWorkUnit.title", // $NON-NLS-1$
pluginConfiguration.getName())) {
@Override
protected void run() throws LoginException, PersistenceException {
result = false;
try {
DynamicDistributionManager.getInstance().saveUsersDynamicPlugin(fDynPlugin, dMonitor);
} catch (Exception e) {
throw new PersistenceException(e);
}
result = true;
}
});
// step 3: regist
dMonitor.setTaskName(// $NON-NLS-1$
Messages.getString("AbstractDynamicDistributionSetupForm.progress.registing", pluginConfiguration.getName()));
if (ActionType.EditExisting.equals(actionType)) {
dynDistrGroup.unregister(fDynPlugin, dMonitor, false);
}
dynDistrGroup.register(fDynPlugin, dMonitor);
// step 4: reset system cache
// $NON-NLS-1$
dMonitor.setTaskName(Messages.getString("AbstractDynamicDistributionSetupForm.progress.resetCache"));
DynamicDistributionManager.getInstance().resetSystemCache();
}
Aggregations