Convert yang-xpath-impl into a JPMS module 51/93151/7
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 18 Oct 2020 17:51:42 +0000 (19:51 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 21 Oct 2020 12:42:01 +0000 (12:42 +0000)
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 <robert.varga@pantheon.tech>
yang/yang-xpath-impl/pom.xml
yang/yang-xpath-impl/src/main/java/module-info.java [new file with mode: 0644]
yang/yang-xpath-impl/src/main/java/org/opendaylight/yangtools/yang/xpath/impl/AntlrXPathParserFactory.java
yang/yang-xpath-impl/src/main/java/org/opendaylight/yangtools/yang/xpath/impl/di/DefaultXPathParserFactory.java [new file with mode: 0644]
yang/yang-xpath-impl/src/main/java/org/opendaylight/yangtools/yang/xpath/impl/di/package-info.java [new file with mode: 0644]

index 537718b1f9a760b35f4966a1e6ad1027b87ce5d6..445f69788235247d354f7aabf9854f6a480f9c98 100644 (file)
             <artifactId>yang-xpath-antlr</artifactId>
         </dependency>
 
-        <dependency>
-            <groupId>javax.inject</groupId>
-            <artifactId>javax.inject</artifactId>
-            <optional>true</optional>
-        </dependency>
         <dependency>
             <groupId>org.kohsuke.metainf-services</groupId>
             <artifactId>metainf-services</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.guicedee.services</groupId>
+            <artifactId>javax.inject</artifactId>
+            <version>1.0.19.9</version>
+            <scope>provided</scope>
+            <optional>true</optional>
+        </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
-            <artifactId>osgi.cmpn</artifactId>
+            <artifactId>org.osgi.service.component.annotations</artifactId>
+            <version>1.3.0</version>
+            <scope>provided</scope>
         </dependency>
     </dependencies>
-
-    <build>
-        <plugins>
-            <plugin>
-                <groupId>org.apache.felix</groupId>
-                <artifactId>maven-bundle-plugin</artifactId>
-                <extensions>true</extensions>
-                <configuration>
-                    <instructions>
-                        <Automatic-Module-Name>org.opendaylight.yangtools.yang.xpath.impl</Automatic-Module-Name>
-                    </instructions>
-                </configuration>
-            </plugin>
-        </plugins>
-    </build>
-
 </project>
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 (file)
index 0000000..bddfdf3
--- /dev/null
@@ -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;
+}
index 0569374538bf30b9f7514d10fd824764b7c164bb..cf0b87ab33e008e966003bb842a35b99db765ceb 100644 (file)
@@ -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 (file)
index 0000000..83e0a0e
--- /dev/null
@@ -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 (file)
index 0000000..76f9dda
--- /dev/null
@@ -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