Java Code Examples for org.eclipse.core.runtime.CoreException#printStackTrace()

The following examples show how to use org.eclipse.core.runtime.CoreException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BazelProjectSupport.java    From eclipse with Apache License 2.0 6 votes vote down vote up
private static IProject createBaseProject(String projectName, URI location) {
  IProject newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);

  if (!newProject.exists()) {
    URI projectLocation = location;
    IProjectDescription desc =
        newProject.getWorkspace().newProjectDescription(newProject.getName());
    if (location != null
        && ResourcesPlugin.getWorkspace().getRoot().getLocationURI().equals(location)) {
      projectLocation = null;
    }

    desc.setLocationURI(projectLocation);
    try {
      newProject.create(desc, null);
      if (!newProject.isOpen()) {
        newProject.open(null);
      }
    } catch (CoreException e) {
      e.printStackTrace();
    }
  }

  return newProject;
}
 
Example 2
Source File: WebUtils.java    From developer-studio with Apache License 2.0 6 votes vote down vote up
public static boolean isDynamicWebProject(IProject containerProject) {
	boolean isWebProject = false;
	try {
		if (containerProject.isOpen()) {
			for (String natureId : containerProject.getDescription().getNatureIds()) {
				isWebProject = natureId.startsWith("org.eclipse.wst");
				if (isWebProject) {
					break;
				}
			}
		}
	} catch (CoreException e) {
		e.printStackTrace();
	}
	return isWebProject;
}
 
Example 3
Source File: SyncGraphvizExportHandler.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean visit(final IResourceDelta delta) {
	IResource resource = delta.getResource();
	if (resource.getType() == IResource.FILE
			&& ((IFile) resource).getName().endsWith(EXTENSION)) {
		try {
			IWorkspace workspace = ResourcesPlugin.getWorkspace();
			if (!workspace.isTreeLocked()) {
				IFile file = (IFile) resource;
				workspace.run(new DotExportRunnable(file), null);
			}
		} catch (CoreException e) {
			e.printStackTrace();
		}
	}
	return true;
}
 
Example 4
Source File: PluginTest.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Import cpp project into workspace, and setup SWTBot.
 */
@BeforeClass
public static void setup() {

    bot = new SWTWorkbenchBot();

    Path file = null;
    try {
        file = Utils.loadFileFromBundle("org.codechecker.eclipse.rcp.it.tests", Utils.RES + CPP_PROJ);
    } catch (URISyntaxException | IOException e) {
        e.printStackTrace();
    }

    Utils.copyFolder(file,
            Paths.get(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString() + File.separator));

    File project = new File(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString() + File.separator
            + CPP_PROJ + File.separator + ".project");
    try {
        ProjectImporter.importProject(project.toPath(), CPP_PROJ);
    } catch (CoreException e1) {
        e1.printStackTrace();
    }
}
 
