FRC using VS Code and Eclipse together for WPILIb programming

I’ve tried using VS Code. I enjoy uisng it for things like JavaScript, Python and Markdown. With Java, I feel like I’m hitting my head against the wall. I’m too used to a “full powered IDE” so an editor makes me aware of what I rely on. (I tried IntelliJ as well and that felt productive easily.)

The nice thing is that 2019 FRC projects are “just” gradle projects. So there is no reason I can’t use both VS Code and Eclipse together! VS Code for creation a new project and deploying. Eclipse for virtually everything else.

Creating a project from VS Code

Just like when I was first trying VS Code, creating a WPILib project is easy. Just like the screensteps say!

  1. Click “W” icon in top right
  2. Choose template for a new project
  3. Choose Java
  4. Choose command based project (or whatever you prefer)
  5. Enter directory – this can be the same directory for all projects since they each get their own folder.
  6. Enter project name
  7. Enter team number
  8. Click generate project

Importing the Project in Eclipse

Since the project is just a Gradle project, you can import it into Eclipse

  • File > Import
  • Existing Gradle Project
  • Enter the root directory that the project is in. For example suppose your directory was “frc” and project name was “NewRobotProject”. Then the root directory would be “…/git/frc/NewRobotProject”. In other words, the directory with your build.gradle file.
  • Click Finish
  • Wait a minute or two. The bottom right will say “Synching Gradle project workspace”. It will show the percentage as the import occurs.

Editing in Multiple IDEs/Editors

At this point, you have a normal Eclipse project.   All the features and keyboard shortcuts from Eclipse are there. For example, open a command and click on the super class name (Command.) Press F3 and it takes you right to the source code. Eclipse knows where it is because Gradle told it.

If you edit in multiple tools, you just need to know how to refresh from disk in each one.

In Eclipse, right click the project and choose refresh. (Or click F5)

In VS Code,mouse over the project name and choose the circle refresh arrow.

Deploying the Project from VS Code

Since the VS Code and Eclipse projects are pointing at the same directory, you only have one project. This means you can simply:

  1. Click “W” icon in top right
  2. Choose “Deploy Robot Code” from the menu

 

getting started with gitlab

CodeRanch is talking about moving to Git for our source code. Some of the moderators expressed a preference for GitLab. I’ve used GitHub, but not GitLab so decided to try it out with one of my personal projects. Looking at it, GitLab has built in CI so I want to see if i can switch to that and get off Jenkins for my pet project.

Signing up for GitLab

You can register with a new account for GitLab or use your credentials for other services including Google, Twitter, GitHub and BitBucket. It feels weird to me to sign in for a version control system with the credentials for another version control system so I created a new account.

While signing up, it automatically imported my gravatar. I had an old picture on there so fixed that. I then added some basic information to my GitLab profile

I set up an SSH key to make it easy to commit from my home computer:

  1. Settings
  2. SSH Keys
  3. Paste in key

I also set up two factor:

  1. Settings
  2. Account
  3. The very first option is “Enable two factor authentication”
  4. It uses Google Authenticator which is my first choice of two factor. They also supply backup codes.

Migrating a repository from GitHub

GitLab has a page about migrating from GitHub. The most important pre-requisite is to make sure each committer to the GitHub project has an account on GitLab. Conveniently, I am the only person who has ever committed to this project!

I then migrated in:

  1. Create a personal access token on GitHub just for this migration
  2. Click “Create a project”
  3. Choose “Import a project” tab
  4. Enter personal access token for github and choose “List your repositories”. Note that this lists both your personal repositories and all of these for GitHub organizations you have access to
  5. Click “Import” on the row next to the repository to migrate. (There’s also an “Import all” on top. I’m not looking to migrate all my repositories though!). Nothing appeared to happen for a minute. I must have missed a status warning. But then the page refreshed and had a “done” checkbox.
  6. Delete the personal access token from GitHub. I don’t like to leave extra access laying around enabled

I confirmed the same number of commits (including the latest), branches and tags are all there.

Jenkins integration

I’ve been running this job on Jenkins each night to check for changes. Since this is a public repository, accessing it for polling is easy and worked on the first shot. While I’d like to switch to GitLab CI, I’m going with incremental progress. GitLab has a good page on interacting with Jenkins.

I temporarily made this a private project to re-test. I confirmed that I could commit and that Jenkins failed to pull. Then I tried to set up Jenkins to be able to interact with project.

When using my own account, I can set up a token with read access to all my projects, but not a specific one. I think I’d have to create an extra account on GitLab for Jenkins if I wanted it to have only access to specific projects. Since this is just an experiment, I’ll use my own token for now.

Failing with the GitLab plugin

  1. Installed the GitLab plugin on Jenkins
  2. In GitLab, went to Settings > Access Tokens
  3. Created a token with read_repository permissions
  4. In Jenkins, manage > Configure System
  5. Add a GitLab Connection. I like that it uses Jenkins Credentials for securing the token
  6. Click “Test Connection”
  7. Using https://gitlab.com/boyarsky gives Client error: HTTP 401 Unauthorized
  8. Using https://gitlab.com/ gives Client error: HTTP 403 Forbidden

I noticed that the Jenkins GitLab plugin is not well supported. The primary committer wrote that he doesn’t use GitLab daily anymore and this affects his time spent on this project.

At this point, I gave up and just set up polling. I created a credential with the username boyarsky and the password as my personal access token. (That I set up while attempting to get GitLab working.) This worked on the first shot.

Now time to start looking at GitLab Ci…