Search in sources :

Example 86 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject 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 87 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project AutoRefactor by JnRouvignac.

the class PrepareApplyRefactoringsJob method addAll.

private void addAll(Queue<RefactoringUnit> results, List<IJavaElement> javaElements) throws JavaModelException {
    for (IJavaElement javaElement : javaElements) {
        final JavaProjectOptions options = getJavaProjectOptions(javaElement);
        if (javaElement instanceof ICompilationUnit) {
            add(results, (ICompilationUnit) javaElement, options);
        } else if (javaElement instanceof IPackageFragment) {
            final IPackageFragment pf = (IPackageFragment) javaElement;
            addAll(results, pf.getCompilationUnits(), options);
        } else if (javaElement instanceof IPackageFragmentRoot) {
            final IPackageFragmentRoot pfr = (IPackageFragmentRoot) javaElement;
            addAll(results, Arrays.asList(pfr.getChildren()));
        } else if (javaElement instanceof IJavaProject) {
            IJavaProject javaProject = (IJavaProject) javaElement;
            for (IPackageFragment pf : javaProject.getPackageFragments()) {
                addAll(results, pf.getCompilationUnits(), options);
            }
        }
    }
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 88 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project azure-tools-for-java by Microsoft.

the class SDKJarsFilter method getSelectedProject.

private IProject getSelectedProject() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    ISelectionService service = window.getSelectionService();
    ISelection selection = service.getSelection();
    Object element = null;
    IResource resource;
    IProject selProject = null;
    if (selection instanceof IStructuredSelection) {
        IStructuredSelection structuredSel = (IStructuredSelection) selection;
        element = structuredSel.getFirstElement();
    }
    if (element instanceof IProject) {
        resource = (IResource) element;
        selProject = resource.getProject();
    } else if (element instanceof IJavaProject) {
        IJavaProject proj = ((IJavaElement) element).getJavaProject();
        selProject = proj.getProject();
    }
    return selProject;
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IJavaProject(org.eclipse.jdt.core.IJavaProject) ISelection(org.eclipse.jface.viewers.ISelection) ISelectionService(org.eclipse.ui.ISelectionService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 89 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project azure-tools-for-java by Microsoft.

the class AzureDockerUIResources method getCurrentSelectedProject.

public static IProject getCurrentSelectedProject() {
    IProject project = null;
    ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
    ISelection selection = selectionService.getSelection();
    if (selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();
        if (element instanceof IResource) {
            project = ((IResource) element).getProject();
        } else if (element instanceof PackageFragmentRoot) {
            IJavaProject jProject = ((PackageFragmentRoot) element).getJavaProject();
            project = jProject.getProject();
        } else if (element instanceof IJavaElement) {
            IJavaProject jProject = ((IJavaElement) element).getJavaProject();
            project = jProject.getProject();
        }
    }
    if (project == null) {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        if (workspace.getRoot() != null && workspace.getRoot().getProjects().length > 0) {
            IProject[] projects = workspace.getRoot().getProjects();
            project = projects[projects.length - 1];
        } else {
            PluginUtil.displayErrorDialog(Display.getDefault().getActiveShell(), "No Active Project", "Must have a project first");
        }
    }
    return project;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) PackageFragmentRoot(org.eclipse.jdt.internal.core.PackageFragmentRoot) IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspace(org.eclipse.core.resources.IWorkspace) ISelection(org.eclipse.jface.viewers.ISelection) ISelectionService(org.eclipse.ui.ISelectionService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource)

Example 90 with IJavaProject

use of org.eclipse.jdt.core.IJavaProject in project XobotOS by xamarin.

the class SharpenBuilder method build.

@Override
protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) throws CoreException {
    final ConfigFile configFile = getConfigFile();
    final SourceInfo sourceInfo = configFile.getSourceInfo();
    final IFolder outputFolder = getProject().getFolder(sourceInfo.getOutputFolder());
    try {
        if (kind == CLEAN_BUILD) {
            outputFolder.delete(true, false, monitor);
            return null;
        } else if (kind == FULL_BUILD)
            outputFolder.delete(true, false, null);
        else if (kind == AUTO_BUILD || kind == INCREMENTAL_BUILD)
            WorkspaceUtilities.initializeTree(outputFolder, null);
        else
            return null;
    } catch (Exception e) {
        throw new RuntimeException("Cannot setup build environment: " + e);
    }
    Map<ICompilationUnit, Boolean> sources = new HashMap<ICompilationUnit, Boolean>();
    final IJavaProject javaProject = JavaCore.create(getProject());
    final List<ICompilationUnit> allUnits = JavaModelUtility.collectCompilationUnits(javaProject);
    if (kind == FULL_BUILD) {
        for (final ICompilationUnit unit : allUnits) {
            sources.put(unit, true);
        }
    } else {
        for (final ICompilationUnit unit : allUnits) {
            sources.put(unit, false);
        }
        IResourceDelta delta = getDelta(getProject());
        ChangedCompilationUnitCollector collector = new ChangedCompilationUnitCollector();
        delta.accept(collector);
        for (final ICompilationUnit unit : collector.changes()) {
            sources.put(unit, true);
        }
    }
    XobotBuilder.run(configFile, getProject(), sources, monitor);
    return null;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SourceInfo(sharpen.xobotos.config.SourceInfo) ConfigFile(sharpen.xobotos.config.ConfigFile) HashMap(java.util.HashMap) CoreException(org.eclipse.core.runtime.CoreException) IJavaProject(org.eclipse.jdt.core.IJavaProject)

Aggregations

IJavaProject (org.eclipse.jdt.core.IJavaProject)743 IProject (org.eclipse.core.resources.IProject)178 IFile (org.eclipse.core.resources.IFile)149 Test (org.junit.Test)146 CoreException (org.eclipse.core.runtime.CoreException)127 JavaModelException (org.eclipse.jdt.core.JavaModelException)124 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)123 IPath (org.eclipse.core.runtime.IPath)110 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)103 ArrayList (java.util.ArrayList)87 IFolder (org.eclipse.core.resources.IFolder)78 IResource (org.eclipse.core.resources.IResource)75 IJavaElement (org.eclipse.jdt.core.IJavaElement)63 IType (org.eclipse.jdt.core.IType)63 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)62 Path (org.eclipse.core.runtime.Path)57 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)56 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)47 StringInputStream (org.eclipse.xtext.util.StringInputStream)39 HashMap (java.util.HashMap)38