gpt4 book ai didi

javascript - Ant javascript 和套接字 numberformatException

转载 作者:行者123 更新时间:2023-11-28 10:00:37 25 4
gpt4 key购买 nike

我有这个 ant 目标来验证端口是否被占用。该脚本实际上确实获得了正确的端口 8080,尽管由于某种原因出现了新行。

<loadfile srcfile="hudson.xml" property="port">
<filterchain>
<scriptfilter language="javascript">
if (self.getToken().indexOf("httpPort") != -1)
self.setToken(parseInt(self.getToken().substring((self.getToken().indexOf("httpPort")+9),(self.getToken().indexOf("httpPort")+9) + 4)));
else
self.setToken(null);
</scriptfilter>
<ignoreblank/>
<trim/>
</filterchain>
</loadfile>

<echo message="Checking whether Hudson is running"/>
<condition property="hudson.running">
<socket server="localhost" port="${port}"/>
</condition>

这会引发 Numberformat 异常。我需要解析该端口的 hudson.xml 文件并验证它当前未被使用。有什么建议吗?

构建失败

java.lang.NumberFormatException: For input string: "8080"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.<init>(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.apache.tools.ant.IntrospectionHelper$11.set(IntrospectionHelper.java:1069)
at org.apache.tools.ant.IntrospectionHelper.setAttribute(IntrospectionHelper.java:388)
at org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:392)
at org.apache.tools.ant.RuntimeConfigurable.maybeConfigure(RuntimeConfigurable.java:349)
at org.apache.tools.ant.UnknownElement.handleChild(UnknownElement.java:568)
at org.apache.tools.ant.UnknownElement.handleChildren(UnknownElement.java:346)
at org.apache.tools.ant.UnknownElement.configure(UnknownElement.java:198)
at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:160)
at org.apache.tools.ant.Task.perform(Task.java:347)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.tools.ant.Target.performTasks(Target.java:385)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
at org.apache.tools.ant.Main.runBuild(Main.java:758)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

最佳答案

过滤器链中还需要一个过滤器 - stripinebreaks .

您的脚本过滤器仅使用该行中找到的端口号替换整行,但这不会删除末尾的新行。

关于javascript - Ant javascript 和套接字 numberformatException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9234638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com