Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Fedorenko2013-08-12 06:52:56 +0000
committerIgor Fedorenko2013-08-12 07:23:34 +0000
commit1486b46af781fb57d24f36f76de937d98624c180 (patch)
treec7e78b6acb39da49eb2e70f0d40ba59ce301541a
parent853883d6bbde9d149061e16db9a1e19b7819f97e (diff)
downloadm2e-core-1486b46af781fb57d24f36f76de937d98624c180.tar.gz
m2e-core-1486b46af781fb57d24f36f76de937d98624c180.tar.xz
m2e-core-1486b46af781fb57d24f36f76de937d98624c180.zip
412436 use reflection to access Equinox file locker
Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/e44/EquinoxLocker.java86
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/nexus/EquinoxLock.java32
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/nexus/EquinoxLocker.java38
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/nexus/NexusIndexManager.java1
4 files changed, 87 insertions, 70 deletions
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/e44/EquinoxLocker.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/e44/EquinoxLocker.java
new file mode 100644
index 00000000..b6f3b63d
--- /dev/null
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/e44/EquinoxLocker.java
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Igor Fedorenko
+ * 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:
+ * Igor Fedorenko - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.core.internal.e44;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.maven.index.fs.Lock;
+import org.apache.maven.index.fs.Locker;
+
+
+/**
+ * This class provides reflection-based adaptor for Equinox internal file Locker implementation and is meant to
+ * compensate for changes between Equinox 3.9 and 3.10.
+ *
+ * @see http://dev.eclipse.org/mhonarc/lists/cross-project-issues-dev/msg09424.html
+ * @since 1.5
+ */
+public class EquinoxLocker implements Locker {
+
+ private static final String E43_LOCATION_HELPER = "org.eclipse.core.runtime.internal.adaptor.BasicLocation";
+
+ private static final String E44_LOCATION_HELPER = "org.eclipse.osgi.internal.location.LocationHelper";
+
+ private static class EquinoxLock implements Lock {
+
+ private Object locker;
+
+ public EquinoxLock(Object locker) {
+ this.locker = locker;
+ }
+
+ public void release() {
+ try {
+ Method releaseMethod = locker.getClass().getMethod("release", (Class<?>[]) null);
+ releaseMethod.invoke(locker, (Object[]) null);
+ } catch(Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ @Override
+ public Lock lock(File directory) throws IOException {
+ File lockFile = new File(directory, LOCK_FILE);
+
+ ClassLoader cl = EquinoxLocker.class.getClassLoader();
+
+ try {
+ Object locker;
+ try {
+ Class<?> locationHelper = cl.loadClass(E44_LOCATION_HELPER);
+ Method createLockerMethod = locationHelper.getMethod("createLocker", File.class, String.class, boolean.class);
+
+ locker = createLockerMethod.invoke(null, lockFile, null /*lockMode*/, false /*debug*/);
+ } catch(ClassNotFoundException ex) {
+ Class<?> locationHelper = cl.loadClass(E43_LOCATION_HELPER);
+ Method createLockerMethod = locationHelper.getMethod("createLocker", File.class, String.class);
+ locker = createLockerMethod.invoke(null, lockFile, null /*lockMode*/);
+ }
+
+ Method lockMethod = locker.getClass().getMethod("lock", (Class<?>[]) null);
+ lockMethod.invoke(locker, (Object[]) null);
+
+ return new EquinoxLock(locker);
+ } catch(InvocationTargetException e) {
+ if(e.getCause() instanceof IOException) {
+ throw (IOException) e.getCause();
+ }
+ throw new RuntimeException(e);
+ } catch(Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/nexus/EquinoxLock.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/nexus/EquinoxLock.java
deleted file mode 100644
index f5b6f57b..00000000
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/nexus/EquinoxLock.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008-2010 Sonatype, Inc.
- * 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:
- * Sonatype, Inc. - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.m2e.core.internal.index.nexus;
-
-import org.eclipse.core.runtime.internal.adaptor.Locker;
-
-import org.apache.maven.index.fs.Lock;
-
-
-@SuppressWarnings("restriction")
-public class EquinoxLock implements Lock {
-
- private final Locker lock;
-
- public EquinoxLock(Locker lock) {
- this.lock = lock;
- }
-
- public void release() {
- lock.release();
- }
-
-}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/nexus/EquinoxLocker.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/nexus/EquinoxLocker.java
deleted file mode 100644
index 02e0af10..00000000
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/nexus/EquinoxLocker.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2008-2010 Sonatype, Inc.
- * 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:
- * Sonatype, Inc. - initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.m2e.core.internal.index.nexus;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.eclipse.core.runtime.internal.adaptor.BasicLocation;
-import org.eclipse.osgi.util.NLS;
-
-import org.apache.maven.index.fs.Lock;
-import org.apache.maven.index.fs.Locker;
-
-
-@SuppressWarnings("restriction")
-public class EquinoxLocker implements Locker {
-
- public Lock lock(File directory) throws IOException {
- org.eclipse.core.runtime.internal.adaptor.Locker lock = BasicLocation.createLocker(new File(directory, LOCK_FILE),
- null);
-
- if(lock.lock()) {
- return new EquinoxLock(lock);
- }
-
- throw new IOException(NLS.bind("Could not acquire lock on directory {0}", directory));
- }
-
-}
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/nexus/NexusIndexManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/nexus/NexusIndexManager.java
index 941d48bd..71959134 100644
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/nexus/NexusIndexManager.java
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/nexus/NexusIndexManager.java
@@ -90,6 +90,7 @@ import org.eclipse.m2e.core.embedder.IMavenConfiguration;
import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.internal.MavenPluginActivator;
import org.eclipse.m2e.core.internal.Messages;
+import org.eclipse.m2e.core.internal.e44.EquinoxLocker;
import org.eclipse.m2e.core.internal.index.IIndex;
import org.eclipse.m2e.core.internal.index.IndexListener;
import org.eclipse.m2e.core.internal.index.IndexManager;

Back to the top