Search in sources :

Example 1 with ISVNProviderService

use of org.talend.core.services.ISVNProviderService in project tdi-studio-se by Talend.

the class JobletUtil method needReadOnlyJoblet.

public boolean needReadOnlyJoblet(JobletProcessItem jobletItem) {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart[] editors = page.getEditors();
    for (IEditorPart editor : editors) {
        if (editor instanceof AbstractMultiPageTalendEditor) {
            List<? extends INode> nodeList = ((AbstractMultiPageTalendEditor) editor).getProcess().getGraphicalNodes();
            for (INode node : nodeList) {
                if (((Node) node).isJoblet() && jobletItem.getProperty() != null) {
                    if (jobletItem.getProperty().getId().equals(node.getComponent().getProcess().getId())) {
                        boolean haveLock = jobletItem.getState().isLocked();
                        boolean isSvn = false;
                        ISVNProviderService service = null;
                        if (PluginChecker.isSVNProviderPluginLoaded()) {
                            service = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
                        }
                        if (service != null && service.isProjectInSvnMode()) {
                            isSvn = service.isProjectInSvnMode();
                        }
                        if (isSvn) {
                            IProxyRepositoryService proxyService = (IProxyRepositoryService) GlobalServiceRegister.getDefault().getService(IProxyRepositoryService.class);
                            IProxyRepositoryFactory factory = proxyService.getProxyRepositoryFactory();
                            ERepositoryStatus repositoryStatus = factory.getStatus(jobletItem);
                            if (repositoryStatus == ERepositoryStatus.LOCK_BY_USER) {
                                haveLock = true;
                            }
                        }
                        if (haveLock) {
                            return true;
                        }
                    }
                }
            }
        }
    }
    return false;
}
Also used : INode(org.talend.core.model.process.INode) ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) IProxyRepositoryService(org.talend.repository.model.IProxyRepositoryService) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ISVNProviderService(org.talend.core.services.ISVNProviderService) IEditorPart(org.eclipse.ui.IEditorPart) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 2 with ISVNProviderService

use of org.talend.core.services.ISVNProviderService in project tdi-studio-se by Talend.

the class CustomComponentSettingPage method finish.

