[openhft-affinity] 01/05: Fixed the build failure with Java 9 (Closes: #875332)

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Fri Mar 9 12:08:19 GMT 2018


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to branch master
in repository openhft-affinity.

commit 8c79379e0b33781ebb4e7c52114ac4ef5457aa58
Author: Emmanuel Bourg <ebourg at apache.org>
Date:   Fri Mar 9 13:04:03 2018 +0100

    Fixed the build failure with Java 9 (Closes: #875332)
---
 debian/changelog                            |   7 ++
 debian/patches/01-java9-compatibility.patch | 150 ++++++++++++++++++++++++++++
 debian/patches/series                       |   1 +
 3 files changed, 158 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index a899902..9121840 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+openhft-affinity (2.2-2) UNRELEASED; urgency=medium
+
+  * Team upload.
+  * Fixed the build failure with Java 9 (Closes: #875332)
+
+ -- Emmanuel Bourg <ebourg at apache.org>  Fri, 09 Mar 2018 13:03:04 +0100
+
 openhft-affinity (2.2-1) unstable; urgency=medium
 
   * Initial release (Closes: #825969)
diff --git a/debian/patches/01-java9-compatibility.patch b/debian/patches/01-java9-compatibility.patch
new file mode 100644
index 0000000..fd9ceeb
--- /dev/null
+++ b/debian/patches/01-java9-compatibility.patch
@@ -0,0 +1,150 @@
+Description: Fixes a build failure with Java 9 caused by the removal of sun.misc.URLClassPath.
+ This patch can be removed after upgrading to the version 3.1.1 or later.
+Origin: backport, https://github.com/OpenHFT/Java-Thread-Affinity/commit/da19214
+Bug-Debian: https://bugs.debian.org/875332
+--- a/affinity/src/main/java/net/openhft/affinity/BootClassPath.java
++++ b/affinity/src/main/java/net/openhft/affinity/BootClassPath.java
+@@ -1,60 +1,115 @@
+ /*
+- * Copyright 2014 Higher Frequency Trading
++ * Copyright 2016 higherfrequencytrading.com
+  *
+- * http://www.higherfrequencytrading.com
+- *
+- * Licensed under the Apache License, Version 2.0 (the "License");
+- * you may not use this file except in compliance with the License.
++ *  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
++ *       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 net.openhft.affinity;
+ 
+ import org.slf4j.Logger;
+ import org.slf4j.LoggerFactory;
+-import sun.misc.URLClassPath;
+ 
+-import java.io.File;
+-import java.net.MalformedURLException;
+-import java.net.URL;
++import java.io.IOException;
++import java.nio.file.FileVisitResult;
++import java.nio.file.Files;
++import java.nio.file.Path;
++import java.nio.file.Paths;
++import java.nio.file.SimpleFileVisitor;
++import java.nio.file.attribute.BasicFileAttributes;
++import java.util.Collections;
++import java.util.Enumeration;
++import java.util.HashSet;
++import java.util.Set;
++import java.util.jar.JarEntry;
++import java.util.jar.JarFile;
+ 
+ enum BootClassPath {
+     INSTANCE;
+ 
+-    private final URLClassPath bootClassPath = new URLClassPath(getBootClassPathURLs());
++    private final Set<String> bootClassPathResources = Collections.unmodifiableSet(getResourcesOnBootClasspath());
+ 
+     public final boolean has(String binaryClassName) {
+-        String resourceClassName = binaryClassName.replace('.', '/').concat(".class");
+-        return bootClassPath.getResource(resourceClassName, false) != null;
++        final String resourceClassName = binaryClassName.replace('.', '/').concat(".class");
++        return bootClassPathResources.contains(resourceClassName);
+     }
+ 
+-    private URL[] getBootClassPathURLs() {
+-        Logger LOGGER = LoggerFactory.getLogger(BootClassPath.class);
+-        try {
+-            String bootClassPath = System.getProperty("sun.boot.class.path");
+-            LOGGER.trace("Boot class-path is: {}",bootClassPath);
++    private static Set<String> getResourcesOnBootClasspath() {
++        final Logger logger = LoggerFactory.getLogger(BootClassPath.class);
++        final Set<String> resources = new HashSet<>();
++        final String bootClassPath = System.getProperty("sun.boot.class.path");
++        logger.trace("Boot class-path is: {}", bootClassPath);
++
++        final String pathSeparator = System.getProperty("path.separator");
++        logger.trace("Path separator is: '{}'", pathSeparator);
++
++        final String[] pathElements = bootClassPath.split(pathSeparator);
++
++        for (final String pathElement : pathElements) {
++            resources.addAll(findResources(Paths.get(pathElement), logger));
++        }
++
++        return resources;
++    }
++
++    private static Set<String> findResources(final Path path, final Logger logger) {
++        if (!Files.exists(path)) {
++            return Collections.emptySet();
++        }
+ 
+-            String pathSeparator = System.getProperty("path.separator");
+-            LOGGER.trace("Path separator is: '{}'", pathSeparator);
++        if (Files.isDirectory(path)) {
++            return findResourcesInDirectory(path, logger);
++        }
++
++        return findResourcesInJar(path, logger);
++    }
+ 
+-            String[] pathElements = bootClassPath.split(pathSeparator);
+-            URL[] pathURLs = new URL[pathElements.length];
+-            for (int i = 0; i < pathElements.length; i++) {
+-                pathURLs[i] = new File(pathElements[i]).toURI().toURL();
++    private static Set<String> findResourcesInJar(final Path path, final Logger logger) {
++        final Set<String> jarResources = new HashSet<>();
++        try {
++            final JarFile jarFile = new JarFile(path.toFile());
++            final Enumeration<JarEntry> entries = jarFile.entries();
++            while (entries.hasMoreElements()) {
++                final JarEntry jarEntry = entries.nextElement();
++                if (jarEntry.getName().endsWith(".class")) {
++                    jarResources.add(jarEntry.getName());
++                }
+             }
+ 
+-            return pathURLs;
+-        } catch (MalformedURLException e) {
+-            LOGGER.warn("Parsing the boot class-path failed! Reason: {}", e.getMessage());
+-            return new URL[0];
++
++        } catch (IOException e) {
++            logger.warn("Not a jar file: {}", path);
+         }
++
++        return jarResources;
++    }
++
++    private static Set<String> findResourcesInDirectory(final Path path, final Logger logger) {
++        final Set<String> dirResources = new HashSet<>();
++        try {
++            Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
++                @Override
++                public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
++                    if (file.getFileName().toString().endsWith(".class")) {
++                        dirResources.add(path.relativize(file).toString());
++                    }
++                    return super.visitFile(file, attrs);
++                }
++            });
++        } catch (IOException e) {
++            logger.warn("Error walking dir: " + path, e);
++        }
++
++        return dirResources;
+     }
+ }
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 0000000..12bc5e0
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1 @@
+01-java9-compatibility.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/openhft-affinity.git



More information about the pkg-java-commits mailing list