Skip to content

Commit 1db32cd

Browse files
joekillertylerjroachgpanshusdhuka
authored
fix(amplify-tools): use projectDir for project.file relative paths (#2011)
- use [standard project property][1] `projectDir` for plugin Per gradle docs [working with files/single file paths][2] project tasks are based on the current working directory. If the project is launched from a menu bar there may not be a current working directory. Pain source: https://youtrack.jetbrains.com/issue/IDEA-265203/Gradle-run-configuration-might-not-use-project-dir-as-working-directory-for-a-task#focus=Comments-27-4834821.0-0 [1]:https://docs.gradle.org/current/userguide/writing_build_scripts.html#sec:standard_project_properties [2]:https://docs.gradle.org/current/userguide/working_with_files.html#sec:single_file_paths Co-authored-by: Tyler Roach <[email protected]> Co-authored-by: gpanshu <[email protected]> Co-authored-by: Saijad Dhuka <[email protected]>
1 parent bf9dc20 commit 1db32cd

File tree

1 file changed

+16
-12
lines changed
  • amplify-tools/amplify-tools-gradle-plugin/src/main/groovy/com/amplifyframework/tools/gradle/plugin

1 file changed

+16
-12
lines changed

amplify-tools/amplify-tools-gradle-plugin/src/main/groovy/com/amplifyframework/tools/gradle/plugin/AmplifyTools.groovy

+16-12
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AmplifyTools implements Plugin<Project> {
1919
project.task('createAmplifyApp') {
2020
def npx = 'npx'
2121

22-
if (project.file(gradleConfigFileName).exists()) {
22+
if (project.file("${project.projectDir}/$gradleConfigFileName").exists()) {
2323
return
2424
}
2525

@@ -29,6 +29,7 @@ class AmplifyTools implements Plugin<Project> {
2929

3030
try {
3131
project.exec {
32+
workingDir ${project.projectDir}
3233
commandLine npx, 'amplify-app', '--platform', 'android'
3334
}
3435
} catch (commandLineFailure) {
@@ -37,7 +38,7 @@ class AmplifyTools implements Plugin<Project> {
3738
}
3839

3940
project.task('getConfig') {
40-
def inputConfigFile = project.file('amplify-gradle-config.json')
41+
def inputConfigFile = project.file("${project.projectDir}/amplify-gradle-config.json")
4142
if (inputConfigFile.isFile()) {
4243
def configText = inputConfigFile.text
4344
def jsonSlurper = new JsonSlurper()
@@ -53,9 +54,9 @@ class AmplifyTools implements Plugin<Project> {
5354
project.getConfig.dependsOn('createAmplifyApp')
5455

5556
project.task('datastoreSync') {
56-
def transformConfFile = project.file('amplify/backend/api/amplifyDatasource/transform.conf.json')
57-
if (project.file('amplify/backend/api').exists()) {
58-
new File('amplify/backend/api').eachFileRecurse(groovy.io.FileType.FILES) {
57+
def transformConfFile = project.file("${project.projectDir}/amplify/backend/api/amplifyDatasource/transform.conf.json")
58+
if (project.file("${project.projectDir}/amplify/backend/api").exists()) {
59+
new File("${project.projectDir}/amplify/backend/api").eachFileRecurse(groovy.io.FileType.FILES) {
5960
if (it.name.endsWith('transform.conf.json')) {
6061
transformConfFile = project.file(it)
6162
}
@@ -95,6 +96,7 @@ class AmplifyTools implements Plugin<Project> {
9596

9697
doLast {
9798
project.exec {
99+
workingDir ${project.projectDir}
98100
commandLine amplify, 'codegen', 'model'
99101
}
100102
}
@@ -144,12 +146,14 @@ class AmplifyTools implements Plugin<Project> {
144146
providersConfig = StringEscapeUtils.escapeJavaScript(providersConfig)
145147
}
146148

147-
if (project.file('./amplify/.config/local-env-info.json').exists()) {
149+
if (project.file("${project.projectDir}/amplify/.config/local-env-info.json").exists()) {
150+
workingDir ${project.projectDir}
148151
project.exec {
149152
commandLine amplify, 'push', '--yes'
150153
}
151154
} else {
152155
project.exec {
156+
workingDir ${project.projectDir}
153157
commandLine amplify, 'init',
154158
'--amplify', amplifyConfig,
155159
'--providers', providersConfig,
@@ -162,9 +166,9 @@ class AmplifyTools implements Plugin<Project> {
162166
project.amplifyPush.dependsOn('datastoreSync')
163167

164168
project.task('addModelgenToWorkspace') {
165-
if (project.file('./.idea/workspace.xml').exists()) {
169+
if (project.file("${project.projectDir}/.idea/workspace.xml").exists()) {
166170
//Open XML file
167-
def xml = new XmlParser().parse('./.idea/workspace.xml')
171+
def xml = new XmlParser().parse("${project.projectDir}/.idea/workspace.xml")
168172
def RunManagerNode = xml.component.find { it.'@name' == 'RunManager' } as Node
169173
def configModelgenCheck = null
170174
if (RunManagerNode) {
@@ -193,7 +197,7 @@ class AmplifyTools implements Plugin<Project> {
193197
RunManagerNode.append(configurationNode)
194198

195199
//Save File
196-
def writer = new FileWriter('./.idea/workspace.xml')
200+
def writer = new FileWriter("${project.projectDir}/.idea/workspace.xml")
197201

198202
//Pretty print XML
199203
groovy.xml.XmlUtil.serialize(xml, writer)
@@ -202,9 +206,9 @@ class AmplifyTools implements Plugin<Project> {
202206
}
203207

204208
project.task('addAmplifyPushToWorkspace') {
205-
if (project.file('./.idea/workspace.xml').exists()) {
209+
if (project.file("${project.projectDir}/.idea/workspace.xml").exists()) {
206210
//Open file
207-
def xml = new XmlParser().parse('./.idea/workspace.xml')
211+
def xml = new XmlParser().parse("${project.projectDir}/.idea/workspace.xml")
208212
def RunManagerNode = xml.component.find { it.'@name' == 'RunManager' } as Node
209213
def configAmplifyPushCheck = null
210214
if (RunManagerNode) {
@@ -233,7 +237,7 @@ class AmplifyTools implements Plugin<Project> {
233237
RunManagerNode.append(configurationNode)
234238

235239
//Save File
236-
def writer = new FileWriter('./.idea/workspace.xml')
240+
def writer = new FileWriter("${project.projectDir}/.idea/workspace.xml")
237241

238242
//Pretty print XML
239243
groovy.xml.XmlUtil.serialize(xml, writer)

0 commit comments

Comments
 (0)