mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Some much need love for the eclipse plugins.
Features/bug fixes include: - Paul's progress bar for the installers - Fix to prevent repeatede installation - Right clicking and running Java projects works now - Better logging to help find issues (Window > Show View > Other > Error Log) Change-Id: I2cc791a58752cdeffec27f73880e7afcd1e95771
This commit is contained in:
@@ -10,6 +10,7 @@ import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.jdt.core.JavaCore;
|
||||
import org.eclipse.jdt.core.JavaModelException;
|
||||
import org.eclipse.ui.IStartup;
|
||||
@@ -73,7 +74,7 @@ public class WPILibJavaPlugin extends AbstractUIPlugin implements IStartup {
|
||||
return props.getProperty("version");
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
e.printStackTrace(System.err);
|
||||
WPILibJavaPlugin.logError("Error getting properties.", e);
|
||||
return "DEVELOPMENT";
|
||||
}
|
||||
}
|
||||
@@ -85,7 +86,7 @@ public class WPILibJavaPlugin extends AbstractUIPlugin implements IStartup {
|
||||
File file = new File(WPILibCore.getDefault().getWPILibBaseDir()+"/java/"+getCurrentVersion()+"/ant/build.properties");
|
||||
props = new AntPropertiesParser(new FileInputStream(file)).getProperties(defaults);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
WPILibJavaPlugin.logError("Error getting properties.", e);
|
||||
props = new Properties(defaults);
|
||||
}
|
||||
return props;
|
||||
@@ -102,7 +103,7 @@ public class WPILibJavaPlugin extends AbstractUIPlugin implements IStartup {
|
||||
try {
|
||||
updateVariables(project);
|
||||
} catch (CoreException e) {
|
||||
e.printStackTrace();
|
||||
WPILibJavaPlugin.logError("Error updating projects.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,7 +117,8 @@ public class WPILibJavaPlugin extends AbstractUIPlugin implements IStartup {
|
||||
JavaCore.setClasspathVariable("networktables", new Path(props.getProperty("networktables.jar")), null);
|
||||
JavaCore.setClasspathVariable("networktables.sources", new Path(props.getProperty("networktables.sources")), null);
|
||||
} catch (JavaModelException e) {
|
||||
e.printStackTrace(); // Classpath variables didn't get set
|
||||
// Classpath variables didn't get set
|
||||
WPILibJavaPlugin.logError("Error setting classpath..", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,4 +126,12 @@ public class WPILibJavaPlugin extends AbstractUIPlugin implements IStartup {
|
||||
public void earlyStartup() {
|
||||
new JavaInstaller(getCurrentVersion()).installIfNecessary();
|
||||
}
|
||||
|
||||
public static void logInfo(String msg) {
|
||||
getDefault().getLog().log(new Status(Status.INFO, PLUGIN_ID, Status.OK, msg, null));
|
||||
}
|
||||
|
||||
public static void logError(String msg, Exception e) {
|
||||
getDefault().getLog().log(new Status(Status.ERROR, PLUGIN_ID, Status.OK, msg, e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class JavaInstaller extends AbstractInstaller {
|
||||
protected void updateInstalledVersion(String version) {
|
||||
IPreferenceStore prefs = WPILibJavaPlugin.getDefault().getPreferenceStore();
|
||||
if (prefs.getBoolean(PreferenceConstants.UPDATE_LIBRARY_VERSION)) {
|
||||
System.out.println("Forcing library version to "+version);
|
||||
WPILibJavaPlugin.logInfo("Forcing library version to "+version);
|
||||
Properties props = WPILibCore.getDefault().getProjectProperties(null);
|
||||
props.setProperty("version", version);
|
||||
WPILibCore.getDefault().saveGlobalProperties(props);
|
||||
|
||||
@@ -20,7 +20,6 @@ import org.eclipse.debug.core.model.IStreamMonitor;
|
||||
import org.eclipse.debug.ui.IDebugUIConstants;
|
||||
import org.eclipse.debug.ui.ILaunchShortcut;
|
||||
import org.eclipse.jdt.core.IJavaElement;
|
||||
import org.eclipse.jdt.core.IJavaProject;
|
||||
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
|
||||
import org.eclipse.jdt.launching.IVMConnector;
|
||||
import org.eclipse.jdt.launching.JavaRuntime;
|
||||
@@ -34,6 +33,7 @@ import com.sun.jdi.connect.Connector.Argument;
|
||||
|
||||
import edu.wpi.first.wpilib.plugins.core.WPILibCore;
|
||||
import edu.wpi.first.wpilib.plugins.core.launching.AntLauncher;
|
||||
import edu.wpi.first.wpilib.plugins.java.WPILibJavaPlugin;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public abstract class JavaLaunchShortcut implements ILaunchShortcut {
|
||||
@@ -54,35 +54,36 @@ public abstract class JavaLaunchShortcut implements ILaunchShortcut {
|
||||
public String getLaunchType() {return DEPLOY_TYPE;}
|
||||
|
||||
public void launch(ISelection selection, String mode) {
|
||||
//Extract resource from selection
|
||||
// Extract resource from selection
|
||||
StructuredSelection sel = (StructuredSelection)selection;
|
||||
IProject activeProject = null;
|
||||
//NOTE: This caused issues earlier, as the sel return was treated as a workspace, instead of a project
|
||||
//When it is a valid FIRST project, the selection is always a JavaProject
|
||||
if(sel.getFirstElement() instanceof IJavaProject){
|
||||
activeProject = ((IJavaProject)sel.getFirstElement()).getProject();
|
||||
}else if(sel.getFirstElement() instanceof IJavaElement){
|
||||
// NOTE: This caused issues earlier, as the sel return was treated as a workspace, instead of a project
|
||||
// When it is a valid FIRST project, the selection is always a JavaProject
|
||||
if(sel.getFirstElement() instanceof IProject) {
|
||||
activeProject = ((IProject)sel.getFirstElement()).getProject();
|
||||
} else if(sel.getFirstElement() instanceof IJavaElement) {
|
||||
activeProject = ((IJavaElement)sel.getFirstElement()).getJavaProject().getProject();
|
||||
}else{
|
||||
} else {
|
||||
WPILibJavaPlugin.logError("Selection isn't a project: "+sel.toString(), null);
|
||||
return;
|
||||
}
|
||||
|
||||
//Run config using project found in extracted resource, with indicated mode
|
||||
// Run config using project found in extracted resource, with indicated mode
|
||||
runConfig(activeProject, mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void launch(IEditorPart editor, String mode) {
|
||||
//Extract resource from editor
|
||||
if(editor != null){
|
||||
// Extract resource from editor
|
||||
if (editor != null) {
|
||||
IFileEditorInput input = (IFileEditorInput)editor.getEditorInput();
|
||||
IFile file = input.getFile();
|
||||
IProject activeProject = file.getProject();
|
||||
|
||||
//If editor existed, run config using extracted resource in indicated mode
|
||||
// If editor existed, run config using extracted resource in indicated mode
|
||||
runConfig(activeProject, mode);
|
||||
}else{
|
||||
System.err.println("editor was null");
|
||||
} else {
|
||||
WPILibJavaPlugin.logError("Editor was null.", null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -117,7 +118,7 @@ public abstract class JavaLaunchShortcut implements ILaunchShortcut {
|
||||
}
|
||||
|
||||
if((lastDeploy != null)&&(!lastDeploy.isTerminated())){
|
||||
System.out.println("Last deploy running");
|
||||
WPILibJavaPlugin.logInfo("Last deploy running");
|
||||
//Find the server connection thread and kill it
|
||||
Vector<ThreadGroup> threadGroups = new Vector<ThreadGroup>();
|
||||
ThreadGroup root = Thread.currentThread().getThreadGroup().getParent();
|
||||
@@ -137,18 +138,20 @@ public abstract class JavaLaunchShortcut implements ILaunchShortcut {
|
||||
stopMethod.invoke(current);
|
||||
lastDeploy.terminate();
|
||||
break;
|
||||
}catch(Exception e){e.printStackTrace();}
|
||||
} catch(Exception e) {
|
||||
WPILibJavaPlugin.logError("Error stopping ant", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Waiting");
|
||||
WPILibJavaPlugin.logInfo("Waiting");
|
||||
try{wait(1000);}catch(Exception e){}
|
||||
|
||||
}
|
||||
|
||||
System.out.println("Running ant file: " + activeProj.getLocation().toOSString() + File.separator + "build.xml");
|
||||
System.out.println("Targets: " + targets + ", Mode: " + mode);
|
||||
WPILibJavaPlugin.logInfo("Running ant file: " + activeProj.getLocation().toOSString() + File.separator + "build.xml");
|
||||
WPILibJavaPlugin.logInfo("Targets: " + targets + ", Mode: " + mode);
|
||||
lastDeploy = AntLauncher.runAntFile(new File (activeProj.getLocation().toOSString() + File.separator + "build.xml"), targets, null, mode);
|
||||
|
||||
if((mode.equals(ILaunchManager.DEBUG_MODE))&&(getLaunchType().equals(DEPLOY_TYPE))) {
|
||||
@@ -157,8 +160,7 @@ public abstract class JavaLaunchShortcut implements ILaunchShortcut {
|
||||
config = getRemoteDebugConfig(activeProj);
|
||||
startDebugConfig(config, lastDeploy);
|
||||
} catch (CoreException e) {
|
||||
System.err.println("Debug attach failed.");
|
||||
e.printStackTrace();
|
||||
WPILibJavaPlugin.logError("Debug attach failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +181,7 @@ public abstract class JavaLaunchShortcut implements ILaunchShortcut {
|
||||
Map<String, String> argMap = new HashMap<String, String>(def.size());
|
||||
argMap.put("hostname", getHostname(activeProj));
|
||||
argMap.put("port", "8348");
|
||||
System.out.println(argMap);
|
||||
WPILibJavaPlugin.logInfo(argMap.toString());
|
||||
config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CONNECT_MAP, argMap);
|
||||
return config;
|
||||
}
|
||||
@@ -196,8 +198,7 @@ public abstract class JavaLaunchShortcut implements ILaunchShortcut {
|
||||
try {
|
||||
config.launch(ILaunchManager.DEBUG_MODE, null);
|
||||
} catch (CoreException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
WPILibJavaPlugin.logError("Error starting debug config..", e);
|
||||
}
|
||||
monitor.removeListener(this);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class JavaPreferencePage
|
||||
* @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
|
||||
*/
|
||||
public void init(IWorkbench workbench) {
|
||||
System.out.println("Preferences initialized.");
|
||||
WPILibJavaPlugin.logInfo("Preferences initialized.");
|
||||
Properties props = WPILibCore.getDefault().getProjectProperties(null);
|
||||
getPreferenceStore().setValue(PreferenceConstants.LIBRARY_VERSION,
|
||||
props.getProperty("version", WPILibJavaPlugin.getDefault().getCurrentVersion()));
|
||||
@@ -93,4 +93,4 @@ public class JavaPreferencePage
|
||||
WPILibJavaPlugin.getDefault().updateProjects();
|
||||
return super.performOk();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ public class FileTemplateWizard extends Wizard implements INewWizard {
|
||||
final IProject project = page.getProject();
|
||||
final String className = page.getClassName();
|
||||
final String packageName = page.getPackage();
|
||||
System.out.println("Class: "+className+" Package: "+packageName);
|
||||
WPILibJavaPlugin.logInfo("Class: "+className+" Package: "+packageName);
|
||||
IRunnableWithProgress op = new IRunnableWithProgress() {
|
||||
public void run(IProgressMonitor monitor) throws InvocationTargetException {
|
||||
try {
|
||||
@@ -99,8 +99,7 @@ public class FileTemplateWizard extends Wizard implements INewWizard {
|
||||
URL url = new URL(WPILibJavaPlugin.getDefault().getBundle().getEntry("/resources/templates/"), source);
|
||||
ProjectCreationUtils.createTemplateFile(project, filepath, url, map);
|
||||
} catch (MalformedURLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
WPILibJavaPlugin.logError("Error finishing making file: "+className, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,9 +110,9 @@ public class FileTemplateWizard extends Wizard implements INewWizard {
|
||||
*/
|
||||
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
||||
this.selection = selection;
|
||||
System.out.println(selection);
|
||||
WPILibJavaPlugin.logInfo(selection.toString());
|
||||
Object element = ((StructuredSelection) selection).getFirstElement();
|
||||
if (element != null) System.out.println(element.getClass());
|
||||
if (element != null) WPILibJavaPlugin.logInfo(element.getClass().toString());
|
||||
if (element instanceof IResource) {
|
||||
project = ((IResource) element).getProject();
|
||||
} else if (element instanceof IPackageFragment) {
|
||||
@@ -122,6 +121,6 @@ public class FileTemplateWizard extends Wizard implements INewWizard {
|
||||
project = ((IPackageFragmentRoot) element).getJavaProject().getProject();
|
||||
} else if (element instanceof ICompilationUnit) {
|
||||
project = ((ICompilationUnit) element).getJavaProject().getProject();
|
||||
} else System.out.println("Element not instance of IResource");
|
||||
} else WPILibJavaPlugin.logInfo("Element not instance of IResource");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.eclipse.swt.widgets.Text;
|
||||
import edu.wpi.first.wpilib.plugins.core.nature.FRCProjectNature;
|
||||
import edu.wpi.first.wpilib.plugins.core.wizards.IProjectFilter;
|
||||
import edu.wpi.first.wpilib.plugins.core.wizards.ProjectComboField;
|
||||
import edu.wpi.first.wpilib.plugins.java.WPILibJavaPlugin;
|
||||
|
||||
/**
|
||||
* The "New" wizard page allows setting the container for the new file as well
|
||||
@@ -68,7 +69,7 @@ public class FileTemplateWizardMainPage extends WizardPage {
|
||||
return project.hasNature(FRCProjectNature.FRC_PROJECT_NATURE)
|
||||
&& project.hasNature(JavaCore.NATURE_ID);
|
||||
} catch (CoreException e) {
|
||||
e.printStackTrace();
|
||||
WPILibJavaPlugin.logError("Error looking for FRCJava project.", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -177,7 +178,7 @@ public class FileTemplateWizardMainPage extends WizardPage {
|
||||
}
|
||||
|
||||
public String getDefaultPackage() {
|
||||
System.out.println("Project: "+project);
|
||||
WPILibJavaPlugin.logInfo("Project: "+project);
|
||||
String defaultPackage = null;
|
||||
if (project != null) {
|
||||
try {
|
||||
@@ -193,11 +194,10 @@ public class FileTemplateWizardMainPage extends WizardPage {
|
||||
}
|
||||
if (defaultPackage == null) defaultPackage = backupPackage;
|
||||
} catch (JavaModelException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
WPILibJavaPlugin.logError("Error getting default package.", e);
|
||||
}
|
||||
}
|
||||
if (defaultPackage != null) return defaultPackage;
|
||||
else return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import edu.wpi.first.wpilib.plugins.core.wizards.NewProjectMainPage;
|
||||
import edu.wpi.first.wpilib.plugins.core.wizards.ProjectCreationUtils;
|
||||
import edu.wpi.first.wpilib.plugins.core.wizards.ProjectType;
|
||||
import edu.wpi.first.wpilib.plugins.core.wizards.TeamNumberPage;
|
||||
import edu.wpi.first.wpilib.plugins.java.WPILibJavaPlugin;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -73,7 +74,7 @@ public class NewJavaWizard extends Wizard implements INewWizard {
|
||||
final String packageName = page.getPackage();
|
||||
final ProjectType projectType = page.getProjectType();
|
||||
final String worldName = page.getWorld();
|
||||
System.out.println("Project: "+projectName+" Package: "+packageName+" Project Type: "+projectType);
|
||||
WPILibJavaPlugin.logInfo("Project: "+projectName+" Package: "+packageName+" Project Type: "+projectType);
|
||||
IRunnableWithProgress op = new IRunnableWithProgress() {
|
||||
public void run(IProgressMonitor monitor) throws InvocationTargetException {
|
||||
try {
|
||||
@@ -118,4 +119,4 @@ public class NewJavaWizard extends Wizard implements INewWizard {
|
||||
public void init(IWorkbench workbench, IStructuredSelection selection) {
|
||||
this.selection = selection;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user