use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class ExportItemUtil method getEclipseProject.
// For fix TDI-34281
protected IProject getEclipseProject(String technicalLabel) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject eclipseProject = workspace.getRoot().getProject(technicalLabel);
return eclipseProject;
}
use of org.eclipse.core.resources.IWorkspace 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;
}
}
}
use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class RepositoryService method isloginDialogDisabled.
private boolean isloginDialogDisabled() {
//$NON-NLS-1$
boolean reload = Boolean.parseBoolean(System.getProperty("talend.project.reload"));
PreferenceManipulator preferenceManipulator = new PreferenceManipulator();
ConnectionBean lastBean = null;
if (reload) {
final ConnectionUserPerReader instance = ConnectionUserPerReader.getInstance();
instance.forceReadConnections();
final String lastConncetion = ConnectionUserPerReader.getInstance().readLastConncetion();
for (ConnectionBean bean : instance.readConnections()) {
if (bean.getName().equals(lastConncetion)) {
lastBean = bean;
break;
}
}
}
if (ArrayUtils.contains(Platform.getApplicationArgs(), EclipseCommandLine.TALEND_DISABLE_LOGINDIALOG_COMMAND)) {
//$NON-NLS-1$
boolean deleteProjectIfExist = ArrayUtils.contains(Platform.getApplicationArgs(), "--deleteProjectIfExist");
IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
brandingService.getBrandingConfiguration().setUseProductRegistration(false);
ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
//$NON-NLS-1$ //$NON-NLS-2$
String projectName = getAppArgValue("-project", "AUTO_LOGIN_PROJECT");
//$NON-NLS-1$
String language = getAppArgValue("-language", ECodeLanguage.JAVA.getName());
//$NON-NLS-1$ //$NON-NLS-2$
String login = getAppArgValue("-login", "auto@login.com");
//$NON-NLS-1$ //$NON-NLS-2$
String password = getAppArgValue("-loginPass", "");
//$NON-NLS-1$
String tacURL = getAppArgValue("-tacURL", null);
// if tacURL is null, the branch will be no useful.
//$NON-NLS-1$
String branch = getAppArgValue("-branch", null);
// if tacURL is not null, will be remote
final boolean isRemote = tacURL != null;
if (reload && lastBean != null) {
final String lastProject = preferenceManipulator.getLastProject();
if (lastProject != null) {
projectName = lastProject;
}
final String lastUser = lastBean.getUser();
if (lastUser != null) {
login = lastUser;
}
final String lastPass = lastBean.getPassword();
if (lastPass != null) {
password = lastPass;
}
}
User userInfo = PropertiesFactoryImpl.eINSTANCE.createUser();
userInfo.setLogin(login);
try {
userInfo.setPassword(PasswordHelper.encryptPasswd(password));
} catch (NoSuchAlgorithmException e) {
ExceptionHandler.process(e);
}
LoginHelper.isAutoLogonFailed = false;
try {
ConnectionBean bean = null;
if (reload && lastBean != null) {
// reload
bean = lastBean;
} else {
if (tacURL != null && isRemote) {
// remote
bean = ConnectionBean.getDefaultRemoteConnectionBean();
bean.setUser(login);
bean.setPassword(password);
bean.getDynamicFields().put(RepositoryConstants.REPOSITORY_URL, tacURL);
} else {
bean = ConnectionBean.getDefaultConnectionBean();
}
}
Context ctx = CorePlugin.getContext();
RepositoryContext repositoryContext = new RepositoryContext();
ctx.putProperty(Context.REPOSITORY_CONTEXT_KEY, repositoryContext);
repositoryContext.setUser(userInfo);
repositoryContext.setClearPassword(password);
repositoryContext.setFields(bean.getDynamicFields());
repositoryFactory.setRepositoryFactoryFromProvider(RepositoryFactoryProvider.getRepositoriyById(bean.getRepositoryId()));
Project project = null;
for (Project p : repositoryFactory.readProject()) {
if (p.getLabel().equals(projectName) || p.getTechnicalLabel().equals(projectName)) {
project = p;
break;
}
}
if (!reload) {
if (deleteProjectIfExist && project != null) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject eclipseProject = workspace.getRoot().getProject(project.getTechnicalLabel());
if (eclipseProject.exists()) {
eclipseProject.delete(true, new NullProgressMonitor());
}
}
if (!isRemote && (project == null || deleteProjectIfExist)) {
Project projectInfor = //$NON-NLS-1$
ProjectHelper.createProject(//$NON-NLS-1$
projectName, //$NON-NLS-1$
"", language, userInfo);
project = repositoryFactory.createProject(projectInfor);
}
} else {
if (project != null && !project.getEmfProject().isLocal() && repositoryFactory.isLocalConnectionProvider()) {
List<IRepositoryFactory> rfList = RepositoryFactoryProvider.getAvailableRepositories();
IRepositoryFactory remoteFactory = null;
for (IRepositoryFactory rf : rfList) {
if (!rf.isLocalConnectionProvider()) {
remoteFactory = rf;
break;
}
}
if (remoteFactory != null) {
repositoryFactory.setRepositoryFactoryFromProvider(remoteFactory);
repositoryFactory.getRepositoryContext().setOffline(true);
}
}
}
if (!repositoryFactory.isLocalConnectionProvider()) {
ProjectManager.getInstance().setMainProjectBranch(project, preferenceManipulator.getLastSVNBranch(new JSONObject(project.getEmfProject().getUrl()).getString("location"), project.getTechnicalLabel()));
}
if (project != null && reload && lastBean != null && repositoryFactory.getRepositoryContext().isOffline()) {
if (PluginChecker.isSVNProviderPluginLoaded()) {
ISVNProviderService svnProviderService = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
if (svnProviderService.isSVNProject(project)) {
String projectUrl = svnProviderService.getProjectUrl(project);
String lastBranch = preferenceManipulator.getLastSVNBranch(projectUrl, project.getTechnicalLabel());
ProjectManager.getInstance().setMainProjectBranch(project, lastBranch);
}
}
}
if (project == null) {
//$NON-NLS-1$
throw new LoginException(Messages.getString("RepositoryService.projectNotFound", projectName));
}
repositoryContext.setProject(project);
repositoryFactory.logOnProject(project, new NullProgressMonitor());
} catch (final PersistenceException e) {
if (e instanceof OperationCancelException) {
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.getString("LoginDialog.logonCanceled"), e.getLocalizedMessage());
}
});
} else {
MessageBoxExceptionHandler.process(e, new Shell());
}
repositoryFactory.logOffProject();
LoginHelper.isAutoLogonFailed = true;
} catch (LoginException e) {
MessageBoxExceptionHandler.process(e, new Shell());
repositoryFactory.logOffProject();
LoginHelper.isAutoLogonFailed = true;
} catch (BusinessException e) {
MessageBoxExceptionHandler.process(e, new Shell());
repositoryFactory.logOffProject();
LoginHelper.isAutoLogonFailed = true;
} catch (CoreException e) {
MessageBoxExceptionHandler.process(e, new Shell());
repositoryFactory.logOffProject();
LoginHelper.isAutoLogonFailed = true;
} catch (JSONException e) {
ExceptionHandler.process(e);
LoginHelper.isAutoLogonFailed = true;
}
if (LoginHelper.isAutoLogonFailed) {
LoginHelper.isRestart = true;
}
return true;
}
return false;
}
use of org.eclipse.core.resources.IWorkspace in project tdi-studio-se by Talend.
the class ImportItemUtil method importItemRecords.
@SuppressWarnings("unchecked")
public List<ItemRecord> importItemRecords(final ResourcesManager manager, final List<ItemRecord> itemRecords, final IProgressMonitor monitor, final boolean overwrite, final IPath destinationPath, final String contentType) {
TimeMeasure.display = CommonsPlugin.isDebugMode();
TimeMeasure.displaySteps = CommonsPlugin.isDebugMode();
TimeMeasure.measureActive = CommonsPlugin.isDebugMode();
TimeMeasure.begin("importItemRecords");
hasJoblets = false;
statAndLogsSettingsReloaded = false;
implicitSettingsReloaded = false;
restoreFolder = new RestoreFolderUtil();
Collections.sort(itemRecords, new Comparator<ItemRecord>() {
@Override
public int compare(ItemRecord o1, ItemRecord o2) {
if (o1.getProperty().getItem() instanceof RoutineItem && o2.getProperty().getItem() instanceof RoutineItem) {
return 0;
} else if (!(o1.getProperty().getItem() instanceof RoutineItem) && !(o2.getProperty().getItem() instanceof RoutineItem)) {
// TUP-2548 sort items by label
String label = o1.getLabel();
if (label == null) {
return -1;
}
final String label2 = o2.getLabel();
if (label2 == null) {
return 1;
}
return label.compareTo(label2);
} else if (o1.getProperty().getItem() instanceof RoutineItem) {
return -1;
} else {
return 1;
}
}
});
//$NON-NLS-1$
monitor.beginTask(Messages.getString("ImportItemWizardPage.ImportSelectedItems"), itemRecords.size() * 2 + 1);
RepositoryWorkUnit repositoryWorkUnit = new //$NON-NLS-1$
RepositoryWorkUnit(//$NON-NLS-1$
"Import Items") {
@Override
public void run() throws PersistenceException {
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
final IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
// bug 10520
final Set<String> overwriteDeletedItems = new HashSet<String>();
final Set<String> idDeletedBeforeImport = new HashSet<String>();
Map<String, String> nameToIdMap = new HashMap<String, String>();
for (ItemRecord itemRecord : itemRecords) {
if (!monitor.isCanceled()) {
if (itemRecord.isValid()) {
if (itemRecord.getState() == State.ID_EXISTED) {
String id = nameToIdMap.get(itemRecord.getProperty().getLabel() + ERepositoryObjectType.getItemType(itemRecord.getProperty().getItem()).toString());
if (id == null) {
/*
* if id exsist then need to genrate new id for this job,in this case the
* job won't override the old one
*/
id = EcoreUtil.generateUUID();
nameToIdMap.put(itemRecord.getProperty().getLabel() + ERepositoryObjectType.getItemType(itemRecord.getProperty().getItem()).toString(), id);
}
itemRecord.getProperty().setId(id);
}
}
}
}
for (ItemRecord itemRecord : itemRecords) {
if (!monitor.isCanceled()) {
if (itemRecord.isValid()) {
importItemRecord(manager, itemRecord, overwrite, destinationPath, overwriteDeletedItems, idDeletedBeforeImport, contentType, monitor);
IRepositoryViewObject object;
try {
Property property = itemRecord.getProperty();
if (property == null) {
object = factory.getSpecificVersion(itemRecord.getItemId(), itemRecord.getItemVersion(), true);
property = object.getProperty();
}
RelationshipItemBuilder.getInstance().addOrUpdateItem(property.getItem(), true);
itemRecord.setProperty(null);
ProxyRepositoryFactory.getInstance().unloadResources(property);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
statAndLogsSettingsReloaded = false;
implicitSettingsReloaded = false;
monitor.worked(1);
}
}
}
// deploy routines Jar
if (!getRoutineExtModulesMap().isEmpty()) {
Set<String> extRoutines = new HashSet<String>();
for (String id : getRoutineExtModulesMap().keySet()) {
Set<String> set = getRoutineExtModulesMap().get(id);
if (set != null) {
extRoutines.addAll(set);
}
}
if (manager instanceof ProviderManager || manager instanceof ZipFileManager) {
deployJarToDesForArchive(manager, extRoutines);
} else {
deployJarToDes(manager, extRoutines);
}
}
if (PluginChecker.isJobLetPluginLoaded()) {
IJobletProviderService service = (IJobletProviderService) GlobalServiceRegister.getDefault().getService(IJobletProviderService.class);
if (service != null) {
service.loadComponentsFromProviders();
}
}
checkDeletedFolders();
monitor.done();
TimeMeasure.step("importItemRecords", "before save");
if (RelationshipItemBuilder.getInstance().isNeedSaveRelations()) {
RelationshipItemBuilder.getInstance().saveRelations();
TimeMeasure.step("importItemRecords", "save relations");
} else {
// with relations
try {
factory.saveProject(ProjectManager.getInstance().getCurrentProject());
} catch (PersistenceException e) {
throw new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(), "Import errors", e));
}
TimeMeasure.step("importItemRecords", "save project");
}
}
};
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, monitor);
} catch (CoreException e) {
// ?
}
}
};
repositoryWorkUnit.setAvoidUnloadResources(true);
repositoryWorkUnit.setUnloadResourcesAfterRun(true);
ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(repositoryWorkUnit);
monitor.done();
// for (ItemRecord itemRecord : itemRecords) {
// itemRecord.clear();
// }
clearAllData();
if (hasJoblets) {
ComponentsFactoryProvider.getInstance().resetSpecificComponents();
}
TimeMeasure.end("importItemRecords");
TimeMeasure.display = false;
TimeMeasure.displaySteps = false;
TimeMeasure.measureActive = false;
return itemRecords;
}
use of org.eclipse.core.resources.IWorkspace in project tesb-studio-se by Talend.
the class OpenAnotherVersionResrouceWizard method performFinish.
@Override
public boolean performFinish() {
if (mainPage.isCreateNewVersionJob()) {
IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
public void run(final IProgressMonitor monitor) throws CoreException {
if (!alreadyEditedByUser) {
getProperty().setVersion(mainPage.getNewVersion());
refreshNewJob();
try {
ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
try {
ProxyRepositoryFactory.getInstance().lock(repoObject);
} catch (PersistenceException | LoginException e) {
ExceptionHandler.process(e);
}
// boolean locked = repoObject.getRepositoryStatus().equals(
// ERepositoryStatus.LOCK_BY_USER);
openAnotherVersion((IRepositoryNode) repoObject.getRepositoryNode());
try {
ProxyRepositoryFactory.getInstance().saveProject(ProjectManager.getInstance().getCurrentProject());
} catch (PersistenceException e) {
ExceptionHandler.process(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(runnable, schedulingRule, IWorkspace.AVOID_UPDATE, null);
} catch (CoreException e) {
MessageBoxExceptionHandler.process(e);
}
} else {
StructuredSelection selection = (StructuredSelection) mainPage.getSelection();
IRepositoryNode node = (IRepositoryNode) selection.getFirstElement();
boolean lastVersion = node.getObject().getVersion().equals(repoObject.getVersion());
repoObject.getProperty().setVersion(originalVersion);
if (lastVersion) {
lockObject(repoObject);
}
// ERepositoryStatus status = node.getObject().getRepositoryStatus();
// boolean isLocked = false;
// if (status == ERepositoryStatus.LOCK_BY_USER) {
// isLocked = true;
// }
// Only latest version can be editted
openAnotherVersion(node);
}
return true;
}
Aggregations