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);
}
}
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();
}
}
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());
}
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();
}
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();
}
Aggregations