m.kelas-karyawan-sebi.prestasi.web.id Layanan Informasi 17 Jam
Telp/Fax : 021-8762002, 8762003, 8762004, 87912360
HP/SMS : 081 1110 4824 27, 0812 9526 2009, 08523 1234 000
WhatsApp : 0817 0816 486, 0812 9526 2009
email : _Hubungi Kami__ silahkan klik
Chatting dengan Staf :
ggkarir.com
ggiklan.com
Pilih Bahasa :   ID   EN   Permintaan Katalog / Brosur (GRATIS via POS)   Ensiklopedia Lowongan Karir Iklan

   
Cari di Apache Ant 
    Apache Ant

    Sebelumnya  (Antlib) (Assertions)  Berikutnya    
Concepts and Types

Custom Components

Custom Components

Overview

Custom components are conditions, selectors, filters and other objects that are defined outside Apache Ant core.

In Ant 1.6 custom conditions, selectors and filters has been overhauled.

It is now possible to define custom conditions, selectors and filters that behave like Ant Core components. This is achieved by allowing datatypes defined in build scripts to be used as custom components if the class of the datatype is compatible, or has been adapted by an adapter class.

The old methods of defining custom components are still supported.

Definition and use

A custom component is a normal Java class that implements a particular interface or extends a particular class, or has been adapted to the interface or class.

It is exactly like writing a custom task. One defines attributes and nested elements by writing setter methods and add methods.

After the class has been written, it is added to the ant system by using <typedef>.

Custom Conditions

Custom conditions are datatypes that implement org.apache.tools.ant.taskdefs.condition.Condition. For example a custom condition that returns true if a string is all upper case could be written as:

