Search in sources :

Example 16 with IRunProcessService

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

the class StandAloneTalendJavaEditor method doSave.

@Override
public void doSave(final IProgressMonitor monitor) {
    IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
    final IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
    try {
        repFactory.lock(item);
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    ERepositoryStatus status = repFactory.getStatus(item);
    if (!status.equals(ERepositoryStatus.LOCK_BY_USER) && !repFactory.getRepositoryContext().isEditableAsReadOnly()) {
        MessageDialog.openWarning(getEditorSite().getShell(), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveTitle"), Messages.getString("AbstractMultiPageTalendEditor.canNotSaveMessage.routine"));
        return;
    }
    EList adapters = item.getProperty().eAdapters();
    adapters.remove(dirtyListener);
    super.doSave(monitor);
    try {
        resetItem();
        ByteArray byteArray = item.getContent();
        byteArray.setInnerContentFromFile(((FileEditorInput) getEditorInput()).getFile());
        final IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
        runProcessService.buildJavaProject();
        // check syntax error
        addProblems();
        //$NON-NLS-1$
        String name = "Save Routine";
        RepositoryWorkUnit<Object> repositoryWorkUnit = new RepositoryWorkUnit<Object>(name, this) {

            @Override
            protected void run() throws LoginException, PersistenceException {
                refreshJobAndSave(repFactory);
            }
        };
        repositoryWorkUnit.setAvoidSvnUpdate(true);
        repositoryWorkUnit.setAvoidUnloadResources(true);
        repFactory.executeRepositoryWorkUnit(repositoryWorkUnit);
        repositoryWorkUnit.throwPersistenceExceptionIfAny();
    // for bug 11930: Unable to save Routines.* in db project
    // repFactory.save(item);
    // startRefreshJob(repFactory);
    } catch (Exception e) {
        // e.printStackTrace();
        ExceptionHandler.process(e);
    }
}
Also used : ERepositoryStatus(org.talend.commons.runtime.model.repository.ERepositoryStatus) EList(org.eclipse.emf.common.util.EList) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ByteArray(org.talend.core.model.properties.ByteArray) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryService(org.talend.repository.model.IRepositoryService)

Example 17 with IRunProcessService

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

the class JavaCommandController method createControl.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties.controllers.AbstractElementPropertySectionController#createControl
     * (org.eclipse.swt.widgets.Composite, org.talend.core.model.process.IElementParameter, int, int, int,
     * org.eclipse.swt.widgets.Control)
     */
@Override
public Control createControl(Composite subComposite, final IElementParameter param, int numInRow, int nbInRow, int top, Control lastControl) {
    Button btnEdit;
    //$NON-NLS-1$
    btnEdit = getWidgetFactory().createButton(subComposite, "", SWT.PUSH);
    btnEdit.setImage(ImageProvider.getImage(CoreUIPlugin.getImageDescriptor(DOTS_BUTTON)));
    FormData data;
    btnEdit.setData(NAME, JAVA_COMMAND);
    btnEdit.setData(PARAMETER_NAME, param.getName());
    btnEdit.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            // execute Java Command
            ElementParameter fullParam = (ElementParameter) param;
            File jar;
            URL url;
            try {
                List<URL> listURL = new ArrayList<URL>();
                ILibraryManagerService libManager = (ILibraryManagerService) GlobalServiceRegister.getDefault().getService(ILibraryManagerService.class);
                IFolder javaLibFolder = null;
                if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
                    IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
                    ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendProcessJavaProject();
                    if (talendProcessJavaProject != null) {
                        javaLibFolder = talendProcessJavaProject.getLibFolder();
                    }
                }
                if (javaLibFolder == null) {
                    return;
                }
                for (String jarString : fullParam.getJar().split(";")) {
                    IPath libPath = javaLibFolder.getLocation();
                    libManager.retrieve(jarString, libPath.toPortableString(), new NullProgressMonitor());
                    jar = libPath.append(jarString).toFile();
                    url = jar.toURL();
                    listURL.add(url);
                }
                URLClassLoader urlClassLoader = new URLClassLoader(listURL.toArray(new URL[0]));
                Class<?> classLoaded = Class.forName(fullParam.getJavaClass(), true, urlClassLoader);
                Object object = classLoaded.newInstance();
                List<String> args = new ArrayList<String>();
                for (String arg : fullParam.getArgs()) {
                    args.add(ElementParameterParser.parse(elem, arg));
                }
                for (Method method : classLoaded.getDeclaredMethods()) {
                    if (method.getName().equals(fullParam.getJavaFunction())) {
                        Object[] arglist = new Object[1];
                        arglist[0] = args.toArray(new String[0]);
                        method.invoke(object, arglist);
                    }
                }
            } catch (Exception e1) {
                MessageBoxExceptionHandler.process(e1);
            }
        }
    });
    if (elem instanceof Node) {
        btnEdit.setToolTipText(VARIABLE_TOOLTIP + param.getVariableName());
    }
    CLabel labelLabel = getWidgetFactory().createCLabel(subComposite, param.getDisplayName());
    data = new FormData();
    if (lastControl != null) {
        data.left = new FormAttachment(lastControl, 0);
    } else {
        data.left = new FormAttachment((((numInRow - 1) * MAX_PERCENT) / nbInRow), 0);
    }
    data.top = new FormAttachment(0, top);
    labelLabel.setLayoutData(data);
    if (numInRow != 1) {
        labelLabel.setAlignment(SWT.RIGHT);
    }
    // **************************
    data = new FormData();
    int currentLabelWidth = STANDARD_LABEL_WIDTH;
    GC gc = new GC(labelLabel);
    Point labelSize = gc.stringExtent(param.getDisplayName());
    gc.dispose();
    if ((labelSize.x + ITabbedPropertyConstants.HSPACE) > currentLabelWidth) {
        currentLabelWidth = labelSize.x + ITabbedPropertyConstants.HSPACE;
    }
    if (numInRow == 1) {
        if (lastControl != null) {
            data.left = new FormAttachment(lastControl, currentLabelWidth);
            data.right = new FormAttachment(lastControl, currentLabelWidth + STANDARD_BUTTON_WIDTH);
        } else {
            data.left = new FormAttachment(0, currentLabelWidth);
            data.right = new FormAttachment(0, currentLabelWidth + STANDARD_BUTTON_WIDTH);
        }
    } else {
        data.left = new FormAttachment(labelLabel, 0, SWT.RIGHT);
        data.right = new FormAttachment(labelLabel, STANDARD_BUTTON_WIDTH, SWT.RIGHT);
    }
    data.top = new FormAttachment(0, top);
    btnEdit.setLayoutData(data);
    // **************************
    hashCurControls.put(param.getName(), btnEdit);
    Point initialSize = btnEdit.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    dynamicProperty.setCurRowSize(initialSize.y + ITabbedPropertyConstants.VSPACE);
    return btnEdit;
}
Also used : CLabel(org.eclipse.swt.custom.CLabel) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) Node(org.talend.designer.core.ui.editor.nodes.Node) URL(java.net.URL) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) ILibraryManagerService(org.talend.core.ILibraryManagerService) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) GC(org.eclipse.swt.graphics.GC) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormData(org.eclipse.swt.layout.FormData) IPath(org.eclipse.core.runtime.IPath) Method(java.lang.reflect.Method) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) URLClassLoader(java.net.URLClassLoader) File(java.io.File) SelectionListener(org.eclipse.swt.events.SelectionListener) IFolder(org.eclipse.core.resources.IFolder)

