Search in sources :

Example 1 with IProcessor

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

the class HTMLDocGenerator method generateSourceCodeInfo.

/**
     * DOC qwei Comment method "generateSourceCodeInfo".
     */
private void generateSourceCodeInfo(ProcessItem item, Element element) {
    if (CorePlugin.getDefault().getPreferenceStore().getBoolean(ITalendCorePrefConstants.DOC_GENERATESOURCECODE)) {
        IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
        IProcess process = service.getProcessFromProcessItem(item);
        IProcessor processor = ProcessorUtilities.getProcessor(process, null, process.getContextManager().getDefaultContext());
        // hidePasswordInSourceCode4Doc(process);
        try {
            processor.cleanBeforeGenerate(TalendProcessOptionConstants.CLEAN_JAVA_CODES | TalendProcessOptionConstants.CLEAN_CONTEXTS | TalendProcessOptionConstants.CLEAN_DATA_SETS);
            processor.generateCode(false, true, false);
        } catch (ProcessorException e) {
            ExceptionHandler.process(e);
        }
        //$NON-NLS-1$
        Element sourceCodeInfoElement = DocumentHelper.createElement("sourcecodes");
        ITalendSynchronizer synchronizer = CorePlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer();
        // StringBuffer componentsCode = new StringBuffer();
        try {
            IFile codeFile = synchronizer.getFile(item);
            if (codeFile == null) {
                return;
            }
            //$NON-NLS-1$
            String tempStr = "";
            InputStream in = codeFile.getContents();
            BufferedReader buffer = new BufferedReader(new InputStreamReader(in));
            while ((tempStr = buffer.readLine()) != null) {
                //$NON-NLS-1$
                Element codeElement = DocumentHelper.createElement("code");
                // componentsCode.append(tempStr).append("\n");
                //$NON-NLS-1$
                codeElement.addAttribute("content", tempStr);
                sourceCodeInfoElement.add(codeElement);
            }
            buffer.close();
            in.close();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            // e.printStackTrace();
            ExceptionHandler.process(e);
        }
        element.add(sourceCodeInfoElement);
    }
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) ProcessorException(org.talend.designer.runprocess.ProcessorException) IFile(org.eclipse.core.resources.IFile) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Element(org.dom4j.Element) BufferedReader(java.io.BufferedReader) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcessor(org.talend.designer.runprocess.IProcessor) IProcess(org.talend.core.model.process.IProcess) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) ProcessorException(org.talend.designer.runprocess.ProcessorException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 2 with IProcessor

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

the class BuildJobHandler method generateJobFiles.

@Override
public IProcessor generateJobFiles(IProgressMonitor monitor) throws Exception {
    LastGenerationInfo.getInstance().getUseDynamicMap().clear();
    LastGenerationInfo.getInstance().getUseRulesMap().clear();
    final Map<String, Object> argumentsMap = new HashMap<String, Object>(getArguments());
    argumentsMap.put(TalendProcessArgumentConstant.ARG_ENABLE_APPLY_CONTEXT_TO_CHILDREN, isOptionChoosed(ExportChoice.applyToChildren));
    //
    argumentsMap.put(TalendProcessArgumentConstant.ARG_ENABLE_STATS, isOptionChoosed(ExportChoice.addStatistics));
    argumentsMap.put(TalendProcessArgumentConstant.ARG_ENABLE_TRACS, isOptionChoosed(ExportChoice.addTracs));
    Properties prop = (Properties) exportChoice.get(ExportChoice.properties);
    if (prop != null) {
        // add all properties for arugment map.
        Enumeration<Object> keys = prop.keys();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement().toString();
            String value = prop.get(key) == null ? null : prop.get(key).toString();
            argumentsMap.put(key, value);
        }
    }
    // context
    boolean needContext = isOptionChoosed(ExportChoice.needContext);
    if (needContext) {
        argumentsMap.put(TalendProcessArgumentConstant.ARG_NEED_CONTEXT, needContext);
        Object context = this.exportChoice.get(ExportChoice.contextName);
        if (context == null) {
            context = this.contextName;
        }
        argumentsMap.put(TalendProcessArgumentConstant.ARG_CONTEXT_NAME, context);
    }
    boolean onlyDefaultContext = isOptionChoosed(ExportChoice.onlyDefautContext);
    if (onlyDefaultContext) {
        argumentsMap.put(TalendProcessArgumentConstant.ARG_ONLY_DEFAUT_CONTEXT, onlyDefaultContext);
    }
    boolean needParamValues = isOptionChoosed(ExportChoice.needParameterValues);
    if (needParamValues) {
        argumentsMap.put(TalendProcessArgumentConstant.ARG_CONTEXT_PARAMS, this.exportChoice.get(ExportChoice.parameterValuesList));
    }
    // log4j
    boolean log4jEnable = isLog4jEnable();
    argumentsMap.put(TalendProcessArgumentConstant.ARG_ENABLE_LOG4J, log4jEnable);
    if (log4jEnable) {
        boolean needLog4jLevel = isOptionChoosed(ExportChoice.needLog4jLevel);
        if (needLog4jLevel) {
            argumentsMap.put(TalendProcessArgumentConstant.ARG_NEED_LOG4J_LEVEL, needLog4jLevel);
            argumentsMap.put(TalendProcessArgumentConstant.ARG_LOG4J_LEVEL, this.exportChoice.get(ExportChoice.log4jLevel));
        }
    }
    // generation option
    int generationOption = (isOptionChoosed(ExportChoice.includeTestSource) || isOptionChoosed(ExportChoice.executeTests)) ? ProcessorUtilities.GENERATE_ALL_CHILDS | ProcessorUtilities.GENERATE_TESTS : ProcessorUtilities.GENERATE_ALL_CHILDS;
    if (isOptionChoosed(ExportChoice.doNotCompileCode)) {
        generationOption = generationOption | ProcessorUtilities.GENERATE_WITHOUT_COMPILING;
    }
    argumentsMap.put(TalendProcessArgumentConstant.ARG_GENERATE_OPTION, generationOption);
    // deployVersion for ci builder
    String deployVersion = (String) exportChoice.get(ExportChoice.deployVersion);
    if (deployVersion != null) {
        argumentsMap.put(TalendProcessArgumentConstant.ARG_DEPLOY_VERSION, deployVersion);
    }
    try {
        IProcessor processor = ProcessorUtilities.generateCode(processItem, contextName, version, argumentsMap, monitor);
        return processor;
    } finally {
        ProcessorUtilities.resetExportConfig();
    }
}
Also used : HashMap(java.util.HashMap) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IProcessor(org.talend.designer.runprocess.IProcessor) Properties(java.util.Properties)

