Ant javascript 和套接字 numberformatException
我有这个 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)
I have this ant target to validate if a port is being occupied. The script does in fact get the correct port of 8080, although some reason there's a new line.
<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>
This throws a Numberformatexception. I need to parse this hudson.xml file for the port and validate that it's currently not being used. Any advice?
BUILD FAILED
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在过滤器链中再添加一个过滤器 -
stripinebreaks
。您的脚本过滤器仅使用该行中找到的端口号替换整行,但这不会删除末尾的新行。
You need one more filter in the filterchain -
stripinebreaks
.Your scriptfilter is replacing the whole line with just the port number found on the line, but that doesn't remove the new line at the end.