Search in sources :

Example 1 with DependencyNode

use of org.talend.designer.maven.aether.node.DependencyNode in project tbd-studio-se by Talend.

the class DynamicModuleAdapter method adapt.

public List<IDynamicConfiguration> adapt(IDynamicMonitor monitor, boolean multiThread) throws Exception {
    DynamicDistributionUtils.checkCancelOrNot(monitor);
    resolve();
    if (monitor != null) {
        String mvnUri = moduleBean.getMvnUri();
        if (StringUtils.isEmpty(mvnUri)) {
            mvnUri = getMvnUri();
        }
        monitor.setTaskName(// $NON-NLS-1$
        Messages.getString("DynamicModuleAdapter.monitor.buildModule", moduleBean.getId(), mvnUri));
    }
    TemplateBean templateBean = getTemplateBean();
    DynamicConfiguration configuration = getConfiguration();
    String distribution = configuration.getDistribution();
    String hadoopVersion = configuration.getVersion();
    String id = configuration.getId();
    List<ESparkVersion> selectedSparkVersions = configuration.getSelectedSparkVersions();
    List<IDynamicConfiguration> librariesNeeded = new ArrayList<>();
    List<String> sparkVersions = moduleBean.getSupportedSparkVersions();
    if (sparkVersions != null && !sparkVersions.isEmpty()) {
        boolean isSupport = false;
        for (String sparkVersion : sparkVersions) {
            try {
                ESparkVersion eSparkVersion = ESparkVersion.valueOf(sparkVersion);
                if (selectedSparkVersions.contains(eSparkVersion)) {
                    isSupport = true;
                    break;
                }
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
        if (!isSupport) {
            this.isSkipped = true;
            return librariesNeeded;
        }
    }
    String type = moduleBean.getType();
    if (ModuleBean.TYPE_BASE.equalsIgnoreCase(type)) {
        String groupId = moduleBean.getGroupId();
        String artifactId = moduleBean.getArtifactId();
        String scope = moduleBean.getScope();
        String extension = moduleBean.getExtension();
        String classifier = moduleBean.getClassifier();
        String moduleVersion = moduleBean.getVersion();
        String useStudioRepository = moduleBean.getUseStudioRepository();
        if (StringUtils.isNotEmpty(useStudioRepository)) {
            ExceptionHandler.process(// $NON-NLS-1$
            new Exception("Currently useStudioRepository is only supported by STANDARD type, will be ignored"), Priority.WARN);
        }
        boolean useLatest = Boolean.valueOf(moduleBean.getUseLatest());
        if (StringUtils.isBlank(extension)) {
            extension = null;
        }
        List<ExclusionBean> exclusionBeans = moduleBean.getExclusions();
        List<ExclusionNode> exclusions = null;
        if (exclusionBeans != null && !exclusionBeans.isEmpty()) {
            exclusions = adaptExclusions(exclusionBeans, monitor);
        }
        DependencyNode dependencyNode = null;
        DependencyNode baseNode = new DependencyNode();
        baseNode.setGroupId(groupId);
        baseNode.setArtifactId(artifactId);
        baseNode.setClassifier(classifier);
        baseNode.setExtension(extension);
        baseNode.setScope(scope);
        if (useLatest) {
            moduleVersion = dependencyResolver.getLatestVersion(groupId, artifactId, null, null, monitor);
        }
        baseNode.setVersion(moduleVersion);
        if (exclusions != null && !exclusions.isEmpty()) {
            baseNode.setExclusions(exclusions);
        }
        try {
            dependencyNode = dependencyResolver.collectDependencies(baseNode, monitor, multiThread);
            librariesNeeded = createLibrariesNeeded(dependencyNode, distribution, hadoopVersion, id, moduleBean, runtimeIds, templateBean);
        } catch (VersionNotFoundException e) {
            ExceptionHandler.process(e);
        }
    } else if (ModuleBean.TYPE_REFERENCE.equalsIgnoreCase(type)) {
        List<ExclusionBean> exclusions = moduleBean.getExclusions();
        if (exclusions != null && !exclusions.isEmpty()) {
            throw new UnsupportedOperationException(// $NON-NLS-1$
            Messages.getString("DynamicModuleAdapter.exception.exclusion.unsupport", type));
        }
        String jarName = moduleBean.getJarName();
        ModuleNeeded moduleNeeded = existingModuleMap.get(jarName);
        if (moduleNeeded == null) {
            throw new UnsupportedOperationException(// $NON-NLS-1$
            Messages.getString("DynamicModuleAdapter.exception.reference.notFound", jarName));
        }
        runtimeIds.add(moduleNeeded.getId());
    } else if (ModuleBean.TYPE_STANDARD.equalsIgnoreCase(type)) {
        List<ExclusionBean> exclusions = moduleBean.getExclusions();
        if (exclusions != null && !exclusions.isEmpty()) {
            throw new UnsupportedOperationException(// $NON-NLS-1$
            Messages.getString("DynamicModuleAdapter.exception.exclusion.unsupport", type));
        }
        String beanId = moduleBean.getId();
        String runtimeId = DynamicDistributionUtils.getPluginKey(distribution, hadoopVersion, id, beanId);
        if (!registedModules.contains(runtimeId)) {
            IDynamicConfiguration libraryNeeded = createLibraryNeeded(moduleBean);
            libraryNeeded.setAttribute(ATTR_ID, runtimeId);
            librariesNeeded.add(libraryNeeded);
            List<String> registedRuntimeIds = new ArrayList<>();
            registedRuntimeIds.add(runtimeId);
            registedModules.add(runtimeId);
        }
        runtimeIds.add(runtimeId);
    }
    return librariesNeeded;
}
Also used : IDynamicConfiguration(org.talend.core.runtime.dynamic.IDynamicConfiguration) ArrayList(java.util.ArrayList) ExclusionBean(org.talend.hadoop.distribution.dynamic.bean.ExclusionBean) ExclusionNode(org.talend.designer.maven.aether.node.ExclusionNode) VersionNotFoundException(org.talend.hadoop.distribution.dynamic.VersionNotFoundException) ESparkVersion(org.talend.hadoop.distribution.ESparkVersion) IDynamicConfiguration(org.talend.core.runtime.dynamic.IDynamicConfiguration) DynamicConfiguration(org.talend.hadoop.distribution.dynamic.DynamicConfiguration) DependencyNode(org.talend.designer.maven.aether.node.DependencyNode) ArrayList(java.util.ArrayList) List(java.util.List) TemplateBean(org.talend.hadoop.distribution.dynamic.bean.TemplateBean) VersionNotFoundException(org.talend.hadoop.distribution.dynamic.VersionNotFoundException) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 2 with DependencyNode

use of org.talend.designer.maven.aether.node.DependencyNode in project tbd-studio-se by Talend.

the class DynamicModuleAdapter method createLibrariesNeeded.

private List<IDynamicConfiguration> createLibrariesNeeded(DependencyNode node, String distribution, String version, String id, ModuleBean bean, List<String> runtimeIds, TemplateBean templateBean) {
    List<IDynamicConfiguration> librariesNeeded = new ArrayList<>();
    if (node == null) {
        return librariesNeeded;
    }
    List<String> registedRuntimeIds = new ArrayList<>();
    String registedModulesKey = getRegistedModulesKey(node);
    String jarName = node.getJarName();
    String runtimeId = DynamicDistributionUtils.getPluginKey(distribution, version, id, jarName);
    if (!registedModules.contains(registedModulesKey)) {
        ModuleNeeded moduleNeeded = null;
        if (reuseExistingJars()) {
            moduleNeeded = existingModuleMap.get(jarName);
        }
        if (moduleNeeded != null) {
            runtimeId = moduleNeeded.getId();
        } else {
            IDynamicConfiguration libraryNeeded = createLibraryNeeded(node, templateBean);
            libraryNeeded.setAttribute(ATTR_CONTEXT, bean.getContext());
            libraryNeeded.setAttribute(ATTR_ID, runtimeId);
            String useStudioRepository = bean.getUseStudioRepository();
            if (StringUtils.isNotEmpty(useStudioRepository)) {
                libraryNeeded.setAttribute(ATTR_TEMP_USE_STUDIO_REPOSITORY, useStudioRepository);
            } else {
                libraryNeeded.removeAttribute(ATTR_TEMP_USE_STUDIO_REPOSITORY);
            }
            librariesNeeded.add(libraryNeeded);
        }
        registedModules.add(registedModulesKey);
    }
    registedRuntimeIds.add(runtimeId);
    List<DependencyNode> dependencies = node.getDependencies();
    if (dependencies != null) {
        for (DependencyNode dependency : dependencies) {
            List<IDynamicConfiguration> childLibrariesNeeded = createLibrariesNeeded(dependency, distribution, version, id, bean, registedRuntimeIds, templateBean);
            librariesNeeded.addAll(childLibrariesNeeded);
        }
    }
    runtimeIds.addAll(registedRuntimeIds);
    return librariesNeeded;
}
Also used : IDynamicConfiguration(org.talend.core.runtime.dynamic.IDynamicConfiguration) DependencyNode(org.talend.designer.maven.aether.node.DependencyNode) ArrayList(java.util.ArrayList) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 3 with DependencyNode

use of org.talend.designer.maven.aether.node.DependencyNode in project tbd-studio-se by Talend.

the class AbstractDependencyResolver method collectDependencies.

@Override
public DependencyNode collectDependencies(DependencyNode baseNode, IDynamicMonitor monitor, boolean multiThread) throws Exception {
    String version = baseNode.getVersion();
    if (StringUtils.isEmpty(version)) {
        String groupId = baseNode.getGroupId();
        String artifactId = baseNode.getArtifactId();
        version = getDependencyVersionByHadoopVersion(groupId, artifactId, monitor);
        if (StringUtils.isEmpty(version)) {
            VersionNotFoundException versionNotFound = new VersionNotFoundException();
            versionNotFound.setVersion(configuration.getVersion());
            versionNotFound.setBaseNode(baseNode);
            throw versionNotFound;
        }
        baseNode.setVersion(version);
    }
    IDynamicDistributionPreference preference = configuration.getPreference();
    String remoteRepositoryUrl = preference.getRepository();
    String username = null;
    String password = null;
    if (!preference.isAnonymous()) {
        username = preference.getUsername();
        password = preference.getPassword();
    }
    String localRepositoryPath = getLocalRepositoryPath();
    DependencyNode node = DynamicDistributionAetherUtils.collectDepencencies(remoteRepositoryUrl, username, password, localRepositoryPath, baseNode, monitor, multiThread);
    return node;
}
Also used : IDynamicDistributionPreference(org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference) DependencyNode(org.talend.designer.maven.aether.node.DependencyNode) VersionNotFoundException(org.talend.hadoop.distribution.dynamic.VersionNotFoundException)

Aggregations

DependencyNode (org.talend.designer.maven.aether.node.DependencyNode)3 ArrayList (java.util.ArrayList)2 ModuleNeeded (org.talend.core.model.general.ModuleNeeded)2 IDynamicConfiguration (org.talend.core.runtime.dynamic.IDynamicConfiguration)2 VersionNotFoundException (org.talend.hadoop.distribution.dynamic.VersionNotFoundException)2 List (java.util.List)1 ExclusionNode (org.talend.designer.maven.aether.node.ExclusionNode)1 ESparkVersion (org.talend.hadoop.distribution.ESparkVersion)1 DynamicConfiguration (org.talend.hadoop.distribution.dynamic.DynamicConfiguration)1 ExclusionBean (org.talend.hadoop.distribution.dynamic.bean.ExclusionBean)1 TemplateBean (org.talend.hadoop.distribution.dynamic.bean.TemplateBean)1 IDynamicDistributionPreference (org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference)1