小编Pix*_*xar的帖子

将 kapt 与多平台子项目一起使用

我有以下项目结构

root-project
?   build.gradle.kts
?
????multiplatform-project
?   ?   build.gradle.kts 
?   ?
?   ????src
?       ?   kotlin
|       |   js
?   
????simple-kotlin-project
    ?   build.gradle.kts
Run Code Online (Sandbox Code Playgroud)

所以总共有 3 个项目(3 个build.gradle.kts文件)。

  1. 这是项目build.gradle.kts

    plugins {
        kotlin("jvm") version kotlinVersion apply false
        kotlin("kapt") version kotlinVersion apply false
        kotlin("multiplatform") version kotlinVersion apply false
    }
    
    subprojects {
        apply<JavaPlugin>()
    
        if (name.contains("multiplatform-project")) {
            apply(plugin = "org.jetbrains.kotlin.multiplatform")
        } else {
            apply(plugin = "kotlin")
        }
    
        apply(plugin = "kotlin-kapt")
    
        dependencies {
            implementation(kotlin("stdlib"))
            implementation(kotlin("reflect"))
            implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.0-M2")
    
            implementation("org.slf4j:slf4j-api:1.7.25")
            implementation("ch.qos.logback:logback-core:1.2.3")
            implementation("ch.qos.logback:logback-classic:1.2.3")
    
            testImplementation("junit:junit:$jUnitVersion")
        } …
    Run Code Online (Sandbox Code Playgroud)

gradle kotlin kapt gradle-kotlin-dsl kotlin-multiplatform

12
推荐指数
2
解决办法
1381
查看次数

在运行时创建测试(谷歌测试)

我有一个必须进行测试的Parser.这个Parser有很多测试输入文件.通过比较解析器的输出与相应的预生成文件来测试解析器的预期行为.

目前我在测试中处理YAML文件以获取输入文件,预期文件及其描述(如果失败,将打印此描述).

还应该在同一输入上测试Parser的参数.

所以,我需要在测试中形成以下代码:

TEST(General, GeneralTestCase)
{
   test_parameters = yaml_conf.get_parameters("General", "GeneralTestCase");
   g_parser.parse(test_parameters);

   ASSERT_TRUE(g_env.parsed_as_expected()) << g_env.get_description("General", "GeneralTestCase");
}

TEST(Special, SpecialTestCase1)
{
   test_parameters = yaml_conf.get_parameters("Special", "SpecialTestCase1");
   g_parser.parse(test_parameters);

   ASSERT_TRUE(g_env.parsed_as_expected()) << g_env.get_description("Special", "SpecialTestCase1");
}

TEST(Special, SpecialTestCase2)
{
   test_parameters = yaml_conf.get_parameters("Special", "SpecialTestCase2");
   g_parser.parse(test_parameters);

   ASSERT_TRUE(g_env.parsed_as_expected()) << g_env.get_description("Special", "SpecialTestCase2");
}
Run Code Online (Sandbox Code Playgroud)

很容易看到代码的重复.所以我觉得有一种方法可以自动化这些测试.

提前致谢.

c++ automation automated-tests googletest

11
推荐指数
1
解决办法
4504
查看次数

UI 线程中执行的异步方法中的异常导致应用程序崩溃

当我await使用抛出异常的方法时,try/catch 不会使应用程序免于崩溃。

有一种投掷方法

void CurrentStep.Process(CancellationToken cancellationToken)
{
    throw new Exception();
}
Run Code Online (Sandbox Code Playgroud)

它是通过以下方式从 UI 线程调用的:ICommand.Execute()

ProcessCurrentStepCommand = AsyncCommandFactory.Create(async cancellationToken => 
{
    try
    {
        await Task.Run(() => CurrentStep.Process(cancellationToken));
    }
    catch {}

    CurrentStep = CurrentStep.NextStepViewModel;
});
Run Code Online (Sandbox Code Playgroud)

ProcessCurrentStepCommand绑定到 UI 上的按钮。当我单击按钮时,我的应用程序崩溃了。我觉得在 UI 线程上抛出异常存在一个普遍的问题,但同时我不明白为什么 catch 块不能让我免于异常。

我现在找到了唯一适合我的方法:

await Task.Factory.StartNew(
    action: () => CurrentStep.Process(cancellationToken),
    creationOptions: TaskCreationOptions.LongRunning);
Run Code Online (Sandbox Code Playgroud)

但看起来很丑。如果我将来忘记了我想用这段代码做什么,我可能会认为我需要清理它,并因某些异常而导致整个应用程序崩溃而陷入麻烦。


当处于调试模式时,一切都表现良好。

  1. 异常源的原始中断。 在此输入图像描述

调用堆栈

UI.exe !UI.Steps.ViewModels.SvmConnectionViewModel.Process(System.Threading.CancellationToken CancellationToken)
UI.exe !UI.MainViewModel..ctor.AnonymousMethod__1() 第 18 行 mscorlib.dll !System.Threading.Tasks.Task.InnerInvoke ()第2911行 mscorlib.dll!System.Threading.Tasks.Task.Execute()第2523行 mscorlib.dll!System.Threading.Tasks.Task.ExecutionContextCallback(object obj)第2888行 mscorlib.dll!System.Threading.ExecutionContext。 RunInternal(System.Threading.ExecutionContextexecutionContext,System.Threading.ContextCallback回调,对象状态,布尔保留SyncCtx)第581行
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContextexecutionContext,System.Threading.ContextCallback回调,对象状态,boolserveSyncCtx)第531行
mscorlib.dll …

