ANT

本文介绍了Ant构建工具的五级日志级别,包括错误、警告、信息、详细和调试,并解释了如何通过命令行参数调整日志输出。此外,还讨论了Ant中不同属性的作用域及其覆盖规则。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ant的log 级别:
-----------------------
ant一共有五种log 级别:
 
Project.java:
public static final int MSG_ERR = 0;         -----------------error

public static final int MSG_WARN = 1;        -----------------warning

public static final int MSG_INFO = 2;        -----------------info

public static final int MSG_VERBOSE = 3;     -----------------verbose

public static final int MSG_DEBUG = 4;       -----------------debug


<echo level="debug">Imminent failure in the antimatter containment facility.</echo>
表示这段消息被设置在:debug 级别。

ant -help:
 -quiet, -q             be extra quiet
 -verbose, -v           be extra verbose
 -debug, -d             print debugging information

从下 面的类org.apache.tools.ant.Main可以看到:
if (arg.equals("-quiet") || arg.equals("-q")) {
    msgOutputLevel = Project.MSG_WARN;
} else if (arg.equals("-verbose") || arg.equals("-v")) {
    printVersion();
    msgOutputLevel = Project.MSG_VERBOSE;
} else if (arg.equals("-debug") || arg.equals("-d")) {
    printVersion();
    msgOutputLevel = Project.MSG_DEBUG;
   
-q 设置为整个ant的日志输出级别为 warning, 那么在ant 标签中设置的log level 级别大于它(也就是info,verbose,debug)的msg不输出;
    也就是(error,warning)级别的msg输出。
缺省级别为:info 即整个ant的日志输出级别为 info, 那么在ant 标签中设置的log level 级别大于它(也就是verbose,debug)的msg不输出;
            也就是(error,warning,info)级别的msg输出。
-v 设置为整个ant的日志输出级别为 verbose, 那么在ant 标签中设置的log level 级别大于它(debug)的msg不输出;
            也就是(error,warning,info,verbose)级别的msg输出。
-d 设置为整个ant的日志输出级别为 debug, 那么在ant 标签中设置的log level 级别大于它(无)的msg不输出;
            也就是(error,warning,info,verbose,debug)级别的msg输出。
   
   
-----------------------
typedef 与taskdef的区别:
-----------------------
typedef:
    1.任何type必须 extends DataType ;注意 (DataType extends ProjectComponent extends Object )
    2.属于Project级别,可以在target外面存在.为taskdef服务,不作为一个task来执行,可以通过id属性来reference
taskdef:
    1.任何task 必须 extends Task ; 注意 (Task extends ProjectComponent extends Object)
    2.只能在target中完成一个具体的工作

Typedef should be used to add your own types to the system. Data
types are things likepaths or filesets that can be defined at
the project level and referenced via their ID attribute.
Custom data types usually need custom tasks to put them to good use.
   
   
   
----------------------- 
<sql>的使用方法:
-----------------------
delimiterType.equals(DelimiterType.NORMAL) && sql.toString().endsWith(delimiter))
||(delimiterType.equals(DelimiterType.ROW)&& line.equals(delimiter))

执行sql的时机有两种情况:

1.当属性为 delimitertype=normal and delimiter =";"的时候, 表示
  sql语句以;结尾的时候, 执行";"之前的sql语句.
2.当属性为delimitertype=row and delimiter ="go"的时候, 表示
  sql语句以"go"作为一行的时候, 执行go语句以前的sql语句. 


Ant中类的api说明:
----------------------------------------
org.apache.tools.ant.Project:
----------------------------------------
在 ant标签中注意
user properties : 从来不被override ------指command line 中得属性  -Dparam1=good -D param2=luck

操作userProperties:保存来在 command line中的属性
inheritedProperties: 在调用<ant file/>使用
properties:  保存ant <property>定义的属性和user properties

但是可以通过java的api做出一些如下 ant标签不能做到的改动,Project类中有如下api:
setUserProperty(name,value):如果name存在的话, 总是override user properties中的内容。
           ----操作userProperties
setInheritedProperty(name,value): 如果name存在的话,总是override InheritedProperty中的内容。
           不可以override user properties.
           ----操作 inheritedProperties
setProperty(name,value): 除了user properties 不被override以外,其他所有properties将被override
           ----操作properties
setNewProperty(name,value):除了user properties 不被override以外,并且name这个key不存在才建立这个pair,
                           如果name已经存在,那么原先name对应的value不受这个value影响。
           ----操作properties
以 上方法最终invoke PropertyHelper中的方法。
/**
 * Add all system properties which aren't already defined as
 * user properties to the project properties.
 */
public void setSystemProperties() {
    Properties systemP = System.getProperties();
    Enumeration e = systemP.propertyNames();
    while (e.hasMoreElements()) {
        String propertyName = (String) e.nextElement();
        String value = systemP.getProperty(propertyName);
        this.setPropertyInternal(propertyName, value);
    }
}
------------------------------------------
org.apache.tools.ant.PropertyHelper:
------------------------------------------
properties 的所有级别:
1.userProperties,   highest level  ----command line中的参数
2.inheritedProperties,  middle level
3.properties,   low level


