Merged branch 'jetty-9.4.x' into 'master'.
This commit is contained in:
commit
146a1d5ed5
|
@ -0,0 +1,8 @@
|
|||
[name]
|
||||
protonego-boot
|
||||
|
||||
[files]
|
||||
http://central.maven.org/maven2/org/mortbay/jetty/alpn/alpn-boot/8.1.11.v20170118/alpn-boot-8.1.11.v20170118.jar|lib/alpn/alpn-boot-8.1.11.v20170118.jar
|
||||
|
||||
[exec]
|
||||
-Xbootclasspath/p:lib/alpn/alpn-boot-8.1.11.v20170118.jar
|
|
@ -244,6 +244,7 @@ The ALPN implementation, relying on modifications of OpenJDK classes, updates ev
|
|||
|1.8.0u111 |8.1.9.v20160720
|
||||
|1.8.0u112 |8.1.10.v20161026
|
||||
|1.8.0u121 |8.1.11.v20170118
|
||||
|1.8.0u131 |8.1.11.v20170118
|
||||
|=============================
|
||||
|
||||
[[alpn-build]]
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
<url>http://www.eclipse.org/jetty</url>
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
[name]
|
||||
protonego-boot
|
||||
|
||||
[files]
|
||||
http://central.maven.org/maven2/org/mortbay/jetty/alpn/alpn-boot/8.1.11.v20170118/alpn-boot-8.1.11.v20170118.jar|lib/alpn/alpn-boot-8.1.11.v20170118.jar
|
||||
|
||||
[exec]
|
||||
-Xbootclasspath/p:lib/alpn/alpn-boot-8.1.11.v20170118.jar
|
|
@ -25,6 +25,7 @@ import java.io.IOException;
|
|||
import java.io.OutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
@ -117,9 +118,9 @@ public class RolloverFileOutputStream extends FilterOutputStream
|
|||
TimeZone zone)
|
||||
throws IOException
|
||||
{
|
||||
this(filename,append,retainDays,zone,null,null);
|
||||
this(filename,append,retainDays,zone,null,null,ZonedDateTime.now(zone.toZoneId()));
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param filename The filename must include the string "yyyy_mm_dd",
|
||||
|
@ -138,20 +139,33 @@ public class RolloverFileOutputStream extends FilterOutputStream
|
|||
String dateFormat,
|
||||
String backupFormat)
|
||||
throws IOException
|
||||
{
|
||||
this(filename,append,retainDays,zone,dateFormat,backupFormat,ZonedDateTime.now(zone.toZoneId()));
|
||||
}
|
||||
|
||||
|
||||
RolloverFileOutputStream(String filename,
|
||||
boolean append,
|
||||
int retainDays,
|
||||
TimeZone zone,
|
||||
String dateFormat,
|
||||
String backupFormat,
|
||||
ZonedDateTime now)
|
||||
throws IOException
|
||||
{
|
||||
super(null);
|
||||
|
||||
if (dateFormat==null)
|
||||
dateFormat=ROLLOVER_FILE_DATE_FORMAT;
|
||||
_fileDateFormat = new SimpleDateFormat(dateFormat);
|
||||
|
||||
|
||||
if (backupFormat==null)
|
||||
backupFormat=ROLLOVER_FILE_BACKUP_FORMAT;
|
||||
_fileBackupFormat = new SimpleDateFormat(backupFormat);
|
||||
|
||||
|
||||
_fileBackupFormat.setTimeZone(zone);
|
||||
_fileDateFormat.setTimeZone(zone);
|
||||
|
||||
|
||||
if (filename!=null)
|
||||
{
|
||||
filename=filename.trim();
|
||||
|
@ -171,7 +185,6 @@ public class RolloverFileOutputStream extends FilterOutputStream
|
|||
__rollover=new Timer(RolloverFileOutputStream.class.getName(),true);
|
||||
|
||||
// Calculate Today's Midnight, based on Configured TimeZone (will be in past, even if by a few milliseconds)
|
||||
ZonedDateTime now = ZonedDateTime.now(zone.toZoneId());
|
||||
setFile(now);
|
||||
// This will schedule the rollover event to the next midnight
|
||||
scheduleNextRollover(now);
|
||||
|
@ -187,7 +200,7 @@ public class RolloverFileOutputStream extends FilterOutputStream
|
|||
*/
|
||||
public static ZonedDateTime toMidnight(ZonedDateTime now)
|
||||
{
|
||||
return now.toLocalDate().atStartOfDay(now.getZone());
|
||||
return now.toLocalDate().atStartOfDay(now.getZone()).plus(1, ChronoUnit.DAYS);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -223,7 +236,7 @@ public class RolloverFileOutputStream extends FilterOutputStream
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
private synchronized void setFile(ZonedDateTime now)
|
||||
synchronized void setFile(ZonedDateTime now)
|
||||
throws IOException
|
||||
{
|
||||
// Check directory
|
||||
|
@ -254,7 +267,7 @@ public class RolloverFileOutputStream extends FilterOutputStream
|
|||
// Yep
|
||||
_file=file;
|
||||
if (!_append && file.exists())
|
||||
file.renameTo(new File(file.toString()+"."+_fileBackupFormat.format(now)));
|
||||
file.renameTo(new File(file.toString()+"."+_fileBackupFormat.format(new Date(now.toInstant().toEpochMilli()))));
|
||||
OutputStream oldOut=out;
|
||||
out=new FileOutputStream(file.toString(),_append);
|
||||
if (oldOut!=null)
|
||||
|
@ -264,12 +277,12 @@ public class RolloverFileOutputStream extends FilterOutputStream
|
|||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
private void removeOldFiles(ZonedDateTime now)
|
||||
void removeOldFiles(ZonedDateTime now)
|
||||
{
|
||||
if (_retainDays>0)
|
||||
{
|
||||
// Establish expiration time, based on configured TimeZone
|
||||
long expired = now.toInstant().toEpochMilli();
|
||||
long expired = now.minus(_retainDays, ChronoUnit.DAYS).toInstant().toEpochMilli();
|
||||
|
||||
File file= new File(_filename);
|
||||
File dir = new File(file.getParent());
|
||||
|
|
|
@ -21,13 +21,24 @@ package org.eclipse.jetty.util;
|
|||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.FileTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.util.Arrays;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.eclipse.jetty.toolchain.test.FS;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.resource.ResourceTest;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
public class RolloverFileOutputStreamTest
|
||||
|
@ -73,13 +84,14 @@ public class RolloverFileOutputStreamTest
|
|||
public void testMidnightRolloverCalc_PDT_Issue1507()
|
||||
{
|
||||
ZoneId zone = toZoneId("PST");
|
||||
ZonedDateTime initialDate = toDateTime("2017.04.27-08:00:00.0 PM PDT", zone);
|
||||
ZonedDateTime initialDate = toDateTime("2017.04.26-08:00:00.0 PM PDT", zone);
|
||||
|
||||
ZonedDateTime midnight = RolloverFileOutputStream.toMidnight(initialDate);
|
||||
assertThat("Midnight", toString(midnight), is("2017.04.27-12:00:00.0 AM PDT"));
|
||||
|
||||
Object expected[][] = {
|
||||
{"2017.04.28-12:00:00.0 AM PDT", 14_400_000L}, // Ensure not negative
|
||||
{"2017.04.27-12:00:00.0 AM PDT", 14_400_000L},
|
||||
{"2017.04.28-12:00:00.0 AM PDT", 86_400_000L},
|
||||
{"2017.04.29-12:00:00.0 AM PDT", 86_400_000L},
|
||||
{"2017.04.30-12:00:00.0 AM PDT", 86_400_000L},
|
||||
{"2017.05.01-12:00:00.0 AM PDT", 86_400_000L},
|
||||
|
@ -93,7 +105,7 @@ public class RolloverFileOutputStreamTest
|
|||
public void testMidnightRolloverCalc_PST_DST_Start()
|
||||
{
|
||||
ZoneId zone = toZoneId("PST");
|
||||
ZonedDateTime initialDate = toDateTime("2016.03.11-01:23:45.0 PM PST", zone);
|
||||
ZonedDateTime initialDate = toDateTime("2016.03.10-01:23:45.0 PM PST", zone);
|
||||
|
||||
ZonedDateTime midnight = RolloverFileOutputStream.toMidnight(initialDate);
|
||||
assertThat("Midnight", toString(midnight), is("2016.03.11-12:00:00.0 AM PST"));
|
||||
|
@ -113,7 +125,7 @@ public class RolloverFileOutputStreamTest
|
|||
public void testMidnightRolloverCalc_PST_DST_End()
|
||||
{
|
||||
ZoneId zone = toZoneId("PST");
|
||||
ZonedDateTime initialDate = toDateTime("2016.11.04-11:22:33.0 AM PDT", zone);
|
||||
ZonedDateTime initialDate = toDateTime("2016.11.03-11:22:33.0 AM PDT", zone);
|
||||
|
||||
ZonedDateTime midnight = RolloverFileOutputStream.toMidnight(initialDate);
|
||||
assertThat("Midnight", toString(midnight), is("2016.11.04-12:00:00.0 AM PDT"));
|
||||
|
@ -133,7 +145,7 @@ public class RolloverFileOutputStreamTest
|
|||
public void testMidnightRolloverCalc_Sydney_DST_Start()
|
||||
{
|
||||
ZoneId zone = toZoneId("Australia/Sydney");
|
||||
ZonedDateTime initialDate = toDateTime("2016.10.01-01:23:45.0 PM AEST", zone);
|
||||
ZonedDateTime initialDate = toDateTime("2016.09.31-01:23:45.0 PM AEST", zone);
|
||||
|
||||
ZonedDateTime midnight = RolloverFileOutputStream.toMidnight(initialDate);
|
||||
assertThat("Midnight", toString(midnight), is("2016.10.01-12:00:00.0 AM AEST"));
|
||||
|
@ -153,7 +165,7 @@ public class RolloverFileOutputStreamTest
|
|||
public void testMidnightRolloverCalc_Sydney_DST_End()
|
||||
{
|
||||
ZoneId zone = toZoneId("Australia/Sydney");
|
||||
ZonedDateTime initialDate = toDateTime("2016.04.02-11:22:33.0 AM AEDT", zone);
|
||||
ZonedDateTime initialDate = toDateTime("2016.04.01-11:22:33.0 AM AEDT", zone);
|
||||
|
||||
ZonedDateTime midnight = RolloverFileOutputStream.toMidnight(initialDate);
|
||||
assertThat("Midnight", toString(midnight), is("2016.04.02-12:00:00.0 AM AEDT"));
|
||||
|
@ -168,4 +180,150 @@ public class RolloverFileOutputStreamTest
|
|||
|
||||
assertSequence(midnight, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilehandling() throws Exception
|
||||
{
|
||||
File testDir = MavenTestingUtils.getTargetTestingDir(ResourceTest.class.getName());
|
||||
Path testPath = testDir.toPath();
|
||||
FS.ensureEmpty(testDir);
|
||||
|
||||
ZoneId zone = toZoneId("Australia/Sydney");
|
||||
ZonedDateTime now = toDateTime("2016.04.10-08:30:12.3 AM AEDT", zone);
|
||||
|
||||
File template = new File(testDir,"test-rofos-yyyy_mm_dd.log");
|
||||
|
||||
try (RolloverFileOutputStream rofos =
|
||||
new RolloverFileOutputStream(template.getAbsolutePath(),false,3,TimeZone.getTimeZone(zone),null,null,now))
|
||||
{
|
||||
rofos.write("TICK".getBytes());
|
||||
rofos.flush();
|
||||
}
|
||||
|
||||
now = now.plus(5,ChronoUnit.MINUTES);
|
||||
|
||||
try (RolloverFileOutputStream rofos =
|
||||
new RolloverFileOutputStream(template.getAbsolutePath(),false,3,TimeZone.getTimeZone(zone),null,null,now))
|
||||
{
|
||||
rofos.write("TOCK".getBytes());
|
||||
rofos.flush();
|
||||
String[] ls = testDir.list();
|
||||
assertThat(ls.length,is(2));
|
||||
String backup = null;
|
||||
for (String n: ls)
|
||||
{
|
||||
if (!"test-rofos-2016_04_10.log".equals(n))
|
||||
backup = n;
|
||||
}
|
||||
|
||||
assertThat(Arrays.asList(ls),Matchers.containsInAnyOrder(backup,"test-rofos-2016_04_10.log"));
|
||||
|
||||
Files.setLastModifiedTime(testPath.resolve(backup),FileTime.from(now.toInstant()));
|
||||
Files.setLastModifiedTime(testPath.resolve("test-rofos-2016_04_10.log"),FileTime.from(now.toInstant()));
|
||||
|
||||
ZonedDateTime time = now.minus(1,ChronoUnit.DAYS);
|
||||
for (int i=10;i-->5;)
|
||||
{
|
||||
String file = "test-rofos-2016_04_0"+i+".log";
|
||||
Path path = testPath.resolve(file);
|
||||
FS.touch(path);
|
||||
Files.setLastModifiedTime(path,FileTime.from(time.toInstant()));
|
||||
|
||||
if (i%2==0)
|
||||
{
|
||||
file = "test-rofos-2016_04_0"+i+".log.083512300";
|
||||
path = testPath.resolve(file);
|
||||
FS.touch(path);
|
||||
Files.setLastModifiedTime(path,FileTime.from(time.toInstant()));
|
||||
time = time.minus(1,ChronoUnit.DAYS);
|
||||
}
|
||||
|
||||
file = "unrelated-"+i;
|
||||
path = testPath.resolve(file);
|
||||
FS.touch(path);
|
||||
Files.setLastModifiedTime(path,FileTime.from(time.toInstant()));
|
||||
|
||||
time = time.minus(1,ChronoUnit.DAYS);
|
||||
}
|
||||
|
||||
ls = testDir.list();
|
||||
assertThat(ls.length,is(14));
|
||||
assertThat(Arrays.asList(ls),Matchers.containsInAnyOrder(
|
||||
"test-rofos-2016_04_05.log",
|
||||
"test-rofos-2016_04_06.log",
|
||||
"test-rofos-2016_04_07.log",
|
||||
"test-rofos-2016_04_08.log",
|
||||
"test-rofos-2016_04_09.log",
|
||||
"test-rofos-2016_04_10.log",
|
||||
"test-rofos-2016_04_06.log.083512300",
|
||||
"test-rofos-2016_04_08.log.083512300",
|
||||
"test-rofos-2016_04_10.log.083512300",
|
||||
"unrelated-9",
|
||||
"unrelated-8",
|
||||
"unrelated-7",
|
||||
"unrelated-6",
|
||||
"unrelated-5"
|
||||
));
|
||||
|
||||
rofos.removeOldFiles(now);
|
||||
ls = testDir.list();
|
||||
assertThat(ls.length,is(10));
|
||||
assertThat(Arrays.asList(ls),Matchers.containsInAnyOrder(
|
||||
"test-rofos-2016_04_08.log",
|
||||
"test-rofos-2016_04_09.log",
|
||||
"test-rofos-2016_04_10.log",
|
||||
"test-rofos-2016_04_08.log.083512300",
|
||||
"test-rofos-2016_04_10.log.083512300",
|
||||
"unrelated-9",
|
||||
"unrelated-8",
|
||||
"unrelated-7",
|
||||
"unrelated-6",
|
||||
"unrelated-5"));
|
||||
|
||||
|
||||
assertThat(IO.toString(new FileReader(new File(testDir,backup))),is("TICK"));
|
||||
assertThat(IO.toString(new FileReader(new File(testDir,"test-rofos-2016_04_10.log"))),is("TOCK"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRollover() throws Exception
|
||||
{
|
||||
File testDir = MavenTestingUtils.getTargetTestingDir(ResourceTest.class.getName());
|
||||
FS.ensureEmpty(testDir);
|
||||
|
||||
ZoneId zone = toZoneId("Australia/Sydney");
|
||||
ZonedDateTime now = toDateTime("2016.04.10-11:59:55.0 PM AEDT", zone);
|
||||
|
||||
File template = new File(testDir,"test-rofos-yyyy_mm_dd.log");
|
||||
|
||||
try (RolloverFileOutputStream rofos =
|
||||
new RolloverFileOutputStream(template.getAbsolutePath(),false,0,TimeZone.getTimeZone(zone),null,null,now))
|
||||
{
|
||||
rofos.write("BEFORE".getBytes());
|
||||
rofos.flush();
|
||||
String[] ls = testDir.list();
|
||||
assertThat(ls.length,is(1));
|
||||
assertThat(ls[0],is("test-rofos-2016_04_10.log"));
|
||||
|
||||
TimeUnit.SECONDS.sleep(10);
|
||||
rofos.write("AFTER".getBytes());
|
||||
ls = testDir.list();
|
||||
assertThat(ls.length,is(2));
|
||||
|
||||
for (String n : ls)
|
||||
{
|
||||
String content = IO.toString(new FileReader(new File(testDir,n)));
|
||||
if ("test-rofos-2016_04_10.log".equals(n))
|
||||
{
|
||||
assertThat(content,is("BEFORE"));
|
||||
}
|
||||
else
|
||||
{
|
||||
assertThat(content,is("AFTER"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
pom.xml
12
pom.xml
|
@ -1464,6 +1464,18 @@
|
|||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>8u131</id>
|
||||
<activation>
|
||||
<property>
|
||||
<name>java.version</name>
|
||||
<value>1.8.0_131</value>
|
||||
</property>
|
||||
</activation>
|
||||
<properties>
|
||||
<alpn.version>8.1.11.v20170118</alpn.version>
|
||||
</properties>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<issueManagement>
|
||||
|
|
Loading…
Reference in New Issue