use of org.talend.designer.runprocess.ProcessorException 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.ProcessorException in project tdi-studio-se by Talend.
the class JobScriptsManager method getCommandByTalendJob.
protected String getCommandByTalendJob(String targetPlatform, ProcessItem processItem, String context, boolean needContext, int statisticPort, int tracePort, String... codeOptions) {
String[] cmd = new String[] {};
try {
IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
IProcess currentProcess = service.getProcessFromProcessItem(processItem);
cmd = ProcessorUtilities.getCommandLine(true, targetPlatform, true, currentProcess, processItem.getProperty(), context, needContext, statisticPort, tracePort, codeOptions);
} catch (ProcessorException e) {
ExceptionHandler.process(e);
}
return ProcessorUtilities.generateCmdByTalendJob(cmd);
}
use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.
the class JSONShadowProcess method run.
public CsvArray run() throws ProcessorException {
IProcess talendProcess = buildProcess();
IProcessor processor = ProcessorUtilities.getProcessor(talendProcess, null);
processor.setProxyParameters(getProxyParameters());
// try {
// Delete previous Perl generated file
File previousFile = outPath.toFile();
if (previousFile.exists()) {
previousFile.delete();
}
// Process ps = processor.run(process.getContextManager().getDefaultContext(), Processor.NO_STATISTICS,
// Processor.NO_TRACES,Processor.WATCH_ALLOWED);//Old
IContext context = talendProcess.getContextManager().getDefaultContext();
processor.setContext(context);
process = processor.run(IProcessor.NO_STATISTICS, IProcessor.NO_TRACES, null);
ProcessStreamTrashReader.readAndForget(process);
if (!outPath.toFile().exists()) {
//$NON-NLS-1$
throw new ProcessorException(Messages.getString("ShadowProcess.notGeneratedOutputException"));
}
try {
CsvArray array = new CsvArray();
array = array.createFrom(outPath.toFile(), currentProcessEncoding);
return array;
} catch (IOException ioe) {
throw new ProcessorException(ioe);
}
}
use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.
the class JobExportAction method exportJobScript.
private boolean exportJobScript(List<? extends IRepositoryNode> nodes, String version, String bundleVersion, IProgressMonitor monitor) {
manager.setJobVersion(version);
manager.setBundleVersion(bundleVersion);
List<ExportFileResource> processes = getProcesses(nodes, "");
boolean isNotFirstTime = directoryName != null;
if (isNotFirstTime && processes != null) {
for (ExportFileResource process : processes) {
process.setDirectoryName(directoryName);
}
}
try {
ProxyRepositoryFactory.getInstance().initialize();
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
ItemCacheManager.clearCache();
if (!isMultiNodes()) {
// TODO : bug with export?
for (ExportFileResource process : processes) {
process.removeAllMap();
ProcessItem processItem = (ProcessItem) process.getItem();
if (!processItem.getProperty().getVersion().equals(version)) {
// update with the correct version.
process.setProcess(ItemCacheManager.getProcessItem(processItem.getProperty().getId(), version));
}
}
}
manager.setProgressMonitor(monitor);
List<ExportFileResource> resourcesToExport = null;
try {
resourcesToExport = manager.getExportResources(processes.toArray(new ExportFileResource[] {}));
IStructuredSelection selection = new StructuredSelection(nodes);
// if job has compile error, will not export to avoid problem if run jobscript
boolean hasErrors = CorePlugin.getDefault().getRunProcessService().checkExportProcess(selection, true);
if (hasErrors) {
manager.deleteTempFiles();
return false;
}
} catch (ProcessorException e) {
MessageBoxExceptionHandler.process(e);
return false;
}
boolean addClasspathJar = true;
IDesignerCoreUIService designerCoreUIService = CoreUIPlugin.getDefault().getDesignerCoreUIService();
if (designerCoreUIService != null) {
addClasspathJar = designerCoreUIService.getPreferenceStore().getBoolean(IRepositoryPrefConstants.ADD_CLASSPATH_JAR);
}
if (isMultiNodes() || addClasspathJar) {
manager.setTopFolder(resourcesToExport);
}
doArchiveExport(monitor, resourcesToExport);
clean();
ProcessorUtilities.resetExportConfig();
// no need to regenerate if run in export model
// boolean generated = generatedCodes(version, monitor, processes);
// if (!generated) {
// return false;
// }
//$NON-NLS-1$
monitor.subTask(Messages.getString("JobScriptsExportWizardPage.newExportSuccess", type));
if (addClasspathJar) {
reBuildJobZipFile(processes);
} else {
String zipFile = getTempDestinationValue();
String destinationZipFile = manager.getDestinationPath();
FileCopyUtils.copy(zipFile, destinationZipFile);
}
return true;
}
use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.
the class JobExportAction method generatedCodes.
/**
* DOC ggu Comment method "generatedCodes".
*
* @param version
* @param monitor
* @param processes
*/
protected boolean generatedCodes(String version, IProgressMonitor monitor, List<ExportFileResource> processes) {
String projectName = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject().getLabel();
List<JobResource> jobResources = new ArrayList<JobResource>();
for (ExportFileResource process : processes) {
ProcessItem processItem = (ProcessItem) process.getItem();
JobInfo jobInfo = new JobInfo(processItem, processItem.getProcess().getDefaultContext(), version);
jobResources.add(new JobResource(projectName, jobInfo));
Set<JobInfo> jobInfos = ProcessorUtilities.getChildrenJobInfo(processItem);
for (JobInfo subjobInfo : jobInfos) {
jobResources.add(new JobResource(projectName, subjobInfo));
}
}
JobResourceManager reManager = JobResourceManager.getInstance();
for (JobResource r : jobResources) {
if (reManager.isProtected(r)) {
try {
ProcessorUtilities.generateCode(r.getJobInfo().getJobId(), r.getJobInfo().getContextName(), r.getJobInfo().getJobVersion(), false, false, monitor);
} catch (ProcessorException e) {
MessageBoxExceptionHandler.process(e);
return false;
}
}
}
return true;
}
Aggregations