Code Monkey home page Code Monkey logo

ant-sed's Introduction

What is Apache Ant?

Apache Ant is a build tool for Java, just like make for C/C++.

Although most Java projects use Maven and Gradle nowadays, there are still projects, like Tomcat, use Ant as their build tool.

What are Ant Tasks?

In Apache Ant, you can do many things with Tasks.

There are tasks for building, testing, and archiving, and many more.

Usually one task is designed for doing one specific job.

Why I create these tasks?

There are built-in tasks for modifying text files, but none of them are easy nor powerful to use. To workaround this, one have to call sed in a exec task as following

 <exec executable="sed">
   <arg line="-i /foo/s/bar/baz/ a.txt b.txt"/>
 </exec>

This works fine, except it looks a bit ugly; and people don't know sed cannot understand this code. What I wish to have is something looks like this

<replaceline contain="foo" change="bar" to="baz" files="a.txt,b.txt"/>

Looks much better, right?

What are these tasks?

There are mainly 3 tasks, for modifying lines,

<replaceline change="foo" to="bar" file="a.txt"/>

for adding lines,

<appendline after="foo" add="baz" file="a.txt"/>

and for deleting lines.

<deleteline contain="foo" file="a.txt"/>

Plus another task for trimming prefix and suffix.

<trimline contain="foo" prefix="#" file="a.txt"/>

Regular expressions are supported.

Read doc.md for more details about how to use these tasks.

How to add them to your Ant build script?

There is a already built my-tasks.jar exists in this repo.

Save this file and add the following lines at the begin of your ant build script

<taskdef resource="my/tasks/antlib.xml">
  <classpath>
    <pathelement location="./my-tasks.jar"/>
  </classpath>
</taskdef>

If you want to build it from source code, clone this repo and run ant. The build.xml in this repo will be executed, and a new my-tasks.jar will be created.

Note that at least JDK 8 and Ant 1.10.x are required

About testing

I have created tests to make sure that these tasks work as I expected.

There are test cases in the tests directory in this repo.

To run all tests, use

./test.sh

To run a specific test, for example, to test the ReplaceLine task

./test.sh replace

To show debug messages

./test.sh replace -d

ant-sed's People

Contributors

joekyo avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.