55
Slide 1 of 55 © People Strategists www.peoplestrategists.com Exploring Maven, SVN and GIT

Exploring Maven SVN GIT

Embed Size (px)

Citation preview

Slide 1 of 55© People Strategists www.peoplestrategists.com

Exploring Maven,

SVN and GIT

Slide 2 of 55© People Strategists www.peoplestrategists.com

Objectives

In this session, you will learn to:

Explore Maven

Install and set up Maven

Create and build Web application using Maven

Manage Dependency

Introduce version control system

Explore subversion

Create repository in subversion

Merge code and avoid conflict

Explore GIT

Explore GitEye

Slide 3 of 55© People Strategists www.peoplestrategists.com

Exploring Maven

Maven:

Is a Yiddish word that means "accumulator of knowledge".

Is a tool that can be used for building and managing any Java based project.

Is based on the concept of a Project Object Model (POM), which is an xml file.

Helps Java Developers to understand the structure of a Java-based project by providing a proper directory structure.

Provides collection of jar files known as Maven repositories.

Provides set of commands to download and make use of Maven repositories.

Maven commands can be used from the Windows command prompt.

Slide 4 of 55© People Strategists www.peoplestrategists.com

Exploring Maven (Contd.)

Maven repositories are used to store constructed artifacts and dependencies of several types.

The two types of Maven repositories are:

Remote repositories:

Mean repositories accessed by different protocols, such as file:// and http://.

Might be central repositories, which are developed by Maven community, or by a third party to provide their artifacts for downloading.

For example, the repo.maven.apache.org is a central repository and http://maven.objectify-appengine.googlecode.com/git/ is a third party repository.

Local repositories:

Refer to a copy of remote downloads on your computer.

Are cache of the remote downloads and contains the temporary build artifacts that you have not yet released.

Maven archetypes (readymade templates) allow users to create projects using templates, which are based on common scenarios.

Slide 5 of 55© People Strategists www.peoplestrategists.com

Exploring Maven (Contd.)

Maven project structure of core application:

Project Home

Project Structure of Core Application

Slide 6 of 55© People Strategists www.peoplestrategists.com

Exploring Maven (Contd.)

Maven project structure of Web application:

Project Home

Project Structure of Web Application

Slide 7 of 55© People Strategists www.peoplestrategists.com

Exploring Maven (Contd.)

Following table lists the description of the project structure.

Folder Description

project home Contains the pom.xml and all subdirectories.

src/main/java Contains the Java classes for the project.

src/main/resourcesContains the deliverable resources for the project, such as property files.

src/main/webapp Contains the html or jsp files.

src/main/webapp/WEB-

INFContains all the configuration files, such as web.xml.

src/main/webapp/css Contains all the stylesheet files of the Web application.

src/test/javaContains the testing classes (JUnit or TestNG test cases) for the project.

src/test/resources Contains resources necessary for testing.

Slide 8 of 55© People Strategists www.peoplestrategists.com

Exploring Maven (Contd.)

Project Object Model (POM):

It was named project.xml in earlier version of Maven.

It is the fundamental unit of work in Maven.

It is an XML file that contains information about the project.

It always resides in the base directory of the project as pom.xml.

It also contains the configuration details, such as plugin, goals, build profiles and various dependencies used by Maven to build the project.

Slide 9 of 55© People Strategists www.peoplestrategists.com

Exploring Maven (Contd.)

Some important terms used in pom.xml are:

project: It is the root element for the pom.xml file.

modelVersion: It indicates the version of the project object model.

groupId: It identifies your project uniquely across all projects. If a user uses your project, it serves as an attribute of the dependency in pom.xml.

artifactId: It is the name of your project within Maven and specifies the artifact's location within the repository.

version: It refers to the initial maven version of your project. It is used within an artifact's repository to maintain different copy of an application. If you want that your artifact should be using last deployed version, you can suffix the version with –SNAPSHOT.

