use of org.talend.core.runtime.dynamic.IDynamicConfiguration in project tbd-studio-se by Talend.
the class DynamicModuleAdapter method createLibraryNeeded.
private IDynamicConfiguration createLibraryNeeded(DependencyNode node, TemplateBean templateBean) {
IDynamicConfiguration libraryNeeded = null;
libraryNeeded = DynamicFactory.getInstance().createDynamicConfiguration();
libraryNeeded.setConfigurationName(TAG_NAME);
String jarname = node.getJarName();
String mvnUri = DynamicDistributionUtils.getMvnUrl(node);
libraryNeeded.setAttribute(ATTR_NAME, jarname);
libraryNeeded.setAttribute(ATTR_MVN_URI, mvnUri);
libraryNeeded.setAttribute(ATTR_EXCLUDE_DEPENDENCIES, Boolean.TRUE.toString());
return libraryNeeded;
}
use of org.talend.core.runtime.dynamic.IDynamicConfiguration in project tbd-studio-se by Talend.
the class DynamicPluginAdapter method cleanUnusedAndRefresh.
/**
* can't use adapt and clean same time
*
* @throws Exception
*/
public void cleanUnusedAndRefresh() throws Exception {
buildIdMaps();
// 1. unify module versions to use latest version
unifyModuleVersions();
// 2. clean unused modules
Set<String> usedModulesSet = new HashSet<String>();
Collection<IDynamicConfiguration> moduleGroups = moduleGroupTemplateMap.values();
Iterator<IDynamicConfiguration> moduleGroupIter = moduleGroups.iterator();
while (moduleGroupIter.hasNext()) {
IDynamicConfiguration moduleGroup = moduleGroupIter.next();
List<IDynamicConfiguration> childConfigurations = moduleGroup.getChildConfigurations();
if (childConfigurations != null) {
Set<String> curUsedModules = new HashSet<>();
Set<IDynamicConfiguration> oldVersionModuleConfigs = new HashSet<>();
Map<String, IDynamicConfiguration> latestGaIdMap = new HashMap<>();
Iterator<IDynamicConfiguration> libraryIter = childConfigurations.iterator();
while (libraryIter.hasNext()) {
IDynamicConfiguration childConfig = libraryIter.next();
String libraryId = (String) childConfig.getAttribute(DynamicModuleGroupAdapter.ATTR_LIBRARY_ID);
if (libraryId != null) {
if (curUsedModules.contains(libraryId)) {
libraryIter.remove();
} else {
String mvnUri = getMvnUri(libraryId);
if (mvnUri != null) {
MavenArtifact curMa = MavenUrlHelper.parseMvnUrl(mvnUri);
String key = getGaKey(curMa);
IDynamicConfiguration storedConfig = latestGaIdMap.get(key);
if (storedConfig == null) {
latestGaIdMap.put(key, childConfig);
curUsedModules.add(libraryId);
} else {
String storedId = (String) storedConfig.getAttribute(DynamicModuleGroupAdapter.ATTR_LIBRARY_ID);
String curVersion = curMa.getVersion();
String storedMvnUri = getMvnUri(storedId);
MavenArtifact storedMa = MavenUrlHelper.parseMvnUrl(storedMvnUri);
String type = storedMa.getType();
boolean isPom = TYPE_POM.equalsIgnoreCase(type);
if (isPom) {
curUsedModules.add(libraryId);
} else {
String storedVersion = storedMa.getVersion();
if (0 < versionComparator.compare(curVersion, storedVersion)) {
curUsedModules.remove(storedId);
curUsedModules.add(libraryId);
oldVersionModuleConfigs.add(storedConfig);
latestGaIdMap.put(key, childConfig);
} else {
libraryIter.remove();
}
}
}
} else {
curUsedModules.add(libraryId);
}
}
}
}
childConfigurations.removeAll(oldVersionModuleConfigs);
Collections.sort(childConfigurations, new DynamicAttributeComparator(DynamicModuleGroupAdapter.ATTR_LIBRARY_ID));
usedModulesSet.addAll(curUsedModules);
}
}
Set<String> unusedModulesSet = new HashSet<String>(moduleMap.keySet());
unusedModulesSet.removeAll(usedModulesSet);
if (!unusedModulesSet.isEmpty()) {
Set<IDynamicConfiguration> unusedConfigs = new HashSet<>();
for (String unusedModule : unusedModulesSet) {
IDynamicConfiguration moduleById = getModuleById(unusedModule);
if (moduleById != null) {
unusedConfigs.add(moduleById);
}
moduleMap.remove(unusedModule);
}
if (!unusedConfigs.isEmpty()) {
IDynamicExtension libNeededExtension = getLibraryNeededExtension(plugin);
List<IDynamicConfiguration> configurations = libNeededExtension.getConfigurations();
configurations.removeAll(unusedConfigs);
Collections.sort(configurations, new DynamicAttributeComparator());
}
}
// 3. refresh classLoader
IDynamicExtension classLoaderExtension = getClassLoaderExtension(plugin);
List<IDynamicConfiguration> classLoaders = classLoaderExtension.getConfigurations();
if (classLoaders != null) {
for (IDynamicConfiguration classLoader : classLoaders) {
String moduleGroupTemplateId = (String) classLoader.getAttribute(DynamicClassloaderAdapter.ATTR_MODULE_GROUP_TEMPLATE_ID);
IDynamicConfiguration moduleGroupByTemplateId = getModuleGroupByTemplateId(moduleGroupTemplateId);
List<IDynamicConfiguration> libraries = moduleGroupByTemplateId.getChildConfigurations();
List<String> libraryIds = new ArrayList<>();
for (IDynamicConfiguration library : libraries) {
String libraryId = (String) library.getAttribute(DynamicModuleGroupAdapter.ATTR_LIBRARY_ID);
if (!libraryIds.contains(libraryId)) {
libraryIds.add(libraryId);
}
}
if (!libraryIds.isEmpty()) {
Collections.sort(libraryIds);
String buildLibrariesString = DynamicClassloaderAdapter.buildLibrariesString(libraryIds);
classLoader.setAttribute(DynamicClassloaderAdapter.ATTR_LIBRARIES, buildLibrariesString);
}
}
}
}
use of org.talend.core.runtime.dynamic.IDynamicConfiguration in project tbd-studio-se by Talend.
the class DynamicPluginAdapter method buildIdMaps.
public void buildIdMaps() throws Exception {
moduleMap.clear();
moduleGroupTemplateMap.clear();
IDynamicExtension libNeededExtension = getLibraryNeededExtension(plugin);
if (libNeededExtension == null) {
throw new Exception("Can't find extension: " + DynamicLibraryNeededExtensionAdaper.ATTR_POINT);
}
List<IDynamicConfiguration> configurations = libNeededExtension.getConfigurations();
if (configurations == null || configurations.isEmpty()) {
throw new Exception("No libraryModuelGroup configured");
}
for (IDynamicConfiguration configuration : configurations) {
if (DynamicModuleGroupAdapter.TAG_NAME.equals(configuration.getTagName())) {
String templateId = (String) configuration.getAttribute(DynamicModuleGroupAdapter.ATTR_GROUP_TEMPLATE_ID);
if (StringUtils.isEmpty(templateId)) {
throw new Exception("Template id is not configured!");
}
moduleGroupTemplateMap.put(templateId, configuration);
} else if (DynamicModuleAdapter.TAG_NAME.equals(configuration.getTagName())) {
String moduleId = (String) configuration.getAttribute(DynamicModuleAdapter.ATTR_ID);
if (StringUtils.isEmpty(moduleId)) {
throw new Exception("Module id is empty!");
}
moduleMap.put(moduleId, configuration);
}
}
}
use of org.talend.core.runtime.dynamic.IDynamicConfiguration in project tbd-studio-se by Talend.
the class DynamicLibraryNeededExtensionAdaper method adapt.
public IDynamicExtension adapt(IDynamicMonitor monitor) throws Exception {
DynamicDistributionUtils.checkCancelOrNot(monitor);
resolve();
TemplateBean templateBean = getTemplateBean();
DynamicConfiguration configuration = getConfiguration();
String templateId = templateBean.getId();
String distributionName = configuration.getDistribution();
String id = configuration.getId();
IDynamicExtension libNeededExtension = DynamicFactory.getInstance().createDynamicExtension();
libNeededExtension.setExtensionId(DynamicDistributionUtils.getExtensionId(DynamicDistributionUtils.getPluginKey(distributionName, templateId, id, ATTR_POINT)));
libNeededExtension.setExtensionPoint(ATTR_POINT);
List<ModuleBean> modules = templateBean.getModules();
if (modules != null) {
try {
Exception[] ex = new Exception[1];
Set<String> registedModules = Collections.synchronizedSet(new LinkedHashSet<>());
for (ModuleBean moduleBean : modules) {
DynamicDistributionUtils.checkCancelOrNot(monitor);
Runnable runnable = new Runnable() {
int count = 0;
@Override
public void run() {
try {
DynamicModuleAdapter dynamicModuleAdapter = new DynamicModuleAdapter(templateBean, configuration, moduleBean, dependencyResolver, registedModules);
List<IDynamicConfiguration> librariesNeeded = dynamicModuleAdapter.adapt(monitor, isEnableMultiThread());
if (librariesNeeded != null && !librariesNeeded.isEmpty()) {
addDynamicConfigurations(libNeededExtension, librariesNeeded);
}
String beanId = moduleBean.getId();
moduleBeanAdapterMap.put(beanId, dynamicModuleAdapter);
} catch (Exception e) {
Throwable rootCause = ExceptionUtils.getRootCause(e);
if (e instanceof FileNotFoundException || rootCause instanceof FileNotFoundException) {
if (count < 5) {
count++;
run();
} else {
ex[0] = e;
}
} else {
ex[0] = e;
}
}
}
};
if (isEnableMultiThread()) {
getThreadPool().execute(runnable);
continue;
} else {
runnable.run();
if (ex[0] != null) {
throw ex[0];
}
}
}
if (isEnableMultiThread()) {
int totalTasks = modules.size();
if (monitor != null) {
monitor.beginTask(// $NON-NLS-1$
Messages.getString("DynamicLibraryNeededExtensionAdaper.monitor.waitAllFinish", totalTasks), totalTasks);
}
int completed = 0;
while (true) {
int activeCount = getThreadPool().getActiveCount();
if (activeCount <= 0) {
break;
}
if (monitor != null) {
int newCompleted = (int) getThreadPool().getCompletedTaskCount();
int newWorked = newCompleted - completed;
completed = newCompleted;
monitor.setTaskName(// $NON-NLS-1$
Messages.getString(// $NON-NLS-1$
"DynamicLibraryNeededExtensionAdaper.monitor.waitAllFinish", activeCount));
monitor.worked(newWorked);
}
Thread.sleep(200);
DynamicDistributionUtils.checkCancelOrNot(monitor);
if (ex[0] != null) {
throw ex[0];
}
}
}
} finally {
if (isEnableMultiThread()) {
if (monitor != null) {
// $NON-NLS-1$
monitor.beginTask("", IProgressMonitor.UNKNOWN);
}
getThreadPool().clearThreads();
threadPool = null;
}
}
}
List<ModuleGroupBean> moduleGroups = templateBean.getModuleGroups();
if (moduleGroups != null) {
for (ModuleGroupBean moduleGroupBean : moduleGroups) {
DynamicDistributionUtils.checkCancelOrNot(monitor);
DynamicModuleGroupAdapter libNeededGroupAdapter = new DynamicModuleGroupAdapter(templateBean, configuration, moduleGroupBean, moduleBeanAdapterMap);
IDynamicConfiguration dynamicModuleGroup = libNeededGroupAdapter.adapt(monitor);
if (dynamicModuleGroup != null) {
libNeededExtension.addConfiguration(dynamicModuleGroup);
String groupId = moduleGroupBean.getId();
moduleGroupBeanAdapterMap.put(groupId, libNeededGroupAdapter);
}
}
}
return libNeededExtension;
}
use of org.talend.core.runtime.dynamic.IDynamicConfiguration in project tbd-studio-se by Talend.
the class DynamicModuleGroupAdapter method createDynamicLibrary.
public static IDynamicConfiguration createDynamicLibrary(String runtimeId) {
IDynamicConfiguration dynamicLibrary = DynamicFactory.getInstance().createDynamicConfiguration();
dynamicLibrary.setConfigurationName(TAG_LIBRARY_NAME);
dynamicLibrary.setAttribute(ATTR_LIBRARY_ID, runtimeId);
return dynamicLibrary;
}
Aggregations