use of org.talend.designer.codegen.ICodeGenerator 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.codegen.ICodeGenerator in project tdi-studio-se by Talend.
the class JavaCodeProblemsChecker method retrieveCode.
/**
* DOC amaumont Comment method "retrieveCode".
*
* @param process
* @param selectedNodeName
* @param externalData optional data, can be null
* @return
*/
private String retrieveCode(IProcess process, String selectedNodeName, IAloneProcessNodeConfigurer nodeConfigurer) {
ICodeGeneratorService codeGeneratorService = RunProcessPlugin.getDefault().getCodeGeneratorService();
ICodeGenerator codeGenerator = codeGeneratorService.createCodeGenerator(process, false, false);
String code = codeGenerator.generateComponentCodeWithRows(selectedNodeName, nodeConfigurer);
return code;
}
use of org.talend.designer.codegen.ICodeGenerator in project tdi-studio-se by Talend.
the class JavaProcessor method generateContextCode.
/*
* (non-Javadoc)
*
* @see org.talend.designer.runprocess.Processor#generateContextCode()
*/
@Override
public void generateContextCode() throws ProcessorException {
RepositoryContext repositoryContext = (RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY);
Project project = repositoryContext.getProject();
ICodeGenerator codeGen;
ICodeGeneratorService service = RunProcessPlugin.getDefault().getCodeGeneratorService();
//$NON-NLS-1$
String javaInterpreter = "";
//$NON-NLS-1$
String javaLib = "";
String currentJavaProject = project.getTechnicalLabel();
String javaContext = getContextPath().toPortableString();
codeGen = service.createCodeGenerator(process, false, false, javaInterpreter, javaLib, javaContext, currentJavaProject);
updateContextCode(codeGen);
}
Aggregations