From e6d21bc31fbffee27470acd68424f6d7fe8af989 Mon Sep 17 00:00:00 2001 From: Romain Manni-Bucau Date: Tue, 30 Jan 2024 18:28:34 +0100 Subject: [PATCH] [knight][winegrower] since Karaf community kind of abandonned winegrower, drop it from our codebase --- documentation/pom.xml | 11 - documentation/src/content/knights.adoc | 1 - .../src/content/winegrower-knight.adoc | 177 ---------- integration-test/pom.xml | 6 - .../arthur/integrationtests/MavenTest.java | 4 - .../resources/integration-tests/scr/pom.xml | 156 --------- .../arthur/integrationtests/Application.java | 28 -- .../arthur/integrationtests/ScrMain.java | 47 --- knights/pom.xml | 1 - knights/winegrower-knight/pom.xml | 70 ---- .../winegrower/WinegrowerExtension.java | 323 ------------------ .../winegrower/feature/WinegrowerFeature.java | 90 ----- ...apache.geronimo.arthur.spi.ArthurExtension | 1 - ...graalvm.compiler.options.OptionDescriptors | 1 - 14 files changed, 916 deletions(-) delete mode 100644 documentation/src/content/winegrower-knight.adoc delete mode 100644 integration-test/src/test/resources/integration-tests/scr/pom.xml delete mode 100644 integration-test/src/test/resources/integration-tests/scr/src/main/java/org/apache/geronimo/arthur/integrationtests/Application.java delete mode 100644 integration-test/src/test/resources/integration-tests/scr/src/main/java/org/apache/geronimo/arthur/integrationtests/ScrMain.java delete mode 100644 knights/winegrower-knight/pom.xml delete mode 100644 knights/winegrower-knight/src/main/java/org/apache/geronimo/arthur/knight/winegrower/WinegrowerExtension.java delete mode 100644 knights/winegrower-knight/src/main/java/org/apache/geronimo/arthur/knight/winegrower/feature/WinegrowerFeature.java delete mode 100644 knights/winegrower-knight/src/main/resources/META-INF/services/org.apache.geronimo.arthur.spi.ArthurExtension delete mode 100644 knights/winegrower-knight/src/main/resources/META-INF/services/org.graalvm.compiler.options.OptionDescriptors diff --git a/documentation/pom.xml b/documentation/pom.xml index 2ff9bcc..2b4acf3 100644 --- a/documentation/pom.xml +++ b/documentation/pom.xml @@ -74,17 +74,6 @@ - - ${project.groupId}.knights - winegrower-knight - ${project.version} - - - * - * - - - diff --git a/documentation/src/content/knights.adoc b/documentation/src/content/knights.adoc index 9e1da19..b275e4b 100644 --- a/documentation/src/content/knights.adoc +++ b/documentation/src/content/knights.adoc @@ -22,7 +22,6 @@ The extensions are generally responsible to generate a valid configuration to le == Available knights - link:jsch-knight.html[JSch]: it contains some end user API integrated with built-in extensions to simplify application graal-ification, -- link:winegrower-knight.html[Winegrower]: Apache winegrower (Cloud OSGi runtime) support. - link:openwebbeans-knight.html[OpenWebBeans]: Apache OpenWebBeans (CDI SE runtime) support. - link:slf4j-knight.html[SLF4J]: SLF4J (JUL binding) integration. - link:hsqldb-knight[HSQLDB]: HSQL database integration. diff --git a/documentation/src/content/winegrower-knight.adoc b/documentation/src/content/winegrower-knight.adoc deleted file mode 100644 index ddd5aed..0000000 --- a/documentation/src/content/winegrower-knight.adoc +++ /dev/null @@ -1,177 +0,0 @@ -//// -Licensed to the Apache Software Foundation (ASF) under one or more -contributor license agreements. See the NOTICE file distributed with -this work for additional information regarding copyright ownership. -The ASF licenses this file to You 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. -//// -= Arthur Winegrower Knights - -Arthur Winegrower knight is responsible to support Winegrower. -It preconfigures the reflection and resource inclusion. - -It generally assumes you have `winegrower-core` in your project dependencies. -Here is a sample dependencies block for a simple SCR application: - -[source,xml] ----- - - - org.osgi - osgi.core - ${osgi.version} - - - org.osgi - osgi.cmpn - ${osgi.version} - - - org.apache.felix - org.apache.felix.scr - ${felix-scr.version} - - - org.slf4j - slf4j-simple - ${slf4j.version} - - - org.apache.winegrower - winegrower-core - ${winegrower.version} - - ----- - -== Coordinates - -[source,xml] ----- - - org.apache.geronimo.arthur.knights - winegrower-knight - ${arthur.version} - ----- - -== Usage - -To make a winegrower application compatible with `native-image` there are a few necessary steps to do: - -. Ensure OSGi metadata (SCR, blueprint etc) descriptors are generated, -. Ensure Winegrower runs in metadata mode, i.e. it does not require to inspect files anymore to find `MANIFEST.MF` files and `OSGI-INF` descriptors, -. Ensure the SCR, blueprint, ... reflection model is registered. - -The `winegrower-knight` handles all but the first point which is still done through `bnd-tool` or `maven-bundle-plugin`. -Here is a definition to generate the `META-INF/MANIFEST.MF` correctly: - -[source,xml] ----- - - org.apache.felix - maven-bundle-plugin - ${maven-bundle.version} - true - - - manifest - process-classes - - bundle - - - true - - - - ----- - -Then, to generate `winegrower` metadata you can either use the related plugin or let the extension do (default). -If you decide to use the plugin you must define it like that: - -[source,xml] ----- - - org.apache.winegrower - winegrower-maven-plugin - ${winegrower.version} - - - metadata - process-classes - - metadata - - - true - - xbean-finder-shaded - - - - - ----- - -And to deactivate the extension metadata generation you must add an extension property: - -[source,xml] ----- - - ${project.groupId} - arthur-maven-plugin - ${project.version} - - - - false - - - ----- - -Finally, whatever way you picked to generate metadata, you must register the winegrower knight in `arthur-maven-plugin`: - - -[source,xml] ----- - - org.apache.geronimo.arthur - arthur-maven-plugin - ${arthur.version} - -
org.company.osgi.ScrMain
- - winegrower - -
-
----- - -== Configuration - -This knight has several configuration options: - -[opts="header",role="table table-bordered",cols="2,1,3"] -|=== -|Name|Type|Description -a|`extension.winegrower.[includes\|excludes]`|String|Comma separated values for scanning filter. It acts on the filename and matches prefixes. -a|`extension.winegrower.metadata.generate`|boolean|Should the winegrower metadata be automatically generated, default to true. -a|`extension.winegrower.metadata.autoFiltering`|boolean|Should winegrower metadata generation use autofiltering to reduce the number of metadata, default to true. -a|`extension.winegrower.metadata.defaultJarName`|String|What name to use for the exploded classpath folder of the module (`target/classes`), default to module folder name. -|=== - ---- - -Previous: link:knights.html[Knights] diff --git a/integration-test/pom.xml b/integration-test/pom.xml index 980ddb8..432aafa 100644 --- a/integration-test/pom.xml +++ b/integration-test/pom.xml @@ -75,12 +75,6 @@ ${project.version} test
- - ${project.groupId}.knights - winegrower-knight - ${project.version} - test - ${project.groupId}.knights openwebbeans-knight diff --git a/integration-test/src/test/java/org/apache/geronimo/arthur/integrationtests/MavenTest.java b/integration-test/src/test/java/org/apache/geronimo/arthur/integrationtests/MavenTest.java index 5a24ed1..1b3dd9a 100644 --- a/integration-test/src/test/java/org/apache/geronimo/arthur/integrationtests/MavenTest.java +++ b/integration-test/src/test/java/org/apache/geronimo/arthur/integrationtests/MavenTest.java @@ -49,10 +49,6 @@ void cuilliere() {} @Spec(expectedOutput = "counter=1, from proxy=from proxy") void owb() {} - @Test - @Spec(expectedOutput = "Starting org.apache.geronimo.arthur.integrationtests.Application") - void scr() {} - @Test @Spec(expectedOutput = "" + "[main] INFO org.apache.geronimo.arthur.integrationtests.OpenJPAMain" + diff --git a/integration-test/src/test/resources/integration-tests/scr/pom.xml b/integration-test/src/test/resources/integration-tests/scr/pom.xml deleted file mode 100644 index c835d3c..0000000 --- a/integration-test/src/test/resources/integration-tests/scr/pom.xml +++ /dev/null @@ -1,156 +0,0 @@ - - - - - org.apache - apache - 21 - - 4.0.0 - - org.apache.geronimo.arthur.integrationtests - scr - 1.0.0-SNAPSHOT - Arthur :: Integration Tests :: SCR - bundle - - - - org.osgi - osgi.core - 7.0.0 - - - org.osgi - osgi.cmpn - 7.0.0 - - - - - org.apache.felix - org.apache.felix.scr - 2.1.16 - - - org.slf4j - slf4j-simple - ${slf4j.version} - - - org.apache.winegrower - winegrower-core - ${winegrower.version} - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${maven.compiler.source} - ${maven.compiler.target} - - - - org.apache.felix - maven-bundle-plugin - 4.2.1 - true - - - manifest - process-classes - - bundle - - - true - - - - - - - org.apache.geronimo.arthur - arthur-maven-plugin - ${project.version} - -
org.apache.geronimo.arthur.integrationtests.ScrMain
- - winegrower - - - - org.apache.geronimo.arthur.cache:graal-integrationtests -
-
-
-
-
diff --git a/integration-test/src/test/resources/integration-tests/scr/src/main/java/org/apache/geronimo/arthur/integrationtests/Application.java b/integration-test/src/test/resources/integration-tests/scr/src/main/java/org/apache/geronimo/arthur/integrationtests/Application.java deleted file mode 100644 index 89fcf21..0000000 --- a/integration-test/src/test/resources/integration-tests/scr/src/main/java/org/apache/geronimo/arthur/integrationtests/Application.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.geronimo.arthur.integrationtests; - -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; - -@Component(service = Application.class, immediate = true) -public class Application { - @Activate - public void init() { - System.out.println("Starting " + getClass().getName()); - } -} diff --git a/integration-test/src/test/resources/integration-tests/scr/src/main/java/org/apache/geronimo/arthur/integrationtests/ScrMain.java b/integration-test/src/test/resources/integration-tests/scr/src/main/java/org/apache/geronimo/arthur/integrationtests/ScrMain.java deleted file mode 100644 index 7857bbb..0000000 --- a/integration-test/src/test/resources/integration-tests/scr/src/main/java/org/apache/geronimo/arthur/integrationtests/ScrMain.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.geronimo.arthur.integrationtests; - -import java.io.IOException; - -import org.apache.winegrower.Ripener; - -public final class ScrMain { - private ScrMain() { - // noop - } - - // strictly speaking we could just use Ripener.main(String[]) but for an IT it is weird to not have any entry point - // - // side note: to debug the binary run: - // $ ./target/scr.graal.bin -Dorg.slf4j.simpleLogger.logFile=System.out -Dorg.slf4j.simpleLogger.defaultLogLevel=DEBUG - public static void main(final String[] args) throws IOException { - setIfMissing("org.slf4j.simpleLogger.logFile", "System.out"); - setIfMissing("org.slf4j.simpleLogger.defaultLogLevel", "WARN"); - setIfMissing("ds.service.changecount.timeout", "1"); // otherwise shutdown will wait 5s for nothing here - - final Ripener.Configuration configuration = new Ripener.Configuration(); - configuration.setJarFilter(it -> true); // we built the metadata so no scanning - try (final Ripener ripener = new Ripener.Impl(configuration).start()) { - // no-op, deployment will print "Starting org.apache.geronimo.arthur.integrationtests.Application" - } - } - - private static void setIfMissing(final String key, final String value) { - System.setProperty(key, System.getProperty(key, value)); - } -} diff --git a/knights/pom.xml b/knights/pom.xml index eff8f10..8585bc5 100644 --- a/knights/pom.xml +++ b/knights/pom.xml @@ -30,7 +30,6 @@ jsch-knight - winegrower-knight openwebbeans-knight slf4j-knight openjpa-knight diff --git a/knights/winegrower-knight/pom.xml b/knights/winegrower-knight/pom.xml deleted file mode 100644 index c8444ee..0000000 --- a/knights/winegrower-knight/pom.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - org.apache.geronimo.arthur.knights - knights - 1.0.9-SNAPSHOT - - 4.0.0 - - winegrower-knight - Arthur :: Knights :: Winegrower - - - knight.winegrower - - - - - org.slf4j - slf4j-api - - - org.apache.geronimo.arthur - arthur-spi - - - - org.apache.xbean - xbean-finder-shaded - - - org.apache.winegrower - winegrower-build-common - ${winegrower.version} - - - org.apache.commons - commons-text - 1.10.0 - - - - org.graalvm.nativeimage - svm - ${graalvm.version} - provided - - - - org.apache.geronimo.arthur - arthur-impl - - - diff --git a/knights/winegrower-knight/src/main/java/org/apache/geronimo/arthur/knight/winegrower/WinegrowerExtension.java b/knights/winegrower-knight/src/main/java/org/apache/geronimo/arthur/knight/winegrower/WinegrowerExtension.java deleted file mode 100644 index bb4c957..0000000 --- a/knights/winegrower-knight/src/main/java/org/apache/geronimo/arthur/knight/winegrower/WinegrowerExtension.java +++ /dev/null @@ -1,323 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.geronimo.arthur.knight.winegrower; - -import static java.util.Collections.list; -import static java.util.Objects.requireNonNull; -import static java.util.Optional.ofNullable; -import static org.apache.xbean.finder.ClassLoaders.findUrls; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.SimpleFileVisitor; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Objects; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.Consumer; -import java.util.function.Predicate; -import java.util.jar.JarFile; -import java.util.jar.Manifest; -import java.util.regex.Pattern; -import java.util.stream.Stream; -import java.util.zip.ZipEntry; - -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; - -import org.apache.geronimo.arthur.spi.ArthurExtension; -import org.apache.geronimo.arthur.spi.model.ClassReflectionModel; -import org.apache.geronimo.arthur.spi.model.ResourceModel; -import org.apache.winegrower.extension.build.common.MetadataBuilder; -import org.apache.xbean.finder.UrlSet; -import org.apache.xbean.finder.util.Files; -import org.w3c.dom.Document; -import org.xml.sax.SAXException; - -import lombok.extern.slf4j.Slf4j; - -@Slf4j // todo: handle manifest.mf generation (replace bundle extension?) -public class WinegrowerExtension implements ArthurExtension { - private DocumentBuilderFactory documentBuilderFactory; - private XPath xpath; - - @Override - public void execute(final Context context) { - final Predicate userFiler = context.createIncludesExcludes("extension.winegrower.", PredicateType.STARTS_WITH); - final boolean generateMetadata = Boolean.parseBoolean(ofNullable(context.getProperty("extension.winegrower.metadata.generate")).orElse("true")); - final boolean metadataAutoFiltering = Boolean.parseBoolean(ofNullable(context.getProperty("extension.winegrower.metadata.autoFiltering")).orElse("true")); - final String metadataDefaultJarName = context.getProperty("extension.winegrower.metadata.defaultJarName"); - - final Predicate filter = name -> userFiler.test(name) && - !name.startsWith("plexus-") && - !name.startsWith("animal-sniffer") && - !name.startsWith("winegrower-build") && - !name.startsWith("winegrower-core") && - !name.startsWith("winegrower-knight") && - !name.startsWith("commons-") && - !name.startsWith("xbean-") && - !name.startsWith("osgi."); - final MetadataBuilder metadata = !generateMetadata ? null : new MetadataBuilder(metadataAutoFiltering); - try { - final Collection> classes = visitClasspath(context, filter, metadata, metadataDefaultJarName); - registerClasses(context, classes); - if (metadata != null && !metadata.getMetadata().isEmpty()) { - final Path workDir = Paths.get(requireNonNull(context.getProperty("workingDirectory"), "workingDirectory property")); - if (metadata.getMetadata().containsKey("index")) { - context.addNativeImageOption("-H:WinegrowerIndex=" + - dump(workDir, "winegrower.index.properties", metadata.getMetadata().get("index"))); - } - if (metadata.getMetadata().containsKey("manifests")) { - context.addNativeImageOption("-H:WinegrowerManifests=" + - dump(workDir, "winegrower.manifests.properties", metadata.getMetadata().get("manifests"))); - } - } else if (generateMetadata) { - log.info("No winegrower metadata to dump"); - } - } catch (final IOException e) { - throw new IllegalStateException(e); - } - } - - private String dump(final Path workDir, final String name, final Properties index) { - if (!java.nio.file.Files.isDirectory(workDir)) { - try { - java.nio.file.Files.createDirectories(workDir); - } catch (final IOException e) { - throw new IllegalStateException(e); - } - } - final Path out = workDir.resolve(name); - try (final OutputStream outputStream = java.nio.file.Files.newOutputStream(out)) { - index.store(outputStream, name); - } catch (final IOException e) { - throw new IllegalStateException(e); - } - log.info("Created '{}'", out); - return out.toAbsolutePath().toString(); - } - - private void registerClasses(final Context context, final Collection> classes) { - final Consumer> logger = log.isDebugEnabled() ? c -> log.debug("Registering '{}'", c) : c -> {}; - classes.stream().peek(logger).map(it -> { - final ClassReflectionModel model = new ClassReflectionModel(); - model.setName(it.getName()); - model.setAllPublicConstructors(true); - model.setAllPublicMethods(true); - model.setAllDeclaredFields(true); - return model; - }).forEach(context::register); - } - - private Collection> visitClasspath(final Context context, final Predicate filter, - final MetadataBuilder metadata, final String metadataDefaultJarName) throws IOException { - final Collection> classes = new ArrayList<>(); - new UrlSet(findUrls(Thread.currentThread().getContextClassLoader())) - .excludeJvm() - .getUrls() - .stream() - .map(Files::toFile) - .filter(file -> filter.test(file.getName())) - .map(File::toPath) - .forEach(jarOrDirectory -> { - if (java.nio.file.Files.isDirectory(jarOrDirectory)) { - browseDirectory(context, jarOrDirectory, classes, metadata, metadataDefaultJarName); - } else if (jarOrDirectory.getFileName().toString().endsWith(".jar")) { - browseJar(context, jarOrDirectory, classes, metadata); - } else { - log.info("Ignoring '{}'", jarOrDirectory); - return; - } - if (metadata != null) { - metadata.afterJar(); - } - }); - return classes; - } - - private void browseJar(final Context context, final Path jarOrDirectory, - final Collection> classes, final MetadataBuilder metadata) { - try (final JarFile jar = new JarFile(jarOrDirectory.toFile())) { - if (metadata == null) { // winegrower metadata - Stream.of("index", "manifests") - .map(it -> "WINEGROWER-INF/" + it + ".properties") - .map(jar::getEntry) - .filter(Objects::nonNull) - .forEach(it -> context.register(resource(it.getName()))); - } - - // activator if needed - final ZipEntry manifestEntry = jar.getEntry("META-INF/MANIFEST.MF"); - if (manifestEntry != null) { - try (final InputStream inputStream = jar.getInputStream(manifestEntry)) { - final Manifest manifest = handleManifest(classes, inputStream, context); - if (metadata != null) { - metadata.onJar(jarOrDirectory.getFileName().toString(), manifest); - } - } catch (final IOException e) { - throw new IllegalStateException(e); - } - } else if (metadata != null) { - metadata.onJar(jarOrDirectory.getFileName().toString(), null); - } - - list(jar.entries()).stream() - .peek(e -> { // register metadata - if (metadata != null) { - metadata.onFile(e.getName()); - } - }) - // SCR and friends - .filter(e -> e.getName().startsWith("OSGI-INF/")) - .filter(e -> isOSGiInfDescriptor(e.getName())) - .peek(e -> { - if (e.getName().endsWith(".xml")) { - try (final InputStream stream = jar.getInputStream(e)) { - registerScrComponentsIfNeeded(jar + "#" + e.getName(), stream, classes, context); - } catch (final IOException ex) { - throw new IllegalStateException(ex); - } - } - }) - .forEach(it -> context.register(resource("OSGI-INF/" + it.getName()))); - } catch (final IOException e) { - throw new IllegalStateException(e); - } - } - - private void browseDirectory(final Context context, final Path directory, - final Collection> classes, final MetadataBuilder metadata, - final String metadataDefaultJarName) { - // winegrower metadata - if (metadata == null) { - final Path winegrowerInf = directory.resolve("WINEGROWER-INF"); - if (java.nio.file.Files.isDirectory(winegrowerInf)) { - Stream.of("index", "manifests") - .map(it -> it + ".properties") - .filter(it -> java.nio.file.Files.exists(winegrowerInf.resolve(it))) - .forEach(it -> context.register(resource("WINEGROWER-INF/" + it))); - } - } - - // activator if needed - final Path manifest = directory.resolve("META-INF/MANIFEST.MF"); - if (java.nio.file.Files.exists(manifest)) { - try (final InputStream inputStream = java.nio.file.Files.newInputStream(manifest)) { - handleManifest(classes, inputStream, context); - } catch (final IOException e) { - throw new IllegalStateException(e); - } - } - - // SCR and friends - final Path osgiInf = directory.resolve("OSGI-INF"); - if (java.nio.file.Files.isDirectory(osgiInf)) { - try { - java.nio.file.Files.list(osgiInf) - .filter(path -> isOSGiInfDescriptor(path.getFileName().toString())) - .peek(it -> { - if (it.getFileName().toString().endsWith(".xml")) { - try (final InputStream stream = java.nio.file.Files.newInputStream(it)) { - registerScrComponentsIfNeeded(it.toString(), stream, classes, context); - } catch (final IOException e) { - throw new IllegalStateException(e); - } - } - }) - .forEach(it -> context.register(resource("OSGI-INF/" + it.getFileName()))); - } catch (final IOException e) { - throw new IllegalStateException(e); - } - } - - // finally init the metadata if needed - if (metadata != null) { - metadata.visitFolder(ofNullable(metadataDefaultJarName).orElseGet(() -> { // bad heuristic to not get a NPE - final AtomicReference current = new AtomicReference<>(directory); - while (Stream.of("classes", "target").anyMatch(it -> it.equals(current.get().getFileName().toString())) && - current.get().getParent() != null && - (java.nio.file.Files.exists(current.get().getParent().resolve("pom.xml")) || - current.get().getParent().getParent() != null && - java.nio.file.Files.exists(current.get().getParent().getParent().resolve("pom.xml")))) { - current.set(current.get().getParent()); - } - return current.get().getFileName().toString(); - }), directory, new SimpleFileVisitor() {}); - } - } - - private boolean isOSGiInfDescriptor(final String filename) { - return filename.endsWith(".xml") || filename.endsWith(".properties"); - } - - private Manifest handleManifest(final Collection> classes, final InputStream inputStream, final Context context) throws IOException { - final Manifest mf = new Manifest(inputStream); - ofNullable(mf.getMainAttributes().getValue("Bundle-Activator")).ifPresent(activator -> { - try { - classes.add(context.loadClass(activator)); - } catch (final IllegalStateException e) { - log.info("Missing class: {}", activator); - } - }); - return mf; - } - - private void registerScrComponentsIfNeeded(final String source, final InputStream stream, final Collection> classes, - final Context context) { - try { - ensureXmlIsInitialized(); - - final Document document = documentBuilderFactory.newDocumentBuilder().parse(stream); - - xpath.reset(); - final String implementation = xpath.evaluate("/*[local-name()='component']/implementation/@class", document.getDocumentElement()); - if (implementation != null && !implementation.isEmpty()) { - context.findHierarchy(context.loadClass(implementation)).forEach(classes::add); - } - } catch (final XPathExpressionException | ParserConfigurationException | IOException e) { - throw new IllegalStateException(e); - } catch (final SAXException sax) { - log.warn("Can't read xml {}", source); - } catch (final IllegalStateException e) { - log.info("Missing class: {}", e.getMessage()); - } - } - - private void ensureXmlIsInitialized() throws ParserConfigurationException { - if (documentBuilderFactory == null) { - documentBuilderFactory = DocumentBuilderFactory.newInstance(); - documentBuilderFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true); - documentBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); - - xpath = XPathFactory.newInstance().newXPath(); - } - } - - private ResourceModel resource(final String name) { - final ResourceModel resource = new ResourceModel(); - resource.setPattern(Pattern.quote(name)); - return resource; - } -} diff --git a/knights/winegrower-knight/src/main/java/org/apache/geronimo/arthur/knight/winegrower/feature/WinegrowerFeature.java b/knights/winegrower-knight/src/main/java/org/apache/geronimo/arthur/knight/winegrower/feature/WinegrowerFeature.java deleted file mode 100644 index 0deacb3..0000000 --- a/knights/winegrower-knight/src/main/java/org/apache/geronimo/arthur/knight/winegrower/feature/WinegrowerFeature.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.geronimo.arthur.knight.winegrower.feature; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.Iterator; -import java.util.stream.Stream; - -import com.oracle.svm.core.annotate.AutomaticFeature; -import com.oracle.svm.core.jdk.Resources; -import com.oracle.svm.core.option.HostedOptionKey; -import org.graalvm.compiler.options.Option; -import org.graalvm.compiler.options.OptionDescriptor; -import org.graalvm.compiler.options.OptionDescriptors; -import org.graalvm.compiler.options.OptionType; -import org.graalvm.nativeimage.hosted.Feature; - -@AutomaticFeature -public class WinegrowerFeature implements Feature { - public static final class Options { - @Option(help = "Winegrower index properties.", type = OptionType.User) - static final HostedOptionKey WinegrowerIndex = new HostedOptionKey<>(null); - - @Option(help = "Winegrower manifests properties.", type = OptionType.User) - static final HostedOptionKey WinegrowerManifests = new HostedOptionKey<>(null); - } - - // org.graalvm.compiler.options.processor is not on central - public static class WinegrowerOptions implements OptionDescriptors { - @Override - public OptionDescriptor get(final String value) { - switch (value) { - case "WinegrowerIndex": - return OptionDescriptor.create( - value, OptionType.User, String.class, - "Winegrower index properties.", - Options.class, value, - Options.WinegrowerIndex); - case "WinegrowerManifests": - return OptionDescriptor.create( - value, OptionType.User, String.class, - "Winegrower manifests properties.", - Options.class, value, - Options.WinegrowerManifests); - default: - return null; - } - } - - @Override - public Iterator iterator() { - return Stream.of("WinegrowerIndex", "WinegrowerManifests").map(this::get).iterator(); - } - } - - @Override - public void beforeAnalysis(final BeforeAnalysisAccess access) { - if (Options.WinegrowerIndex.hasBeenSet()) { - register(Options.WinegrowerIndex.getValue(), "WINEGROWER-INF/index.properties"); - } - if (Options.WinegrowerManifests.hasBeenSet()) { - register(Options.WinegrowerManifests.getValue(), "WINEGROWER-INF/manifests.properties"); - } - } - - private void register(final String path, final String resource) { - try (final InputStream stream = Files.newInputStream(Paths.get(path))) { - Resources.registerResource(resource, stream); - } catch (final IOException e) { - throw new IllegalStateException(e); - } - } -} diff --git a/knights/winegrower-knight/src/main/resources/META-INF/services/org.apache.geronimo.arthur.spi.ArthurExtension b/knights/winegrower-knight/src/main/resources/META-INF/services/org.apache.geronimo.arthur.spi.ArthurExtension deleted file mode 100644 index 530211b..0000000 --- a/knights/winegrower-knight/src/main/resources/META-INF/services/org.apache.geronimo.arthur.spi.ArthurExtension +++ /dev/null @@ -1 +0,0 @@ -org.apache.geronimo.arthur.knight.winegrower.WinegrowerExtension diff --git a/knights/winegrower-knight/src/main/resources/META-INF/services/org.graalvm.compiler.options.OptionDescriptors b/knights/winegrower-knight/src/main/resources/META-INF/services/org.graalvm.compiler.options.OptionDescriptors deleted file mode 100644 index d1448ed..0000000 --- a/knights/winegrower-knight/src/main/resources/META-INF/services/org.graalvm.compiler.options.OptionDescriptors +++ /dev/null @@ -1 +0,0 @@ -org.apache.geronimo.arthur.knight.winegrower.feature.WinegrowerFeature$WinegrowerOptions