Browse Source

please don't use <zip>'s file attribute

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271422 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
f20a1d1c4d
3 changed files with 76 additions and 3 deletions
  1. +17
    -3
      src/main/org/apache/tools/ant/taskdefs/Zip.java
  2. +47
    -0
      src/main/org/apache/tools/ant/util/DateUtils.java
  3. +12
    -0
      src/testcases/org/apache/tools/ant/util/DateUtilsTest.java

+ 17
- 3
src/main/org/apache/tools/ant/taskdefs/Zip.java View File

@@ -62,12 +62,13 @@ import java.io.OutputStream;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;

import java.util.Calendar;
import java.util.Hashtable;
import java.util.Stack;

import java.util.Vector;
import java.util.zip.CRC32;
import java.util.zip.ZipInputStream;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.FileScanner;
import org.apache.tools.ant.Project;
@@ -76,6 +77,7 @@ import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.EnumeratedAttribute;
import org.apache.tools.ant.types.ZipFileSet;
import org.apache.tools.ant.types.ZipScanner;
import org.apache.tools.ant.util.DateUtils;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.SourceFileScanner;
import org.apache.tools.ant.util.MergingMapper;
@@ -135,9 +137,21 @@ public class Zip extends MatchingTask {
* @deprecated Use setDestFile(File) instead
*/
public void setFile(File file) {
log("DEPRECATED - The file attribute has been renamed destfile."
+" This attribute will be unsupported before Ant1.5 is released",
log("DEPRECATED - The file attribute has been renamed destfile.",
Project.MSG_ERR);
log("This attribute will be unsupported before Ant1.5 is released.",
Project.MSG_ERR);

log("Be aware that the effect of using the file attribute depends on",
Project.MSG_ERR);
log("the phase of the moon.", Project.MSG_WARN);
int phase = DateUtils.getPhaseOfMoon(Calendar.getInstance());
if (phase == 4) {
log("You are lucky! Full moon tonight.");
} else if (phase == 0) {
log("Be careful! New moon tonight.", Project.MSG_WARN);
}
setDestFile(file);
}



+ 47
- 0
src/main/org/apache/tools/ant/util/DateUtils.java View File

@@ -57,6 +57,7 @@ import java.text.ChoiceFormat;
import java.text.DateFormat;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

@@ -66,6 +67,11 @@ import java.util.TimeZone;
* or a plurialization correct elapsed time in minutes and seconds.
*
* @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*
* @since Ant 1.5
*
* @version $Revision$
*/
public final class DateUtils {

@@ -172,4 +178,45 @@ public final class DateUtils {
return sdf;
}

/**
* Calculate the phase of the moon for a given date.
*
* <p>Code heavily influenced by hacklib.c in <a
* href="http://www.nethack.org/">Nethack</a></p>
*
* <p>The Algorithm:
*
* <pre>
* moon period = 29.53058 days ~= 30, year = 365.2422 days
*
* days moon phase advances on first day of year compared to preceding year
* = 365.2422 - 12*29.53058 ~= 11
*
* years in Metonic cycle (time until same phases fall on the same days of
* the month) = 18.6 ~= 19
*
* moon phase on first day of year (epact) ~= (11*(year%19) + 18) % 30
* (18 as initial condition for 1900)
*
* current phase in days = first day phase + days elapsed in year
*
* 6 moons ~= 177 days
* 177 ~= 8 reported phases * 22
* + 11/22 for rounding
* </pre>
*
* @return The phase of the moon as a number between 0 and 7 with
* 0 meaning new moon and 4 meaning full moon.
*
* @since 1.2, Ant 1.5
*/
public static int getPhaseOfMoon(Calendar cal) {
int dayOfTheYear = cal.get(Calendar.DAY_OF_YEAR);
int yearInMetonicCycle = ((cal.get(Calendar.YEAR)-1900) % 19) + 1;
int epact = (11 * yearInMetonicCycle + 18) % 30;
if ((epact == 25 && yearInMetonicCycle > 11) || epact == 24) {
epact++;
}
return (((((dayOfTheYear + epact) * 6) + 11) % 177) / 22) & 7;
}
}

+ 12
- 0
src/testcases/org/apache/tools/ant/util/DateUtilsTest.java View File

@@ -63,6 +63,7 @@ import junit.framework.TestCase;
* TestCase for DateUtils.
*
* @author <a href="mailto:sbailliez@apache.org">Stephane Bailliez</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
*/
public class DateUtilsTest extends TestCase {
public DateUtilsTest(String s) {
@@ -115,4 +116,15 @@ public class DateUtilsTest extends TestCase {
DateUtils.ISO8601_TIME_PATTERN);
assertEquals("20:11:12", text);
}

public void testPhaseOfMoon() {
TimeZone timeZone = TimeZone.getTimeZone("GMT");
Calendar cal = Calendar.getInstance(timeZone);
// should be full moon
cal.set(2002, 2, 27);
assertEquals(4, DateUtils.getPhaseOfMoon(cal));
// should be new moon
cal.set(2002, 2, 12);
assertEquals(0, DateUtils.getPhaseOfMoon(cal));
}
}

Loading…
Cancel
Save