Search in sources :

Example 1 with MultiLanguageDocsProvider

use of com.linkedin.restli.tools.idlgen.MultiLanguageDocsProvider in project rest.li by linkedin.

the class RestLiSnapshotExporter method export.

public GeneratorResult export(String apiName, String[] classpath, String[] sourcePaths, String[] resourcePackages, String[] resourceClasses, String outdir, List<DocsProvider> additionalDocProviders) throws IOException {
    final RestLiConfig config = new RestLiConfig();
    if (resourcePackages != null) {
        config.addResourcePackageNames(resourcePackages);
    }
    final Map<String, String> classFileNames = new HashMap<String, String>();
    for (String path : sourcePaths) {
        classFileNames.putAll(FileClassNameScanner.scan(path));
    }
    Collection<String> sourceFileNames = null;
    if (resourceClasses != null || resourcePackages == null) {
        if (resourceClasses != null) {
            config.addResourceClassNames(resourceClasses);
            sourceFileNames = new ArrayList<String>(resourceClasses.length);
            for (String resourceClass : resourceClasses) {
                final String resourceFileName = classFileNames.get(resourceClass);
                if (resourceFileName == null) {
                    log.warn("Unable to find source file for class " + resourceClass + " .  No Javadoc will be generated for it.");
                } else {
                    sourceFileNames.add(resourceFileName);
                }
            }
        } else {
            config.addResourceClassNames(classFileNames.keySet());
        }
    }
    log.info("Executing Rest.li annotation processor...");
    final RestLiApiBuilder apiBuilder = new RestLiApiBuilder(config);
    final Map<String, ResourceModel> rootResourceMap = apiBuilder.build();
    if (rootResourceMap.isEmpty()) {
        return new SnapshotResult();
    }
    // We always include the doc provider for javadoc
    DocsProvider javadocProvider = new DocletDocsProvider(apiName, classpath, sourcePaths, resourcePackages);
    DocsProvider docsProvider;
    if (additionalDocProviders == null || additionalDocProviders.isEmpty()) {
        docsProvider = javadocProvider;
    } else {
        // dynamically load doc providers for additional language, if available
        List<DocsProvider> languageSpecificDocsProviders = new ArrayList<DocsProvider>();
        languageSpecificDocsProviders.add(javadocProvider);
        languageSpecificDocsProviders.addAll(MultiLanguageDocsProvider.loadExternalProviders(additionalDocProviders));
        docsProvider = new MultiLanguageDocsProvider(languageSpecificDocsProviders);
    }
    log.info("Registering source files with doc providers...");
    docsProvider.registerSourceFiles(classFileNames.values());
    log.info("Exporting snapshot files...");
    final GeneratorResult result = generateSnapshotFiles(apiName, outdir, rootResourceMap, docsProvider);
    log.info("Done!");
    return result;
}
Also used : MultiLanguageDocsProvider(com.linkedin.restli.tools.idlgen.MultiLanguageDocsProvider) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DocletDocsProvider(com.linkedin.restli.tools.idlgen.DocletDocsProvider) MultiLanguageDocsProvider(com.linkedin.restli.tools.idlgen.MultiLanguageDocsProvider) DocsProvider(com.linkedin.restli.internal.server.model.ResourceModelEncoder.DocsProvider) RestLiApiBuilder(com.linkedin.restli.internal.server.model.RestLiApiBuilder) DocletDocsProvider(com.linkedin.restli.tools.idlgen.DocletDocsProvider) GeneratorResult(com.linkedin.pegasus.generator.GeneratorResult) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiConfig(com.linkedin.restli.server.RestLiConfig)

Aggregations

GeneratorResult (com.linkedin.pegasus.generator.GeneratorResult)1 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)1 DocsProvider (com.linkedin.restli.internal.server.model.ResourceModelEncoder.DocsProvider)1 RestLiApiBuilder (com.linkedin.restli.internal.server.model.RestLiApiBuilder)1 RestLiConfig (com.linkedin.restli.server.RestLiConfig)1 DocletDocsProvider (com.linkedin.restli.tools.idlgen.DocletDocsProvider)1 MultiLanguageDocsProvider (com.linkedin.restli.tools.idlgen.MultiLanguageDocsProvider)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1