Training: Day Two - Eclipse, Git, Maven

48
ECLIPSE

description

This is the second in our four part training sessions introducing FenixEdu development for new collaborators. In this second session, we introduce some of the tools used in FenixEdu development, Eclipse, Git and Maven

Transcript of Training: Day Two - Eclipse, Git, Maven

Page 1: Training: Day Two - Eclipse, Git, Maven

ECLIPSE

Page 2: Training: Day Two - Eclipse, Git, Maven

CODE STYLE

Golden RuleALWAYS USE THE GOD DAMN STYLE

✓ Minimize the change set on commits and conflicts

✓ Ease the overall readability of the code base

✓ Format the code automatically via IDE save actions

Benefits

When working on a large team, code style is no place to be creative.

Page 3: Training: Day Two - Eclipse, Git, Maven

SAVE ACTIONS

Save actions allow you to automate a set of tasks that will

Golden RuleALWAYS ENABLE THE GOD DAMN SAVE ACTIONS

✓ Code style is applied automatically

✓ Imports are organized according to the same set of rules

✓ Minimize the change set on commits and conflicts

Benefits

Page 4: Training: Day Two - Eclipse, Git, Maven

BUILD AUTOMATICALLY

When handling big projects, the build automatically feature can be an unpleasant experience.

Golden RuleSAY NO TO BUILD AUTOMATICALLY

✓ Eclipse will be more responsive

✓ Embedded servlet containers will not react to code changes

✓ Embrace the limitations of FenixFramework

Benefits

Page 5: Training: Day Two - Eclipse, Git, Maven

ECLIPSE JEDI

If you want to maximize your productivity, you should use less mouse and more keyboard.

Golden RuleLEARN YOUR TOOL AND SOME DAMN SHORTCUTS

✓ Increase your productivity

✓ Fix and solve your problems quicker

✓ Look smart and geek

Benefits

Page 6: Training: Day Two - Eclipse, Git, Maven

ECLIPSE JEDI - SHORTCUTS

Some of the most commonly used shortcuts

Auto-completeCtrl+Space

Fix FormattingCtrl+Shift+F

Open ResourceCtrl+Shift+R

Open TypeCtrl+Shift+T

Ctrl+O Quick Outline

Ctrl+L Go to Line

Ctrl+T Quick Hierarchy

Page 7: Training: Day Two - Eclipse, Git, Maven

GIT

Page 8: Training: Day Two - Eclipse, Git, Maven

WHAT IS GIT?

Distributed Version Control System (DVCS) that provides local branching for free.

Golden RuleSNAPSHOTS NOT DIFFERENCES

✓ Each clone is a safety copy

✓ Local branching is free of headaches

✓ Lots of awesome features (stash, rebase, squash, etc...)

Benefits

Page 9: Training: Day Two - Eclipse, Git, Maven

SVN VS GIT

Version 1 Version 2 Version 3 Version 4 Version 5

file A

file B

file C

Δ1 Δ2

Δ1 Δ2

Δ1 Δ2

Δ3

Checkins over time

Version 1 Version 2 Version 3 Version 4 Version 5

A

B

C

Checkins over time

A1

B

C1

A1

B

C2

A2

B1

C2

A2

B2

C3

SVN

GIT

Page 10: Training: Day Two - Eclipse, Git, Maven

GIT REPOSITORY

A GIT repository, among other artifacts, is essentially composed by:

✓ A set of commits

✓ A set of references (pointers) to commits (aka heads)

efc3a a4b4a d56d4

44d5c

head A

head B

Page 11: Training: Day Two - Eclipse, Git, Maven

COMMIT

✓ A set of files (blobs) that reflect the state of the project at

a particular time

✓ Reference to the parent commits (i.e. the set of states

from which the new state was originated from)

✓ A SHA1 name which grants the commit unicity and

checksum properties

A commit comprehends:

efc3a a4b4a

Page 12: Training: Day Two - Eclipse, Git, Maven

HEAD

✓ A reference to a particular commit with a more human

perceptive name

✓ A Git repository can have any number of heads

✓ At a given time, one of the heads is selected as the current

head, which is also a reference called HEAD

efc3a a4b4a d56d4