package: It refers to the Java package that is created while creating a project.

Slide 10 of 55© People Strategists www.peoplestrategists.com

Exploring Maven (Contd.)

SNAPSHOT: It is a special version that indicates a current development copy of your artifact. Unlike regular versions, Maven checks for a new SNAPSHOT version in a remote repository and fetches the last deployed version for every build.

plugin: It defines the plugin you project is using.

dependency: It defines the version of the project object model.

Maven uses the pom.xml file in the following order:

Read the pom.xml file and parse the content.

Download dependencies to local dependency repository.

Execute life cycle/build phase/goal.

Execute plugins, if any.

Slide 11 of 55© People Strategists www.peoplestrategists.com

Exploring Maven (Contd.)

Two types of the POM are:

Minimal POM

Super POM

Slide 12 of 55© People Strategists www.peoplestrategists.com

Exploring Maven (Contd.)

Minimal POM:

It contains only the necessary elements, which are:

project

modelVersion

groupId

artifactId

version

The following code illustrates the minimal POM:

<project>

<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany.app</groupId>

<artifactId>my-app</artifactId>

<version>1</version>

</project>

Slide 13 of 55© People Strategists www.peoplestrategists.com

Exploring Maven (Contd.)

Super POM:

It is Maven's default POM and can comprise of all the elements.

The following code illustrates super POM:

<project>

<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany.app</groupId>

<artifactId>my-app</artifactId>

<version>1</version>

<plugins>

<plugin>

<artifactId>maven-antrun-plugin</artifactId>

<version>1.3</version>

</plugin>

</plugins>

<dependencies>

<dependency>

<groupId>org.apache.maven</groupId>

<artifactId>maven-artifact</artifactId>

<version>${mavenVersion}</version>

</dependency>

</project>

Slide 14 of 55© People Strategists www.peoplestrategists.com

Installing and Setting Up Maven

The following table lists the system requirements for installing Maven.

Item Requirements

JDK Maven 3.2 requires JDK 1.6 or aboveMaven 3.0/3.1 requires JDK 1.5 or above

Memory No minimum requirement

Disk 10MB for the Maven installation itself.At least 500MB for your local Maven repository.

Operating System No minimum requirement.

Slide 15 of 55© People Strategists www.peoplestrategists.com

Installing and Setting Up Maven (Contd.)

To install and set up Maven, You need to perform following steps:

Set up JDK

Install Maven

Set Maven environment variables

Configure system path

Slide 16 of 55© People Strategists www.peoplestrategists.com

Installing and Setting Up Maven (Contd.)

To set up JDK in windows, you need to perform following steps:

Download the latest SDK from the URL, http://www.oracle.com/technetwork/java/javase/downloads/in

dex.html.

Set the JAVA_HOME path to C:\Program Files\Java\jdk1.8.0 path.

Set the PATH variable to C:\Jdk_Folder\bin;%PATH%;.

To set up JDK in linux, you need to perform following steps:

Download the latest SDK from the URL, http://www.oracle.com/technetwork/java/javase/downloads/in

dex.html.

Type export JAVA_HOME=/usr/local/jdk on command prompt.

Type export PATH=$PATH:$JAVA_HOME/bin/ on command prompt.

Set up JDK

Slide 17 of 55© People Strategists www.peoplestrategists.com

Installing and Setting Up Maven (Contd.)

To install Maven in windows, You need to perform following steps:

Go to the URL, http://maven.apache.org/download.cgi to download installation file for your target system.

Extract the file to a directory. For example, C:\apache-maven.

In linux, extract the file to the following directory:

/usr/local/apache-maven

Install Maven

Slide 18 of 55© People Strategists www.peoplestrategists.com

Installing and Setting Up Maven (Contd.)

To set these in windows, you need to perform following steps:

Set M2_HOME to C:\apache-maven-install-path.

Set M2 to %M2_HOME%\bin.

Set MAVEN_OPTS to -Xms256m -Xmx512m.

