use of org.eclipse.core.resources.IWorkspaceRoot in project tdi-studio-se by Talend.
the class DeleteAllJobWhenStartUp method earlyStartup.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IStartup#earlyStartup()
*/
@Override
public void earlyStartup() {
if (!GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
return;
}
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject codeProject = root.getProject(TalendMavenConstants.PROJECT_NAME);
if (!codeProject.exists() || !codeProject.isAccessible()) {
return;
}
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
ITalendProcessJavaProject talendJavaProject = processService.getTalendProcessJavaProject();
if (talendJavaProject != null) {
IJavaProject jProject = talendJavaProject.getJavaProject();
if (!jProject.isOpen()) {
jProject.open(monitor);
}
// empty the src/main/java...
IFolder srcFolder = talendJavaProject.getSrcFolder();
talendJavaProject.cleanFolder(monitor, srcFolder);
// contexts
IFolder resourcesFolder = talendJavaProject.getResourcesFolder();
emptyContexts(monitor, resourcesFolder, talendJavaProject);
// empty the outputs, target
IFolder targetFolder = talendJavaProject.getTargetFolder();
talendJavaProject.cleanFolder(monitor, targetFolder);
// empty the src/test/java
IFolder testSrcFolder = talendJavaProject.getTestSrcFolder();
talendJavaProject.cleanFolder(monitor, testSrcFolder);
// empty the src/test/java (main for contexts)
IFolder testResourcesFolder = talendJavaProject.getTestResourcesFolder();
talendJavaProject.cleanFolder(monitor, testResourcesFolder);
// empty temp
IFolder tempFolder = talendJavaProject.getTempFolder();
talendJavaProject.cleanFolder(monitor, tempFolder);
// empty lib/...
IFolder libFolder = talendJavaProject.getLibFolder();
talendJavaProject.cleanFolder(monitor, libFolder);
// rules
IFolder rulesResFolder = talendJavaProject.getResourceSubFolder(monitor, JavaUtils.JAVA_RULES_DIRECTORY);
talendJavaProject.cleanFolder(monitor, rulesResFolder);
// sqltempalte
IFolder sqlTemplateResFolder = talendJavaProject.getResourceSubFolder(monitor, JavaUtils.JAVA_SQLPATTERNS_DIRECTORY);
talendJavaProject.cleanFolder(monitor, sqlTemplateResFolder);
}
}
;
};
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, new NullProgressMonitor());
} catch (CoreException e) {
if (e.getCause() != null) {
ExceptionHandler.process(e.getCause());
} else {
ExceptionHandler.process(e);
}
}
executed = true;
}
use of org.eclipse.core.resources.IWorkspaceRoot in project tdi-studio-se by Talend.
the class ChangeProjectTechinicalNameMigrationTask method execute.
/*
* (non-Javadoc)
*
* @see org.talend.migration.IWorkspaceMigrationTask#execute()
*/
@Override
public boolean execute() {
if (!ProjectManager.enableSpecialTechnicalProjectName()) {
// no need to do migration.
return false;
}
try {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
try {
root.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
IProject[] projects = root.getProjects();
for (IProject localProject : projects) {
try {
if (localProject.hasNature(TalendNature.ID)) {
// only for talend project
Project talendProject = xmiResManager.loadProject(localProject);
if (needCheckProject(localProject, talendProject)) {
checkTalendProject(localProject, talendProject);
}
}
} catch (Exception e) {
ExceptionHandler.process(e);
return false;
}
}
} finally {
xmiResManager.unloadResources();
}
// always true, no need do again.
return true;
}
use of org.eclipse.core.resources.IWorkspaceRoot in project tdi-studio-se by Talend.
the class DemosImportTest method createTempDemoProject.
protected void createTempDemoProject(String demoName) throws CoreException, PersistenceException {
Project projectInfor = new Project();
projectInfor.setLabel(demoName);
projectInfor.setDescription("no desc");
projectInfor.setLanguage(ECodeLanguage.JAVA);
User user = PropertiesFactory.eINSTANCE.createUser();
user.setLogin("testauto@talend.com");
projectInfor.setAuthor(user);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
String technicalLabel = Project.createTechnicalName(projectInfor.getLabel());
IProject prj = root.getProject(technicalLabel);
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
IProjectDescription desc = null;
if (prj.exists()) {
// always delete to avoid conflicts between 2 tests
prj.delete(true, null);
}
desc = workspace.newProjectDescription(technicalLabel);
desc.setNatureIds(new String[] { TalendNature.ID });
desc.setComment(projectInfor.getDescription());
prj.create(desc, null);
prj.open(IResource.DEPTH_INFINITE, null);
prj.setDefaultCharset("UTF-8", null);
} catch (CoreException e) {
throw new PersistenceException(e);
}
tempDemoProject = new Project();
// Fill project object
tempDemoProject.setLabel(projectInfor.getLabel());
tempDemoProject.setDescription(projectInfor.getDescription());
tempDemoProject.setLanguage(projectInfor.getLanguage());
tempDemoProject.setAuthor(projectInfor.getAuthor());
tempDemoProject.setLocal(true);
tempDemoProject.setTechnicalLabel(technicalLabel);
XmiResourceManager xmiResourceManager = new XmiResourceManager();
Resource projectResource = xmiResourceManager.createProjectResource(prj);
projectResource.getContents().add(tempDemoProject.getEmfProject());
projectResource.getContents().add(tempDemoProject.getAuthor());
xmiResourceManager.saveResource(projectResource);
}
use of org.eclipse.core.resources.IWorkspaceRoot in project tdi-studio-se by Talend.
the class AddContextCommentValueMigrationTaskTest method createTempProject.
private static void createTempProject() throws CoreException, PersistenceException, LoginException {
Project projectInfor = new Project();
projectInfor.setLabel("testauto");
projectInfor.setDescription("no desc");
projectInfor.setLanguage(ECodeLanguage.JAVA);
User user = PropertiesFactory.eINSTANCE.createUser();
user.setLogin("testauto@talend.com");
projectInfor.setAuthor(user);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
String technicalLabel = Project.createTechnicalName(projectInfor.getLabel());
IProject prj = root.getProject(technicalLabel);
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
IProjectDescription desc = null;
if (prj.exists()) {
// always delete to avoid conflicts between 2 tests
prj.delete(true, null);
}
desc = workspace.newProjectDescription(technicalLabel);
desc.setNatureIds(new String[] { TalendNature.ID });
desc.setComment(projectInfor.getDescription());
prj.create(desc, null);
prj.open(IResource.DEPTH_INFINITE, null);
prj.setDefaultCharset("UTF-8", null);
} catch (CoreException e) {
throw new PersistenceException(e);
}
sampleProject = new Project();
// Fill project object
sampleProject.setLabel(projectInfor.getLabel());
sampleProject.setDescription(projectInfor.getDescription());
sampleProject.setLanguage(projectInfor.getLanguage());
sampleProject.setAuthor(projectInfor.getAuthor());
sampleProject.setLocal(true);
sampleProject.setTechnicalLabel(technicalLabel);
XmiResourceManager xmiResourceManager = new XmiResourceManager();
Resource projectResource = xmiResourceManager.createProjectResource(prj);
projectResource.getContents().add(sampleProject.getEmfProject());
projectResource.getContents().add(sampleProject.getAuthor());
xmiResourceManager.saveResource(projectResource);
}
use of org.eclipse.core.resources.IWorkspaceRoot in project tdi-studio-se by Talend.
the class FixUnevenItemContextParametersMigrationTaskTest method createTempProject.
private static void createTempProject() throws CoreException, PersistenceException, LoginException {
Project projectInfor = new Project();
projectInfor.setLabel("testauto");
projectInfor.setDescription("no desc");
projectInfor.setLanguage(ECodeLanguage.JAVA);
User user = PropertiesFactory.eINSTANCE.createUser();
user.setLogin("testauto@talend.com");
projectInfor.setAuthor(user);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
String technicalLabel = Project.createTechnicalName(projectInfor.getLabel());
IProject prj = root.getProject(technicalLabel);
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
IProjectDescription desc = null;
if (prj.exists()) {
// always delete to avoid conflicts between 2 tests
prj.delete(true, null);
}
desc = workspace.newProjectDescription(technicalLabel);
desc.setNatureIds(new String[] { TalendNature.ID });
desc.setComment(projectInfor.getDescription());
prj.create(desc, null);
prj.open(IResource.DEPTH_INFINITE, null);
prj.setDefaultCharset("UTF-8", null);
} catch (CoreException e) {
throw new PersistenceException(e);
}
sampleProject = new Project();
// Fill project object
sampleProject.setLabel(projectInfor.getLabel());
sampleProject.setDescription(projectInfor.getDescription());
sampleProject.setLanguage(projectInfor.getLanguage());
sampleProject.setAuthor(projectInfor.getAuthor());
sampleProject.setLocal(true);
sampleProject.setTechnicalLabel(technicalLabel);
XmiResourceManager xmiResourceManager = new XmiResourceManager();
Resource projectResource = xmiResourceManager.createProjectResource(prj);
projectResource.getContents().add(sampleProject.getEmfProject());
projectResource.getContents().add(sampleProject.getAuthor());
xmiResourceManager.saveResource(projectResource);
}
Aggregations