Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Spring CodeGen): write pom.xml with SpringWriter. #1057

Merged
merged 5 commits into from
Oct 26, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
identified vars to pass in.
  • Loading branch information
zhumin8 committed Oct 21, 2022
commit 42d8d9270349dfd25cc3b51ae569bed9f2edc2f4
139 changes: 77 additions & 62 deletions src/main/java/com/google/api/generator/spring/SpringWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.google.api.generator.gapic.model.GapicContext;
import com.google.api.generator.gapic.model.GapicPackageInfo;
import com.google.api.generator.spring.composer.Utils;
import com.google.common.base.Splitter;
import com.google.protobuf.ByteString;
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse;
import com.google.protobuf.util.JsonFormat;
Expand Down Expand Up @@ -196,69 +197,83 @@ private static void writePom(GapicContext context, JarOutputStream jos) {
try {
jos.putNextEntry(jarEntry);
StringJoiner sb = new StringJoiner(",\\\n");

String pakkageName = context.services().get(0).pakkage();
String clientLibraryGroup =
"com.google.cloud"; // it this always true? if not how to get this info
String clientLibraryName =
Splitter.on(".").limit(2).splitToList(pakkageName).get(1); // is this safe to assume?
String clientLibraryVersion = "2.3.0"; // to pass in
pakkageName = pakkageName.replace('.', '-');
String clientLibraryTitle = context.serviceYamlProto().getTitle();
String version = "0.0.1-SNAPSHOT"; // to pass in
sb.add(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+ " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd\">\n"
+ " <modelVersion>4.0.0</modelVersion>\n"
+ "\n"
+ " <groupId>com.sample</groupId>\n"
+ " <artifactId>cloud-language</artifactId>\n"
+ " <version>0.0.1-SNAPSHOT</version>\n"
+ " <name>autoconfig</name>\n"
+ " <description>autoconfig poc project for Spring Boot</description>\n"
+ "\n"
+ "\n"
+ "<!-- Depend on the specific client library directly. Avoids dependency on libraries bom-->\n"
+ " <dependencies>\n"
+ " <dependency>\n"
+ " <groupId>com.google.cloud</groupId>\n"
+ "<!-- //safe to parse from package name? com.google.cloud.language -->\n"
+ " <artifactId>google-cloud-language</artifactId>\n"
+ " <version>2.3.0</version>\n"
+ " </dependency>\n"
+ "\n"
+ " <dependency>\n"
+ " <groupId>org.springframework.boot</groupId>\n"
+ " <artifactId>spring-boot-starter</artifactId>\n"
+ " <version>2.6.3</version>\n"
+ " </dependency>\n"
+ "\n"
+ "<!--this dependency only needed for a few util classes. Can be moved to shared location-->\n"
+ " <dependency>\n"
+ " <groupId>com.google.cloud</groupId>\n"
+ " <artifactId>spring-cloud-gcp-core</artifactId>\n"
+ " <version>3.2.1</version>\n"
+ " </dependency>\n"
+ "</dependencies>\n"
+ " <build>\n"
+ " <pluginManagement>\n"
+ " <plugins>\n"
+ " <plugin>\n"
+ " <groupId>org.apache.maven.plugins</groupId>\n"
+ " <artifactId>maven-jar-plugin</artifactId>\n"
+ " <version>3.2.2</version>\n"
+ " </plugin>\n"
+ " </plugins>\n"
+ " </pluginManagement>\n"
+ "\n"
+ " <plugins>\n"
+ " <plugin>\n"
+ " <groupId>org.apache.maven.plugins</groupId>\n"
+ " <artifactId>maven-jar-plugin</artifactId>\n"
+ " <configuration>\n"
+ " <archive>\n"
+ " <manifest>\n"
+ " <addDefaultImplementationEntries>true</addDefaultImplementationEntries>\n"
+ " </manifest>\n"
+ " </archive>\n"
+ " </configuration>\n"
+ " </plugin>\n"
+ " </plugins>\n"
+ " </build>\n"
+ "\n"
+ "</project>");
String.format(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+ " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd\">\n"
+ " <modelVersion>4.0.0</modelVersion>\n"
+ "\n"
+ " <groupId>com.google.cloud.spring</groupId>\n"
+ " <artifactId>%s-starter</artifactId>\n"
+ " <version>%s</version>\n"
+ " <name>%s Starter</name>\n"
+ " <description>Spring Boot Starter with AutoConfiguration for %s</description>\n"
+ "\n"
+ "\n"
+ " <dependencies>\n"
+ " <dependency>\n"
+ " <groupId>%s</groupId>\n"
+ " <artifactId>%s</artifactId>\n"
+ " <version>%s</version>\n"
+ " </dependency>\n"
+ "\n"
+ " <dependency>\n"
+ " <groupId>org.springframework.boot</groupId>\n"
+ " <artifactId>spring-boot-starter</artifactId>\n"
+ " <version>2.6.3</version>\n"
+ " </dependency>\n"
+ "\n"
+ "<!--this dependency only needed for a few util classes. Can be moved to shared location-->\n"
+ " <dependency>\n"
+ " <groupId>com.google.cloud</groupId>\n"
+ " <artifactId>spring-cloud-gcp-core</artifactId>\n"
+ " <version>3.2.1</version>\n"
+ " </dependency>\n"
+ "</dependencies>\n"
+ " <build>\n"
+ " <pluginManagement>\n"
+ " <plugins>\n"
+ " <plugin>\n"
+ " <groupId>org.apache.maven.plugins</groupId>\n"
+ " <artifactId>maven-jar-plugin</artifactId>\n"
+ " <version>3.2.2</version>\n"
+ " </plugin>\n"
+ " </plugins>\n"
+ " </pluginManagement>\n"
+ "\n"
+ " <plugins>\n"
+ " <plugin>\n"
+ " <groupId>org.apache.maven.plugins</groupId>\n"
+ " <artifactId>maven-jar-plugin</artifactId>\n"
+ " <configuration>\n"
+ " <archive>\n"
+ " <manifest>\n"
+ " <addDefaultImplementationEntries>true</addDefaultImplementationEntries>\n"
+ " </manifest>\n"
+ " </archive>\n"
+ " </configuration>\n"
+ " </plugin>\n"
+ " </plugins>\n"
+ " </build>\n"
+ "\n"
+ "</project>",
pakkageName,
version,
clientLibraryTitle,
clientLibraryTitle,
clientLibraryGroup,
clientLibraryName,
clientLibraryVersion));

jos.write(sb.toString().getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
Expand Down