Search in sources :

Example 31 with IWorkspace

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

the class PluginUtil method refreshWorkspace.

/**
	 * Refreshes the workspace.
	 */
public static void refreshWorkspace() {
    try {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IWorkspaceRoot root = workspace.getRoot();
        root.refreshLocal(IResource.DEPTH_INFINITE, null);
    } catch (CoreException e) {
        //This is just a try to refresh workspace.
        //User can also refresh the workspace manually.
        //So user should not get any exception prompt.
        Activator.getDefault().log(Messages.resCLExWkspRfrsh, null);
    }
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace)

Example 32 with IWorkspace

use of org.eclipse.core.resources.IWorkspace 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 33 with IWorkspace

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

the class SparkSubmitModel method action.

public void action(@NotNull SparkSubmissionParameter submissionParameter) {
    this.submissionParameter = submissionParameter;
    if (isLocalArtifact()) {
        submit();
    } else {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IWorkspaceRoot root = workspace.getRoot();
        IProject proj = root.getProject(submissionParameter.getArtifactName());
        JarExportJob job = new JarExportJob("Building jar", proj);
        job.schedule();
        job.addJobChangeListener(new JobChangeAdapter() {

            public void done(IJobChangeEvent event) {
                if (event.getResult().isOK()) {
                    submit();
                }
            }

            ;
        });
    }
}
Also used : IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) IProject(org.eclipse.core.resources.IProject)

Example 34 with IWorkspace

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

the class CreateProjectUtil method convert.

@NotNull
private static IFile convert(@NotNull File file) {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IPath location = Path.fromOSString(file.getAbsolutePath());
    IFile ifile = workspace.getRoot().getFileForLocation(location);
    return ifile;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IWorkspace(org.eclipse.core.resources.IWorkspace) NotNull(com.microsoft.azuretools.azurecommons.helpers.NotNull)

Example 35 with IWorkspace

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

the class ApplicationInsightsResourceRegistryEclipse method getInUseInstrumentationKeys.

/**
	 * Method scans all open Maven or Dynamic web projects form workspace
	 * and prepare a list of instrumentation keys which are in use.
	 * @return
	 */
public static List<String> getInUseInstrumentationKeys() {
    List<String> keyList = new ArrayList<String>();
    try {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IWorkspaceRoot root = workspace.getRoot();
        for (IProject iProject : root.getProjects()) {
            if (iProject.isOpen() && WebPropertyTester.isWebProj(iProject)) {
                String aiXMLPath;
                if (iProject.hasNature(Messages.natMaven)) {
                    aiXMLPath = Messages.aiXMLPathMaven;
                } else {
                    aiXMLPath = Messages.aiXMLPath;
                }
                AILibraryHandler handler = new AILibraryHandler();
                IFile file = iProject.getFile(aiXMLPath);
                if (file.exists()) {
                    handler.parseAIConfXmlPath(file.getLocation().toOSString());
                    String key = handler.getAIInstrumentationKey();
                    if (key != null && !key.isEmpty()) {
                        keyList.add(key);
                    }
                }
            }
        }
    } catch (Exception ex) {
        Activator.getDefault().log(ex.getMessage(), ex);
    }
    return keyList;
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) IOException(java.io.IOException) RestOperationException(com.microsoft.applicationinsights.management.rest.client.RestOperationException) AzureCmdException(com.microsoft.azuretools.azurecommons.helpers.AzureCmdException)

Aggregations

IWorkspace (org.eclipse.core.resources.IWorkspace)118 IProject (org.eclipse.core.resources.IProject)55 CoreException (org.eclipse.core.runtime.CoreException)54 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)37 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)36 IPath (org.eclipse.core.runtime.IPath)35 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)29 IStatus (org.eclipse.core.runtime.IStatus)27 IFile (org.eclipse.core.resources.IFile)24 PersistenceException (org.talend.commons.exception.PersistenceException)23 IProjectDescription (org.eclipse.core.resources.IProjectDescription)21 File (java.io.File)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)19 Path (org.eclipse.core.runtime.Path)19 ISchedulingRule (org.eclipse.core.runtime.jobs.ISchedulingRule)19 IResource (org.eclipse.core.resources.IResource)18 Status (org.eclipse.core.runtime.Status)14 IOException (java.io.IOException)13 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)13 ArrayList (java.util.ArrayList)12