From 7498bbf83619d87db25e54177cf014ba59738a6e Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sun, 18 Oct 2020 19:51:42 +0200 Subject: [PATCH] Convert yang-xpath-impl into a JPMS module This is a bit more involved, as we are using a different javax.inject and do not use osgi.cmpn but org.osgi.service.component.annotations directly. The latter results in a dependency on an automatic module, but that is not really a problem as we never touch them at runtime. Since we do not want to export out implementation directly, and it still needs to be discoverable via reflection, we dedicate org.opendaylight.yang.xpath.impl.di package for that purpose. It will come in handy for other injection frameworks as well. JIRA: YANGTOOLS-1145 Change-Id: Ie80b02eba551fa89c334f20484e386d808316ca3 Signed-off-by: Robert Varga --- yang/yang-xpath-impl/pom.xml | 32 ++++++------------- .../src/main/java/module-info.java | 24 ++++++++++++++ .../xpath/impl/AntlrXPathParserFactory.java | 13 ++++---- .../impl/di/DefaultXPathParserFactory.java | 20 ++++++++++++ .../yang/xpath/impl/di/package-info.java | 12 +++++++ 5 files changed, 72 insertions(+), 29 deletions(-) create mode 100644 yang/yang-xpath-impl/src/main/java/module-info.java create mode 100644 yang/yang-xpath-impl/src/main/java/org/opendaylight/yangtools/yang/xpath/impl/di/DefaultXPathParserFactory.java create mode 100644 yang/yang-xpath-impl/src/main/java/org/opendaylight/yangtools/yang/xpath/impl/di/package-info.java diff --git a/yang/yang-xpath-impl/pom.xml b/yang/yang-xpath-impl/pom.xml index 537718b1f9..445f697882 100644 --- a/yang/yang-xpath-impl/pom.xml +++ b/yang/yang-xpath-impl/pom.xml @@ -44,34 +44,22 @@ yang-xpath-antlr - - javax.inject - javax.inject - true - org.kohsuke.metainf-services metainf-services + + com.guicedee.services + javax.inject + 1.0.19.9 + provided + true + org.osgi - osgi.cmpn + org.osgi.service.component.annotations + 1.3.0 + provided - - - - - org.apache.felix - maven-bundle-plugin - true - - - org.opendaylight.yangtools.yang.xpath.impl - - - - - - diff --git a/yang/yang-xpath-impl/src/main/java/module-info.java b/yang/yang-xpath-impl/src/main/java/module-info.java new file mode 100644 index 0000000000..bddfdf310d --- /dev/null +++ b/yang/yang-xpath-impl/src/main/java/module-info.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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 + */ +import org.opendaylight.yangtools.yang.xpath.api.YangXPathParserFactory; +import org.opendaylight.yangtools.yang.xpath.impl.AntlrXPathParserFactory; + +module org.opendaylight.yangtools.yang.xpath.impl { + exports org.opendaylight.yangtools.yang.xpath.impl.di; + + provides YangXPathParserFactory with AntlrXPathParserFactory; + + requires org.opendaylight.yangtools.yang.xpath.api; + requires org.opendaylight.yangtools.yang.xpath.antlr; + requires org.slf4j; + + // Annotations + requires static javax.inject; + requires static metainf.services; + requires static org.osgi.service.component.annotations; +} diff --git a/yang/yang-xpath-impl/src/main/java/org/opendaylight/yangtools/yang/xpath/impl/AntlrXPathParserFactory.java b/yang/yang-xpath-impl/src/main/java/org/opendaylight/yangtools/yang/xpath/impl/AntlrXPathParserFactory.java index 0569374538..cf0b87ab33 100644 --- a/yang/yang-xpath-impl/src/main/java/org/opendaylight/yangtools/yang/xpath/impl/AntlrXPathParserFactory.java +++ b/yang/yang-xpath-impl/src/main/java/org/opendaylight/yangtools/yang/xpath/impl/AntlrXPathParserFactory.java @@ -7,7 +7,6 @@ */ package org.opendaylight.yangtools.yang.xpath.impl; -import javax.inject.Singleton; import org.kohsuke.MetaInfServices; import org.opendaylight.yangtools.yang.common.QNameModule; import org.opendaylight.yangtools.yang.common.YangNamespaceContext; @@ -23,24 +22,24 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; @MetaInfServices -@Singleton @Component(immediate = true) -public final class AntlrXPathParserFactory implements YangXPathParserFactory { +public class AntlrXPathParserFactory implements YangXPathParserFactory { private static final Logger LOG = LoggerFactory.getLogger(AntlrXPathParserFactory.class); @Override - public YangXPathParser newParser(final YangXPathMathMode mathMode) { + public final YangXPathParser newParser(final YangXPathMathMode mathMode) { return new AntlrXPathParser.Base(mathMode); } @Override - public QualifiedBound newParser(final YangXPathMathMode mathMode, final YangNamespaceContext namespaceContext) { + public final QualifiedBound newParser(final YangXPathMathMode mathMode, + final YangNamespaceContext namespaceContext) { return new AntlrXPathParser.Qualified(mathMode, namespaceContext); } @Override - public UnqualifiedBound newParser(final YangXPathMathMode mathMode, final YangNamespaceContext namespaceContext, - final QNameModule defaultNamespace) { + public final UnqualifiedBound newParser(final YangXPathMathMode mathMode, + final YangNamespaceContext namespaceContext, final QNameModule defaultNamespace) { return new AntlrXPathParser.Unqualified(mathMode, namespaceContext, defaultNamespace); } diff --git a/yang/yang-xpath-impl/src/main/java/org/opendaylight/yangtools/yang/xpath/impl/di/DefaultXPathParserFactory.java b/yang/yang-xpath-impl/src/main/java/org/opendaylight/yangtools/yang/xpath/impl/di/DefaultXPathParserFactory.java new file mode 100644 index 0000000000..83e0a0e182 --- /dev/null +++ b/yang/yang-xpath-impl/src/main/java/org/opendaylight/yangtools/yang/xpath/impl/di/DefaultXPathParserFactory.java @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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 + */ +package org.opendaylight.yangtools.yang.xpath.impl.di; + +import javax.inject.Inject; +import javax.inject.Singleton; +import org.opendaylight.yangtools.yang.xpath.impl.AntlrXPathParserFactory; + +@Singleton +public final class DefaultXPathParserFactory extends AntlrXPathParserFactory { + @Inject + public DefaultXPathParserFactory() { + // Noop + } +} diff --git a/yang/yang-xpath-impl/src/main/java/org/opendaylight/yangtools/yang/xpath/impl/di/package-info.java b/yang/yang-xpath-impl/src/main/java/org/opendaylight/yangtools/yang/xpath/impl/di/package-info.java new file mode 100644 index 0000000000..76f9ddae31 --- /dev/null +++ b/yang/yang-xpath-impl/src/main/java/org/opendaylight/yangtools/yang/xpath/impl/di/package-info.java @@ -0,0 +1,12 @@ +/* + * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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 + */ +/** + * Package exposing {@link org.opendaylight.yangtools.yang.xpath.api.YangXPathParserFactory} component to various + * dependency injection frameworks, so they can locate them. + */ +package org.opendaylight.yangtools.yang.xpath.impl.di; \ No newline at end of file -- 2.36.6