1. Maven
Maven is a project management and comprehension tool. From now on we will be using Mave to
-
Declare and donwload code dependencies (libraries)
-
Build our code
-
Build our tests
-
Run our tests
-
Generate reports about
-
out code
-
our tests
-
Most IDEs (including Eclipse and IntelliJ) have support for Maven. During this lab we will demonstrate how to use Maven from within Eclipse. We will also explain the basic concepts and files used to configure and control Maven. There is plenty of docuementation online about Maven that you should read.
Project that use Maven can be uploaded to Mave Central. This is a repository of project that you can search, download and use in your project.
1.1. Eclipse
Show and tell of how to start a Maven project.
-
Create new Maven Project
-
groupId
- maps to the the root packageedu.neu.ccs.cs5004.seattle
-
artifactId
- the package under root package that holds your application, e.g.,assignment1
-
-
Explain structure of Maven Project
-
Explain how to run a
-
build (
compile
) -
tests (
test
) -
reports (
site
)
-
2. POM.xml
Maven, like most build tools, uses targets
to designate what actions to perform, for example
-
To build your source code
-
Find the program’s source
-
Use Java’s compiler to build the source
-
-
To test your source code
-
Find the program’s source and build it
-
Find the program’s test source and build it
-
Run the tests using your testing framework
-
Maven reads pom.xml
in order to figure out what actions to perform for each target.
2.1. POM intro
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> (1)
<modelVersion>4.0.0</modelVersion> (2)
<groupId>edu.neu.ccs.cs5004.seattle</groupId> (3)
<artifactId>assignment1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>assignment1</name> (4)
<url>http://maven.apache.org</url> (5)
<properties> (6)
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
1 | Points to the schema and default Maven pom configuration |
2 | The maven model version that we are going to use |
3 | The groupId is a unique identifier for the organization or project |
4 | The artifactId is an identifier for the project |
5 | The version is the project version |
6 | The packaging is what kind of package we would like to generate from our compiled code |
2.2. POM dependencies
<dependencies> (1)
<dependency> (2)
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
1 | This starts a group of 1 or more dependencies for your project. Dependencies are other libraries/code that you need in order to build/test your code. |
2 | If you search Maven Central you can find your dependencies, their names and versions and Maven Central even provides the XML that you need to add to your POM in order to download and use this dependency. |
2.3. POM plugins: build
Maven plugins can be used to customize or add actions during the execution of a target. Here is the relevant XML that customizes our
build
target.
<!-- build -->
<build> (1)
<plugins> (2)
<plugin> (3)
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
1 | Designate which target we would like to alter/add/customize |
2 | Starts a group of plugins that we would like to use for this target |
3 | Starts a plugin with its customizatio. Here we are using the compiler plugin and configuring it so that the source file and output (target) files must be java 1.8. |
2.4. POM plugins: reports
<reporting> (1)
<plugins> (2)
<plugin> (3)
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
</plugin>
<plugin> (4)
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<xmlOutput>true</xmlOutput>
<!-- Optional directory to put findbugs xdoc xml report -->
<xmlOutputDirectory>target/site</xmlOutputDirectory>
</configuration>
</plugin>
</plugins>
</reporting>
3. Refactoring in Eclipse
Show and tell of Eclipse’s Refactoring operations.
-
Rename
-
Extract constant
-
Extract method
-
Extract interface
-
Extract class
-
Pull up
-
Push down
4. ADTs, again.
We would like to design a program that implements a Double Ended Queue
(DEQ). A DEQ is much like a queue but we can operate on both ends of the queue. We will use {< >}
to represent an empty DEQ
We are asked to create a DEQ that holds Strings.
Operation | Specification | Comments |
---|---|---|
|
|
|
|
{<>}.isEmpty() = true {<s,x, ... >}.isEmpty() = false |
|
|
{<>}.size() = 0 {<s, x, ...>}.size() = 1 + {<x, ...>}.size() |
|
|
{<>}.prepend(x) = {< x >} {<s, y, ..>}.prepend(x) = {<x, s, y, ...>} |
|
|
{<>}.append(x) = {< x >} {<s, y, ..>}.append(x) = {<s, y, ...,x>} |
|
|
{<>}.eject() = {<>} {<s, x, ..., y>}.eject() = {<s, x, ...>} |
|
|
{<>}.pop() = {<>} {<s, x, ...,>}.pop() = {<x, ...>} |
|
|
{<>}.last() = ERROR {<s, x, ...,y>}.last() = y |
|
|
{<>}.first() = ERROR {<s, x, ...>}.first() = x |
|
|
{<>}.has(s) = false {<s, x, ...>}.has(s) = true {<y,x, ...>}.has(s) = {<x, ...>}.has(x) |
|
Can we use your implementation to also provide a Queue
implementation. Here is the ADT for a simple Queue
.
Operation | Specification | Comments |
---|---|---|
|
|
|
|
{<>}.isEmpty() = true {<s,x, ... >}.isEmpty() = false |
|
|
{<>}.size() = 0 {<s, x, ...>}.size() = 1 + {<x, ...>}.size() |
|
|
{<>}.push(x) = {< x >} {<s, y, ..>}.push(x) = {<x, s, y, ...>} |
|
|
{<>}.pop() = {<>} {<s, x, ...,>}.pop() = {<x, ...>} |
|
|
{<>}.peek() = ERROR {<s, x, ...>}.peek() = x |
|
|
{<>}.has(s) = false {<s, x, ...>}.has(s) = true {<y,x, ...>}.has(s) = {<x, ...>}.has(x) |
|
4.1. Priority Queue
A Priority Queue PQ
is similar to a simple Queue
but the elements of a PQ
are pairs that contain
-
a priority, for our case this is a number
-
a value, for our case this is a string.
The operations on a PQ
are similar to the ones in Queue
-
Empty()
is the same as inQueue
. -
isEmpty()
is the same as inQueue
. -
size()
is the same as inQueue
. -
push(p,v)
adds a new element to theQueue
with priorityp
and valuev
. There is no restriction as to where in thePQ
the new element is added. -
pop()
returns a newPQ
by removing the element that has the highest priority. -
peek()
returns the valuev
of the element inPQ
that has the highest priority. -
has(s)
is the same as inQueue
, it checks that the values
is in thePQ
.