Search in sources :

Example 21 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)

Example 22 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 23 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 24 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project AutoRefactor by JnRouvignac.

the class JavaCoreHelper method createJavaProject.

public static IJavaProject createJavaProject(String projectName, String binFolderName) throws Exception {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IProject project = root.getProject(projectName);
    if (!project.exists()) {
        project.create(null);
    } else {
        project.refreshLocal(IResource.DEPTH_INFINITE, null);
    }
    if (!project.isOpen()) {
        project.open(null);
    }
    final IFolder binFolder = project.getFolder(binFolderName);
    createFolder(binFolder);
    addNatureToProject(project, JavaCore.NATURE_ID);
    final IJavaProject javaProject = JavaCore.create(project);
    javaProject.setOutputLocation(binFolder.getFullPath(), null);
    javaProject.setRawClasspath(new IClasspathEntry[0], null);
    return javaProject;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 25 with IWorkspaceRoot

use of org.eclipse.core.resources.IWorkspaceRoot in project azure-tools-for-java by Microsoft.

the class AIResourceChangeListener method getProjectNameAsPerKey.

/**
	 * Method scans all open Maven or Dynamic web projects form workspace
	 * and returns name of project who is using specific key.
	 * @return
	 */
public static String getProjectNameAsPerKey(String keyToRemove) {
    String name = "";
    try {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IWorkspaceRoot root = workspace.getRoot();
        for (IProject iProject : root.getProjects()) {
            if (iProject.isOpen() && WebPropertyTester.isWebProj(iProject)) {
                String aiXMLPath;
                String webXMLPath;
                if (iProject.hasNature(Messages.natMaven)) {
                    aiXMLPath = Messages.aiXMLPathMaven;
                    webXMLPath = Messages.webxmlPathMaven;
                } else {
                    aiXMLPath = Messages.aiXMLPath;
                    webXMLPath = Messages.webxmlPath;
                }
                AILibraryHandler handler = new AILibraryHandler();
                IFile aiFile = iProject.getFile(aiXMLPath);
                IFile webFile = iProject.getFile(webXMLPath);
                if (aiFile.exists() && webFile.exists()) {
                    handler.parseWebXmlPath(webFile.getLocation().toOSString());
                    handler.parseAIConfXmlPath(aiFile.getLocation().toOSString());
                    // if application insights configuration is enabled.
                    if (handler.isAIWebFilterConfigured()) {
                        String key = handler.getAIInstrumentationKey();
                        if (key != null && !key.isEmpty() && key.equals(keyToRemove)) {
                            return iProject.getName();
                        }
                    }
                }
            }
        }
    } catch (Exception ex) {
        Activator.getDefault().log(Messages.genKeyListErr, ex);
    }
    return name;
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) AILibraryHandler(com.microsoft.azuretools.core.applicationinsights.AILibraryHandler)

Aggregations

IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)172 IProject (org.eclipse.core.resources.IProject)69 IPath (org.eclipse.core.runtime.IPath)60 IResource (org.eclipse.core.resources.IResource)57 IFile (org.eclipse.core.resources.IFile)53 CoreException (org.eclipse.core.runtime.CoreException)50 IWorkspace (org.eclipse.core.resources.IWorkspace)34 File (java.io.File)30 Path (org.eclipse.core.runtime.Path)29 IContainer (org.eclipse.core.resources.IContainer)26 URI (java.net.URI)18 IFolder (org.eclipse.core.resources.IFolder)17 IOException (java.io.IOException)15 IProjectDescription (org.eclipse.core.resources.IProjectDescription)13 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 IStatus (org.eclipse.core.runtime.IStatus)11 IJavaProject (org.eclipse.jdt.core.IJavaProject)11 Location (ch.acanda.eclipse.pmd.domain.Location)10