44d5c

head A

head B HEAD

Page 13: Training: Day Two - Eclipse, Git, Maven

INITIALIZING THE REPOSITORY

Git repositories work using your filesystem

The repository is handled in the .git folder in the root of your project

$ git init

Page 14: Training: Day Two - Eclipse, Git, Maven

STAGE ONE OR MORE FILES

$ touch README.md$ git add README.md

working

directory

staging

area

git

repository

git commit

git checkout

git add

git reset HEAD

Page 15: Training: Day Two - Eclipse, Git, Maven

efc3amaster

HEAD

$ git commit -m “Added README”

SAVING THE SNAPSHOT (COMMIT)

Page 16: Training: Day Two - Eclipse, Git, Maven

efc3amaster

HEAD

$ git add *.java

ADDING MORE FILES TO THE PICTURE

Page 17: Training: Day Two - Eclipse, Git, Maven

$ git commit -m “Added Java files”

efc3a

ac2admaster

HEAD

MAKING ANOTHER COMMIT

Page 18: Training: Day Two - Eclipse, Git, Maven

$ git branch feature/x

efc3a

ac2admaster feature/x

HEAD

BRANCHING (1)

Page 19: Training: Day Two - Eclipse, Git, Maven

BRANCHING (2)

$ git checkout feature/x

efc3a

ac2admaster feature/x

HEAD

Page 20: Training: Day Two - Eclipse, Git, Maven

QUICK BRANCHING (1)

efc3a

ac2admaster

HEAD

Page 21: Training: Day Two - Eclipse, Git, Maven

QUICK BRANCHING (2)

efc3a

ac2admaster feature/x

HEAD

$ git checkout -b feature/x

Page 22: Training: Day Two - Eclipse, Git, Maven

MERGING (1)

$ git commit -m “Fixed stuff”

efc3a

ac2ad

4ecd4

master

feature/x

HEAD

Page 23: Training: Day Two - Eclipse, Git, Maven

MERGING (1)

$ git checkout master

efc3a

ac2ad

4ecd4

master

feature/x

HEAD

Page 24: Training: Day Two - Eclipse, Git, Maven

MERGING (2)

$ git merge feature/x

efc3a

ac2ad

4ecd4

master

feature/x

HEAD

Page 25: Training: Day Two - Eclipse, Git, Maven

MERGING (3)

efc3a

ac2ad

4ecd4master feature/x

HEAD

Fast-Forward

Page 26: Training: Day Two - Eclipse, Git, Maven

MERGING (4)

efc3a

ac2ad

4ecd4masterfeature/x

HEAD

f3d3e

Other situation

Page 27: Training: Day Two - Eclipse, Git, Maven

MERGING (5)

$ git checkout master

efc3a

ac2ad

4ecd4masterfeature/x

HEAD

f3d3e

Page 28: Training: Day Two - Eclipse, Git, Maven

MERGING (6)

$ git merge feature/x

efc3a

ac2ad

4ecd4

master

feature/x

HEAD

f3d3e

4ecd4

Ugly History

Page 29: Training: Day Two - Eclipse, Git, Maven

DELETING A BRANCH

$ git branch -d feature/xUgly History

efc3a

ac2ad

4ecd4

master

HEAD

f3d3e

4ecd4

Page 30: Training: Day Two - Eclipse, Git, Maven

REBASE (1)

efc3a

ac2ad

4ecd4masterfeature/x

HEAD

f3d3e

Page 31: Training: Day Two - Eclipse, Git, Maven

REBASE (2)

$ git rebase -i master

efc3a

ac2ad

4ecd4master

feature/x

HEAD

2fd3e

f3d3e

Page 32: Training: Day Two - Eclipse, Git, Maven

MERGING (1)

$ git checkout master

efc3a

ac2ad

4ecd4master

feature/x2fd3eHEAD

Clean History

Page 33: Training: Day Two - Eclipse, Git, Maven

MERGING (2)

$ git merge feature/x

efc3a

ac2ad

4ecd4

master feature/x2fd3e

HEAD

Fast-Forward

Page 34: Training: Day Two - Eclipse, Git, Maven

GITHUB

A service that hosts Git repositories online with extra features

