Search in sources :

Example 11 with IRunProcessService

use of org.talend.designer.runprocess.IRunProcessService in project tdi-studio-se by Talend.

the class JavaTestShadow method process.

public void process(Text testResultText, TableViewer tableViewer) {
    Map<String, String> map = RoutineFunctionParser.getTypePackgeMethods();
    Function function = CategoryComposite.getSelectedFunction();
    String expression = ExpressionBuilderDialog.getExpressionComposite().getExpression();
    if (function != null && expression != null && !"".equals(expression)) {
        if (serverThread == null || !serverThread.isAlive()) {
            server = ExpressionTestServer.getInstance(Display.getCurrent(), testResultText);
            serverThread = new Thread(server);
            serverThread.start();
        }
        //$NON-NLS-1$
        String methodFullName = map.get(function.getTalendType().getName() + "." + function.getName());
        //$NON-NLS-1$
        String[] fullClassAndMethod = methodFullName.split("\\.");
        String methodName = fullClassAndMethod[fullClassAndMethod.length - 1];
        expression = expression.replaceAll(methodName, methodFullName);
        ExpressionArguments arguments = new ExpressionArguments();
        arguments.setExpression(expression);
        arguments.setVariables((List<Variable>) tableViewer.getInput());
        ExpressionGenerator codeGenerator = new ExpressionGenerator();
        String fileContent = codeGenerator.generate(arguments);
        ITalendProcessJavaProject talendProcessJavaProject = null;
        if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
            IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
            talendProcessJavaProject = processService.getTalendProcessJavaProject();
        }
        if (talendProcessJavaProject == null) {
            return;
        }
        IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
        IFolder outputFolder = talendProcessJavaProject.getOutputFolder();
        //$NON-NLS-1$
        IFile file = srcFolder.getFile(new Path(JavaUtils.JAVA_ROUTINES_DIRECTORY + "/ExpressionVariableTest.java"));
        //$NON-NLS-1$
        IFile classFile = outputFolder.getFile(new Path(JavaUtils.JAVA_ROUTINES_DIRECTORY + "/ExpressionVariableTest.class"));
        InputStream in = new ByteArrayInputStream(fileContent.getBytes());
        try {
            if (!file.exists()) {
                file.create(in, true, null);
            } else {
                file.delete(true, null);
                classFile.delete(true, null);
                file.create(in, true, null);
            }
            while (!classFile.exists()) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e1) {
                    RuntimeExceptionHandler.process(e1);
                }
            }
        } catch (CoreException e1) {
            RuntimeExceptionHandler.process(e1);
        }
        try {
            in.close();
            in = null;
        } catch (IOException e2) {
            RuntimeExceptionHandler.process(e2);
        }
        String javaInterpreter = CorePlugin.getDefault().getPreferenceStore().getString(ITalendCorePrefConstants.JAVA_INTERPRETER);
        IPath path = outputFolder.getLocation();
        //$NON-NLS-1$ //$NON-NLS-2$
        String[] str = new String[] { javaInterpreter, "-cp", path.toOSString(), "routines.ExpressionVariableTest" };
        InputStreamReader reader = null;
        try {
            Process exec = Runtime.getRuntime().exec(str);
            reader = new InputStreamReader(exec.getErrorStream());
            char[] buffer = new char[1024];
            int i = 0;
            StringBuffer bufferString = new StringBuffer();
            while ((i = reader.read(buffer)) != -1) {
                bufferString.append(buffer, 0, i);
            }
            reader.close();
            if (bufferString.length() > 0) {
                testResultText.setText(bufferString.toString());
            }
        } catch (IOException e1) {
            RuntimeExceptionHandler.process(e1);
        } finally {
            reader = null;
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Variable(org.talend.commons.runtime.model.expressionbuilder.Variable) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) IOException(java.io.IOException) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) Function(org.talend.designer.rowgenerator.data.Function) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IFolder(org.eclipse.core.resources.IFolder)

Example 12 with IRunProcessService

use of org.talend.designer.runprocess.IRunProcessService in project tdi-studio-se by Talend.

the class ActiveProcessTracker method partClosed.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart)
     */
