Search in sources :

Example 1 with IBuildJobHandler

use of org.talend.core.runtime.process.IBuildJobHandler in project tdi-studio-se by Talend.

the class BuildJobFactory method createBuildJobHandler.

public static IBuildJobHandler createBuildJobHandler(ProcessItem processItem, String contextName, String version, Map<ExportChoice, Object> exportChoiceMap, String buildType) {
    // if null, will try to find the type from item for build type.
    if (StringUtils.isEmpty(buildType)) {
        final Object type = processItem.getProperty().getAdditionalProperties().get(TalendProcessArgumentConstant.ARG_BUILD_TYPE);
        if (type != null) {
            buildType = type.toString();
        }
    // else{ // if didn't set, should use default provider to create it.
    }
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put(IBuildParametes.ITEM, processItem);
    parameters.put(IBuildParametes.VERSION, version);
    parameters.put(IBuildJobParameters.CONTEXT_GROUP, contextName);
    parameters.put(IBuildJobParameters.CHOICE_OPTION, exportChoiceMap);
    final AbstractBuildProvider buildProvider = BuildExportManager.getInstance().getBuildProvider(buildType, parameters);
    if (buildProvider != null) {
        IBuildExportHandler buildExportHandler = buildProvider.createBuildExportHandler(parameters);
        if (buildExportHandler instanceof IBuildJobHandler) {
            // if buildType is null, will get first one. so use exact provider one.
            buildExportHandler.getArguments().put(TalendProcessArgumentConstant.ARG_BUILD_TYPE, buildProvider.getBuildType().getName());
            return (IBuildJobHandler) buildExportHandler;
        }
    }
    return null;
}
Also used : AbstractBuildProvider(org.talend.core.runtime.repository.build.AbstractBuildProvider) HashMap(java.util.HashMap) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) IBuildExportHandler(org.talend.core.runtime.repository.build.IBuildExportHandler)

Example 2 with IBuildJobHandler

use of org.talend.core.runtime.process.IBuildJobHandler in project tdi-studio-se by Talend.

the class BuildJobFactory method createBuildJobHandler.

/**
     * Create the build job handler according the job export type. Now only implement the handler of standalone job.
     * <p>
     * DOC ycbai Comment method "createBuildJobHandler".
     * 
     * @param exportChoiceMap
     * @param contextName
     * @param jobExportType
     * @return
     */
public static IBuildJobHandler createBuildJobHandler(ProcessItem processItem, String contextName, String version, Map<ExportChoice, Object> exportChoiceMap, JobExportType jobExportType) {
    if (jobExportType != null)
        switch(jobExportType) {
            case POJO:
                // continue
                break;
            case WSWAR:
            case WSZIP:
            case // TODO, later, when osgi pom is finished, will try to enable it.
            OSGI:
                // don't support others
                return null;
            default:
                // try the first one by default
                jobExportType = null;
                break;
        }
    String buildType = null;
    if (jobExportType != null) {
        final String newType = oldBuildTypeMap.get(jobExportType);
        if (newType == null) {
            // not valid type
            return null;
        }
        buildType = newType;
    }
    IBuildJobHandler buildJobHandler = createBuildJobHandler(processItem, contextName, version, exportChoiceMap, buildType);
    if (buildJobHandler == null) {
        // default
        buildJobHandler = new BuildJobHandler(processItem, version, contextName, exportChoiceMap);
    }
    return buildJobHandler;
}
Also used : IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) BuildJobHandler(org.talend.repository.ui.wizards.exportjob.handler.BuildJobHandler) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler)

Example 3 with IBuildJobHandler

use of org.talend.core.runtime.process.IBuildJobHandler in project tdi-studio-se by Talend.

the class BuildJobManager method buildJobs.

