This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository jtimer. See https://gitlab.nuiton.org/chorem/jtimer.git commit 8c2618585c94bc5c09d5f08a2b5d265658183c7c Author: CHRE <CHATELLIER@codelutin.com> Date: Fri May 27 10:07:47 2016 +0200 Move 'system' package outside 'ui' package to allow native system init --- src/license/THIRD-PARTY.properties | 19 +++++++ src/main/java/org/chorem/jtimer/JTimer.java | 25 +++----- .../chorem/jtimer/{ui => }/system/SystemInfo.java | 9 ++- .../jtimer/{ui => }/system/SystemInfoFactory.java | 23 +++----- .../{ui => }/system/macos/ApplicationServices.java | 4 +- .../{ui => }/system/macos/MacOSSystemInfo.java | 14 +++-- .../jtimer/{ui => }/system/macos/package-info.java | 4 +- .../jtimer/{ui => }/system/package-info.java | 4 +- .../{ui => }/system/unix/UnixSystemInfo.java | 35 +++++++++--- .../chorem/jtimer/{ui => }/system/unix/X11.java | 2 +- .../chorem/jtimer/{ui => }/system/unix/Xss.java | 4 +- .../jtimer/{ui => }/system/unix/package-info.java | 4 +- .../jtimer/{ui => }/system/win32/Kernel32.java | 2 +- .../jtimer/{ui => }/system/win32/User32.java | 2 +- .../{ui => }/system/win32/Win32SystemInfo.java | 12 ++-- .../jtimer/{ui => }/system/win32/package-info.java | 4 +- .../ui/system/UnsupportedSystemInfoException.java | 66 ---------------------- .../org/chorem/jtimer/ui/tasks/RunTaskJob.java | 24 +++----- .../{ui => }/system/SystemInfoFactoryTest.java | 22 +++----- 19 files changed, 115 insertions(+), 164 deletions(-) diff --git a/src/license/THIRD-PARTY.properties b/src/license/THIRD-PARTY.properties new file mode 100644 index 0000000..a3d13e9 --- /dev/null +++ b/src/license/THIRD-PARTY.properties @@ -0,0 +1,19 @@ +# Generated by org.codehaus.mojo.license.AddThirdPartyMojo +#------------------------------------------------------------------------------- +# Already used licenses in project : +# - ASL, version 2 +# - Apache License, Version 2.0 +# - GNU LESSER GENERAL PUBLIC LICENSE +# - LGPL 2.1 +# - LGPL, version 2.1 +# - Lesser General Public License (LGPL) +# - Lesser General Public License (LGPL) v 3.0 +# - The Apache Software License, Version 2.0 +#------------------------------------------------------------------------------- +# Please fill the missing licenses for dependencies : +# +# +#Fri May 27 09:37:37 CEST 2016 +org.apache.ant--ant--1.7.0=Apache License, Version 2.0 +org.apache.ant--ant-launcher--1.7.0=Apache License, Version 2.0 +org.testng--testng--6.9.11=Apache License, Version 2.0 diff --git a/src/main/java/org/chorem/jtimer/JTimer.java b/src/main/java/org/chorem/jtimer/JTimer.java index 6d89e2f..eefd80c 100644 --- a/src/main/java/org/chorem/jtimer/JTimer.java +++ b/src/main/java/org/chorem/jtimer/JTimer.java @@ -24,7 +24,6 @@ package org.chorem.jtimer; import java.awt.BorderLayout; import java.awt.Dimension; -import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; @@ -34,6 +33,7 @@ import java.io.IOException; import java.util.Calendar; import java.util.Date; import java.util.List; +import java.util.Optional; import java.util.Timer; import javax.swing.ButtonGroup; @@ -66,6 +66,8 @@ import org.chorem.jtimer.data.DataViolationException; import org.chorem.jtimer.data.TimerCore; import org.chorem.jtimer.entities.TimerProject; import org.chorem.jtimer.entities.TimerTask; +import org.chorem.jtimer.system.SystemInfo; +import org.chorem.jtimer.system.SystemInfoFactory; import org.chorem.jtimer.ui.HelpFrame; import org.chorem.jtimer.ui.NewTaskView; import org.chorem.jtimer.ui.StatusBar; @@ -183,23 +185,10 @@ public class JTimer extends SingleFrameApplication implements ApplicationContext ctxt = getContext(); resourceMap = ctxt.getResourceMap(); - // fixme awt application name. Can be seen only with gnome-shell - // tray icon is displayed with name "org-chorem-jtimer-JTimer" instead of - // only "jTimer" with following fix : - try { - Toolkit xToolkit = Toolkit.getDefaultToolkit(); - java.lang.reflect.Field awtAppClassNameField = xToolkit.getClass().getDeclaredField("awtAppClassName"); - awtAppClassNameField.setAccessible(true); - awtAppClassNameField.set(xToolkit, resourceMap.getString("Application.title")); - } catch (NoSuchFieldException ex) { - // probably not running on linux - if (log.isTraceEnabled()) { - log.trace("Can't find any field named 'awtAppClassName'", ex); - } - } catch (Exception ex) { - if (log.isWarnEnabled()) { - log.warn("Can change awt application name", ex); - } + // native init + Optional<SystemInfo> systemInfo = SystemInfoFactory.getSystemInfo(); + if (systemInfo.isPresent()) { + systemInfo.get().systemInit(); } // fix start in iconified mode diff --git a/src/main/java/org/chorem/jtimer/ui/system/SystemInfo.java b/src/main/java/org/chorem/jtimer/system/SystemInfo.java similarity index 84% rename from src/main/java/org/chorem/jtimer/ui/system/SystemInfo.java rename to src/main/java/org/chorem/jtimer/system/SystemInfo.java index 4cd31c7..a69b83e 100644 --- a/src/main/java/org/chorem/jtimer/ui/system/SystemInfo.java +++ b/src/main/java/org/chorem/jtimer/system/SystemInfo.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2007 - 2016 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -20,7 +20,7 @@ * #L% */ -package org.chorem.jtimer.ui.system; +package org.chorem.jtimer.system; /** * System info interface for all systems. @@ -34,6 +34,11 @@ package org.chorem.jtimer.ui.system; public interface SystemInfo { /** + * Perform additional init related to system native call. + */ + void systemInit(); + + /** * Get system idle time in milliseconds. * * @return system idle time in milliseconds diff --git a/src/main/java/org/chorem/jtimer/ui/system/SystemInfoFactory.java b/src/main/java/org/chorem/jtimer/system/SystemInfoFactory.java similarity index 74% rename from src/main/java/org/chorem/jtimer/ui/system/SystemInfoFactory.java rename to src/main/java/org/chorem/jtimer/system/SystemInfoFactory.java index d116fbc..53881c8 100644 --- a/src/main/java/org/chorem/jtimer/ui/system/SystemInfoFactory.java +++ b/src/main/java/org/chorem/jtimer/system/SystemInfoFactory.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2007 - 2016 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -20,16 +20,18 @@ * #L% */ -package org.chorem.jtimer.ui.system; +package org.chorem.jtimer.system; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.ui.system.macos.MacOSSystemInfo; -import org.chorem.jtimer.ui.system.unix.UnixSystemInfo; -import org.chorem.jtimer.ui.system.win32.Win32SystemInfo; +import org.chorem.jtimer.system.macos.MacOSSystemInfo; +import org.chorem.jtimer.system.unix.UnixSystemInfo; +import org.chorem.jtimer.system.win32.Win32SystemInfo; import com.sun.jna.Platform; +import java.util.Optional; + /** * Build system info determined from system. * @@ -59,11 +61,8 @@ public class SystemInfoFactory { * * @return SystemInfo instance * @see SystemInfo - * @throws UnsupportedSystemInfoException if system info is not supported - * for system */ - public static SystemInfo getSystemInfo() - throws UnsupportedSystemInfoException { + public static Optional<SystemInfo> getSystemInfo() { if (instance == null) { String os = System.getProperty("os.name"); @@ -80,13 +79,9 @@ public class SystemInfoFactory { instance = new UnixSystemInfo(); } else if (Platform.isMac()) { instance = new MacOSSystemInfo(); - } else { - // system unknown - throw new UnsupportedSystemInfoException( - "Can't get system info for " + os); } } - return instance; + return Optional.ofNullable(instance); } } diff --git a/src/main/java/org/chorem/jtimer/ui/system/macos/ApplicationServices.java b/src/main/java/org/chorem/jtimer/system/macos/ApplicationServices.java similarity index 96% rename from src/main/java/org/chorem/jtimer/ui/system/macos/ApplicationServices.java rename to src/main/java/org/chorem/jtimer/system/macos/ApplicationServices.java index 14554d8..be75e66 100644 --- a/src/main/java/org/chorem/jtimer/ui/system/macos/ApplicationServices.java +++ b/src/main/java/org/chorem/jtimer/system/macos/ApplicationServices.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2010 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2010 - 2016 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -20,7 +20,7 @@ * #L% */ -package org.chorem.jtimer.ui.system.macos; +package org.chorem.jtimer.system.macos; import com.sun.jna.Library; import com.sun.jna.Native; diff --git a/src/main/java/org/chorem/jtimer/ui/system/macos/MacOSSystemInfo.java b/src/main/java/org/chorem/jtimer/system/macos/MacOSSystemInfo.java similarity index 85% rename from src/main/java/org/chorem/jtimer/ui/system/macos/MacOSSystemInfo.java rename to src/main/java/org/chorem/jtimer/system/macos/MacOSSystemInfo.java index af5f51a..2c6035f 100644 --- a/src/main/java/org/chorem/jtimer/ui/system/macos/MacOSSystemInfo.java +++ b/src/main/java/org/chorem/jtimer/system/macos/MacOSSystemInfo.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2010 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2010 - 2016 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -20,9 +20,9 @@ * #L% */ -package org.chorem.jtimer.ui.system.macos; +package org.chorem.jtimer.system.macos; -import org.chorem.jtimer.ui.system.SystemInfo; +import org.chorem.jtimer.system.SystemInfo; /** * MacOSSystemInfo @@ -38,9 +38,11 @@ import org.chorem.jtimer.ui.system.SystemInfo; */ public class MacOSSystemInfo implements SystemInfo { - /* - * @see org.chorem.jtimer.ui.system.SystemInfo#getIdleTime() - */ + @Override + public void systemInit() { + + } + @Override public long getIdleTime() { double idleTimeSeconds = ApplicationServices.INSTANCE diff --git a/src/main/java/org/chorem/jtimer/ui/system/macos/package-info.java b/src/main/java/org/chorem/jtimer/system/macos/package-info.java similarity index 88% rename from src/main/java/org/chorem/jtimer/ui/system/macos/package-info.java rename to src/main/java/org/chorem/jtimer/system/macos/package-info.java index 23fd14d..0e7c51e 100644 --- a/src/main/java/org/chorem/jtimer/ui/system/macos/package-info.java +++ b/src/main/java/org/chorem/jtimer/system/macos/package-info.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2007 - 2016 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -22,4 +22,4 @@ /** * Mac OS specific system info implementation. */ -package org.chorem.jtimer.ui.system.macos; +package org.chorem.jtimer.system.macos; diff --git a/src/main/java/org/chorem/jtimer/ui/system/package-info.java b/src/main/java/org/chorem/jtimer/system/package-info.java similarity index 89% rename from src/main/java/org/chorem/jtimer/ui/system/package-info.java rename to src/main/java/org/chorem/jtimer/system/package-info.java index 85c1687..4b697dd 100644 --- a/src/main/java/org/chorem/jtimer/ui/system/package-info.java +++ b/src/main/java/org/chorem/jtimer/system/package-info.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2007 - 2016 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -22,4 +22,4 @@ /** * System interface using JNA to get system information. */ -package org.chorem.jtimer.ui.system; +package org.chorem.jtimer.system; diff --git a/src/main/java/org/chorem/jtimer/ui/system/unix/UnixSystemInfo.java b/src/main/java/org/chorem/jtimer/system/unix/UnixSystemInfo.java similarity index 77% rename from src/main/java/org/chorem/jtimer/ui/system/unix/UnixSystemInfo.java rename to src/main/java/org/chorem/jtimer/system/unix/UnixSystemInfo.java index b4997f2..a0b90d4 100644 --- a/src/main/java/org/chorem/jtimer/ui/system/unix/UnixSystemInfo.java +++ b/src/main/java/org/chorem/jtimer/system/unix/UnixSystemInfo.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2007 - 2016 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -20,14 +20,16 @@ * #L% */ -package org.chorem.jtimer.ui.system.unix; +package org.chorem.jtimer.system.unix; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.ui.system.SystemInfo; +import org.chorem.jtimer.system.SystemInfo; import com.sun.jna.ptr.IntByReference; +import java.awt.Toolkit; + /** * Linux system info. * @@ -45,13 +47,32 @@ public class UnixSystemInfo implements SystemInfo { /** log. */ private static Log log = LogFactory.getLog(UnixSystemInfo.class); - /* - * @see org.chorem.jtimer.ui.system.SystemInfo#getIdleTime() - */ + @Override + public void systemInit() { + // fixme awt application name. Can be seen only with gnome-shell + // tray icon is displayed with name "org-chorem-jtimer-JTimer" instead of + // only "jTimer" with following fix : + try { + Toolkit xToolkit = Toolkit.getDefaultToolkit(); + java.lang.reflect.Field awtAppClassNameField = xToolkit.getClass().getDeclaredField("awtAppClassName"); + awtAppClassNameField.setAccessible(true); + awtAppClassNameField.set(xToolkit, "jTimer"); + } catch (NoSuchFieldException ex) { + // probably not running on linux + if (log.isTraceEnabled()) { + log.trace("Can't find any field named 'awtAppClassName'", ex); + } + } catch (Exception ex) { + if (log.isWarnEnabled()) { + log.warn("Can change awt application name", ex); + } + } + } + @Override public long getIdleTime() { - long idleTime = 0; + long idleTime; try { idleTime = getXssIdleTime(); diff --git a/src/main/java/org/chorem/jtimer/ui/system/unix/X11.java b/src/main/java/org/chorem/jtimer/system/unix/X11.java similarity index 96% rename from src/main/java/org/chorem/jtimer/ui/system/unix/X11.java rename to src/main/java/org/chorem/jtimer/system/unix/X11.java index 7bc2e29..bdf7a3b 100644 --- a/src/main/java/org/chorem/jtimer/ui/system/unix/X11.java +++ b/src/main/java/org/chorem/jtimer/system/unix/X11.java @@ -12,7 +12,7 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ -package org.chorem.jtimer.ui.system.unix; +package org.chorem.jtimer.system.unix; import com.sun.jna.Library; import com.sun.jna.Native; diff --git a/src/main/java/org/chorem/jtimer/ui/system/unix/Xss.java b/src/main/java/org/chorem/jtimer/system/unix/Xss.java similarity index 96% rename from src/main/java/org/chorem/jtimer/ui/system/unix/Xss.java rename to src/main/java/org/chorem/jtimer/system/unix/Xss.java index 344ab2c..7a156e6 100644 --- a/src/main/java/org/chorem/jtimer/ui/system/unix/Xss.java +++ b/src/main/java/org/chorem/jtimer/system/unix/Xss.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2007 - 2010 CodeLutin, Chatellier Eric + * Copyright (C) 2007 - 2016 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -20,7 +20,7 @@ * #L% */ -package org.chorem.jtimer.ui.system.unix; +package org.chorem.jtimer.system.unix; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/org/chorem/jtimer/ui/system/unix/package-info.java b/src/main/java/org/chorem/jtimer/system/unix/package-info.java similarity index 88% rename from src/main/java/org/chorem/jtimer/ui/system/unix/package-info.java rename to src/main/java/org/chorem/jtimer/system/unix/package-info.java index f55ad4c..58d9b22 100644 --- a/src/main/java/org/chorem/jtimer/ui/system/unix/package-info.java +++ b/src/main/java/org/chorem/jtimer/system/unix/package-info.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2007 - 2016 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -22,4 +22,4 @@ /** * Linux specific system info implementation. */ -package org.chorem.jtimer.ui.system.unix; +package org.chorem.jtimer.system.unix; diff --git a/src/main/java/org/chorem/jtimer/ui/system/win32/Kernel32.java b/src/main/java/org/chorem/jtimer/system/win32/Kernel32.java similarity index 97% rename from src/main/java/org/chorem/jtimer/ui/system/win32/Kernel32.java rename to src/main/java/org/chorem/jtimer/system/win32/Kernel32.java index 0d89d4d..3e7a4ea 100644 --- a/src/main/java/org/chorem/jtimer/ui/system/win32/Kernel32.java +++ b/src/main/java/org/chorem/jtimer/system/win32/Kernel32.java @@ -19,7 +19,7 @@ * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% */ -package org.chorem.jtimer.ui.system.win32; +package org.chorem.jtimer.system.win32; import com.sun.jna.Native; import com.sun.jna.win32.StdCallLibrary; diff --git a/src/main/java/org/chorem/jtimer/ui/system/win32/User32.java b/src/main/java/org/chorem/jtimer/system/win32/User32.java similarity index 97% rename from src/main/java/org/chorem/jtimer/ui/system/win32/User32.java rename to src/main/java/org/chorem/jtimer/system/win32/User32.java index d63c28c..70d6500 100644 --- a/src/main/java/org/chorem/jtimer/ui/system/win32/User32.java +++ b/src/main/java/org/chorem/jtimer/system/win32/User32.java @@ -19,7 +19,7 @@ * <http://www.gnu.org/licenses/gpl-3.0.html>. * #L% */ -package org.chorem.jtimer.ui.system.win32; +package org.chorem.jtimer.system.win32; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/org/chorem/jtimer/ui/system/win32/Win32SystemInfo.java b/src/main/java/org/chorem/jtimer/system/win32/Win32SystemInfo.java similarity index 91% rename from src/main/java/org/chorem/jtimer/ui/system/win32/Win32SystemInfo.java rename to src/main/java/org/chorem/jtimer/system/win32/Win32SystemInfo.java index da0e2ef..bc38335 100644 --- a/src/main/java/org/chorem/jtimer/ui/system/win32/Win32SystemInfo.java +++ b/src/main/java/org/chorem/jtimer/system/win32/Win32SystemInfo.java @@ -20,9 +20,9 @@ * #L% */ -package org.chorem.jtimer.ui.system.win32; +package org.chorem.jtimer.system.win32; -import org.chorem.jtimer.ui.system.SystemInfo; +import org.chorem.jtimer.system.SystemInfo; /** * Win32 System info. @@ -60,9 +60,11 @@ public class Win32SystemInfo implements SystemInfo { return Kernel32.INSTANCE.GetTickCount() - lastInputInfo.dwTime; } - /* - * @see org.chorem.jtimer.ui.system.SystemInfo#getIdleTime() - */ + @Override + public void systemInit() { + + } + @Override public long getIdleTime() { long millisTime = getIdleTimeMillisWin32(); diff --git a/src/main/java/org/chorem/jtimer/ui/system/win32/package-info.java b/src/main/java/org/chorem/jtimer/system/win32/package-info.java similarity index 88% rename from src/main/java/org/chorem/jtimer/ui/system/win32/package-info.java rename to src/main/java/org/chorem/jtimer/system/win32/package-info.java index 9f33714..980645e 100644 --- a/src/main/java/org/chorem/jtimer/ui/system/win32/package-info.java +++ b/src/main/java/org/chorem/jtimer/system/win32/package-info.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2007 - 2016 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -22,4 +22,4 @@ /** * Windows specific system info implementation. */ -package org.chorem.jtimer.ui.system.win32; +package org.chorem.jtimer.system.win32; diff --git a/src/main/java/org/chorem/jtimer/ui/system/UnsupportedSystemInfoException.java b/src/main/java/org/chorem/jtimer/ui/system/UnsupportedSystemInfoException.java deleted file mode 100644 index 28410c1..0000000 --- a/src/main/java/org/chorem/jtimer/ui/system/UnsupportedSystemInfoException.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * #%L - * jTimer - * %% - * Copyright (C) 2007 - 2011 CodeLutin, Chatellier Eric - * %% - * This program 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. - * - * This program 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 this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * #L% - */ - -package org.chorem.jtimer.ui.system; - -/** - * Exception thrown when system info is not available. - * - * @author chatellier - * @version $Revision$ - * - * Last update : $Date$ - * By : $Author$ - */ -public class UnsupportedSystemInfoException extends Exception { - - /** serialVersionUID. */ - private static final long serialVersionUID = 138458861335881500L; - - /** - * Constructor. - * - * @param message message - * @param cause cause - */ - public UnsupportedSystemInfoException(String message, Throwable cause) { - super(message, cause); - } - - /** - * Constructor. - * - * @param message message - */ - public UnsupportedSystemInfoException(String message) { - super(message); - } - - /** - * Constructor. - * - * @param cause cause. - */ - public UnsupportedSystemInfoException(Throwable cause) { - super(cause); - } -} diff --git a/src/main/java/org/chorem/jtimer/ui/tasks/RunTaskJob.java b/src/main/java/org/chorem/jtimer/ui/tasks/RunTaskJob.java index 0b3d0b4..d458691 100644 --- a/src/main/java/org/chorem/jtimer/ui/tasks/RunTaskJob.java +++ b/src/main/java/org/chorem/jtimer/ui/tasks/RunTaskJob.java @@ -26,6 +26,7 @@ import java.util.Calendar; import java.util.Collection; import java.util.Date; import java.util.HashSet; +import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; @@ -42,9 +43,8 @@ import org.chorem.jtimer.entities.TimerAlert; import org.chorem.jtimer.entities.TimerAlert.Type; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.entities.TimerTaskHelper; -import org.chorem.jtimer.ui.system.SystemInfo; -import org.chorem.jtimer.ui.system.SystemInfoFactory; -import org.chorem.jtimer.ui.system.UnsupportedSystemInfoException; +import org.chorem.jtimer.system.SystemInfo; +import org.chorem.jtimer.system.SystemInfoFactory; import org.chorem.jtimer.ui.tasks.IdleDialog.IdleOption; import org.jdesktop.application.Task; @@ -74,7 +74,7 @@ public class RunTaskJob extends Task<Void, Void> { protected TimerDataManager dataManager; /** System information (idle...). */ - protected SystemInfo systemInfo; + protected Optional<SystemInfo> systemInfo; /** Already thrown alert. */ protected Collection<TimerAlert> alreadyTrownAlerts; @@ -111,14 +111,7 @@ public class RunTaskJob extends Task<Void, Void> { checkAlreadyThrownAlerts(managedTask); // init system info to get idleTime - try { - systemInfo = SystemInfoFactory.getSystemInfo(); - } catch (UnsupportedSystemInfoException e) { - if (log.isErrorEnabled()) { - log.error("Can't get system info", e); - } - systemInfo = null; - } + systemInfo = SystemInfoFactory.getSystemInfo(); } /** @@ -162,9 +155,6 @@ public class RunTaskJob extends Task<Void, Void> { return managedTask; } - /* - * @see org.jdesktop.swingworker.SwingWorker#doInBackground() - */ @Override protected Void doInBackground() throws Exception { @@ -195,8 +185,8 @@ public class RunTaskJob extends Task<Void, Void> { // check user idle time long idleTime = 0; - if (systemInfo != null) { // idle time available - idleTime = systemInfo.getIdleTime(); + if (systemInfo.isPresent()) { // idle time available + idleTime = systemInfo.get().getIdleTime(); if (log.isDebugEnabled()) { log.debug("User is idle since " + (idleTime / 1000) + " s"); diff --git a/src/test/java/org/chorem/jtimer/ui/system/SystemInfoFactoryTest.java b/src/test/java/org/chorem/jtimer/system/SystemInfoFactoryTest.java similarity index 70% rename from src/test/java/org/chorem/jtimer/ui/system/SystemInfoFactoryTest.java rename to src/test/java/org/chorem/jtimer/system/SystemInfoFactoryTest.java index 26b0752..40187ae 100644 --- a/src/test/java/org/chorem/jtimer/ui/system/SystemInfoFactoryTest.java +++ b/src/test/java/org/chorem/jtimer/system/SystemInfoFactoryTest.java @@ -2,7 +2,7 @@ * #%L * jTimer * %% - * Copyright (C) 2009 - 2011 CodeLutin, Chatellier Eric + * Copyright (C) 2009 - 2016 CodeLutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -20,18 +20,17 @@ * #L% */ -package org.chorem.jtimer.ui.system; +package org.chorem.jtimer.system; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.AbstractJTimerTest; import org.chorem.jtimer.ui.report.ReportGeneratorTest; -import org.chorem.jtimer.ui.system.SystemInfo; -import org.chorem.jtimer.ui.system.SystemInfoFactory; -import org.chorem.jtimer.ui.system.UnsupportedSystemInfoException; import org.testng.Assert; import org.testng.annotations.Test; +import java.util.Optional; + /** * Test for SystemInfoFactory. * @@ -55,20 +54,15 @@ public class SystemInfoFactoryTest extends AbstractJTimerTest { @Test public void getSystemInfoTest() { try { - SystemInfo systemInfo = SystemInfoFactory.getSystemInfo(); - - Assert.assertTrue(systemInfo.getIdleTime() >= 0, - "Idle time must be positive"); - } catch (UnsupportedSystemInfoException e) { - // can happen - if (log.isInfoEnabled()) { - log.info("No system info available in system, skip test"); + Optional<SystemInfo> systemInfo = SystemInfoFactory.getSystemInfo(); + if (systemInfo.isPresent()) { + Assert.assertTrue(systemInfo.get().getIdleTime() >= 0, "Idle time must be positive"); } } catch (UnsatisfiedLinkError e) { // can happen on system where libX11 is available // libXss is not (on xvfb x server for example) if (log.isWarnEnabled()) { - log.warn("Can't initialize native system librairies", e); + log.warn("Can't initialize native system libraries", e); } } } -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.