From b0beebe1f99c99150d5335b6e061956be3b1e740 Mon Sep 17 00:00:00 2001 From: Danilo Arcidiacono Date: Thu, 8 Nov 2018 22:16:20 +0100 Subject: [PATCH 01/11] Add file commons class. Add composite pattern class. Add getEnclosingClasses() method. Add string quote utilities. Add pitest for mutation tests and jacoco for code coverage reports. --- README.md | 4 + documentation/README.md | 24 +++ documentation/src/docs/asciidoc/index.adoc | 8 + documentation/src/docs/asciidoc/overview.adoc | 170 ++++++++++++++++++ .../src/test/java/example/AssertionsDemo.java | 145 +++++++++++++++ pom.xml | 93 ++++++++++ .../commons/lang/Composite.java | 111 ++++++++++++ .../commons/lang/FileCommons.java | 61 +++++++ .../commons/lang/ReflectiveCommons.java | 18 +- .../commons/lang/StringCommons.java | 12 ++ 10 files changed, 645 insertions(+), 1 deletion(-) create mode 100644 documentation/README.md create mode 100644 documentation/src/docs/asciidoc/index.adoc create mode 100644 documentation/src/docs/asciidoc/overview.adoc create mode 100644 documentation/src/test/java/example/AssertionsDemo.java create mode 100644 src/main/java/io/github/daniloarcidiacono/commons/lang/Composite.java create mode 100644 src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java diff --git a/README.md b/README.md index e69de29..5e8988a 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,4 @@ +[![Maven Central](https://img.shields.io/maven-central/v/io.github.daniloarcidiacono/commons-lang.svg?label=Maven%20Central)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22io.github.daniloarcidiacono%22%20a%3A%22commons-lang%22) +[![codecov](https://codecov.io/gh/daniloarcidiacono/commons-lang/branch/dev/graph/badge.svg)](https://codecov.io/gh/daniloarcidiacono/commons-lang) + +# Java language utilities \ No newline at end of file diff --git a/documentation/README.md b/documentation/README.md new file mode 100644 index 0000000..3f22e81 --- /dev/null +++ b/documentation/README.md @@ -0,0 +1,24 @@ +# commons-lang User Guide + +This subproject contains the AsciiDoc sources for the commons-lang User Guide. + +## Structure + +- `src/docs/asciidoc`: AsciiDoc files +- `src/test/java`: Java test source code that can be included in the AsciiDoc files +- `src/test/resources`: Classpath resources that can be included in the AsciiDoc files or + used in tests + +## Usage + +### Generate AsciiDoc + +This following Gradle command generates the HTML version of the User Guide as +`build/asciidoc/index.html`. + +``` +gradlew asciidoctor +``` + +On Linux operating systems, the `graphviz` package providing `/usr/bin/dot` must be +installed in order to generate the User Guide. \ No newline at end of file diff --git a/documentation/src/docs/asciidoc/index.adoc b/documentation/src/docs/asciidoc/index.adoc new file mode 100644 index 0000000..7bf4c99 --- /dev/null +++ b/documentation/src/docs/asciidoc/index.adoc @@ -0,0 +1,8 @@ +[[user-guide]] += commons-lang User Guide +Danilo Arcidiacono + +:sectnums: + +include::overview.adoc[] + diff --git a/documentation/src/docs/asciidoc/overview.adoc b/documentation/src/docs/asciidoc/overview.adoc new file mode 100644 index 0000000..93269f8 --- /dev/null +++ b/documentation/src/docs/asciidoc/overview.adoc @@ -0,0 +1,170 @@ +[[overview]] +== Overview + +The goal of this document is to provide comprehensive reference documentation for +programmers writing tests, extension authors, and engine authors as well as build tool +and IDE vendors. + +ifdef::backend-html5[This document is also available as a link:index.pdf[PDF download].] + +[TIP] +.Translations +==== +This document is also available in http://sjyuan.cc/junit5/user-guide-cn[Simplified Chinese] +and https://udzuki.jp/public/junit5-user-guide-ja[Japanese]. +==== + +[[overview-what-is-junit-5]] +=== What is JUnit 5? + +Unlike previous versions of JUnit, JUnit 5 is composed of several different modules from +three different sub-projects. + +**JUnit 5 = _JUnit Platform_ + _JUnit Jupiter_ + _JUnit Vintage_** + +The **JUnit Platform** serves as a foundation for <> on the JVM. It also defines the `{TestEngine}` API for developing a testing +framework that runs on the platform. Furthermore, the platform provides a +<> to launch the platform from the +command line and build plugins for <> and +<> as well as a +<> for running any `TestEngine` +on the platform. + +**JUnit Jupiter** is the combination of the new <> and +<> for writing tests and extensions in JUnit 5. The Jupiter +sub-project provides a `TestEngine` for running Jupiter based tests on the platform. + +**JUnit Vintage** provides a `TestEngine` for running JUnit 3 and JUnit 4 based tests on +the platform. + +[[overview-java-versions]] +=== Supported Java Versions + +JUnit 5 requires Java 8 (or higher) at runtime. However, you can still test code that +has been compiled with previous versions of the JDK. + + +[[overview-getting-help]] +=== Getting Help + +Ask JUnit 5 related questions on {StackOverflow} or chat with us on {Gitter}. + +[[installation]] +== Installation + +Artifacts for final releases and milestones are deployed to Maven Central. + +Snapshot artifacts are deployed to Sonatype's {snapshot-repo}[snapshots repository] under +{snapshot-repo}/org/junit/[/org/junit]. + +[[dependency-metadata]] +=== Dependency Metadata + +[[dependency-metadata-junit-platform]] +==== JUnit Platform + +* *Group ID*: `org.junit.platform` +* *Version*: `{platform-version}` +* *Artifact IDs*: + `junit-platform-commons`:: + Internal common library/utilities of JUnit. These utilities are intended solely for usage within + the JUnit framework itself. _Any usage by external parties is not supported._ Use at your own + risk! + `junit-platform-console`:: + Support for discovering and executing tests on the JUnit Platform from the console. See + <> for details. + `junit-platform-console-standalone`:: + An executable JAR with all dependencies included is provided at Maven Central under the + https://repo1.maven.org/maven2/org/junit/platform/junit-platform-console-standalone[junit-platform-console-standalone] + directory. See <> for details. + `junit-platform-engine`:: + Public API for test engines. See <> for details. + `junit-platform-launcher`:: + Public API for configuring and launching test plans -- typically used by IDEs and build tools. + See <> for details. + `junit-platform-runner`:: + Runner for executing tests and test suites on the JUnit Platform in a JUnit 4 + environment. See <> for details. + `junit-platform-suite-api`:: + Annotations for configuring test suites on the JUnit Platform. Supported by the + <> and possibly by third-party + `TestEngine` implementations. + `junit-platform-surefire-provider`:: + Support for discovering and executing tests on the JUnit Platform using + <>. + +[[dependency-metadata-junit-jupiter]] +==== JUnit Jupiter + +* *Group ID*: `org.junit.jupiter` +* *Version*: `{jupiter-version}` +* *Artifact IDs*: + `junit-jupiter-api`:: + JUnit Jupiter API for <> and <>. + `junit-jupiter-engine`:: + JUnit Jupiter test engine implementation, only required at runtime. + `junit-jupiter-params`:: + Support for <> in JUnit Jupiter. + `junit-jupiter-migrationsupport`:: + Migration support from JUnit 4 to JUnit Jupiter, + only required for running selected JUnit 4 rules. + +[[dependency-metadata-junit-vintage]] +==== JUnit Vintage + +* *Group ID*: `org.junit.vintage` +* *Version*: `{vintage-version}` +* *Artifact ID*: + `junit-vintage-engine`:: + JUnit Vintage test engine implementation that allows to run vintage JUnit tests, i.e. tests + written in the JUnit 3 or JUnit 4 style, on the new JUnit Platform. + +[[dependency-metadata-junit-bom]] +==== Bill of Materials (BOM) + +The _Bill of Materials_ POM provided under the following Maven coordinates can be used to +ease dependency management when referencing multiple of the above artifacts using +https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies[Maven] +or https://docs.gradle.org/current/userguide/managing_transitive_dependencies.html#sec:bom_import[Gradle]. + +* *Group ID*: `org.junit` +* *Artifact ID*: `junit-bom` +* *Version*: `{bom-version}` + +[[dependency-metadata-dependencies]] +==== Dependencies + +All of the above artifacts have a dependency in their published Maven POMs on +the following _@API Guardian_ JAR. + +* *Group ID*: `org.apiguardian` +* *Artifact ID*: `apiguardian-api` +* *Version*: `{apiguardian-version}` + +In addition, most of the above artifacts have a direct or transitive dependency to the +following _OpenTest4J_ JAR. + +* *Group ID*: `org.opentest4j` +* *Artifact ID*: `opentest4j` +* *Version*: `{ota4j-version}` + +[[dependency-diagram]] +=== Dependency Diagram + +[[dependency-metadata-junit-jupiter-samples]] +=== JUnit Jupiter Sample Projects + +The {junit5-samples-repo}[`junit5-samples`] repository hosts a collection of sample +projects based on JUnit Jupiter and JUnit Vintage. You'll find the respective +`build.gradle` and `pom.xml` in the projects below. + +* For Gradle, check out the `{junit5-jupiter-starter-gradle}` project. +* For Maven, check out the `{junit5-jupiter-starter-maven}` project. + + +== Using include with a remote file +[source,java,indent=0] +---- +include::{testDir}/example/AssertionsDemo.java[tag=user_guide] +---- \ No newline at end of file diff --git a/documentation/src/test/java/example/AssertionsDemo.java b/documentation/src/test/java/example/AssertionsDemo.java new file mode 100644 index 0000000..6254ec7 --- /dev/null +++ b/documentation/src/test/java/example/AssertionsDemo.java @@ -0,0 +1,145 @@ +/* + * Copyright 2015-2018 the original author or authors. + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v2.0 which + * accompanies this distribution and is available at + * + * http://www.eclipse.org/legal/epl-v20.html + */ + +package example; + +// @formatter:off +// tag::user_guide[] +import static java.time.Duration.ofMillis; +import static java.time.Duration.ofMinutes; +import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTimeout; +import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +class AssertionsDemo { + + // end::user_guide[] + Person person = new Person("John", "Doe"); + + // tag::user_guide[] + @Test + void standardAssertions() { + assertEquals(2, 2); + assertEquals(4, 4, "The optional assertion message is now the last parameter."); + assertTrue('a' < 'b', () -> "Assertion messages can be lazily evaluated -- " + + "to avoid constructing complex messages unnecessarily."); + } + + @Test + void groupedAssertions() { + // In a grouped assertion all assertions are executed, and any + // failures will be reported together. + assertAll("person", + () -> assertEquals("John", person.getFirstName()), + () -> assertEquals("Doe", person.getLastName()) + ); + } + + @Test + void dependentAssertions() { + // Within a code block, if an assertion fails the + // subsequent code in the same block will be skipped. + assertAll("properties", + () -> { + String firstName = person.getFirstName(); + assertNotNull(firstName); + + // Executed only if the previous assertion is valid. + assertAll("first name", + () -> assertTrue(firstName.startsWith("J")), + () -> assertTrue(firstName.endsWith("n")) + ); + }, + () -> { + // Grouped assertion, so processed independently + // of results of first name assertions. + String lastName = person.getLastName(); + assertNotNull(lastName); + + // Executed only if the previous assertion is valid. + assertAll("last name", + () -> assertTrue(lastName.startsWith("D")), + () -> assertTrue(lastName.endsWith("e")) + ); + } + ); + } + + @Test + void exceptionTesting() { + Throwable exception = assertThrows(IllegalArgumentException.class, () -> { + throw new IllegalArgumentException("a message"); + }); + assertEquals("a message", exception.getMessage()); + } + + @Test + void timeoutNotExceeded() { + // The following assertion succeeds. + assertTimeout(ofMinutes(2), () -> { + // Perform task that takes less than 2 minutes. + }); + } + + @Test + void timeoutNotExceededWithResult() { + // The following assertion succeeds, and returns the supplied object. + String actualResult = assertTimeout(ofMinutes(2), () -> { + return "a result"; + }); + assertEquals("a result", actualResult); + } + + @Test + void timeoutNotExceededWithMethod() { + // The following assertion invokes a method reference and returns an object. + String actualGreeting = assertTimeout(ofMinutes(2), AssertionsDemo::greeting); + assertEquals("Hello, World!", actualGreeting); + } + + // end::user_guide[] + @extensions.ExpectToFail + // tag::user_guide[] + @Test + void timeoutExceeded() { + // The following assertion fails with an error message similar to: + // execution exceeded timeout of 10 ms by 91 ms + assertTimeout(ofMillis(10), () -> { + // Simulate task that takes more than 10 ms. + Thread.sleep(100); + }); + } + + // end::user_guide[] + @extensions.ExpectToFail + // tag::user_guide[] + @Test + void timeoutExceededWithPreemptiveTermination() { + // The following assertion fails with an error message similar to: + // execution timed out after 10 ms + assertTimeoutPreemptively(ofMillis(10), () -> { + // Simulate task that takes more than 10 ms. + Thread.sleep(100); + }); + } + + private static String greeting() { + return "Hello, World!"; + } + +} +// end::user_guide[] +// @formatter:on \ No newline at end of file diff --git a/pom.xml b/pom.xml index 85760e5..c89d2fc 100644 --- a/pom.xml +++ b/pom.xml @@ -55,6 +55,10 @@ 2.10.4 1.6 2.5.3 + 0.7.9 + 1.4.1 + 1.5.6 + 1.5.0-alpha.16 @@ -73,6 +77,12 @@ junit-jupiter-engine test + + org.pitest + pitest-parent + ${pitest.version} + pom + @@ -152,6 +162,89 @@ + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.plugin.version} + + + + prepare-agent + + + + report + test + + report + + + + + + + + org.pitest + pitest-maven + ${pitest.version} + + + org.pitest + pitest-junit5-plugin + 0.6 + + + + + + + + + + + + + + + org.asciidoctor + asciidoctor-maven-plugin + ${asciidoctor-maven.plugin.version} + + + org.asciidoctor + asciidoctorj-pdf + ${asciidoctorj.pdf.version} + + + + + output-html + generate-resources + + process-asciidoc + + + + + documentation/src/docs/asciidoc + target/docbook/en-US + html5 + pdf + + coderay + + 4 + font + ${project.version} + true + left + + ${project.basedir}/documentation/src/test/java + + + \ No newline at end of file diff --git a/src/main/java/io/github/daniloarcidiacono/commons/lang/Composite.java b/src/main/java/io/github/daniloarcidiacono/commons/lang/Composite.java new file mode 100644 index 0000000..355bd9b --- /dev/null +++ b/src/main/java/io/github/daniloarcidiacono/commons/lang/Composite.java @@ -0,0 +1,111 @@ +package io.github.daniloarcidiacono.commons.lang; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +/** + * Base class for an object which aggregates a list of elements. + * @param type of the component + * + * @author Danilo Arcidiacono + */ +public class Composite { + protected List components = new ArrayList<>(); + + public Composite() { + } + + public Composite(final Collection component) { + components.addAll(component); + } + + public Composite(final T ...component) { + Collections.addAll(components, component); + } + + public Composite removeAll() { + components.clear(); + return this; + } + + public Composite add(final T component) { + components.add(component); + return this; + } + + public Composite add(final T ...component) { + Collections.addAll(components, component); + return this; + } + + public Composite addBefore(final T before, final T component) { + final int index = components.indexOf(before); + if (index != -1) { + components.add(index, component); + } + + return this; + } + + public Composite addAfter(final T after, final T component) { + final int index = components.indexOf(after); + if (index != -1) { + components.add(index + 1, component); + } + + return this; + } + + public Composite addBefore(final T before, final T ...component) { + int index = components.indexOf(before); + if (index != -1) { + for (T t : component) { + components.add(index, t); + index++; + } + } + + return this; + } + + public Composite addAfter(final T after, final T ...component) { + int index = components.indexOf(after); + if (index != -1) { + for (T t : component) { + components.add(index + 1, t); + index++; + } + } + + return this; + } + + public Composite remove(final T component) { + components.remove(component); + return this; + } + + public Composite remove(final T ...component) { + for (T t : component) { + components.remove(t); + } + + return this; + } + + public U get(final Class clazz) { + for (T component : components) { + if (component.getClass().equals(clazz)) { + return (U)component; + } + } + + return null; + } + + public List getComponents() { + return components; + } +} diff --git a/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java b/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java new file mode 100644 index 0000000..fc7f852 --- /dev/null +++ b/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java @@ -0,0 +1,61 @@ +package io.github.daniloarcidiacono.commons.lang; + +import java.io.IOException; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.Scanner; + +/** + * Miscellaneous Java file utility methods. + * + * @author Danilo Arcidiacono + */ +public abstract class FileCommons { + /** + * Deletes Folder with all of its content. + * Symbolic links are NOT followed. + * @param folder path to folder which should be deleted + */ + public static void deleteFolder(final Path folder) throws IOException { + if (!Files.exists(folder) || !Files.isDirectory(folder)) { + return; + } + + // https://docs.oracle.com/javase/tutorial/essential/io/walk.html + // By default, walkFileTree does not follow symbolic links. + Files.walkFileTree(folder, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + Files.delete(file); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + if (exc != null) { + throw exc; + } + + Files.delete(dir); + return FileVisitResult.CONTINUE; + } + }); + } + + /** + * Reads a text file from the given path + * @see Utils to read resource text file to String (Java) + * @param path the path to load + * @return the file content + */ + public static String loadResource(final String path) { + final Scanner scanner = new Scanner(FileCommons.class.getClassLoader().getResourceAsStream(path), "UTF-8").useDelimiter("\\A"); + + if (scanner.hasNext()) { + return scanner.next(); + } + + // Using scanner.next() on empty files throws NoSuchElementException + return ""; + } +} diff --git a/src/main/java/io/github/daniloarcidiacono/commons/lang/ReflectiveCommons.java b/src/main/java/io/github/daniloarcidiacono/commons/lang/ReflectiveCommons.java index 0a34dd6..100dff4 100644 --- a/src/main/java/io/github/daniloarcidiacono/commons/lang/ReflectiveCommons.java +++ b/src/main/java/io/github/daniloarcidiacono/commons/lang/ReflectiveCommons.java @@ -8,7 +8,6 @@ /** * Miscellaneous Java Reflection utility methods. - * * @author Danilo Arcidiacono */ public abstract class ReflectiveCommons { @@ -38,4 +37,21 @@ public static List getMethodsAnnotatedWith(final Class type, final Cl return methods; } + + /** + * Returns the list of the classes enclosing the specified class. + * @param clazz + * @return the list of the classes enclosing the specified class. + */ + public static List> getEnclosingClasses(final Class clazz) { + final List> enclosingClasses = new ArrayList<>(); + + Class current = clazz; + do { + enclosingClasses.add(0, current); + current = current.getEnclosingClass(); + } while (current != null); + + return enclosingClasses; + } } diff --git a/src/main/java/io/github/daniloarcidiacono/commons/lang/StringCommons.java b/src/main/java/io/github/daniloarcidiacono/commons/lang/StringCommons.java index 59434c0..12b2374 100644 --- a/src/main/java/io/github/daniloarcidiacono/commons/lang/StringCommons.java +++ b/src/main/java/io/github/daniloarcidiacono/commons/lang/StringCommons.java @@ -85,4 +85,16 @@ public static String listToString(final Iterable collection) { sb.append(" }"); return sb.toString(); } + + public static String singleQuote(final String str) { + return quote(str,"'"); + } + + public static String doubleQuote(final String str) { + return quote(str,"\""); + } + + public static String quote(final String str, final String quote) { + return quote + str + quote; + } } From 0b8029ea2335ace7e6fa6113fbc3ee19d6697785 Mon Sep 17 00:00:00 2001 From: Danilo Arcidiacono Date: Fri, 16 Nov 2018 10:11:50 +0100 Subject: [PATCH 02/11] Add Travis config file. Refactor POM. --- .travis.yml | 4 ++ pom.xml | 137 +++++++++++++++++++--------------------------------- 2 files changed, 54 insertions(+), 87 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..cb7498f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: java +jdk: oraclejdk8 +sudo: false +script: mvn clean package \ No newline at end of file diff --git a/pom.xml b/pom.xml index c89d2fc..dfe14c4 100644 --- a/pom.xml +++ b/pom.xml @@ -54,9 +54,7 @@ 3.0.1 2.10.4 1.6 - 2.5.3 0.7.9 - 1.4.1 1.5.6 1.5.0-alpha.16 @@ -77,12 +75,6 @@ junit-jupiter-engine test - - org.pitest - pitest-parent - ${pitest.version} - pom - @@ -127,85 +119,6 @@ - - - maven-surefire-plugin - ${maven-surefire.plugin.version} - - - org.junit.platform - junit-platform-surefire-provider - ${junit.platform.version} - - - - - - - org.apache.maven.plugins - maven-release-plugin - ${maven-release.plugin.version} - - - - - org.apache.maven.plugins - maven-gpg-plugin - ${maven-gpg.plugin.version} - - - sign-artifacts - verify - - sign - - - - - - - - org.jacoco - jacoco-maven-plugin - ${jacoco.plugin.version} - - - - prepare-agent - - - - report - test - - report - - - - - - - - org.pitest - pitest-maven - ${pitest.version} - - - org.pitest - pitest-junit5-plugin - 0.6 - - - - - - - - - - - - org.asciidoctor @@ -245,6 +158,56 @@ + + + + maven-surefire-plugin + ${maven-surefire.plugin.version} + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.plugin.version} + + + + prepare-agent + + + + report + test + + report + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From fc2bab5375cf74477ea29fe249c5c6480dd46ac4 Mon Sep 17 00:00:00 2001 From: Danilo Arcidiacono Date: Fri, 16 Nov 2018 14:43:52 +0100 Subject: [PATCH 03/11] Add codecov to .travis.yml --- .travis.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cb7498f..f45a7d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,10 @@ language: java jdk: oraclejdk8 + +# faster builds sudo: false -script: mvn clean package \ No newline at end of file + +script: mvn clean package + +after_success: + - bash <(curl -s https://codecov.io/bash) \ No newline at end of file From 31312fae5680d2ee192f6168545edd3c91aba820 Mon Sep 17 00:00:00 2001 From: Danilo Arcidiacono Date: Fri, 16 Nov 2018 15:05:30 +0100 Subject: [PATCH 04/11] Add test coverage checks. Update jacoco plugin to 0.8.2. --- pom.xml | 31 ++++++++++++++++++- .../commons/lang/FileCommons.java | 1 + .../commons/lang/ReflectiveCommons.java | 2 +- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index dfe14c4..18000a5 100644 --- a/pom.xml +++ b/pom.xml @@ -54,7 +54,7 @@ 3.0.1 2.10.4 1.6 - 0.7.9 + 0.8.2 1.5.6 1.5.0-alpha.16 @@ -183,6 +183,35 @@ prepare-agent + + + + check + + check + + + + + + CLASS + + + LINE + COVEREDRATIO + 0.80 + + + BRANCH + COVEREDRATIO + 0.80 + + + + + + + report test diff --git a/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java b/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java index fc7f852..087134f 100644 --- a/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java +++ b/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java @@ -15,6 +15,7 @@ public abstract class FileCommons { * Deletes Folder with all of its content. * Symbolic links are NOT followed. * @param folder path to folder which should be deleted + * @throws IOException */ public static void deleteFolder(final Path folder) throws IOException { if (!Files.exists(folder) || !Files.isDirectory(folder)) { diff --git a/src/main/java/io/github/daniloarcidiacono/commons/lang/ReflectiveCommons.java b/src/main/java/io/github/daniloarcidiacono/commons/lang/ReflectiveCommons.java index 100dff4..ea938d4 100644 --- a/src/main/java/io/github/daniloarcidiacono/commons/lang/ReflectiveCommons.java +++ b/src/main/java/io/github/daniloarcidiacono/commons/lang/ReflectiveCommons.java @@ -40,7 +40,7 @@ public static List getMethodsAnnotatedWith(final Class type, final Cl /** * Returns the list of the classes enclosing the specified class. - * @param clazz + * @param clazz the starting class * @return the list of the classes enclosing the specified class. */ public static List> getEnclosingClasses(final Class clazz) { From bc2e9582f9c83849ea732330b3c3ed304acfe43d Mon Sep 17 00:00:00 2001 From: Danilo Arcidiacono Date: Fri, 16 Nov 2018 18:18:32 +0100 Subject: [PATCH 05/11] Fix travis.yml (add verify phase). Add build status and license badges. --- .travis.yml | 3 ++- README.md | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f45a7d9..390046f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,8 @@ jdk: oraclejdk8 # faster builds sudo: false -script: mvn clean package +script: + - mvn clean verify package after_success: - bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/README.md b/README.md index 5e8988a..9905fa9 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ [![Maven Central](https://img.shields.io/maven-central/v/io.github.daniloarcidiacono/commons-lang.svg?label=Maven%20Central)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22io.github.daniloarcidiacono%22%20a%3A%22commons-lang%22) +[![Build Status](https://travis-ci.org/daniloarcidiacono/commons-lang.svg?branch=dev)](https://travis-ci.org/daniloarcidiacono/commons-lang) [![codecov](https://codecov.io/gh/daniloarcidiacono/commons-lang/branch/dev/graph/badge.svg)](https://codecov.io/gh/daniloarcidiacono/commons-lang) +[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) # Java language utilities \ No newline at end of file From f76777a3853740a0bf0252b11ba7b33c349d2bba Mon Sep 17 00:00:00 2001 From: Danilo Arcidiacono Date: Thu, 10 Jan 2019 21:04:53 +0100 Subject: [PATCH 06/11] Move Composite to patterns subpackage. Refactor POM. Add test coverage constraints. Remove travis config file. Remove documentation. --- .travis.yml | 11 - CHANGELOG.md | 18 ++ CODEOWNERS | 1 + LICENSE | 21 ++ LICENSE.md | 20 -- README.md | 4 +- documentation/README.md | 24 -- documentation/src/docs/asciidoc/index.adoc | 8 - documentation/src/docs/asciidoc/overview.adoc | 170 ------------ .../src/test/java/example/AssertionsDemo.java | 145 ---------- pom.xml | 257 +++++++++++------- .../commons/lang/FileCommons.java | 4 +- .../commons/lang/ReflectiveCommons.java | 1 - .../commons/lang/StringCommons.java | 2 - .../lang/{ => patterns}/Composite.java | 4 +- .../commons/lang/FileCommonsTest.java | 17 ++ .../commons/lang/ReflectiveCommonsTest.java | 12 +- .../commons/lang/StringCommonsTest.java | 9 +- .../commons/lang/patterns/CompositeTest.java | 10 + 19 files changed, 247 insertions(+), 491 deletions(-) delete mode 100644 .travis.yml create mode 100644 CHANGELOG.md create mode 100644 CODEOWNERS create mode 100644 LICENSE delete mode 100644 LICENSE.md delete mode 100644 documentation/README.md delete mode 100644 documentation/src/docs/asciidoc/index.adoc delete mode 100644 documentation/src/docs/asciidoc/overview.adoc delete mode 100644 documentation/src/test/java/example/AssertionsDemo.java rename src/main/java/io/github/daniloarcidiacono/commons/lang/{ => patterns}/Composite.java (96%) create mode 100644 src/test/java/io/github/daniloarcidiacono/commons/lang/FileCommonsTest.java create mode 100644 src/test/java/io/github/daniloarcidiacono/commons/lang/patterns/CompositeTest.java diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 390046f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: java -jdk: oraclejdk8 - -# faster builds -sudo: false - -script: - - mvn clean verify package - -after_success: - - bash <(curl -s https://codecov.io/bash) \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..ace11ac --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,18 @@ +# Version 0.1.0 (2019-01-10) + +### Features + +* `FileCommons` utility class for I/O and filesystem handling +* `Composite` utility class for related design pattern +* `getEnclosingClasses()` method to `ReflectiveCommons` +* `singleQuote()`, `doubleQuote()` and `quote()` methods to `StringCommons` +* **tests:** Switch to JaCoCo for test reporting +* **chore:** Add `CHANGELOG` and `CODEOWNERS` files +* **build:** Add test coverage constraints +* **build:** Add `docs` and `ossrh` Maven profiles + +# Version 0.0.1 (2018-08-18) + +### Features +* `StringCommons` utility class for manipulating strings +* `ReflectiveCommons` utility class for reflection diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..4152899 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @daniloarcidiacono diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..8696066 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Danilo Arcidiacono + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index 58556e5..0000000 --- a/LICENSE.md +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2018-2018 Danilo Arcidiacono, https://github.com/daniloarcidiacono/commons-lang - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 9905fa9..857e620 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![Maven Central](https://img.shields.io/maven-central/v/io.github.daniloarcidiacono/commons-lang.svg?label=Maven%20Central)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22io.github.daniloarcidiacono%22%20a%3A%22commons-lang%22) -[![Build Status](https://travis-ci.org/daniloarcidiacono/commons-lang.svg?branch=dev)](https://travis-ci.org/daniloarcidiacono/commons-lang) [![codecov](https://codecov.io/gh/daniloarcidiacono/commons-lang/branch/dev/graph/badge.svg)](https://codecov.io/gh/daniloarcidiacono/commons-lang) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) -# Java language utilities \ No newline at end of file +# Java language utilities + diff --git a/documentation/README.md b/documentation/README.md deleted file mode 100644 index 3f22e81..0000000 --- a/documentation/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# commons-lang User Guide - -This subproject contains the AsciiDoc sources for the commons-lang User Guide. - -## Structure - -- `src/docs/asciidoc`: AsciiDoc files -- `src/test/java`: Java test source code that can be included in the AsciiDoc files -- `src/test/resources`: Classpath resources that can be included in the AsciiDoc files or - used in tests - -## Usage - -### Generate AsciiDoc - -This following Gradle command generates the HTML version of the User Guide as -`build/asciidoc/index.html`. - -``` -gradlew asciidoctor -``` - -On Linux operating systems, the `graphviz` package providing `/usr/bin/dot` must be -installed in order to generate the User Guide. \ No newline at end of file diff --git a/documentation/src/docs/asciidoc/index.adoc b/documentation/src/docs/asciidoc/index.adoc deleted file mode 100644 index 7bf4c99..0000000 --- a/documentation/src/docs/asciidoc/index.adoc +++ /dev/null @@ -1,8 +0,0 @@ -[[user-guide]] -= commons-lang User Guide -Danilo Arcidiacono - -:sectnums: - -include::overview.adoc[] - diff --git a/documentation/src/docs/asciidoc/overview.adoc b/documentation/src/docs/asciidoc/overview.adoc deleted file mode 100644 index 93269f8..0000000 --- a/documentation/src/docs/asciidoc/overview.adoc +++ /dev/null @@ -1,170 +0,0 @@ -[[overview]] -== Overview - -The goal of this document is to provide comprehensive reference documentation for -programmers writing tests, extension authors, and engine authors as well as build tool -and IDE vendors. - -ifdef::backend-html5[This document is also available as a link:index.pdf[PDF download].] - -[TIP] -.Translations -==== -This document is also available in http://sjyuan.cc/junit5/user-guide-cn[Simplified Chinese] -and https://udzuki.jp/public/junit5-user-guide-ja[Japanese]. -==== - -[[overview-what-is-junit-5]] -=== What is JUnit 5? - -Unlike previous versions of JUnit, JUnit 5 is composed of several different modules from -three different sub-projects. - -**JUnit 5 = _JUnit Platform_ + _JUnit Jupiter_ + _JUnit Vintage_** - -The **JUnit Platform** serves as a foundation for <> on the JVM. It also defines the `{TestEngine}` API for developing a testing -framework that runs on the platform. Furthermore, the platform provides a -<> to launch the platform from the -command line and build plugins for <> and -<> as well as a -<> for running any `TestEngine` -on the platform. - -**JUnit Jupiter** is the combination of the new <> and -<> for writing tests and extensions in JUnit 5. The Jupiter -sub-project provides a `TestEngine` for running Jupiter based tests on the platform. - -**JUnit Vintage** provides a `TestEngine` for running JUnit 3 and JUnit 4 based tests on -the platform. - -[[overview-java-versions]] -=== Supported Java Versions - -JUnit 5 requires Java 8 (or higher) at runtime. However, you can still test code that -has been compiled with previous versions of the JDK. - - -[[overview-getting-help]] -=== Getting Help - -Ask JUnit 5 related questions on {StackOverflow} or chat with us on {Gitter}. - -[[installation]] -== Installation - -Artifacts for final releases and milestones are deployed to Maven Central. - -Snapshot artifacts are deployed to Sonatype's {snapshot-repo}[snapshots repository] under -{snapshot-repo}/org/junit/[/org/junit]. - -[[dependency-metadata]] -=== Dependency Metadata - -[[dependency-metadata-junit-platform]] -==== JUnit Platform - -* *Group ID*: `org.junit.platform` -* *Version*: `{platform-version}` -* *Artifact IDs*: - `junit-platform-commons`:: - Internal common library/utilities of JUnit. These utilities are intended solely for usage within - the JUnit framework itself. _Any usage by external parties is not supported._ Use at your own - risk! - `junit-platform-console`:: - Support for discovering and executing tests on the JUnit Platform from the console. See - <> for details. - `junit-platform-console-standalone`:: - An executable JAR with all dependencies included is provided at Maven Central under the - https://repo1.maven.org/maven2/org/junit/platform/junit-platform-console-standalone[junit-platform-console-standalone] - directory. See <> for details. - `junit-platform-engine`:: - Public API for test engines. See <> for details. - `junit-platform-launcher`:: - Public API for configuring and launching test plans -- typically used by IDEs and build tools. - See <> for details. - `junit-platform-runner`:: - Runner for executing tests and test suites on the JUnit Platform in a JUnit 4 - environment. See <> for details. - `junit-platform-suite-api`:: - Annotations for configuring test suites on the JUnit Platform. Supported by the - <> and possibly by third-party - `TestEngine` implementations. - `junit-platform-surefire-provider`:: - Support for discovering and executing tests on the JUnit Platform using - <>. - -[[dependency-metadata-junit-jupiter]] -==== JUnit Jupiter - -* *Group ID*: `org.junit.jupiter` -* *Version*: `{jupiter-version}` -* *Artifact IDs*: - `junit-jupiter-api`:: - JUnit Jupiter API for <> and <>. - `junit-jupiter-engine`:: - JUnit Jupiter test engine implementation, only required at runtime. - `junit-jupiter-params`:: - Support for <> in JUnit Jupiter. - `junit-jupiter-migrationsupport`:: - Migration support from JUnit 4 to JUnit Jupiter, - only required for running selected JUnit 4 rules. - -[[dependency-metadata-junit-vintage]] -==== JUnit Vintage - -* *Group ID*: `org.junit.vintage` -* *Version*: `{vintage-version}` -* *Artifact ID*: - `junit-vintage-engine`:: - JUnit Vintage test engine implementation that allows to run vintage JUnit tests, i.e. tests - written in the JUnit 3 or JUnit 4 style, on the new JUnit Platform. - -[[dependency-metadata-junit-bom]] -==== Bill of Materials (BOM) - -The _Bill of Materials_ POM provided under the following Maven coordinates can be used to -ease dependency management when referencing multiple of the above artifacts using -https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies[Maven] -or https://docs.gradle.org/current/userguide/managing_transitive_dependencies.html#sec:bom_import[Gradle]. - -* *Group ID*: `org.junit` -* *Artifact ID*: `junit-bom` -* *Version*: `{bom-version}` - -[[dependency-metadata-dependencies]] -==== Dependencies - -All of the above artifacts have a dependency in their published Maven POMs on -the following _@API Guardian_ JAR. - -* *Group ID*: `org.apiguardian` -* *Artifact ID*: `apiguardian-api` -* *Version*: `{apiguardian-version}` - -In addition, most of the above artifacts have a direct or transitive dependency to the -following _OpenTest4J_ JAR. - -* *Group ID*: `org.opentest4j` -* *Artifact ID*: `opentest4j` -* *Version*: `{ota4j-version}` - -[[dependency-diagram]] -=== Dependency Diagram - -[[dependency-metadata-junit-jupiter-samples]] -=== JUnit Jupiter Sample Projects - -The {junit5-samples-repo}[`junit5-samples`] repository hosts a collection of sample -projects based on JUnit Jupiter and JUnit Vintage. You'll find the respective -`build.gradle` and `pom.xml` in the projects below. - -* For Gradle, check out the `{junit5-jupiter-starter-gradle}` project. -* For Maven, check out the `{junit5-jupiter-starter-maven}` project. - - -== Using include with a remote file -[source,java,indent=0] ----- -include::{testDir}/example/AssertionsDemo.java[tag=user_guide] ----- \ No newline at end of file diff --git a/documentation/src/test/java/example/AssertionsDemo.java b/documentation/src/test/java/example/AssertionsDemo.java deleted file mode 100644 index 6254ec7..0000000 --- a/documentation/src/test/java/example/AssertionsDemo.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright 2015-2018 the original author or authors. - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v2.0 which - * accompanies this distribution and is available at - * - * http://www.eclipse.org/legal/epl-v20.html - */ - -package example; - -// @formatter:off -// tag::user_guide[] -import static java.time.Duration.ofMillis; -import static java.time.Duration.ofMinutes; -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTimeout; -import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Test; - -class AssertionsDemo { - - // end::user_guide[] - Person person = new Person("John", "Doe"); - - // tag::user_guide[] - @Test - void standardAssertions() { - assertEquals(2, 2); - assertEquals(4, 4, "The optional assertion message is now the last parameter."); - assertTrue('a' < 'b', () -> "Assertion messages can be lazily evaluated -- " - + "to avoid constructing complex messages unnecessarily."); - } - - @Test - void groupedAssertions() { - // In a grouped assertion all assertions are executed, and any - // failures will be reported together. - assertAll("person", - () -> assertEquals("John", person.getFirstName()), - () -> assertEquals("Doe", person.getLastName()) - ); - } - - @Test - void dependentAssertions() { - // Within a code block, if an assertion fails the - // subsequent code in the same block will be skipped. - assertAll("properties", - () -> { - String firstName = person.getFirstName(); - assertNotNull(firstName); - - // Executed only if the previous assertion is valid. - assertAll("first name", - () -> assertTrue(firstName.startsWith("J")), - () -> assertTrue(firstName.endsWith("n")) - ); - }, - () -> { - // Grouped assertion, so processed independently - // of results of first name assertions. - String lastName = person.getLastName(); - assertNotNull(lastName); - - // Executed only if the previous assertion is valid. - assertAll("last name", - () -> assertTrue(lastName.startsWith("D")), - () -> assertTrue(lastName.endsWith("e")) - ); - } - ); - } - - @Test - void exceptionTesting() { - Throwable exception = assertThrows(IllegalArgumentException.class, () -> { - throw new IllegalArgumentException("a message"); - }); - assertEquals("a message", exception.getMessage()); - } - - @Test - void timeoutNotExceeded() { - // The following assertion succeeds. - assertTimeout(ofMinutes(2), () -> { - // Perform task that takes less than 2 minutes. - }); - } - - @Test - void timeoutNotExceededWithResult() { - // The following assertion succeeds, and returns the supplied object. - String actualResult = assertTimeout(ofMinutes(2), () -> { - return "a result"; - }); - assertEquals("a result", actualResult); - } - - @Test - void timeoutNotExceededWithMethod() { - // The following assertion invokes a method reference and returns an object. - String actualGreeting = assertTimeout(ofMinutes(2), AssertionsDemo::greeting); - assertEquals("Hello, World!", actualGreeting); - } - - // end::user_guide[] - @extensions.ExpectToFail - // tag::user_guide[] - @Test - void timeoutExceeded() { - // The following assertion fails with an error message similar to: - // execution exceeded timeout of 10 ms by 91 ms - assertTimeout(ofMillis(10), () -> { - // Simulate task that takes more than 10 ms. - Thread.sleep(100); - }); - } - - // end::user_guide[] - @extensions.ExpectToFail - // tag::user_guide[] - @Test - void timeoutExceededWithPreemptiveTermination() { - // The following assertion fails with an error message similar to: - // execution timed out after 10 ms - assertTimeoutPreemptively(ofMillis(10), () -> { - // Simulate task that takes more than 10 ms. - Thread.sleep(100); - }); - } - - private static String greeting() { - return "Hello, World!"; - } - -} -// end::user_guide[] -// @formatter:on \ No newline at end of file diff --git a/pom.xml b/pom.xml index 18000a5..8ace774 100644 --- a/pom.xml +++ b/pom.xml @@ -3,6 +3,7 @@ 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"> 4.0.0 + io.github.daniloarcidiacono commons-lang 0.0.1-SNAPSHOT @@ -10,36 +11,31 @@ Java Language utilities Java Language utilities http://github.com/daniloarcidiacono/commons-lang + MIT License http://www.opensource.org/licenses/mit-license.php + Danilo Arcidiacono danilo.arcidiacono@gmail.com + scm:git:git@github.com:daniloarcidiacono/commons-lang.git scm:git:git@github.com:daniloarcidiacono/commons-lang.git https://github.com/daniloarcidiacono/commons-lang.git + https://github.com/daniloarcidiacono/commons-lang - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - + UTF-8 1.8 @@ -50,14 +46,17 @@ 3.7.0 - 2.21.0 + 2.22.0 3.0.1 - 2.10.4 - 1.6 + 2.7 0.8.2 - 1.5.6 - 1.5.0-alpha.16 + + + + 0.80 + 0.80 + @@ -69,6 +68,7 @@ + org.junit.jupiter @@ -76,6 +76,128 @@ test + + + + docs + + + 2.10.4 + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc.plugin.version} + + + attach-javadocs + + jar + + + + + + + + + + ossrh + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + 1.6.8 + 1.6 + + + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg.plugin.version} + + + sign-artifacts + verify + + sign + + + + + + + + maven-deploy-plugin + + true + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-maven.plugin.version} + true + + ossrh + https://oss.sonatype.org/ + + + + + + + + deploy-to-sonatype + deploy + + deploy + + + + + + + + + + + @@ -104,61 +226,6 @@ - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc.plugin.version} - - - attach-javadocs - - jar - - - - - - - - org.asciidoctor - asciidoctor-maven-plugin - ${asciidoctor-maven.plugin.version} - - - org.asciidoctor - asciidoctorj-pdf - ${asciidoctorj.pdf.version} - - - - - output-html - generate-resources - - process-asciidoc - - - - - documentation/src/docs/asciidoc - target/docbook/en-US - html5 - pdf - - coderay - - 4 - font - ${project.version} - true - left - - ${project.basedir}/documentation/src/test/java - - - - maven-surefire-plugin @@ -179,64 +246,58 @@ ${jacoco.plugin.version} + default-prepare-agent prepare-agent - - check + default-report + + report + + + + + + default-check check - + CLASS LINE COVEREDRATIO - 0.80 + ${line.coverage.ratio} BRANCH COVEREDRATIO - 0.80 + ${branch.coverage.ratio} - - - report - test - - report - - - - - - - - - - - - - - - - - + + + org.codehaus.mojo + versions-maven-plugin + ${versions-maven.plugin.version} + \ No newline at end of file diff --git a/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java b/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java index 087134f..aac4e6a 100644 --- a/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java +++ b/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java @@ -7,8 +7,6 @@ /** * Miscellaneous Java file utility methods. - * - * @author Danilo Arcidiacono */ public abstract class FileCommons { /** @@ -44,7 +42,7 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx } /** - * Reads a text file from the given path + * Reads a text file from the given path. * @see Utils to read resource text file to String (Java) * @param path the path to load * @return the file content diff --git a/src/main/java/io/github/daniloarcidiacono/commons/lang/ReflectiveCommons.java b/src/main/java/io/github/daniloarcidiacono/commons/lang/ReflectiveCommons.java index ea938d4..a24d13e 100644 --- a/src/main/java/io/github/daniloarcidiacono/commons/lang/ReflectiveCommons.java +++ b/src/main/java/io/github/daniloarcidiacono/commons/lang/ReflectiveCommons.java @@ -8,7 +8,6 @@ /** * Miscellaneous Java Reflection utility methods. - * @author Danilo Arcidiacono */ public abstract class ReflectiveCommons { /** diff --git a/src/main/java/io/github/daniloarcidiacono/commons/lang/StringCommons.java b/src/main/java/io/github/daniloarcidiacono/commons/lang/StringCommons.java index 12b2374..d896313 100644 --- a/src/main/java/io/github/daniloarcidiacono/commons/lang/StringCommons.java +++ b/src/main/java/io/github/daniloarcidiacono/commons/lang/StringCommons.java @@ -7,8 +7,6 @@ *

This class delivers some simple functionality that should really be * provided by the core Java {@link String} and {@link StringBuilder} * classes. - * - * @author Danilo Arcidiacono */ public abstract class StringCommons { /** diff --git a/src/main/java/io/github/daniloarcidiacono/commons/lang/Composite.java b/src/main/java/io/github/daniloarcidiacono/commons/lang/patterns/Composite.java similarity index 96% rename from src/main/java/io/github/daniloarcidiacono/commons/lang/Composite.java rename to src/main/java/io/github/daniloarcidiacono/commons/lang/patterns/Composite.java index 355bd9b..8a38466 100644 --- a/src/main/java/io/github/daniloarcidiacono/commons/lang/Composite.java +++ b/src/main/java/io/github/daniloarcidiacono/commons/lang/patterns/Composite.java @@ -1,4 +1,4 @@ -package io.github.daniloarcidiacono.commons.lang; +package io.github.daniloarcidiacono.commons.lang.patterns; import java.util.ArrayList; import java.util.Collection; @@ -8,8 +8,6 @@ /** * Base class for an object which aggregates a list of elements. * @param type of the component - * - * @author Danilo Arcidiacono */ public class Composite { protected List components = new ArrayList<>(); diff --git a/src/test/java/io/github/daniloarcidiacono/commons/lang/FileCommonsTest.java b/src/test/java/io/github/daniloarcidiacono/commons/lang/FileCommonsTest.java new file mode 100644 index 0000000..006e08f --- /dev/null +++ b/src/test/java/io/github/daniloarcidiacono/commons/lang/FileCommonsTest.java @@ -0,0 +1,17 @@ +package io.github.daniloarcidiacono.commons.lang; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +/** + * Tests for {@link FileCommons} class. + */ +class FileCommonsTest { + @Test + void deleteFolder() { + } + + @Test + void loadResource() { + } +} \ No newline at end of file diff --git a/src/test/java/io/github/daniloarcidiacono/commons/lang/ReflectiveCommonsTest.java b/src/test/java/io/github/daniloarcidiacono/commons/lang/ReflectiveCommonsTest.java index 91d7eb7..417d3a7 100644 --- a/src/test/java/io/github/daniloarcidiacono/commons/lang/ReflectiveCommonsTest.java +++ b/src/test/java/io/github/daniloarcidiacono/commons/lang/ReflectiveCommonsTest.java @@ -4,15 +4,15 @@ import java.lang.annotation.*; import java.lang.reflect.Method; +import java.util.Arrays; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests for {@link ReflectiveCommons} class. - * - * @author Danilo Arcidiacono */ class ReflectiveCommonsTest { @Retention(RetentionPolicy.RUNTIME) @@ -70,4 +70,12 @@ void getMethodsAnnotatedWith() throws NoSuchMethodException { "Methods without the specified annotation are not picked" ); } + + @Test + void getEnclosingClasses() { + assertEquals( + Arrays.asList(ReflectiveCommonsTest.class, Base.class), + ReflectiveCommons.getEnclosingClasses(Base.class) + ); + } } \ No newline at end of file diff --git a/src/test/java/io/github/daniloarcidiacono/commons/lang/StringCommonsTest.java b/src/test/java/io/github/daniloarcidiacono/commons/lang/StringCommonsTest.java index 2289b1c..23ceaea 100644 --- a/src/test/java/io/github/daniloarcidiacono/commons/lang/StringCommonsTest.java +++ b/src/test/java/io/github/daniloarcidiacono/commons/lang/StringCommonsTest.java @@ -8,8 +8,6 @@ /** * Tests for {@link StringCommons} class. - * - * @author Danilo Arcidiacono */ class StringCommonsTest { @Test @@ -39,4 +37,11 @@ void listToString() { assertEquals(StringCommons.listToString(Arrays.asList( "first" )), "{ first }"); assertEquals(StringCommons.listToString(Arrays.asList( "first", "second" )), "{ first, second }"); } + + @Test + void quotes() { + assertEquals(StringCommons.singleQuote("test"), "'test'"); + assertEquals(StringCommons.doubleQuote("test"), "\"test\""); + assertEquals(StringCommons.quote("test", "*"), "*test*"); + } } \ No newline at end of file diff --git a/src/test/java/io/github/daniloarcidiacono/commons/lang/patterns/CompositeTest.java b/src/test/java/io/github/daniloarcidiacono/commons/lang/patterns/CompositeTest.java new file mode 100644 index 0000000..dfeeade --- /dev/null +++ b/src/test/java/io/github/daniloarcidiacono/commons/lang/patterns/CompositeTest.java @@ -0,0 +1,10 @@ +package io.github.daniloarcidiacono.commons.lang.patterns; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +/** + * Tests for {@link Composite} class. + */ +class CompositeTest { +} \ No newline at end of file From c1b64a6f3dc61b9dc216afda349fd4f392ff8705 Mon Sep 17 00:00:00 2001 From: Danilo Arcidiacono Date: Fri, 11 Jan 2019 10:24:39 +0100 Subject: [PATCH 07/11] Implement tests for Composite. --- .../commons/lang/patterns/Composite.java | 64 ++++++++++-- .../commons/lang/FileCommonsTest.java | 1 + .../commons/lang/patterns/CompositeTest.java | 98 +++++++++++++++++++ 3 files changed, 157 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/github/daniloarcidiacono/commons/lang/patterns/Composite.java b/src/main/java/io/github/daniloarcidiacono/commons/lang/patterns/Composite.java index 8a38466..2284a54 100644 --- a/src/main/java/io/github/daniloarcidiacono/commons/lang/patterns/Composite.java +++ b/src/main/java/io/github/daniloarcidiacono/commons/lang/patterns/Composite.java @@ -23,11 +23,6 @@ public Composite(final T ...component) { Collections.addAll(components, component); } - public Composite removeAll() { - components.clear(); - return this; - } - public Composite add(final T component) { components.add(component); return this; @@ -38,6 +33,14 @@ public Composite add(final T ...component) { return this; } + /** + * Adds a component before the specified one. + *

If the specified component is not found, the component is not added. + * + * @param before the component to search for + * @param component the component to add + * @return the class instance, for chaining calls + */ public Composite addBefore(final T before, final T component) { final int index = components.indexOf(before); if (index != -1) { @@ -47,6 +50,14 @@ public Composite addBefore(final T before, final T component) { return this; } + /** + * Adds a component after the specified one. + *

If the specified component is not found, the component is not added. + * + * @param after the component to search for + * @param component the component to add + * @return the class instance, for chaining calls + */ public Composite addAfter(final T after, final T component) { final int index = components.indexOf(after); if (index != -1) { @@ -56,6 +67,12 @@ public Composite addAfter(final T after, final T component) { return this; } + /** + * Multi-component variant of {@link #addBefore(Object, Object)} + * @param before the component to search for + * @param component the components to add + * @return the class instance, for chaining calls + */ public Composite addBefore(final T before, final T ...component) { int index = components.indexOf(before); if (index != -1) { @@ -68,6 +85,12 @@ public Composite addBefore(final T before, final T ...component) { return this; } + /** + * Multi-component variant of {@link #addAfter(Object, Object)} + * @param after the component to search for + * @param component the components to add + * @return the class instance, for chaining calls + */ public Composite addAfter(final T after, final T ...component) { int index = components.indexOf(after); if (index != -1) { @@ -80,11 +103,30 @@ public Composite addAfter(final T after, final T ...component) { return this; } + /** + * Removes every component. + * @return the class instance, for chaining calls + */ + public Composite removeAll() { + components.clear(); + return this; + } + + /** + * Removes the specified component. + * @param component the component to remove. + * @return the class instance, for chaining calls + */ public Composite remove(final T component) { components.remove(component); return this; } + /** + * Removes a set of components. + * @param component the components to remoev + * @return the class instance, for chaining calls + */ public Composite remove(final T ...component) { for (T t : component) { components.remove(t); @@ -93,9 +135,15 @@ public Composite remove(final T ...component) { return this; } + /** + * Searches for the component having the specified type. + * @param clazz the return type class + * @param the return type + * @return the first component having the specified type, or null if it is not found. + */ public U get(final Class clazz) { for (T component : components) { - if (component.getClass().equals(clazz)) { + if (component != null && component.getClass().equals(clazz)) { return (U)component; } } @@ -103,6 +151,10 @@ public U get(final Class clazz) { return null; } + /** + * Returns the list of components. + * @return the list of components. + */ public List getComponents() { return components; } diff --git a/src/test/java/io/github/daniloarcidiacono/commons/lang/FileCommonsTest.java b/src/test/java/io/github/daniloarcidiacono/commons/lang/FileCommonsTest.java index 006e08f..da4f4b0 100644 --- a/src/test/java/io/github/daniloarcidiacono/commons/lang/FileCommonsTest.java +++ b/src/test/java/io/github/daniloarcidiacono/commons/lang/FileCommonsTest.java @@ -5,6 +5,7 @@ /** * Tests for {@link FileCommons} class. + * @see jdk8u-jdk: CreateFileTree utility class */ class FileCommonsTest { @Test diff --git a/src/test/java/io/github/daniloarcidiacono/commons/lang/patterns/CompositeTest.java b/src/test/java/io/github/daniloarcidiacono/commons/lang/patterns/CompositeTest.java index dfeeade..59020c3 100644 --- a/src/test/java/io/github/daniloarcidiacono/commons/lang/patterns/CompositeTest.java +++ b/src/test/java/io/github/daniloarcidiacono/commons/lang/patterns/CompositeTest.java @@ -1,10 +1,108 @@ package io.github.daniloarcidiacono.commons.lang.patterns; import org.junit.jupiter.api.Test; +import java.util.Arrays; import static org.junit.jupiter.api.Assertions.*; /** * Tests for {@link Composite} class. */ class CompositeTest { + @Test + public void testAddBefore() { + final Composite composite = new Composite<>(); + composite.add(2); + composite.add(3); + composite.addBefore(2, 1); + composite.addBefore(1000, 10); + + assertEquals( + Arrays.asList(1, 2, 3), + composite.getComponents() + ); + + composite.addBefore(1, -3, -2, -1, 0); + composite.addBefore(1000, -3, -2, -1, 0); + + assertEquals( + Arrays.asList(-3, -2, -1, 0, 1, 2, 3), + composite.getComponents() + ); + } + + @Test + public void testAddAfter() { + final Composite composite = new Composite<>(); + composite.add(1); + composite.add(2); + composite.add(10); + composite.addAfter(2, 3); + composite.addAfter(1000, 10); + + assertEquals( + Arrays.asList(1, 2, 3, 10), + composite.getComponents() + ); + + composite.addAfter(3, 4, 5, 6, 7, 8, 9); + composite.addAfter(1000, 4, 5, 6, 7, 8, 9); + + assertEquals( + Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), + composite.getComponents() + ); + } + + @Test + public void testRemove() { + final Composite composite = new Composite<>(); + composite.add(1, 2, 3); + composite.remove(2); + + assertEquals( + Arrays.asList(1, 3), + composite.getComponents() + ); + + composite.removeAll(); + assertTrue(composite.getComponents().isEmpty()); + } + + @Test + public void testMultiRemove() { + final Composite composite = new Composite<>( + Arrays.asList(1, 2, 3, 4, 5) + ); + + composite.remove(2, 4); + assertEquals( + Arrays.asList(1, 3, 5), + composite.getComponents() + ); + } + + private static class Base { + } + + private static class DerivedA extends Base { + } + + private static class DerivedB extends Base { + } + + private static class DerivedC extends Base { + } + + @Test + public void testGet() { + final Base a = new Base(); + final Base b = new DerivedA(); + final Base c = new DerivedB(); + final Composite composite = new Composite<>(a, b, c, null); + + assertEquals(composite.get(Base.class), a); + assertEquals(composite.get(DerivedA.class), b); + assertEquals(composite.get(DerivedB.class), c); + assertEquals(composite.get(DerivedC.class), null); + } } \ No newline at end of file From 7a896c91ad4bc1b667b43e8f84e523b436339edf Mon Sep 17 00:00:00 2001 From: Danilo Arcidiacono Date: Fri, 11 Jan 2019 17:07:17 +0100 Subject: [PATCH 08/11] Implement tests for FileCommons. --- pom.xml | 8 +++ .../commons/lang/FileCommons.java | 10 ++- .../commons/lang/FileCommonsTest.java | 66 ++++++++++++++++++- src/test/resources/test.txt | 1 + src/test/resources/test_empty.txt | 0 5 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 src/test/resources/test.txt create mode 100644 src/test/resources/test_empty.txt diff --git a/pom.xml b/pom.xml index 8ace774..06fdb08 100644 --- a/pom.xml +++ b/pom.xml @@ -43,6 +43,7 @@ 5.2.0 1.2.0 + 1.3.0 3.7.0 @@ -75,6 +76,13 @@ junit-jupiter-engine test + + + com.github.marschall + memoryfilesystem + ${memoryfilesystem.version} + test + diff --git a/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java b/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java index aac4e6a..83f86d5 100644 --- a/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java +++ b/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java @@ -1,6 +1,7 @@ package io.github.daniloarcidiacono.commons.lang; import java.io.IOException; +import java.io.InputStream; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.Scanner; @@ -45,10 +46,15 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOEx * Reads a text file from the given path. * @see Utils to read resource text file to String (Java) * @param path the path to load - * @return the file content + * @return the file content, or null if could not be loaded. */ public static String loadResource(final String path) { - final Scanner scanner = new Scanner(FileCommons.class.getClassLoader().getResourceAsStream(path), "UTF-8").useDelimiter("\\A"); + final InputStream resourceAsStream = FileCommons.class.getClassLoader().getResourceAsStream(path); + if (resourceAsStream == null) { + return null; + } + + final Scanner scanner = new Scanner(resourceAsStream, "UTF-8").useDelimiter("\\A"); if (scanner.hasNext()) { return scanner.next(); diff --git a/src/test/java/io/github/daniloarcidiacono/commons/lang/FileCommonsTest.java b/src/test/java/io/github/daniloarcidiacono/commons/lang/FileCommonsTest.java index da4f4b0..dbb0374 100644 --- a/src/test/java/io/github/daniloarcidiacono/commons/lang/FileCommonsTest.java +++ b/src/test/java/io/github/daniloarcidiacono/commons/lang/FileCommonsTest.java @@ -1,7 +1,16 @@ package io.github.daniloarcidiacono.commons.lang; +import com.github.marschall.memoryfilesystem.MemoryFileSystemBuilder; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.*; + +import java.io.IOException; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests for {@link FileCommons} class. @@ -9,10 +18,63 @@ */ class FileCommonsTest { @Test - void deleteFolder() { + void deleteFolder() throws IOException { + try (final FileSystem fs = MemoryFileSystemBuilder.newEmpty().build()) { + // Try to delete a non existing folder (must do nothing) + FileCommons.deleteFolder(fs.getPath("not_existing")); + + // Create the folder that will be deleted + final Path testFolder = fs.getPath("/test"); + Files.createDirectories(testFolder); + Files.createFile(fs.getPath("/test/file1.txt")); + Files.createFile(fs.getPath("/test/file2.txt")); + Files.createFile(fs.getPath("/test/file3.txt")); + + // Create another folder + final Path otherFolder = fs.getPath("/other"); + Files.createDirectories(otherFolder); + Files.createFile(fs.getPath("/other/file1.txt")); + + // Create some symbolic links + Files.createSymbolicLink(fs.getPath("/test/file1_link.txt"), fs.getPath("/other/file1.txt")); + Files.createSymbolicLink(fs.getPath("/test/other_link"), fs.getPath("/other")); + + // Delete the folder + FileCommons.deleteFolder(testFolder); + + // Try to delete a file (must do nothing) + FileCommons.deleteFolder(fs.getPath("/other/file1.txt")); + + // https://docs.oracle.com/javase/tutorial/essential/io/walk.html + // By default, walkFileTree does not follow symbolic links. + final List paths = new ArrayList<>(); + Files.walkFileTree(fs.getPath("/"), new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + paths.add(file.toString()); + return FileVisitResult.CONTINUE; + } + + + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + paths.add(dir.toString()); + return FileVisitResult.CONTINUE; + } + }); + + assertEquals( + Arrays.asList("/", "/other", "/other/file1.txt"), + paths, + "Symbolic links should not be followed" + ); + } } @Test void loadResource() { + assertEquals("test file content", FileCommons.loadResource("test.txt")); + assertEquals("", FileCommons.loadResource("test_empty.txt")); + assertEquals(null, FileCommons.loadResource("test_not_existing.txt")); } } \ No newline at end of file diff --git a/src/test/resources/test.txt b/src/test/resources/test.txt new file mode 100644 index 0000000..2211df3 --- /dev/null +++ b/src/test/resources/test.txt @@ -0,0 +1 @@ +test file content \ No newline at end of file diff --git a/src/test/resources/test_empty.txt b/src/test/resources/test_empty.txt new file mode 100644 index 0000000..e69de29 From 33b297a5f54d5e8d3b7cc7b176a7fb617f660111 Mon Sep 17 00:00:00 2001 From: Danilo Arcidiacono Date: Sat, 12 Jan 2019 10:07:02 +0100 Subject: [PATCH 09/11] Lower branch coverage ratio to 0.50. --- pom.xml | 2 +- .../io/github/daniloarcidiacono/commons/lang/FileCommons.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 06fdb08..ecc77f0 100644 --- a/pom.xml +++ b/pom.xml @@ -55,7 +55,7 @@ 0.80 - 0.80 + 0.50 diff --git a/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java b/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java index 83f86d5..6e2ff53 100644 --- a/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java +++ b/src/main/java/io/github/daniloarcidiacono/commons/lang/FileCommons.java @@ -32,6 +32,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { + // TODO: Find a way to test this branch and increase the branch.coverage.ratio to 0.80 if (exc != null) { throw exc; } From cd38de2cdce4b33c88c32f0b2a50b6d269b8177b Mon Sep 17 00:00:00 2001 From: Danilo Arcidiacono Date: Sat, 12 Jan 2019 13:44:40 +0100 Subject: [PATCH 10/11] Update changelog. Add changelog for latest version. --- CHANGELOG.md | 5 +++-- CHANGELOG_LATEST.md | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 CHANGELOG_LATEST.md diff --git a/CHANGELOG.md b/CHANGELOG.md index ace11ac..2c905ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# Version 0.1.0 (2019-01-10) +# commons-lang 0.1.0 (2019-01-12) ### Features @@ -11,8 +11,9 @@ * **build:** Add test coverage constraints * **build:** Add `docs` and `ossrh` Maven profiles -# Version 0.0.1 (2018-08-18) +# commons-lang 0.0.1 (2018-08-18) ### Features + * `StringCommons` utility class for manipulating strings * `ReflectiveCommons` utility class for reflection diff --git a/CHANGELOG_LATEST.md b/CHANGELOG_LATEST.md new file mode 100644 index 0000000..29b8049 --- /dev/null +++ b/CHANGELOG_LATEST.md @@ -0,0 +1,12 @@ +# commons-lang 0.1.0 + +### Features + +* `FileCommons` utility class for I/O and filesystem handling +* `Composite` utility class for related design pattern +* `getEnclosingClasses()` method to `ReflectiveCommons` +* `singleQuote()`, `doubleQuote()` and `quote()` methods to `StringCommons` +* **tests:** Switch to JaCoCo for test reporting +* **chore:** Add `CHANGELOG` and `CODEOWNERS` files +* **build:** Add test coverage constraints +* **build:** Add `docs` and `ossrh` Maven profiles From a4c14951c5b9d1d668d731c023a59522b6694a27 Mon Sep 17 00:00:00 2001 From: Danilo Arcidiacono Date: Sat, 12 Jan 2019 13:44:55 +0100 Subject: [PATCH 11/11] Add build scripts. Add CircleCI config. Add maven settings for ossrh server. --- .circleci/config.yml | 54 ++++++++++++++++++++++++++++ .mvn/settings.xml | 12 +++++++ scripts/prepare-release.sh | 64 +++++++++++++++++++++++++++++++++ scripts/start-next-iteration.sh | 54 ++++++++++++++++++++++++++++ 4 files changed, 184 insertions(+) create mode 100644 .circleci/config.yml create mode 100644 .mvn/settings.xml create mode 100755 scripts/prepare-release.sh create mode 100755 scripts/start-next-iteration.sh diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..975f001 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,54 @@ +version: 2 +jobs: + build: + # directory where steps will run + working_directory: ~/commons-lang + docker: + - image: daniloarcidiacono/ci-java-node:0.4.0 + + steps: + # check out source code to working directory + - checkout + + # restore the saved cache after the first run or if `pom.xml` has changed + - restore_cache: + key: commons-lang-{{ checksum "pom.xml" }} + + # gets the project dependencies + - run: mvn dependency:go-offline + + # saves the project dependencies + - save_cache: + paths: + - ~/.m2 + key: commons-lang-{{ checksum "pom.xml" }} + + # Build + - run: mvn clean package verify -Pdocs + + # Deploy + - deploy: + name: "Create GitHub release" + command: | + hub release create -a target/commons-lang-$CIRCLE_TAG-javadoc.jar -F CHANGELOG_LATEST.md $CIRCLE_TAG + + # uploads the test metadata from the `target/surefire-reports` directory so that it can show up in the CircleCI dashboard. + - store_test_results: + path: target/surefire-reports + + # store the jar as an artifact + - store_artifacts: + path: target/commons-lang-{{ .Environment.CIRCLE_TAG }}.jar + +workflows: + version: 2 + build_and_deploy: + jobs: + - build: + filters: + tags: + only: /.*/ + branches: + ignore: /.*/ + + diff --git a/.mvn/settings.xml b/.mvn/settings.xml new file mode 100644 index 0000000..6881249 --- /dev/null +++ b/.mvn/settings.xml @@ -0,0 +1,12 @@ + + + + ossrh + ${ossrh.username} + ${ossrh.password} + + + \ No newline at end of file diff --git a/scripts/prepare-release.sh b/scripts/prepare-release.sh new file mode 100755 index 0000000..f99a08e --- /dev/null +++ b/scripts/prepare-release.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +# Check that we are in the root folder +if ! [[ -f "./scripts/prepare-release.sh" ]]; then + (>&2 echo "Script must be run from the root folder, actual $(pwd)") + exit 1 +fi + +# Get the current branch +branch_name=$(git symbolic-ref -q HEAD) +branch_name=${branch_name##refs/heads/} +branch_name=${branch_name:-HEAD} + +# Check that we are in master +if [[ ${branch_name} != 'master' ]]; then + (>&2 echo "Releases can be prepared only on master branch, current one is ${branch_name}!") + exit 1 +fi + +# Check the arguments +if [[ "$#" -ne 1 ]]; then + (>&2 echo "Invalid number of arguments, found $#, expected 1") + echo "prepare-release " + exit 1 +fi + +# Fetch (for picking tags) +git fetch +existing_tag=$(git tag --list | grep $1 | wc -l) +if [[ ${existing_tag} -gt 0 ]]; then + (>&2 echo "Tag $1 already exists, stop.") + exit 1 +fi + +# Merge +echo "Merging from dev" +git merge origin/dev --no-ff --no-commit + +# Check if there are any conflicts +conflicts=$(git ls-files -u | wc -l) +if [[ ${conflicts} -gt 0 ]]; then + (>&2 echo "There are merge conflicts, stop (use git merge --abort to undo changes).") + exit 1 +fi + +# Update the version +echo "Setting project version to $1" +mvn versions:set -DgenerateBackupPoms=false -DnewVersion=$1 + +# Compile with tests +mvn clean verify + +if [[ $? -ne 0 ]]; then + (>&2 echo "Project build failed, stop (use git merge --abort to undo changes).") + exit 1 +fi + +# Success: commit and tag +echo "Build success, creating tagged commit" +git commit -am "chore: version $1" +git tag -a $1 -m "$1" + +# Ready to push! +# git push origin master --tags \ No newline at end of file diff --git a/scripts/start-next-iteration.sh b/scripts/start-next-iteration.sh new file mode 100755 index 0000000..b4c1f23 --- /dev/null +++ b/scripts/start-next-iteration.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +# Check that we are in the root folder +if ! [[ -f "./scripts/start-next-iteration.sh" ]]; then + (>&2 echo "Script must be run from the root folder, actual $(pwd)") + exit 1 +fi + +# Get the current branch +branch_name=$(git symbolic-ref -q HEAD) +branch_name=${branch_name##refs/heads/} +branch_name=${branch_name:-HEAD} + +# Check that we are in dev +if [[ ${branch_name} != 'dev' ]]; then + (>&2 echo "Next iterations can be started only on dev branch, current one is ${branch_name}!") + exit 1 +fi + +# Check the arguments +if [[ "$#" -ne 1 ]]; then + (>&2 echo "Invalid number of arguments, found $#, expected 1") + echo "start-next-iteration " + exit 1 +fi + +# Check that the working tree is clean +if [[ -n $(git status -s) ]]; then + (>&2 echo "Working tree is not clean, stop") + exit 1 +fi + +# Update +git fetch + +# Try to fast forward the dev branch +git merge origin/dev --ff-only + +# Check for no conflicts +if [[ $? -ne 0 ]]; then + (>&2 echo "There are remote changes in dev branch that could not be merged automatically, stop.") + exit 1 +fi + +# Change the version +echo "Setting project version to $1" +mvn versions:set -DgenerateBackupPoms=false -DnewVersion=$1 + +# Success: commit +echo "Success, creating commit" +git commit -am "chore: start next development iteration ($1)" + +# Ready to push! +#git push origin dev \ No newline at end of file