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