use of org.eclipse.core.runtime.NullProgressMonitor in project tdi-studio-se by Talend.
the class BuildJobHandlerTest method testBuildJob.
@Test
public void testBuildJob() throws Exception {
Map<ExportChoice, Object> exportChoiceMap = new HashMap<ExportChoice, Object>();
exportChoiceMap.put(ExportChoice.needLauncher, true);
exportChoiceMap.put(ExportChoice.needSystemRoutine, true);
exportChoiceMap.put(ExportChoice.needUserRoutine, true);
exportChoiceMap.put(ExportChoice.needTalendLibraries, true);
exportChoiceMap.put(ExportChoice.needJobItem, false);
exportChoiceMap.put(ExportChoice.needJobScript, true);
exportChoiceMap.put(ExportChoice.needSourceCode, true);
exportChoiceMap.put(ExportChoice.includeLibs, true);
exportChoiceMap.put(ExportChoice.includeTestSource, false);
exportChoiceMap.put(ExportChoice.executeTests, false);
exportChoiceMap.put(ExportChoice.binaries, true);
exportChoiceMap.put(ExportChoice.needContext, true);
exportChoiceMap.put(ExportChoice.contextName, "Default");
exportChoiceMap.put(ExportChoice.applyToChildren, false);
exportChoiceMap.put(ExportChoice.needLog4jLevel, false);
exportChoiceMap.put(ExportChoice.log4jLevel, null);
exportChoiceMap.put(ExportChoice.needDependencies, true);
exportChoiceMap.put(ExportChoice.needParameterValues, false);
destinationPath = ExportJobUtil.getTmpFolderPath() + "/testBuildJob.zip";
BuildJobManager.getInstance().buildJob(destinationPath, processItem, "0.1", "Default", exportChoiceMap, JobExportType.POJO, new NullProgressMonitor());
assertTrue(new File(destinationPath).exists());
ZipFile zip = null;
try {
zip = new ZipFile(destinationPath);
// jobInfo
ZipEntry jobInfoEntry = zip.getEntry("jobInfo.properties");
assertNotNull("Can't find the jobInfo.properties", jobInfoEntry);
final InputStream jobInfoStream = zip.getInputStream(jobInfoEntry);
Properties jobInfoProp = new Properties();
jobInfoProp.load(jobInfoStream);
assertEquals("testBuildJob", jobInfoProp.getProperty("job"));
assertEquals("0.1", jobInfoProp.getProperty("jobVersion"));
assertEquals("Default", jobInfoProp.getProperty("contextName"));
assertEquals("_bWyBUAYbEeapTZ0aKwL_YA", jobInfoProp.getProperty("jobId"));
assertEquals("Standard", jobInfoProp.getProperty("jobType"));
final String technicalLabel = ProjectManager.getInstance().getCurrentProject().getTechnicalLabel();
assertEquals(technicalLabel, jobInfoProp.getProperty("project"));
ZipEntry libEntry = zip.getEntry("lib");
assertNotNull("No lib folder", libEntry);
// log4j
ZipEntry log4jXmlEntry = zip.getEntry("testBuildJob/log4j.xml");
assertNotNull("No log4j.xml", log4jXmlEntry);
// shell+bat
ZipEntry batEntry = zip.getEntry("testBuildJob/testBuildJob_run.bat");
assertNotNull("No bat file", batEntry);
ZipEntry shEntry = zip.getEntry("testBuildJob/testBuildJob_run.sh");
assertNotNull("No shell file", shEntry);
ZipEntry jarEntry = zip.getEntry("testBuildJob/testbuildjob_0_1.jar");
assertNotNull("No shell file", jarEntry);
// src
ZipEntry javaEntry = zip.getEntry("testBuildJob/src/main/java/" + technicalLabel.toLowerCase() + "/testbuildjob_0_1/testBuildJob.java");
assertNotNull("No job source code file", javaEntry);
ZipEntry routinesEntry = zip.getEntry("testBuildJob/src/main/java/routines/");
assertNotNull("No routines source code files", routinesEntry);
assertTrue(routinesEntry.isDirectory());
ZipEntry contextEntry = zip.getEntry("testBuildJob/src/main/resources/" + technicalLabel.toLowerCase() + "/testbuildjob_0_1/contexts/Default.properties");
assertNotNull("No context file", contextEntry);
// dq
ZipEntry tdq = zip.getEntry("testBuildJob/items/reports/");
assertNotNull("Can't find the dq reports items", tdq);
assertTrue(tdq.isDirectory());
// if the tdm is load
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITransformService.class)) {
ITransformService tdmService = (ITransformService) GlobalServiceRegister.getDefault().getService(ITransformService.class);
if (tdmService.isTransformItem(processItem)) {
ZipEntry tdmSettingEntry = zip.getEntry("testBuildJob/items/" + technicalLabel.toLowerCase() + "/.settings/com.oaklandsw.base.projectProps");
assertNotNull("Can't export tdm rightly", tdmSettingEntry);
/*
* the __tdm has been moved into job jar. so need test it in jar.
*/
// ZipEntry tdmEntry = zip.getEntry("testBuildJob/__tdm/");
// assertNotNull("Can't export tdm rightly", tdmEntry);
// assertTrue("build job with tdm failure", tdmEntry.isDirectory());
// testbuildjob_0_1.jar!/__tdm/TEST_NOLOGIN.zip
final JarInputStream jarStream = new JarInputStream(zip.getInputStream(jarEntry));
boolean found = false;
JarEntry entry;
while ((entry = jarStream.getNextJarEntry()) != null) {
final String name = entry.getName();
if (name.contains("__tdm") && name.endsWith(technicalLabel + ".zip")) {
found = true;
}
}
jarStream.close();
assertTrue("Can't find the __tdm in job jar after build", found);
}
}
} finally {
if (zip != null) {
zip.close();
}
}
}
use of org.eclipse.core.runtime.NullProgressMonitor in project tdi-studio-se by Talend.
the class BuildJobHandlerTest method setUp.
@Before
public void setUp() throws Exception {
// Fix the NPE for org.talend.designer.core.ui.editor.process.Process.createMainParameters(Process.java:401)
bridgeProject = ReponsitoryContextBridge.getProject();
ReponsitoryContextBridge.setProject(ProjectManager.getInstance().getCurrentProject().getEmfProject());
ImportExportHandlersManager importManager = new ImportExportHandlersManager();
// job with tdm and tdq component.
URL testJobURL = FileLocator.find(Platform.getBundle("org.talend.repository.test"), new Path("/resources/testBuildJob.zip"), null);
if (testJobURL != null) {
testJobURL = FileLocator.toFileURL(testJobURL);
}
File srcFile = new File(testJobURL.getFile());
FileResourcesUnityManager fileUnityManager = ResourcesManagerFactory.getInstance().createFileUnityManager(srcFile);
ResourcesManager resManager = fileUnityManager.doUnify();
List<ImportItem> projectRecords = importManager.populateImportingItems(resManager, true, new NullProgressMonitor());
assertTrue(projectRecords.size() > 0);
importManager.importItemRecords(new NullProgressMonitor(), resManager, projectRecords, true, projectRecords.toArray(new ImportItem[0]), null);
IRepositoryViewObject obj = ProxyRepositoryFactory.getInstance().getLastVersion("_bWyBUAYbEeapTZ0aKwL_YA");
Item item = obj.getProperty().getItem();
assertTrue(item instanceof ProcessItem);
processItem = (ProcessItem) item;
}
use of org.eclipse.core.runtime.NullProgressMonitor 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.NullProgressMonitor in project tdi-studio-se by Talend.
the class MergeTosMetadataMigrationTask method execute.
@Override
public ExecutionResult execute(Item item) {
if (item instanceof ConnectionItem) {
try {
URI itemURI = getItemURI(item);
if (itemURI != null) {
URI itemResourceURI = getItemResourceURI(itemURI);
if (metadata400to410 == null) {
metadata400to410 = new TosMetadataMigrationFrom400to410();
}
Resource migratedResource = metadata400to410.migrate(itemResourceURI.toString(), new NullProgressMonitor());
HashMap<String, Object> xmlSaveOtions = XML_SAVE_OTIONS_1_0;
if (migratedResource != null) {
// check for DB connection caus we need to setup Schema and Catalog properly
EObject content = migratedResource.getContents().get(0);
if (content != null && "DatabaseConnection".equals(content.eClass().getName())) {
// resource is dynamic EMF so convert it to static model by serialising it and reloading it
ByteArrayOutputStream tempStream = new ByteArrayOutputStream();
try {
// serialize into memory
try {
migratedResource.save(tempStream, XML_SAVE_OTIONS_1_0);
} catch (Exception e) {
// try with version 1.1
tempStream = new ByteArrayOutputStream();
xmlSaveOtions = XML_SAVE_OTIONS_1_1;
migratedResource.save(tempStream, xmlSaveOtions);
} finally {
tempStream.close();
}
// create a resource to laod the inmemory resource that should be a static EMF model
migratedResource = resourceSet.createResource(URI.createURI(//$NON-NLS-1$
"http://talend/dummy_static.metadata"));
migratedResource.load(new ByteArrayInputStream(tempStream.toByteArray()), xmlSaveOtions);
// check that DBConnection is firdt element
DatabaseConnection databaseConnection = SwitchHelpers.DATABASECONNECTION_SWITCH.doSwitch(migratedResource.getContents().get(0));
// do not check for null caus DB connection is already check above
String databaseType = databaseConnection.getDatabaseType();
databaseConnection.setDriverClass(ExtractMetaDataUtils.getInstance().getDriverClassByDbType(databaseType));
EDatabaseTypeName currentType = EDatabaseTypeName.getTypeFromDbType(databaseType);
EDatabaseSchemaOrCatalogMapping curCatalog = currentType.getCatalogMappingField();
EDatabaseSchemaOrCatalogMapping curSchema = currentType.getSchemaMappingField();
// all the DB connection are migrated with a Schema by default
if (!curCatalog.equals(EDatabaseSchemaOrCatalogMapping.None)) {
List<Schema> schemas = ConnectionHelper.getSchema(databaseConnection);
if (!curSchema.equals(EDatabaseSchemaOrCatalogMapping.None)) {
// we need to place the current schemas into a catalogs
ConnectionHelper.removeSchemas(schemas, databaseConnection);
for (Schema schema : schemas) {
// compute the name of the schema and the catalogs
String schemaName = computeSchemaName(schema, databaseConnection, curSchema);
String catalogName = computeCatalogName(databaseConnection, curCatalog);
schema.setName(schemaName);
Catalog catalog = RelationalFactory.eINSTANCE.createCatalog();
// catalogs are not in a contained reference
migratedResource.getContents().add(catalog);
catalog.setName(catalogName);
// add the schema to the catalog and the the catalog to the connection
CatalogHelper.addSchemas(Collections.singleton(schema), catalog);
ConnectionHelper.addCatalog(catalog, databaseConnection);
}
} else {
// we need to replace the Schemas with a Catalogs
for (Schema schema : schemas) {
// compute the name the catalog
String catalogName = computeCatalogName(databaseConnection, curCatalog);
// use owned elements to get everything regardless of tables or views or
// else
Catalog catalog = RelationalFactory.eINSTANCE.createCatalog();
// catalogs are not in a contained reference
migratedResource.getContents().add(catalog);
catalog.setName(catalogName);
catalog.getOwnedElement().addAll(schema.getOwnedElement());
ConnectionHelper.addCatalog(catalog, databaseConnection);
ConnectionHelper.removeSchemas(Collections.singleton(schema), databaseConnection);
}
}
} else if (!curSchema.equals(EDatabaseSchemaOrCatalogMapping.None)) {
List<Schema> schemas = ConnectionHelper.getSchema(databaseConnection);
for (Schema schema : schemas) {
String schemaName = computeSchemaName(schema, databaseConnection, curSchema);
schema.setName(schemaName);
}
}
// else no catalog so we keep the schema as is
} catch (Exception e) {
// we have an exception finalising the migration but we trap it caus we still try to
// save it
log.error("Cannot complete merge metadata migration on file:" + itemResourceURI.toString(), e);
ExceptionHandler.process(e);
} finally {
tempStream.close();
}
}
// else not a DB connection so persist
OutputStream outputStream = item.eResource().getResourceSet().getURIConverter().createOutputStream(itemResourceURI, null);
try {
migratedResource.save(outputStream, xmlSaveOtions);
} finally {
outputStream.close();
}
}
return ExecutionResult.SUCCESS_WITH_ALERT;
}
} catch (ATLCoreException e) {
log.error(e);
ExceptionHandler.process(e);
return ExecutionResult.SUCCESS_NO_ALERT;
} catch (IOException e) {
log.error(e);
ExceptionHandler.process(e);
return ExecutionResult.SUCCESS_NO_ALERT;
} finally {
resourceSet.getResources().clear();
}
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.eclipse.core.runtime.NullProgressMonitor in project tdi-studio-se by Talend.
the class ActiveProcessTracker method partOpened.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart)
*/
@Override
public void partOpened(IWorkbenchPart part) {
boolean existedJobOpened = false;
if (part instanceof AbstractMultiPageTalendEditor) {
AbstractMultiPageTalendEditor mpte = (AbstractMultiPageTalendEditor) part;
if (mpte.isJobAlreadyOpened()) {
mpte.updateChildrens();
// close the first editor and keep the new one. (so only one will remain)
IEditorReference[] ref = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findEditors(mpte.getEditorInput(), mpte.getEditorId(), IWorkbenchPage.MATCH_INPUT);
IEditorPart editorPart = ref[0].getEditor(false);
editorPart.doSave(new NullProgressMonitor());
((AbstractMultiPageTalendEditor) editorPart).setKeepPropertyLocked(true);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeEditor(editorPart, false);
existedJobOpened = true;
}
} else {
if (GlobalServiceRegister.getDefault().isServiceRegistered(IDiagramModelService.class)) {
CorePlugin.getDefault().getDiagramModelService().handleNewEditorAction(part);
}
}
IProcess2 process = getJobFromActivatedEditor(part);
if (part instanceof AbstractMultiPageTalendEditor && process instanceof Process) {
((Process) process).setEditor((AbstractMultiPageTalendEditor) part);
}
if (process != null && currentProcess != process && lastProcessOpened != process) {
lastProcessOpened = process;
addJobInProblemView(process);
} else if (existedJobOpened) {
currentProcess = process;
for (IJobTrackerListener listener : jobTrackerListeners) {
listener.focusOnJob(process);
}
}
}
Aggregations