private void finish(IProgressMonitor... monitorWrap) {
    IProgressMonitor monitor = null;
    if (monitorWrap != null && monitorWrap.length == 1) {
        monitor = monitorWrap[0];
    }
    final IProxyRepositoryFactory prf = CorePlugin.getDefault().getProxyRepositoryFactory();
    if (PluginChecker.isSVNProviderPluginLoaded() && (!sharedAdded.isEmpty() || !backAdded.isEmpty())) {
        RepositoryWorkUnit repositoryWorkUnit = new RepositoryWorkUnit("Update custom components") {

            @Override
            public void run() throws PersistenceException {
                final IWorkspaceRunnable op = new IWorkspaceRunnable() {

                    @Override
                    public void run(IProgressMonitor subMonitor) throws CoreException {
                        ISVNProviderService service = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
                        String projectLabel = pro.getTechnicalLabel();
                        IWorkspace workspace = ResourcesPlugin.getWorkspace();
                        IProject eclipseProject = workspace.getRoot().getProject(projectLabel);
                        String targetRoot = eclipseProject.getLocation().toString() + "/" + ERepositoryObjectType.getFolderName(ERepositoryObjectType.COMPONENTS);
                        File componentFolder = new File(targetRoot);
                        URL url = null;
                        try {
                            if (!componentFolder.exists()) {
                                FilesUtils.createFoldersIfNotExists(targetRoot, false);
                            }
                            Bundle b = Platform.getBundle(IComponentsFactory.COMPONENTS_LOCATION);
                            url = FileLocator.toFileURL(FileLocator.find(b, new Path(""), null));
                            String sourceRoot = url.getFile();
                            // delete share
                            for (IComponent component : backAdded.keySet()) {
                                String componentFullPath = targetRoot + File.separator + component.getName();
                                if (service.isSVNProject(pro)) {
                                    service.svnEclipseHandlerDelete(eclipseProject, pro, componentFullPath);
                                    if (subMonitor != null) {
                                        subMonitor.worked(10);
                                    }
                                } else {
                                    File file = new File(componentFullPath);
                                    if (file != null && file.exists()) {
                                        org.talend.utils.io.FilesUtils.deleteFolder(file, true);
                                    }
                                }
                            }
                            if (!backAdded.isEmpty()) {
                                getCustomComponentSettings().removeAll(backAdded.values());
                            }
                            FileFilter ff = new FileFilter() {

                                @Override
                                public boolean accept(File pathname) {
                                    if (FilesUtils.isSVNFolder(pathname)) {
                                        return false;
                                    }
                                    return true;
                                }
                            };
                            // share
                            for (IComponent component : sharedAdded.keySet()) {
                                String sourcePath = sourceRoot + component.getPathSource() + File.separator + component.getName();
                                File sourceFile = new File(sourcePath);
                                String targetPath = targetRoot + File.separatorChar + component.getName();
                                File targetFile = new File(targetPath);
                                FilesUtils.copyFolder(sourceFile, targetFile, true, ff, null, true, false);
                                if (subMonitor != null) {
                                    subMonitor.worked(10);
                                }
                            }
                        } catch (Exception e) {
                            resetCustomComponentSetting();
                            ExceptionHandler.process(e);
                        }
                        try {
                            prf.saveProject(pro);
                        } catch (PersistenceException e) {
                            ExceptionHandler.process(e);
                        }
                        try {
                            eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, subMonitor);
                        } catch (CoreException e1) {
                            ExceptionHandler.process(e1);
                        }
                    }
                };
                IWorkspace workspace = ResourcesPlugin.getWorkspace();
                try {
                    ISchedulingRule schedulingRule = workspace.getRoot();
                    // the update the project files need to be done in the workspace runnable to avoid all
                    // notification
                    // of changes before the end of the modifications.
                    workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
                } catch (CoreException e) {
                    throw new PersistenceException(e.getCause());
                }
            }
        };
        repositoryWorkUnit.setRefreshRepository(false);
        repositoryWorkUnit.setForceTransaction(true);
        prf.executeRepositoryWorkUnit(repositoryWorkUnit);
        try {
            repositoryWorkUnit.throwPersistenceExceptionIfAny();
        } catch (PersistenceException e) {
            e.printStackTrace();
        }
    }
    if (monitor != null) {
        monitor.done();
    }
    // refresh again after the gui closed .
    try {
        String projectLabel = pro.getTechnicalLabel();
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IProject eclipseProject = workspace.getRoot().getProject(projectLabel);
        eclipseProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    } catch (CoreException e1) {
        ExceptionHandler.process(e1);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Bundle(org.osgi.framework.Bundle) IComponent(org.talend.core.model.components.IComponent) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) ISVNProviderService(org.talend.core.services.ISVNProviderService) IProject(org.eclipse.core.resources.IProject) URL(java.net.URL) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) FileFilter(java.io.FileFilter) File(java.io.File) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 3 with ISVNProviderService

use of org.talend.core.services.ISVNProviderService in project tdi-studio-se by Talend.

the class Problems method isSVN.

private static boolean isSVN() {
    boolean isSvn = false;
    ISVNProviderService service = null;
    if (PluginChecker.isSVNProviderPluginLoaded()) {
        service = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
    }
    if (service != null && service.isProjectInSvnMode()) {
        isSvn = service.isProjectInSvnMode();
    }
    return isSvn;
}
Also used : ISVNProviderService(org.talend.core.services.ISVNProviderService)

Example 4 with ISVNProviderService

use of org.talend.core.services.ISVNProviderService in project tdi-studio-se by Talend.

the class MultiPageTalendEditor method setName.