@Override
public void partClosed(IWorkbenchPart part) {
    if (part instanceof AbstractMultiPageTalendEditor && currentProcess != null) {
        AbstractMultiPageTalendEditor mpte = (AbstractMultiPageTalendEditor) part;
        if (mpte.isKeepPropertyLocked()) {
            currentProcess = null;
            return;
        }
        IProcess process = getJobFromActivatedEditor(part);
        if (process != null) {
            Problems.removeProblemsByProcess(process);
            Problems.removeJob(process);
            IRunProcessService service = DesignerPlugin.getDefault().getRunProcessService();
            service.removeProcess(process);
            CodeView.refreshCodeView(null);
            if (currentProcess == process) {
                //$NON-NLS-1$
                Contexts.setTitle("");
                Contexts.clearAll();
                if (lastProcessOpened == currentProcess) {
                    lastProcessOpened = null;
                }
                currentProcess = null;
                for (IJobTrackerListener listener : jobTrackerListeners) {
                    listener.allJobClosed();
                }
            } else if (lastProcessOpened == process) {
                lastProcessOpened = currentProcess;
            }
            if (GlobalServiceRegister.getDefault().isServiceRegistered(ISQLBuilderService.class)) {
                ISQLBuilderService sqlBuilderService = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
                sqlBuilderService.closeSqlBuilderDialogs(process.getName());
            }
        }
    } else if (part instanceof IEditorPart) {
        if (GlobalServiceRegister.getDefault().isServiceRegistered(IDiagramModelService.class) && CorePlugin.getDefault().getDiagramModelService().isBusinessDiagramEditor((IEditorPart) part)) {
            //$NON-NLS-1$
            Contexts.setTitle("");
            Contexts.clearAll();
        }
    }
    if (part instanceof AbstractMultiPageTalendEditor) {
        AbstractMultiPageTalendEditor mpte = (AbstractMultiPageTalendEditor) part;
        mpte.beforeDispose();
        JobSettings.switchToCurJobSettingsView();
    }
}
Also used : IRunProcessService(org.talend.designer.runprocess.IRunProcessService) IEditorPart(org.eclipse.ui.IEditorPart) IProcess(org.talend.core.model.process.IProcess) ISQLBuilderService(org.talend.core.ui.services.ISQLBuilderService)

Example 13 with IRunProcessService

use of org.talend.designer.runprocess.IRunProcessService in project tdi-studio-se by Talend.

the class EditPropertiesAction method processRename.