Example 3 with IProcessor

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

the class StandardJobStandaloneBuildProviderTest method test_createPomCreator.

@Test
public void test_createPomCreator() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    Item jobItem = createJobItem();
    final IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
    Assert.assertNotNull(designerCoreService);
    final IProcess processFromItem = designerCoreService.getProcessFromItem(jobItem);
    IProcessor processor = ProcessorUtilities.getProcessor(processFromItem, jobItem.getProperty());
    final Class<? extends IProcessor> processorClazz = processor.getClass();
    Assert.assertEquals("org.talend.designer.runprocess.maven.MavenJavaProcessor", processorClazz.getName());
    processor.setContext(processor.getProcess().getContextManager().getDefaultContext());
    parameters.put(IBuildPomCreatorParameters.PROCESSOR, processor);
    final Method getPomFileMethod = processorClazz.getDeclaredMethod("getPomFile");
    getPomFileMethod.setAccessible(true);
    final Object getPomFile = getPomFileMethod.invoke(processor);
    Assert.assertTrue(getPomFile instanceof IFile);
    IFile pomFile = (IFile) getPomFile;
    parameters.put(IBuildPomCreatorParameters.FILE_POM, pomFile);
    final Method getAssemblyFileMethod = processorClazz.getDeclaredMethod("getAssemblyFile");
    getAssemblyFileMethod.setAccessible(true);
    final Object getAssemblyFile = getAssemblyFileMethod.invoke(processor);
    Assert.assertTrue(getPomFile instanceof IFile);
    IFile assemblyFile = (IFile) getAssemblyFile;
    parameters.put(IBuildPomCreatorParameters.FILE_ASSEMBLY, assemblyFile);
    // before set classpath, must do initJobClasspath
    final Method initJobClasspathMethod = processorClazz.getDeclaredMethod("initJobClasspath");
    initJobClasspathMethod.setAccessible(true);
    initJobClasspathMethod.invoke(processor);
    final Field windowsClasspathField = processorClazz.getDeclaredField("windowsClasspath");
    windowsClasspathField.setAccessible(true);
    parameters.put(IBuildPomCreatorParameters.CP_WIN, windowsClasspathField.get(processor));
    final Field unixClasspathField = processorClazz.getDeclaredField("unixClasspath");
    unixClasspathField.setAccessible(true);
    parameters.put(IBuildPomCreatorParameters.CP_LINUX, unixClasspathField.get(processor));
    parameters.put(IBuildParametes.ITEM, processor.getProperty().getItem());
    final Map<String, Object> arguments = processor.getArguments();
    parameters.put(IBuildPomCreatorParameters.ARGUMENTS_MAP, arguments);
    parameters.put(IBuildPomCreatorParameters.OVERWRITE_POM, true);
    // create pom and assembly
    RepositoryObjectTypeBuildProvider provider = createTestBuildProvider();
    final IMavenPomCreator pomCreator = provider.createPomCreator(parameters);
    Assert.assertNotNull("Create the pom creator failure", pomCreator);
    Assert.assertEquals(CreateMavenJobPom.class, pomCreator.getClass());
    pomCreator.create(null);
    pomFile.getParent().refreshLocal(IResource.DEPTH_ONE, null);
    Assert.assertTrue("the pom file " + pomFile.getName() + " is not created ", pomFile.exists());
    assemblyFile.getParent().refreshLocal(IResource.DEPTH_ONE, null);
    Assert.assertTrue("the assembly file " + assemblyFile.getName() + " is not created ", assemblyFile.exists());
}
Also used : IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) IMavenPomCreator(org.talend.core.runtime.repository.build.IMavenPomCreator) IProcessor(org.talend.designer.runprocess.IProcessor) Method(java.lang.reflect.Method) Item(org.talend.core.model.properties.Item) Field(java.lang.reflect.Field) RepositoryObjectTypeBuildProvider(org.talend.core.runtime.repository.build.RepositoryObjectTypeBuildProvider) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) Test(org.junit.Test)

