# HG changeset patch # User Jiri Vanek # Date 1542983584 -3600 # Node ID fd84d9b293df9a2c8fcda4a936b15de517ffb438 # Parent 4453afdafaf94bf6dbfad084e25d261a3a03cde5 Fixed LockedFile for readonly on windows * netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java: made isUnix deprecated * netx/net/sourceforge/jnlp/util/lockingfile/LockedFile.java: creating file (for windows) only if not readonly * tests/netx/unit/net/sourceforge/jnlp/util/lockingfile/NonWindowsLockedFile.java: tests for os set to no windows * tests/netx/unit/net/sourceforge/jnlp/util/lockingfile/WindowsLockedFileTest.java: tests for os set to windows diff -r 4453afdafaf9 -r fd84d9b293df ChangeLog --- a/ChangeLog Fri Nov 23 13:41:00 2018 +0100 +++ b/ChangeLog Fri Nov 23 15:33:04 2018 +0100 @@ -1,3 +1,13 @@ +2018-11-23 Lars Herschke + Jiri Vanek + + Fixed LockedFile for readonly on windows + * netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java: made isUnix deprecated + * netx/net/sourceforge/jnlp/util/lockingfile/LockedFile.java: creating file (for windows) only if not readonly + * tests/netx/unit/net/sourceforge/jnlp/util/lockingfile/NonWindowsLockedFile.java: tests for os set to no windows + * tests/netx/unit/net/sourceforge/jnlp/util/lockingfile/WindowsLockedFileTest.java: tests for os set to windows + + 2018-11-23 Lars Herschke Fix for java.lang.NoClassDefFoundError: Could not initialize class net.sourceforge.jnlp.runtime.JNLPRuntime$DeploymentConfigurationHolder diff -r 4453afdafaf9 -r fd84d9b293df netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java --- a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java Fri Nov 23 13:41:00 2018 +0100 +++ b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java Fri Nov 23 15:33:04 2018 +0100 @@ -775,6 +775,7 @@ * @return {@code true} if running on a Unix or Unix-like system (including * Linux and *BSD) */ + @Deprecated public static boolean isUnix() { String sep = System.getProperty("file.separator"); return (sep != null && sep.equals("/")); diff -r 4453afdafaf9 -r fd84d9b293df netx/net/sourceforge/jnlp/util/lockingfile/LockedFile.java --- a/netx/net/sourceforge/jnlp/util/lockingfile/LockedFile.java Fri Nov 23 13:41:00 2018 +0100 +++ b/netx/net/sourceforge/jnlp/util/lockingfile/LockedFile.java Fri Nov 23 15:33:04 2018 +0100 @@ -197,7 +197,9 @@ /*Comment why itis different*/ @Override public void lock() throws IOException { - super.file.createNewFile(); + if (!isReadOnly()) { + super.file.createNewFile(); + } super.threadLock.lock(); } diff -r 4453afdafaf9 -r fd84d9b293df tests/netx/unit/net/sourceforge/jnlp/util/lockingfile/NonWindowsLockedFile.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/netx/unit/net/sourceforge/jnlp/util/lockingfile/NonWindowsLockedFile.java Fri Nov 23 15:33:04 2018 +0100 @@ -0,0 +1,30 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package net.sourceforge.jnlp.util.lockingfile; + +import org.junit.AfterClass; +import org.junit.BeforeClass; + +/** + * + * @author jvanek + */ +public class NonWindowsLockedFile extends WindowsLockedFileTest { + + private static String os; + + @BeforeClass + public static void smuggleOs() { + os = System.getProperty("os.name"); + System.setProperty("os.name", "No Windows for itw"); + } + + @AfterClass + public static void restoreOs() { + System.setProperty("os.name", os); + } + +} diff -r 4453afdafaf9 -r fd84d9b293df tests/netx/unit/net/sourceforge/jnlp/util/lockingfile/WindowsLockedFileTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/netx/unit/net/sourceforge/jnlp/util/lockingfile/WindowsLockedFileTest.java Fri Nov 23 15:33:04 2018 +0100 @@ -0,0 +1,71 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package net.sourceforge.jnlp.util.lockingfile; + +import java.io.File; +import java.io.IOException; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * @author jvanek + */ +public class WindowsLockedFileTest { + + private static String os; + + @BeforeClass + public static void smuggleOs() { + os = System.getProperty("os.name"); + System.setProperty("os.name", "Windows for itw"); + } + + @AfterClass + public static void restoreOs() { + System.setProperty("os.name", os); + } + + @Test + public void testLockUnlockOkExists() throws IOException { + File f = File.createTempFile("itw", "lockingFile"); + f.deleteOnExit(); + LockedFile lf = LockedFile.getInstance(f); + lf.lock(); + lf.unlock(); + } + + @Test + public void testLockUnlockOkNotExists() throws IOException { + File f = File.createTempFile("itw", "lockingFile"); + f.delete(); + LockedFile lf = LockedFile.getInstance(f); + lf.lock(); + lf.unlock(); + } + + @Test + public void testLockUnlockNoOkNotExists() throws IOException { + File parent = File.createTempFile("itw", "lockingFile"); + parent.deleteOnExit(); + File f = new File(parent, "itwLcokingRelict"); + f.delete(); + parent.setReadOnly(); + LockedFile lf = LockedFile.getInstance(f); + lf.lock(); + lf.unlock();; + } + + @Test + public void testLockUnlockNotOkExists() throws IOException { + File f = new File("/some/deffinitley/not/exisitng/file.itw"); + LockedFile lf = LockedFile.getInstance(f); + lf.lock(); + lf.unlock(); + } + +}