/**
     * DOC smallet Comment method "setName".
     * 
     * @param label
     */
@Override
public void setName() {
    if (getEditorInput() == null) {
        return;
    }
    super.setName();
    IProcess2 process2 = this.getProcess();
    if (process2 == null) {
        return;
    }
    Property property = process2.getProperty();
    if (property == null) {
        return;
    }
    String label = property.getDisplayName();
    //$NON-NLS-1$
    String jobVersion = "0.1";
    if (process2 != null) {
        jobVersion = process2.getVersion();
    }
    // if (getActivePage() == 1) {
    ISVNProviderService service = null;
    if (PluginChecker.isSVNProviderPluginLoaded()) {
        service = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
        if (revisionChanged && service.isProjectInSvnMode()) {
            revisionNumStr = service.getCurrentSVNRevision(process2);
            revisionChanged = false;
            if (revisionNumStr != null) {
                //$NON-NLS-1$
                revisionNumStr = ".r" + revisionNumStr;
            }
        }
    }
    //$NON-NLS-1$
    String title = "MultiPageTalendEditor.Job";
    if (process2 != null) {
        Item item = process2.getProperty().getItem();
        if (item instanceof JobletProcessItem) {
            //$NON-NLS-1$
            title = "MultiPageTalendEditor.Joblet";
        }
    }
    IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
    boolean allowVerchange = brandingService.getBrandingConfiguration().isAllowChengeVersion();
    if (allowVerchange) {
        if (revisionNumStr != null) {
            setPartName(Messages.getString(title, label, jobVersion) + revisionNumStr);
        } else {
            setPartName(Messages.getString(title, label, jobVersion));
        }
    } else {
        if (revisionNumStr != null) {
            //$NON-NLS-1$
            setPartName(Messages.getString(title, label, "") + revisionNumStr);
        } else {
            //$NON-NLS-1$
            setPartName(Messages.getString(title, label, ""));
        }
    }
}
Also used : Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IProcess2(org.talend.core.model.process.IProcess2) ISVNProviderService(org.talend.core.services.ISVNProviderService) IBrandingService(org.talend.core.ui.branding.IBrandingService) Property(org.talend.core.model.properties.Property)

Example 5 with ISVNProviderService

use of org.talend.core.services.ISVNProviderService in project tdi-studio-se by Talend.

the class RepositoryService method isloginDialogDisabled.

