Search in sources :

Example 16 with IProcessor

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);
// }
// }
}
Also used : IProcessor(org.talend.designer.runprocess.IProcessor)

Example 17 with IProcessor

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;
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) CreateMavenJobPom(org.talend.designer.maven.tools.creator.CreateMavenJobPom) IProcessor(org.talend.designer.runprocess.IProcessor) Map(java.util.Map) Property(org.talend.core.model.properties.Property) IFolder(org.eclipse.core.resources.IFolder)

Example 18 with IProcessor

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);
            }
        }
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) ProcessorException(org.talend.designer.runprocess.ProcessorException) Resource(org.eclipse.emf.ecore.resource.Resource) IProcessor(org.talend.designer.runprocess.IProcessor) URI(org.eclipse.emf.common.util.URI) ProcessorException(org.talend.designer.runprocess.ProcessorException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProcessItem(org.talend.core.model.properties.ProcessItem) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) File(java.io.File) IProcess(org.talend.core.model.process.IProcess)

Example 19 with IProcessor

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());
}
Also used : IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) IMavenPomCreator(org.talend.core.runtime.repository.build.IMavenPomCreator) IProcessor(org.talend.designer.runprocess.IProcessor) Method(java.lang.reflect.Method) Item(org.talend.core.model.properties.Item) RepositoryObjectTypeBuildProvider(org.talend.core.runtime.repository.build.RepositoryObjectTypeBuildProvider) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) Test(org.junit.Test)

Example 20 with IProcessor

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;
}
Also used : ProcessorException(org.talend.designer.runprocess.ProcessorException) IProcessor(org.talend.designer.runprocess.IProcessor) IOException(java.io.IOException) StringTokenizer(java.util.StringTokenizer) CsvArray(org.talend.core.utils.CsvArray) File(java.io.File)

Aggregations

IProcessor (org.talend.designer.runprocess.IProcessor)25 ProcessorException (org.talend.designer.runprocess.ProcessorException)11 IProcess (org.talend.core.model.process.IProcess)10 IOException (java.io.IOException)9 IFile (org.eclipse.core.resources.IFile)8 IContext (org.talend.core.model.process.IContext)8 Item (org.talend.core.model.properties.Item)7 Property (org.talend.core.model.properties.Property)7 File (java.io.File)6 IPath (org.eclipse.core.runtime.IPath)6 IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)6 Map (java.util.Map)5 IFolder (org.eclipse.core.resources.IFolder)5 ProcessItem (org.talend.core.model.properties.ProcessItem)5 CsvArray (org.talend.core.utils.CsvArray)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 HashMap (java.util.HashMap)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3