use of com.google.common.io.Resources in project curiostack by curioswitch.
the class GrpcApiPlugin method apply.
@Override
public void apply(Project project) {
project.getPluginManager().apply(JavaLibraryPlugin.class);
project.getExtensions().create(ImmutableGrpcExtension.NAME, GrpcExtension.class);
GRPC_DEPENDENCIES.forEach(dep -> project.getDependencies().add("api", "io.grpc:" + dep));
project.afterEvaluate(p -> {
ImmutableGrpcExtension config = project.getExtensions().getByType(GrpcExtension.class);
Map<String, String> managedVersions = project.getExtensions().getByType(DependencyManagementExtension.class).getManagedVersions();
ProtobufConfigurator protobuf = project.getConvention().getPlugin(ProtobufConvention.class).getProtobuf();
protobuf.protoc(LambdaClosure.of((ExecutableLocator locator) -> locator.setArtifact("com.google.protobuf:protoc:" + managedVersions.get("com.google.protobuf:protoc"))));
protobuf.plugins(LambdaClosure.of((NamedDomainObjectContainer<ExecutableLocator> locators) -> {
locators.create("grpc").setArtifact("io.grpc:protoc-gen-grpc-java:" + managedVersions.get("io.grpc:grpc-core"));
if (config.web()) {
locators.create("ts").setPath(project.file("node_modules/.bin/protoc-gen-ts-resolved" + (IS_WINDOWS ? ".cmd" : "")).getAbsolutePath());
}
}));
String archivesBaseName = project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName();
String descriptorSetOutputPath = project.getBuildDir() + "/resources/main/META-INF/armeria/grpc/" + project.getGroup() + "." + archivesBaseName + ".dsc";
protobuf.generateProtoTasks(LambdaClosure.of((JavaGenerateProtoTaskCollection tasks) -> {
tasks.all().forEach(task -> {
task.getBuiltins().getByName("java").setOutputSubDir("");
task.getPlugins().create("grpc").setOutputSubDir("");
if (config.web()) {
// We generate web protos into build/web to make it easier to
// reference from other projects.
task.getBuiltins().create("js").option("import_style=commonjs,binary").setOutputSubDir("../../../../web");
task.getPlugins().create("ts").option("service=true").setOutputSubDir("../../../../web");
}
});
tasks.ofSourceSet("main").forEach(task -> {
task.getOutputs().file(descriptorSetOutputPath);
task.setGenerateDescriptorSet(true);
DescriptorSetOptions options = task.getDescriptorSetOptions();
options.setIncludeSourceInfo(true);
options.setIncludeImports(true);
options.setPath(new GStringImpl(new Object[] {}, new String[] { descriptorSetOutputPath }));
});
}));
});
// Add the protobuf plugin last to make sure our afterEvaluate runs before it.
project.getPluginManager().apply(ProtobufPlugin.class);
// Additional configuration of tasks created by protobuf plugin.
project.afterEvaluate(p -> {
ImmutableGrpcExtension config = project.getExtensions().getByType(GrpcExtension.class);
if (config.web()) {
String currentProjectPath = project.getPath().replace(':', '_');
NpmTask installTsProtocGen = project.getRootProject().getTasks().create("installTsProtocGen_" + currentProjectPath, NpmTask.class);
installTsProtocGen.setWorkingDir(project.getProjectDir());
installTsProtocGen.setArgs(ImmutableList.of("install", "--no-save", "ts-protoc-gen@" + TS_PROTOC_GEN_VERSION));
installTsProtocGen.getInputs().property("ts-protoc-gen-version", TS_PROTOC_GEN_VERSION);
installTsProtocGen.getOutputs().dir("node_modules/ts-protoc-gen");
// gradle-protobuf-plugin does not allow manipulating PATH for protoc invocation, so
// there's no way
// to point it at our downloaded nodejs. We go ahead and create our own plugin
// executable with the
// nodejs path resolved.
Task addResolvedPluginScript = project.getTasks().create("addResolvedPluginScript").dependsOn(installTsProtocGen).doFirst(t -> {
String nodePath = project.getRootProject().getExtensions().getByType(NodeExtension.class).getVariant().getNodeExec();
writeResolvedScript(project, nodePath, "protoc-gen-ts-resolved", "ts-protoc-gen/lib/ts_index");
});
addResolvedPluginScript.getOutputs().files(ImmutableMap.of("protoc-gen-ts-resolved", "node_modules/.bin/protoc-gen-ts-resolved", "protoc-gen-ts-resolved-cmd", "node_modules/.bin/protoc-gen-ts-resolved.cmd"));
String packageName = config.webPackageName().isEmpty() ? project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName() : config.webPackageName();
Path packageJsonPath = Paths.get(project.getBuildDir().getAbsolutePath(), "web", "package.json");
Path indexJsPath = Paths.get(project.getBuildDir().getAbsolutePath(), "web", "index.ts");
Path tsConfigPath = Paths.get(project.getBuildDir().getAbsolutePath(), "web", "tsconfig.json");
Task addPackageJson = project.getTasks().create("packageJson").dependsOn("generateProto").doFirst(t -> {
try {
Files.write(packageJsonPath, PACKAGE_JSON_TEMPLATE.replaceFirst("\\|PACKAGE_NAME\\|", packageName).replaceFirst("\\|TYPES_GOOGLE_PROTOBUF_VERSION\\|", TYPES_GOOGLE_PROTOBUF_VERSION).replaceFirst("\\|GOOGLE_PROTOBUF_VERSION\\|", GOOGLE_PROTOBUF_VERSION).replaceFirst("\\|GRPC_WEB_CLIENT_VERSION\\|", GRPC_WEB_CLIENT_VERSION).replaceFirst("\\|CURIOSTACK_BASE_NODE_DEV_VERSION\\|", CURIOSTACK_BASE_NODE_DEV_VERSION).getBytes(StandardCharsets.UTF_8));
Files.write(tsConfigPath, TSCONFIG_TEMPLATE.getBytes(StandardCharsets.UTF_8));
Files.write(indexJsPath, new byte[0]);
} catch (IOException e) {
throw new UncheckedIOException("Could not write package.json.", e);
}
});
addPackageJson.getOutputs().files(ImmutableMap.of("PACKAGE_JSON", packageJsonPath.toFile(), "INDEX_TS", indexJsPath.toFile(), "TS_CONFIG", tsConfigPath.toFile()));
Task generateProto = project.getTasks().getByName("generateProto");
generateProto.dependsOn(addResolvedPluginScript).finalizedBy(addPackageJson);
project.getRootProject().getTasks().findByName("yarn").dependsOn(generateProto);
// Unclear why sometimes compileTestJava fails with "no source files" instead of being
// skipped (usually when activating web), but it's not that hard to at least check the
// source set directory.
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
if (sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME).getAllJava().isEmpty()) {
project.getTasks().getByName("compileTestJava").setEnabled(false);
}
}
});
}
use of com.google.common.io.Resources in project rpki-validator-3 by RIPE-NCC.
the class TrustAnchorsFactory method createCertificateAuthority.
public X509ResourceCertificate createCertificateAuthority(CertificateAuthority ca, CertificateAuthority issuer, ValidityPeriod mftValidityPeriod) {
ManifestCmsBuilder manifestBuilder = new ManifestCmsBuilder();
X509ResourceCertificate caCertificate = createCaCertificate(ca, ca.keyPair.getPublic(), issuer.dn, issuer.crlDistributionPoint, issuer.keyPair);
X509Crl crl = new X509CrlBuilder().withIssuerDN(caCertificate.getSubject()).withThisUpdateTime(DateTime.now()).withNextUpdateTime(DateTime.now().plusHours(8)).withAuthorityKeyIdentifier(ca.keyPair.getPublic()).withNumber(nextSerial()).build(ca.keyPair.getPrivate());
rpkiObjects.add(new RpkiObject(ca.crlDistributionPoint, crl));
manifestBuilder.addFile(ca.crlDistributionPoint.substring(ca.crlDistributionPoint.lastIndexOf('/') + 1), crl.getEncoded());
if (ca.children != null) {
for (CertificateAuthority child : ca.children) {
X509ResourceCertificate childCertificate = createCertificateAuthority(child, ca);
rpkiObjects.add(new RpkiObject(ca.repositoryURI + "/" + child.dn + ".cer", childCertificate));
manifestBuilder.addFile(child.dn + ".cer", childCertificate.getEncoded());
}
}
if (ca.roaPrefixes != null) {
ca.roaPrefixes.stream().collect(groupingBy(RoaPrefix::getAsn)).forEach((asn, roaPrefix) -> {
KeyPair roaKeyPair = KEY_PAIR_FACTORY.generate();
IpResourceSet resources = new IpResourceSet();
roaPrefix.stream().forEach(p -> resources.add(IpRange.parse(p.getPrefix())));
X509ResourceCertificate roaCertificate = new X509ResourceCertificateBuilder().withResources(resources).withIssuerDN(new X500Principal(ca.dn)).withSubjectDN(new X500Principal("CN=AS" + asn + ", CN=roa, " + ca.dn)).withValidityPeriod(typicalValidityPeriod()).withPublicKey(roaKeyPair.getPublic()).withSigningKeyPair(ca.keyPair).withCa(false).withKeyUsage(KeyUsage.digitalSignature).withSerial(nextSerial()).withCrlDistributionPoints(URI.create(ca.crlDistributionPoint)).build();
RoaCms roaCms = new RoaCmsBuilder().withAsn(new Asn(asn)).withPrefixes(roaPrefix.stream().map(p -> new net.ripe.rpki.commons.crypto.cms.roa.RoaPrefix(IpRange.parse(p.getPrefix()), p.getMaximumLength())).collect(toList())).withCertificate(roaCertificate).withSignatureProvider(BouncyCastleProvider.PROVIDER_NAME).build(roaKeyPair.getPrivate());
rpkiObjects.add(new RpkiObject(ca.repositoryURI + "/" + "AS" + asn + ".roa", roaCms));
manifestBuilder.addFile("AS" + asn + ".roa", roaCms.getEncoded());
});
}
KeyPair manifestKeyPair = KEY_PAIR_FACTORY.generate();
X509ResourceCertificate manifestCertificate = new X509ResourceCertificateBuilder().withInheritedResourceTypes(EnumSet.allOf(IpResourceType.class)).withIssuerDN(caCertificate.getSubject()).withSubjectDN(new X500Principal("CN=manifest, " + caCertificate.getSubject())).withValidityPeriod(mftValidityPeriod).withPublicKey(manifestKeyPair.getPublic()).withSigningKeyPair(ca.keyPair).withCa(false).withKeyUsage(KeyUsage.digitalSignature).withSerial(nextSerial()).withCrlDistributionPoints(URI.create(ca.crlDistributionPoint)).build();
manifestBuilder.withCertificate(manifestCertificate).withManifestNumber(nextSerial()).withThisUpdateTime(DateTime.now()).withNextUpdateTime(DateTime.now().plusHours(8));
ManifestCms manifest = manifestBuilder.build(manifestKeyPair.getPrivate());
rpkiObjects.add(new RpkiObject(ca.manifestURI, manifest));
return caCertificate;
}
Aggregations