Search in sources :

Example 1 with IRunProcessService

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

the class Log4jSettingPage method performOk.

@Override
public boolean performOk() {
    boolean ok = super.performOk();
    if (templateTxt != null && !templateTxt.isDisposed()) {
        IRunProcessService service = null;
        if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
            service = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
        }
        if (reset) {
            if (service != null) {
                Log4jPrefsSettingManager.getInstance().saveLog4jNodeIntoPref(Log4jPrefsConstants.LOG4J_ENABLE_NODE, String.valueOf(false));
                Log4jPrefsSettingManager.getInstance().saveLog4jNodeIntoPref(Log4jPrefsConstants.LOG4J_CONTENT_NODE, service.getLogTemplate(Log4jPrefsConstants.LOG4JFILEPATH));
            }
        } else {
            if (log4jBtn != null && !log4jBtn.isDisposed()) {
                Log4jPrefsSettingManager.getInstance().saveLog4jNodeIntoPref(Log4jPrefsConstants.LOG4J_ENABLE_NODE, String.valueOf(log4jBtn.getSelection()));
            }
            Log4jPrefsSettingManager.getInstance().saveLog4jNodeIntoPref(Log4jPrefsConstants.LOG4J_CONTENT_NODE, templateTxt.getText());
        }
        reset = false;
    }
    // updat the log4j file for code project
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ICoreService.class)) {
        ICoreService service = (ICoreService) GlobalServiceRegister.getDefault().getService(ICoreService.class);
        if (service != null) {
            service.syncLog4jSettings();
        }
    }
    return ok;
}
Also used : IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ICoreService(org.talend.core.ICoreService)

Example 2 with IRunProcessService

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

the class RepositoryPreferenceInitializer method getTemplateTxt.

private String getTemplateTxt(String path) {
    IRunProcessService service = null;
    String templateString = "";
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
        service = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
    }
    if (service != null) {
        templateString = service.getLogTemplate(path);
    }
    return templateString;
}
Also used : IRunProcessService(org.talend.designer.runprocess.IRunProcessService)

Example 3 with IRunProcessService

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

the class WSDL2JAVAController method syncRoutine.

/**
     * DOC xtan there will be refactor for this method with JavaRoutineSynchronizer.syncRoutine().
     * 
     * @param routineItem
     * @param copyToTemp
     * @return
     * @throws SystemException
     */
private IFile syncRoutine(RoutineItem routineItem, boolean copyToTemp, String name) throws SystemException {
    FileOutputStream fos = null;
    try {
        IRunProcessService service = DesignerPlugin.getDefault().getRunProcessService();
        ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
        if (talendProcessJavaProject == null) {
            return null;
        }
        IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
        IFile file = srcFolder.getFile(JavaUtils.JAVA_ROUTINES_DIRECTORY + '/' + routineItem.getProperty().getLabel() + JavaUtils.JAVA_EXTENSION);
        if (copyToTemp) {
            String routineContent = new String(routineItem.getContent().getInnerContent());
            routineContent = chanageRoutinesPackage(routineContent, name);
            String label = routineItem.getProperty().getLabel();
            if (!label.equals(ITalendSynchronizer.TEMPLATE)) {
                routineContent = routineContent.replaceAll(ITalendSynchronizer.TEMPLATE, label);
                File f = file.getLocation().toFile();
                fos = new FileOutputStream(f);
                fos.write(routineContent.getBytes());
                fos.close();
            }
        }
        if (!file.exists()) {
            file.refreshLocal(1, null);
        }
        return file;
    } catch (CoreException e) {
        throw new SystemException(e);
    } catch (IOException e) {
        throw new SystemException(e);
    } finally {
        try {
            fos.close();
        } catch (Exception e) {
            // ignore me even if i'm null
            ExceptionHandler.process(e);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) SystemException(org.talend.commons.exception.SystemException) FileOutputStream(java.io.FileOutputStream) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) IOException(java.io.IOException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) CoreException(org.eclipse.core.runtime.CoreException) SystemException(org.talend.commons.exception.SystemException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) IFolder(org.eclipse.core.resources.IFolder)

Example 4 with IRunProcessService

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

the class TalendJavaSourceViewer method createViewerWithVariables.

public static ReconcilerViewer createViewerWithVariables(Composite composite, int styles, IExpressionDataBean dataBean) {
    IDocument document = new Document();
    StringBuffer buff = new StringBuffer();
    //$NON-NLS-1$
    buff.append("\npackage internal;\n\n");
    buff.append(getImports());
    //$NON-NLS-1$ //$NON-NLS-2$
    buff.append("public class " + VIEWER_CLASS_NAME + currentId + " {\n");
    IRunProcessService runProcessService = getRunProcessService();
    if (runProcessService != null && runProcessService.getSelectedContext() != null) {
        List<IContextParameter> params = runProcessService.getSelectedContext().getContextParameterList();
        buff.append(TEXT_1);
        for (IContextParameter ctxParam : params) {
            buff.append(TEXT_2);
            buff.append(ctxParam.getName());
            buff.append(TEXT_3);
            buff.append(ctxParam.getName());
            buff.append(TEXT_4);
        }
        buff.append(TEXT_5);
        for (IContextParameter ctxParam : params) {
            if (//$NON-NLS-1$ //$NON-NLS-2$
            ctxParam.getType().equals("id_List Of Value") || ctxParam.getType().equals("id_File") || ctxParam.getType().equals("id_Directory") || ctxParam.getType().equals("id_Character")) {
                //$NON-NLS-1$ //$NON-NLS-2$
                buff.append(TEXT_6);
                buff.append(ctxParam.getName());
                buff.append(TEXT_7);
            } else {
                buff.append(TEXT_8);
                buff.append(JavaTypesManager.getTypeToGenerate(ctxParam.getType(), true));
                buff.append(TEXT_9);
                buff.append(ctxParam.getName());
                buff.append(TEXT_10);
            }
        }
        buff.append(TEXT_11);
        //$NON-NLS-1$
        buff.append("\tprivate static ContextProperties context = new ContextProperties();\n");
        //$NON-NLS-1$
        buff.append("\tprivate static final java.util.Map<String, Object> globalMap = new java.util.HashMap<String, Object>();\n");
        if (dataBean != null) {
            buff.append(parseVariables(dataBean.getVariables()));
            //$NON-NLS-1$ //$NON-NLS-2$
            buff.append("\tpublic " + dataBean.getExpressionType() + " myFunction(){\n");
        }
        //$NON-NLS-1$
        buff.append("\t\treturn \n");
    }
    int length = buff.toString().length();
    //$NON-NLS-1$
    String defaultValue = "";
    //$NON-NLS-1$
    buff.append(defaultValue + "\n;\t\n}\n}");
    document.set(buff.toString());
    return initializeViewer(composite, styles, true, document, length);
}
Also used : IRunProcessService(org.talend.designer.runprocess.IRunProcessService) Document(org.eclipse.jface.text.Document) IDocument(org.eclipse.jface.text.IDocument) IContextParameter(org.talend.core.model.process.IContextParameter) IDocument(org.eclipse.jface.text.IDocument)

Example 5 with IRunProcessService

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

the class BDJobReArchieveCreator method create.

public void create(File file, boolean isExport) {
    if (file == null || !file.exists() || (isExport && !file.isFile()) || fatherProcessItem == null) {
        return;
    }
    // check
    if (!isMRWithHDInsight() && !isFatJar()) {
        return;
    }
    Property property = processItem.getProperty();
    Property fatherProperty = fatherProcessItem.getProperty();
    String label = property.getLabel();
    String fatherLabel = fatherProperty.getLabel();
    String version = property.getVersion();
    JavaJobExportReArchieveCreator creator = new JavaJobExportReArchieveCreator(file.getAbsolutePath(), label);
    String jobJarName = JavaResourcesHelper.getJobJarName(property.getLabel(), property.getVersion()) + FileExtensions.JAR_FILE_SUFFIX;
    try {
        if (isExport) {
            // If we are in an export context, we first unzip the archive, then we modify the jar.
            // create temp folders.
            // clean temp folder
            creator.deleteTempFiles();
            //$NON-NLS-1$ //$NON-NLS-2$
            File zipTmpFolder = new File(creator.getTmpFolder(), "zip-" + label + "_" + version);
            //$NON-NLS-1$ //$NON-NLS-2$
            File jarTmpFolder = new File(creator.getTmpFolder(), "jar-" + label + "_" + version);
            zipTmpFolder.mkdirs();
            jarTmpFolder.mkdirs();
            // unzip the files.
            FilesUtils.unzip(file.getAbsolutePath(), zipTmpFolder.getAbsolutePath());
            // same the the job pom assembly for package.
            File originalJarFile = new File(zipTmpFolder, fatherLabel + '/' + jobJarName);
            modifyJar(originalJarFile, jarTmpFolder, creator, jobJarName, zipTmpFolder, property);
            ZipToFile.zipFile(zipTmpFolder.getAbsolutePath(), file.getAbsolutePath());
        } else {
            // If we are in a local context, we just have to modify the jar.
            // clean temp folder
            creator.deleteTempFiles();
            //$NON-NLS-1$ //$NON-NLS-2$
            File jarTmpFolder = new File(creator.getTmpFolder(), "jar-" + label + "_" + version);
            jarTmpFolder.mkdirs();
            if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
                IRunProcessService service = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
                ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
                File targetFolder = new File(talendProcessJavaProject.getTargetFolder().getLocationURI());
                // In a local mode, the routines/beans/udfs jars are not in the lib folder. We then copy them.
                // Copy routines and rename it to match the
                // "JavaUtils.ROUTINE_JAR_NAME + FileExtensions.JAR_FILE_SUFFIX" name
                Set<FilterInfo> codeJars = new HashSet<FilterInfo>(Arrays.asList(new FilterInfo(JavaUtils.ROUTINE_JAR_NAME, FileExtensions.JAR_FILE_SUFFIX)));
                for (File f : FileUtils.getAllFilesFromFolder(targetFolder, codeJars)) {
                    FilesUtils.copyFile(f, new File(talendProcessJavaProject.getLibFolder().getLocation().toPortableString() + "/" + JavaUtils.ROUTINE_JAR_NAME + //$NON-NLS-1$
                    FileExtensions.JAR_FILE_SUFFIX));
                }
                // Copy beans and rename it to match the "JavaUtils.BEANS_JAR_NAME + FileExtensions.JAR_FILE_SUFFIX"
                // name
                codeJars = new HashSet<FilterInfo>(Arrays.asList(new FilterInfo(JavaUtils.BEANS_JAR_NAME, FileExtensions.JAR_FILE_SUFFIX)));
                for (File f : FileUtils.getAllFilesFromFolder(targetFolder, codeJars)) {
                    FilesUtils.copyFile(f, new File(talendProcessJavaProject.getLibFolder().getLocation().toPortableString() + "/" + JavaUtils.BEANS_JAR_NAME + //$NON-NLS-1$
                    FileExtensions.JAR_FILE_SUFFIX));
                }
                // Copy udfs and rename it to match the
                // "JavaUtils.PIGUDFS_JAR_NAME + FileExtensions.JAR_FILE_SUFFIX"
                // name
                codeJars = new HashSet<FilterInfo>(Arrays.asList(new FilterInfo(JavaUtils.PIGUDFS_JAR_NAME, FileExtensions.JAR_FILE_SUFFIX)));
                for (File f : FileUtils.getAllFilesFromFolder(targetFolder, codeJars)) {
                    FilesUtils.copyFile(f, new File(talendProcessJavaProject.getLibFolder().getLocation().toPortableString() + "/" + JavaUtils.PIGUDFS_JAR_NAME + //$NON-NLS-1$
                    FileExtensions.JAR_FILE_SUFFIX));
                }
                modifyJar(new File(file, jobJarName), jarTmpFolder, creator, jobJarName, talendProcessJavaProject.getLibFolder().getParent().getLocation().toFile(), property);
            } else {
                //$NON-NLS-1$
                CommonExceptionHandler.log("Unable to update the job jar because the RunProcessService is not registered.");
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    } finally {
        // when debug, keep the files first. because when build again. will do clean also.
        if (!CommonsPlugin.isDebugMode()) {
            creator.deleteTempFiles();
        }
    }
}
Also used : IRunProcessService(org.talend.designer.runprocess.IRunProcessService) JavaJobExportReArchieveCreator(org.talend.repository.ui.wizards.exportjob.JavaJobExportReArchieveCreator) Property(org.talend.core.model.properties.Property) ZipToFile(org.talend.repository.ui.utils.ZipToFile) File(java.io.File) FilterInfo(org.talend.utils.files.FilterInfo) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IOException(java.io.IOException) HashSet(java.util.HashSet)

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