private GradleProject getContext() { IWorkbench wb = PlatformUI.getWorkbench(); IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); IWorkbenchPage page = win == null ? null : win.getActivePage(); if (page != null) { ISelection selection = page.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; if (!ss.isEmpty()) { Object obj = ss.getFirstElement(); if (obj instanceof IResource) { IResource rsrc = (IResource) obj; IProject prj = rsrc.getProject(); if (prj != null) { return GradleCore.create(prj); } } } } IEditorPart part = page.getActiveEditor(); if (part != null) { IEditorInput input = part.getEditorInput(); IResource rsrc = (IResource) input.getAdapter(IResource.class); if (rsrc != null) { IProject prj = rsrc.getProject(); if (prj != null) { return GradleCore.create(prj); } } } } return null; }
private List<GradleProject> getGradleProjects() { IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); ArrayList<GradleProject> result = new ArrayList<GradleProject>(); for (IProject p : projects) { try { if (p.isAccessible() && p.hasNature(GradleNature.NATURE_ID)) { result.add(GradleCore.create(p)); } } catch (CoreException e) { GradleCore.log(e); } } return result; }
@Override public void rethrowAsCore() throws CoreException { if (hasErrors()) { if (recorded.size() == 1) { throw ExceptionUtil.coreException(recorded.get(0)); } else { StringBuffer msg = new StringBuffer("Multiple problems: \n"); IStatus[] children = new IStatus[recorded.size()]; int i = 0; for (IStatus e : recorded) { if (i < 3) { msg.append(e.getMessage() + "\n"); } else if (i == 3) { msg.append("...more errors..."); } children[i++] = e; } IStatus status = new MultiStatus(GradleCore.PLUGIN_ID, 666, children, msg.toString(), null); throw new CoreException(status); } } else if (recorded.size() > 0) { // no errors but has some recorded stuff. Log this stuff to the error log rather than simply // discarding it. for (IStatus e : recorded) { GradleCore.log(e); } } }
public String getContents() { try { return contents.toString(encoding); } catch (UnsupportedEncodingException e) { GradleCore.log(e); return contents.toString(); // Best effort, use default encoding } }
public static void javaXXeveryone(String version) throws CoreException { // 1: The eclipse workspace default VM should be Java 7 IVMInstall vm = ensureJavaXXdefaultVM(version); // 2: Compiler/source compliance for JDT JavaUtils.setJavaXXCompliance(version); // Compiler/source compliance also Java 7 // 3: Force Gradle JVM default GradleCore.getInstance().getPreferences().setJavaHomeJREName(vm.getName()); }
/* (non-Javadoc) * @see org.eclipse.jface.action.Action#run() */ @Override public void run() { try { owner.requestRefreshTasks(); } catch (CoreException e) { GradleCore.log(e); } }
private boolean haveGradleModel() { try { return project != null && project.getGradleModel() != null; } catch (FastOperationFailedException e) { } catch (CoreException e) { GradleCore.log(e); } return false; }
private void projectComboChanged() { String newProjectName = projectCombo.getText(); if ("".equals(newProjectName)) { setProject(null); } else { IProject newProject = ResourcesPlugin.getWorkspace().getRoot().getProject(newProjectName); setProject(GradleCore.create(newProject)); } }
/** * @return THe set of tasks that is valid. May return null if it is not possible at the moment to * determine task validity (typically, this happens if we don;t have a Gradle project model * ready yet. Callers should be ready to deal with that situation. */ private Set<String> getValidTasks() { try { GradleProject gp = getTreeInput(); if (gp != null) { return gp.getAllTasks(); } } catch (FastOperationFailedException e) { // Ignore: may happen if gradle model not ready } catch (CoreException e) { GradleCore.log(e); } return null; // Couldn't determine what is valid }
public void initializeFrom(ILaunchConfiguration conf) { debug(">>> initializing Gradle launch tab"); try { for (Object attName : conf.getAttributes().keySet()) { debug("" + attName); } } catch (CoreException e) { GradleCore.log(e); } debug("<<< initializing Gradle launch tab"); setProject(GradleLaunchConfigurationDelegate.getProject(conf)); setChecked(GradleLaunchConfigurationDelegate.getTasks(conf)); }
protected boolean shouldConfigureApt(EclipseProject gradleModel) { return AptUtils.isAptEnabled(GradleCore.create(gradleModel).getJavaProject()) || shouldEnableApt(gradleModel); }
@Override protected void noDuplicateHandle(int severity, Throwable e) { GradleCore.log(ExceptionUtil.status(severity, e)); }