Search in sources :

Example 6 with IBuildJobHandler

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());
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) BuildJobHandler(org.talend.repository.ui.wizards.exportjob.handler.BuildJobHandler) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) Property(org.talend.core.model.properties.Property) Test(org.junit.Test)

Example 7 with IBuildJobHandler

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());
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) BuildJobHandler(org.talend.repository.ui.wizards.exportjob.handler.BuildJobHandler) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) Property(org.talend.core.model.properties.Property) Test(org.junit.Test)

Example 8 with IBuildJobHandler

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);
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) Property(org.talend.core.model.properties.Property) Test(org.junit.Test)

Example 9 with IBuildJobHandler

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());
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) BuildJobHandler(org.talend.repository.ui.wizards.exportjob.handler.BuildJobHandler) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) Property(org.talend.core.model.properties.Property) Test(org.junit.Test)

Example 10 with IBuildJobHandler

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;
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) JobInfo(org.talend.core.model.process.JobInfo) JavaJobExportReArchieveCreator(org.talend.repository.ui.wizards.exportjob.JavaJobExportReArchieveCreator) HashSet(java.util.HashSet) IStatus(org.eclipse.core.runtime.IStatus) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IPath(org.eclipse.core.runtime.IPath) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProcessItem(org.talend.core.model.properties.ProcessItem) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) PersistenceException(org.talend.commons.exception.PersistenceException) ZipToFile(org.talend.repository.ui.utils.ZipToFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

IBuildJobHandler (org.talend.core.runtime.process.IBuildJobHandler)14 Test (org.junit.Test)9 ProcessItem (org.talend.core.model.properties.ProcessItem)9 BuildJobHandler (org.talend.repository.ui.wizards.exportjob.handler.BuildJobHandler)7 Property (org.talend.core.model.properties.Property)6 File (java.io.File)2 IFile (org.eclipse.core.resources.IFile)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)2 ZipToFile (org.talend.repository.ui.utils.ZipToFile)2 JavaJobExportReArchieveCreator (org.talend.repository.ui.wizards.exportjob.JavaJobExportReArchieveCreator)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 IStatus (org.eclipse.core.runtime.IStatus)1