Example 5
Source File: TypeScriptSourceMapLanguageSupport.java    From typescript.java with MIT License 6 votes vote down vote up
@Override
public IPath getSourceMapFile(IPath tsFilePath) {
	// Search js file in the same folder than ts file.
	IPath jsMapFilePath = tsFilePath.removeFileExtension().addFileExtension("js.map");
	IFile jsMapFile = WorkbenchResourceUtil.findFileFromWorkspace(jsMapFilePath);
	if (jsMapFile != null) {
		return jsMapFilePath;
	}
	// Search js file in the well folder by using tsconfig.json
	IFile tsFile = WorkbenchResourceUtil.findFileFromWorkspace(tsFilePath);
	try {
		IDETsconfigJson tsconfig = TypeScriptResourceUtil.findTsconfig(tsFile);
		if (tsconfig != null) {
			IContainer configOutDir = tsconfig.getOutDir();
			if (configOutDir != null && configOutDir.exists()) {
				IPath tsFileNamePath = WorkbenchResourceUtil.getRelativePath(tsFile, configOutDir)
						.removeFileExtension();
				return tsFileNamePath.addFileExtension("js");
			}
		}
	} catch (CoreException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 6
Source File: WorkspaceTreeContentProvider.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public Object[] getElements(Object inputElement) {
	try {
		if (inputElement instanceof IContainer) {
			return filterForContent(((IContainer) inputElement).members());
		}
		if (inputElement instanceof Object[]) {
			return filterForContent((Object[]) inputElement);
		}
		if (inputElement instanceof Collection) {
			return filterForContent(((Collection) inputElement).toArray());
		}
	} catch (CoreException e) {
		e.printStackTrace();
	}
	return new Object[0];
}
 
Example 7
Source File: DiagramPartitioningBreadcrumbViewer.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
protected Set<IFile> getProjectStatechartInput(Diagram diagram) {
	final IFile file = WorkspaceSynchronizer.getFile(diagram.eResource());
	final IProject project = file.getProject();
	final Set<IFile> result = new HashSet<IFile>();
	try {
		project.accept(new IResourceVisitor() {
			public boolean visit(IResource resource) throws CoreException {
				// TODO check for package explorer filters here
				if (resource.isHidden()) {
					return false;
				}
				if (resource instanceof IFile) {
					if (file.getFileExtension().equals(resource.getFileExtension()))
						result.add((IFile) resource);
				}
				return true;
			}
		});
	} catch (CoreException e) {
		e.printStackTrace();
	}
	return result;
}
 
Example 8
Source File: XMLPersistenceProviderTester.java    From ice with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This operation cleans up after the test and removes the project space.
 */
@AfterClass
static public void teardown() {

	// Delete the projects.
	try {
		project.delete(true, null);
		otherProject.delete(true, null);
	} catch (CoreException e) {
		// Complain
		e.printStackTrace();
	}

	// Stop the provider
	xmlpp.stop();

	return;
}
 
Example 9
Source File: WordsFA.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 输出字数统计结果到结果窗体中
 * @param WordsFAResultMap
 */
public void printWordsFAReslut() {
	String htmlPath = createFAResultHtml();
	try {
		model.getAnalysisIFileList().get(0).getProject().getFolder("Intermediate").getFolder("Report").refreshLocal(IResource.DEPTH_INFINITE, null);
	} catch (CoreException e1) {
		e1.printStackTrace();
	}
	
	final FileEditorInput input = new FileEditorInput(ResourceUtils.fileToIFile(htmlPath));
	if (PlatformUI.getWorkbench().isClosing()) {
		return;
	}
	
	Display.getDefault().asyncExec(new Runnable() {
		public void run() {
			try {
				PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, QAConstant.FA_HtmlBrowserEditor, true);
			} catch (PartInitException e) {
				logger.error(Messages.getString("qa.fileAnalysis.WordsFA.log5"), e);
				e.printStackTrace();
			}
		}
	});
}
 
Example 10
Source File: WordsFA.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 输出字数统计结果到结果窗体中
 * @param WordsFAResultMap
 */
public void printWordsFAReslut() {
	String htmlPath = createFAResultHtml();
	try {
		model.getAnalysisIFileList().get(0).getProject().getFolder("Intermediate").getFolder("Report").refreshLocal(IResource.DEPTH_INFINITE, null);
	} catch (CoreException e1) {
		e1.printStackTrace();
	}
	
	final FileEditorInput input = new FileEditorInput(ResourceUtils.fileToIFile(htmlPath));
	Display.getDefault().asyncExec(new Runnable() {
		public void run() {
			try {
				PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(input, QAConstant.FA_HtmlBrowserEditor, true);
			} catch (PartInitException e) {
				logger.error(Messages.getString("qa.fileAnalysis.WordsFA.log5"), e);
				e.printStackTrace();
			}
		}
	});
}
 
Example 11
Source File: DotnetTestDelegate.java    From aCute with Eclipse Public License 2.0 5 votes vote down vote up
private ILaunchConfiguration getLaunchConfiguration(String mode, IResource resource) {
	ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
	ILaunchConfigurationType configType = launchManager
			.getLaunchConfigurationType("org.eclipse.acute.dotnettest.DotnetTestDelegate"); //$NON-NLS-1$
	try {
		ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(configType);

		String configName;
		if (resource.getLocation().toFile().isFile()) {
			configName = NLS.bind(Messages.DotnetTestDelegate_configuration, resource.getParent().getName() + "." + resource.getName()); //$NON-NLS-1$
		} else {
			configName = NLS.bind(Messages.DotnetTestDelegate_configuration, resource.getName());
		}

		for (ILaunchConfiguration iLaunchConfiguration : launchConfigurations) {
			if (iLaunchConfiguration.getName().equals(configName)
					&& iLaunchConfiguration.getModes().contains(mode)) {
				return iLaunchConfiguration;
			}
		}
		configName = launchManager.generateLaunchConfigurationName(configName);
		ILaunchConfigurationWorkingCopy wc = configType.newInstance(null, configName);
		if (resource.getLocation().toFile().isFile()) {
			if (resource.getFileExtension().equals("cs")) { //$NON-NLS-1$
				wc.setAttribute(TEST_SELECTION_TYPE, SELECTED_TEST);
				wc.setAttribute(TEST_CLASS, resource.getName().replaceFirst("\\.cs$", "")); //$NON-NLS-1$ //$NON-NLS-2$
			}
			resource = resource.getParent();
		}
		wc.setAttribute(DebugPlugin.ATTR_WORKING_DIRECTORY, resource.getLocation().toString());

		return wc;
	} catch (CoreException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 12
Source File: VibeLauncherTester.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Clean up after ourselves
 */
@AfterClass
public static void cleanup() {
	try {
		projectSpace.close(null);
		projectSpace.delete(true, null);
	} catch (CoreException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		fail("VIBE Launcher Tester: Error!  Could not clean up project space.");
	}
}
 
Example 13
Source File: SearchWholeWordAction.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(IAction action) {
   	final String pattern = getPattern();
   	if (pattern.isEmpty()) {
   		return;
   	}
       
       try {
       	ISearchQuery query = TextSearchQueryProvider.getPreferred().createQuery(new TextSearchInput() {
			
			@Override
			public boolean isRegExSearch() {
				return true;
			}
			
			@Override
			public boolean isCaseSensitiveSearch() {
				return true;
			}
			
			@Override
			public String getSearchText() {
				return pattern;
			}
			
			@Override
			public FileTextSearchScope getScope() {
				return SearchWholeWordAction.this.getScope(); //$NON-NLS-1$
			}
		});
       	NewSearchUI.runQueryInBackground(query);
	} catch (CoreException e) {
		e.printStackTrace();
	}
       
	return;
}
 
Example 14
Source File: AnalysisTest.java    From CodeCheckerEclipsePlugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Import project - Set nature.
 */
@BeforeClass
public static void setUpBeforeClass() {
    bot = new SWTWorkbenchBot();

    // Import project
    Path file = null;
    try {
        file = Utils.loadFileFromBundle("org.codechecker.eclipse.rcp.it.tests", Utils.RES + CPP_PROJ);
    } catch (URISyntaxException | IOException e) {
        e.printStackTrace();
    }

    Utils.copyFolder(file,
            Paths.get(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString() + File.separator));

    File projectFile = new File(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString() + File.separator
            + CPP_PROJ + File.separator + GuiUtils.DOT_PROJECT);
    try {
        ProjectImporter.importProject(projectFile.toPath(), CPP_PROJ);
    } catch (CoreException e1) {
        e1.printStackTrace();
    }

    // Add CodeChecker Nature.
    project = bot.tree().getTreeItem(CPP_PROJ);
    project.contextMenu(GuiUtils.ADD_NATURE_MENU).click();
}
 
Example 15
Source File: VibeLauncherBuilderTester.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <p>
 * A utility operation that sets up the IProject space for the tests. It
 * creates a CaebatTesterWorkspace for the launcher to be built in.
 * </p>
 */
private void setupIProject() {
	URI defaultProjectLocation = null;
	String separator = System.getProperty("file.separator");

	try {
		// Get the project handle
		IProject project = projectSpace;
		// If the project does not exist, create it
		if (!project.exists()) {
			// Set the location as ${workspace_loc}/ItemTesterWorkspace
			defaultProjectLocation = (new File(
					System.getProperty("user.home") + separator
							+ "ICETests" + separator
							+ "caebatTesterWorkspace")).toURI();
			// Create the project description
			IProjectDescription desc = ResourcesPlugin.getWorkspace()
					.newProjectDescription("caebatTesterWorkspace");
			// Set the location of the project
			desc.setLocationURI(defaultProjectLocation);
			// Create the project
			project.create(desc, null);
		}
		// Open the project if it is not already open
		if (project.exists() && !project.isOpen()) {
			project.open(null);
		}
	} catch (CoreException e) {
		// Catch for creating the project
		e.printStackTrace();
		fail();
	}

}
 
Example 16
Source File: LaunchEvent.java    From scava with Eclipse Public License 2.0 5 votes vote down vote up
public LaunchEvent(ILaunch launch) {
	this.launch = launch;

	ILaunchConfiguration launchConfiguration = launch.getLaunchConfiguration();
	try {
		IResource[] mappedResources = launchConfiguration.getMappedResources();
		for (IResource iResource : mappedResources) {
			launchedFile = iResource.getName();
			launchedProject = iResource.getProject();
		}
	} catch (CoreException e) {
		e.printStackTrace();
	}
}
 
Example 17
Source File: INIWriterTester.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 
 */
@BeforeClass
public static void beforeTests() {

	// Local Declarations
	IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	IProject project = null;
	String separator = System.getProperty("file.separator");
	String userDir = System.getProperty("user.home") + separator
			+ "ICETests" + separator + "ioTesterWorkspace";
	// Enable Debugging
	System.setProperty("DebugICE", "");

	// Setup the project
	try {
		// Get the project handle
		IPath projectPath = new Path(userDir + separator + ".project");
		// Create the project description
		IProjectDescription desc = ResourcesPlugin.getWorkspace()
				.loadProjectDescription(projectPath);
		// Get the project handle and create it
		project = workspaceRoot.getProject(desc.getName());
		// Get the project handle and create it
		project = workspaceRoot.getProject(desc.getName());
		// Create the project if it doesn't exist
		if (!project.exists()) {
			project.create(desc, new NullProgressMonitor());
		}
		// Open the project if it is not already open
		if (project.exists() && !project.isOpen()) {
			project.open(new NullProgressMonitor());
		}
		// Refresh the workspace
		project.refreshLocal(IResource.DEPTH_INFINITE, null);
	} catch (CoreException e) {
		// Catch exception for creating the project
		e.printStackTrace();
		fail();
	}

	// Set the global project reference.
	projectSpace = project;

	return;
}
 
Example 18
Source File: VibeKVPairTester.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * <p>
 * This operation sets up the workspace.
 * </p>
 */
@BeforeClass
public static void beforeTests() {

	// Local Declarations
	IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	IProject project = null;
	String separator = System.getProperty("file.separator");
	String userDir = System.getProperty("user.home") + separator
			+ "ICETests" + separator + "caebatTesterWorkspace";
	// Enable Debugging
	System.setProperty("DebugICE", "");

	// Setup the project
	try {
		// Get the project handle
		IPath projectPath = new Path(userDir + separator + ".project");
		// Create the project description
		IProjectDescription desc = ResourcesPlugin.getWorkspace()
				.loadProjectDescription(projectPath);
		// Get the project handle and create it
		project = workspaceRoot.getProject(desc.getName());
		// Create the project if it doesn't exist
		if (!project.exists()) {
			project.create(desc, new NullProgressMonitor());
		}
		// Open the project if it is not already open
		if (project.exists() && !project.isOpen()) {
			project.open(new NullProgressMonitor());
		}
		// Refresh the workspace
		project.refreshLocal(IResource.DEPTH_INFINITE, null);
	} catch (CoreException e) {
		// Catch exception for creating the project
		e.printStackTrace();
		fail();
	}

	// Set the global project reference.
	projectSpace = project;

	return;
}
 
Example 19
Source File: INIReaderTester.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 
 */
@BeforeClass
public static void beforeTests() {

	// Local Declarations
	IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	IProject project = null;
	String separator = System.getProperty("file.separator");
	String userDir = System.getProperty("user.home") + separator
			+ "ICETests" + separator + "ioTesterWorkspace";
	// Enable Debugging
	System.setProperty("DebugICE", "");

	// Setup the project
	try {
		// Get the project handle
		IPath projectPath = new Path(userDir + separator + ".project");
		// Create the project description
		IProjectDescription desc = ResourcesPlugin.getWorkspace()
		                    .loadProjectDescription(projectPath);
		// Get the project handle and create it
		project = workspaceRoot.getProject(desc.getName());
		// Get the project handle and create it
		project = workspaceRoot.getProject(desc.getName());
		// Create the project if it doesn't exist
		if (!project.exists()) {
			project.create(desc, new NullProgressMonitor());
		}
		// Open the project if it is not already open
		if (project.exists() && !project.isOpen()) {
		   project.open(new NullProgressMonitor());
		}
		// Refresh the workspace
		project.refreshLocal(IResource.DEPTH_INFINITE, null);
	} catch (CoreException e) {
		// Catch exception for creating the project
		e.printStackTrace();
		fail();
	}

	// Set the global project reference.
	projectSpace = project;

	return;
}
 
Example 20
Source File: ICEFormEditor.java    From ice with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * This operation overrides init so that the ICE Form, passed as an
 * IEditorInput, can be stored.
 * 
 * @param site
 *            the site on the workbench where the Form is drawn
 * @param input
 *            the input for this editor
 */
@Override
public void init(IEditorSite site, IEditorInput input)
		throws RuntimeException {

	// Get the E4 Context. This is how you get into the E4 application model
	// if you are running from a 3.x part and don't have your own
	// application model. See bugs.eclipse.org/bugs/show_bug.cgi?id=376486
	// and chapter 101 of Lar Vogel's e4 book.
	e4Context = site.getService(IEclipseContext.class);

	// Instruct the framework to perform dependency injection for
	// this Form using the ContextInjectionFactory.
	ContextInjectionFactory.inject(this, e4Context);

	// Get the Client Reference
	IClient client = null;
	try {
		client = IClient.getClient();
	} catch (CoreException e1) {
		e1.printStackTrace();
	}

	// Set the site
	setSite(site);

	// Grab the form from the input or the client depending on the type of
	// the input. This should only be a temporary switch until we remove the
	// ICEFormInput and redirect the way the client works.
	if (input instanceof ICEFormInput) {
		ICEFormInput = (ICEFormInput) input;
		iceDataForm = ICEFormInput.getForm();

		// Set the part name to be the file name
		setPartName(iceDataForm.getName() + ".xml");

		// Set the input
		setInput(input);
	} else if (input instanceof FileEditorInput && client != null) {
		// Grab the file and load the form
		IFile formFile = ((FileEditorInput) input).getFile();
		// try {
		// IClient client = IClient.getClient();
		iceDataForm = client.loadItem(formFile);
		logger.info("IClient and Form loaded.");
		// Set *correct* input via a little short circuit.
		ICEFormInput = new ICEFormInput(iceDataForm);
		setInput(ICEFormInput);

		// Set the IFormWidget on the IClient
		client.addFormWidget(new EclipseFormWidget(this));

		// Set the part name to be the file name
		setPartName(input.getName());

		// Register the client as a listener
		// of specific form editor events.
		try {
			registerUpdateListener(
					IUpdateEventListener.getUpdateEventListener());
			registerProcessListener(
					IProcessEventListener.getProcessEventListener());
			registerResourceProvider(
					ISimpleResourceProvider.getSimpleResourceProvider());
		} catch (CoreException e) {
			// Complain
			logger.error(
					"Unable to get register the update, process, or simpleresource implementations!",
					e);
		}

	} else {
		// Throw errors if the type is wrong
		logger.error("Unable to load Form Editor!");
		throw new RuntimeException("Input passed to ICEFormEditor.init()"
				+ " is not of type ICEFormInput or FileEditorInput, or the IClient instance is null.");
	}

	// Get the Item Name for the Form Header.
	for (Identifiable i : client.getItems()) {
		if (iceDataForm.getItemID() == i.getId()) {
			itemName = i.getClass().getSimpleName() + " Item " + i.getId();
			break;
		}
	}

	// Register this ICEFormEditor with the provided Form
	iceDataForm.register(this);

	return;
}