-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BugFix: Open SAM Project on creation in Rider 231 (#3683)
* fix opening sam projects * feedback changes * empty commit * feedback changes * feedback changes 2 * added changelog
- Loading branch information
Showing
4 changed files
with
204 additions
and
80 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
.changes/next-release/bugfix-6d07456d-d796-4a15-b1cc-8bb8a5751426.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"type" : "bugfix", | ||
"description" : "Fix threading issue preventing SAM Applications from opening in Rider 2023.1" | ||
} |
97 changes: 97 additions & 0 deletions
97
...1-223/software/aws/toolkits/jetbrains/services/lambda/dotnet/DotNetSamProjectGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.jetbrains.services.lambda.dotnet | ||
|
||
import com.intellij.openapi.module.ModuleManager | ||
import com.intellij.openapi.progress.DumbProgressIndicator | ||
import com.intellij.openapi.progress.ProgressManager | ||
import com.intellij.openapi.project.rootManager | ||
import com.intellij.openapi.util.io.FileUtil | ||
import com.intellij.openapi.vfs.LocalFileSystem | ||
import com.jetbrains.rider.ideaInterop.fileTypes.msbuild.CsprojFileType | ||
import com.jetbrains.rider.projectView.SolutionManager | ||
import com.jetbrains.rider.projectView.actions.projectTemplating.backend.ReSharperTemplatesInteraction | ||
import com.jetbrains.rider.projectView.actions.projectTemplating.impl.ProjectTemplateDialogContext | ||
import com.jetbrains.rider.projectView.actions.projectTemplating.impl.ProjectTemplateTransferableModel | ||
import kotlinx.coroutines.runBlocking | ||
import software.aws.toolkits.resources.message | ||
import java.io.File | ||
|
||
class DotNetSamProjectGenerator( | ||
private val context: ProjectTemplateDialogContext, | ||
group: String, | ||
categoryName: String, | ||
model: ProjectTemplateTransferableModel | ||
) : DotNetSamProjectGeneratorRoot(context, group, categoryName, model) { | ||
|
||
override fun expand() = Runnable { | ||
val samPanel = getSamPanel() | ||
val generator = getSamGenerator() | ||
val samSettings = samPanel.getNewProjectSettings() | ||
|
||
val solutionDirectory = getSolutionDirectory() | ||
?: throw Exception(message("sam.init.error.no.solution.basepath")) | ||
|
||
val fileSystem = LocalFileSystem.getInstance() | ||
if (!solutionDirectory.exists()) { | ||
FileUtil.createDirectory(solutionDirectory) | ||
} | ||
|
||
val outDirVf = fileSystem.refreshAndFindFileByIoFile(solutionDirectory) | ||
?: throw Exception(message("sam.init.error.no.virtual.file")) | ||
|
||
val progressManager = ProgressManager.getInstance() | ||
val samProjectBuilder = generator.createModuleBuilder() | ||
progressManager.runProcessWithProgressSynchronously( | ||
{ | ||
samProjectBuilder.runSamInit( | ||
context.project, | ||
projectNameField.text, | ||
samSettings, | ||
null, | ||
outDirVf | ||
) | ||
}, | ||
message("sam.init.generating.template"), | ||
false, | ||
null | ||
) | ||
|
||
// Create solution file | ||
val projectFiles = | ||
File(solutionDirectory, "src").walk().filter { it.extension == CsprojFileType.defaultExtension } + | ||
File(solutionDirectory, "test").walk().filter { it.extension == CsprojFileType.defaultExtension } | ||
|
||
// Get the rest of generated files and copy to "SolutionItems" default folder in project structure | ||
val solutionFiles = solutionDirectory.listFiles()?.filter { it.isFile }?.toList() ?: emptyList() | ||
|
||
val solutionFile = ReSharperTemplatesInteraction.createSolution( | ||
name = getSolutionName(), | ||
directory = solutionDirectory, | ||
projectFiles = projectFiles.toList(), | ||
protocolHost = context.protocolHost, | ||
solutionFiles = solutionFiles | ||
) ?: throw Exception(message("sam.init.error.solution.create.fail")) | ||
|
||
val project = runBlocking { | ||
SolutionManager.openExistingSolution( | ||
projectToClose = null, | ||
forceOpenInNewFrame = false, | ||
solutionFile = solutionFile, | ||
forceConsiderTrusted = true | ||
) | ||
} ?: return@Runnable | ||
|
||
vcsPanel?.createInitializer()?.execute(project) | ||
|
||
val modifiableModel = ModuleManager.getInstance(project).modules.firstOrNull()?.rootManager?.modifiableModel ?: return@Runnable | ||
try { | ||
val progressIndicator = if (progressManager.hasProgressIndicator()) progressManager.progressIndicator else DumbProgressIndicator() | ||
|
||
samProjectBuilder.runPostSamInit(project, modifiableModel, progressIndicator, samSettings, outDirVf) | ||
} finally { | ||
modifiableModel.dispose() | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
...-231+/software/aws/toolkits/jetbrains/services/lambda/dotnet/DotNetSamProjectGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package software.aws.toolkits.jetbrains.services.lambda.dotnet | ||
|
||
import com.intellij.openapi.module.ModuleManager | ||
import com.intellij.openapi.progress.DumbProgressIndicator | ||
import com.intellij.openapi.progress.ProgressManager | ||
import com.intellij.openapi.project.rootManager | ||
import com.intellij.openapi.util.io.FileUtil | ||
import com.intellij.openapi.vfs.LocalFileSystem | ||
import com.jetbrains.rider.ideaInterop.fileTypes.msbuild.CsprojFileType | ||
import com.jetbrains.rider.projectView.SolutionManager | ||
import com.jetbrains.rider.projectView.actions.projectTemplating.backend.ReSharperTemplatesInteraction | ||
import com.jetbrains.rider.projectView.actions.projectTemplating.impl.ProjectTemplateDialogContext | ||
import com.jetbrains.rider.projectView.actions.projectTemplating.impl.ProjectTemplateTransferableModel | ||
import kotlinx.coroutines.launch | ||
import software.aws.toolkits.jetbrains.core.coroutines.applicationCoroutineScope | ||
import software.aws.toolkits.resources.message | ||
import java.io.File | ||
|
||
class DotNetSamProjectGenerator( | ||
private val context: ProjectTemplateDialogContext, | ||
group: String, | ||
categoryName: String, | ||
model: ProjectTemplateTransferableModel | ||
) : DotNetSamProjectGeneratorRoot(context, group, categoryName, model) { | ||
override fun expand() = Runnable { | ||
val samPanel = getSamPanel() | ||
val generator = getSamGenerator() | ||
val samSettings = samPanel.getNewProjectSettings() | ||
|
||
val solutionDirectory = getSolutionDirectory() | ||
?: throw Exception(message("sam.init.error.no.solution.basepath")) | ||
|
||
val fileSystem = LocalFileSystem.getInstance() | ||
if (!solutionDirectory.exists()) { | ||
FileUtil.createDirectory(solutionDirectory) | ||
} | ||
|
||
val outDirVf = fileSystem.refreshAndFindFileByIoFile(solutionDirectory) | ||
?: throw Exception(message("sam.init.error.no.virtual.file")) | ||
|
||
val progressManager = ProgressManager.getInstance() | ||
val samProjectBuilder = generator.createModuleBuilder() | ||
progressManager.runProcessWithProgressSynchronously( | ||
{ | ||
samProjectBuilder.runSamInit( | ||
context.project, | ||
projectNameField.text, | ||
samSettings, | ||
null, | ||
outDirVf | ||
) | ||
}, | ||
message("sam.init.generating.template"), | ||
false, | ||
null | ||
) | ||
|
||
// Create solution file | ||
val projectFiles = | ||
File(solutionDirectory, "src").walk().filter { it.extension == CsprojFileType.defaultExtension } + | ||
File(solutionDirectory, "test").walk().filter { it.extension == CsprojFileType.defaultExtension } | ||
|
||
// Get the rest of generated files and copy to "SolutionItems" default folder in project structure | ||
val solutionFiles = solutionDirectory.listFiles()?.filter { it.isFile }?.toList() ?: emptyList() | ||
|
||
val solutionFile = ReSharperTemplatesInteraction.createSolution( | ||
name = getSolutionName(), | ||
directory = solutionDirectory, | ||
projectFiles = projectFiles.toList(), | ||
protocolHost = context.protocolHost, | ||
solutionFiles = solutionFiles | ||
) ?: throw Exception(message("sam.init.error.solution.create.fail")) | ||
|
||
applicationCoroutineScope().launch { | ||
val project = | ||
SolutionManager.openExistingSolution( | ||
projectToClose = null, | ||
forceOpenInNewFrame = false, | ||
solutionFile = solutionFile, | ||
forceConsiderTrusted = true | ||
) ?: return@launch | ||
vcsPanel?.createInitializer()?.execute(project) | ||
|
||
val modifiableModel = ModuleManager.getInstance(project).modules.firstOrNull()?.rootManager?.modifiableModel ?: return@launch | ||
try { | ||
val progressIndicator = if (progressManager.hasProgressIndicator()) progressManager.progressIndicator else DumbProgressIndicator() | ||
|
||
samProjectBuilder.runPostSamInit(project, modifiableModel, progressIndicator, samSettings, outDirVf) | ||
} finally { | ||
modifiableModel.dispose() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters