Bug 526210 - Remove Locker_JavaIO
Now that update.configurator mandates Java 1.8 we are sure that
java.nio.channels.FileLock is available so Locker_JavaNIO can be used
unconditionally.
Change-Id: If0e77df26cb62996973a9faed854275ea71230c3
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/Locker_JavaIo.java b/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/Locker_JavaIo.java
deleted file mode 100644
index d70a1fb..0000000
--- a/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/Locker_JavaIo.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2004, 2017 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.update.internal.configurator;
-
-import java.io.*;
-
-/**
- * Internal class.
- */
-public class Locker_JavaIo implements Locker {
- private File lockFile;
- private RandomAccessFile lockRAF;
-
- public Locker_JavaIo(File lockFile) {
- this.lockFile = lockFile;
- }
-
- @Override
- public synchronized boolean lock() throws IOException {
- //if the lock file already exists, try to delete,
- //assume failure means another eclipse has it open
- if (lockFile.exists())
- lockFile.delete();
- if (lockFile.exists())
- return false;
-
- //open the lock file so other instances can't co-exist
- lockRAF = new RandomAccessFile(lockFile, "rw"); //$NON-NLS-1$
- lockRAF.writeByte(0);
-
- return true;
- }
-
- @Override
- public synchronized void release() {
- try {
- if (lockRAF != null) {
- lockRAF.close();
- lockRAF = null;
- }
- } catch (IOException e) {
- //don't complain, we're making a best effort to clean up
- }
- if (lockFile != null)
- lockFile.delete();
- }
-}
diff --git a/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfiguration.java b/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfiguration.java
index 258eff5..5eff1c6 100644
--- a/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfiguration.java
+++ b/update/org.eclipse.update.configurator/src/org/eclipse/update/internal/configurator/PlatformConfiguration.java
@@ -76,8 +76,6 @@
//private FileLock lock;
private Locker lock = null;
private static int defaultPolicy = DEFAULT_POLICY_TYPE;
- private static boolean checkNio = false;
- private static boolean useNio;
private static final String ECLIPSE = "eclipse"; //$NON-NLS-1$
private static final String CONFIG_HISTORY = "history"; //$NON-NLS-1$
@@ -775,7 +773,7 @@
File lockFile = new File(url.getFile(), ConfigurationActivator.NAME_SPACE + File.separator + CONFIG_FILE_LOCK_SUFFIX);
verifyPath(url, config == null ? null : config.getInstallURL());
// PAL nio optional
- lock = createLocker(lockFile);
+ lock = new Locker_JavaNio(lockFile);
try {
lock.lock();
} catch (IOException ioe) {
@@ -790,26 +788,6 @@
}
}
- /**
- * Create a locker using java new I/O or regular I/O
- * depending whether we run in J2SE or cdcFoundation
- * PAL nio optional
- */
- private static Locker createLocker(File lock) {
- if (!checkNio) {
- useNio = true;
- try {
- Class.forName("java.nio.channels.FileLock"); //$NON-NLS-1$
- } catch (ClassNotFoundException e) {
- useNio = false;
- }
- }
- if (useNio)
- return new Locker_JavaNio(lock);
-
- return new Locker_JavaIo(lock);
- }
-
private long computeChangeStamp() {
featuresChangeStamp = computeFeaturesChangeStamp();
pluginsChangeStamp = computePluginsChangeStamp();