Search in sources :

Example 6 with IDynamicDistributionPreference

use of org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference in project tbd-studio-se by Talend.

the class DynamicDistributionPreferenceForm method checkRepository.

private boolean checkRepository() {
    try {
        repositoryText.setBackground(null);
        // $NON-NLS-1$
        repositoryText.setToolTipText("");
        boolean overrideDefaultSetupSelected = overrideDefaultSetupBtn.getSelection();
        repositoryText.setEditable(overrideDefaultSetupSelected);
        if (!overrideDefaultSetupSelected) {
            IDynamicDistributionsGroup selectedSetupDynamicDistriGroup = getSelectedSetupDynamicDistriGroup();
            if (selectedSetupDynamicDistriGroup != null) {
                IDynamicDistributionPreference dynamicDistributionPreference = selectedSetupDynamicDistriGroup.getDynamicDistributionPreference(ProjectManager.getInstance().getCurrentProject());
                String defaultRepository = dynamicDistributionPreference.getDefaultRepository();
                repositoryText.setText(defaultRepository);
                repositoryText.setToolTipText(defaultRepository);
            }
        } else {
            String repository = repositoryText.getText();
            if (StringUtils.isEmpty(repository.trim())) {
                String errorMessage = Messages.getString(// $NON-NLS-1$
                "DynamicDistributionPreferenceForm.exception.setup.override.repository.empty");
                repositoryText.setToolTipText(errorMessage);
                repositoryText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
                showMessage(errorMessage, WizardPage.ERROR);
                return false;
            } else {
                repositoryText.setToolTipText(repository);
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return false;
    } finally {
        boolean isReadonly = isReadonly();
        if (isReadonly) {
            overrideDefaultSetupBtn.setEnabled(false);
            repositoryText.setEditable(false);
        }
    }
    return true;
}
Also used : IDynamicDistributionPreference(org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference) IDynamicDistributionsGroup(org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 7 with IDynamicDistributionPreference

use of org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference 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();
    }
}
Also used : Project(org.talend.core.model.general.Project) IDynamicDistributionPreference(org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference) DynamicPluginAdapter(org.talend.hadoop.distribution.dynamic.adapter.DynamicPluginAdapter) IDynamicDistributionTemplate(org.talend.hadoop.distribution.dynamic.template.IDynamicDistributionTemplate) IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) Bundle(org.osgi.framework.Bundle) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)

Example 8 with IDynamicDistributionPreference

use of org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference in project tbd-studio-se by Talend.

the class AbstractDependencyResolver method listVersions.

@Override
public List<String> listVersions(String groupId, String artifactId, String baseVersion, String topVersion, IDynamicMonitor monitor) throws Exception {
    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();
    return DynamicDistributionAetherUtils.versionRange(remoteRepositoryUrl, username, password, localRepositoryPath, groupId, artifactId, null, null, monitor);
}
Also used : IDynamicDistributionPreference(org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference)

Example 9 with IDynamicDistributionPreference

use of org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference 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)

Example 10 with IDynamicDistributionPreference

use of org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference 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();
}
Also used : IDynamicDistributionPreference(org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference) DynamicPluginAdapter(org.talend.hadoop.distribution.dynamic.adapter.DynamicPluginAdapter) IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration) LoginException(org.talend.commons.exception.LoginException) PersistenceException(org.talend.commons.exception.PersistenceException)

Aggregations

IDynamicDistributionPreference (org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference)12 IDynamicDistributionsGroup (org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup)4 LoginException (org.talend.commons.exception.LoginException)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 Project (org.talend.core.model.general.Project)2 IDynamicPlugin (org.talend.core.runtime.dynamic.IDynamicPlugin)2 IDynamicPluginConfiguration (org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)2 DynamicConfiguration (org.talend.hadoop.distribution.dynamic.DynamicConfiguration)2 DynamicPluginAdapter (org.talend.hadoop.distribution.dynamic.adapter.DynamicPluginAdapter)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 IProject (org.eclipse.core.resources.IProject)1 Bundle (org.osgi.framework.Bundle)1 DependencyNode (org.talend.designer.maven.aether.node.DependencyNode)1 VersionNotFoundException (org.talend.hadoop.distribution.dynamic.VersionNotFoundException)1 IDynamicDistributionTemplate (org.talend.hadoop.distribution.dynamic.template.IDynamicDistributionTemplate)1 ProjectManager (org.talend.repository.ProjectManager)1