To set these in linux, you need to perform following steps:

Type export M2_HOME=/usr/local/apache-maven-install-pathon command prompt.

Type export M2=$M2_HOME/bin on command prompt.

Type export MAVEN_OPTS=-Xms256m -Xmx512m on command prompt.

Set Maven environment variables

Slide 19 of 55© People Strategists www.peoplestrategists.com

Installing and Setting Up Maven (Contd.)

In order to use Maven command line tools anywhere on a system, we have to add Maven bin directory location to system path.

To do this in windows, you need to perform following step:

Append the string ;%M2% to the end of the system variable PATH.

To do this in linux, you need to perform following step:

Type export PATH=$M2:$PATH on command prompt.

Configure system path

Slide 20 of 55© People Strategists www.peoplestrategists.com

Creating and Building Web Application Using Maven

Consider a scenario where you need to develop a Web application, helloworld that displays a message “Welcome to Maven World.” For this, you want to use the maven archetype.

The expected output of the Web application is shown in the following figure.

The Expected Output

Slide 21 of 55© People Strategists www.peoplestrategists.com

Introducing Version Control System

Version Control System (VCS) is a software that helps software developers to work together and maintain a complete history of their work.

The Goals of VCS are:

It allows developers to work simultaneously.

It does not overwrite each other’s changes.

It maintains history of every version of everything.

Two categories of VCS are:

Centralized Version Control System (CVCS)

Distributed/Decentralized Version Control System (DVCS)

Slide 22 of 55© People Strategists www.peoplestrategists.com

Introducing Version Control System (Contd.)

Centralized Version Control System (CVCS):

Uses a central server to store all files and enables team collaboration.

Stores the files on a single machine called server.

Some examples are SVN and Perforce.

Distributed/Decentralized Version Control System (DVCS):

Checks out the latest snapshot of the directory and fully mirrors the repository.

Allows any client to copy back the checked out repository to the server to restore it.

Does not rely on the central server.

Allows you to perform operations, such as commit changes, create branches, and view logs while you are offline.

Needs network connection only to publish your changes and take the latest changes.

Some examples are GIT and Darcs.

Slide 23 of 55© People Strategists www.peoplestrategists.com

Introducing Version Control System (Contd.)

Some of the VCS terminologies are:

Repository:

Is the heart of any version control system.

Is the central place where developers store all their work.

Stores files as well as the history.

Is accessed over a network, acting as a server and version control tool acting as a client.

Trunk:

Is a directory where all the main development happens and is usually checked out by developers to work on the project.

Branches:

is used to create another line of development.

Is useful to keep separate the new version of a software from the fixes of the old version.

Slide 24 of 55© People Strategists www.peoplestrategists.com

Introducing Version Control System (Contd.)

Working copy:

Is a snapshot of the repository.

Is a private workplace where developers can do their work remaining isolated from the rest of the team.

Tags:

Use tag directory to store named snapshots of the project.

Is a descriptive and memorable name given to a specific version in the repository.

Commit changes:

Is the act of committing the changes made in the working copy to the repository.

Is rolled back if an error comes in between the process of commit.

URL:

Represents the location of the repository on the server.

Slide 25 of 55© People Strategists www.peoplestrategists.com

Exploring Subversion

Subversion (SVN):

Is often abbreviated as SVN and falls under CVCS.

Is developed as a project of the Apache Software Foundation.

Is a software versioning and revision control system distributed under an open source license.

Is part of a rich community of developers and users.

Is a software that helps software developers to maintain a complete history files.

Some of the available SVNs are:

SlikSVN (32- and 64-bit client MSI)

VisualSVN (32- and 64-bit client and server)

WANdisco (32- and 64-bit client and server)

TortoiseSVN (32-bit and 64-bit)

Slide 26 of 55© People Strategists www.peoplestrategists.com

Exploring Subversion (Contd.)

To install TortoiseSVN, follow the following steps:

