mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
add bundled markdown doc SPI layer
This commit is contained in:
parent
7d92c37c55
commit
26b5ba161b
@ -0,0 +1,26 @@
|
||||
package io.nosqlbench.engine.api.activityimpl.uniform;
|
||||
|
||||
import io.nosqlbench.docapi.BundledMarkdownManifest;
|
||||
import io.nosqlbench.docapi.Docs;
|
||||
import io.nosqlbench.docapi.DocsBinder;
|
||||
import io.nosqlbench.nb.annotations.Maturity;
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
import io.nosqlbench.nb.api.spi.SimpleServiceLoader;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service(value = BundledMarkdownManifest.class, selector = "adapter-docs")
|
||||
public class BundledDriverAdapterDocs implements BundledMarkdownManifest {
|
||||
@Override
|
||||
public DocsBinder getDocs() {
|
||||
Docs docs = new Docs().namespace("adapter-docs");
|
||||
SimpleServiceLoader<DriverAdapter> loader = new SimpleServiceLoader<>(DriverAdapter.class, Maturity.Any);
|
||||
List<SimpleServiceLoader.Component<? extends DriverAdapter>> namedProviders = loader.getNamedProviders();
|
||||
for (SimpleServiceLoader.Component<? extends DriverAdapter> namedProvider : namedProviders) {
|
||||
DriverAdapter driverAdapter = namedProvider.provider.get();
|
||||
DocsBinder bundledDocs = driverAdapter.getBundledDocs();
|
||||
docs.merge(bundledDocs);
|
||||
}
|
||||
return docs;
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
package io.nosqlbench.docapi;
|
||||
|
||||
import joptsimple.OptionParser;
|
||||
import joptsimple.OptionSet;
|
||||
import joptsimple.OptionSpec;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.DirectoryStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
public class BundledMarkdownExporter {
|
||||
public static void main(String[] args) {
|
||||
|
||||
final OptionParser parser = new OptionParser();
|
||||
|
||||
OptionSpec<String> zipfileSpec = parser.accepts("zipfile", "zip file to write to")
|
||||
.withOptionalArg().ofType(String.class).defaultsTo("exported_docs.zip");
|
||||
|
||||
OptionSpec<?> helpSpec = parser.acceptsAll(List.of("help", "h", "?"), "Display help").forHelp();
|
||||
OptionSet options = parser.parse(args);
|
||||
if (options.has(helpSpec)) {
|
||||
try {
|
||||
parser.printHelpOn(System.out);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to show help:" + e);
|
||||
}
|
||||
}
|
||||
|
||||
String zipfile = options.valueOf(zipfileSpec);
|
||||
|
||||
new BundledMarkdownExporter().exportDocs(Path.of(zipfile));
|
||||
}
|
||||
|
||||
private void exportDocs(Path out) {
|
||||
ZipOutputStream zipstream;
|
||||
try {
|
||||
OutputStream stream = Files.newOutputStream(out, StandardOpenOption.WRITE, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
|
||||
zipstream = new ZipOutputStream(stream);
|
||||
zipstream.setMethod(ZipOutputStream.DEFLATED);
|
||||
zipstream.setLevel(9);
|
||||
|
||||
DocsBinder docsNameSpaces = BundledMarkdownLoader.loadBundledMarkdown();
|
||||
for (DocsNameSpace docs_ns : docsNameSpaces) {
|
||||
for (Path p : docs_ns) {
|
||||
addEntry(p, p.getParent(), zipstream);
|
||||
}
|
||||
}
|
||||
zipstream.finish();
|
||||
stream.close();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void addEntry(Path p, Path r, ZipOutputStream zos) throws IOException {
|
||||
|
||||
String name = r.relativize(p).toString();
|
||||
name = Files.isDirectory(p) ? (name.endsWith(File.separator) ? name : name + File.separator) : name;
|
||||
|
||||
ZipEntry entry = new ZipEntry(name);
|
||||
|
||||
|
||||
if (Files.isDirectory(p)) {
|
||||
zos.putNextEntry(entry);
|
||||
DirectoryStream<Path> stream = Files.newDirectoryStream(p);
|
||||
for (Path path : stream) {
|
||||
addEntry(path,r,zos);
|
||||
}
|
||||
zos.closeEntry();
|
||||
} else {
|
||||
entry.setTime(Files.getLastModifiedTime(p).toMillis());
|
||||
zos.putNextEntry(entry);
|
||||
byte[] bytes = Files.readAllBytes(p);
|
||||
zos.write(bytes);
|
||||
zos.closeEntry();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package io.nosqlbench.docapi;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
public class BundledMarkdownLoader {
|
||||
|
||||
public static DocsBinder loadBundledMarkdown() {
|
||||
ServiceLoader<BundledMarkdownManifest> loader = ServiceLoader.load(BundledMarkdownManifest.class);
|
||||
Docs docs = new Docs();
|
||||
for (BundledMarkdownManifest docPathInfos : loader) {
|
||||
docs.merge(docPathInfos.getDocs());
|
||||
}
|
||||
|
||||
return docs;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package io.nosqlbench.docapi;
|
||||
|
||||
/**
|
||||
* At runtime, any instances of markdown content or other static
|
||||
* assets which are intended to be copied into the external doc site,
|
||||
* or otherwise made available under a local doc service.
|
||||
*/
|
||||
public interface BundledMarkdownManifest {
|
||||
DocsBinder getDocs();
|
||||
}
|
@ -36,6 +36,7 @@ public class SimpleServiceLoader<T> {
|
||||
this.serviceType = serviceType;
|
||||
this.maturity = maturity;
|
||||
}
|
||||
|
||||
public SimpleServiceLoader setMaturity(Maturity maturity) {
|
||||
this.maturity = maturity;
|
||||
return this;
|
||||
@ -80,9 +81,8 @@ public class SimpleServiceLoader<T> {
|
||||
public synchronized List<Component<? extends T>> getNamedProviders(String... includes) {
|
||||
ServiceLoader<? extends T> loader = ServiceLoader.load(serviceType);
|
||||
List<String> defaultedPatterns = (includes != null && includes.length > 0) ? Arrays.asList(includes) : List.of(".*");
|
||||
List<Pattern> qualifiedPatterns = defaultedPatterns.stream().map(p -> {
|
||||
return Pattern.compile(p);
|
||||
}).collect(Collectors.toList());
|
||||
List<Pattern> qualifiedPatterns = defaultedPatterns.stream()
|
||||
.map(Pattern::compile).collect(Collectors.toList());
|
||||
|
||||
List<Component<? extends T>> components = new ArrayList<>();
|
||||
|
||||
|
@ -0,0 +1,12 @@
|
||||
package io.nosqlbench.docapi;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class BundledMarkdownExporterTest {
|
||||
|
||||
@Test
|
||||
public void zipUpDocs() {
|
||||
BundledMarkdownExporter.main(new String[0]);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package io.nosqlbench.docapi;
|
||||
|
||||
import io.nosqlbench.nb.annotations.Service;
|
||||
|
||||
@Service(value = BundledMarkdownManifest.class, selector = "bundled-markdown-test-docs")
|
||||
public class BundledMarkdownTestManifest implements BundledMarkdownManifest {
|
||||
@Override
|
||||
public DocsBinder getDocs() {
|
||||
return new Docs()
|
||||
.namespace("bundled-markdown-test-docs")
|
||||
.addFirstFoundContentPath(
|
||||
"nb-api/src/test/resources/testsite1/",
|
||||
"testsite1"
|
||||
)
|
||||
.asDocsBinder();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user