ra4king / CircuitSim

Basic Circuit Simulator
https://ra4king.github.io/CircuitSim
BSD 3-Clause "New" or "Revised" License
76 stars 28 forks source link

CircuitSim updates to build with OpenJDK 14 & JavaFX 14 #66

Closed arcostasi closed 4 years ago

arcostasi commented 4 years ago

I found your project last week searching on GitHub for new simulation tools and yours caught my attention for the elegance of the designer and the programming. I would like to congratulate you for the excellent tool you have developed, I believe it was not easy and I hope you continue to be excited about your CircuitSim project.

I spent the weekend updating and analyzing your project to run on the latest version of OpenJDK and OpenJFX

During the update, I had some difficulties with the building scripts because I'm using Windows and also because I don't have much experience with Java and Gradle.

I had to create a new gradle.build to be able to build with OpenJDK 14 and JavaFX 14, follow the script:

plugins {
    id 'java'

    // Apply the application plugin to add support for building a Java application
    id 'application'
}

// Define the main class for the application
mainClassName = 'com.ra4king.circuitsim.gui.CircuitSim'
group 'CircuitSim'
version '1.8.2'

ext.moduleName = 'Project.com.ra4king.circuitsim.gui'
sourceCompatibility = JavaVersion.VERSION_14

// In this section you declare where to find the dependencies of your project
repositories {
    // Use mavenCentral for resolving dependencies
    mavenCentral()
}

def currentOS = org.gradle.internal.os.OperatingSystem.current()
def platform
if (currentOS.isWindows()) {
    platform = 'win'
} else if (currentOS.isLinux()) {
    platform = 'linux'
} else if (currentOS.isMacOsX()) {
    platform = 'mac'
}

dependencies {
    // This dependency is used by the application.
    implementation 'com.google.code.gson:gson:2.8.6'

    implementation "org.openjfx:javafx-base:14.0.2.1:${platform}"
    implementation "org.openjfx:javafx-controls:14.0.2.1:${platform}"
    implementation "org.openjfx:javafx-graphics:14.0.2.1:${platform}"
}

jar {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    into 'resources', {
        from 'resources'
    }
    inputs.property("moduleName", moduleName)
    manifest {
        attributes(
            'Automatic-Module-Name': moduleName,
            'Main-Class': mainClassName
        )
    }
    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

compileJava {
    inputs.property("moduleName", moduleName)
    doFirst {
        options.compilerArgs = [
            '--module-path', classpath.asPath,
            '--add-modules', 'javafx.controls',
            '-Xlint:unchecked'
        ]
        classpath = files()
    }
}

task createJar(type: Copy) {
    dependsOn 'jar'
    into "$buildDir/libs"
    from configurations.runtime
}

Another configuration file created was module-info.java in src/main/java:

module Project.com.ra4king.circuitsim.gui {
    requires javafx.controls;
    requires com.google.gson;
    exports com.ra4king.circuitsim.gui;
}

I changed your folder structure src/com/ra4king/circuitsim to src/main/java/com/ra4king/circuitsim, src\resources images to src/main/resources/images and src/resources fonts to src/main/resources/fonts, I changed the path in your code resources/*.png code for images/*.png and fonts resources/*.png to fonts/*.ttf, with these changes I was able to build in my environment Windows 10 64 bits with OpenJDK 14.0.2 and JavaFX 14

After the build, only a 2 warnings was displayed:

warning: [unchecked] unchecked method invocation: method edit in class TableView is applied to given types
              tableView.edit(focusedCellPosition.getRow(), focusedCellPosition.getTableColumn());
                            ^
  required: int,TableColumn<S,?>
  found:    int,TableColumn
  where S is a type-variable:
    S extends Object declared in class TableView
D:\Projetos\Java\CircuitSim\src\main\java\com\ra4king\circuitsim\gui\Properties.java:937: warning: [unchecked] unchecked conversion
              tableView.edit(focusedCellPosition.getRow(), focusedCellPosition.getTableColumn());
                                                                                             ^
  required: TableColumn<S,?>
  found:    TableColumn
  where S is a type-variable:
    S extends Object declared in class TableView
2 warnings

@SuppressWarnings("unchecked")
public void createAndShowMemoryWindow(Stage stage, List<MemoryLine> lines) {...

As I don't have much experience with Java, I went to research the warning and they said it was nothing and I could use a @SuppressWarnings("unchecked") in the calling method. i added on top of the method: void createAndShowMemoryWindow(... in the file Properties.java and no more warnings were presented.

to build jar:

gradlew jar

Follow my script run.bat of how I'm doing to run the jar and JavaFX dependencies:

java -Xmx250M --module-path "%PATH_TO_FX%" --add-modules javafx.controls -jar build/libs/CircuitSim-1.8.2.jar

My enviroment %PATH_TO_FX% is C:\Program Files\Java\javafx-sdk-14.0.2.1 and was added in the Windows variable environment.

Considerations about my steps are welcome so that we can continue to improve this amazing project and I hope that I can studying your project to be able to contribute in the future.

Congratulations again Roi Atalla @ra4king and all the best! ;)

ausbin commented 4 years ago

I'm not Roi, but I have to agree he's elegant. In fact, experiencing his elegance in person the first time was so intense that it felt like I had sprinted full-speed into a brick wall of Egyptian magnificence

I am sorry about the current build process being difficult, not my finest work (#26).

How does this strategy compare to #63? In particular, I'm curious if #63 works on Windows since I haven't tried it. But I think I like your strategy here better because it doesn't seem to depend on third-party gradle libraries or jlink

arcostasi commented 4 years ago

Hello Austin,

I added the Badass J Link Plugin in current gradle.build, following the strategy #63 and the follow message was displayed:

FAILURE: Build failed with an exception.

gradlew jlink --debug

10:54:36.212 [INFO] [org.gradle.internal.nativeintegration.services.NativeServices] Initialized native services in: C:\Android.gradle\native 10:54:36.237 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 10:54:36.238 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception. 10:54:36.238 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 10:54:36.238 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong: 10:54:36.239 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Could not determine java version from '14.0.2'.

I believe that I need to make some more modifications to work with this plugin.

Anyway, thank you for your attention!

ra4king commented 4 years ago

Wow! Hello Anderson and thank you for the praise, it means a lot! Figuring out the new Java module system and Gradle has proven to be too much during my busy work schedule so I'm eternally glad you looked into it here!

I spent some time to set this up and get IntelliJ to run the binary. I had to make 1 more change: the main class cannot extend Application otherwise the --module-path param is required and I couldn't get Gradle or IntelliJ to include it automatically. I created CircuitSimRunner that just launches the CircuitSim application. Everything now works, both in IntelliJ and command-line!

Thank you again for the praise Anderson and you too Austin. I will adopt this and reject #63 (sorry Austin!).

ra4king commented 4 years ago

Check out commit 4e0a9d0dfa60e470e3dc3272ee3fb4ed135f05c1 !