Blob Blame History Raw
From f35b198f727a7b4d8e57ed52b6aa77b24a3af274 Mon Sep 17 00:00:00 2001
From: Mat Booth <mat.booth@redhat.com>
Date: Thu, 23 Apr 2015 10:27:12 +0100
Subject: [PATCH] Keep compatibility with xmvn 2.1.0

Add copies of functions from xmvn 2.4.0 that we need to maintain
compatibility with xmvn 2.1.0

This branch should be used only when xmvn >= 2.4.0 is not available.

Signed-off-by: Mat Booth <mat.booth@redhat.com>
---
 pom.xml                                            |   2 +-
 .../fedoraproject/xmvn/tools/install/JarUtils.java | 143 +++++++++++++++++++++
 2 files changed, 144 insertions(+), 1 deletion(-)
 create mode 100644 xmvn-p2-installer-plugin/src/main/java/org/fedoraproject/xmvn/tools/install/JarUtils.java

diff --git a/fedoraproject-p2/pom.xml b/fedoraproject-p2/pom.xml
index 9febe26..91910e4 100644
--- a/fedoraproject-p2/pom.xml
+++ b/fedoraproject-p2/pom.xml
@@ -24,7 +24,7 @@
 
   <properties>
     <tycho-version>0.23.0</tycho-version>
-    <xmvn-version>2.4.0</xmvn-version>
+    <xmvn-version>2.1.0</xmvn-version>
     <equinox-version>3.10.100.v20150521-1310</equinox-version>
   </properties>
 
diff --git a/fedoraproject-p2/xmvn-p2-installer-plugin/src/main/java/org/fedoraproject/xmvn/tools/install/JarUtils.java b/fedoraproject-p2/xmvn-p2-installer-plugin/src/main/java/org/fedoraproject/xmvn/tools/install/JarUtils.java
new file mode 100644
index 0000000..ccba2b0
--- /dev/null
+++ b/fedoraproject-p2/xmvn-p2-installer-plugin/src/main/java/org/fedoraproject/xmvn/tools/install/JarUtils.java
@@ -0,0 +1,106 @@
+/*-
+ * Copyright (c) 2012-2015 Red Hat, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.fedoraproject.xmvn.tools.install;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Mikolaj Izdebski
+ */
+public class JarUtils
+{
+    private static final Logger logger = LoggerFactory.getLogger( JarUtils.class );
+
+    /**
+     * Heuristically try to determine whether given JAR (or WAR, EAR, ...) file contains native (architecture-dependent)
+     * code.
+     * <p>
+     * Currently this code only checks only for ELF binaries, but that behavior can change in future.
+     * 
+     * @return {@code true} if native code was found inside given JAR
+     */
+    public static boolean containsNativeCode( Path jar )
+    {
+        // From /usr/include/linux/elf.h
+        final int ELFMAG0 = 0x7F;
+        final int ELFMAG1 = 'E';
+        final int ELFMAG2 = 'L';
+        final int ELFMAG3 = 'F';
+
+        try (ZipInputStream jis = new ZipInputStream( Files.newInputStream( jar ) ))
+        {
+            ZipEntry ent;
+            while ( ( ent = jis.getNextEntry() ) != null )
+            {
+                if ( ent.isDirectory() )
+                    continue;
+                if ( jis.read() == ELFMAG0 && jis.read() == ELFMAG1 && jis.read() == ELFMAG2 && jis.read() == ELFMAG3 )
+                {
+                    logger.debug( "Native code found inside {}: {}", jar, ent.getName() );
+                    return true;
+                }
+            }
+
+            logger.trace( "Native code not found inside {}", jar );
+            return false;
+        }
+        catch ( IOException e )
+        {
+            logger.debug( "I/O exception caught when trying to determine whether JAR contains native code: {}", jar, e );
+            return false;
+        }
+    }
+
+    static class NativeMethodFound
+        extends RuntimeException
+    {
+        private static final long serialVersionUID = 1;
+
+        final String className;
+
+        final String methodName;
+
+        final String methodSignature;
+
+        NativeMethodFound( String className, String methodName, String methodSignature )
+        {
+            this.className = className;
+            this.methodName = methodName;
+            this.methodSignature = methodSignature;
+        }
+    }
+
+    /**
+     * Heuristically try to determine whether given JAR (or WAR, EAR, ...) file is using native (architecture-dependent)
+     * code.
+     * <p>
+     * Currently this code only checks if any class file declares Java native methods, but that behavior can change in
+     * future.
+     * 
+     * @return {@code true} given JAR as found inside to use native code
+     */
+    public static boolean usesNativeCode( Path jar )
+    {
+        return false;
+    }
+}
-- 
2.1.0