use of org.eclipse.core.runtime.IProgressMonitor 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.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.
the class JobScriptsExportWizardPage method finish.
// protected String getDestinationValueSU() {
// return this.suDestinationFilePath != null ? this.suDestinationFilePath : ""; //$NON-NLS-1$
//
// }
/**
* The Finish button was pressed. Try to do the required work now and answer a boolean indicating success. If false
* is returned then the wizard will not close.
*
* @returns boolean
*/
@Override
public boolean finish() {
// TODO
if (treeViewer != null) {
treeViewer.removeCheckStateListener(checkStateListener);
}
saveWidgetValues();
if (manager == null) {
manager = createJobScriptsManager();
}
if (!ensureTargetIsValid()) {
return false;
}
if (ensureLog4jSettingIsValid()) {
MessageDialog dialog = new MessageDialog(getShell(), "Question", null, Messages.getString("Log4jSettingPage.IlleagalBuild"), MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
dialog.open();
int result = dialog.getReturnCode();
if (result != MessageDialog.OK) {
return false;
}
}
JobExportType jobExportType = getCurrentExportType1();
if (JobExportType.POJO.equals(jobExportType)) {
IRunnableWithProgress worker = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
buildJobWithMaven(JobExportType.POJO, monitor);
}
};
try {
getContainer().run(false, true, worker);
} catch (InvocationTargetException e) {
MessageBoxExceptionHandler.process(e.getCause(), getShell());
return false;
} catch (InterruptedException e) {
return false;
}
} else {
List<ContextParameterType> contextEditableResultValuesList = null;
if (manager != null) {
contextEditableResultValuesList = manager.getContextEditableResultValuesList();
}
if (nodes.length == 1) {
RepositoryNode node = nodes[0];
if (node.getType() == ENodeType.SYSTEM_FOLDER) {
manager.setTopFolderName(ProjectManager.getInstance().getCurrentProject().getLabel());
} else {
manager.setTopFolderName(getDefaultFileNameWithType());
}
} else {
manager.setTopFolderName(getDefaultFileNameWithType());
}
// for feature:11976, recover back the old default manager value with ContextParameters
if (contextEditableResultValuesList == null) {
manager.setContextEditableResultValuesList(new ArrayList<ContextParameterType>());
} else {
manager.setContextEditableResultValuesList(contextEditableResultValuesList);
}
manager.setMultiNodes(isMultiNodes());
// achen modify to fix bug 0006222
IRunnableWithProgress worker = new JobExportAction(Arrays.asList(getCheckNodes()), getSelectedJobVersion(), manager, originalRootFolderName, getProcessType());
try {
getContainer().run(false, true, worker);
} catch (InvocationTargetException e) {
MessageBoxExceptionHandler.process(e.getCause(), getShell());
return false;
} catch (InterruptedException e) {
return false;
}
}
// see bug 7181
if (zipOption != null && zipOption.equals("true")) {
// unzip
try {
String zipFile;
if (manager != null) {
zipFile = manager.getDestinationPath();
} else {
zipFile = getDestinationValue();
int separatorIndex = zipFile.lastIndexOf(File.separator);
if (separatorIndex == -1) {
//$NON-NLS-1$
String userDir = System.getProperty("user.dir");
zipFile = userDir + File.separator + zipFile;
}
}
// Added by Marvin Wang on Feb.1, 2012 for bug TDI-18824
File file = new File(zipFile);
if (file.exists()) {
ZipToFile.unZipFile(zipFile, file.getParentFile().getAbsolutePath());
}
} catch (Exception e) {
MessageBoxExceptionHandler.process(e, getShell());
return false;
}
}
if (treeViewer != null) {
treeViewer.dispose();
}
// end
return true;
}
use of org.eclipse.core.runtime.IProgressMonitor in project tesb-studio-se by Talend.
the class CheckingBundlesProgressTest method testRun.
/**
* Test method for
* {@link org.talend.designer.esb.runcontainer.ui.progress.CheckingBundlesProgress#run(org.eclipse.core.runtime.IProgressMonitor)}
* .
*
* @throws Exception
*/
@Test
public void testRun() throws Exception {
long[] bundles = new long[] { 1, 2, 3 };
IProgressMonitor monitor = new NullProgressMonitor();
monitor.beginTask("test", 1);
try {
CheckingBundlesProgress mock = Mockito.mock(CheckingBundlesProgress.class);
Mockito.when(mock.checkRunning()).thenReturn(true);
mock.run(monitor);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
Assert.assertFalse(monitor.isCanceled());
}
use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.
the class TestComponentsAction method initialize.
public void initialize() {
Job job = new //$NON-NLS-1$
Job(//$NON-NLS-1$
"Component Test") {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
// IProgressMonitor monitorWrap = new CodeGeneratorProgressMonitor(monitor);
//$NON-NLS-1$
monitor.beginTask("Component Test Running", 1100);
IComponentsFactory componentsFactory = ComponentsFactoryProvider.getInstance();
Set<IComponent> components = componentsFactory.getComponents();
monitor.worked(100);
RepositoryContext repositoryContext = (RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY);
ECodeLanguage codeLanguage = repositoryContext.getProject().getLanguage();
String path = getPath();
// TODO
int taskTotal = components.size();
for (IComponent component : components) {
String templateURI = path + File.separatorChar + component.getName() + File.separatorChar + TestParameter.GENERATE_TEST;
File templateFile = new File(templateURI);
// System.out.println(templateFile + " " + templateFile.exists());
if (templateFile.exists()) {
File[] fileArray = getFile(templateFile, codeLanguage);
//$NON-NLS-1$ //$NON-NLS-2$
generateCode(fileArray, templateURI.replace("\\", "/"));
}
monitor.worked(1 * 1000 / taskTotal);
}
} catch (Exception e) {
//$NON-NLS-1$
log.error("Exception during test Initialization", e);
}
monitor.done();
return Status.OK_STATUS;
}
};
job.schedule();
}
use of org.eclipse.core.runtime.IProgressMonitor in project tdi-studio-se by Talend.
the class JSONToXPathLinker method createLinks.
/**
* DOC amaumont Comment method "createLinks".
*/
public void createLinks() {
removeAllLinks();
getBackgroundRefresher().refreshBackground();
ProgressDialog progressDialog = new ProgressDialog(getTree().getShell(), 1000) {
private IProgressMonitor monitorWrap;
@Override
public void run(IProgressMonitor monitor) {
TableItem[] loopTableItems = loopTableEditorView.getTable().getItems();
TableItem[] fieldsTableItems = fieldsTableEditorView.getTable().getItems();
monitorWrap = new EventLoopProgressMonitor(monitor);
String taskName = "Loop links creation ...";
int totalWork = loopTableItems.length + fieldsTableItems.length;
monitorWrap.beginTask(taskName, totalWork);
List<JSONXPathLoopDescriptor> xpathLoopDescriptorList = loopTableEditorView.getModel().getBeansList();
for (int i = 0; i < loopTableItems.length; i++) {
if (monitorWrap.isCanceled()) {
return;
}
TableItem tableItem = loopTableItems[i];
JSONXPathLoopDescriptor xpathLoopDescriptor = xpathLoopDescriptorList.get(i);
String originalValue = xpathLoopDescriptor.getAbsoluteXPathQuery();
if (xpathLoopDescriptor.getConnection() != null) {
ContextType contextType = ConnectionContextHelper.getContextTypeForContextMode(xpathLoopDescriptor.getConnection(), xpathLoopDescriptor.getConnection().getContextName());
if (contextType != null) {
originalValue = ConnectionContextHelper.getOriginalValue(contextType, xpathLoopDescriptor.getAbsoluteXPathQuery());
originalValue = TalendQuoteUtils.removeQuotes(originalValue);
}
}
if (originalValue != null) {
createLoopLinks(originalValue, tableItem, monitorWrap);
}
monitorWrap.worked(1);
}
List<SchemaTarget> schemaTargetList = fieldsTableEditorView.getModel().getBeansList();
createFieldsLinkWithProgressMonitor(monitorWrap, schemaTargetList.size() + loopTableItems.length, schemaTargetList, 0, fieldsTableItems.length);
monitorWrap.done();
}
};
try {
progressDialog.executeProcess();
} catch (InvocationTargetException e) {
ExceptionHandler.process(e);
} catch (InterruptedException e) {
// Nothing to do
}
}
Aggregations