public boolean buildJobs(String destinationPath, List<? extends IRepositoryNode> nodes, List<String> topNames, String version, String context, Map<ExportChoice, Object> exportChoiceMap, JobExportType jobExportType, IProgressMonitor monitor) throws Exception {
    IProgressMonitor pMonitor = new NullProgressMonitor();
    if (monitor != null) {
        pMonitor = monitor;
    }
    final List<ProcessItem> processes = getProcesses(nodes);
    if (processes.size() == 1) {
        ProcessItem item = processes.get(0);
        buildJob(destinationPath, item, version, context, exportChoiceMap, jobExportType, pMonitor);
    } else {
        int scale = 1000;
        int steps = 3;
        pMonitor.beginTask(Messages.getString("JobScriptsExportWizardPage.newExportJobScript", jobExportType), //$NON-NLS-1$
        steps * scale * nodes.size());
        String topName = null;
        if (topNames != null && !topNames.isEmpty()) {
            topName = topNames.get(0);
        } else {
            topName = ProjectManager.getInstance().getCurrentProject().getLabel();
        }
        File desFile = new File(destinationPath);
        //$NON-NLS-1$ //$NON-NLS-2$
        File createTempFile = File.createTempFile("building_job", "");
        createTempFile.delete();
        File tempFolder = new File(desFile.getParent() + File.separator + createTempFile.getName());
        if (tempFolder.exists()) {
            tempFolder.delete();
        }
        File tempProFolder = new File(tempFolder, topName);
        tempProFolder.mkdirs();
        for (int i = 0; i < processes.size(); i++) {
            ProcessItem processItem = processes.get(i);
            //$NON-NLS-1$
            pMonitor.setTaskName(Messages.getString("BuildJobManager.building", processItem.getProperty().getLabel()));
            IBuildJobHandler buildJobHandler = BuildJobFactory.createBuildJobHandler(processItem, context, processItem.getProperty().getVersion(), exportChoiceMap, jobExportType);
            buildJobHandler.generateItemFiles(true, new SubProgressMonitor(pMonitor, scale));
            buildJobHandler.generateJobFiles(new SubProgressMonitor(pMonitor, scale));
            buildJobHandler.build(new SubProgressMonitor(pMonitor, scale));
            IFile jobTargetFile = buildJobHandler.getJobTargetFile();
            if (jobTargetFile != null && jobTargetFile.exists()) {
                // unzip to temp folder
                FilesUtils.unzip(jobTargetFile.getLocation().toPortableString(), tempProFolder.getAbsolutePath());
                String zipPath = jobTargetFile.getLocation().toPortableString();
                if (needClasspathJar(exportChoiceMap)) {
                    JavaJobExportReArchieveCreator creator = new JavaJobExportReArchieveCreator(zipPath, processItem.getProperty().getLabel());
                    creator.setTempFolder(tempFolder.getAbsolutePath());
                    creator.buildNewJar();
                }
            }
            pMonitor.worked(scale);
        }
        FilesUtils.zip(tempFolder.getAbsolutePath(), destinationPath);
        FilesUtils.deleteFile(tempFolder, true);
        pMonitor.done();
    }
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) ProcessItem(org.talend.core.model.properties.ProcessItem) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) JavaJobExportReArchieveCreator(org.talend.repository.ui.wizards.exportjob.JavaJobExportReArchieveCreator) ZipToFile(org.talend.repository.ui.utils.ZipToFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 4 with IBuildJobHandler

use of org.talend.core.runtime.process.IBuildJobHandler in project tdi-studio-se by Talend.

the class BuildJobFactoryTest method test_createBuildJobHandler_JobExportType_null.

@Test
public void test_createBuildJobHandler_JobExportType_null() {
    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) 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 5 with IBuildJobHandler

use of org.talend.core.runtime.process.IBuildJobHandler in project tdi-studio-se by Talend.

the class BuildJobFactoryTest method test_createBuildJobHandler_JobExportType_OSGi.

@Test
public void test_createBuildJobHandler_JobExportType_OSGi() {
    IBuildJobHandler handler = BuildJobFactory.createBuildJobHandler(PropertiesFactory.eINSTANCE.createProcessItem(), "Default", "0.1", JobScriptsManagerFactory.getDefaultExportChoiceMap(), JobExportType.OSGI);
    Assert.assertNull("Have supportted OSGi, not support before", handler);
}
Also used : IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) Test(org.junit.Test)

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