Skip to content

Commit d3fd1a9

Browse files
Preserve customized properties during SDK integration (#11635)
## Summary - Preserve manually maintained properties files during SDK integration. - Continue generating properties files for new projects and other libraries. - Add regression coverage for both behaviors. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 07d84544-66c8-4957-9868-4c6b4de24f6b
1 parent 9953b07 commit d3fd1a9

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: fix
3+
packages:
4+
- "@typespec/http-client-java"
5+
---
6+
7+
Preserve existing properties files for certain libraries during SDK integration.

packages/http-client-java/generator/http-client-generator/src/main/java/com/microsoft/typespec/http/client/generator/Main.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
public class Main {
5151
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
5252
private static final String DEFAULT_OUTPUT_DIR = "http-client-generator-test/tsp-output/";
53+
private static final String RESOURCES_ARTIFACT_ID = "azure-resourcemanager-resources";
5354
// private static final String DEFAULT_OUTPUT_DIR = "http-client-generator-clientcore-test/tsp-output/";
5455

5556
private static Yaml yaml = null;
@@ -134,7 +135,8 @@ private static void handleFluent(CodeModel codeModel, EmitterOptions emitterOpti
134135

135136
// properties file
136137
String artifactId = FluentUtils.getArtifactId();
137-
if (!CoreUtils.isNullOrEmpty(artifactId)) {
138+
if (!CoreUtils.isNullOrEmpty(artifactId)
139+
&& shouldWriteFluentPropertiesFile(emitterOptions.getOutputDir(), artifactId, sdkIntegration)) {
138140
fluentPlugin.writeFile("src/main/resources/" + artifactId + ".properties", "version=${project.version}\n",
139141
null);
140142
}
@@ -144,6 +146,15 @@ private static void handleFluent(CodeModel codeModel, EmitterOptions emitterOpti
144146
.forEach(textFile -> fluentPlugin.writeFile(textFile.getFilePath(), textFile.getContents(), null));
145147
}
146148

149+
static boolean shouldWriteFluentPropertiesFile(String outputDir, String artifactId, boolean sdkIntegration) {
150+
if (!sdkIntegration || !RESOURCES_ARTIFACT_ID.equals(artifactId)) {
151+
return true;
152+
}
153+
154+
// This library maintains additional properties by hand, so SDK integration must not overwrite the file.
155+
return Files.notExists(Paths.get(outputDir, "src/main/resources", artifactId + ".properties"));
156+
}
157+
147158
private static void handleDPG(CodeModel codeModel, EmitterOptions emitterOptions, boolean sdkIntegration,
148159
String outputDir) {
149160
// initialize plugin
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11
package com.microsoft.typespec.http.client.generator;
22

3+
import java.io.IOException;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
import org.junit.jupiter.api.Assertions;
37
import org.junit.jupiter.api.Test;
8+
import org.junit.jupiter.api.io.TempDir;
49

510
public class MainTest {
611

712
@Test
8-
public void testHello() {
13+
public void testWriteFluentPropertiesFileForNewProject(@TempDir Path tempDir) {
14+
Assertions.assertTrue(
15+
Main.shouldWriteFluentPropertiesFile(tempDir.toString(), "azure-resourcemanager-resources", true));
16+
}
17+
18+
@Test
19+
public void testWriteFluentPropertiesFileForOtherArtifact(@TempDir Path tempDir) throws IOException {
20+
Path propertiesFile = tempDir.resolve("src/main/resources/azure-resourcemanager-compute.properties");
21+
Files.createDirectories(propertiesFile.getParent());
22+
Files.writeString(propertiesFile, "version=${project.version}\n");
23+
24+
Assertions.assertTrue(
25+
Main.shouldWriteFluentPropertiesFile(tempDir.toString(), "azure-resourcemanager-compute", true));
26+
}
27+
28+
@Test
29+
public void testPreserveResourcesPropertiesFileDuringSdkIntegration(@TempDir Path tempDir) throws IOException {
30+
Path propertiesFile = tempDir.resolve("src/main/resources/azure-resourcemanager-resources.properties");
31+
Files.createDirectories(propertiesFile.getParent());
32+
Files.writeString(propertiesFile,
33+
"version=${project.version}\npremium-libraries=azure-resourcemanager-compute\n");
34+
35+
Assertions.assertFalse(
36+
Main.shouldWriteFluentPropertiesFile(tempDir.toString(), "azure-resourcemanager-resources", true));
37+
Assertions.assertTrue(
38+
Main.shouldWriteFluentPropertiesFile(tempDir.toString(), "azure-resourcemanager-resources", false));
939
}
1040
}

0 commit comments

Comments
 (0)