/** Project properties map (usually String to String). */
private Hashtable properties = new Hashtable();      
说明:整个project对应的properties,通过 <property name=...>等方式进来的。

/**
 * Map of "user" properties (as created in the Ant task, for example).
 * Note that these key/value pairs are also always put into the
 * project properties, so only the project properties need to be queried.
 * Mapping is String to String.
 */
private Hashtable userProperties = new Hashtable();                   
说明: user (CLI) properties take precedence : java -Duser=user -Dpassword=1234.
       通过命令行方式进入进来的properties.

/**
 * Map of inherited "user" properties - that are those "user"
 * properties that have been created by tasks and not been set
 * from the command line or a GUI tool.
 * Mapping is String to String.
 */
private Hashtable inheritedProperties = new Hashtable();
说明:可以继承下来的properties


<call ...>--- Call class
<antcall ...>--- CallTarget class 实质是CallTarget 调用Call.

---------------------------------------------------------------------------------
由 于使用ant,antcall标签,必然会new Project,所以Project对应的properties会发生改变,
1.如果 inheritAll=true,userProperties(系统启动的时候已经将systemProperties对入到
userProperties 中去了)和自己之前定义的properties都被copy到新的project里面来了。
2.如果 inheritAll=false,userProperties的属性会被copy到新的project中去,但是自己之前
定义的 properteis都不会被copy到新的project里面来了。从而有了一个干净的环境。
---------------------------------------------------------------------------------

<ant> 用法与<antcall>用法相同,注意下面properties被override的情况。
----------------------
for example:
----------------------
ant -f build.xml -Dparam1=good

<antcall target="echo">
    <param name="param1" value="param1" />
    <param name="param2" value="param2" />
    <param name="param3" value="param3" />
</antcall>

<target name="echo" description="echo" if="permission.call">
        <property name="param1" value="${param0}" />
        <property name="param2" value="${param0}" />
        <property name="param3" value="${param0}" />

        <echo>param1=${param1}</echo>
        <echo>param2=${param2}</echo>
        <echo>param3=${param3}</echo>
</target>

-Dparam1=good 为command line 属性(北叫做user properties)。它的属性是完全不可以别override.
即 使<antcall>中设置了<param name="param1" value="param1" /> param1的值仍然为good.

如果在<target name="echo">中即使定义了<property name="param2" value="fdfdfdfdfd" />
由于<param name="param2" value="param2" />, 那么param2的值将会被override,变成"param2"

下面是详细的说明:
By default, all of the properties of the current project will be available in the new project.
Alternatively, you can set the inheritAll attribute to false and only "user" properties
(i.e., those passed on the command-line) will be passed to the new project. In either case,
the set of properties passed to the new project will override the properties that are set in the new project
(See also the property task).
You can also set properties in the new project from the old project by using nested param tags.
These properties are always passed to the new project and any project created in that project
regardless of the setting of inheritAll. This allows you to parameterize your subprojects. Properties
defined on the command line can not be overridden by nested <param> elements.

05-31
### 关于Ant Design和Apache Ant的选择 用户提到的两个技术方向分别是 **Ant Design** 和 **Apache Ant**。以下是两者的详细介绍及适用场景: #### 1. Ant Design Ant Design 是一个专注于后端开发体验的企业级 UI 设计语言和 React 实现[^3]。它提供了丰富的组件库,适用于构建现代化的 Web 应用程序。以下是一些关键特性: - **组件丰富**:包括警告提示(Alert)、对话框(Modal)、全局提示(Message)、通知提醒框(Notification)以及加载中(Spin)等组件[^3]。 - **易于集成**:支持与 React 框架无缝集成,开发者可以通过简单的配置快速搭建项目[^1]。 - **离线文档**:通过下载 Ant Design 的离线版本文档,开发者可以在无网络环境下查阅完整的 API 文档和示例代码[^4]。 ```python # 示例:安装 Ant Design 并使用其组件 npm install antd --save import { Alert } from 'antd'; <Alert message="Success Tip" type="success" /> ``` #### 2. Apache Ant Apache Ant 是一个基于 Java 的构建工具,类似于 Make 工具,但不需要依赖 Unix shell 命令[^4]。它主要用于自动化构建、测试和部署任务。以下是其主要特点: - **跨平台**:由于基于 Java,因此可以在任何支持 Java 的平台上运行。 - **灵活性**:通过 XML 文件定义构建任务,支持复杂的构建逻辑。 - **插件扩展**:可以通过自定义任务或使用第三方插件扩展功能。 ```xml <!-- 示例:Apache Ant 构建文件 --> <project name="HelloWorld" default="build" basedir="."> <target name="build"> <echo message="Hello, World!" /> </target> </project> ``` ### 技术选择建议 如果用户的关注点是前端开发,尤其是需要快速构建企业级 Web 应用程序,则 Ant Design 是更合适的选择[^1]。如果用户的需求集中在后端项目的构建、自动化测试或部署,则 Apache Ant 更为适用[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值