Search in sources :

Example 1 with ParsingConfig

use of org.glassfish.hk2.classmodel.reflect.util.ParsingConfig in project Payara by payara.

the class ApplicationProcessedDocument method getTypes.

public static Types getTypes() throws IOException, InterruptedException {
    synchronized (instance) {
        if (allTypes == null) {
            File userDir = new File(System.getProperty("user.dir"));
            File modelDir = new File(userDir, "target" + File.separator + "test-classes");
            if (modelDir.exists()) {
                ParsingContext pc = (new ParsingContext.Builder().config(new ParsingConfig() {

                    @Override
                    public Set<String> getAnnotationsOfInterest() {
                        return Collections.emptySet();
                    }

                    @Override
                    public Set<String> getTypesOfInterest() {
                        return Collections.emptySet();
                    }

                    @Override
                    public boolean modelUnAnnotatedMembers() {
                        return true;
                    }
                })).build();
                Parser parser = new Parser(pc);
                parser.parse(modelDir, null);
                Exception[] exceptions = parser.awaitTermination(100, TimeUnit.DAYS);
                if (exceptions != null) {
                    for (Exception e : exceptions) {
                        System.out.println("Found Exception ! : " + e);
                    }
                    Assert.assertTrue("Exceptions returned", exceptions.length == 0);
                }
                allTypes = pc.getTypes();
            }
        }
    }
    return allTypes;
}
Also used : ParsingConfig(org.glassfish.hk2.classmodel.reflect.util.ParsingConfig) ParsingContext(org.glassfish.hk2.classmodel.reflect.ParsingContext) Set(java.util.Set) HashSet(java.util.HashSet) File(java.io.File) IOException(java.io.IOException) Parser(org.glassfish.hk2.classmodel.reflect.Parser)

Example 2 with ParsingConfig

use of org.glassfish.hk2.classmodel.reflect.util.ParsingConfig in project Payara by payara.

the class ApplicationLifecycle method getDeployableParser.

public Parser getDeployableParser(ReadableArchive source, boolean skipScanExternalLibProp, boolean modelUnAnnotatedMembers, StructuredDeploymentTracing tracing, Logger logger) throws IOException {
    try {
        ResourceLocator locator = determineLocator();
        // scan the jar and store the result in the deployment context.
        ParsingContext.Builder parsingContextBuilder = new ParsingContext.Builder().logger(logger).executorService(executorService.getUnderlyingExecutorService()).config(new ParsingConfig() {

            @Override
            public Set<String> getAnnotationsOfInterest() {
                return Collections.emptySet();
            }

            @Override
            public Set<String> getTypesOfInterest() {
                return Collections.emptySet();
            }

            @Override
            public boolean modelUnAnnotatedMembers() {
                return modelUnAnnotatedMembers;
            }
        });
        // workaround bug in Builder
        parsingContextBuilder.locator(locator);
        ParsingContext parsingContext = parsingContextBuilder.build();
        Parser parser = new Parser(parsingContext);
        ReadableArchiveScannerAdapter scannerAdapter = new ReadableArchiveScannerAdapter(parser, source);
        DeploymentSpan mainScanSpan = tracing.startSpan(DeploymentTracing.AppStage.CLASS_SCANNING, source.getName());
        parser.parse(scannerAdapter, () -> mainScanSpan.close());
        for (ReadableArchive externalLibArchive : getExternalLibraries(source, skipScanExternalLibProp)) {
            ReadableArchiveScannerAdapter libAdapter = null;
            try {
                DeploymentSpan span = tracing.startSpan(DeploymentTracing.AppStage.CLASS_SCANNING, externalLibArchive.getName());
                libAdapter = new ReadableArchiveScannerAdapter(parser, externalLibArchive);
                parser.parse(libAdapter, () -> span.close());
            } finally {
                if (libAdapter != null) {
                    libAdapter.close();
                }
            }
        }
        parser.awaitTermination();
        scannerAdapter.close();
        return parser;
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
}
Also used : ParsingConfig(org.glassfish.hk2.classmodel.reflect.util.ParsingConfig) ParsingContext(org.glassfish.hk2.classmodel.reflect.ParsingContext) DeploymentSpan(org.glassfish.internal.deployment.analysis.DeploymentSpan) IOException(java.io.IOException) ReadableArchive(org.glassfish.api.deployment.archive.ReadableArchive) ResourceLocator(org.glassfish.hk2.classmodel.reflect.util.ResourceLocator) Parser(org.glassfish.hk2.classmodel.reflect.Parser)

Aggregations

IOException (java.io.IOException)2 Parser (org.glassfish.hk2.classmodel.reflect.Parser)2 ParsingContext (org.glassfish.hk2.classmodel.reflect.ParsingContext)2 ParsingConfig (org.glassfish.hk2.classmodel.reflect.util.ParsingConfig)2 File (java.io.File)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)1 ResourceLocator (org.glassfish.hk2.classmodel.reflect.util.ResourceLocator)1 DeploymentSpan (org.glassfish.internal.deployment.analysis.DeploymentSpan)1