Search in sources :

Example 21 with IProcessor

use of org.talend.designer.runprocess.IProcessor in project tdi-studio-se by Talend.

the class RowGenProcessMain method runPreviewCode.

/**
     * qzhang Comment method "runPreviewCode".
     */
public Process runPreviewCode() {
    getProcess();
    if (jobContextManager == null) {
        // proc.getContextManager().setListContext(component.getProcess().getContextManager().getListContext());
        proc.getContextManager().setDefaultContext(component.getProcess().getContextManager().getDefaultContext());
    } else {
        // proc.getContextManager().setListContext(jobContextManager.getListContext());
        proc.getContextManager().setDefaultContext(jobContextManager.getDefaultContext());
    }
    // IContext context2 = new org.talend.core.model.context.JobContext(PREVIEW);
    // if (UIManager.isJavaProject()) {
    // List<IContextParameter> params = new ArrayList<IContextParameter>();
    // JobContextParameter contextParameter = new JobContextParameter();
    // contextParameter.setContext(context2);
    // contextParameter.setName(PREVIEW);
    // contextParameter.setValue(PREVIEW);
    // contextParameter.setType("String");
    // params.add(contextParameter);
    // context2.setContextParameterList(params);
    // }
    // generate context files.
    IProcessor contextProcessor = ProcessorUtilities.getProcessor(proc, null);
    contextProcessor.setContext(proc.getContextManager().getDefaultContext());
    try {
        contextProcessor.cleanBeforeGenerate(TalendProcessOptionConstants.CLEAN_CONTEXTS);
        contextProcessor.generateContextCode();
    } catch (ProcessorException pe) {
        ExceptionHandler.process(pe);
    }
    IProcessor processor = ProcessorUtilities.getProcessor(proc, null, proc.getContextManager().getDefaultContext());
    try {
        return processor.run(IProcessor.NO_STATISTICS, IProcessor.NO_TRACES, null);
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return null;
    }
}
Also used : ProcessorException(org.talend.designer.runprocess.ProcessorException) IProcessor(org.talend.designer.runprocess.IProcessor) ProcessorException(org.talend.designer.runprocess.ProcessorException) IOException(java.io.IOException)

Example 22 with IProcessor

use of org.talend.designer.runprocess.IProcessor in project tesb-studio-se by Talend.

the class CreateMavenBundlePom method getProcessor.

public static IProcessor getProcessor(JobInfo jobInfo) {
    if (jobInfo.getProcessor() != null) {
        return jobInfo.getProcessor();
    }
    IProcess process = null;
    ProcessItem processItem;
    processItem = jobInfo.getProcessItem();
    if (processItem == null && jobInfo.getJobVersion() == null) {
        processItem = ItemCacheManager.getProcessItem(jobInfo.getJobId());
    }
    if (processItem == null && jobInfo.getJobVersion() != null) {
        processItem = ItemCacheManager.getProcessItem(jobInfo.getJobId(), jobInfo.getJobVersion());
    }
    if (processItem == null && jobInfo.getProcess() == null) {
        return null;
    }
    if (jobInfo.getProcess() == null) {
        if (processItem != null) {
            IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
            process = service.getProcessFromProcessItem(processItem);
            if (process instanceof IProcess2) {
                ((IProcess2) process).setProperty(processItem.getProperty());
            }
        }
        if (process == null) {
            return null;
        }
    } else {
        process = jobInfo.getProcess();
    }
    Property curProperty = processItem.getProperty();
    if (processItem.getProperty() == null && process instanceof IProcess2) {
        curProperty = ((IProcess2) process).getProperty();
    }
    IRunProcessService service = CorePlugin.getDefault().getRunProcessService();
    IProcessor processor = service.createCodeProcessor(process, curProperty, ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject().getLanguage(), true);
    jobInfo.setProcessor(processor);
    return processor;
}
Also used : RepositoryContext(org.talend.core.context.RepositoryContext) ProcessItem(org.talend.core.model.properties.ProcessItem) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) IProcess2(org.talend.core.model.process.IProcess2) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcessor(org.talend.designer.runprocess.IProcessor) IProcess(org.talend.core.model.process.IProcess) ActivationProperty(org.apache.maven.model.ActivationProperty) Property(org.talend.core.model.properties.Property)

