Content. Development Tools 2(57)

Similar documents
Topics covered. Introduction to Maven Maven for Dependency Management Maven Lifecycles and Plugins Hands on session. Maven 2

What is Maven? Apache Maven is a software project management and comprehension tool (build, test, packaging, reporting, site, deploy).

MAVEN MOCK TEST MAVEN MOCK TEST IV

Setting up a Maven Project

maven Build System Making Projects Make Sense

Pour aller plus loin : Programmation outillée

Maven. INF5750/ Lecture 2 (Part II)

Simplified Build Management with Maven

MAVEN MOCK TEST MAVEN MOCK TEST I

Cheat Sheet: Wildfly Swarm

sites</distribsiteroot>

Component based Development. Table of Contents. Notes. Notes. Notes. Web Application Development. Zsolt Tóth

Apache Maven. Created by anova r&d bvba

MAVEN MOCK TEST MAVEN MOCK TEST III

Packaging, automation, Continuous Integration

Index. Bitwise operations, 131. Cloud, 88, 101

MAVEN INTERVIEW QUESTIONS

Maven POM project modelversion groupid artifactid packaging version name

I Got My Mojo Workin'

TOP REASONS WHY YOU SHOULD SWITCH TO MAVEN 3

Sonatype CLM - IDE User Guide. Sonatype CLM - IDE User Guide

Apache Maven MarsJUG. Arnaud Héritier exo platform Software Factory Manager

Fat / Uber jars - Using the Shade Plugin

TIBCO StreamBase 10.2 Building and Running Applications in Studio, Studio Projects and Project Structure. November 2017

JPA Tools Guide (v5.0)

Oracle Code Day Hands On Labs (HOL) (Install, Repository, Local Deploy, DevCS, OACCS)

Oracle Code Day Hands On Labs HOL

Hello Maven. TestNG, Eclipse, IntelliJ IDEA. Óbuda University, Java Enterprise Edition John von Neumann Faculty of Informatics Lab 2.

JDO Tools Guide (v5.1)

Sonatype CLM Enforcement Points - Nexus. Sonatype CLM Enforcement Points - Nexus

Set up Maven plugins in Eclipse. Creating a new project

4. Check the site specified in previous step to work with, expand Maven osgi-bundles, and select slf4j.api,

Repository Management and Sonatype Nexus. Repository Management and Sonatype Nexus

Checking Out and Building Felix with NetBeans

AUTOMATION TESTING FRAMEWORK FOR LUMINOUS LMS

Funambol Connector Development Tutorial

Unable To The Artifact From Any Repository Maven-clean-plugin

Maven Introduction to Concepts: POM, Dependencies, Plugins, Phases

DevOps and Maven. Eamonn de Leastar Dr. Siobhán Drohan Produced by:

... Maven.... The Apache Maven Project

Sonatype CLM - CI User Guide. Sonatype CLM - CI User Guide

Administering Apache Geronimo With Custom Server Assemblies and Maven. David Jencks

About the Tutorial. Audience. Prerequisites. Disclaimer & Copyright. Jenkins

GAVIN KING RED HAT CEYLON SWARM

STQA Mini Project No. 1

Maven 2 & Continuum. by Trygve Laugstøl

GlassFish V3 Engineer's guide

Groovy. Extending Java with scripting capabilities. Last updated: 10 July 2017

Testing with Soap UI. Tomaš Maconko

Struts 2 Maven Archetypes

juddi Developer Guide

SECTION II: JAVA SERVLETS

JDK-WildFly-NetBeans Setup Local

How Do I Inspect Error Logs in Warehouse Builder?

MANUAL DO ALUNO DE ENGENHARIA DE SOFTWARE

This tutorial explains how you can use Gradle as a build automation tool for Java as well as Groovy projects.

Arquillian & ShrinkWrap

Introduction to project industrialization using Maven YaJUG 06/10/2009. Copyright Pierre-Antoine Grégoire License Creative Commons 2.

Chapter 1: First steps with JAX-WS Web Services

Gant as Ant and Maven Replacement

