use of org.talend.core.runtime.process.IBuildJobHandler in project tdi-studio-se by Talend.
the class BuildJobFactoryTest method test_createBuildJobHandler_JobExportType_POJO.
@Test
public void test_createBuildJobHandler_JobExportType_POJO() {
Property property = PropertiesFactory.eINSTANCE.createProperty();
property.setAuthor(((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
property.setLabel("ABC");
property.setVersion(VersionUtils.DEFAULT_VERSION);
//$NON-NLS-1$
property.setStatusCode("");
ProcessItem processItem = PropertiesFactory.eINSTANCE.createProcessItem();
processItem.setProperty(property);
IBuildJobHandler handler = BuildJobFactory.createBuildJobHandler(processItem, "Default", property.getVersion(), JobScriptsManagerFactory.getDefaultExportChoiceMap(), JobExportType.POJO);
Assert.assertNotNull("Can't build job for standalone job", handler);
Assert.assertEquals(BuildJobHandler.class.getName(), handler.getClass().getName());
}
use of org.talend.core.runtime.process.IBuildJobHandler in project tdi-studio-se by Talend.
the class BuildJobFactoryTest method test_createBuildJobHandler_String_default_withStandaloneSetting.
@Test
public void test_createBuildJobHandler_String_default_withStandaloneSetting() {
Property property = PropertiesFactory.eINSTANCE.createProperty();
property.setAuthor(((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
property.setLabel("ABC");
property.setVersion(VersionUtils.DEFAULT_VERSION);
//$NON-NLS-1$
property.setStatusCode("");
ProcessItem processItem = PropertiesFactory.eINSTANCE.createProcessItem();
processItem.setProperty(property);
property.getAdditionalProperties().put(TalendProcessArgumentConstant.ARG_BUILD_TYPE, "STANDALONE");
IBuildJobHandler handler = BuildJobFactory.createBuildJobHandler(processItem, "Default", property.getVersion(), JobScriptsManagerFactory.getDefaultExportChoiceMap(), (String) null);
Assert.assertNotNull("Can't build job for standalone job", handler);
Assert.assertEquals(BuildJobHandler.class.getName(), handler.getClass().getName());
}
use of org.talend.core.runtime.process.IBuildJobHandler in project tdi-studio-se by Talend.
the class BuildJobFactoryTest method test_createBuildJobHandler_String_default_withOSGiSetting.
@Test
public void test_createBuildJobHandler_String_default_withOSGiSetting() {
Property property = PropertiesFactory.eINSTANCE.createProperty();
property.setAuthor(((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
property.setLabel("ABC");
property.setVersion(VersionUtils.DEFAULT_VERSION);
//$NON-NLS-1$
property.setStatusCode("");
ProcessItem processItem = PropertiesFactory.eINSTANCE.createProcessItem();
processItem.setProperty(property);
property.getAdditionalProperties().put(TalendProcessArgumentConstant.ARG_BUILD_TYPE, "OSGI");
IBuildJobHandler handler = BuildJobFactory.createBuildJobHandler(processItem, "Default", property.getVersion(), JobScriptsManagerFactory.getDefaultExportChoiceMap(), (String) null);
Assert.assertNull("Have supported OSGi build handler, not support before", handler);
}
use of org.talend.core.runtime.process.IBuildJobHandler in project tdi-studio-se by Talend.
the class BuildJobFactoryTest method test_createBuildJobHandler_String_standalone.
@Test
public void test_createBuildJobHandler_String_standalone() {
Property property = PropertiesFactory.eINSTANCE.createProperty();
property.setAuthor(((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
property.setLabel("ABC");
property.setVersion(VersionUtils.DEFAULT_VERSION);
//$NON-NLS-1$
property.setStatusCode("");
ProcessItem processItem = PropertiesFactory.eINSTANCE.createProcessItem();
processItem.setProperty(property);
IBuildJobHandler handler = BuildJobFactory.createBuildJobHandler(processItem, "Default", property.getVersion(), JobScriptsManagerFactory.getDefaultExportChoiceMap(), "STANDALONE");
Assert.assertNotNull("Can't build job for standalone job", handler);
Assert.assertEquals(BuildJobHandler.class.getName(), handler.getClass().getName());
}
use of org.talend.core.runtime.process.IBuildJobHandler in project tdi-studio-se by Talend.
the class BuildJobManager method buildJob.
public void buildJob(String destinationPath, ProcessItem itemToExport, String version, String context, Map<ExportChoice, Object> exportChoiceMap, JobExportType jobExportType, boolean checkCompilationError, IProgressMonitor monitor) throws Exception {
IProgressMonitor pMonitor = new NullProgressMonitor();
if (monitor != null) {
pMonitor = monitor;
}
final boolean oldMeasureActived = TimeMeasure.measureActive;
if (!oldMeasureActived) {
// not active before.
TimeMeasure.display = TimeMeasure.displaySteps = TimeMeasure.measureActive = CommonsPlugin.isDebugMode();
}
final String timeMeasureId = "Build job for " + itemToExport.getProperty().getLabel() + ' ' + version;
TimeMeasure.begin(timeMeasureId);
try {
final int scale = 1000;
int total = 4;
//$NON-NLS-1$
pMonitor.beginTask(Messages.getString("JobScriptsExportWizardPage.newExportJobScript", jobExportType), scale * total);
ProcessItem processItem = itemToExport;
// get correct version
if (!RelationshipItemBuilder.LATEST_VERSION.equals(version) && version != null && !"".equals(version) && !version.equals(processItem.getProperty().getVersion())) {
processItem = ItemCacheManager.getProcessItem(processItem.getProperty().getId(), version);
}
final String label = processItem.getProperty().getLabel();
final IBuildJobHandler buildJobHandler = BuildJobFactory.createBuildJobHandler(processItem, context, version, exportChoiceMap, jobExportType);
ProcessUtils.setJarWithContext(ProcessUtils.needsToHaveContextInsideJar(processItem));
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor wrMonitor) throws CoreException {
try {
wrMonitor.beginTask(Messages.getString("JobScriptsExportWizardPage.newExportJobScript", jobExportType), scale * 3);
TimeMeasure.step(timeMeasureId, "prepare to build job");
buildJobHandler.generateItemFiles(true, new SubProgressMonitor(wrMonitor, scale));
wrMonitor.worked(scale);
TimeMeasure.step(timeMeasureId, "generateItemFiles");
buildJobHandler.generateJobFiles(new SubProgressMonitor(wrMonitor, scale));
wrMonitor.worked(scale);
TimeMeasure.step(timeMeasureId, "generateJobFiles");
buildJobHandler.build(new SubProgressMonitor(wrMonitor, scale));
TimeMeasure.step(timeMeasureId, "build and package");
wrMonitor.done();
} catch (Exception e) {
throw new CoreException(new org.eclipse.core.runtime.Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(), "Error", e));
}
}
;
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
// the update the project files need to be done in the workspace runnable to avoid all
// notification
// of changes before the end of the modifications.
workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, pMonitor);
} catch (CoreException e) {
Throwable cause = e.getCause();
if (cause == null) {
throw new PersistenceException(e);
}
throw new PersistenceException(cause);
}
ProcessUtils.setJarWithContext(false);
IFile jobTargetFile = buildJobHandler.getJobTargetFile();
if (jobTargetFile != null && jobTargetFile.exists()) {
IPath jobZipLocation = jobTargetFile.getLocation();
File jobZipFile = jobZipLocation.toFile();
String jobZip = jobZipLocation.toString();
if (needClasspathJar(exportChoiceMap)) {
ExportJobUtil.deleteTempFiles();
JavaJobExportReArchieveCreator creator = new JavaJobExportReArchieveCreator(jobZip, label);
FilesUtils.unzip(jobZip, creator.getTmpFolder() + File.separator + label + "_" + version);
creator.buildNewJar();
ZipToFile.zipFile(creator.getTmpFolder(), jobZip);
creator.deleteTempFiles();
TimeMeasure.step(timeMeasureId, "Recreate job jar for classpath");
}
// TBD-2500
Set<ProcessItem> processItems = new HashSet<ProcessItem>();
processItems.add(processItem);
// We get the father job childs.
Set<JobInfo> infos = ProcessorUtilities.getChildrenJobInfo(processItem);
Iterator<JobInfo> infoIterator = infos.iterator();
while (infoIterator.hasNext()) {
processItems.add(infoIterator.next().getProcessItem());
}
TimeMeasure.step(timeMeasureId, "getChildrenJobInfo");
// We iterate over the job and its childs in order to re-archive them if needed.
for (ProcessItem pi : processItems) {
BDJobReArchieveCreator bdRecreator = new BDJobReArchieveCreator(pi, processItem);
bdRecreator.create(jobZipFile);
}
TimeMeasure.step(timeMeasureId, "BDJobReArchieveCreator");
File jobFileTarget = new File(destinationPath);
if (jobFileTarget.isDirectory()) {
jobFileTarget = new File(destinationPath, jobZipFile.getName());
}
FilesUtils.copyFile(jobZipFile, jobFileTarget);
TimeMeasure.step(timeMeasureId, "Copy packaged file to target");
} else if (jobTargetFile != null) {
throw new Exception("Job was not built successfully, please check the logs for more details available on the workspace/.Java/lastGenerated.log");
}
if (checkCompilationError) {
CorePlugin.getDefault().getRunProcessService().checkLastGenerationHasCompilationError(false);
}
pMonitor.worked(scale);
pMonitor.done();
} finally {
TimeMeasure.end(timeMeasureId);
// if active before, not disable and active still.
if (!oldMeasureActived) {
TimeMeasure.display = TimeMeasure.displaySteps = TimeMeasure.measureActive = false;
}
}
}
Aggregations