Skip to content

Commit

Permalink
Merge pull request #13 from mauritssilvis/java_darts_modules
Browse files Browse the repository at this point in the history
Turn the Java projects into modules
  • Loading branch information
mauritssilvis authored Mar 20, 2023
2 parents d171b97 + 09761ef commit 3589a19
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 37 deletions.
8 changes: 8 additions & 0 deletions api/java-darts-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to the `java-darts-api` project (see [darts](https://github.
The file format is based on [keep a changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [semantic versioning](https://semver.org/spec/v2.0.0.html).

## [0.6.0] - 2023-03-20

### Changed

#### General

- Wrap the code in a Java module.

## [0.5.0] - 2023-03-19

### Added
Expand Down
12 changes: 1 addition & 11 deletions api/java-darts-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
}

group = "nl.mauritssilvis.darts.java"
version = "0.5.0"
version = "0.6.0"

repositories {
mavenCentral()
Expand Down Expand Up @@ -90,10 +90,6 @@ nexusPublishing {
}

tasks {
processResources {
dependsOn("copyResources")
}

jar {
manifest {
attributes(
Expand All @@ -107,9 +103,3 @@ tasks {
options.memberLevel = JavadocMemberLevel.PACKAGE
}
}

tasks.register<Copy>("copyResources") {
from(projectDir)
into(sourceSets.main.get().output.resourcesDir.toString())
include("LICENSE.md", "README.md")
}
21 changes: 21 additions & 0 deletions api/java-darts-api/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright © 2023 Maurits Silvis
* SPDX-License-Identifier: GPL-3.0-or-later
*/

/**
* The Java module for the Java API of darts.
*
* @author Maurits Silvis
* @since 0.6.0
*/
module nl.mauritssilvis.darts.java.api {
requires static lombok;

exports nl.mauritssilvis.darts.java.api.boards;
exports nl.mauritssilvis.darts.java.api.finders.checkouts;
exports nl.mauritssilvis.darts.java.api.finders.paths;
exports nl.mauritssilvis.darts.java.api.output;
exports nl.mauritssilvis.darts.java.api.settings;
exports nl.mauritssilvis.darts.java.api.tables;
}
8 changes: 8 additions & 0 deletions cli/java-darts-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to the `java-darts-cli` project (see [darts](https://github.
The file format is based on [keep a changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [semantic versioning](https://semver.org/spec/v2.0.0.html).

## [0.6.0] - 2023-03-20

### Changed

#### General

- Wrap the code in a Java module.

## [0.5.0] - 2023-03-19

### Removed
Expand Down
13 changes: 2 additions & 11 deletions cli/java-darts-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
}

group = "nl.mauritssilvis.darts.java"
version = "0.5.0"
version = "0.6.0"

repositories {
mavenCentral()
Expand Down Expand Up @@ -45,6 +45,7 @@ java {

application {
applicationName = "darts"
mainModule.set("nl.mauritssilvis.darts.java.cli")
mainClass.set("nl.mauritssilvis.darts.java.cli.DartsApp")
}

Expand Down Expand Up @@ -105,10 +106,6 @@ nexusPublishing {
}

tasks {
processResources {
dependsOn("copyResources")
}

compileJava {
// Set the location for files generated by picocli
options.compilerArgs.add("-Aproject=${project.group}/${project.name}")
Expand Down Expand Up @@ -142,12 +139,6 @@ tasks {
}
}

tasks.register<Copy>("copyResources") {
from(projectDir)
into(sourceSets.main.get().output.resourcesDir.toString())
include("LICENSE.md", "README.md")
}

tasks.register<Delete>("cleanDist") {
file("bin").deleteRecursively()
file("lib").deleteRecursively()
Expand Down
22 changes: 22 additions & 0 deletions cli/java-darts-cli/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright © 2023 Maurits Silvis
* SPDX-License-Identifier: GPL-3.0-or-later
*/

/**
* The Java module for the Java-based command-line interface for darts.
*
* @author Maurits Silvis
* @since 0.6.0
*/
module nl.mauritssilvis.darts.java.cli {
requires static lombok;

requires nl.mauritssilvis.darts.java.api;
requires nl.mauritssilvis.darts.java.core;
requires info.picocli;

opens nl.mauritssilvis.darts.java.cli to info.picocli;

exports nl.mauritssilvis.darts.java.cli;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

import picocli.CommandLine.IVersionProvider;

import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

/**
* An implementation of the {@code IVersionProvider} class that returns the
* current version of the Java-based command-line toolbox {@code darts} with a
Expand All @@ -18,13 +24,55 @@
class Version implements IVersionProvider {
@Override
public String[] getVersion() {
String title = getClass().getPackage().getImplementationTitle();
String version = getClass().getPackage().getImplementationVersion();
String title = "java-darts-cli";
String version = "";

Attributes attributes = getManifestAttributes(title);

if (!attributes.isEmpty()) {
String implementationTitle = attributes.getValue("Implementation-Title");
String implementationVersion = attributes.getValue("Implementation-Version");

if (implementationTitle != null) {
title = implementationTitle;
}

if (implementationVersion != null) {
version = "-" + implementationVersion;
}
}

return new String[]{
title + " " + version,
title + version,
"Copyright © 2023 Maurits Silvis",
"SPDX-License-Identifier: GPL-3.0-or-later"
};
}

private Attributes getManifestAttributes(String title) {
Attributes emptyAttributes = new Attributes();
Enumeration<URL> resources;

try {
resources = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");
} catch (IOException ignore) {
return emptyAttributes;
}

while (resources.hasMoreElements()) {
URL url = resources.nextElement();

try {
Manifest manifest = new Manifest(url.openStream());
Attributes mainAttributes = manifest.getMainAttributes();

if (title.equals(mainAttributes.getValue("Implementation-Title"))) {
return mainAttributes;
}
} catch (IOException ignore) {
}
}

return emptyAttributes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void getTheVersion(String arg) {
String errString = err.toString();

List<String> elements = List.of(
"java-darts-cli",
"Copyright",
"Maurits Silvis",
"SPDX-License-Identifier: GPL-3.0-or-later"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ void getTheVersion(String arg) {
String errString = err.toString();

List<String> elements = List.of(
"java-darts-cli",
"Copyright",
"Maurits Silvis",
"SPDX-License-Identifier: GPL-3.0-or-later"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ void getTheVersion(String arg) {
String errString = err.toString();

List<String> elements = List.of(
"java-darts-cli",
"Copyright",
"Maurits Silvis",
"SPDX-License-Identifier: GPL-3.0-or-later"
Expand Down
8 changes: 8 additions & 0 deletions core/java-darts-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to the `java-darts-core` project (see [darts](https://github
The file format is based on [keep a changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [semantic versioning](https://semver.org/spec/v2.0.0.html).

## [0.6.0] - 2023-03-20

### Changed

#### General

- Wrap the code in a Java module.

## [0.5.0] - 2023-03-19

### Added
Expand Down
14 changes: 2 additions & 12 deletions core/java-darts-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
}

group = "nl.mauritssilvis.darts.java"
version = "0.5.0"
version = "0.6.0"

repositories {
mavenCentral()
Expand All @@ -27,7 +27,7 @@ dependencies {

testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2")

implementation("nl.mauritssilvis.darts.java:java-darts-api:${project.version}")
api("nl.mauritssilvis.darts.java:java-darts-api:${project.version}")
}

java {
Expand Down Expand Up @@ -97,10 +97,6 @@ nexusPublishing {
}

tasks {
processResources {
dependsOn("copyResources")
}

test {
useJUnitPlatform()
}
Expand All @@ -118,9 +114,3 @@ tasks {
options.memberLevel = JavadocMemberLevel.PACKAGE
}
}

tasks.register<Copy>("copyResources") {
from(projectDir)
into(sourceSets.main.get().output.resourcesDir.toString())
include("LICENSE.md", "README.md")
}
25 changes: 25 additions & 0 deletions core/java-darts-core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright © 2023 Maurits Silvis
* SPDX-License-Identifier: GPL-3.0-or-later
*/

/**
* The Java module for the Java implementation of darts.
*
* @author Maurits Silvis
* @since 0.6.0
*/
module nl.mauritssilvis.darts.java.core {
requires static lombok;

requires transitive nl.mauritssilvis.darts.java.api;

exports nl.mauritssilvis.darts.java.core.boards;
exports nl.mauritssilvis.darts.java.core.boards.output;
exports nl.mauritssilvis.darts.java.core.finders.checkouts;
exports nl.mauritssilvis.darts.java.core.finders.paths;
exports nl.mauritssilvis.darts.java.core.output;
exports nl.mauritssilvis.darts.java.core.settings;
exports nl.mauritssilvis.darts.java.core.tables;
exports nl.mauritssilvis.darts.java.core.tables.output;
}

0 comments on commit 3589a19

Please sign in to comment.