Skip to content

Instantly share code, notes, and snippets.

@tanaka9230
Last active September 5, 2017 08:06
Show Gist options
  • Save tanaka9230/5edac6369aba0257b79b to your computer and use it in GitHub Desktop.
Save tanaka9230/5edac6369aba0257b79b to your computer and use it in GitHub Desktop.
Apache Ant build file examples
<?xml version="1.0" encoding="UTF-8"?>
<!-- Apache Ant build.xml -->
<project name="reform file names" default="main">
<target name="init">
<property name="target" value="cooked"/>
</target>
<target name="main" depends="init">
<mkdir dir="${target}"/>
<copy todir="${target}">
<fileset dir=".">
<include name="*.jpg"/>
</fileset>
<scriptmapper language="javascript">
<![CDATA[
var Pattern = java.util.regex.Pattern;
var Integer = java.lang.Integer;
var String = java.lang.String;
var m = Pattern.compile("(.*) \\- (.*)\\.jpg").matcher(source);
m.find();
var cooked = String.format("%1$s-%2$03d.jpg", m.group(1), Integer.valueOf(m.group(2)));
self.addMappedName(cooked);
]]>
</scriptmapper>
</copy>
<touch pattern="yyyy-MM-dd HH:mm:ss.SSS" datetime="2007-11-23 00:00:00.000">
<fileset dir="${target}">
<include name="*.jpg"/>
</fileset>
</touch>
</target>
<target name="clean" depends="init">
<delete dir="${target}"/>
</target>
</project>
@echo off
setlocal
echo ** exec-example **
set SRC_DIR=%1
set TGT_DIR=%2
echo SRC_DIR=%SRC_DIR%
echo TGT_DIR=%TGT_DIR%
for %%F in (%SRC_DIR%\*.csv) do (
echo - %%F
type %%F
copy %%F %TGT_DIR%
)
:: to emulate an abend
rem exit /B 2
#!/bin/bash
echo "** exec-example **"
SRC_DIR=$1
TGT_DIR=$2
echo "SRC_DIR=${SRC_DIR}"
echo "TGT_DIR=${TGT_DIR}"
for FILE in ${SRC_DIR}/*.csv
do
echo "- ${FILE}"
cat ${FILE}
cp ${FILE} ${TGT_DIR}
done
# to emulate an abend
#exit 2
<?xml version="1.0" encoding="UTF-8"?>
<!-- Apache Ant build.xml -->
<project name="exec" default="exec">
<target name="init">
<property name="aimed-script-name" value="exec-example"/>
<property name="work-dir" value="."/>
</target>
<target name="exec" depends="init">
<exec osfamily="dos" dir="${work-dir}" executable="cmd.exe" resultproperty="exit-status">
<arg value="/c"/>
<arg value="${aimed-script-name}.bat"/>
<arg path="${work-dir}/source"/>
<arg path="${work-dir}/target"/>
</exec>
<exec osfamily="unix" dir="${work-dir}" executable="sh" resultproperty="exit-status">
<arg value="./${aimed-script-name}.sh"/>
<arg path="${work-dir}/source"/>
<arg path="${work-dir}/target"/>
</exec>
<fail status="${exit-status}">
<condition>
<not><equals arg1="${exit-status}" arg2="0"/></not>
</condition>
</fail>
</target>
</project>
@echo off
setlocal
set BAT_HOME=%~dp0
echo [cd %BAT_HOME%]
cd %BAT_HOME%
echo [call ant -f fixcrlf.xml]
call ant -f fixcrlf.xml
echo -------------------------------------------------------------------------------
echo 終了するには何かキーを押してください . . .
pause > nul
<?xml version="1.0" encoding="UTF-8"?>
<!-- Apache Ant build.xml -->
<project name="fixcrlf">
<fixcrlf srcdir="./" destdir="./cooked" includes="**/*.java"
encoding="EUC_JP" outputencoding="UTF-8" eol="lf"/>
</project>
@echo off
call ant -f javarun.xml -Dapi-name="%1" -Dlogin-user-name="%2" -Dproc-timestamp="%3"
echo ERRORLEVEL=%ERRORLEVEL%
<?xml version="1.0" encoding="UTF-8"?>
<!-- Apache Ant build.xml -->
<project name="javarun" default="javarun">
<target name="init">
<property name="aimed-class-name" value="example.Main"/>
<property name="classes-dir" value="target/classes"/>
<property name="lib-dir" value="target/lib"/>
<!--<property name="api-name" value="xxxx"/>-->
<!--<property name="login-user-name" value="xxxx"/>-->
<!--<property name="proc-timestamp" value="xxxx"/>-->
</target>
<target name="javarun" depends="init">
<java classname="${aimed-class-name}" dir="." fork="true" resultproperty="exit-status">
<classpath>
<pathelement location="${classes-dir}"/>
<fileset dir="${lib-dir}">
<include name="**/*.jar"/>
</fileset>
<pathelement path="${java.class.path}"/>
</classpath>
<arg value="${api-name}"/>
<arg value="${login-user-name}"/>
<arg value="${proc-timestamp}"/>
</java>
<fail status="${exit-status}">
<condition>
<not><equals arg1="${exit-status}" arg2="0"/></not>
</condition>
</fail>
</target>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Apache Ant build.xml -->
<project name="rename" default="rename">
<target name="init">
<property name="source" value="."/>
<property name="target" value="."/>
</target>
<target name="rename" depends="init">
<move todir="${target}">
<fileset dir="${source}">
<include name="P*.*"/>
</fileset>
<regexpmapper from="^P999[0-9]{4}\-([0-9]{3})\-([0-9]{2})\.tif$$" to="20170801_\1\2.tif"/>
</move>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment