Skip to content

Commit

Permalink
Merge branch 'main' into http-client-java_bump-cadl-ranch
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft authored Dec 11, 2024
2 parents a7c73d9 + a862ac7 commit f0d1428
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ function getMediaTypes(type: SdkType): string[] {
function loadOperationPaging(
method: SdkServiceMethod<SdkHttpOperation>,
): OperationPaging | undefined {
if (method.kind !== "paging") {
if (method.kind !== "paging" || method.__raw_paged_metadata === undefined) {
return undefined;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/http-client-csharp/emitter/test/Unit/usage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ interface LegacyLro {
);

ok(radiologyInsightsInferenceResult);
strictEqual(radiologyInsightsInferenceResult.usage, UsageFlags.Output | UsageFlags.Json);
// TODO -- TCGC now has a bug that the LRO final result does not have Json usage when the polling operation does not have convenientAPI but the LRO has convenientAPI. https://github.com/Azure/typespec-azure/issues/1964
//strictEqual(radiologyInsightsInferenceResult.usage, UsageFlags.Output | UsageFlags.Json);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public enum InputModelTypeUsage
MultipartFormData = 32,
Spread = 64,
Error = 128,
Json = 256
Json = 256,
Xml = 512,
Exception = 1024,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"kind": "model",
"name": "InvalidAuth",
"crossLanguageDefinitionId": "Authentication.ApiKey.InvalidAuth",
"usage": "Output,Error,Json",
"usage": "Error,Json,Exception",
"decorators": [],
"properties": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"kind": "model",
"name": "InvalidAuth",
"crossLanguageDefinitionId": "Authentication.Http.Custom.InvalidAuth",
"usage": "Output,Error,Json",
"usage": "Error,Json,Exception",
"decorators": [],
"properties": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"kind": "model",
"name": "InvalidAuth",
"crossLanguageDefinitionId": "Authentication.OAuth2.InvalidAuth",
"usage": "Output,Error,Json",
"usage": "Error,Json,Exception",
"decorators": [],
"properties": [
{
Expand Down
8 changes: 4 additions & 4 deletions packages/http-client-csharp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/http-client-csharp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@azure-tools/cadl-ranch": "0.16.1",
"@azure-tools/cadl-ranch-specs": "0.39.3",
"@azure-tools/typespec-azure-core": "0.48.0",
"@azure-tools/typespec-client-generator-core": "0.48.1",
"@azure-tools/typespec-client-generator-core": "0.48.4",
"@microsoft/api-extractor": "^7.47.11",
"@types/node": "~22.7.5",
"@typespec/compiler": "0.62.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
package com.microsoft.typespec.http.client.generator.core.customization.implementation.ls;

import com.microsoft.typespec.http.client.generator.core.customization.implementation.Utils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.net.URI;
Expand All @@ -16,6 +18,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;
import org.apache.tools.tar.TarEntry;
import org.apache.tools.tar.TarInputStream;
Expand All @@ -33,7 +36,7 @@ public EclipseLanguageServerFacade(String pathToLanguageServerPlugin, Logger log
int javaVersion = Runtime.version().feature();

Path languageServerPath = (pathToLanguageServerPlugin == null)
? getLanguageServerDirectory(javaVersion, logger)
? getLanguageServerDirectory(javaVersion, logger, false)
: Paths.get(pathToLanguageServerPlugin).resolve("jdt-language-server");

List<String> command = new ArrayList<>();
Expand Down Expand Up @@ -71,18 +74,55 @@ public EclipseLanguageServerFacade(String pathToLanguageServerPlugin, Logger log
command.add("./config_linux");
}

logger.info("Starting Eclipse JDT language server at {}", languageServerPath);
server = new ProcessBuilder(command).redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectInput(ProcessBuilder.Redirect.PIPE)
.redirectErrorStream(true)
.directory(languageServerPath.toFile())
.start();
Process server = startServer(command, languageServerPath, logger);
if (!server.isAlive()) {
if (pathToLanguageServerPlugin == null) {
// If user didn't specify language server path, we do a clean re-download.
logger
.warn("Eclipse language server failed to start. The folder may be corrupted. Try re-download.");
server = startServer(command, getLanguageServerDirectory(javaVersion, logger, true), logger);
if (!server.isAlive()) {
// if server failed to start anyway, throw with server output.
throw new RuntimeException(String.format(
"Eclipse language server failed to start, error output:\n %s", readServerOutput(server)));
}
} else {
// if user specify the language server path, we just throw with server output.
throw new RuntimeException(String.format(
"Eclipse language server failed to start, error output:\n %s", readServerOutput(server)));
}
}
this.server = server;
} catch (Exception e) {
throw new RuntimeException(e);
}
}

private static Path getLanguageServerDirectory(int javaVersion, Logger logger) throws IOException {
private String readServerOutput(Process server) throws IOException {
if (server.getInputStream() == null) {
return null;
}
StringBuilder stringBuilder = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(server.getInputStream()))) {
reader.lines().forEachOrdered(line -> stringBuilder.append(line).append("\n"));
}
return stringBuilder.toString();
}

private Process startServer(List<String> command, Path languageServerPath, Logger logger) throws Exception {
logger.info("Starting Eclipse JDT language server at {}", languageServerPath);
final Process server;
server = new ProcessBuilder(command).redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectInput(ProcessBuilder.Redirect.PIPE)
.redirectErrorStream(true)
.directory(languageServerPath.toFile())
.start();
server.waitFor(1, TimeUnit.SECONDS);
return server;
}

private static Path getLanguageServerDirectory(int javaVersion, Logger logger, boolean forceReDownload)
throws IOException {
Path tmp = Paths.get(System.getProperty("java.io.tmpdir"));
Path autorestLanguageServer = tmp.resolve("autorest-java-language-server");

Expand All @@ -104,9 +144,12 @@ private static Path getLanguageServerDirectory(int javaVersion, Logger logger) t
}

Path languageServer = languageServerPath.resolve("jdt-language-server");
if (!Files.exists(languageServerPath) || !Files.exists(languageServer)) {
Files.createDirectories(languageServerPath);

if (!Files.exists(languageServer) || forceReDownload) {
Files.createDirectories(languageServer);
Path zipPath = languageServerPath.resolve("jdt-language-server.tar.gz");
Files.deleteIfExists(zipPath);

logger.info("Downloading Eclipse JDT language server from {} to {}", downloadUrl, zipPath);
try (InputStream in = downloadUrl.openStream()) {
Files.copy(in, zipPath);
Expand All @@ -122,13 +165,15 @@ private static Path getLanguageServerDirectory(int javaVersion, Logger logger) t
private static Path unzipLanguageServer(Path zipPath) throws IOException {
try (TarInputStream tar = new TarInputStream(new GZIPInputStream(Files.newInputStream(zipPath)))) {
Path languageServerDirectory = zipPath.getParent().resolve("jdt-language-server");
Files.createDirectory(languageServerDirectory);
TarEntry entry;
while ((entry = tar.getNextEntry()) != null) {
if (entry.isDirectory()) {
Files.createDirectories(languageServerDirectory.resolve(entry.getName()));
} else {
Files.copy(tar, languageServerDirectory.resolve(entry.getName()));
Path entryPath = languageServerDirectory.resolve(entry.getName());
// In case of corrupted folder, delete before create.
Files.deleteIfExists(entryPath);
Files.copy(tar, entryPath);
}
}

Expand Down

0 comments on commit f0d1428

Please sign in to comment.