Example 23 with IProcessor

use of org.talend.designer.runprocess.IProcessor in project tesb-studio-se by Talend.

the class RouteOSGiBundleBuildProvider method createPomCreator.

/*
     * (non-Javadoc)
     *
     * @see org.talend.core.runtime.repository.build.AbstractBuildProvider#createPomCreator(java.util.Map)
     */
@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 (!ProcessorUtilities.isGeneratePomOnly() && (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;
    }
    CreateMavenBundlePom osgiPomCreator = new CreateMavenBundlePom((IProcessor) processor, (IFile) pomFile);
    osgiPomCreator.setUnixClasspath(linuxClassPath.toString());
    osgiPomCreator.setWindowsClasspath(winClassPath.toString());
    osgiPomCreator.setAssemblyFile((IFile) assemblyFile);
    osgiPomCreator.setArgumentsMap((Map<String, Object>) argumentsMap);
    osgiPomCreator.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());
        osgiPomCreator.setObjectTypeFolder(objectTypeFolder);
        osgiPomCreator.setItemRelativePath(itemRelativePath);
    }
    return osgiPomCreator;
}
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) IProcessor(org.talend.designer.runprocess.IProcessor) Map(java.util.Map) Property(org.talend.core.model.properties.Property) IFolder(org.eclipse.core.resources.IFolder)

Example 24 with IProcessor

use of org.talend.designer.runprocess.IProcessor in project tesb-studio-se by Talend.

the class RouteletOSGiBundleBuildProvider 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 (!ProcessorUtilities.isGeneratePomOnly() && (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;
    }
    CreateRouteletMavenBundlePom osgiPomCreator = new CreateRouteletMavenBundlePom((IProcessor) processor, (IFile) pomFile);
    osgiPomCreator.setUnixClasspath(linuxClassPath.toString());
    osgiPomCreator.setWindowsClasspath(winClassPath.toString());
    osgiPomCreator.setAssemblyFile((IFile) assemblyFile);
    osgiPomCreator.setArgumentsMap((Map<String, Object>) argumentsMap);
    osgiPomCreator.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());
        osgiPomCreator.setObjectTypeFolder(objectTypeFolder);
        osgiPomCreator.setItemRelativePath(itemRelativePath);
    }
    return osgiPomCreator;
}
Also used : Item(org.talend.core.model.properties.Item) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IProcessor(org.talend.designer.runprocess.IProcessor) Map(java.util.Map) Property(org.talend.core.model.properties.Property) IFolder(org.eclipse.core.resources.IFolder)

Example 25 with IProcessor

use of org.talend.designer.runprocess.IProcessor in project tesb-studio-se by Talend.

the class CreateRouteAsOSGIPomTest method initializeAndCompare.

private void initializeAndCompare(String testCaseName) throws PersistenceException, IOException, CoreException {
    IProcessor processor = getProcessor(testCaseName);
    Project project = ProjectManager.getInstance().getCurrentProject();
    IProject fsProject = ResourceUtils.getProject(project);
    IPath path = getPomPathForTest(testCaseName);
    IMavenPomCreator pomCreator = createPomCreator(processor, fsProject.getFile(path));
    try {
        pomCreator.create(new NullProgressMonitor());
    } catch (Exception e) {
        e.printStackTrace();
        ExceptionHandler.process(e);
        fail(e.getMessage());
    }
    compareGeneratedFilesWithReference(processor.getCodeProject(), testCaseName.toLowerCase() + UNDERSCORE + TEST_ITEM_VERSION);
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) IMavenPomCreator(org.talend.core.runtime.repository.build.IMavenPomCreator) IProcessor(org.talend.designer.runprocess.IProcessor) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException)

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