-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
151 additions
and
62 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
...eployment/src/main/java/io/quarkiverse/primefaces/deployment/AbstractJandexProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package io.quarkiverse.primefaces.deployment; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.DotName; | ||
|
||
import io.quarkus.deployment.builditem.CombinedIndexBuildItem; | ||
import io.quarkus.logging.Log; | ||
|
||
abstract class AbstractJandexProcessor { | ||
|
||
protected List<String> collectClassesInPackage(CombinedIndexBuildItem combinedIndex, String packageName) { | ||
final List<String> classes = new ArrayList<>(); | ||
final List<DotName> packages = new ArrayList<>(combinedIndex.getIndex().getSubpackages(packageName)); | ||
packages.add(DotName.createSimple(packageName)); | ||
for (DotName aPackage : packages) { | ||
final List<String> packageClasses = combinedIndex.getIndex() | ||
.getClassesInPackage(aPackage) | ||
.stream() | ||
.map(ClassInfo::toString) | ||
.toList(); | ||
classes.addAll(packageClasses); | ||
} | ||
Log.debugf("Package Classes: %s", classes); | ||
return classes; | ||
} | ||
|
||
protected List<String> collectInterfacesInPackage(CombinedIndexBuildItem combinedIndex, String packageName) { | ||
final List<String> classes = new ArrayList<>(); | ||
final List<DotName> packages = new ArrayList<>(combinedIndex.getIndex().getSubpackages(packageName)); | ||
packages.add(DotName.createSimple(packageName)); | ||
for (DotName aPackage : packages) { | ||
final List<String> packageClasses = combinedIndex.getIndex() | ||
.getClassesInPackage(aPackage) | ||
.stream() | ||
.filter(ClassInfo::isInterface) // Filter only interfaces | ||
.map(ClassInfo::toString) | ||
.toList(); | ||
classes.addAll(packageClasses); | ||
} | ||
Log.debugf("Package Interfaces: %s", classes); | ||
return classes; | ||
} | ||
|
||
protected List<String> collectSubclasses(CombinedIndexBuildItem combinedIndex, String className) { | ||
List<String> classes = combinedIndex.getIndex() | ||
.getAllKnownSubclasses(DotName.createSimple(className)) | ||
.stream() | ||
.map(ClassInfo::toString) | ||
.collect(Collectors.toList()); | ||
classes.add(className); | ||
Log.debugf("Subclasses: %s", classes); | ||
return classes; | ||
} | ||
|
||
protected List<String> collectImplementors(CombinedIndexBuildItem combinedIndex, String className) { | ||
Set<String> classes = combinedIndex.getIndex() | ||
.getAllKnownImplementors(DotName.createSimple(className)) | ||
.stream() | ||
.map(ClassInfo::toString) | ||
.collect(Collectors.toCollection(HashSet::new)); | ||
classes.add(className); | ||
Set<String> subclasses = new HashSet<>(); | ||
for (String implementationClass : classes) { | ||
subclasses.addAll(collectSubclasses(combinedIndex, implementationClass)); | ||
} | ||
classes.addAll(subclasses); | ||
Log.debugf("Implementors: %s", classes); | ||
return new ArrayList<>(classes); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...ces/deployment/src/main/java/io/quarkiverse/primefaces/deployment/Barcode4JProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.quarkiverse.primefaces.deployment; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.CombinedIndexBuildItem; | ||
import io.quarkus.deployment.builditem.IndexDependencyBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBundleBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; | ||
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedPackageBuildItem; | ||
import io.quarkus.logging.Log; | ||
|
||
/** | ||
* Register Barcode4J library. | ||
*/ | ||
public class Barcode4JProcessor extends AbstractJandexProcessor { | ||
|
||
@BuildStep | ||
void indexTransitiveDependencies(BuildProducer<IndexDependencyBuildItem> index) { | ||
index.produce(new IndexDependencyBuildItem("org.primefaces.extensions", "barcode4j-light")); | ||
} | ||
|
||
@BuildStep | ||
void runtimeBarcodeInitializedClasses(BuildProducer<RuntimeInitializedPackageBuildItem> runtimeInitializedPackages) { | ||
//@formatter:off | ||
List<String> classes = new ArrayList<>( | ||
Stream.of(org.krysalis.barcode4j.output.bitmap.BitmapEncoderRegistry.class.getName(), | ||
"javax.swing.plaf.metal", | ||
"javax.swing.text.html", | ||
"javax.swing.text.rtf", | ||
"sun.datatransfer", | ||
"sun.swing" | ||
).toList()); | ||
//@formatter:on | ||
Log.debugf("Barcode4J Runtime: %s", classes); | ||
classes.stream() | ||
.map(RuntimeInitializedPackageBuildItem::new) | ||
.forEach(runtimeInitializedPackages::produce); | ||
} | ||
|
||
@BuildStep | ||
void registerBarcodeForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass, | ||
CombinedIndexBuildItem combinedIndex) { | ||
final List<String> classNames = new ArrayList<>(); | ||
classNames.add("javax.imageio.ImageIO"); | ||
classNames.add(org.krysalis.barcode4j.output.bitmap.ImageIOBitmapEncoder.class.getName()); | ||
|
||
Log.debugf("Barcode4J Reflection: %s", classNames); | ||
// methods and fields | ||
reflectiveClass.produce( | ||
ReflectiveClassBuildItem.builder(classNames.toArray(new String[0])).methods().fields().serialization().build()); | ||
} | ||
|
||
@BuildStep | ||
void registerBarcodeResources(BuildProducer<NativeImageResourceBuildItem> nativeImageResourceProducer, | ||
BuildProducer<NativeImageResourceBundleBuildItem> resourceBundleBuildItem) { | ||
// Register individual resource files | ||
nativeImageResourceProducer.produce(new NativeImageResourceBuildItem( | ||
"org/krysalis/barcode4j/impl/fourstate/usps-4bc-bar-to-character-table.csv")); | ||
|
||
// Register resource bundles | ||
resourceBundleBuildItem | ||
.produce(new NativeImageResourceBundleBuildItem("org.krysalis.barcode4j.impl.code128.EAN128AIs")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters