Search in sources :

Example 26 with IWorkspaceRoot

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;
}
Also used : IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IFolder(org.eclipse.core.resources.IFolder) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule)

Example 27 with IWorkspaceRoot

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;
}
Also used : Project(org.talend.core.model.properties.Project) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 28 with IWorkspaceRoot

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);
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) User(org.talend.core.model.properties.User) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) PersistenceException(org.talend.commons.exception.PersistenceException) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) IProject(org.eclipse.core.resources.IProject)

Example 29 with IWorkspaceRoot

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);
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) User(org.talend.core.model.properties.User) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) PersistenceException(org.talend.commons.exception.PersistenceException) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) IProject(org.eclipse.core.resources.IProject)

Example 30 with IWorkspaceRoot

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);
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) User(org.talend.core.model.properties.User) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) PersistenceException(org.talend.commons.exception.PersistenceException) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) XmiResourceManager(org.talend.core.repository.utils.XmiResourceManager) IProject(org.eclipse.core.resources.IProject)

Aggregations

IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)92 IPath (org.eclipse.core.runtime.IPath)41 IProject (org.eclipse.core.resources.IProject)31 IFile (org.eclipse.core.resources.IFile)30 IResource (org.eclipse.core.resources.IResource)29 CoreException (org.eclipse.core.runtime.CoreException)25 File (java.io.File)19 IWorkspace (org.eclipse.core.resources.IWorkspace)15 Path (org.eclipse.core.runtime.Path)14 IFolder (org.eclipse.core.resources.IFolder)12 IJavaProject (org.eclipse.jdt.core.IJavaProject)11 ArrayList (java.util.ArrayList)10 IContainer (org.eclipse.core.resources.IContainer)10 IOException (java.io.IOException)7 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)7 URI (java.net.URI)5 IProjectDescription (org.eclipse.core.resources.IProjectDescription)5 IStatus (org.eclipse.core.runtime.IStatus)5 Project (aQute.bnd.build.Project)4 Workspace (aQute.bnd.build.Workspace)4