Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@typespec/http-client-java"
---

Preserve existing properties files for certain libraries during SDK integration.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
public class Main {
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
private static final String DEFAULT_OUTPUT_DIR = "http-client-generator-test/tsp-output/";
private static final String RESOURCES_ARTIFACT_ID = "azure-resourcemanager-resources";
// private static final String DEFAULT_OUTPUT_DIR = "http-client-generator-clientcore-test/tsp-output/";

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

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

static boolean shouldWriteFluentPropertiesFile(String outputDir, String artifactId, boolean sdkIntegration) {
if (!sdkIntegration || !RESOURCES_ARTIFACT_ID.equals(artifactId)) {
return true;
}

// This library maintains additional properties by hand, so SDK integration must not overwrite the file.
return Files.notExists(Paths.get(outputDir, "src/main/resources", artifactId + ".properties"));
}

private static void handleDPG(CodeModel codeModel, EmitterOptions emitterOptions, boolean sdkIntegration,
String outputDir) {
// initialize plugin
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
package com.microsoft.typespec.http.client.generator;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

public class MainTest {

@Test
public void testHello() {
public void testWriteFluentPropertiesFileForNewProject(@TempDir Path tempDir) {
Assertions.assertTrue(
Main.shouldWriteFluentPropertiesFile(tempDir.toString(), "azure-resourcemanager-resources", true));
}

@Test
public void testWriteFluentPropertiesFileForOtherArtifact(@TempDir Path tempDir) throws IOException {
Path propertiesFile = tempDir.resolve("src/main/resources/azure-resourcemanager-compute.properties");
Files.createDirectories(propertiesFile.getParent());
Files.writeString(propertiesFile, "version=${project.version}\n");

Assertions.assertTrue(
Main.shouldWriteFluentPropertiesFile(tempDir.toString(), "azure-resourcemanager-compute", true));
}

@Test
public void testPreserveResourcesPropertiesFileDuringSdkIntegration(@TempDir Path tempDir) throws IOException {
Path propertiesFile = tempDir.resolve("src/main/resources/azure-resourcemanager-resources.properties");
Files.createDirectories(propertiesFile.getParent());
Files.writeString(propertiesFile,
"version=${project.version}\npremium-libraries=azure-resourcemanager-compute\n");

Assertions.assertFalse(
Main.shouldWriteFluentPropertiesFile(tempDir.toString(), "azure-resourcemanager-resources", true));
Assertions.assertTrue(
Main.shouldWriteFluentPropertiesFile(tempDir.toString(), "azure-resourcemanager-resources", false));
}
}