MCPcopy Index your code
hub / github.com/actions/setup-java / setupJava

Function setupJava

src/distributions/base-installer.ts:48–176  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

46 ): Promise<JavaDownloadRelease>;
47
48 public async setupJava(): Promise<JavaInstallerResults> {
49 let foundJava = this.findInToolcache();
50 if (foundJava && !this.checkLatest) {
51 core.info(`Resolved Java ${foundJava.version} from tool-cache`);
52 } else {
53 core.info('Trying to resolve the latest version from remote');
54 const MAX_RETRIES = 4;
55 const RETRY_DELAY_MS = 2000;
56 const retryableCodes = [
57 'ETIMEDOUT',
58 'ECONNRESET',
59 'ENOTFOUND',
60 'ECONNREFUSED'
61 ];
62 let retries = MAX_RETRIES;
63 while (retries > 0) {
64 try {
65 // Clear console timers before each attempt to prevent conflicts
66 if (retries < MAX_RETRIES && core.isDebug()) {
67 const consoleAny = console as any;
68 consoleAny._times?.clear?.();
69 }
70 const javaRelease = await this.findPackageForDownload(this.version);
71 core.info(`Resolved latest version as ${javaRelease.version}`);
72 if (foundJava?.version === javaRelease.version) {
73 core.info(`Resolved Java ${foundJava.version} from tool-cache`);
74 } else {
75 core.info('Trying to download...');
76 foundJava = await this.downloadTool(javaRelease);
77 core.info(`Java ${foundJava.version} was downloaded`);
78 }
79 break;
80 } catch (error: any) {
81 retries--;
82 // Check if error is retryable (including aggregate errors)
83 const isRetryable =
84 (error instanceof tc.HTTPError &&
85 error.httpStatusCode &&
86 [429, 502, 503, 504, 522].includes(error.httpStatusCode)) ||
87 retryableCodes.includes(error?.code) ||
88 (error?.errors &&
89 Array.isArray(error.errors) &&
90 error.errors.some((err: any) =>
91 retryableCodes.includes(err?.code)
92 ));
93 if (retries > 0 && isRetryable) {
94 core.debug(
95 `Attempt failed due to network or timeout issues, initiating retry... (${retries} attempts left)`
96 );
97 await new Promise(r => setTimeout(r, RETRY_DELAY_MS));
98 continue;
99 }
100 if (error instanceof tc.HTTPError) {
101 if (error.httpStatusCode === 403) {
102 core.error('HTTP 403: Permission denied or access restricted.');
103 } else if (error.httpStatusCode === 429) {
104 core.warning(
105 'HTTP 429: Rate limit exceeded. Please retry later.'

Callers

nothing calls this directly

Calls 2

downloadToolMethod · 0.45

Tested by

no test coverage detected