✓ Create forks from other repositories

✓ Push commits to your own fork

✓ Request pulls from your fork (e.g. pull-requests)

Contribution Methodology

Page 35: Training: Day Two - Eclipse, Git, Maven

CLONE

$ git clone --origin fork [email protected]:davidmartinho/fenix

The clone command creates a full copy of the repository, i.e. all commits, tags and heads.

$ git remote add origin https://github.com/FenixEdu/fenix.git

Clone your fork

Add FenixEdu as a remote to fetch updates

(the --origin fork is to name the remote fork instead of the default origin)

Pull from FenixEdu with rebase to keep history clean

$ git pull --rebase origin master

Page 36: Training: Day Two - Eclipse, Git, Maven

PULL REQUESTS

The pull request is not a git feature.

Github has this pull request feature to improve contributions and allows developers to merge outside contributions directly on github.

Golden RuleALWAYS MAKE PULL REQUEST ON FENIX

Page 37: Training: Day Two - Eclipse, Git, Maven

MAVEN

Page 38: Training: Day Two - Eclipse, Git, Maven

WHAT IS MAVEN?

Golden RuleDEPENDENCIES BINARIES HAVE NO PLACE IN VCS

✓ Convention over Configuration

✓ Keeps the VCS repository out of binaries

✓ Format the code automatically via IDE save actions

Benefits

Maven is much more than a project building tool. It allows you to build and manage your project.

Page 39: Training: Day Two - Eclipse, Git, Maven

MAVEN BUILDING BLOCKS

LIFECYCLESMaven knowns how a project is cleaned and built.A lifecycle is essentially a pre-defined list of phases to ensure such clean and build processes.

PLUGINSThe phases by themselves are worthless.We associate plugin goals (implemented by Mojos) to one of the phases.

Page 40: Training: Day Two - Eclipse, Git, Maven

CLEAN LIFECYCLE

pre-cleanexecute necessary tasks prior to project clean

cleandeletes all files generated during the building process

post-cleanexecutes necessary tasks needed after the building process

pre-clean

clean

post-clean

Page 41: Training: Day Two - Eclipse, Git, Maven

DEFAULT LIFECYCLE

generate-sources

compile

process-classes

prepare-package

package

install

deploy

24 phasesomitted the most uncommon

Page 42: Training: Day Two - Eclipse, Git, Maven

generate-sources

compile

process-classes

prepare-package

package

install

deploy

ffmavenplugin

Page 43: Training: Day Two - Eclipse, Git, Maven

HOW DOES IT WORK?

generate-sources

compile

process-classes

prepare-package

package

install

deploy

maven-compiler-pluginffmavenplugin

Page 44: Training: Day Two - Eclipse, Git, Maven

HOW DOES IT WORK?

generate-sources

compile

process-classes

prepare-package

package

install

deploy

maven-compiler-pluginffmavenplugin

Page 45: Training: Day Two - Eclipse, Git, Maven

HOW DOES IT WORK?

generate-sources

compile

process-classes

prepare-package

package

install

deploy

maven-compiler-pluginffmavenplugin

maven-jar-plugin

Page 46: Training: Day Two - Eclipse, Git, Maven

POM (Project Object Model)

✓ Declarative XML file

✓ Identifies your project (groupId, artifactId, version, packaging)

✓ Declares the project dependencies and their scopes

✓ Declares which plugin goals should run on which phase

✓ Declare additional repositories for the dependencies

Page 47: Training: Day Two - Eclipse, Git, Maven

REPOSITORIES

MAVEN CENTRAL REPOSITORYContains most of the commonly known Java libraries (e.g. log4j, hibernate, jodatime, etc...)

DSI NEXUS REPOSITORYContains our binaries (e.g. fenix-framework, tools, bennu, workflow, organization, etc...)

PROXIED THIRD-PARTY REPOSITORIESNexus allows us to proxy and cache some other third-party repositories. Good when they’re out-of-service

Page 48: Training: Day Two - Eclipse, Git, Maven

INSTALL VS DEPLOY

$ mvn clean install

📁 ~/.m2/repository

$ mvn clean deploy

☁fenix-ashes.ist.utl.pt/nexus