Session 24. Spring Framework Introduction. Reading & Reference. dev.to/lechatthecat/how-to-use-spring-boot-java-web-framework-withintellij-idea-202p

Jenkins User Conference Israel. #jenkinsconf. CI / Liveperson. Gidi Samuels. July 16, #jenkinsconf

Pieter van den Hombergh Stefan Sobek. April 18, 2018

Continuous Integration (CI) with Jenkins

Package Management and Build Tools

Jaxb2 Maven Plugin Could Not Process Schema

Module Road Map. 7. Version Control with Subversion Introduction Terminology

Specification Lead: Red Hat Inc.

Selenium Testing Course Content

6.170 Laboratory in Software Engineering Eclipse Reference for 6.170

vrealize Code Stream Plug-In SDK Development Guide

Continuous Integration INRIA

EMC Documentum Composer

B O NU S C H A P T E R

ONAP Developer Typical Setup 2017 July ONAP Virtual Developers Event

Getting started with Geomajas. Geomajas Developers and Geosparc

FROM NOTHING TO COMPLETE ENVIRONMENT WITH MAVEN, OOMPH & DOCKER. Max Bureck, 21. June 2017

GlassFish V3. Jerome Dochez. Sun Microsystems, Inc. hk2.dev.java.net, glassfish.dev.java.net. Session ID YOUR LOGO HERE

Red Hat JBoss Fuse 6.3

Java Programming Language

... Apache Maven PDF Plugin v. 1.4 User Guide.... The Apache Software Foundation

Migration Cheat Cheet for Java EE 5 to Java EE 6

Class Dependency Analyzer CDA Developer Guide

<put document name here> 1/13

JPA Enhancement Guide (v5.1)

The Actual Real World at EclipseCon/ALM

ActiveSpaces Transactions. Quick Start Guide. Software Release Published May 25, 2015

TOOLING SUPPORT FOR ENTERPRISE DEVELOPMENT RYAN CUPRAK & REZA RAHMAN

JavaLand Dirk Mahler

Apache Maven: Best Practices

ewon Flexy JAVA J2SE Toolkit User Guide

AppDev StudioTM 3.2 SAS. Migration Guide

An Integrated Approach to Managing Windchill Customizations. Todd Baltes Lead PLM Technical Architect SRAM

Apache Maven. Péter Jeszenszky Faculty of Informatics, University of Debrecen Last modified: March 8, 2018

Maven in the wild. An introduction to Maven

designed to enable you to create a foundation for your own plugin project.

TCK Reference Guide for JSR Bean Validation

Red Hat Fuse 7.0 Installing on Apache Karaf

BUILD AND DEPLOY SOA PROJECTS FROM DEVELOPER CLOUD SERVICE TO ORACLE SOA CLOUD SERVICE

Contents. Enterprise Systems Maven and Log4j. Maven. What is maven?

Transcription:

Development Tools

Content Project management and build, Maven Unit testing, Arquillian Code coverage, JaCoCo Profiling, NetBeans Static Analyzer, NetBeans Continuous integration, Hudson Development Tools 2(57)

Project Management and Build With Maven Maven Home page: http://maven.apache.org/ Tutorial, user guide and reference manual: http://maven.apache.org/guides/index.html Development Tools 4(57)

Maven, Content Why do we need a build tool? What is a project management tool? Maven architecture Pom file Using Maven in NetBeans Development Tools 5(57)

Why do we need a build tool? All actions (compile, deploy, run, create documentation, etc.) must be well-defined and reproducible. We need to store commands, switches, command line arguments, environment variables (like classpath), etc. All IDEs use a build tool. Configured via IDE dialogs instead of editing the build tool's script text files. NetBeans, and many other IDEs, use Ant for building. Development Tools 6(57)

Maven vs Ant An ant file is like a program, you specify what to do, when to do it and where (in which directory) the used files are found. With maven you only specify what to do, e.g., compile, not how to do it. Many common tasks, like compiling, are done by default, you do not even need to specify them. As a result, a maven script becomes shorter and easier to understand than an ant script. In particular, the NetBeans ant scripts are very long and complex. Development Tools 7(57)

