- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我从 org.apache.tools.ant.DefaultLogger
的 DefaultLogger
创建了一个子类:
public class ExtendedLogger extends DefaultLogger {
// My stuff
}
我拿了资料here .
所以我从 DefaultLogger
重载了一些方法:
@Override
public void targetStarted(BuildEvent event){
System.out.println("Logger : "+"[TARGET STARTED]\n");
}
@Override
public void targetFinished(BuildEvent event){
System.out.println("Logger : "+"[TARGET FINISHED]\n");
}
效果很好(我可以看到输出)。
这些方法也有效:
public void taskStarted(BuildEvent event);
public void taskFinished(BuildEvent event);
但我有麻烦:
@Override
public void buildFinished(BuildEvent event) {
System.out.println("Logger : "+"[BUILD FINISHED]\n");
}
@Override
public void buildStarted(BuildEvent event) {
System.out.println("Logger : "+"[BUILD STARTED]\n");
}
不可能进入这些方法!
我哪里错了?
谢谢。
编辑 12/01/2016 :
我只是尝试了一个简单的 testBuild.xml,就像@Vaspar 说的那样:
<?xml version="1.0" encoding="UTF-8"?>
<project name="MyProject" default="Init" basedir=".">
<target name="Init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<echo message="INIT-ING"/>
</target>
<!-- targets used in my project -->
<target name="Clean" description="Clean output directory.">
<echo>Clean</echo>
</target>
<target name="CleanAutogenerated" description="Clean auto-generated folder.">
<echo>CleanAutogenerated</echo>
</target>
<target name="AutoGenerateTopics" description="Manual specific targets.">
<echo>AutoGenerateTopics</echo>
</target>
<target name="BuildDocument" description="Build full documentation">
<echo>BuildDocument</echo>
</target>
</project>
输出是:
Logger : [TARGET STARTED] org.apache.tools.ant.BuildEvent[source=Clean]
Logger : [TASK STARTED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnknownElement@12f33e1]
[echo] Clean
Logger : [TASK FINISHED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnknownElement@12f33e1]
Logger : [TARGET FINISHED] org.apache.tools.ant.BuildEvent[source=Clean]
CleanDocumentTask DONE
Logger : [TARGET STARTED] org.apache.tools.ant.BuildEvent[source=CleanAutogenerated]
Logger : [TASK STARTED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnknownElement@1e2862f]
[echo] CleanAutogenerated
Logger : [TASK FINISHED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnknownElement@1e2862f]
Logger : [TARGET FINISHED] org.apache.tools.ant.BuildEvent[source=CleanAutogenerated]
CleanAutoGenerateTask DONE
Logger : [TARGET STARTED] org.apache.tools.ant.BuildEvent[source=AutoGenerateTopics]
Logger : [TASK STARTED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnknownElement@19bf1ed]
[echo] AutoGenerateTopics
Logger : [TASK FINISHED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnknownElement@19bf1ed]
Logger : [TARGET FINISHED] org.apache.tools.ant.BuildEvent[source=AutoGenerateTopics]
AutoGenerateTask DONE
Logger : [TARGET STARTED] org.apache.tools.ant.BuildEvent[source=BuildDocument]
Logger : [TASK STARTED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnknownElement@10b85cb]
[echo] BuildDocument
Logger : [TASK FINISHED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnknownElement@10b85cb]
Logger : [TARGET FINISHED] org.apache.tools.ant.BuildEvent[source=BuildDocument]
DocumentTask DONE
请注意,CleanDocumentTask DONE
、DocumentTask DONE
等都是我的项目(不是 ant)的纯 Java 输出。
如您所见,targetStarted
或 targetFinished
仍然没有输出:/
编辑 12/01/2016 (2) :
我的 ExtendedLogger.java 的内容:
import javax.swing.SwingUtilities;
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.DefaultLogger;
/*
* This class has been wrote to deals with ant build outputs.
*
* However, buildFinished and buildStarted seems not to work.
* See details at :
*
* http://api.dpml.net/ant/1.7.0/org/apache/tools/ant/DefaultLogger.html
*
*/
public class ExtendedLogger extends DefaultLogger {
/*
* public class ColorPane extends JTextPane
*
* (personal class : JTextPane + Ansi coloring)
*/
ColorPane colorPane = null;
public ExtendedLogger(ColorPane c){
super();
if (c != null){
colorPane = c;
} else {
System.out.println("ColorPane given to constructor is null. Exiting program.");
System.exit(0);
}
}
@Override
public void buildFinished(BuildEvent event) {
ColorPane.appendInEDT("[BUILD FINISHED]\n", ColorPane.B_Yellow, colorPane);
System.out.println("Logger : "+"[BUILD FINISHED]\n");
}
@Override
public void buildStarted(BuildEvent event) {
ColorPane.appendInEDT("[BUILD STARTED]\n", ColorPane.B_Yellow, colorPane);
System.out.println("Logger : "+"[BUILD STARTED]\n");
}
@Override
public void log(String message){
appendInEDT(message);
}
private void appendInEDT(String s){
/*
* Detach the graphical modifications in the Event Dispatch Thread (EDT)
*/
final String newLine = s;
Thread t = new Thread(new Runnable(){
public void run(){
colorPane.append(ColorPane.B_White, newLine+"\n");
}
});
if (SwingUtilities.isEventDispatchThread()) {
t.start();
} else {
SwingUtilities.invokeLater(t);
}
}
}
最佳答案
令人惊讶。我使用了您的代码示例,并且还能够获取 buildStarted/buildFinished 日志。
import org.apache.tools.ant.BuildEvent;
import org.apache.tools.ant.DefaultLogger;
public class CustomLogger extends DefaultLogger{
@Override
public void targetStarted(BuildEvent event){
System.out.println("Logger : "+"[TARGET STARTED] " + event);
}
@Override
public void targetFinished(BuildEvent event){
System.out.println("Logger : "+"[TARGET FINISHED] " + event);
}
@Override
public void taskStarted(BuildEvent event) {
System.out.println("Logger : "+"[TASK FINISHED] " + event);
}
@Override
public void taskFinished(BuildEvent event) {
System.out.println("Logger : "+"[TASK FINISHED] " + event);
}
@Override
public void buildFinished(BuildEvent event) {
System.out.println("Logger : "+"[BUILD FINISHED] " + event);
}
@Override
public void buildStarted(BuildEvent event) {
System.out.println("Logger : "+"[BUILD STARTED] " + event);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project name="MyProject" default="init" basedir=".">
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<echo message="INIT-ING"/>
</target>
</project>
下面是输出。
/DummyTest> ant -logger CustomLogger
Buildfile: /DummyTest/build.xml
Logger : [BUILD STARTED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.Project@1318bd3c]
Logger : [TARGET STARTED] org.apache.tools.ant.BuildEvent[source=init]
[tstamp] Logger : [TASK FINISHED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnknownElement@31623389]
Logger : [TASK FINISHED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnknownElement@31623389]
[echo] Logger : [TASK FINISHED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnknownElement@636c7a8f]
[echo] INIT-ING
Logger : [TASK FINISHED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.UnknownElement@636c7a8f]
Logger : [TARGET FINISHED] org.apache.tools.ant.BuildEvent[source=init]
Logger : [BUILD FINISHED] org.apache.tools.ant.BuildEvent[source=org.apache.tools.ant.Project@1318bd3c]
关于java - buildFinished 和 buildStarted 将不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34723466/
在 $HOME/.gradle/init.gradle我有: gradle.buildFinished { buildResult -> commandLine 'bash', "blah b
我从 org.apache.tools.ant.DefaultLogger 的 DefaultLogger 创建了一个子类: public class ExtendedLogger extends D
我是一名优秀的程序员,十分优秀!