Skip to content

Commit 2a9aef9

Browse files
authored
Revert "support JAVA_HOME environment variable (#756)" (#761)
This reverts commit 3e949d8.
1 parent 5d0e7c0 commit 2a9aef9

File tree

6 files changed

+27
-54
lines changed

6 files changed

+27
-54
lines changed

apps/generator-cli/src/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ OpenAPI Generator allows generation of API client libraries (SDK generation), se
1010
configuration automatically given an OpenAPI Spec (both 2.0 and 3.0 are supported). Please see
1111
[OpenAPITools/openapi-generator](https://github.com/OpenAPITools/openapi-generator).
1212

13-
The OpenAPI Generator is a Java project. `openapi-generator-cli` will download the appropriate JAR file and invoke the `java` executable to run the OpenAPI Generator. You must have the `java` binary executable available on your `PATH` or have set `JAVA_HOME` correctly for this to work.
13+
The OpenAPI Generator is a Java project. `openapi-generator-cli` will download the appropriate JAR file and invoke the `java` executable to run the OpenAPI Generator. You must have the `java` binary executable available on your `PATH` for this to work.
1414

1515
If you find this tool useful, please consider sponsoring this project financially via https://opencollective.com/openapi_generator or directly to [Kay Schecker](https://github.com/sponsors/kay-schecker) (the author of this tool) :pray:
1616

apps/generator-cli/src/app/helpers/index.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

apps/generator-cli/src/app/services/generator.service.spec.ts

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Test } from '@nestjs/testing';
22
import { GeneratorService } from './generator.service';
33
import { LOGGER } from '../constants';
4-
import { javaCmd } from '../helpers';
54
import { VersionManagerService } from './version-manager.service';
65
import { ConfigService } from './config.service';
76

@@ -127,21 +126,20 @@ describe('GeneratorService', () => {
127126
});
128127
});
129128

