use of org.talend.designer.runprocess.IRunProcessService in project tdi-studio-se by Talend.
the class JavaTestShadow method process.
public void process(Text testResultText, TableViewer tableViewer) {
Map<String, String> map = RoutineFunctionParser.getTypePackgeMethods();
Function function = CategoryComposite.getSelectedFunction();
String expression = ExpressionBuilderDialog.getExpressionComposite().getExpression();
if (function != null && expression != null && !"".equals(expression)) {
if (serverThread == null || !serverThread.isAlive()) {
server = ExpressionTestServer.getInstance(Display.getCurrent(), testResultText);
serverThread = new Thread(server);
serverThread.start();
}
//$NON-NLS-1$
String methodFullName = map.get(function.getTalendType().getName() + "." + function.getName());
//$NON-NLS-1$
String[] fullClassAndMethod = methodFullName.split("\\.");
String methodName = fullClassAndMethod[fullClassAndMethod.length - 1];
expression = expression.replaceAll(methodName, methodFullName);
ExpressionArguments arguments = new ExpressionArguments();
arguments.setExpression(expression);
arguments.setVariables((List<Variable>) tableViewer.getInput());
ExpressionGenerator codeGenerator = new ExpressionGenerator();
String fileContent = codeGenerator.generate(arguments);
ITalendProcessJavaProject talendProcessJavaProject = null;
if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
talendProcessJavaProject = processService.getTalendProcessJavaProject();
}
if (talendProcessJavaProject == null) {
return;
}
IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
IFolder outputFolder = talendProcessJavaProject.getOutputFolder();
//$NON-NLS-1$
IFile file = srcFolder.getFile(new Path(JavaUtils.JAVA_ROUTINES_DIRECTORY + "/ExpressionVariableTest.java"));
//$NON-NLS-1$
IFile classFile = outputFolder.getFile(new Path(JavaUtils.JAVA_ROUTINES_DIRECTORY + "/ExpressionVariableTest.class"));
InputStream in = new ByteArrayInputStream(fileContent.getBytes());
try {
if (!file.exists()) {
file.create(in, true, null);
} else {
file.delete(true, null);
classFile.delete(true, null);
file.create(in, true, null);
}
while (!classFile.exists()) {
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
RuntimeExceptionHandler.process(e1);
}
}
} catch (CoreException e1) {
RuntimeExceptionHandler.process(e1);
}
try {
in.close();
in = null;
} catch (IOException e2) {
RuntimeExceptionHandler.process(e2);
}
String javaInterpreter = CorePlugin.getDefault().getPreferenceStore().getString(ITalendCorePrefConstants.JAVA_INTERPRETER);
IPath path = outputFolder.getLocation();
//$NON-NLS-1$ //$NON-NLS-2$
String[] str = new String[] { javaInterpreter, "-cp", path.toOSString(), "routines.ExpressionVariableTest" };
InputStreamReader reader = null;
try {
Process exec = Runtime.getRuntime().exec(str);
reader = new InputStreamReader(exec.getErrorStream());
char[] buffer = new char[1024];
int i = 0;
StringBuffer bufferString = new StringBuffer();
while ((i = reader.read(buffer)) != -1) {
bufferString.append(buffer, 0, i);
}
reader.close();
if (bufferString.length() > 0) {
testResultText.setText(bufferString.toString());
}
} catch (IOException e1) {
RuntimeExceptionHandler.process(e1);
} finally {
reader = null;
}
}
}
use of org.talend.designer.runprocess.IRunProcessService in project tdi-studio-se by Talend.
the class ActiveProcessTracker method partClosed.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart)
*/
@Override
public void partClosed(IWorkbenchPart part) {
if (part instanceof AbstractMultiPageTalendEditor && currentProcess != null) {
AbstractMultiPageTalendEditor mpte = (AbstractMultiPageTalendEditor) part;
if (mpte.isKeepPropertyLocked()) {
currentProcess = null;
return;
}
IProcess process = getJobFromActivatedEditor(part);
if (process != null) {
Problems.removeProblemsByProcess(process);
Problems.removeJob(process);
IRunProcessService service = DesignerPlugin.getDefault().getRunProcessService();
service.removeProcess(process);
CodeView.refreshCodeView(null);
if (currentProcess == process) {
//$NON-NLS-1$
Contexts.setTitle("");
Contexts.clearAll();
if (lastProcessOpened == currentProcess) {
lastProcessOpened = null;
}
currentProcess = null;
for (IJobTrackerListener listener : jobTrackerListeners) {
listener.allJobClosed();
}
} else if (lastProcessOpened == process) {
lastProcessOpened = currentProcess;
}
if (GlobalServiceRegister.getDefault().isServiceRegistered(ISQLBuilderService.class)) {
ISQLBuilderService sqlBuilderService = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
sqlBuilderService.closeSqlBuilderDialogs(process.getName());
}
}
} else if (part instanceof IEditorPart) {
if (GlobalServiceRegister.getDefault().isServiceRegistered(IDiagramModelService.class) && CorePlugin.getDefault().getDiagramModelService().isBusinessDiagramEditor((IEditorPart) part)) {
//$NON-NLS-1$
Contexts.setTitle("");
Contexts.clearAll();
}
}
if (part instanceof AbstractMultiPageTalendEditor) {
AbstractMultiPageTalendEditor mpte = (AbstractMultiPageTalendEditor) part;
mpte.beforeDispose();
JobSettings.switchToCurJobSettingsView();
}
}
use of org.talend.designer.runprocess.IRunProcessService in project tdi-studio-se by Talend.
the class EditPropertiesAction method processRename.
protected void processRename(IRepositoryNode node, String originalName) {
try {
IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
ITalendProcessJavaProject talendProcessJavaProject = runProcessService.getTalendProcessJavaProject();
if (talendProcessJavaProject == null) {
return;
}
IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
IPackageFragmentRoot root = talendProcessJavaProject.getJavaProject().getPackageFragmentRoot(srcFolder);
// add for bug TDI-24379 on August 23, 2013.
IFolder srcInterFolder = srcFolder.getFolder(JavaUtils.JAVA_INTERNAL_DIRECTORY);
if (srcInterFolder.exists()) {
File file = new File(srcInterFolder.getLocationURI());
for (File f : file.listFiles()) {
if (f.isFile()) {
f.delete();
}
}
}
// qli modified to fix the bug 5400 and 6185.
// update for fix [TESB-6784]
IPackageFragment routinesPkg = getPackageFragment(root, node);
// ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName +
// SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName + ".java");
if (unit == null) {
return;
}
String newName = node.getObject().getProperty().getLabel();
JavaRenameProcessor processor = new RenameCompilationUnitProcessor(unit);
// processor.setNewElementName(newName + SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
processor.setNewElementName(newName + ".java");
RenameRefactoring ref = new RenameRefactoring(processor);
final PerformRefactoringOperation operation = new PerformRefactoringOperation(ref, CheckConditionsOperation.ALL_CONDITIONS);
IRunnableWithProgress r = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
operation.run(monitor);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
});
}
};
PlatformUI.getWorkbench().getProgressService().run(true, true, r);
RefactoringStatus conditionStatus = operation.getConditionStatus();
if (conditionStatus.hasError()) {
//$NON-NLS-1$
String errorMessage = Messages.getString("EditPropertiesAction.renameError", unit.getElementName(), newName);
RefactoringStatusEntry[] entries = conditionStatus.getEntries();
for (RefactoringStatusEntry entry : entries) {
//$NON-NLS-1$
errorMessage += "\n>>>" + entry.getMessage();
}
Shell shell = null;
IRepositoryView viewPart = getViewPart();
if (viewPart != null) {
shell = viewPart.getViewSite().getShell();
} else {
shell = Display.getCurrent().getActiveShell();
}
//$NON-NLS-1$
MessageDialog.openError(shell, Messages.getString("EditPropertiesAction.warning"), errorMessage);
return;
}
// ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + ".java");
if (newUnit == null) {
return;
}
RoutineItem item = (RoutineItem) node.getObject().getProperty().getItem();
IFile javaFile = (IFile) newUnit.getAdapter(IResource.class);
try {
ByteArray byteArray = item.getContent();
byteArray.setInnerContentFromFile(javaFile);
IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
repFactory.save(item);
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
use of org.talend.designer.runprocess.IRunProcessService in project tdi-studio-se by Talend.
the class ContextModifyCommand method getContextResource.
/**
* Gets the context file resource according to the project type.
*
* @param process
* @param context
* @return
*/
private IResource getContextResource(IProcess2 process, IContext context) throws Exception {
IPath path = new Path(JavaResourcesHelper.getProjectFolderName(process.getProperty().getItem())).append(JavaResourcesHelper.getJobFolderName(process.getName(), process.getVersion())).append(JavaUtils.JAVA_CONTEXTS_DIRECTORY).append(context.getName() + JavaUtils.JAVA_CONTEXT_EXTENSION);
if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
IRunProcessService service = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
if (talendProcessJavaProject != null) {
IFolder srcFolder = talendProcessJavaProject.getResourcesFolder();
return srcFolder.getFile(path);
}
}
return null;
}
use of org.talend.designer.runprocess.IRunProcessService in project tdi-studio-se by Talend.
the class JobLaunchConfigurationDelegate method launch.
@Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
String jobId = configuration.getAttribute(TalendDebugUIConstants.JOB_ID, (String) null);
String jobName = configuration.getAttribute(TalendDebugUIConstants.JOB_NAME, (String) null);
String jobVersion = configuration.getAttribute(TalendDebugUIConstants.JOB_VERSION, (String) null);
// find process from open editor.
IProcess2 process = DesignerUtilities.findProcessFromEditors(jobId, jobVersion);
// find process from repository
if (process == null) {
process = findProcessFromRepository(jobId, jobVersion);
}
if (process == null) {
//$NON-NLS-1$
ExceptionHandler.log(Messages.getString("JobLaunchConfigurationDelegate.jobNotFound", jobName));
return;
}
final IProcess2 p = process;
// Run job
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
IRunProcessService service = DesignerPlugin.getDefault().getRunProcessService();
service.setActiveProcess(p);
service.refreshView();
service.getRunProcessAction().run();
}
});
}
Aggregations