Blame SOURCES/tycho-port-to-xmvn-2.1.0.patch

4c9427
From f35b198f727a7b4d8e57ed52b6aa77b24a3af274 Mon Sep 17 00:00:00 2001
4c9427
From: Mat Booth <mat.booth@redhat.com>
4c9427
Date: Thu, 23 Apr 2015 10:27:12 +0100
4c9427
Subject: [PATCH] Keep compatibility with xmvn 2.1.0
4c9427
4c9427
Add copies of functions from xmvn 2.4.0 that we need to maintain
4c9427
compatibility with xmvn 2.1.0
4c9427
4c9427
This branch should be used only when xmvn >= 2.4.0 is not available.
4c9427
4c9427
Signed-off-by: Mat Booth <mat.booth@redhat.com>
4c9427
---
4c9427
 pom.xml                                            |   2 +-
4c9427
 .../fedoraproject/xmvn/tools/install/JarUtils.java | 143 +++++++++++++++++++++
4c9427
 2 files changed, 144 insertions(+), 1 deletion(-)
4c9427
 create mode 100644 xmvn-p2-installer-plugin/src/main/java/org/fedoraproject/xmvn/tools/install/JarUtils.java
4c9427
4c9427
diff --git a/fedoraproject-p2/pom.xml b/fedoraproject-p2/pom.xml
4c9427
index 9febe26..91910e4 100644
4c9427
--- a/fedoraproject-p2/pom.xml
4c9427
+++ b/fedoraproject-p2/pom.xml
4c9427
@@ -24,7 +24,7 @@
4c9427
 
4c9427
   <properties>
4c9427
     <tycho-version>0.23.0</tycho-version>
4c9427
-    <xmvn-version>2.4.0</xmvn-version>
4c9427
+    <xmvn-version>2.1.0</xmvn-version>
4c9427
     <equinox-version>3.10.100.v20150521-1310</equinox-version>
4c9427
   </properties>
4c9427
 
4c9427
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
4c9427
new file mode 100644
4c9427
index 0000000..ccba2b0
4c9427
--- /dev/null
4c9427
+++ b/fedoraproject-p2/xmvn-p2-installer-plugin/src/main/java/org/fedoraproject/xmvn/tools/install/JarUtils.java
4c9427
@@ -0,0 +1,106 @@
4c9427
+/*-
4c9427
+ * Copyright (c) 2012-2015 Red Hat, Inc.
4c9427
+ *
4c9427
+ * Licensed under the Apache License, Version 2.0 (the "License");
4c9427
+ * you may not use this file except in compliance with the License.
4c9427
+ * You may obtain a copy of the License at
4c9427
+ *
4c9427
+ *     http://www.apache.org/licenses/LICENSE-2.0
4c9427
+ *
4c9427
+ * Unless required by applicable law or agreed to in writing, software
4c9427
+ * distributed under the License is distributed on an "AS IS" BASIS,
4c9427
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4c9427
+ * See the License for the specific language governing permissions and
4c9427
+ * limitations under the License.
4c9427
+ */
4c9427
+package org.fedoraproject.xmvn.tools.install;
4c9427
+
4c9427
+import java.io.IOException;
4c9427
+import java.nio.file.Files;
4c9427
+import java.nio.file.Path;
4c9427
+import java.util.zip.ZipEntry;
4c9427
+import java.util.zip.ZipInputStream;
4c9427
+
4c9427
+import org.slf4j.Logger;
4c9427
+import org.slf4j.LoggerFactory;
4c9427
+
4c9427
+/**
4c9427
+ * @author Mikolaj Izdebski
4c9427
+ */
4c9427
+public class JarUtils
4c9427
+{
4c9427
+    private static final Logger logger = LoggerFactory.getLogger( JarUtils.class );
4c9427
+
4c9427
+    /**
4c9427
+     * Heuristically try to determine whether given JAR (or WAR, EAR, ...) file contains native (architecture-dependent)
4c9427
+     * code.
4c9427
+     * 

4c9427
+     * Currently this code only checks only for ELF binaries, but that behavior can change in future.
4c9427
+     * 
4c9427
+     * @return {@code true} if native code was found inside given JAR
4c9427
+     */
4c9427
+    public static boolean containsNativeCode( Path jar )
4c9427
+    {
4c9427
+        // From /usr/include/linux/elf.h
4c9427
+        final int ELFMAG0 = 0x7F;
4c9427
+        final int ELFMAG1 = 'E';
4c9427
+        final int ELFMAG2 = 'L';
4c9427
+        final int ELFMAG3 = 'F';
4c9427
+
4c9427
+        try (ZipInputStream jis = new ZipInputStream( Files.newInputStream( jar ) ))
4c9427
+        {
4c9427
+            ZipEntry ent;
4c9427
+            while ( ( ent = jis.getNextEntry() ) != null )
4c9427
+            {
4c9427
+                if ( ent.isDirectory() )
4c9427
+                    continue;
4c9427
+                if ( jis.read() == ELFMAG0 && jis.read() == ELFMAG1 && jis.read() == ELFMAG2 && jis.read() == ELFMAG3 )
4c9427
+                {
4c9427
+                    logger.debug( "Native code found inside {}: {}", jar, ent.getName() );
4c9427
+                    return true;
4c9427
+                }
4c9427
+            }
4c9427
+
4c9427
+            logger.trace( "Native code not found inside {}", jar );
4c9427
+            return false;
4c9427
+        }
4c9427
+        catch ( IOException e )
4c9427
+        {
4c9427
+            logger.debug( "I/O exception caught when trying to determine whether JAR contains native code: {}", jar, e );
4c9427
+            return false;
4c9427
+        }
4c9427
+    }
4c9427
+
4c9427
+    static class NativeMethodFound
4c9427
+        extends RuntimeException
4c9427
+    {
4c9427
+        private static final long serialVersionUID = 1;
4c9427
+
4c9427
+        final String className;
4c9427
+
4c9427
+        final String methodName;
4c9427
+
4c9427
+        final String methodSignature;
4c9427
+
4c9427
+        NativeMethodFound( String className, String methodName, String methodSignature )
4c9427
+        {
4c9427
+            this.className = className;
4c9427
+            this.methodName = methodName;
4c9427
+            this.methodSignature = methodSignature;
4c9427
+        }
4c9427
+    }
4c9427
+
4c9427
+    /**
4c9427
+     * Heuristically try to determine whether given JAR (or WAR, EAR, ...) file is using native (architecture-dependent)
4c9427
+     * code.
4c9427
+     * 

4c9427
+     * Currently this code only checks if any class file declares Java native methods, but that behavior can change in
4c9427
+     * future.
4c9427
+     * 
4c9427
+     * @return {@code true} given JAR as found inside to use native code
4c9427
+     */
4c9427
+    public static boolean usesNativeCode( Path jar )
4c9427
+    {
4c9427
+        return false;
4c9427
+    }
4c9427
+}
4c9427
-- 
4c9427
2.1.0
4c9427