Download the software from URL, http://tortoisesvn.net/downloads.html.

Double-click the .msi file, the setup dialog box appears, as shown in the following figure.

Follow the instructions to install the software.

The Setup Dialog Box

Slide 27 of 55© People Strategists www.peoplestrategists.com

Creating Repository in Subversion

Creating a repository in TortoiseSVN:

Create a new folder in your desired drive.

Right-click the folder and select TortoiseSVN -> Create repository here. The Repository created dialog box appears as shown in the following figure.

Click the Create folder structure button.

Click the OK button.

The Repository created Dialog Box

Slide 28 of 55© People Strategists www.peoplestrategists.com

Creating Repository in Subversion (Contd.)

By default, the repository has a folder layout, as shown in the following figure.

Right-click the repository and select TortoiseSVN -> Repo-browser. It shows the folders, as shown in the following figure.

The Folder Layout

Repository Browser

Slide 29 of 55© People Strategists www.peoplestrategists.com

Creating Repository in Subversion (Contd.)

Adding a project to your repository:

Right-click the desired project.

Select TortoiseSVN -> Import. The Import dialog box appears.

Click the OK button. The project gets imported to the repository.

Click the OK button to close the Import dialog box.

Slide 30 of 55© People Strategists www.peoplestrategists.com

Creating Repository in Subversion (Contd.)

Creating a working directory:

Right-click project folder.

Select SVN Checkout. The Checkout dialog box appears, as shown in the following figure.

Click the OK button to checkout the project.

The Checkout Dialog Box

Slide 31 of 55© People Strategists www.peoplestrategists.com

Creating Repository in Subversion (Contd.)

Updating the project with latest version:

Right-click project folder in working directory.

Select SVN Update. The Update finished dialog box appears.

Click the OK button.

Committing the changes:

Right-click project folder in working directory.

Select SVN commit. The Commit dialog box appears.

Click the OK button.

Reversing the changes:

Right-click project folder in working directory.

Select TortoiseSVN -> Revert.

Select the version you want to revert in the Revert dialog box.

Click the OK button.

Slide 32 of 55© People Strategists www.peoplestrategists.com

Merging Code and Avoiding Conflict

Merging a project:

Right-click project folder.

Select TortoiseSVN -> Merge. The Merge dialog box appears, as shown in the following figure.

Select Merge type, which are:

Merge a range of revisions

Merge two different trees

The Merge Dialog Box

Slide 33 of 55© People Strategists www.peoplestrategists.com

Merging Code and Avoiding Conflict (Contd.)

Merge a range of revisions merges two versions of a project from one branch to other.

Merge two different trees merge the differences of two different branches into your working copy.

Click Next.

Select revision range, which are:

All revisions: It merges all the revisions.

Specific range: It merges the specified range.

Reverse merge: It merges the versions in reverse order.

Click the Next button.

Click the Merge button.

Slide 34 of 55© People Strategists www.peoplestrategists.com

Exploring GIT

GIT:

Was initially developed by Linus Torvalds for Linux kernel development.

Is a distributed revision control and source code management system.

Is a free software distributed under the terms of the GNU General Public License.

Is fast as most of the operations are performed locally.

Uses a common cryptographic hash function called secure hash function (SHA1), to name and identify objects within its database.

Terms related to GIT are:

Local repository: It is private workplace where developers make changes.

Working directory: It is the place where files are checked out.

Staging area: It is the place where GIT looks for the files while committing the changes to GIT repository.

Pull: It copies the changes from a remote repository instance to a local one.

Push: It copies changes from a local repository to a GIT repository.

Slide 35 of 55© People Strategists www.peoplestrategists.com

Exploring GIT (Contd.)

Basic workflow of GIT is:

Modify the checked out file from the working directory.

Add these files to the staging area.

Perform commit operation that moves the files from the staging area to GIT repository.

Basic Workflow of GIT

Slide 36 of 55© People Strategists www.peoplestrategists.com

Exploring GIT (Contd.)

