Search in sources :

Example 51 with IRunProcessService

use of org.talend.designer.runprocess.IRunProcessService 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 52 with IRunProcessService

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

the class JavaCamelJobScriptsExportWSAction method run.

@Override
public final void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    this.monitor = monitor;
    String groupId = getGroupId();
    String routeName = getArtifactId();
    String routeVersion = getArtifactVersion();
    // FIXME temporary solution for TESB-27587, in case of artivact id is diff with parent route name
    // if (CommonUIPlugin.isFullyHeadless()) {
    // try {
    // String artifactId = RouteArtifactId.get();
    // if (artifactId == null) {
    // RouteArtifactId.set(routeName);
    // // getProcessItem().getProperty().setLabel(routeName);
    // } else {
    // routeName = RouteArtifactId.get();
    // }
    // } catch (Exception e) {
    // }
    // }
    // FIXME temporary solution, should be replaced by proper handling
    // of MicroService vs. KAR build.
    boolean isCreatingMicroService = false;
    Boolean oldMS = RouteProcessingExchange.isCreatingMicroService.get();
    RouteProcessingExchange.isCreatingMicroService.set(Boolean.FALSE);
    try {
        prepareJobBuild();
        Boolean isMS = RouteProcessingExchange.isCreatingMicroService.get();
        if (isMS != null) {
            isCreatingMicroService = isMS.booleanValue();
        }
    } catch (Exception e) {
        throw new InvocationTargetException(e);
    } finally {
        RouteProcessingExchange.isCreatingMicroService.set(oldMS);
        if (oldMS == null) {
            RouteProcessingExchange.resetMavenOffline();
        }
    }
    // FIXME may require some further actions to get all POMs.
    if (ProcessorUtilities.isGeneratePomOnly()) {
        return;
    }
    featuresModel = new FeaturesModel(groupId, routeName, routeVersion);
    try {
        File routeFile;
        try {
            // $NON-NLS-1$
            routeFile = File.createTempFile("route", FileConstants.JAR_FILE_SUFFIX, new File(getTempDir()));
            addBuildArtifact(routeObject, "jar", routeFile);
        } catch (IOException e) {
            throw new InvocationTargetException(e);
        }
        BundleModel routeModel = new BundleModel(groupId, routeName, routeVersion, routeFile);
        final ProcessItem routeProcess = (ProcessItem) routeObject.getProperty().getItem();
        if (featuresModel.addBundle(routeModel)) {
            CamelFeatureUtil.addFeatureAndBundles(routeProcess, featuresModel);
            featuresModel.setConfigName(routeObject.getLabel());
            featuresModel.setContexts(JobContextUtils.getContextsMap(routeProcess));
            exportAllReferenceJobs(routeName, routeProcess);
            final Set<String> routelets = new HashSet<>();
            exportAllReferenceRoutelets(routeName, routeProcess, routelets);
            routeVersion = routeVersion.replace("-", ".");
            exportRouteBundle(routeObject, routeFile, version, null, null, routeVersion, null, routelets, null);
        }
        try {
            if (destinationKar != null) {
                // FIXME should be replaced by proper handling of
                // microservice vs. KAR creation.
                String dest = destinationKar;
                int suffixNdx = dest.length() - 4;
                String suffix = "kar";
                if (isCreatingMicroService) {
                    if (dest.regionMatches(true, suffixNdx, ".kar", 0, 4)) {
                        dest = dest.substring(0, suffixNdx) + ".jar";
                        suffix = "jar";
                    } else if (dest.regionMatches(true, suffixNdx, ".zip", 0, 4)) {
                        suffix = "zip";
                    }
                } else {
                    if (dest.regionMatches(true, suffixNdx, ".zip", 0, 4)) {
                        Boolean isZip = (Boolean) manager.getExportChoice().get(ExportChoice.needMavenScript);
                        if (isZip == null || !isZip.booleanValue()) {
                            dest = dest.substring(0, suffixNdx) + ".kar";
                        }
                    }
                }
                addBuildArtifact(routeObject, suffix, new File(dest));
            }
            IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
            ITalendProcessJavaProject talendProcessJavaProject = runProcessService.getTalendJobJavaProject(routeObject.getProperty());
            FilesUtils.copyFile(featuresModel.getContent(), new File(talendProcessJavaProject.getBundleResourcesFolder().getLocation().toOSString() + File.separator + "feature.xml"));
            // Build project and collect build artifacts
            try {
                buildJob();
            } catch (Exception ex) {
                throw new InvocationTargetException(ex);
            }
            collectBuildArtifacts();
        } catch (Exception e) {
            e.printStackTrace();
        }
        processResults(featuresModel, monitor);
    } finally {
        // remove generated files
        removeTempFiles();
    }
}
Also used : FeaturesModel(org.talend.designer.publish.core.models.FeaturesModel) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) BundleModel(org.talend.designer.publish.core.models.BundleModel) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) ProcessItem(org.talend.core.model.properties.ProcessItem) File(java.io.File) HashSet(java.util.HashSet)