private boolean isloginDialogDisabled() {
    //$NON-NLS-1$
    boolean reload = Boolean.parseBoolean(System.getProperty("talend.project.reload"));
    PreferenceManipulator preferenceManipulator = new PreferenceManipulator();
    ConnectionBean lastBean = null;
    if (reload) {
        final ConnectionUserPerReader instance = ConnectionUserPerReader.getInstance();
        instance.forceReadConnections();
        final String lastConncetion = ConnectionUserPerReader.getInstance().readLastConncetion();
        for (ConnectionBean bean : instance.readConnections()) {
            if (bean.getName().equals(lastConncetion)) {
                lastBean = bean;
                break;
            }
        }
    }
    if (ArrayUtils.contains(Platform.getApplicationArgs(), EclipseCommandLine.TALEND_DISABLE_LOGINDIALOG_COMMAND)) {
        //$NON-NLS-1$
        boolean deleteProjectIfExist = ArrayUtils.contains(Platform.getApplicationArgs(), "--deleteProjectIfExist");
        IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
        brandingService.getBrandingConfiguration().setUseProductRegistration(false);
        ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
        //$NON-NLS-1$ //$NON-NLS-2$
        String projectName = getAppArgValue("-project", "AUTO_LOGIN_PROJECT");
        //$NON-NLS-1$
        String language = getAppArgValue("-language", ECodeLanguage.JAVA.getName());
        //$NON-NLS-1$ //$NON-NLS-2$
        String login = getAppArgValue("-login", "auto@login.com");
        //$NON-NLS-1$ //$NON-NLS-2$
        String password = getAppArgValue("-loginPass", "");
        //$NON-NLS-1$
        String tacURL = getAppArgValue("-tacURL", null);
        // if tacURL is null, the branch will be no useful.
        //$NON-NLS-1$
        String branch = getAppArgValue("-branch", null);
        // if tacURL is not null, will be remote
        final boolean isRemote = tacURL != null;
        if (reload && lastBean != null) {
            final String lastProject = preferenceManipulator.getLastProject();
            if (lastProject != null) {
                projectName = lastProject;
            }
            final String lastUser = lastBean.getUser();
            if (lastUser != null) {
                login = lastUser;
            }
            final String lastPass = lastBean.getPassword();
            if (lastPass != null) {
                password = lastPass;
            }
        }
        User userInfo = PropertiesFactoryImpl.eINSTANCE.createUser();
        userInfo.setLogin(login);
        try {
            userInfo.setPassword(PasswordHelper.encryptPasswd(password));
        } catch (NoSuchAlgorithmException e) {
            ExceptionHandler.process(e);
        }
        LoginHelper.isAutoLogonFailed = false;
        try {
            ConnectionBean bean = null;
            if (reload && lastBean != null) {
                // reload
                bean = lastBean;
            } else {
                if (tacURL != null && isRemote) {
                    // remote
                    bean = ConnectionBean.getDefaultRemoteConnectionBean();
                    bean.setUser(login);
                    bean.setPassword(password);
                    bean.getDynamicFields().put(RepositoryConstants.REPOSITORY_URL, tacURL);
                } else {
                    bean = ConnectionBean.getDefaultConnectionBean();
                }
            }
            Context ctx = CorePlugin.getContext();
            RepositoryContext repositoryContext = new RepositoryContext();
            ctx.putProperty(Context.REPOSITORY_CONTEXT_KEY, repositoryContext);
            repositoryContext.setUser(userInfo);
            repositoryContext.setClearPassword(password);
            repositoryContext.setFields(bean.getDynamicFields());
            repositoryFactory.setRepositoryFactoryFromProvider(RepositoryFactoryProvider.getRepositoriyById(bean.getRepositoryId()));
            Project project = null;
            for (Project p : repositoryFactory.readProject()) {
                if (p.getLabel().equals(projectName) || p.getTechnicalLabel().equals(projectName)) {
                    project = p;
                    break;
                }
            }
            if (!reload) {
                if (deleteProjectIfExist && project != null) {
                    IWorkspace workspace = ResourcesPlugin.getWorkspace();
                    IProject eclipseProject = workspace.getRoot().getProject(project.getTechnicalLabel());
                    if (eclipseProject.exists()) {
                        eclipseProject.delete(true, new NullProgressMonitor());
                    }
                }
                if (!isRemote && (project == null || deleteProjectIfExist)) {
                    Project projectInfor = //$NON-NLS-1$
                    ProjectHelper.createProject(//$NON-NLS-1$
                    projectName, //$NON-NLS-1$
                    "", language, userInfo);
                    project = repositoryFactory.createProject(projectInfor);
                }
            } else {
                if (project != null && !project.getEmfProject().isLocal() && repositoryFactory.isLocalConnectionProvider()) {
                    List<IRepositoryFactory> rfList = RepositoryFactoryProvider.getAvailableRepositories();
                    IRepositoryFactory remoteFactory = null;
                    for (IRepositoryFactory rf : rfList) {
                        if (!rf.isLocalConnectionProvider()) {
                            remoteFactory = rf;
                            break;
                        }
                    }
                    if (remoteFactory != null) {
                        repositoryFactory.setRepositoryFactoryFromProvider(remoteFactory);
                        repositoryFactory.getRepositoryContext().setOffline(true);
                    }
                }
            }
            if (!repositoryFactory.isLocalConnectionProvider()) {
                ProjectManager.getInstance().setMainProjectBranch(project, preferenceManipulator.getLastSVNBranch(new JSONObject(project.getEmfProject().getUrl()).getString("location"), project.getTechnicalLabel()));
            }
            if (project != null && reload && lastBean != null && repositoryFactory.getRepositoryContext().isOffline()) {
                if (PluginChecker.isSVNProviderPluginLoaded()) {
                    ISVNProviderService svnProviderService = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
                    if (svnProviderService.isSVNProject(project)) {
                        String projectUrl = svnProviderService.getProjectUrl(project);
                        String lastBranch = preferenceManipulator.getLastSVNBranch(projectUrl, project.getTechnicalLabel());
                        ProjectManager.getInstance().setMainProjectBranch(project, lastBranch);
                    }
                }
            }
            if (project == null) {
                //$NON-NLS-1$
                throw new LoginException(Messages.getString("RepositoryService.projectNotFound", projectName));
            }
            repositoryContext.setProject(project);
            repositoryFactory.logOnProject(project, new NullProgressMonitor());
        } catch (final PersistenceException e) {
            if (e instanceof OperationCancelException) {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.getString("LoginDialog.logonCanceled"), e.getLocalizedMessage());
                    }
                });
            } else {
                MessageBoxExceptionHandler.process(e, new Shell());
            }
            repositoryFactory.logOffProject();
            LoginHelper.isAutoLogonFailed = true;
        } catch (LoginException e) {
            MessageBoxExceptionHandler.process(e, new Shell());
            repositoryFactory.logOffProject();
            LoginHelper.isAutoLogonFailed = true;
        } catch (BusinessException e) {
            MessageBoxExceptionHandler.process(e, new Shell());
            repositoryFactory.logOffProject();
            LoginHelper.isAutoLogonFailed = true;
        } catch (CoreException e) {
            MessageBoxExceptionHandler.process(e, new Shell());
            repositoryFactory.logOffProject();
            LoginHelper.isAutoLogonFailed = true;
        } catch (JSONException e) {
            ExceptionHandler.process(e);
            LoginHelper.isAutoLogonFailed = true;
        }
        if (LoginHelper.isAutoLogonFailed) {
            LoginHelper.isRestart = true;
        }
        return true;
    }
    return false;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RepositoryContext(org.talend.core.context.RepositoryContext) PreferenceManipulator(org.talend.core.prefs.PreferenceManipulator) User(org.talend.core.model.properties.User) OperationCancelException(org.talend.commons.exception.OperationCancelException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Shell(org.eclipse.swt.widgets.Shell) BusinessException(org.talend.commons.exception.BusinessException) ConnectionUserPerReader(org.talend.repository.ui.login.connections.ConnectionUserPerReader) IContext(org.talend.core.model.process.IContext) RepositoryContext(org.talend.core.context.RepositoryContext) Context(org.talend.core.context.Context) IRepositoryFactory(org.talend.core.repository.model.IRepositoryFactory) ISVNProviderService(org.talend.core.services.ISVNProviderService) JSONException(org.talend.utils.json.JSONException) IBrandingService(org.talend.core.ui.branding.IBrandingService) IProject(org.eclipse.core.resources.IProject) IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) JSONObject(org.talend.utils.json.JSONObject) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) ConnectionBean(org.talend.core.model.general.ConnectionBean)

Aggregations

ISVNProviderService (org.talend.core.services.ISVNProviderService)6 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)3 IProject (org.eclipse.core.resources.IProject)2 IWorkspace (org.eclipse.core.resources.IWorkspace)2 CoreException (org.eclipse.core.runtime.CoreException)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 IProcess2 (org.talend.core.model.process.IProcess2)2 IBrandingService (org.talend.core.ui.branding.IBrandingService)2 File (java.io.File)1 FileFilter (java.io.FileFilter)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URL (java.net.URL)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Path (org.eclipse.core.runtime.Path)1 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)1 Shell (org.eclipse.swt.widgets.Shell)1 IEditorPart (org.eclipse.ui.IEditorPart)1