Example 18 with IRunProcessService

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

the class MultipleThreadDynamicComposite method operationInThread.

// refactore to be synchonized with the dispose() method because of TDI-24184
// the synchronized methodis a quick fix but not the ideal one because this method is accessing many attributes
// of the current class that may be modified by other thread (just like "elem" modified by the dispose() method.
protected synchronized void operationInThread() {
    if (elem == null) {
        return;
    }
    // hywang modified for
    List<? extends IElementParameter> listParam = elem.getElementParametersWithChildrens();
    Boolean updateNeeded = (Boolean) elem.getPropertyValue(updataComponentParamName);
    if (updateNeeded != null) {
        if (updateNeeded) {
            if (elem != null) {
                addComponents(forceRedraw);
                elem.setPropertyValue(updataComponentParamName, new Boolean(false));
                forceRedraw = false;
            }
        }
    }
    final ECodeLanguage language = ((RepositoryContext) org.talend.core.CorePlugin.getContext().getProperty(org.talend.core.context.Context.REPOSITORY_CONTEXT_KEY)).getProject().getLanguage();
    IRunProcessService service = DesignerPlugin.getDefault().getRunProcessService();
    final ICodeProblemsChecker syntaxChecker = service.getSyntaxChecker(language);
    List<Problem> javaProblem = null;
    for (int i = 0; i < listParam.size(); i++) {
        if (listParam.get(i).getCategory() == section) {
            if (listParam.get(i).isShow(listParam)) {
                final IElementParameter e = listParam.get(i);
                e.isReadOnly();
                e.isNoCheck();
                if (language == ECodeLanguage.JAVA && javaProblem == null) {
                    if (!e.isReadOnly() && !e.isNoCheck()) {
                        javaProblem = syntaxChecker.checkProblems(null);
                    }
                }
                final List<Problem> nodePros = javaProblem;
                if (generator != null) {
                    AbstractElementPropertySectionController controller = generator.getController(e.getFieldType(), MultipleThreadDynamicComposite.this);
                    if (controller != null) {
                        controller.updateCodeProblems(nodePros);
                        controller.refresh(e, checkErrorsWhenViewRefreshed);
                    }
                }
            }
        }
    }
    if (propertyResized) {
        try {
            removeListener(SWT.Resize, resizeListener);
            getParent().layout();
            composite.pack();
            propertyResized = false;
            addListener(SWT.Resize, resizeListener);
        } catch (Exception e) {
        }
    }
    checkErrorsWhenViewRefreshed = false;
//        long time = TimeMeasure.timeSinceBegin("DC:refresh:" + getCurrentComponent()); //$NON-NLS-1$
//        TimeMeasure.end("DC:refresh:" + getCurrentComponent()); //$NON-NLS-1$
// if (DynamicTabbedPropertySection.DEBUG_TIME) {
//            System.out.println("DC;total;" + getCurrentComponent() + ";" + time); //$NON-NLS-1$ //$NON-NLS-2$
// }
}
Also used : AbstractElementPropertySectionController(org.talend.designer.core.ui.editor.properties.controllers.AbstractElementPropertySectionController) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ICodeProblemsChecker(org.talend.core.language.ICodeProblemsChecker) IElementParameter(org.talend.core.model.process.IElementParameter) Problem(org.talend.core.model.process.Problem) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 19 with IRunProcessService

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

