我有这个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>
这会引发Numberformatexception。我需要为端口解析这个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
。
您的脚本过滤器仅用行上的端口号替换整行,但这不会删除末尾的新行。