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);
}
}
}
}
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);
}
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();
}
}
Aggregations