the class JavaCamelJobScriptsExportWSAction method collectBuildArtifacts.

protected void collectBuildArtifacts() throws IOException {
    IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
    for (Map.Entry<IRepositoryViewObject, Map<String, File>> e : buildArtifactsMap.entrySet()) {
        IRepositoryViewObject repoObject = e.getKey();
        Map<String, File> m = e.getValue();
        ITalendProcessJavaProject talendProcessJavaProject = runProcessService.getTalendJobJavaProject(repoObject.getProperty());
        String bundleVersion = null;
        if (repoObject != null && JobUtils.isJob(repoObject.getProperty())) {
            IProcess process = CoreRuntimePlugin.getInstance().getDesignerCoreService().getProcessFromItem(repoObject.getProperty().getItem());
            if (process != null && ProcessUtils.isChildRouteProcess(process)) {
                bundleVersion = PomIdsHelper.getJobVersion(routeObject.getProperty());
            }
        } else if (repoObject != null && JobUtils.isRoute(repoObject.getProperty()) && routeObject != null) {
            bundleVersion = PomIdsHelper.getJobVersion(routeObject.getProperty());
        }
        for (Map.Entry<String, File> e1 : m.entrySet()) {
            String extension = e1.getKey();
            if (extension != null && extension.equalsIgnoreCase("jar") && bundleVersion != null) {
                extension = "-" + bundleVersion + "." + extension;
            }
            File destination = e1.getValue();
            List<File> fileList = new ArrayList<File>();
            FilesUtils.getAllFilesFromFolder(talendProcessJavaProject.getTargetFolder().getLocation().toFile(), fileList, null);
            if (!fileList.isEmpty()) {
                for (File f : fileList) {
                    if (f.isFile() && f.getName().endsWith(extension) && destination != null && StringUtils.isNotBlank(destination.getPath())) {
                        if (!"classpath.jar".equalsIgnoreCase(f.getName())) {
                            FilesUtils.copyFile(f, destination);
                            break;
                        }
                    }
                }
            }
        }
    }
}
Also used : IRunProcessService(org.talend.designer.runprocess.IRunProcessService) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ArrayList(java.util.ArrayList) Map(java.util.Map) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap) File(java.io.File) IProcess(org.talend.core.model.process.IProcess) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject)