wpf exception ui-thread task-parallel-library async-await

3
推荐指数
1
解决办法
2221
查看次数

SSH.NET实时命令输出监控

script.sh远程Linux机器上有一个运行时间很长的脚本.我需要启动它并实时监控它的活动.它活动期间的脚本可以输出到stdoutstderr.我正在寻找一种捕获两种流的方法.

我使用Renci SSH.NET上传script.sh并启动它,所以很高兴看到这个库有一个解决方案.在我看来,完美的解决方案是新方法:

var realTimeScreen= ...;

var commandExecutionStatus = sshClient.RunCommandAsync(
    command: './script.sh',
    stdoutEventHandler: stdoutString => realTimeScreen.UpdateStdout(stdString)
    stderrEventHandler: stderrString => realTimeScreen.UpdateStderr(stderrString));
...
commandExecutionStatus.ContinueWith(monitoringTask =>
{
    if (monitoringTask.Completed)
    {
        realTimeScreen.Finish();
    }
});
Run Code Online (Sandbox Code Playgroud)

wpf ssh monitoring async-await ssh.net

3
推荐指数
2
解决办法
2万
查看次数

使用Jenkins进行下游参数的Groovy脚本

在Jenkins中,我尝试使用Groovy脚本将参数传递到构建管道的下游作业.在我的第一份工作中,我添加了一个Build步骤"Execute Groovy Script"并将内容添加到Groovy命令中:

import hudson.model.*
import hudson.util.*
def thr = Thread.currentThread()
def build = thr?.executable
printf "Setting UPSTREAM_ID as "+ build.getEnvVars()['BUILD_ID']  +"\n" ; 
build.addAction(new ParametersAction(new StringParameterValue('UPSTREAM_ID', build.getEnvVars()['BUILD_ID'])))
Run Code Online (Sandbox Code Playgroud)

我得到输出:

    [workspace] $ C:\Progra~1\Groovy\Groovy-1.5.8\bin\groovy.exe d:\JenkinsAT\jobs\Test_Job\workspace\hudson8779135058472653024.groovy
    org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, D:\JenkinsAT\jobs\Test_Job\workspace\hudson8779135058472653024.groovy: 6: unable to resolve class ParametersAction 
     @ line 6, column 17.
       build.addAction(new ParametersAction(new StringParameterValue('SVN_UPSTREAM', build.getEnvVars()['BUILD_ID'])))
                       ^
    D:\JenkinsAT\jobs\Test_Job\workspace\hudson8779135058472653024.groovy: 6: unable to resolve class StringParameterValue 
     @ line 6, column 38.
       build.addAction(new ParametersAction(new StringParameterValue('SVN_UPSTREAM', build.getEnvVars()['BUILD_ID'])))
                                            ^

2 errors
Run Code Online (Sandbox Code Playgroud)

我在我的机器上安装了Groovy 1.5.8,我的Jenkins版本是1.519.我在这做什么错.

groovy jenkins jenkins-plugins

2
推荐指数
1
解决办法
4884
查看次数

停止挂同步方法

XenAPI 中有一个方法HTTP_actions.put_import() ,它是同步的,并且支持通过其 delegate 取消

我有以下方法:

private void UploadImage(.., Func<bool> isTaskCancelled)
{
    try
    {
        HTTP_actions.put_import(
            cancellingDelegate: () => isTaskCancelled(),
            ...);
    }
    catch (HTTP.CancelledException exception)
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

在某些情况下,该方法HTTP_actions.put_import会挂起并且不会对isTaskCancelled(). 在这种情况下,整个应用程序也会挂起。

我可以在单独的线程中运行此方法,并在收到取消信号后强制终止它,但此方法并不总是挂起,有时我想优雅地取消此方法。只有当这个方法真的悬了的时候,我才想亲手杀死它。

处理这种情况的最佳方法是什么?

c# multithreading asynchronous task cancellation

1
推荐指数
1
解决办法
4234
查看次数