package com.mydomain;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.taskdefs.condition.Condition;public class AllUpperCaseCondition implements Condition {    private String value;    // The setter for the "value" attribute    public void setValue(String value) {        this.value = value;    }    // This method evaluates the condition    public boolean eval() {        if (value == null) {            throw new BuildException("value attribute is not set");        }        return value.toUpperCase().equals(value);   }}      

Adding the condition to the system is achieved as follows:

<typedef    name="alluppercase"    classname="com.mydomain.AllUpperCaseCondition"    classpath="${mydomain.classes}"/>      

This condition can now be used wherever a Core Ant condition is used.

<condition property="allupper">   <alluppercase value="THIS IS ALL UPPER CASE"/></condition>      

Custom Selectors

Custom selectors are datatypes that implement org.apache.tools.ant.types.selectors.FileSelector.

There is only one method required. public boolean isSelected(File basedir, String filename, File file). It returns true or false depending on whether the given file should be selected or not.

An example of a custom selection that selects filenames ending in ".java" would be:

package com.mydomain;import java.io.File;import org.apache.tools.ant.types.selectors.FileSelector;public class JavaSelector implements FileSelector {    public boolean isSelected(File b, String filename, File f) {       return filename.toLowerCase().endsWith(".java");    }}      

Adding the selector to the system is achieved as follows:

<typedef    name="javaselector"    classname="com.mydomain.JavaSelector"    classpath="${mydomain.classes}"/>      

This selector can now be used wherever a Core Ant selector is used, for example:

<copy todir="to">   <fileset dir="src">      <javaselector/>   </fileset></copy>      

One may use org.apache.tools.ant.types.selectors.BaseSelector, a convenience class that provides reasonable default behaviour. It has some predefined behaviours you can take advantage of. Any time you encounter a problem when setting attributes or adding tags, you can call setError(String errmsg) and the class will know that there is a problem. Then, at the top of your isSelected() method call validate() and a BuildException will be thrown with the contents of your error message. The validate() method also gives you a last chance to check your settings for consistency because it calls verifySettings(). Override this method and call setError() within it if you detect any problems in how your selector is set up.

To write custom selector containers one should extend org.apache.tools.ant.types.selectors.BaseSelectorContainer. Implement the public boolean isSelected(File baseDir, String filename, File file) method to do the right thing. Chances are you'll want to iterate over the selectors under you, so use selectorElements() to get an iterator that will do that.

For example to create a selector container that will select files if a certain number of contained selectors select, one could write a selector as follows:

public class MatchNumberSelectors extends BaseSelectorContainer {    private int number = -1;    public void setNumber(int number) {        this.number = number;    }    public void verifySettings() {        if (number < 0) {           throw new BuildException("Number attribute should be set");        }    }    public boolean isSelected(File baseDir, String filename, File file) {        validate();        int numberSelected = 0;        for (Enumeration e = selectorElements(); e.hasNextElement();) {            FileSelector s = (FileSelector) e.nextElement();            if (s.isSelected(baseDir, filename, file)) {                numberSelected++;            }        }        return numberSelected == number;    }}      

To define and use this selector one could do:

<typedef name="numberselected"         classname="com.mydomain.MatchNumberSelectors"/>...<fileset dir="${src.path}">   <numberselected number="2">      <contains text="script" casesensitive="no"/>      <size value="4" units="Ki" when="more"/>      <javaselector/>   </numberselected></fileset>      

The custom selector

The custom selector was the pre ant 1.6 way of defining custom selectors. This method is still supported for backward compatibility.

You can write your own selectors and use them within the selector containers by specifying them within the <custom> tag.

To create a new Custom Selector, you have to create a class that implements org.apache.tools.ant.types.selectors.ExtendFileSelector. The easiest way to do that is through the convenience base class org.apache.tools.ant.types.selectors.BaseExtendSelector, which provides all of the methods for supporting <param> tags. First, override the isSelected() method, and optionally the verifySettings() method. If your custom selector requires parameters to be set, you can also override the setParameters() method and interpret the parameters that are passed in any way you like. Several of the core selectors demonstrate how to do that because they can also be used as custom selectors.

Once that is written, you include it in your build file by using the <custom> tag.

Attribute Description Required
classname The name of your class that implements org.apache.tools.ant.types.selectors.FileSelector. Yes
classpath The classpath to use in order to load the custom selector class. If neither this classpath nor the classpathref are specified, the class will be loaded from the classpath that Ant uses. No
classpathref A reference to a classpath previously defined. If neither this reference nor the classpath above are specified, the class will be loaded from the classpath that Ant uses. No

Here is how you use <custom> to use your class as a selector:

<fileset dir="${mydir}" includes="**/*">    <custom classname="com.mydomain.MySelector">        <param name="myattribute" value="myvalue"/>    </custom></fileset>      

The core selectors that can also be used as custom selectors are

  • Contains Selector with classname org.apache.tools.ant.types.selectors.ContainsSelector
  • Date Selector with classname org.apache.tools.ant.types.selectors.DateSelector
  • Depth Selector with classname org.apache.tools.ant.types.selectors.DepthSelector
  • Filename Selector with classname org.apache.tools.ant.types.selectors.FilenameSelector
  • Size Selector with classname org.apache.tools.ant.types.selectors.SizeSelector

Here is the example from the Depth Selector section rewritten to use the selector through <custom>.

<fileset dir="${doc.path}" includes="**/*">    <custom classname="org.apache.tools.ant.types.selectors.DepthSelector">        <param name="max" value="1"/>    </custom></fileset>      

Selects all files in the base directory and one directory below that.

Custom Filter Readers

Custom filter readers selectors are datatypes that implement org.apache.tools.ant.types.filters.ChainableReader.

There is only one method required. Reader chain(Reader reader). This returns a reader that filters input from the specified reader.

For example a filterreader that removes every second character could be:

public class RemoveOddCharacters implements ChainableReader {   public Reader chain(Reader reader) {      return new BaseFilterReader(reader) {          int count = 0;          public int read() throws IOException {              while (true) {                int c = in.read();                if (c == -1) {                    return c;                }                count++;                if ((count % 2) == 1) {                    return c;                }              }          }      }   }}      

For line oriented filters it may be easier to extend ChainableFilterReader an inner class of org.apache.tools.ant.filters.TokenFilter.

For example a filter that appends the line number could be

public class AddLineNumber extends ChainableReaderFilter {   private void lineNumber = 0;   public String filter(String string) {      lineNumber++;      return "" + lineNumber + "" + string;   }}      

    Sebelumnya  (Antlib) (Assertions)  Berikutnya    


TeknologiBiografiPerlMikroprosesorKhonghucuSemua Debat Forum



Tags: Custom Components, Apache Ant, 2242, Concepts and Types Custom Components Custom Components Overview Custom components are conditions selectors filters and other objects that are defined outside Apache Ant core, In Ant 1.6 custom conditions selectors and filters has been overhauled, It is now possible to define custom conditions selectors and filters that behave like Ant Core components, This is achieved by allowing datatypes define, Custom Components, Bahasa Indonesia, Contoh Instruksi, Tutorial, Referensi, Buku, Petunjuk, Ilmu politik, Fn, Teknik energi listrik s1, Fo, S1 system nalysis, Forumsingo, Sistem informasi s1, Dua, Komputerisasi akutansi dan bisnis m.kelas karyawan sebi, prestasi.web.id
 Macam2 Perdebatan    Program S2 (Pascasarjana, Magister)    Download Brosur / Katalog    Lowongan Karir
Penyelenggara
Kelas Reguler (Hybrid)
TUJUAN
SELAMAT DATANG
PENERIMAAN MHS BARU
DANA PENDIDIKAN
WAKTU KULIAH & DOSEN
Kumpulan Web Kuliah Paralel
Kumpulan Web Gabungan PTS
Kumpulan Web Program Reguler
Kumpulan Web Program Magister (Pascasarjana, S2)
Kumpulan Web Kelas Karyawan

 Latihan Soal Try Out    Jadwal Sholat    Alquran Online    Buku Tutorial    Soal-Jawab Psikotes    Kumpulan Referensi Bebas    Berbagai Informasi    Pendaftaran Online    Pengajuan Keringanan Biaya Kuliah    Kuliah Hybrid di 112 PTS Terbaik    Program Kelas Bebas Biaya    Program Kelas Lanjutan    Program Perkuliahan Reguler    Kuliah Paralel
Permintaan Kirim Brosur
(GRATIS via POS)
Nama Lengkap Penerima

Alamat Penerima Katalog

Kota + Provinsi

Kode Pos

Email (tidak wajib)

✶ harus diisi lengkap & jelas
Atau kirimkan nama dan
alamat lengkap via SMS ke HP:
0811 1990 9026


Brosur Gratis
Brosur Kelas Karyawan
Gabungan Seluruh Wilayah Indonesia

pdf (11,2 MB)ZIP (8,8 MB)
Image/JPG (36,2 MB)
Brosur Kelas Karyawan
JABODETABEK

pdf (5,5 MB)ZIP (4,4 MB)
Image/JPG (13,2 MB)
Brosur Kelas Karyawan
DIY,JATENG,JATIM & BALI

pdf (4,4 MB)ZIP (3,5 MB)
Image/JPG (14,5 MB)
Brosur Kelas Karyawan
JAWA BARAT

pdf (2,8 MB)ZIP (2,2 MB)
Image/JPG (7,1 MB)
Brosur Kelas Karyawan
SULAWESI

pdf (1,9 MB)ZIP (1,5 MB)
Image/JPG (5,6 MB)
Brosur Kelas Karyawan
SUMATERA & BATAM

pdf (2,2 MB)ZIP (1,7 MB)
Image/JPG (6,5 MB)
Brosur Khusus Reguler
pdf (4,1 Mb)ZIP (8,4 Mb)
Kalender NKRI 2023
Image/JPG (2,1 Mb)pdf (400 kb)

CARA Meningkatkan
Pendapatan, Sumber Daya PTS dan Kualitas Pendidikannya
http://kpt.co.id
Terobosan Baru

PT. Gilland Ganesha
Membutuhkan Segera

  • Design Grafis
  • Tenaga Ahli Pemrograman

Seluruh Ringkasan di :
Kesempatan karier

155 Ras Kucing di Dunia

Bola bulu kucing, breed quality kucing, cara memberi makan kucing, dsb.

Facebook Kuliah Karyawan

Web Artikel
Data Persepsi Korupsi
Kuliah Teknik Komputer
Partai2 di Kamerun
Senat di Dunia

p2k.utmj.ac.id  |  s2-stmikjakarta.web.id  |  satyagama.web.id  |  s2-satyagama.web.id  |  swins.web.id  |  p2k.stikma.ac.id  |  unnur.web.id
ilmu-politik-ecp.fn.web.id  ⊞   teknik-energi-listrik-s1-ecp.fo.web.id  ⊞   s1-system-nalysis-ecp.forumsingo.com  ⊞   sistem-informasi-s1-ecp.dua.web.id  ⊞   komputerisasi-akutansi-dan-bisnis-ecp.doktor.web.id  ⊞   database-administrator-ecp.discussion.web.id  ⊞   k3-ecp.department.web.id  ⊞   ilmu-sosial-politik-ecp.democracy.web.id