use of com.linkedin.restli.internal.server.model.RestLiApiBuilder in project rest.li by linkedin.
the class RestLiResourceModelExporter method export.
/**
* @param apiName the name of the API
* @param classpath classpath to to load the resources. this is purely for Javadoc Doclet {@link RestLiDoclet}
* @param sourcePaths paths to scan for resource Java source files. this is purely for Javadoc Doclet {@link RestLiDoclet}
* if both resourcePackages and resourceClasses is null, all classes defined in the directories will be scanned
* @param resourcePackages packages to scan for resources
* @param resourceClasses specific classes as resources
* @param outdir directory in which to output the IDL files
* @param additionalDocProviders names of additional classes in the classpath that implement DocsProvider, if empty,
* only javadoc will be supported.
* @return a result that includes collection of files generated and modified. Note: getSourceFiles() on the result
* will always return an empty List as the code generation operates on classpaths and the ClassLoader and not files.
* @throws IOException could be {@link java.io.FileNotFoundException} if unable to write the output file,
* otherwise, {@link IOException} if failure happened when writing the output file
*/
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 documentation will be generated for it.");
} else {
sourceFileNames.add(resourceFileName);
}
}
} else {
config.addResourceClassNames(classFileNames.keySet());
sourceFileNames = classFileNames.values();
}
}
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 Result();
}
// 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 IDL files...");
final GeneratorResult result = generateIDLFiles(apiName, outdir, rootResourceMap, docsProvider);
log.info("Done!");
return result;
}
use of com.linkedin.restli.internal.server.model.RestLiApiBuilder 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;
}
Aggregations