Example 20 with IRunProcessService

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

the class RouteResourceUtil method synchronizeRouteResource.

public static Collection<IPath> synchronizeRouteResource(final ProcessItem item) {
    final boolean routelet;
    if (item.eClass() == CamelPropertiesPackage.Literals.CAMEL_PROCESS_ITEM) {
        routelet = false;
    } else if (item.eClass() == CamelPropertiesPackage.Literals.ROUTELET_PROCESS_ITEM) {
        routelet = true;
    } else {
        return null;
    }
    if (!GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
        return null;
    }
    final IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
    final ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendJobJavaProject(item.getProperty());
    if (talendProcessJavaProject == null) {
        return null;
    }
    final IFolder routeExternalResourceFolder = talendProcessJavaProject.getExternalResourcesFolder();
    final IFolder routeResourceFolder = talendProcessJavaProject.getResourcesFolder();
    final Collection<IPath> result = new ArrayList<IPath>();
    // add spring file
    if (!routelet) {
        final IFolder metaExtInf = routeExternalResourceFolder.getFolder("META-INF/spring/");
        final IFolder metaInf = routeResourceFolder.getFolder("META-INF/spring/");
        try {
            prepareFolder(metaExtInf);
            prepareFolder(metaInf);
            final IFile springExt = metaExtInf.getFile(item.getProperty().getLabel().toLowerCase() + ".xml");
            final IFile spring = metaInf.getFile(item.getProperty().getLabel().toLowerCase() + ".xml");
            final InputStream inputStream = new ByteArrayInputStream(((CamelProcessItem) item).getSpringContent().getBytes());
            routeExternalResourceFolder.refreshLocal(IResource.DEPTH_INFINITE, null);
            routeResourceFolder.refreshLocal(IResource.DEPTH_INFINITE, null);
            if (springExt.exists()) {
                springExt.setContents(inputStream, 0, null);
            } else {
                springExt.create(inputStream, true, null);
            }
            result.add(springExt.getLocation());
            if (spring.exists()) {
                spring.setContents(springExt.getContents(), 0, null);
            } else {
                spring.create(springExt.getContents(), true, null);
            }
        } catch (CoreException e) {
            ExceptionHandler.process(e);
        }
    }
    for (ResourceDependencyModel model : getResourceDependencies(item)) {
        IFile file = copyResources(routeExternalResourceFolder, model);
        String itemName = getItemName(model.getItem()) + file.getName();
        if (file != null) {
            try {
                FilesUtils.copyFile(file.getLocation().toFile(), new File(talendProcessJavaProject.getBundleResourcesFolder().getLocation().toOSString() + File.separator + RESOURCES + File.separator + itemName));
                FilesUtils.copyFile(file.getLocation().toFile(), new File(talendProcessJavaProject.getResourcesFolder().getLocation().toOSString() + File.separator + itemName));
            } catch (IOException e) {
                e.printStackTrace();
            }
            result.add(file.getLocation());
        }
    }
    return result;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ResourceDependencyModel(org.talend.designer.camel.resource.core.model.ResourceDependencyModel) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) CamelProcessItem(org.talend.camel.core.model.camelProperties.CamelProcessItem) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

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