Example 53 with IRunProcessService

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

the class RouteJavaScriptOSGIForESBManager method addResources.

// Add Route Resource http://jira.talendforge.org/browse/TESB-6227
@Override
protected void addResources(ExportFileResource osgiResource, ProcessItem processItem) throws Exception {
    IFolder srcFolder = null;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
        IRunProcessService processService = GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
        ITalendProcessJavaProject talendProcessJavaProject = processService.getTalendJobJavaProject(processItem.getProperty());
        if (talendProcessJavaProject != null) {
            srcFolder = talendProcessJavaProject.getExternalResourcesFolder();
        }
    }
    if (srcFolder == null) {
        return;
    }
    IPath srcPath = srcFolder.getLocation();
    // http://jira.talendforge.org/browse/TESB-6437
    // https://jira.talendforge.org/browse/TESB-7893
    Collection<IPath> routeResource = RouteResourceUtil.synchronizeRouteResource(processItem);
    if (routeResource != null) {
        for (IPath path : RouteResourceUtil.synchronizeRouteResource(processItem)) {
            osgiResource.addResource(path.removeLastSegments(1).makeRelativeTo(srcPath).toString(), path.toFile().toURI().toURL());
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) IRunProcessService(org.talend.designer.runprocess.IRunProcessService) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IFolder(org.eclipse.core.resources.IFolder)

Example 54 with IRunProcessService

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

the class CamelNewBeanWizard method refreshLibrariesListForTheBean.

private void refreshLibrariesListForTheBean() {
    GlobalServiceRegister globalServiceRegister = GlobalServiceRegister.getDefault();
    if (globalServiceRegister.isServiceRegistered(IRunProcessService.class)) {
        IRunProcessService runProcessService = globalServiceRegister.getService(IRunProcessService.class);
        MavenPomSynchronizer.addChangeLibrariesListener();
        runProcessService.updateLibraries((RoutineItem) beanItem.getProperty().getItem());
    }
}
Also used : IRunProcessService(org.talend.designer.runprocess.IRunProcessService) GlobalServiceRegister(org.talend.core.GlobalServiceRegister)

Aggregations

IRunProcessService (org.talend.designer.runprocess.IRunProcessService)54 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)30 IFolder (org.eclipse.core.resources.IFolder)17 IFile (org.eclipse.core.resources.IFile)15 File (java.io.File)14 IOException (java.io.IOException)13 ArrayList (java.util.ArrayList)12 CoreException (org.eclipse.core.runtime.CoreException)11 PersistenceException (org.talend.commons.exception.PersistenceException)10 URL (java.net.URL)9 MalformedURLException (java.net.MalformedURLException)7 IPath (org.eclipse.core.runtime.IPath)7 IProcess (org.talend.core.model.process.IProcess)7 IDesignerCoreService (org.talend.designer.core.IDesignerCoreService)6 ProcessorException (org.talend.designer.runprocess.ProcessorException)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 DocumentException (org.dom4j.DocumentException)5 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 HashSet (java.util.HashSet)4 ProcessItem (org.talend.core.model.properties.ProcessItem)4