Write custom tasks and easy to extend Ant (2) code

zhaozj2021-02-16  48

End: All code:

(What can I not bring an accessory?)

TIMERTASK.JAVA:

Import java.util. *;

Import org.apache.tools.ant.task;

Import org.apache.tools.ant.project;

Import org.apache.tools.nt.buildexception;

/ **

* Timertask.java

*

Copyright: Copyright (c) 2003 You can modify, copy, use this program, but please keep the annotation statement here! ! !

* @Author Li Shangqiang blundblade@sina.com

* /

Public class timertask extends task {

Private List Foolist = new arraylist ();

Private string action = ""; // init, print

Private static final string time_property_internal = "timer.msecs";

Private static final string time_property_name = "Timer.Passed";

Public void execute () throws buildexception {

System.out.println ("I am a Timer");

System.out.println ("But There is So Many Foos:" Foolist);

IF (this.getowningTarget () == NULL)

Return;

Project proj = this.getowningTarget (). GetProject ();

String startime = proj.getProperty (time_property_internal);

Try {

Long currmsecs = system.currenttimemillis ();

IF (Action.equals ("Print")) {

IF (Strtime == Null)

Proj.SetProperty (TIME_PROPERTY_NAME, "Timer Not Initilized");

Else {

Long Startmsecs = long.parselong (strtime);

Long passedsecs = currmsecs - startmsecs;

INT minutes = (int) (PassedSecs * 1.0 / (1000 * 60 * 60));

INT Hours = minutes / 60;

Minutes = minutes% 60;

STRTIME = Hours "Hours" Minutes "Minutes";

Proj.SetProperty (time_property_name, startime);

}

}

Else IF (Action.equals ("init")) {

Proj.SetProperty (time_property_internal, long.tostring (currmsecs));

}

}

Catch (NumberFormatexception NFE) {

Throw new buildexception (NFE.getMessage ());

}

}

Public void addfoo (footask foo) {

FOOList.Add (foo);

}

/ **

* @Return

* /

Public String getAction () {

Return Action;

}

/ **

* @Param String

* /

Public void setAction (String string) {

Action = String;

}

}

转载请注明原文地址:https://www.9cbs.com/read-25267.html

New Post(0)