Maven vs Ant (Cont'd) Ant forces you to manage all files yourself. Manually download all third-party jars your code depends on and place them in correct directory. Often very cumbersome and time-consuming. Maven defines your project's directory structure and manages all files in the project. Just specify the dependencies and maven downloads needed jars and uses them as required. Development Tools 8(57)

What is a project management tool? Maven not only builds the project. Also defines project directory structure, which tasks to perform and in what order. Development Tools 9(57)

Maven Philosophy Maven defines project directory structure. Always the same, no configuration needed. Maven defines what to do and in which order. Always the same, no configuration needed. User only defines a unique project name, package format (jar, war...) and dependencies (third-party products used). Much more configuration is of course possible. Development Tools 10(57)

Lifecycles, Phases and Goals Maven projects consist of lifecycles, which are divided in phases, which are divided in goals. There are three lifecycles: default, clean and site. Default lifecycle creates the application. Clean lifecycle removes all files generated by maven. Site lifecycle generates a web site with project documentation. Development Tools 11(57)

Major Phases in Default Lifecycle process-resources, Copy resources directory into destination directory. compile, Compile the source code. process-test-resources, Copy resources directory into the test destination directory. test-compile, Compile the test source code. test, Run tests using a suitable unit testing framework. package, Package compiled code in JAR (or other). install, Install the package into the local repository. deploy, Copy the package to the remote repository. Development Tools 12(57)

Clean and Site lifecycle These lifecycles have only one important phase each. Clean lifecycle has clean phase. Site lifecycle has site phase. Development Tools 13(57)

Execution To run maven, you specify a phase. Phases in the lifecycle of the specified phase are executed in order. The lifecycle starts from the beginning and stops after the specified phase. Development Tools 14(57)

What Happens in Each Phase? Each phase executes a set of goals. The packaging type decides which goals belong to which phase. Additional goals can be added manually. A goal is actually a piece of Java code, which is packaged in a plugin. One plugin can define many goals Development Tools 15(57)

Typical Goals The jar and war packaging types use (at least) the following goals. Phase process-resources plugin:goal resources:resources compile process-test-resources test-compile test package install deploy compiler:compile resources:testresources compiler:testcompile surefire:test jar:jar or war:war install:install deploy:deploy Development Tools 16(57)

Packages are Stored in Repositories Maven stores all packaged products (mainly jars) in repositories. Enables Maven to handle all dependencies since needed jars can be downloaded from repositories where they are stored. Promotes code reuse since local repositories can be used to share jars between projects. There is a default central repository and a local repository will be created. Other repositories must be specified as a dependency. Development Tools 17(57)

Project Object Model A Maven project is described in a Project Object Model file, pom.xml. The pom describes, at least, a unique name for the product and which dependencies it has (that is, which third-party products it uses). All POMs inherit a parent POM. If the parent is not specified it inherits the default POM. The used POM, including inherited data is shown with the command mvn help:effective-pom In NetBeans, open the POM and click Effective. Development Tools 18(57)

POM Generated by NetBeans groupid, artifactid and version together defines a unique name for the created archive. packaging decides the archive format for the product. name is the project's display name. It is used mainly in generated documentation. <groupid>se.kth.iv1201</groupid> <artifactid>myproject</artifactid> <version>1.0-snapshot</version> <packaging>war</packaging> <name>myproject</name> Development Tools 19(57)

POM Generated by NetBeans (Cont'd) A dependency defines a package our product uses. scope decides when the included package should be available. Default is compile, which means it is always available. Here we have specified provided, which means it will not be available at runtime (since it is provided by the server). <dependencies> <dependency> <groupid>javax</groupid> <artifactid>javaee-web-api</artifactid> <version>7.0</version> <scope>provided</scope> </dependency> </dependencies> Development Tools 20(57)

POM Generated by NetBeans (Cont'd) <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> It is not required to specify plugins. Here, the compiler plugin is specified because we want to configure it (to use JDK1.7 for Java files and class files). Development Tools 21(57)

Using Maven in NetBeans To create a Maven project you should choose Maven in the Categories list. Choose correct type of project in the Projects list. Development Tools 22(57)

Using Maven in NetBeans (Cont'd) You can update the POM by editing project properties. In particular, The Actions category allows you to configure the items on the right-click menu of the project. It is also possible to manually edit the POM. Development Tools 23(57)

In-Container Testing With Arquillian Arquillian Home page: http://arquillian.org/ Documentation: http://arquillian.org/guides/getting_started/?utm_source=cta Development Tools 24(57)

Arquillian, Content In-Container Tests How Arquillian Works How to Write an Arquillian Test Development Tools 25(57)

In-Container Tests Runs inside a container, which is identical to the container of the live application. All resources, like persistence managers and database connections, used by the application are available to the test. Everything, for example dependency injection, works the same way in the test as in the live application. Components are tested in real environment. Development Tools 26(57)

The Alternative, Mocking No container is available. All resources, for example injected objects and database connections, must be substituted by fake objects (mocking). Components are tested in artificial environment. Development Tools 27(57)

How Arquillian Works Starts the server (GlassFish, Payara, WildFly, ). Creates an archive with selected components of the application to test. Deploys the archive to the server. Communicates with the arquillian Servlet, which calls the test methods inside the server and returns the test result. Integrated with (for example) Junit, runs as a Junit test. Development Tools 28(57)

Install Arquillian Need to configure an entire new server, including all resources required by the application. Install arquillian and all its components: Integration with server The server itself Integration with Junit Junit Database connector Full POM is included in the nb-proj-with-tools example project Available on the course web, see https://www.kth.se/social/course/iv1201/page/program-examples/ Development Tools 29(57)

A Test Class Annotated @org.junit.runner.runw ith(arquillian.class) to specify that it shall be executed by Arquillian Objects can be injected with @javax.inject.inject, as in any CDI container. Test methods are annotated org.junit.test, as any Junit test. Development Tools 30(57)

Create The Deployable Archive Each test class shall contain a method annotated @org.jboss.arquillian.container.test.api.deployment, which can produce a deployable archive. Use the static method org.jboss.shrinkwrap.api.shrinkwrap.create to create the archive. Use addclass to add classes to the archive. Only classes specified here will be included. Use addasresource to add the persistence.xml file, which specified the persistence unit. Use addasmanifestresource to add an empty beans.xml file to the META-INF directory of the archive. This is required to start CDI. Development Tools 31(57)

Configure The Embedded Server The JDBC resource and connection pool are, us usual, specified in a file called glassfish-resources.xml (if the embedded server is Payara or GlassFish). The location of this file is specified in Arquillian's config file, arquillian.xml, as above. Development Tools 32(57)

Run The Test Right-click the project and choose Test, just as usual. Development Tools 33(57)

Code Coverage With JaCoCo JaCoCo Home Page: http://www.eclemma.org/jacoco/ Documentation: http://www.eclemma.org/jacoco/trunk/doc/ Development Tools 49(57)

JaCoCo, Content What is a Code Coverage Tool? JaCoCo Basics Development Tools 50(57)

What is a Code Coverage Tool? Records which parts of the program have been executed during a test and generates a report of the coverage. Visualizes how complete the tests are. It is normally not meaningful to strive for 100% coverage, getters and setters may be omitted from the test. We shall, however, make sure all important parts of the code are tested. Development Tools 51(57)

JaCoCo Basics Add this configuration to the POM to enable JaCoCo. <plugin> <groupid>org.jacoco</groupid> <artifactid>jacoco-maven-plugin</artifactid> <version>0.6.0.201210061924</version> <executions> <execution> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report</id> <phase>prepare-package</phase> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin> Development Tools 52(57)

JaCoCo Basics JaCoCo is included in NetBeans. Right-click the project and choose Code Coverage. Make sure Collect and Display Code Coverage is checked. To generate the code coverage report, choose Show Report... Development Tools 53(57)

JaCoCo Basics (Cont'd) Initially there is nothing to report, click Run All Tests to generate a report. For this to work, you must have created tests. Development Tools 54(57)

JaCoCo Basics (Cont'd) If you open a Java source file you will see the executed lines marked in green and those not executed in pink. Development Tools 55(57)

Profiling With NetBeans Development Tools 56(57)

Profiling, Content Why Profiling? How to Profile Using NetBeans. Development Tools 57(57)

Why Profiling? A profiler reports memory usage, CPU time, thread state and other information about program execution. Report can be per package, per class, per method, etc. Either updated live as a running total or a snapshot at a specific time. This is very important if you want to optimize your code. Never optimize without knowing what and where is the problem. Development Tools 58(57)

How to Profile Using NetBeans NetBeans comes with a bundled profiler. Before profiling the JDK must be calibrated, the profiler must know how long time different Java operations, e.g., method call, takes. In NetBeans, choose the menu item Tools Options, then choose the Java tab and the Profiler tab. Select General in the list to the left and click the Manage button. In the dialog box that appears, select the JDK you are using and click the Calibrate button. Switch off CPU frequency scaling when doing this. Only needed once per JDK. Development Tools 59(57)

How to Profile (Cont'd) Right-click the project and choose Profile to display the profile window. Select in the toolbar what to profile, for example CPU and memory usage (telemetry), top image below, or method calls, bottom image below. Development Tools 60(57)

A Sample Profiler Session, showing active threads Development Tools 61(57)

Static Analyzing With NetBeans Development Tools 62(57)

Static Analyzing, Content Why Static Analyzer? How to Use NetBeans' Static Analyzer. Development Tools 63(57)

Why Do Static Analysis? Static analysis means the code is analyzed without executing the program. A static analyzer checks for coding mistakes. It can be for example bugs, unneccessary code or badly formatted code. Like the compiler, such a tool helps find coding errors. In particular, since a static analyzer checks coding style, many of the misstakes it finds will not be found by executing the program. Development Tools 64(57)

Static Analysis With NetBeans Choose Source Inspect... from the menu to start the static analyzer. Choose which analyzes to perform. In the example below, all analyzers will be executed. Development Tools 65(57)

Static Analysis With NetBeans (Cont'd) Here, the analyzer found missing javadoc and an if statement that can be rewritten as below. Development Tools 66(57)

Continuous Integration With Hudson Hudson Home Page: http://www.hudson-ci.org/ Documentation, including online book: http://wiki.eclipse.org/hudson-ci/documentation Development Tools 67(57)

Continuous Integration, Content What is Continuous Integration? An Introduction to the Hudson Continuous Integration Server. Development Tools 68(57)

What is Continuous Integration (CI)? A software development practice where all developers frequently integrate new code with existing code. Each integration is verified by an automated build, to detect integration errors as quickly as possible. The automated build includes tests, code coverage reports, repository updates, etc. Development Tools 69(57)

What is a CI Server? A continuous integration (CI) server manages all parts included in a build. Using a CI server all team members perform exactly the same tasks on each submit. While developing, team members perform all tests locally, in the IDE. Immediately when a piece of code is finished, it is submitted to the CI server. The CI server runs all checks on the entire codebase, publishes the result, updates the code repository and deploys the new version. Development Tools 70(57)

Hudson CI Server The Hudson CI server can manage all tools and perform all tasks covered in this presentation, and many more. NetBeans can connect to a Hudson server,. But the server itself must be installed separately. The image below shows a possible configuration of the Hudson Builder in NetBeans. Development Tools 71(57)

Make Hudson Build the Project Right-click the new Hudson instance (local in this example) and choose New Build... to show the New Continuous Build Dialog. (upper image) Right-click the new build and choose Start Job to start the build. (lower image) Again right-click the build and choose Open in Browser to show the result. Development Tools 72(57)

Build Result Hudson displays a lot of information about to the build. We can see for example Test result (no failures) Compiler warnings (none) Static analysis results Code coverage reports Repository status Built modules (one stable) Development Tools 73(57)