130-
const cmd = (name: string, javaCmd: string, appendix: string[]) => ({
129+
const cmd = (name, appendix: string[]) => ({
131130
name,
132-
command: `${javaCmd} -jar "/path/to/4.2.1.jar" generate ${appendix.join(
131+
command: `java -jar "/path/to/4.2.1.jar" generate ${appendix.join(
133132
' '
134133
)}`,
135134
});
136135

137136
const cmdWithCustomJar = (
138137
name: string,
139-
javaCmd: string,
140138
customJar: string,
141139
appendix: string[]
142140
) => ({
143141
name,
144-
command: `${javaCmd} -cp "/path/to/4.2.1.jar:${customJar}" org.openapitools.codegen.OpenAPIGenerator generate ${appendix.join(
142+
command: `java -cp "/path/to/4.2.1.jar:${customJar}" org.openapitools.codegen.OpenAPIGenerator generate ${appendix.join(
145143
' '
146144
)}`,
147145
});
@@ -150,19 +148,19 @@ describe('GeneratorService', () => {
150148
[
151149
'foo.json',
152150
[
153-
cmd('[angular] abc/app/pet.yaml', javaCmd, [
151+
cmd('[angular] abc/app/pet.yaml', [
154152
`--input-spec="${cwd}/abc/app/pet.yaml"`,
155153
`--output="${cwd}/generated-sources/openapi/typescript-angular/pet"`,
156154
`--generator-name="typescript-angular"`,
157155
`--additional-properties="fileNaming=kebab-case,apiModulePrefix=Pet,npmName=petRestClient,supportsES6=true,withInterfaces=true"`,
158156
]),
159-
cmd('[angular] abc/app/car.yaml', javaCmd, [
157+
cmd('[angular] abc/app/car.yaml', [
160158
`--input-spec="${cwd}/abc/app/car.yaml"`,
161159
`--output="${cwd}/generated-sources/openapi/typescript-angular/car"`,
162160
`--generator-name="typescript-angular"`,
163161
`--additional-properties="fileNaming=kebab-case,apiModulePrefix=Car,npmName=carRestClient,supportsES6=true,withInterfaces=true"`,
164162
]),
165-
cmd('[baz] def/app/pet.yaml', javaCmd, [
163+
cmd('[baz] def/app/pet.yaml', [
166164
`--input-spec="${cwd}/def/app/pet.yaml"`,
167165
`--name="pet"`,
168166
`--name-uc-first="Pet"`,
@@ -176,7 +174,7 @@ describe('GeneratorService', () => {
176174
'--some-bool',
177175
'--some-int=1',
178176
]),
179-
cmd('[baz] def/app/car.json', javaCmd, [
177+
cmd('[baz] def/app/car.json', [
180178
`--input-spec="${cwd}/def/app/car.json"`,
181179
`--name="car"`,
182180
`--name-uc-first="Car"`,
@@ -195,12 +193,12 @@ describe('GeneratorService', () => {
195193
[
196194
'bar.json',
197195
[
198-
cmd('[bar] api/cat.yaml', javaCmd, [
196+
cmd('[bar] api/cat.yaml', [
199197
`--input-spec="${cwd}/api/cat.yaml"`,
200198
`--output="bar/cat"`,
201199
'--some-bool',
202200
]),
203-
cmd('[bar] api/bird.json', javaCmd, [
201+
cmd('[bar] api/bird.json', [
204202
`--input-spec="${cwd}/api/bird.json"`,
205203
`--output="bar/bird"`,
206204
'--some-bool',
@@ -210,26 +208,16 @@ describe('GeneratorService', () => {
210208
[
211209
'bar.json',
212210
[
213-
cmdWithCustomJar(
214-
'[bar] api/cat.yaml',
215-
javaCmd,
216-
'../some/custom.jar',
217-
[
218-
`--input-spec="${cwd}/api/cat.yaml"`,
219-
`--output="bar/cat"`,
220-
'--some-bool',
221-
]
222-
),
223-
cmdWithCustomJar(
224-
'[bar] api/bird.json',
225-
javaCmd,
226-
'../some/custom.jar',
227-
[
228-
`--input-spec="${cwd}/api/bird.json"`,
229-
`--output="bar/bird"`,
230-
'--some-bool',
231-
]
232-
),
211+
cmdWithCustomJar('[bar] api/cat.yaml', '../some/custom.jar', [
212+
`--input-spec="${cwd}/api/cat.yaml"`,
213+
`--output="bar/cat"`,
214+
'--some-bool',
215+
]),
216+
cmdWithCustomJar('[bar] api/bird.json', '../some/custom.jar', [
217+
`--input-spec="${cwd}/api/bird.json"`,
218+
`--output="bar/bird"`,
219+
'--some-bool',
220+
]),
233221
],
234222
'../some/custom.jar',
235223
],
@@ -238,7 +226,7 @@ describe('GeneratorService', () => {
238226
[
239227
'no-glob.json',
240228
[
241-
cmd('[noGlob] http://example.local/openapi.json', javaCmd, [
229+
cmd('[noGlob] http://example.local/openapi.json', [
242230
`--input-spec="http://example.local/openapi.json"`,
243231
`--output="no-glob/openapi"`,
244232
`--name="openapi"`,

apps/generator-cli/src/app/services/generator.service.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import * as os from 'os';
1010
import { VersionManagerService } from './version-manager.service';
1111
import { ConfigService } from './config.service';
1212
import { LOGGER } from '../constants';
13-
import { javaCmd } from '../helpers';
1413

1514
interface GeneratorConfig {
1615
glob: string;
@@ -242,8 +241,7 @@ export class GeneratorService {
242241
this.isWin() ? ';' : ':'
243242
)}" org.openapitools.codegen.OpenAPIGenerator`
244243
: `-jar "${cliPath}"`;
245-
246-
return [javaCmd, process.env['JAVA_OPTS'], subCmd, 'generate', appendix]
244+
return ['java', process.env['JAVA_OPTS'], subCmd, 'generate', appendix]
247245
.filter(isString)
248246
.join(' ');
249247
};

apps/generator-cli/src/app/services/pass-through.service.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Test } from '@nestjs/testing';
22
import chalk from 'chalk';
33
import { Command, createCommand } from 'commander';
44
import { COMMANDER_PROGRAM, LOGGER } from '../constants';
5-
import { javaCmd } from '../helpers';
65
import { GeneratorService } from './generator.service';
76
import { PassThroughService } from './pass-through.service';
87
import { VersionManagerService } from './version-manager.service';
@@ -193,7 +192,7 @@ describe('PassThroughService', () => {
193192
await program.parseAsync([name, ...argv], { from: 'user' });
194193
expect(childProcess.spawn).toHaveBeenNthCalledWith(
195194
1,
196-
`${javaCmd} -jar "/some/path/to/4.2.1.jar"`,
195+
'java -jar "/some/path/to/4.2.1.jar"',
197196
[name, ...argv],
198197
{
199198
stdio: 'inherit',
@@ -207,7 +206,7 @@ describe('PassThroughService', () => {
207206
await program.parseAsync([name, ...argv], { from: 'user' });
208207
expect(childProcess.spawn).toHaveBeenNthCalledWith(
209208
1,
210-
`${javaCmd} java-opt-1=1 -jar "/some/path/to/4.2.1.jar"`,
209+
'java java-opt-1=1 -jar "/some/path/to/4.2.1.jar"',
211210
[name, ...argv],
212211
{
213212
stdio: 'inherit',
@@ -225,7 +224,7 @@ describe('PassThroughService', () => {
225224

226225
expect(childProcess.spawn).toHaveBeenNthCalledWith(
227226
1,
228-
`${javaCmd} -cp "${[
227+
`java -cp "${[
229228
'/some/path/to/4.2.1.jar',
230229
'../some/custom.jar',
231230
].join(cpDelimiter)}" org.openapitools.codegen.OpenAPIGenerator`,
@@ -304,7 +303,7 @@ describe('PassThroughService', () => {
304303
it('spawns the correct process', () => {
305304
expect(childProcess.spawn).toHaveBeenNthCalledWith(
306305
1,
307-
`${javaCmd} -jar "/some/path/to/4.2.1.jar"`,
306+
'java -jar "/some/path/to/4.2.1.jar"',
308307
cmd.split(' '),
309308
{ stdio: 'inherit', shell: true }
310309
);

apps/generator-cli/src/app/services/pass-through.service.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { exec, spawn } from 'child_process';
44
import { Command } from 'commander';
55
import { isString, startsWith, trim } from 'lodash';
66
import { COMMANDER_PROGRAM, LOGGER } from '../constants';
7-
import { javaCmd } from '../helpers';
87
import { GeneratorService } from './generator.service';
98
import { VersionManagerService } from './version-manager.service';
109
import { ConfigService } from './config.service';
@@ -143,7 +142,7 @@ export class PassThroughService {
143142
)}" org.openapitools.codegen.OpenAPIGenerator`
144143
: `-jar "${cliPath}"`;
145144

146-
return [javaCmd, process.env['JAVA_OPTS'], subCmd]
145+
return ['java', process.env['JAVA_OPTS'], subCmd]
147146
.filter(isString)
148147
.join(' ');
149148
}

0 commit comments

Comments
 (0)