Skip to content

Commit

Permalink
Adds module-info and upgrades source code to java 8
Browse files Browse the repository at this point in the history
  • Loading branch information
fathzer committed Sep 3, 2024
1 parent 2d63c38 commit 174b382
Show file tree
Hide file tree
Showing 26 changed files with 294 additions and 120 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/java8Check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Check java class version
on:
push:
branches:
- "*"
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build and check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
- name: Cache Maven packages
uses: actions/cache@v4
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and check
run: |
mvn -P sonar package
cd java8Test
mvn package
echo "checking ../javaluator-demo/target/javaluator-demo.jar"
java -jar target/javaReleaseTest.jar ../javaluator-demo/target/javaluator-demo.jar 52
# Let check the library itself in case demo pom points to an older release of the library
OUT="$(ls ../javaluator/target/javaluator*.jar | grep -v javadoc.jar | grep -v sources.jar)"
echo "checking $OUT"
java -jar target/javaReleaseTest.jar $OUT 52
OUT="$(ls ../javaluator-examples/target/javaluator-examples*.jar | grep -v javadoc.jar | grep -v sources.jar)"
echo "checking $OUT"
java -jar target/javaReleaseTest.jar $OUT 52
26 changes: 16 additions & 10 deletions DeliveryProcess.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,34 @@
## Deploy the artifact on Maven central

1. Push the code in `master` branch.
It will trigger some workflows. Please note that `tutorial` workflow may fail! It only means [Javaluator tutorial on Javaluator's site](https://javaluator.fathzer.com) require some updates.
If Sonar quality gate fail ... try to fix its complaints ;-)
It will trigger some workflows. Please note that `tutorial` workflow may fail! If it fails, it means that [Javaluator tutorial on Javaluator's site](https://javaluator.fathzer.com) require some updates.
If Sonar quality gate fails ... try to fix its complaints ;-)

