Slide 1

Slide 1 text

Intro to
 Java Development ! Part 1 Summer 2014

Slide 2

Slide 2 text

Working with code

Slide 3

Slide 3 text

Source code • Text files that developers read and write to tell the program what to do • The programming language dictates - the structure and format of the “code” - whether the files are compiled or interpreted

Slide 4

Slide 4 text

Sample source file (portion of one Java source file)

Slide 5

Slide 5 text

Compiling Java code .java compile build source code 01101 10101 01101 10101 01101 10101 01101 10101 01101 10101 01101 10101 01101 10101 01101 10101 .class bytecode .jar archive

Slide 6

Slide 6 text

Compiling Java code .java compile build .jar source code 01101 10101 01101 10101 01101 10101 01101 10101 01101 10101 01101 10101 01101 10101 01101 10101 .class bytecode .jar archive dependencies

Slide 7

Slide 7 text

Running Java code .jar run .jar archive dependencies Java Runtime Environment (JRE) all .jar files

Slide 8

Slide 8 text

Deploying Java code to robot .jar deploy .jar archive dependencies Java Runtime Environment (JRE) all .jar files cRIO or roboRIO requires your computer being connected to the robot’s network

Slide 9

Slide 9 text

Our environment We’ve carefully set up our tools and our source code to make this easier

Slide 10

Slide 10 text

Compiling and deploying robot code .java compile source code .class bytecode .jar archive .jar dependencies build deploy JRE all .jar files cRIO or roboRIO $ ant compile $ ant jar $ ant deploy $ ant deploy run or ‘deploy’ and ‘run’ require your computer being connected to the robot’s network

Slide 11

Slide 11 text

Compiling and deploying robot code .java compile source code .class bytecode .jar archive .jar dependencies build deploy JRE all .jar files cRIO or roboRIO $ ant compile jar deploy run ‘deploy’ and ‘run’ require your computer being connected to the robot’s network

Slide 12

Slide 12 text

Compiling and deploying robot code .java compile source code .class bytecode .jar archive .jar dependencies build deploy JRE all .jar files cRIO or roboRIO $ ant run ‘deploy’ and ‘run’ require your computer being connected to the robot’s network

Slide 13

Slide 13 text

Compiling and deploying robot code For a specific robot program in one of the folders/projects: $ cd $ ant compile or $ ant deploy or $ ant run ‘deploy’ and ‘run’ require your computer being connected to the robot’s network

Slide 14

Slide 14 text

Compiling and deploying robot code ‘deploy’ and ‘run’ require your computer being connected to the robot’s network

Slide 15

Slide 15 text

Within Eclipse 1. Select project 2. Select External Tools button 3. Click “Compile” menu item 4. Check output

Slide 16

Slide 16 text

Working with Git

Slide 17

Slide 17 text

What is Git? • Program that keeps track of all changes to a set of files • Keeps entire history in a repository - makes local file system look like the files at some point in time - user changes files locally, then commits into history • Every developer - has a local copy of the repository - can pull changes from other copies of the repository - can (sometimes) push changes into other copies of the repository

Slide 18

Slide 18 text

Version 1 Version 2 Version 3 Version 4 Version 5 Version 6 History of files over time A0 B0 C0 time B0 A1 C1 A2 B0 C1 A2 B1 C1 A3 B2 C2 A3 B3 C2 D0 D0 D1 each of these is called a commit

Slide 19

Slide 19 text

ab387de 8376def 12acef3 87bb322 501ae4 f634ca History of files over time A0 B0 C0 time B0 A1 C1 A2 B0 C1 A2 B1 C1 A3 B2 C2 A3 B3 C2 D0 D0 D1 and are identified with a content-based secure hash ID

Slide 20

Slide 20 text

ab387de 8376def 12acef3 87bb322 501ae4 f634ca History of files over time time

Slide 21

Slide 21 text

A3 B3 C2 D1 ab387de 8376def 12acef3 87bb322 501ae4 f634ca History of files over time Git can make the files and folders look exactly like any one of these commits last first

Slide 22

Slide 22 text

B0 A1 C1 ab387de 8376def 12acef3 87bb322 501ae4 f634ca History of files over time …which means we can go back in time to the way the source code looked at a specific point last first

Slide 23

Slide 23 text

B0 A1 C1 ab387de 8376def 12acef3 87bb322 501ae4 f634ca History of files over time We can even tag commits with meaningful labels. 
 
 That makes it easy to see the code for a particular version or release or point in time. 2.0 1.0

Slide 24

Slide 24 text

ab387de 8376def 12acef3 87bb322 501ae4 f634ca History of files over time A branch is simply a line of commits master We often call the primary branch “master” We can name branches anything

Slide 25

Slide 25 text

ab387de 8376def 12acef3 87bb322 501ae4 f634ca History of files over time master We can create branches at any time

Slide 26

Slide 26 text

B0 B0 ab387de 8376def 12acef3 87bb322 501ae4 f634ca History of files over time We might create a branch to fix a bug on an old version so we can release an update 2.0 1.0 A1 C1 acfef3 1.1 A1 C1 B0.1

Slide 27

Slide 27 text

ab387de 8376def 12acef3 87bb322 501ae4 f634ca History of files over time master A3 B3 C2 D1

Slide 28

Slide 28 text

D1 C3 B4 E0 A3 A3 B3 C2 D1 ab387de 8376def 12acef3 87bb322 501ae4 f634ca History of files over time master feature1 A3 B3 C2 D1 B4 C3 E0 dae74c A4 E1 9893a4 We call these local branches on which we work 
 topic branches git checkout -b feature1 master

Slide 29

Slide 29 text

D1 A3 B4 C3 E0 D1 C3 B4 E0 A3 ab387de 8376def 12acef3 87bb322 501ae4 f634ca History of files over time master feature1 dae74c A4 E1 9893a4 But how do we get the
 commits on our topic branch 
 into the ‘master’ branch? After all, these are only on our local machines.

Slide 30

Slide 30 text

Git is distributed ! (which means we can pull from and push to other repositories)

Slide 31

Slide 31 text

Remember when you set up your repository? frc-4931/2014 jsmith/2014 fork 2014 Jane’s computer github.com sdaniels/2014 kthompson/2014 2014 Sid’s computer 2014 Kathy’s computer clone clone clone

Slide 32

Slide 32 text

Git knows about the other repositories frc-4931/2014 jsmith/2014 2014 Jane’s computer github.com “origin” “upstream”

Slide 33

Slide 33 text

Git knows about the other repositories frc-4931/2014 jsmith/2014 2014 Jane’s computer github.com gets ‘master’ branch from “upstream” repository (only what we don’t already have) git pull upstream master We can do things like:

Slide 34

Slide 34 text

Git knows about the other repositories frc-4931/2014 jsmith/2014 2014 Jane’s computer github.com git pull upstream master git push origin master We can do things like: copies ‘master’ branch into “origin” repository

Slide 35

Slide 35 text

Sharing topic branches via GitHub frc-4931/2014 jsmith/2014 2014 Jane’s computer github.com git pull upstream master git push origin master We can do things like: copies ‘feature’ branch into “origin” repository git push origin feature1 feature1 feature1

Slide 36

Slide 36 text

Request your commits get merged into master frc-4931/2014 jsmith/2014 2014 Jane’s computer github.com feature1 pull-request feature1 Use github.com to create a pull request for “feature1” branch Anyone watching frc-4931/2014 gets an email notification

Slide 37

Slide 37 text

Commits are merged into ‘upstream’ repository frc-4931/2014 jsmith/2014 2014 Jane’s computer github.com feature1 feature1 merge pull-request merges commits from ‘feature1’ into ‘master’ branch Someone reviews pull- request. If acceptable, they merge it into the ‘master’ branch.

Slide 38

Slide 38 text

The ‘master’ branch now has the new commits frc-4931/2014 jsmith/2014 2014 Jane’s computer github.com feature1 feature1 master But you don’t have them yet! (The commits are on ‘feature1’ branch, not ‘master’)

Slide 39

Slide 39 text

Pull the latest ‘master’ from the official repository frc-4931/2014 jsmith/2014 2014 Jane’s computer github.com gets ‘master’ branch from “upstream” repository git pull upstream master master feature1 feature1 master (We already have the new commits, but they’re on ‘feature1’ branch, so this operation simply updates ‘master’ branch to have those commits.)

Slide 40

Slide 40 text

Clean up your local topic branches frc-4931/2014 jsmith/2014 2014 Jane’s computer github.com git branch -r feature1 master feature1 feature1 master git push origin :feature1

Slide 41

Slide 41 text

Others update their ‘master’ the same way frc-4931/2014 jsmith/2014 2014 Jane’s computer github.com sdaniels/2014 kthompson/2014 2014 Sid’s computer 2014 Kathy’s computer master master master master master git pull upstream master git pull upstream master

Slide 42

Slide 42 text

What are the steps?

Slide 43

Slide 43 text

Deploy latest code on robot First get the latest from ‘master’ and compile…! $ git checkout master $ git pull upstream master $ cd $ ant compile Then connect to robot’s network, deploy and run:! $ ant deploy run

Slide 44

Slide 44 text

Make changes to robot code (part 1 of 2) First make sure there’s an issue for your work.! Then get the latest from ‘master’ …! $ git checkout master $ git pull upstream master $ git checkout -b master Make changes and compile! $ cd $ ant compile Connect to robot network, and compile/run on robot:! $ ant deploy run

Slide 45

Slide 45 text

Make changes to robot code (part 2 of 2) When everything works, commit and push to your fork:! $ git commit . $ git push origin Finally use github.com to create a pull-request!