use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.
the class AbstractMultiPageTalendEditor method generateCode.
/**
* DOC bqian Comment method "generateCode".
*/
protected void generateCode() {
final IProcess2 process = getProcess();
if (!(process.getProperty().getItem() instanceof ProcessItem)) {
// shouldn't work for joblet
return;
}
if (process.getGeneratingNodes().size() != 0) {
Job job = new //$NON-NLS-1$
AccessingEmfJob(//$NON-NLS-1$
"Generating code") {
@Override
protected IStatus doRun(IProgressMonitor monitor) {
try {
ProcessorUtilities.generateCode(process, process.getContextManager().getDefaultContext(), false, false, true, ProcessorUtilities.GENERATE_WITH_FIRST_CHILD);
} catch (ProcessorException e) {
ExceptionHandler.process(e);
}
return Status.OK_STATUS;
}
};
job.setUser(true);
job.setPriority(Job.BUILD);
// start as soon as possible
job.schedule();
}
}
use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.
the class JavaProcessor method generateCode.
/*
* Append the generated java code form context into java file wihtin the project. If the file not existed new one
* will be created.
*
* @see org.talend.designer.runprocess.IProcessor#generateCode(org.talend.core .model.process.IContext, boolean,
* boolean, boolean)
*/
@Override
public void generateCode(boolean statistics, boolean trace, boolean javaProperties, int option) throws ProcessorException {
super.generateCode(statistics, trace, javaProperties, option);
try {
// hywang modified for 6484
String currentJavaProject = ProjectManager.getInstance().getProject(property).getTechnicalLabel();
ICodeGenerator codeGen;
ICodeGeneratorService service = RunProcessPlugin.getDefault().getCodeGeneratorService();
if (javaProperties) {
//$NON-NLS-1$
String javaInterpreter = "";
//$NON-NLS-1$
String javaLib = "";
String javaContext = getContextPath().toPortableString();
codeGen = service.createCodeGenerator(process, statistics, trace, javaInterpreter, javaLib, javaContext, currentJavaProject);
} else {
codeGen = service.createCodeGenerator(process, statistics, trace);
}
// set the selected context. if don't find, will keep default
if (!process.getContextManager().getDefaultContext().getName().equals(context.getName())) {
boolean found = false;
for (IContext c : process.getContextManager().getListContext()) {
if (c.getName().equals(context.getName())) {
found = true;
}
}
if (found) {
codeGen.setContextName(context.getName());
}
}
//$NON-NLS-1$
String processCode = "";
try {
// must before codegen for job to set the rule flag.
if (PluginChecker.isRulesPluginLoaded()) {
IRulesProviderService rulesService = (IRulesProviderService) GlobalServiceRegister.getDefault().getService(IRulesProviderService.class);
if (rulesService != null) {
boolean useGenerateRuleFiles = false;
List<? extends INode> allNodes = this.process.getGeneratingNodes();
for (int i = 0; i < allNodes.size(); i++) {
if (allNodes.get(i) instanceof INode) {
INode node = allNodes.get(i);
if (rulesService.isRuleComponent(node) && !node.getElementParameter(EParameterName.PROPERTY_TYPE.getName()).getValue().toString().equals("BUILT_IN")) {
//$NON-NLS-1$
useGenerateRuleFiles = true;
break;
}
}
}
if (useGenerateRuleFiles && rulesService != null && currentJavaProject != null) {
rulesService.generateFinalRuleFiles(currentJavaProject, this.process);
LastGenerationInfo.getInstance().setUseRules(this.process.getId(), this.process.getVersion(), true);
}
}
}
processCode = codeGen.generateProcessCode();
} catch (SystemException e) {
//$NON-NLS-1$
throw new ProcessorException(Messages.getString("Processor.generationFailed"), e);
} catch (IOException e) {
ExceptionHandler.process(e);
}
if (!BitwiseOptionUtils.containOption(option, TalendProcessOptionConstants.GENERATE_WITHOUT_FORMAT)) {
processCode = doFormat(processCode);
}
// see feature 4610:option to see byte length of each code method
processCode = computeMethodSizeIfNeeded(processCode);
InputStream codeStream = new ByteArrayInputStream(processCode.getBytes());
// Generating files
IFile codeFile = this.getCodeProject().getFile(this.getSrcCodePath());
if (!codeFile.exists()) {
// in win.
try {
org.talend.commons.utils.io.FilesUtils.removeExistedResources(null, codeFile, true, true);
} catch (Exception e) {
throw new ProcessorException(e);
}
IFolder parentFolder = (IFolder) codeFile.getParent();
if (!parentFolder.exists()) {
parentFolder.create(true, true, null);
}
codeFile.create(codeStream, true, null);
} else {
codeFile.setContents(codeStream, true, false, null);
}
// codeFile.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
processCode = null;
// updateContextCode(codeGen);
//$NON-NLS-1$
codeFile.getProject().deleteMarkers("org.eclipse.jdt.debug.javaLineBreakpointMarker", true, IResource.DEPTH_INFINITE);
List<INode> breakpointNodes = CorePlugin.getContext().getBreakpointNodes(process);
if (!breakpointNodes.isEmpty()) {
String[] nodeNames = new String[breakpointNodes.size()];
int pos = 0;
String nodeName;
for (INode node : breakpointNodes) {
nodeName = node.getUniqueName();
if (node.getComponent().getMultipleComponentManagers().size() > 0) {
//$NON-NLS-1$
nodeName += "_" + node.getComponent().getMultipleComponentManagers().get(0).getInput().getName();
}
//$NON-NLS-1$ //$NON-NLS-2$
nodeNames[pos++] = "[" + nodeName + " main ] start";
}
int[] lineNumbers = getLineNumbers(codeFile, nodeNames);
setBreakpoints(codeFile, getMainClass(), lineNumbers);
}
} catch (CoreException e1) {
if (e1.getStatus() != null && e1.getStatus().getException() != null) {
ExceptionHandler.process(e1.getStatus().getException());
}
//$NON-NLS-1$
throw new ProcessorException(Messages.getString("Processor.tempFailed"), e1);
}
}
use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.
the class JavaProcessorUtilities method handleMissingJarsForProcess.
/**
*
* Added by Marvin Wang on Nov 7, 2012.
*
* @param missingJarsForRoutines
* @param missingJarsForProcess
* @param missingJars
* @throws BusinessException
*/
private static void handleMissingJarsForProcess(Set<String> missingJarsForRoutines, final Set<String> missingJarsForProcess, String missingJars) throws ProcessorException {
//$NON-NLS-1$
final StringBuffer sb = new StringBuffer("");
if (missingJarsForProcess.size() > 0) {
//$NON-NLS-1$
sb.append(Messages.getString("JavaProcessorUtilities.msg.missingjar.forProcess"));
for (String missingJar : missingJarsForProcess) {
sb.append(missingJar);
//$NON-NLS-1$
sb.append(", ");
}
if (missingJarsForRoutines.size() > 0) {
// subForMsg(sb.toString());
//$NON-NLS-1$
sb.append("\r\n\r\n\r\n");
//$NON-NLS-1$
sb.append(Messages.getString("JavaProcessorUtilities.msg.missingjar.note"));
//$NON-NLS-1$
sb.append("\r\n");
//$NON-NLS-1$
sb.append(Messages.getString("JavaProcessorUtilities.msg.missingjar.onlyforroutine"));
//$NON-NLS-1$
sb.append("\r\n");
for (String missingJar : missingJarsForRoutines) {
sb.append(missingJar);
//$NON-NLS-1$
sb.append(", ");
}
subForMsg(sb.toString());
} else {
subForMsg(sb.toString());
}
if (!CommonsPlugin.isHeadless()) {
Display display = DisplayUtils.getDisplay();
if (display != null) {
display.syncExec(new Runnable() {
@Override
public void run() {
// fix for TDI-24906
MessageDialog dialog = new MessageDialog(Display.getDefault().getActiveShell(), Messages.getString("JavaProcessorUtilities.msg.missingjar.warningtitle"), null, subForMsg(sb.toString()), 4, new String[] { IDialogConstants.OK_LABEL }, 0) {
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.window.Window#setShellStyle(int)
*/
@Override
protected void setShellStyle(int newShellStyle) {
super.setShellStyle(getShellStyle() | SWT.APPLICATION_MODAL);
}
};
dialog.open();
}
});
}
} else {
throw new ProcessorException(missingJars);
}
} else {
if (missingJarsForRoutines.size() > 0) {
//$NON-NLS-1$
sb.append(Messages.getString("JavaProcessorUtilities.msg.missingjar.onlyforroutine"));
for (String missingJar : missingJarsForRoutines) {
sb.append(missingJar);
//$NON-NLS-1$
sb.append(", ");
}
CommonExceptionHandler.warn(subForMsg(sb.toString()));
}
}
}
use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.
the class AbstractJavaProcessor method buildExportZip.
protected String buildExportZip(ProcessItem processItem, IProgressMonitor progressMonitor) throws ProcessorException {
Map<ExportChoice, Object> exportChoiceMap = JobScriptsManagerFactory.getDefaultExportChoiceMap();
exportChoiceMap.put(ExportChoice.needLauncher, false);
exportChoiceMap.put(ExportChoice.needJobItem, true);
// exportChoiceMap.put(ExportChoice.needJobScript, true); //?? for old build? no need
if (CommonsPlugin.isDebugMode()) {
exportChoiceMap.put(ExportChoice.needSourceCode, true);
} else {
exportChoiceMap.put(ExportChoice.needSourceCode, false);
}
exportChoiceMap.put(ExportChoice.binaries, true);
exportChoiceMap.put(ExportChoice.includeLibs, true);
exportChoiceMap.put(ExportChoice.needAssembly, true);
if (progressMonitor.isCanceled()) {
throw new ProcessorException(new InterruptedException());
}
final String archiveFilePath = Path.fromOSString(CorePlugin.getDefault().getPreferenceStore().getString(ITalendCorePrefConstants.FILE_PATH_TEMP)).append(getFilePathPrefix() + '_' + process.getName() + FileExtensions.ZIP_FILE_SUFFIX).toString();
try {
exportChoiceMap.put(ExportChoice.needContext, true);
String contextName = processItem.getProcess().getDefaultContext();
exportChoiceMap.put(ExportChoice.contextName, contextName);
buildJob(archiveFilePath, processItem, processItem.getProperty().getVersion(), contextName, exportChoiceMap, JobExportType.POJO, progressMonitor);
} catch (Exception e) {
throw new ProcessorException(e);
} finally {
ProcessorUtilities.resetExportConfig();
}
return archiveFilePath;
}
use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.
the class ExportProcessorHelper method exportPigudf.
public void exportPigudf(IProcessor processor, Property property, int statisticsPort, int tracePort) throws ProcessorException {
// build java project
CorePlugin.getDefault().getRunProcessService().buildJavaProject();
Map<ExportChoice, Object> exportChoiceMap = new EnumMap<ExportChoice, Object>(ExportChoice.class);
exportChoiceMap.put(ExportChoice.needPigudf, true);
ProcessItem processItem = (ProcessItem) property.getItem();
ExportFileResource fileResource = new ExportFileResource(processItem, property.getLabel());
ExportFileResource[] exportFileResources = new ExportFileResource[] { fileResource };
JobScriptsManager jobScriptsManager = JobScriptsManagerFactory.createManagerInstance(exportChoiceMap, processor.getContext().getName(), JobScriptsManager.ALL_ENVIRONMENTS, statisticsPort, tracePort, JobExportType.POJO);
URL url = jobScriptsManager.getExportPigudfResources(exportFileResources);
if (url == null) {
return;
}
File file = new File(url.getFile());
File libFolder = JavaProcessorUtilities.getJavaProjectLibFolder();
if (libFolder == null) {
return;
}
File target = new File(libFolder.getAbsolutePath() + property.getLabel() + "_" + property.getVersion() + "_" + file.getName());
try {
FilesUtils.copyFile(file, target);
} catch (IOException e) {
throw new ProcessorException(e.getMessage());
}
}
Aggregations