2. Run `mvn clean deploy` on the project.
As the compiler target is Java 1.6, it will fail with recent release of Java. Java 8 is able to make the compile.
The easiest way to use java 8 is to [configure a *toolchain*](#HowToConfigureToolchain).
2. Ensure *toolchain* is configured ([see how to do it](#how-to-configure-toolchain)) and the jdk required in [*pom.xml*](https://github.com/fathzer/javaluator/blob/master/pom.xml)) is available.

3. Run `mvn clean deploy` on the project.
Of course, signing material (certificate and its password) are not included in this project: There should be `fathzer_private_key.asc` and `fathzer_key_pwd.txt` files in the user's home directory.

3. Create a release in Github.

## Javaluator's site update

1. Update the [`father/hosting`](https://github.com/fathzer/hosting) private project.
1. If a new demo has to be compiled, run `mvn -P demo clean package` on the project.

2. Update the [`father/hosting`](https://github.com/fathzer/hosting) private project.
- If the `tutorial` workflow fails, have a look at its logs, it should contains the list of files that should be updated in the project. Once the project is updated, retry the failed action, it should succeed.

- Add the version release notes to the `javaluator/www/en/doc/relnotes.txt` file.

2. Don't forget to push the updates in the production site!
3. Don't forget to push the updates in the production site!

## Update javadoc on javadoc.io

Once the Maven artifacts are available on [Maven central](https://search.maven.org/search?q=a:javaluator), open the link `https://javadoc.io/doc/com.fathzer/javaluator/*VERSION*/` were *VERSION* is the new release number.
javadoc.io will process the request and made the new release available after a couple of minutes.

## How to configure toolchain
Add a *toolchain.xml* file](#HowToConfigureToolchain) in your `.m2` directory.
Add a *toolchain.xml* file in your `.m2` directory.

This file should contain something like:
```
Expand All @@ -32,7 +39,7 @@ This file should contain something like:
<toolchain>
<type>jdk</type>
<provides>
<version>8</version>
<version>21</version>
<vendor>sun</vendor>
</provides>
<configuration>
Expand All @@ -41,5 +48,4 @@ This file should contain something like:
</toolchain>
<toolchains>
```
Once it is done, java 8 is activated with the `jdk` system property: `mvn -Djdk=8 clean deploy`

1 change: 1 addition & 0 deletions java8Test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This folder contains a program used by 'java8Check.yml' workflow to check if generated classes are compatible with a java 8 (the exact release is defined in the workflow) virtual machine.
50 changes: 50 additions & 0 deletions java8Test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.fathzer</groupId>
<artifactId>parent-pom</artifactId>
<version>1.0.8</version>
<relativePath></relativePath>
</parent>
<artifactId>java-release-test</artifactId>
<version>0.0.1</version>
<name>java-release-test</name>
<description>A program that tests a jar contains classes compatible with a
specific java release.</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.source.skip>true</maven.source.skip>
<maven.javadoc.skip>true</maven.javadoc.skip>
<maven.install.skip>true</maven.install.skip>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<configuration>
<finalName>javaReleaseTest</finalName>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.fathzer.java.release.Check</mainClass>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
47 changes: 47 additions & 0 deletions java8Test/src/main/java/com/fathzer/java/release/Check.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.fathzer.java.release;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.function.Predicate;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Check {
private static final String CLASS_SUFFIX = ".class";

public static void main(String[] args) {
try {
if (args.length!=2) {
throw new IllegalArgumentException("This program requires two arguments: a jar file path and a maximum class level");
}
final File jar = new File(args[0]);
final int maxRelease = Integer.parseInt(args[1]);
new Check().check(jar, maxRelease, s->s.endsWith("-info.class"));
System.out.println("ok");
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}

private void check(File jar, int maxRelease, Predicate<String> ignored) throws IOException {
try (ZipInputStream zip = new ZipInputStream(new FileInputStream(jar))) {
final DataInputStream data = new DataInputStream(zip);
for (ZipEntry entry = zip.getNextEntry(); entry!=null; entry = zip.getNextEntry()) {
if (!entry.isDirectory() && entry.getName().endsWith(CLASS_SUFFIX) && !ignored.test(entry.getName())) {
if (zip.skip(6)!=6) {
throw new IOException("End of file reached before major class version");
}
final int release = data.readUnsignedShort();
if (release>maxRelease) {
throw new IllegalArgumentException("The major class version of "+entry.getName()+" is "+release);
}
}
}
}
}


}
17 changes: 14 additions & 3 deletions javaluator-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<parent>
<groupId>com.fathzer</groupId>
<artifactId>javaluator-parent-pom</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
</parent>
<artifactId>javaluator-demo</artifactId>
<version>3.0.2</version>
<version>3.0.3</version>

<properties>
<maven.javadoc.skip>true</maven.javadoc.skip>
Expand All @@ -20,7 +20,7 @@
<dependency>
<groupId>com.fathzer</groupId>
<artifactId>javaluator</artifactId>
<version>3.0.4</version>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>com.fathzer</groupId>
Expand All @@ -46,6 +46,17 @@
</manifestEntries>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>module-info.class</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ public class ConstantTableModel extends AbstractTableModel {
private List<Constant> constants;

public ConstantTableModel(Collection<Constant> collection) {
this.constants = new ArrayList<Constant>(collection);
Collections.sort(this.constants, new Comparator<Constant>() {
public int compare(Constant c1, Constant c2) {
return c1.getName().compareTo(c2.getName());
}
});
this.constants = new ArrayList<>(collection);
final Comparator<Constant> cmp = (c1, c2) -> c1.getName().compareTo(c2.getName());
Collections.sort(this.constants, cmp);
}

public int getColumnCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import java.awt.Insets;

import javax.swing.border.TitledBorder;
Expand Down Expand Up @@ -86,8 +84,7 @@ private JLabel getLblNewLabel() {
private TextWidget getExpression() {
if (expression == null) {
expression = new TextWidget();
expression.addPropertyChangeListener(TextWidget.TEXT_PROPERTY, new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
expression.addPropertyChangeListener(TextWidget.TEXT_PROPERTY, evt -> {
try {
String exp = expression.getText();
Object result = exp.length()==0 ? exp : getEvaluator().evaluate(exp);
Expand All @@ -98,7 +95,6 @@ public void propertyChange(PropertyChangeEvent evt) {
getResultLabel().setText("error: "+e);
resultLabel.setForeground(Color.RED);
}
}
});
expression.setColumns(30);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import javax.swing.table.AbstractTableModel;
Expand All @@ -15,12 +14,8 @@ public class FunctionTableModel extends AbstractTableModel {
private List<Function> functions;

public FunctionTableModel(Collection<Function> collection) {
this.functions = new ArrayList<Function>(collection);
Collections.sort(this.functions, new Comparator<Function>() {
public int compare(Function f1, Function f2) {
return f1.getName().compareTo(f2.getName());
}
});
this.functions = new ArrayList<>(collection);
Collections.sort(this.functions, (f1,f2) -> f1.getName().compareTo(f2.getName()));
}

public int getColumnCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import javax.swing.table.AbstractTableModel;
Expand All @@ -15,12 +14,8 @@ public class OperatorTableModel extends AbstractTableModel {
private List<Operator> operators;

public OperatorTableModel(Collection<Operator> collection) {
this.operators = new ArrayList<Operator>(collection);
Collections.sort(this.operators, new Comparator<Operator>() {
public int compare(Operator o1, Operator o2) {
return o1.getPrecedence()-o2.getPrecedence();
}
});
this.operators = new ArrayList<>(collection);
Collections.sort(this.operators, (o1, o2) -> o1.getPrecedence()-o2.getPrecedence());
}

public int getColumnCount() {
Expand Down
5 changes: 5 additions & 0 deletions javaluator-demo/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module javaluator.demo {
requires javaluator;
requires java.desktop;
requires ajlib;
}
28 changes: 3 additions & 25 deletions javaluator-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<parent>
<groupId>com.fathzer</groupId>
<artifactId>javaluator-parent-pom</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
</parent>

<artifactId>javaluator-examples</artifactId>
<version>3.0.4</version>
<version>3.0.5</version>

<name>javaluator-examples</name>
<description>Some examples of use of Javaluator.</description>
Expand All @@ -17,29 +17,7 @@
<dependency>
<groupId>com.fathzer</groupId>
<artifactId>javaluator</artifactId>
<version>3.0.4</version>
<version>3.0.5</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected Iterator<String> tokenize(String expression) {
}

public static void main(String[] args) {
Map<String,String> variableToValue = new HashMap<String, String>();
Map<String,String> variableToValue = new HashMap<>();
variableToValue.put("type", "PORT");
AbstractEvaluator<Boolean> evaluator = new TextualOperatorsEvaluator();
System.out.println ("type=PORT -> "+evaluator.evaluate("type=PORT", variableToValue));
Expand Down
Loading

0 comments on commit 174b382

Please sign in to comment.