Example 4 with IProcessor

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

the class JobScriptsManager method generateJobFiles.

/**
     * Generates the job files.
     * 
     * @param needGenerateCode
     * @param contextName
     * @param process
     * @throws ProcessorException
     */
protected IProcess generateJobFiles(ProcessItem process, String contextName, String version, boolean statistics, boolean trace, boolean applyContextToChildren, IProgressMonitor monitor) throws ProcessorException {
    LastGenerationInfo.getInstance().getUseDynamicMap().clear();
    IProcessor processor = ProcessorUtilities.generateCode(process, contextName, version, statistics, trace, applyContextToChildren, isOptionChoosed(ExportChoice.needContext), monitor);
    return processor.getProcess();
}
Also used : IProcessor(org.talend.designer.runprocess.IProcessor)

Example 5 with IProcessor

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

the class JobJavaScriptOSGIForESBRuntimeManager method generateJobFiles.

@Override
protected IProcess generateJobFiles(ProcessItem process, String contextName, String version, boolean statistics, boolean trace, boolean applyContextToChildren, IProgressMonitor monitor) throws ProcessorException {
    LastGenerationInfo.getInstance().getUseDynamicMap().clear();
    // TODO stat port tracer, to replace the port, need to improve efficiency
    IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
    IProcess currentProcess = service.getProcessFromProcessItem(process);
    IProcessor processor = ProcessorUtilities.getProcessor(currentProcess, null);
    StatPortChecker checker = null;
    if (processor instanceof MavenJavaProcessor) {
        MavenJavaProcessor mvnProcessor = (MavenJavaProcessor) processor;
        checker = new StatPortChecker(processor.getCodeProject().getFile(mvnProcessor.getSrcCodePath()).getLocation(), statisticPort, tracePort);
        new Thread(checker, "Statistic Port Finder").start();
        mvnProcessor = null;
    }
    IProcessor processor2 = ProcessorUtilities.generateCode(process, contextName, version, statistics, trace, applyContextToChildren, isOptionChoosed(ExportChoice.needContext), monitor);
    if (checker != null) {
        checker.stop();
    }
    return processor2.getProcess();
}
Also used : StatPortChecker(org.talend.designer.esb.runcontainer.util.StatPortChecker) MavenJavaProcessor(org.talend.designer.runprocess.maven.MavenJavaProcessor) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcessor(org.talend.designer.runprocess.IProcessor) IProcess(org.talend.core.model.process.IProcess)

Aggregations

IProcessor (org.talend.designer.runprocess.IProcessor)25 ProcessorException (org.talend.designer.runprocess.ProcessorException)11 IProcess (org.talend.core.model.process.IProcess)10 IOException (java.io.IOException)9 IFile (org.eclipse.core.resources.IFile)8 IContext (org.talend.core.model.process.IContext)8 Item (org.talend.core.model.properties.Item)7 Property (org.talend.core.model.properties.Property)7 File (java.io.File)6 IPath (org.eclipse.core.runtime.IPath)6 IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)6 Map (java.util.Map)5 IFolder (org.eclipse.core.resources.IFolder)5 ProcessItem (org.talend.core.model.properties.ProcessItem)5 CsvArray (org.talend.core.utils.CsvArray)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 HashMap (java.util.HashMap)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3