use of org.scannotation.AnnotationDB in project simplejpa by appoxy.
the class EntityManagerFactoryImpl method scanClasses.
private void scanClasses(Set<String> libsToScan) {
try {
logger.info("Scanning for entity classes...");
URL[] urls;
try {
urls = ClasspathUrlFinder.findClassPaths();
} catch (Exception e) {
System.err.println("CAUGHT");
e.printStackTrace();
urls = new URL[0];
}
if (libsToScan != null) {
URL[] urls2 = new URL[urls.length + libsToScan.size()];
System.arraycopy(urls, 0, urls2, 0, urls.length);
// urls = new URL[libsToScan.size()];
int count = 0;
for (String s : libsToScan) {
logger.fine("libinset=" + s);
urls2[count + urls.length] = new File(s).toURL();
count++;
}
urls = urls2;
}
logger.info("classpath=" + System.getProperty("java.class.path"));
for (URL url : urls) {
logger.info("Scanning: " + url.toString());
}
if (logger.isLoggable(Level.FINE)) {
logger.fine("classpath urls:");
for (URL url : urls) {
logger.fine(url.toString());
}
}
AnnotationDB annotationDB = new AnnotationDB();
annotationDB.scanArchives(urls);
entities = annotationDB.getAnnotationIndex().get(Entity.class.getName());
if (entities != null) {
for (String entity : entities) {
initEntity(entity);
}
}
logger.info("Finished scanning for entity classes.");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.scannotation.AnnotationDB in project simplejpa by appoxy.
the class AnnotationTests method findAnnotations.
@Test
public void findAnnotations() throws IOException {
// scan java.class.path
URL[] urls = ClasspathUrlFinder.findClassPaths();
AnnotationDB db = new AnnotationDB();
db.scanArchives(urls);
Set<String> entities = db.getAnnotationIndex().get(Entity.class.getName());
for (String entity : entities) {
System.out.println("entity=" + entity);
}
}
use of org.scannotation.AnnotationDB in project sling by apache.
the class GenerateAdapterMetadataMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
try {
final Map<String, Object> descriptor = new HashMap<>();
final AnnotationDB annotationDb = new AnnotationDB();
annotationDb.scanArchives(buildOutputDirectory.toURI().toURL());
final Set<String> annotatedClassNames = new HashSet<String>();
addAnnotatedClasses(annotationDb, annotatedClassNames, Adaptable.class);
addAnnotatedClasses(annotationDb, annotatedClassNames, Adaptables.class);
for (final String annotatedClassName : annotatedClassNames) {
getLog().info(String.format("found adaptable annotation on %s", annotatedClassName));
final String pathToClassFile = annotatedClassName.replace('.', '/') + ".class";
final File classFile = new File(buildOutputDirectory, pathToClassFile);
final FileInputStream input = new FileInputStream(classFile);
final ClassReader classReader;
try {
classReader = new ClassReader(input);
} finally {
input.close();
}
final ClassNode classNode = new ClassNode();
classReader.accept(classNode, SKIP_CODE | SKIP_DEBUG | SKIP_FRAMES);
@SuppressWarnings("unchecked") final List<AnnotationNode> annotations = classNode.invisibleAnnotations;
for (final AnnotationNode annotation : annotations) {
if (ADAPTABLE_DESC.equals(annotation.desc)) {
parseAdaptableAnnotation(annotation, classNode, descriptor);
} else if (ADAPTABLES_DESC.equals(annotation.desc)) {
parseAdaptablesAnnotation(annotation, classNode, descriptor);
}
}
}
final File outputFile = new File(outputDirectory, fileName);
outputFile.getParentFile().mkdirs();
try (FileWriter writer = new FileWriter(outputFile);
JsonWriter jsonWriter = Json.createWriter(writer)) {
jsonWriter.writeObject(JsonSupport.toJson(descriptor));
}
addResource();
} catch (IOException e) {
throw new MojoExecutionException("Unable to generate metadata", e);
} catch (JsonException e) {
throw new MojoExecutionException("Unable to generate metadata", e);
}
}
use of org.scannotation.AnnotationDB in project compiler by boalang.
the class SymbolTable method importLibs.
private static void importLibs(final List<URL> urls) throws IOException {
// load built-in functions
final Class<?>[] builtinFuncs = { boa.functions.BoaAstIntrinsics.class, boa.functions.BoaGraphIntrinsics.class, boa.functions.BoaIntrinsics.class, boa.functions.BoaMetricIntrinsics.class, boa.functions.BoaModifierIntrinsics.class, boa.functions.BoaCasts.class, boa.functions.BoaMathIntrinsics.class, boa.functions.BoaSortIntrinsics.class, boa.functions.BoaSpecialIntrinsics.class, boa.functions.BoaStringIntrinsics.class, boa.functions.BoaTimeIntrinsics.class };
for (final Class<?> c : builtinFuncs) importFunctions(c);
// load built-in aggregators
final Class<?>[] builtinAggs = { boa.aggregators.BottomAggregator.class, boa.aggregators.CollectionAggregator.class, boa.aggregators.ConfidenceIntervalAggregator.class, boa.aggregators.DistinctAggregator.class, boa.aggregators.FloatHistogramAggregator.class, boa.aggregators.FloatMeanAggregator.class, boa.aggregators.FloatQuantileAggregator.class, boa.aggregators.FloatSumAggregator.class, boa.aggregators.GraphAggregator.class, boa.aggregators.GraphvizAggregator.class, boa.aggregators.IntHistogramAggregator.class, boa.aggregators.IntMeanAggregator.class, boa.aggregators.IntQuantileAggregator.class, boa.aggregators.IntSumAggregator.class, boa.aggregators.KurtosisAggregator.class, boa.aggregators.LogAggregator.class, boa.aggregators.MaximumAggregator.class, boa.aggregators.MedianAggregator.class, boa.aggregators.MinimumAggregator.class, boa.aggregators.SetAggregator.class, boa.aggregators.SkewnessAggregator.class, boa.aggregators.StatisticsAggregator.class, boa.aggregators.StDevAggregator.class, boa.aggregators.TopAggregator.class, boa.aggregators.UniqueAggregator.class, boa.aggregators.VarianceAggregator.class };
for (final Class<?> c : builtinAggs) importAggregator(c);
// also check any libs passed into the compiler
if (urls.size() > 0) {
final AnnotationDB db = new AnnotationDB();
db.setScanMethodAnnotations(true);
db.setScanClassAnnotations(true);
for (final URL url : urls) db.scanArchives(url);
final Map<String, Set<String>> annotationIndex = db.getAnnotationIndex();
for (final String s : annotationIndex.get(AggregatorSpec.class.getCanonicalName())) importAggregator(s);
for (final String s : annotationIndex.get(FunctionSpec.class.getCanonicalName())) importFunctions(s);
}
}
Aggregations