Detailed workflow of GIT is:

Clone the GIT repository as a working copy.

Modify the working copy by adding/editing files.

Update the working copy by taking other developer's changes, if any.

Review the changes and commit.

Push the changes to the repository.

Detailed Workflow of GIT

Slide 37 of 55© People Strategists www.peoplestrategists.com

Exploring GIT (Contd.)

Installing GIT:

Download the software from URL, https://git-scm.com/download/win.

Double-click the setup file. The Git Setup dialog box appears, as shown in the following figure.

Click the Next button.The Git Setup Dialog Box

Slide 38 of 55© People Strategists www.peoplestrategists.com

Exploring GIT (Contd.)

Click the Next button. The next screen appears, as shown in the following figure.

Select all the check boxes and click the Next button.

Click the Next button.

The Git Setup Dialog Box

Slide 39 of 55© People Strategists www.peoplestrategists.com

Exploring GIT (Contd.)

Click the Next button. The next screen appears, as shown in the following figure.

Click the Next button in the next screens to install the software.

The Git Setup Dialog Box

Slide 40 of 55© People Strategists www.peoplestrategists.com

Exploring GIT (Contd.)

Creating a repository:

Open the git Bash file from the installation directory. The command prompt window appears, as shown in the following figure.

Type git init myrepository and press Enter. The repository gets initialized or created, as shown in the following figure.

The Command Prompt Window

The Command Prompt Window

Slide 41 of 55© People Strategists www.peoplestrategists.com

Exploring GIT (Contd.)

Some of the GIT commands are listed in the following table:

Command Syntax Description

init git init <directory> Creates a .git subdirectory in the project root, which contains all of the necessary metadata for the repository.

init --bare git init -- bare <directory> Initializes an empty git repository, but omit the working directory.

clone git clone <repo> Copies an existing git repository to local file system.

git clone <repo> <directory> Copies an existing git repository to the specified directory.

config git config user.name <name> Defines the author name to be used for all commits in the current repository.

git config --global

user.name <name>Defines the author name to be used for all commits in the current repository by the current user.

git config --global

user.email <email>Defines the author email to be used for all commits by the current user.

Slide 42 of 55© People Strategists www.peoplestrategists.com

Exploring GIT (Contd.)

Command Syntax Description

add git add <file> Stages all changes in <file> for the next commit.

git add <directory> Stage all changes in <directory> for the next commit.

git add -p lets you choose portions of a file to add to the next commit.

commit git commit Commits the snapshot in the staging area.

git commit -a Commits a snapshot of all changes in the working directory.

status git status Lists the files’ status, such as staged, unstaged, and untracked.

log git log Displays committed snapshots.

git log -n <limit> Limits the number of commits by <limit>. For example, git log -n 3 will display only 3 commits.

Slide 43 of 55© People Strategists www.peoplestrategists.com

Exploring GIT (Contd.)

Some of the GIT Graphical User Interface tool are:

GIT Extension

SourceTree

SmartGit.

GitEye

GitEye:

Is a popular distributed version control and source code management (SCM) system.

Improves GIT performance through an intuitive graphical interface that simplifies all GIT commands.

Is pre-integrated with CloudForge, TeamForge and GitHub, and works on most platforms.

Provides easy access to all GIT functions and repositories, and can be used with cloud or on-premise GIT repositories.

Slide 44 of 55© People Strategists www.peoplestrategists.com

Exploring GIT (Contd.)

Installing and configuring GitEye:

Download the GitEye software from the https://www.collab.net/downloads/giteye URL.

Unzip and store the files in GitEye folder in your local drive.

Double-click the GitEye.exe file. The CollabNet GitEye window appears, as shown in the following figure.

The CollabNet GitEye Window

Slide 45 of 55© People Strategists www.peoplestrategists.com

Exploring GIT (Contd.)

Creating a new repository:

Click the Create Repository button. The Create a Git Repository dialog box appears, as shown in the following figure.

Browse the location where you want to create the repository.

Select Create as bare repository if you want to create a blank repository.

The Add Git Repositories Dialog Box

Slide 46 of 55© People Strategists www.peoplestrategists.com

Exploring GIT (Contd.)

Click the Finish button. The Git Repositories window displays the newly created repository, as shown in the following figure.

The Git Repositories Window

Slide 47 of 55© People Strategists www.peoplestrategists.com

Exploring GIT (Contd.)

Adding an existing repository:

Click the Add Repository button. The Add Git Repositories dialog box appears, as shown in the following figure.

The Add Git Repositories Dialog Box

Slide 48 of 55© People Strategists www.peoplestrategists.com

Exploring GIT (Contd.)

Browse and select the desired repository. For example, mygit.

Click the Finish button.

Cloning a repository:

Create a user account on the repository’s URL, such as github.com.

Click the Clone Repository button. The Clone Git Repository dialog box appears, as shown in the following figure.

The Clone Git Repository Dialog Box

Slide 49 of 55© People Strategists www.peoplestrategists.com

Exploring GIT (Contd.)

Select the source. For example, GitHub.

Click the Next button.

Select search parameter.

Type a text (for example, app) and click the Search button. Repositories gets populated, as shown in the following figure.

The Clone Git Repository Dialog Box

Slide 50 of 55© People Strategists www.peoplestrategists.com

Exploring GIT (Contd.)

Select a repository and click Next. The Branch Selection page appears.

Select the checkboxes you need.

Click the Next button.

Click the Finish button. The repository gets added to the Git Repositorieswindow, as shown in the following figure.

The Git Repositories Window

Slide 51 of 55© People Strategists www.peoplestrategists.com

Exploring GIT (Contd.)

Modifying a file:

Double-click to checkout the directory or file you want to modify.

Locate the files in your local drive.

Make the changes as per you need.

Save the changes.

You can make the changes in the Working directory.

Pushing a file:

Select the directory or file in the repository.

Go to Git-> Push to Upstream.

Enter your credential.

Click the OK button.

Slide 52 of 55© People Strategists www.peoplestrategists.com

Exploring GIT (Contd.)

Committing changes to the remote repository:

Right-click directory or file you want to commit.

Select Commit. The Commit Changes dialog box appears.

Type the description in the Commit message text area.

Select Files.

Click the Commit button. If files are changed, files will be committed otherwise “There are no staged files.” error will be displayed.

Slide 53 of 55© People Strategists www.peoplestrategists.com

Summary

In this session, you learned that:

Maven is a tool that can be used for building and managing any Java based project.

Maven provides collection of jar files known as Maven repositories.

The two types of Maven repositories are:

Remote repositories

Local repositories

Maven archetypes allow users to create projects using templates, which are based on common scenarios.

POM is the fundamental unit of work in Maven.

Version Control System (VCS) is a software that helps software developers to work together and maintain a complete history of their work.

Two categories of VCS are:

Centralized Version Control System (CVCS)

Distributed/Decentralized Version Control System (DVCS)

Slide 54 of 55© People Strategists www.peoplestrategists.com

Summary (Contd.)

Repository is the central place where developers store all their work.

Trunk is a directory where all the main development happens and is usually checked out by developers to work on the project.

Branches is used to create another line of development.

GIT is a distributed revision control and source code management system.

Local repository is private workplace where developers make changes.

Working directory is the place where files are checked out.

Staging area is the place where GIT looks for the files while committing the changes to GIT repository.

Pull operation copies the changes from a remote repository instance to a local one.

Push operation copies changes from a local repository to a GIT repository.

Slide 55 of 55© People Strategists www.peoplestrategists.com

Summary (Contd.)

TortoiseSVN is a centralized version control system that helps to record the various version of a file.

GitEye is a popular distributed version control and source code management (SCM) system.

It improves GIT performance through an intuitive graphical interface that simplifies all GIT commands.