From 80134164a4be39153f76223135f3d7c24d4c719e Mon Sep 17 00:00:00 2001 From: Thad House Date: Wed, 18 Jul 2018 22:01:19 -0700 Subject: [PATCH] Move Java main function from library to user code (#1148) It is much more reliable than the old approach, as it no longer depends on a magic string in a manifest file, and if the user changes their main class, or makes it not import from something RobotBase, it will fail to compile instead of failing at runtime. With requiring an importer, we should be able to automate this in the importer. --- myRobot/build.gradle | 3 +- myRobot/src/main/java/Main.java | 22 ++++++++++ .../java/edu/wpi/first/wpilibj/RobotBase.java | 38 +++++----------- .../wpilibj/examples/axiscamera/Main.java | 29 +++++++++++++ .../wpi/first/wpilibj/examples/examples.json | 43 +++++++++++++------ .../first/wpilibj/examples/gearsbot/Main.java | 29 +++++++++++++ .../wpilibj/examples/gettingstarted/Main.java | 29 +++++++++++++ .../wpi/first/wpilibj/examples/gyro/Main.java | 29 +++++++++++++ .../wpilibj/examples/gyromecanum/Main.java | 29 +++++++++++++ .../examples/intermediatevision/Main.java | 29 +++++++++++++ .../wpilibj/examples/mecanumdrive/Main.java | 29 +++++++++++++ .../wpilibj/examples/motorcontrol/Main.java | 29 +++++++++++++ .../examples/motorcontrolencoder/Main.java | 29 +++++++++++++ .../first/wpilibj/examples/pacgoat/Main.java | 29 +++++++++++++ .../examples/potentiometerpid/Main.java | 29 +++++++++++++ .../wpilibj/examples/quickvision/Main.java | 29 +++++++++++++ .../wpilibj/examples/quickvision/Robot.java | 1 - .../wpilibj/examples/tankdrive/Main.java | 29 +++++++++++++ .../wpilibj/examples/ultrasonic/Main.java | 29 +++++++++++++ .../wpilibj/examples/ultrasonicpid/Main.java | 29 +++++++++++++ .../wpilibj/templates/commandbased/Main.java | 29 +++++++++++++ .../wpilibj/templates/iterative/Main.java | 29 +++++++++++++ .../first/wpilibj/templates/sample/Main.java | 29 +++++++++++++ .../first/wpilibj/templates/templates.json | 12 ++++-- .../first/wpilibj/templates/timed/Main.java | 29 +++++++++++++ 25 files changed, 621 insertions(+), 49 deletions(-) create mode 100644 myRobot/src/main/java/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/axiscamera/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gettingstarted/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyro/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyromecanum/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/intermediatevision/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdrive/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrol/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/potentiometerpid/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/quickvision/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrive/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonic/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonicpid/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/iterative/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/sample/Main.java create mode 100644 wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/timed/Main.java diff --git a/myRobot/build.gradle b/myRobot/build.gradle index 55bb577ed0..480bf323f1 100644 --- a/myRobot/build.gradle +++ b/myRobot/build.gradle @@ -20,7 +20,7 @@ ext { apply from: "${rootDir}/shared/opencv.gradle" -mainClassName = 'edu.wpi.first.wpilibj.RobotBase' +mainClassName = 'Main' apply plugin: 'com.github.johnrengelman.shadow' @@ -112,7 +112,6 @@ model { run.systemProperty 'java.library.path', filePath run.environment 'LD_LIBRARY_PATH', filePath run.workingDir filePath - run.args << 'MyRobot' found = true } diff --git a/myRobot/src/main/java/Main.java b/myRobot/src/main/java/Main.java new file mode 100644 index 0000000000..aee472a208 --- /dev/null +++ b/myRobot/src/main/java/Main.java @@ -0,0 +1,22 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +import edu.wpi.first.wpilibj.RobotBase; + +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(MyRobot::new); + } +} diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java index f9afc8b1c1..0655f88877 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java @@ -10,10 +10,8 @@ package edu.wpi.first.wpilibj; import java.io.File; import java.io.IOException; import java.io.OutputStream; -import java.net.URL; import java.nio.file.Files; -import java.util.Enumeration; -import java.util.jar.Manifest; +import java.util.function.Supplier; import edu.wpi.cscore.CameraServerJNI; import edu.wpi.first.networktables.NetworkTableInstance; @@ -200,7 +198,7 @@ public abstract class RobotBase implements AutoCloseable { */ @SuppressWarnings({"PMD.AvoidInstantiatingObjectsInLoops", "PMD.AvoidCatchingThrowable", "PMD.CyclomaticComplexity", "PMD.NPathComplexity"}) - public static void main(String... args) { + public static void startRobot(Supplier robotSupplier) { if (!HAL.initialize(500, 0)) { throw new IllegalStateException("Failed to initialize. Terminating"); } @@ -211,39 +209,23 @@ public abstract class RobotBase implements AutoCloseable { HAL.report(tResourceType.kResourceType_Language, tInstances.kLanguage_Java); - String robotName = ""; - if (args.length > 0) { - robotName = args[0]; - } else { - Enumeration resources = null; - try { - resources = Thread.currentThread() - .getContextClassLoader().getResources("META-INF/MANIFEST.MF"); - } catch (IOException ex) { - ex.printStackTrace(); - } - while (resources != null && resources.hasMoreElements()) { - try { - Manifest manifest = new Manifest(resources.nextElement().openStream()); - robotName = manifest.getMainAttributes().getValue("Robot-Class"); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - } - System.out.println("********** Robot program starting **********"); - RobotBase robot; + T robot; try { - robot = (RobotBase) Class.forName(robotName).newInstance(); + robot = robotSupplier.get(); } catch (Throwable throwable) { Throwable cause = throwable.getCause(); if (cause != null) { throwable = cause; } + String robotName = "Unknown"; + StackTraceElement[] elements = throwable.getStackTrace(); + if (elements.length > 0) { + robotName = elements[0].getClassName(); + } DriverStation.reportError("Unhandled exception instantiating robot " + robotName + " " - + throwable.toString(), throwable.getStackTrace()); + + throwable.toString(), elements); DriverStation.reportWarning("Robots should not quit, but yours did!", false); DriverStation.reportError("Could not instantiate robot " + robotName + "!", false); System.exit(1); diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/axiscamera/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/axiscamera/Main.java new file mode 100644 index 0000000000..1c21a4acaa --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/axiscamera/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.examples.axiscamera; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json index 51e44b2c21..eb2a26ed93 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/examples.json @@ -6,7 +6,8 @@ "Getting Started with Java" ], "foldername": "gettingstarted", - "gradlebase": "java" + "gradlebase": "java", + "mainclass": "Main" }, { "name": "Tank Drive", @@ -18,7 +19,8 @@ "Safety" ], "foldername": "tankdrive", - "gradlebase": "java" + "gradlebase": "java", + "mainclass": "Main" }, { "name": "Mecanum Drive", @@ -30,7 +32,8 @@ "Safety" ], "foldername": "mecanumdrive", - "gradlebase": "java" + "gradlebase": "java", + "mainclass": "Main" }, { "name": "Ultrasonic", @@ -41,7 +44,8 @@ "Analog" ], "foldername": "ultrasonic", - "gradlebase": "java" + "gradlebase": "java", + "mainclass": "Main" }, { "name": "Ultrasonic PID", @@ -52,7 +56,8 @@ "Analog" ], "foldername": "ultrasonicpid", - "gradlebase": "java" + "gradlebase": "java", + "mainclass": "Main" }, { "name": "Potentiometer PID", @@ -64,7 +69,8 @@ "Joystick" ], "foldername": "potentiometerpid", - "gradlebase": "java" + "gradlebase": "java", + "mainclass": "Main" }, { "name": "Gyro", @@ -76,7 +82,8 @@ "Joystick" ], "foldername": "gyro", - "gradlebase": "java" + "gradlebase": "java", + "mainclass": "Main" }, { "name": "Gyro Mecanum", @@ -88,7 +95,8 @@ "Joystick" ], "foldername": "gyromecanum", - "gradlebase": "java" + "gradlebase": "java", + "mainclass": "Main" }, { "name": "Motor Controller", @@ -99,7 +107,8 @@ "Robot and Motor" ], "foldername": "motorcontrol", - "gradlebase": "java" + "gradlebase": "java", + "mainclass": "Main" }, { "name": "Motor Control With Encoder", @@ -114,6 +123,7 @@ ], "foldername": "motorcontrolencoder", "gradlebase": "java" + ,"mainclass": "Main" }, { "name": "GearsBot", @@ -122,7 +132,8 @@ "Complete Robot" ], "foldername": "gearsbot", - "gradlebase": "java" + "gradlebase": "java", + "mainclass": "Main" }, { "name": "PacGoat", @@ -131,7 +142,8 @@ "Complete Robot" ], "foldername": "pacgoat", - "gradlebase": "java" + "gradlebase": "java", + "mainclass": "Main" }, { "name": "Simple Vision", @@ -141,7 +153,8 @@ "Complete List" ], "foldername": "quickvision", - "gradlebase": "java" + "gradlebase": "java", + "mainclass": "Main" }, { "name": "Intermediate Vision", @@ -151,7 +164,8 @@ "Complete List" ], "foldername": "intermediatevision", - "gradlebase": "java" + "gradlebase": "java", + "mainclass": "Main" }, { "name": "Axis Camera Sample", @@ -160,6 +174,7 @@ "Vision" ], "foldername": "axiscamera", - "gradlebase": "java" + "gradlebase": "java", + "mainclass": "Main" } ] diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/Main.java new file mode 100644 index 0000000000..02a1475734 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gearsbot/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.examples.gearsbot; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gettingstarted/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gettingstarted/Main.java new file mode 100644 index 0000000000..282f922120 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gettingstarted/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.examples.gettingstarted; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyro/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyro/Main.java new file mode 100644 index 0000000000..4c5574e2a9 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyro/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.examples.gyro; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyromecanum/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyromecanum/Main.java new file mode 100644 index 0000000000..63300b6537 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/gyromecanum/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.examples.gyromecanum; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/intermediatevision/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/intermediatevision/Main.java new file mode 100644 index 0000000000..a0210b445b --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/intermediatevision/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.examples.intermediatevision; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdrive/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdrive/Main.java new file mode 100644 index 0000000000..4a8f2e1714 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/mecanumdrive/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.examples.mecanumdrive; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrol/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrol/Main.java new file mode 100644 index 0000000000..f817e8f50a --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrol/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.examples.motorcontrol; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Main.java new file mode 100644 index 0000000000..5b03eeded4 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/motorcontrolencoder/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.examples.motorcontrolencoder; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/Main.java new file mode 100644 index 0000000000..04a26be3a5 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/pacgoat/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.examples.pacgoat; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/potentiometerpid/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/potentiometerpid/Main.java new file mode 100644 index 0000000000..72b945400b --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/potentiometerpid/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.examples.potentiometerpid; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/quickvision/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/quickvision/Main.java new file mode 100644 index 0000000000..be7edc6102 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/quickvision/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.examples.quickvision; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/quickvision/Robot.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/quickvision/Robot.java index d9f2ac562a..5b74800399 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/quickvision/Robot.java +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/quickvision/Robot.java @@ -21,5 +21,4 @@ public class Robot extends IterativeRobot { public void robotInit() { CameraServer.getInstance().startAutomaticCapture(); } - } diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrive/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrive/Main.java new file mode 100644 index 0000000000..e1dc017317 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/tankdrive/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.examples.tankdrive; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonic/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonic/Main.java new file mode 100644 index 0000000000..edf56f8fdb --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonic/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.examples.ultrasonic; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonicpid/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonicpid/Main.java new file mode 100644 index 0000000000..b8bffc77fe --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples/ultrasonicpid/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.examples.ultrasonicpid; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/Main.java new file mode 100644 index 0000000000..84ddea4677 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/commandbased/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.templates.commandbased; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/iterative/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/iterative/Main.java new file mode 100644 index 0000000000..d7f6e265b2 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/iterative/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.templates.iterative; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/sample/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/sample/Main.java new file mode 100644 index 0000000000..787aff0a6f --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/sample/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.templates.sample; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +} diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json index 5db1283335..138971357b 100644 --- a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/templates.json @@ -6,7 +6,8 @@ "Iterative" ], "foldername": "iterative", - "gradlebase": "java" + "gradlebase": "java", + "mainclass": "Main" }, { "name": "Timed Robot", @@ -15,7 +16,8 @@ "Timed" ], "foldername": "timed", - "gradlebase": "java" + "gradlebase": "java", + "mainclass": "Main" }, { "name": "Command Robot", @@ -24,7 +26,8 @@ "Command" ], "foldername": "commandbased", - "gradlebase": "java" + "gradlebase": "java", + "mainclass": "Main" }, { "name": "Sample Robot", @@ -33,6 +36,7 @@ "Sample" ], "foldername": "sample", - "gradlebase": "java" + "gradlebase": "java", + "mainclass": "Main" } ] diff --git a/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/timed/Main.java b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/timed/Main.java new file mode 100644 index 0000000000..4cc64e03c6 --- /dev/null +++ b/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/templates/timed/Main.java @@ -0,0 +1,29 @@ +/*----------------------------------------------------------------------------*/ +/* Copyright (c) 2018 FIRST. All Rights Reserved. */ +/* Open Source Software - may be modified and shared by FRC teams. The code */ +/* must be accompanied by the FIRST BSD license file in the root directory of */ +/* the project. */ +/*----------------------------------------------------------------------------*/ + +package edu.wpi.first.wpilibj.templates.timed; + +import edu.wpi.first.wpilibj.RobotBase; + +/** + * Do NOT add any static variables to this class, or any initialization at all. + * Unless you know what you are doing, do not modify this file except to + * change the parameter class to the startRobot call. + */ +public final class Main { + private Main() { + } + + /** + * Main initialization function. Do not perform any initialization here. + * + *

If you change your main robot class, change the parameter type. + */ + public static void main(String... args) { + RobotBase.startRobot(Robot::new); + } +}