Skip to content

Commit

Permalink
Include hostname in report filename
Browse files Browse the repository at this point in the history
  • Loading branch information
klaren committed Mar 23, 2018
1 parent 2c1985b commit 8ddc62d
Showing 1 changed file with 11 additions and 2 deletions.
Expand Up @@ -25,6 +25,8 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.util.Date;
Expand Down Expand Up @@ -117,8 +119,7 @@ public void execute( String[] stringArgs ) throws IncorrectUsage, CommandFailed
Path destinationDir = new File( destinationArgument.parse( args ) ).toPath();
try
{
SimpleDateFormat dumpFormat = new SimpleDateFormat( "yyyy-MM-dd_HHmmss" );
Path reportFile = destinationDir.resolve( dumpFormat.format( new Date() ) + ".zip" );
Path reportFile = destinationDir.resolve( getDefaultFilename() );
out.println( "Writing report to " + reportFile.toAbsolutePath().toString() );
reporter.dump( classifiers.get(), reportFile, progress, force );
}
Expand All @@ -128,6 +129,14 @@ public void execute( String[] stringArgs ) throws IncorrectUsage, CommandFailed
}
}

private String getDefaultFilename() throws UnknownHostException
{
String hostName = InetAddress.getLocalHost().getHostName();
String safeFilename = hostName.replaceAll( "[^a-zA-Z0-9._]+", "_" );
SimpleDateFormat dumpFormat = new SimpleDateFormat( "yyyy-MM-dd_HHmmss" );
return safeFilename + "-" + dumpFormat.format( new Date() ) + ".zip";
}

private DiagnosticsReporterProgress buildProgress()
{
DiagnosticsReporterProgress progress;
Expand Down

0 comments on commit 8ddc62d

Please sign in to comment.