Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Java 9 + 10 #43

Merged
merged 5 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
language: java
jdk:
- oraclejdk8
- openjdk7
- oraclejdk8
- oraclejdk9
- oraclejdk10
- openjdk10
sudo: required
install: true
before_script:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@
<skipCheckoutIfExists>true</skipCheckoutIfExists>
<!-- checkout a specific tag / pinned version -->
<scmVersionType>tag</scmVersionType>
<scmVersion>v3.0.2</scmVersion>
<scmVersion>v3.0.3</scmVersion>
</configuration>
</execution>
</executions>
Expand Down
2 changes: 1 addition & 1 deletion src/build/launch4j-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<bundledJre64Bit>false</bundledJre64Bit>
<bundledJreAsFallback>false</bundledJreAsFallback>
<minVersion>1.7.0</minVersion>
<maxVersion>1.8.0</maxVersion>
<maxVersion></maxVersion>
<jdkPreference>preferJre</jdkPreference>
<runtimeBits>64/32</runtimeBits>
</jre>
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/de/paginagmbh/epubchecker/EpubValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* in a SwingWorker instance
*
* @author Tobias Fischer
* @date 2016-12-16
* @date 2018-07-30
*/
public class EpubValidator {

Expand Down Expand Up @@ -236,11 +236,11 @@ protected void done() {


// set error counter in mac dock badge
if(guiManager.getMacApp() != null) {
if(guiManager.getMacOsIntegration() != null) {
if(report.getWarningCount() + report.getErrorCount() > 0) {
guiManager.getMacApp().setDockIconBadge(new Integer(report.getWarningCount() + report.getErrorCount()).toString());
guiManager.getMacOsIntegration().setDockIconBadge(new Integer(report.getWarningCount() + report.getErrorCount()).toString());
} else {
guiManager.getMacApp().setDockIconBadge("error");
guiManager.getMacOsIntegration().setDockIconBadge("error");
}
}

Expand All @@ -267,8 +267,8 @@ protected void done() {
gui.addLogMessage("\n\n" + resultMessage + "\n");

// set error counter in mac dock badge
if(guiManager.getMacApp() != null) {
guiManager.getMacApp().setDockIconBadge("✓");
if(guiManager.getMacOsIntegration() != null) {
guiManager.getMacOsIntegration().setDockIconBadge("✓");
}

// #20 save the temporarily created EPUB file if ExpandedSaveMode != NEVER is set
Expand Down
14 changes: 6 additions & 8 deletions src/main/java/de/paginagmbh/epubchecker/GuiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import org.json.JSONObject;

import com.apple.eawt.Application;

/**
* GUI Manager singelton
*
Expand All @@ -16,7 +14,7 @@
*
*
* @author Tobias Fischer
* @date 2016-12-12
* @date 2018-07-30
*
*/
public class GuiManager {
Expand All @@ -27,7 +25,7 @@ public class GuiManager {
private Dimension MainGuiDimension = null;
private Point MainGuiPosition = null;
private MainGUI currentGUI = null;
private Application macApp = null;
private MacOsIntegration macOsIntegration = null;
private Boolean menuOptionAutoSaveLogfile = false;
private File currentFile = null;
private Localization l10n = null;
Expand Down Expand Up @@ -93,11 +91,11 @@ public void setCurrentGUI(MainGUI currentGUI) {
this.currentGUI = currentGUI;
}

public Application getMacApp() {
return macApp;
public MacOsIntegration getMacOsIntegration() {
return macOsIntegration;
}
public void setMacApp(Application macApp) {
this.macApp = macApp;
public void setMacOsIntegration(MacOsIntegration macOsIntegration) {
this.macOsIntegration = macOsIntegration;
}

public Boolean getMenuOptionAutoSaveLogfile() {
Expand Down
126 changes: 126 additions & 0 deletions src/main/java/de/paginagmbh/epubchecker/MacOsIntegration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright 2004 - 2013 Wayne Grant
* 2013 - 2018 Kai Kramer
*
* This file is part of KeyStore Explorer.
*
* KeyStore Explorer is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeyStore Explorer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeyStore Explorer. If not, see <http://www.gnu.org/licenses/>.
*/
package de.paginagmbh.epubchecker;
/*
* Taken in parts from https://github.com/SubOptimal/keystore-explorer/blob/master/kse/src/org/kse/gui/MacOsIntegration.java
* under the GNU General Public License v3.0
*/

import java.io.File;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.List;

public class MacOsIntegration implements InvocationHandler {

private final MainGUI mainGui;
private Double javaVersion = 0.0;


public MacOsIntegration() {
this.mainGui = GuiManager.getInstance().getCurrentGUI();

// Check Java Version
String v = System.getProperty("java.version");
if (v.startsWith("1.")) {
// parse Java versions up to 1.8
javaVersion = Double.parseDouble(v.substring(0, 3));
} else {
// parse Java versions 9 and higher (9, 9-ea, 9+, 9.1, 10, 10.0, 11, 11*, 11.13, etc.)
javaVersion = Double.parseDouble(v.replaceAll("^(9|\\d\\d)(\\.\\d\\d?)?.*$", "$1$2"));
}
}


public void addEventHandlers() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException,
InvocationTargetException, InstantiationException {

// using reflection to avoid Mac specific classes being required for compiling
// KSE on other platforms
Class<?> applicationClass = Class.forName("com.apple.eawt.Application");
Class<?> aboutHandlerClass = null;
Class<?> openFilesHandlerClass = null;

if (javaVersion <= 1.8) {
aboutHandlerClass = Class.forName("com.apple.eawt.AboutHandler");
openFilesHandlerClass = Class.forName("com.apple.eawt.OpenFilesHandler");

} else if (javaVersion >= 9.0) {
aboutHandlerClass = Class.forName("java.awt.desktop.AboutHandler");
openFilesHandlerClass = Class.forName("java.awt.desktop.OpenFilesHandler");
}

Object application = applicationClass.getConstructor((Class[]) null).newInstance((Object[]) null);
Object proxy = Proxy.newProxyInstance(MacOsIntegration.class.getClassLoader(),
new Class<?>[] { aboutHandlerClass, openFilesHandlerClass }, this);

applicationClass.getDeclaredMethod("setAboutHandler", aboutHandlerClass).invoke(application, proxy);
applicationClass.getDeclaredMethod("setOpenFileHandler", openFilesHandlerClass).invoke(application, proxy);
}


@Override
@SuppressWarnings("unchecked")
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if ("openFiles".equals(method.getName())) {
if (args[0] != null) {
Object files = args[0].getClass().getMethod("getFiles").invoke(args[0]);
if (files instanceof List) {
// validate EPUB file(s)
new EpubValidator().validate((List<File>) files);
}
}
} else if ("handleAbout".equals(method.getName())) {
SubGUI s = new SubGUI(mainGui);
s.displayAboutBox();
}
return null;
}


public void setDockIconBadge(String string) {
// https://docs.oracle.com/javase/9/migrate/toc.htm#JSMIG-GUID-97C1D0BB-D5D3-4CAD-B17D-03A87A0AAF3B
// https://bugs.openjdk.java.net/browse/JDK-8048731
// https://docs.oracle.com/javase/9/docs/api/java/awt/Taskbar.html

try {
// Java 6, 7, 8
if (javaVersion <= 1.8) {
Class<?> c = Class.forName("com.apple.eawt.Application");
Method methodSetIconBadge = c.getDeclaredMethod("setDockIconBadge", String.class);
Object applicationInstance = c.getConstructor((Class[]) null).newInstance((Object[]) null);
methodSetIconBadge.invoke(applicationInstance, string);

// Java 9, 10, 11, ..., 20, ...
} else if (javaVersion >= 9.0) {
Class<?> c = Class.forName("java.awt.Taskbar");
Method methodGetTaskbar = c.getDeclaredMethod("getTaskbar");
Object taskbarInstance = methodGetTaskbar.invoke(null);
Method methodSetIconBadge = c.getDeclaredMethod("setIconBadge", String.class);
methodSetIconBadge.invoke(taskbarInstance, string);
}
} catch (Exception e) {
System.out.println("ERROR: Failed to load Mac OS integration: Dock Icon Badge feature not working as expected! Please report to the developer!");
e.printStackTrace();
}
}
}
79 changes: 15 additions & 64 deletions src/main/java/de/paginagmbh/epubchecker/PaginaEPUBChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.awt.Dimension;
import java.awt.Point;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
Expand All @@ -11,15 +12,6 @@
import javax.swing.JFrame;
import javax.swing.UIManager;

import com.apple.eawt.AboutHandler;
import com.apple.eawt.AppEvent.AboutEvent;
import com.apple.eawt.AppEvent.OpenFilesEvent;
import com.apple.eawt.AppEvent.QuitEvent;
import com.apple.eawt.Application;
import com.apple.eawt.OpenFilesHandler;
import com.apple.eawt.QuitHandler;
import com.apple.eawt.QuitResponse;



/**
Expand All @@ -28,16 +20,16 @@
* @author Tobias Fischer
* @copyright pagina GmbH, Tübingen
* @version 1.7.2-beta
* @date 2018-07-25
* @date 2018-07-30
*/
public class PaginaEPUBChecker {

// +++++++++++++++++++++++++ DON'T FORGET TO UPDATE EVERYTIME ++++++++++++++++++ //

public static final String PROGRAMVERSION = "1.7.2";
public static final String VERSIONDATE = "15.08.2017";
public static final String VERSIONDATE = "30.07.2018";
public static final String PROGRAMRELEASE = "beta"; // "" or "beta"
public static final String RELEASENOTES = "- Added Japanese translation (Thanks to Masayoshi Takahashi!)<br/>- Require Java 7 or Java 8 JRE/JDK to run the App";
public static final String RELEASENOTES = "- Added Japanese translation (Thanks to Masayoshi Takahashi!)<br/>- Support for Java 9 and 10 on Mac OS and Windows";

// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //

Expand Down Expand Up @@ -87,7 +79,16 @@ public PaginaEPUBChecker(String[] args) {

// init mac specific event listeners; after GUI is loaded
if(FileManager.os_name.equals("mac")) {
initMacOSEventListeners();
MacOsIntegration macOsIntegration = new MacOsIntegration();
try {
macOsIntegration.addEventHandlers();
// store current Application object in GuiManager
guiManager.setMacOsIntegration(macOsIntegration);

} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
System.out.println("ERROR: Failed to load Mac OS integration: 'About' menu or Drag&Drop features may not work as expected! Please report to the developer!");
e.printStackTrace();
}
}


Expand Down Expand Up @@ -144,7 +145,7 @@ public void loadAndInitGuiAndDependencies() {
String currentLanguage = guiManager.getCurrentLanguage();

// set the defaultLocale for epubcheck resource bundles
// TODO: seems as this has no effect when switching the language and the user already validated an epub
// TODO: seems as this has no effect when switching the language and the user already validated an epub (#23)
if(currentLanguage.equals("german")) {
Locale.setDefault(new Locale("de", "DE"));
} else if(currentLanguage.equals("french")) {
Expand Down Expand Up @@ -190,56 +191,6 @@ public void loadAndInitGuiAndDependencies() {



/* ********************************************************************************************************** */

public void initMacOSEventListeners() {
// mac specific event listeners
// have to be set after the GUI was loaded

/*
* Help and tutorial:
* https://developer.apple.com/library/mac/documentation/Java/Reference/JavaSE6_AppleExtensionsRef/api/com/apple/eawt/Application.html#addApplicationListener%28com.apple.eawt.ApplicationListener%29
*
*/


// create an instance of the mac osx Application class
Application macApp = Application.getApplication();

// Exit handler
macApp.setQuitHandler(new QuitHandler() {
@Override
public void handleQuitRequestWith(QuitEvent arg0, QuitResponse arg1) {
System.exit(0);
}
});

// AboutMenu handler
macApp.setAboutHandler(new AboutHandler() {
@Override
public void handleAbout(AboutEvent arg0) {
SubGUI s = new SubGUI(guiManager.getCurrentGUI());
s.displayAboutBox();
}
});

// Drop handler (for dropping files on the program or dock)
macApp.setOpenFileHandler(new OpenFilesHandler() {

@Override
public void openFiles(OpenFilesEvent arg0) {
// validate EPUB files
new EpubValidator().validate(arg0.getFiles());
}
});

// store current Application object in GuiManager
guiManager.setMacApp(macApp);
}




/* ********************************************************************************************************** */

private String __(String s) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/de/paginagmbh/epubchecker/SubGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* @author Tobias Fischer
* @copyright pagina GmbH, Tübingen
* @date 2016-12-12
* @date 2018-07-25
*/
public class SubGUI {

Expand Down Expand Up @@ -46,7 +46,8 @@ public void displayAboutBox() {
.replaceAll("%VERSION_DATE%", PaginaEPUBChecker.VERSIONDATE)
+ "\n\n"
+ __("about_content-3") + "\n\n"
+ __("about_content-4") + "\n\n",
+ __("about_content-4") + "\n\n"
+ "Java Version: " + System.getProperty("java.version") + "\n\n",

__("About"),
JOptionPane.INFORMATION_MESSAGE,
Expand Down