Search in sources :

Example 1 with PackageInfoDefinition

use of com.google.api.generator.engine.ast.PackageInfoDefinition in project gapic-generator-java by googleapis.

the class JavaWriterVisitorTest method writePackageInfoDefinition.

@Test
public void writePackageInfoDefinition() {
    PackageInfoDefinition packageInfo = PackageInfoDefinition.builder().setPakkage("com.google.example.library.v1").setAnnotations(AnnotationNode.withType(TypeNode.withReference(ConcreteReference.withClazz(Generated.class)))).setFileHeader(CommentStatement.withComment(BlockComment.withComment("Lorum ipsum dolor sit amet"))).setHeaderCommentStatements(CommentStatement.withComment(JavaDocComment.withComment("Consecteteur adipisping elit"))).build();
    packageInfo.accept(writerVisitor);
    assertEquals(LineFormatter.lines("/*\n", " * Lorum ipsum dolor sit amet\n", " */\n", "\n", "/** Consecteteur adipisping elit */\n", "@Generated\n", "package com.google.example.library.v1;\n", "\n", "import javax.annotation.Generated;\n"), writerVisitor.write());
}
Also used : PackageInfoDefinition(com.google.api.generator.engine.ast.PackageInfoDefinition) Test(org.junit.Test)

Example 2 with PackageInfoDefinition

use of com.google.api.generator.engine.ast.PackageInfoDefinition in project gapic-generator-java by googleapis.

the class ImportWriterVisitorTest method writePackageInfoDefinitionImports.

@Test
public void writePackageInfoDefinitionImports() {
    PackageInfoDefinition packageInfo = PackageInfoDefinition.builder().setPakkage("com.google.example.library.v1").setAnnotations(AnnotationNode.withType(TypeNode.withReference(ConcreteReference.withClazz(Generated.class)))).setFileHeader(CommentStatement.withComment(BlockComment.withComment("Lorum ipsum dolor sit amet"))).setHeaderCommentStatements(CommentStatement.withComment(JavaDocComment.withComment("Consecteteur adipisping elit"))).build();
    packageInfo.accept(writerVisitor);
    assertEquals("import javax.annotation.Generated;\n\n", writerVisitor.write());
}
Also used : PackageInfoDefinition(com.google.api.generator.engine.ast.PackageInfoDefinition) Test(org.junit.Test)

Example 3 with PackageInfoDefinition

use of com.google.api.generator.engine.ast.PackageInfoDefinition in project gapic-generator-java by googleapis.

the class ClientLibraryPackageInfoComposer method generatePackageInfo.

public static GapicPackageInfo generatePackageInfo(GapicContext context) {
    Preconditions.checkState(!context.services().isEmpty(), "No services found to generate");
    // Pick some service's package, as we assume they are all the same.
    String libraryPakkage = context.services().get(0).pakkage();
    PackageInfoDefinition packageInfo = PackageInfoDefinition.builder().setPakkage(libraryPakkage).setHeaderCommentStatements(createPackageInfoJavadoc(context)).setAnnotations(AnnotationNode.builder().setType(TypeNode.withReference(ConcreteReference.withClazz(Generated.class))).setDescription("by gapic-generator-java").build()).build();
    return GapicPackageInfo.with(packageInfo);
}
Also used : PackageInfoDefinition(com.google.api.generator.engine.ast.PackageInfoDefinition)

Example 4 with PackageInfoDefinition

use of com.google.api.generator.engine.ast.PackageInfoDefinition in project gapic-generator-java by googleapis.

the class Writer method writePackageInfo.

private static String writePackageInfo(GapicPackageInfo gapicPackageInfo, JavaWriterVisitor codeWriter, JarOutputStream jos) {
    PackageInfoDefinition packageInfo = gapicPackageInfo.packageInfo();
    packageInfo.accept(codeWriter);
    String code = codeWriter.write();
    codeWriter.clear();
    String packagePath = "src/main/java/" + packageInfo.pakkage().replaceAll("\\.", "/");
    JarEntry jarEntry = new JarEntry(String.format("%s/package-info.java", packagePath));
    try {
        jos.putNextEntry(jarEntry);
        jos.write(code.getBytes(StandardCharsets.UTF_8));
    } catch (IOException e) {
        throw new GapicWriterException("Could not write code for package-info.java", e);
    }
    return packagePath;
}
Also used : PackageInfoDefinition(com.google.api.generator.engine.ast.PackageInfoDefinition) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) JarEntry(java.util.jar.JarEntry)

Aggregations

PackageInfoDefinition (com.google.api.generator.engine.ast.PackageInfoDefinition)4 Test (org.junit.Test)2 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1 JarEntry (java.util.jar.JarEntry)1