use of org.talend.designer.runprocess.IProcessor in project tdi-studio-se by Talend.
the class ExpressionTestMain method startProcess.
/**
* yzhang Comment method "startProcess".
*
* @param p
* @param context
*/
private void startProcess(IProcess p, IContext context) {
final IProcessor processor = ProcessorUtilities.getProcessor(p, null, context);
new Thread(new Runnable() {
public void run() {
try {
process = processor.run(IProcessor.NO_STATISTICS, IProcessor.NO_TRACES, null);
Thread.sleep(500);
Display.getDefault().asyncExec(new Runnable() {
public void run() {
feedBackTestResult();
}
});
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
}).start();
// int counter = 0;
// while (process == null && counter < 6) {
// try {
// System.out.println("Thread : stop 500ms. ");
// Thread.sleep(500);
// counter++;
// } catch (InterruptedException e) {
// RuntimeExceptionHandler.process(e);
// }
// }
}
use of org.talend.designer.runprocess.IProcessor in project tdi-studio-se by Talend.
the class StandardJobStandaloneBuildProvider method createPomCreator.
@Override
public IMavenPomCreator createPomCreator(Map<String, Object> parameters) {
if (parameters == null || parameters.isEmpty()) {
return null;
}
final Object processor = parameters.get(PROCESSOR);
if (processor == null || !(processor instanceof IProcessor)) {
return null;
}
final Object pomFile = parameters.get(FILE_POM);
if (pomFile == null || !(pomFile instanceof IFile)) {
return null;
}
final Object item = parameters.get(ITEM);
if (item == null || !(item instanceof Item)) {
return null;
}
Object argumentsMap = parameters.get(ARGUMENTS_MAP);
if (argumentsMap == null) {
argumentsMap = Collections.emptyMap();
}
if (!(argumentsMap instanceof Map)) {
return null;
}
Object overwrite = parameters.get(OVERWRITE_POM);
if (overwrite == null) {
overwrite = Boolean.FALSE;
}
final Object assemblyFile = parameters.get(FILE_ASSEMBLY);
if (assemblyFile == null || !(assemblyFile instanceof IFile)) {
return null;
}
final Object winClassPath = parameters.get(CP_WIN);
if (winClassPath == null) {
return null;
}
final Object linuxClassPath = parameters.get(CP_LINUX);
if (linuxClassPath == null) {
return null;
}
CreateMavenJobPom creator = new CreateMavenJobPom((IProcessor) processor, (IFile) pomFile);
creator.setUnixClasspath(linuxClassPath.toString());
creator.setWindowsClasspath(winClassPath.toString());
creator.setAssemblyFile((IFile) assemblyFile);
creator.setArgumentsMap((Map<String, Object>) argumentsMap);
creator.setOverwrite(Boolean.parseBoolean(overwrite.toString()));
final Property itemProperty = ((Item) item).getProperty();
IPath itemLocationPath = ItemResourceUtil.getItemLocationPath(itemProperty);
IFolder objectTypeFolder = ItemResourceUtil.getObjectTypeFolder(itemProperty);
if (itemLocationPath != null && objectTypeFolder != null) {
IPath itemRelativePath = itemLocationPath.removeLastSegments(1).makeRelativeTo(objectTypeFolder.getLocation());
creator.setObjectTypeFolder(objectTypeFolder);
creator.setItemRelativePath(itemRelativePath);
}
return creator;
}
use of org.talend.designer.runprocess.IProcessor in project tdi-studio-se by Talend.
the class TestComponentsAction method generateCode.
public void generateCode(File[] tempFile, String componentPath) {
for (File file : tempFile) {
if (file.length() > 0) {
URI uri = URI.createFileURI(file.toString());
TalendFilePackage.eINSTANCE.getNsURI();
Resource resource = new ResourceSetImpl().getResource(uri, true);
ProcessType processType = (ProcessType) EcoreUtil.getObjectByType(resource.getContents(), TalendFilePackage.eINSTANCE.getProcessType());
IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
ProcessItem item = PropertiesFactory.eINSTANCE.createProcessItem();
item.setProcess(processType);
item.setProperty(PropertiesFactory.eINSTANCE.createProperty());
item.getProperty().setLabel(TestParameter.TEST_DIR);
item.getProperty().setAuthor(PropertiesFactory.eINSTANCE.createUser());
item.getProperty().setId(file.getName());
item.getProperty().setStatusCode(file.getName());
item.getProperty().setVersion(TestParameter.VERSION);
IProcess process = service.getProcessFromProcessItem(item);
setDefaultProperties(process, componentPath);
IProcessor processor = ProcessorUtilities.getProcessor(process, item.getProperty(), process.getContextManager().getDefaultContext());
try {
// generate
//$NON-NLS-1$
log.info(TestParameter.GENERATE_START + " : " + file.getName());
// processor.generateCode(process.getContextManager().getDefaultContext(), false, false, true);
processor.generateCode(false, false, true);
//$NON-NLS-1$
log.info(TestParameter.GENERATE_END + " : " + file.getName());
// run
//$NON-NLS-1$
log.info(TestParameter.RUN_START + " : " + file.getName());
java.lang.Process runningProcess = processor.run(IProcessor.NO_STATISTICS, IProcessor.NO_TRACES, null);
StringBuffer errBuff = new StringBuffer();
if (isRunOK(runningProcess, errBuff)) {
//$NON-NLS-1$
log.info(TestParameter.RUN_SUCCESS + " : " + file.getName());
} else {
// 2 possibilities : OK not found / error stream
//$NON-NLS-1$
log.error(TestParameter.RUN_FAIL + " : " + file.getName(), new Exception(errBuff.toString()));
}
} catch (ProcessorException e) {
log.error(e.getMessage(), e);
}
}
}
}
use of org.talend.designer.runprocess.IProcessor in project tdi-studio-se by Talend.
the class StandardJobOSGiBundleBuildProviderTest 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);
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(CreateMavenStandardJobOSGiPom.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());
}
use of org.talend.designer.runprocess.IProcessor in project tdi-studio-se by Talend.
the class GuessSchemaProcess method run.
public CsvArray run() throws ProcessorException {
CsvArray array = new CsvArray();
buildProcess();
IProcessor processor = ProcessorUtilities.getProcessor(process, null);
processor.setContext(selectContext);
File previousFile = temppath.toFile();
if (previousFile.exists()) {
previousFile.delete();
}
java.lang.Process executeprocess = processor.run(IProcessor.NO_STATISTICS, IProcessor.NO_TRACES, null);
StringBuffer buffer = new StringBuffer();
ProcessStreamTrashReaderUtil.readAndForget(executeprocess, buffer);
final String errorMessage = buffer.toString();
boolean checkError = !info.isHive() | !previousFile.exists();
if (checkError && !"".equals(buffer.toString())) {
throw new ProcessorException(errorMessage) {
private static final long serialVersionUID = 1L;
/*
* (non-Javadoc)
*
* @see java.lang.Throwable#initCause(java.lang.Throwable)
*/
@Override
public synchronized Throwable initCause(Throwable cause) {
// TODO Auto-generated method stub
return super.initCause(cause);
}
/*
* (non-Javadoc)
*
* @see java.lang.Throwable#getMessage()
*/
@Override
public String getMessage() {
StringTokenizer tokenizer = new StringTokenizer(errorMessage, "\n");
StringBuilder sqlError = new StringBuilder();
if (tokenizer.countTokens() > 2) {
tokenizer.nextToken();
sqlError.append(tokenizer.nextToken()).append("\n");
}
return sqlError.toString();
}
};
} else {
try {
array = array.createFrom(previousFile, currentProcessEncoding);
} catch (IOException ioe) {
throw new ProcessorException(ioe) {
/*
* (non-Javadoc)
*
* @see java.lang.Throwable#getMessage()
*/
@Override
public String getMessage() {
//$NON-NLS-1$ //$NON-NLS-2$
return Messages.getString("GuessSchemaController.0", System.getProperty("line.separator"));
}
};
}
}
return array;
}
Aggregations