protected void processRename(IRepositoryNode node, String originalName) {
    try {
        IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
        ITalendProcessJavaProject talendProcessJavaProject = runProcessService.getTalendProcessJavaProject();
        if (talendProcessJavaProject == null) {
            return;
        }
        IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
        IPackageFragmentRoot root = talendProcessJavaProject.getJavaProject().getPackageFragmentRoot(srcFolder);
        // add for bug TDI-24379 on August 23, 2013.
        IFolder srcInterFolder = srcFolder.getFolder(JavaUtils.JAVA_INTERNAL_DIRECTORY);
        if (srcInterFolder.exists()) {
            File file = new File(srcInterFolder.getLocationURI());
            for (File f : file.listFiles()) {
                if (f.isFile()) {
                    f.delete();
                }
            }
        }
        // qli modified to fix the bug 5400 and 6185.
        // update for fix [TESB-6784]
        IPackageFragment routinesPkg = getPackageFragment(root, node);
        // ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName +
        // SuffixConstants.SUFFIX_STRING_java);
        //$NON-NLS-1$
        ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName + ".java");
        if (unit == null) {
            return;
        }
        String newName = node.getObject().getProperty().getLabel();
        JavaRenameProcessor processor = new RenameCompilationUnitProcessor(unit);
        // processor.setNewElementName(newName + SuffixConstants.SUFFIX_STRING_java);
        //$NON-NLS-1$
        processor.setNewElementName(newName + ".java");
        RenameRefactoring ref = new RenameRefactoring(processor);
        final PerformRefactoringOperation operation = new PerformRefactoringOperation(ref, CheckConditionsOperation.ALL_CONDITIONS);
        IRunnableWithProgress r = new IRunnableWithProgress() {

            @Override
            public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            operation.run(monitor);
                        } catch (CoreException e) {
                            ExceptionHandler.process(e);
                        }
                    }
                });
            }
        };
        PlatformUI.getWorkbench().getProgressService().run(true, true, r);
        RefactoringStatus conditionStatus = operation.getConditionStatus();
        if (conditionStatus.hasError()) {
            //$NON-NLS-1$
            String errorMessage = Messages.getString("EditPropertiesAction.renameError", unit.getElementName(), newName);
            RefactoringStatusEntry[] entries = conditionStatus.getEntries();
            for (RefactoringStatusEntry entry : entries) {
                //$NON-NLS-1$
                errorMessage += "\n>>>" + entry.getMessage();
            }
            Shell shell = null;
            IRepositoryView viewPart = getViewPart();
            if (viewPart != null) {
                shell = viewPart.getViewSite().getShell();
            } else {
                shell = Display.getCurrent().getActiveShell();
            }
            //$NON-NLS-1$
            MessageDialog.openError(shell, Messages.getString("EditPropertiesAction.warning"), errorMessage);
            return;
        }
        // ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + SuffixConstants.SUFFIX_STRING_java);
        //$NON-NLS-1$
        ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + ".java");
        if (newUnit == null) {
            return;
        }
        RoutineItem item = (RoutineItem) node.getObject().getProperty().getItem();
        IFile javaFile = (IFile) newUnit.getAdapter(IResource.class);
        try {
            ByteArray byteArray = item.getContent();
            byteArray.setInnerContentFromFile(javaFile);
            IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
            IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
            repFactory.save(item);
        } catch (Exception e) {
            // e.printStackTrace();
            ExceptionHandler.process(e);
        }
    } catch (Exception e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) PerformRefactoringOperation(org.eclipse.ltk.core.refactoring.PerformRefactoringOperation) IRepositoryView(org.talend.repository.ui.views.IRepositoryView) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IRepositoryService(org.talend.repository.model.IRepositoryService) Shell(org.eclipse.swt.widgets.Shell) ByteArray(org.talend.core.model.properties.ByteArray) JavaRenameProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.JavaRenameProcessor) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) RefactoringStatusEntry(org.eclipse.ltk.core.refactoring.RefactoringStatusEntry) RoutineItem(org.talend.core.model.properties.RoutineItem) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) RenameCompilationUnitProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameCompilationUnitProcessor) CoreException(org.eclipse.core.runtime.CoreException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 14 with IRunProcessService

use of org.talend.designer.runprocess.IRunProcessService in project tdi-studio-se by Talend.

the class ContextModifyCommand method getContextResource.

/**
     * Gets the context file resource according to the project type.
     * 
     * @param process
     * @param context
     * @return
     */
private IResource getContextResource(IProcess2 process, IContext context) throws Exception {
    IPath path = new Path(JavaResourcesHelper.getProjectFolderName(process.getProperty().getItem())).append(JavaResourcesHelper.getJobFolderName(process.getName(), process.getVersion())).append(JavaUtils.JAVA_CONTEXTS_DIRECTORY).append(context.getName() + JavaUtils.JAVA_CONTEXT_EXTENSION);
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
        IRunProcessService service = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
        ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
        if (talendProcessJavaProject != null) {
            IFolder srcFolder = talendProcessJavaProject.getResourcesFolder();
            return srcFolder.getFile(path);
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IFolder(org.eclipse.core.resources.IFolder)

Example 15 with IRunProcessService

use of org.talend.designer.runprocess.IRunProcessService in project tdi-studio-se by Talend.

the class JobLaunchConfigurationDelegate method launch.

@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
    String jobId = configuration.getAttribute(TalendDebugUIConstants.JOB_ID, (String) null);
    String jobName = configuration.getAttribute(TalendDebugUIConstants.JOB_NAME, (String) null);
    String jobVersion = configuration.getAttribute(TalendDebugUIConstants.JOB_VERSION, (String) null);
    // find process from open editor.
    IProcess2 process = DesignerUtilities.findProcessFromEditors(jobId, jobVersion);
    // find process from repository
    if (process == null) {
        process = findProcessFromRepository(jobId, jobVersion);
    }
    if (process == null) {
        //$NON-NLS-1$
        ExceptionHandler.log(Messages.getString("JobLaunchConfigurationDelegate.jobNotFound", jobName));
        return;
    }
    final IProcess2 p = process;
    // Run job
    Display.getDefault().asyncExec(new Runnable() {

        @Override
        public void run() {
            IRunProcessService service = DesignerPlugin.getDefault().getRunProcessService();
            service.setActiveProcess(p);
            service.refreshView();
            service.getRunProcessAction().run();
        }
    });
}
Also used : IRunProcessService(org.talend.designer.runprocess.IRunProcessService) IProcess2(org.talend.core.model.process.IProcess2)

Aggregations

IRunProcessService (org.talend.designer.runprocess.IRunProcessService)51 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)30 IFolder (org.eclipse.core.resources.IFolder)17 IFile (org.eclipse.core.resources.IFile)15 File (java.io.File)14 IOException (java.io.IOException)13 ArrayList (java.util.ArrayList)12 CoreException (org.eclipse.core.runtime.CoreException)11 URL (java.net.URL)9 PersistenceException (org.talend.commons.exception.PersistenceException)9 MalformedURLException (java.net.MalformedURLException)7 IPath (org.eclipse.core.runtime.IPath)7 IProcess (org.talend.core.model.process.IProcess)7 ProcessorException (org.talend.designer.runprocess.ProcessorException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 DocumentException (org.dom4j.DocumentException)5 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 HashSet (java.util.HashSet)4 ProcessItem (org.talend.core.model.properties.ProcessItem)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3