Search in sources :

Example 6 with BundleModel

use of org.talend.designer.publish.core.models.BundleModel in project tesb-studio-se by Talend.

the class ExportServiceAction method exportJobsBundle.

private void exportJobsBundle(IProgressMonitor monitor, FeaturesModel feature) throws InvocationTargetException, InterruptedException {
    for (IRepositoryViewObject node : nodes) {
        ProcessItem processItem = (ProcessItem) node.getProperty().getItem();
        String bundleVersion = getBundleVersion();
        if (bundleVersion != null)
            bundleVersion = bundleVersion.replace("-", ".");
        if (exportChoiceMap == null) {
            exportChoiceMap = new HashMap<ExportChoice, Object>();
            exportChoiceMap.put(ExportChoice.needContext, true);
            exportChoiceMap.put(ExportChoice.bundleVersion, bundleVersion);
        } else {
            if (exportChoiceMap.get(ExportChoice.needContext) == null) {
                exportChoiceMap.put(ExportChoice.needContext, true);
            }
            if (exportChoiceMap.get(ExportChoice.bundleVersion) == null) {
                exportChoiceMap.put(ExportChoice.bundleVersion, bundleVersion);
            }
        }
        IBuildJobHandler buildJobOSGiHandler = BuildJobFactory.createBuildJobHandler(processItem, IContext.DEFAULT, processItem.getProperty().getVersion(), exportChoiceMap, JobExportType.OSGI);
        if (buildJobOSGiHandler != null) {
            // buildJobOSGiHandler.generateItemFiles(true, monitor);
            try {
                buildJobOSGiHandler.generateJobFiles(monitor);
                buildJobOSGiHandler.build(monitor);
                // TESB-21586 Windows-specific path objects created by Studio CommandLine when publishing
                IFile serviceTargetFile = buildJobOSGiHandler.getJobTargetFile();
                if (serviceTargetFile != null && serviceTargetFile.exists()) {
                    feature.addBundle(new BundleModel(getGroupId(), serviceManager.getNodeLabel(node), getServiceVersion(), serviceTargetFile.getLocation().toFile()));
                }
            } catch (Exception e) {
                throw new InvocationTargetException(e);
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) ProcessItem(org.talend.core.model.properties.ProcessItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) BundleModel(org.talend.designer.publish.core.models.BundleModel) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) PersistenceException(org.talend.commons.exception.PersistenceException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 7 with BundleModel

use of org.talend.designer.publish.core.models.BundleModel in project tesb-studio-se by Talend.

the class JavaCamelJobScriptsExportWSAction method exportAllReferenceJobs.

private void exportAllReferenceJobs(String routeName, ProcessItem routeProcess) throws InvocationTargetException, InterruptedException {
    Set<String> jobPackageNames = new HashSet<String>();
    for (NodeType cTalendJob : EmfModelUtils.getComponentsByName(routeProcess, "cTalendJob")) {
        // $NON-NLS-1$
        String jobId = null;
        String jobVersion = null;
        String jobContext = null;
        for (Object o : cTalendJob.getElementParameter()) {
            if (!(o instanceof ElementParameterType)) {
                continue;
            }
            ElementParameterType ept = (ElementParameterType) o;
            String eptName = ept.getName();
            if ("FROM_EXTERNAL_JAR".equals(eptName) && "true".equals(ept.getValue())) {
                // $NON-NLS-1$
                break;
            }
            if ("SELECTED_JOB_NAME:PROCESS_TYPE_PROCESS".equals(eptName)) {
                // $NON-NLS-1$
                jobId = ept.getValue();
            } else if ("SELECTED_JOB_NAME:PROCESS_TYPE_VERSION".equals(eptName)) {
                // $NON-NLS-1$
                jobVersion = ept.getValue();
            } else if ("SELECTED_JOB_NAME:PROCESS_TYPE_CONTEXT".equals(eptName)) {
                // $NON-NLS-1$
                jobContext = ept.getValue();
            }
        }
        if (jobId == null || jobVersion == null) {
            continue;
        }
        IRepositoryViewObject repositoryObject;
        Project jobProject;
        try {
            repositoryObject = getJobRepositoryNode(jobId, ERepositoryObjectType.PROCESS);
            jobProject = getJobProject(jobId, ERepositoryObjectType.PROCESS);
        } catch (PersistenceException e) {
            throw new InvocationTargetException(e);
        }
        if (RelationshipItemBuilder.LATEST_VERSION.equals(jobVersion)) {
            jobVersion = repositoryObject.getVersion();
        }
        String jobName = repositoryObject.getProperty().getDisplayName();
        String jobBundleName = routeName + "_" + jobName;
        String jobBundleSymbolicName = jobBundleName;
        String jobPackageName = getJobPackageName(jobProject, jobName, jobVersion);
        if (!jobPackageNames.contains(jobPackageName)) {
            jobPackageNames.add(jobPackageName);
        }
        Project project = ProjectManager.getInstance().getCurrentProject();
        if (project != null) {
            String projectName = project.getLabel();
            if (projectName != null && projectName.length() > 0) {
                jobBundleSymbolicName = projectName.toLowerCase() + '.' + jobBundleSymbolicName;
            }
        }
        File jobFile;
        try {
            // $NON-NLS-1$
            jobFile = File.createTempFile("job", FileConstants.JAR_FILE_SUFFIX, new File(getTempDir()));
            addBuildArtifact(repositoryObject, "jar", jobFile);
        } catch (IOException e) {
            throw new InvocationTargetException(e);
        }
        String jobBundleVersion = buildBundleVersionForReferencedJob(routeProcess, jobId);
        String jobArtifactVersion = jobBundleVersion;
        String jobGroup = (String) routeProcess.getProperty().getAdditionalProperties().get(BUILD_FROM_COMMANDLINE_GROUP);
        if (jobGroup == null) {
            jobGroup = PomIdsHelper.getJobGroupId(routeProcess.getProperty());
        }
        BundleModel jobModel = new BundleModel(jobGroup, jobBundleName, jobBundleVersion, jobFile);
        if (featuresModel.getBundles().contains(jobModel)) {
            featuresModel.getBundles().remove(jobModel);
        }
        if (featuresModel.addBundle(jobModel)) {
            exportRouteUsedJobBundle(repositoryObject, jobFile, jobVersion, jobBundleName, jobBundleSymbolicName, jobArtifactVersion.replace("-", "."), getArtifactId(), version, jobContext);
        }
    }
    addJobPackageToOsgiImport(routeProcess, jobPackageNames);
}
Also used : BundleModel(org.talend.designer.publish.core.models.BundleModel) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) Project(org.talend.core.model.general.Project) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) CamelRepositoryNodeType(org.talend.camel.model.CamelRepositoryNodeType) ENodeType(org.talend.repository.model.IRepositoryNode.ENodeType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryObject(org.talend.core.model.repository.RepositoryObject) IRepositoryObject(org.talend.core.model.repository.IRepositoryObject) File(java.io.File) HashSet(java.util.HashSet)

Example 8 with BundleModel

use of org.talend.designer.publish.core.models.BundleModel 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)

Aggregations

BundleModel (org.talend.designer.publish.core.models.BundleModel)8 ProcessItem (org.talend.core.model.properties.ProcessItem)6 IOException (java.io.IOException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 PersistenceException (org.talend.commons.exception.PersistenceException)4 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)4 FeaturesModel (org.talend.designer.publish.core.models.FeaturesModel)4 File (java.io.File)3 IFile (org.eclipse.core.resources.IFile)3 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)3 HashSet (java.util.HashSet)2 CoreException (org.eclipse.core.runtime.CoreException)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 CamelRepositoryNodeType (org.talend.camel.model.CamelRepositoryNodeType)2 Project (org.talend.core.model.general.Project)2 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)2 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)2 ENodeType (org.talend.repository.model.IRepositoryNode.ENodeType)2 FileOutputStream (java.io.FileOutputStream)1 Collection (java.util.Collection)1