|
@@ -28,17 +28,23 @@ import org.apache.catalina.startup.Tomcat;
|
|
import org.apache.catalina.util.ServerInfo;
|
|
import org.apache.catalina.util.ServerInfo;
|
|
|
|
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.ServletException;
|
|
|
|
+import java.io.BufferedReader;
|
|
import java.io.File;
|
|
import java.io.File;
|
|
-import java.io.FileWriter;
|
|
|
|
|
|
+import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
|
+import java.io.InputStreamReader;
|
|
|
|
+import java.io.OutputStreamWriter;
|
|
|
|
+import java.io.Writer;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Method;
|
|
import java.net.URL;
|
|
import java.net.URL;
|
|
import java.net.URLClassLoader;
|
|
import java.net.URLClassLoader;
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
import java.nio.file.FileVisitOption;
|
|
import java.nio.file.FileVisitOption;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Path;
|
|
|
|
+import java.nio.file.Paths;
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
import java.time.Instant;
|
|
import java.time.Instant;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -47,61 +53,26 @@ import java.util.List;
|
|
import java.util.Properties;
|
|
import java.util.Properties;
|
|
import java.util.jar.Attributes;
|
|
import java.util.jar.Attributes;
|
|
import java.util.jar.Manifest;
|
|
import java.util.jar.Manifest;
|
|
|
|
+import java.util.stream.Collectors;
|
|
import java.util.zip.ZipEntry;
|
|
import java.util.zip.ZipEntry;
|
|
import java.util.zip.ZipInputStream;
|
|
import java.util.zip.ZipInputStream;
|
|
|
|
|
|
-public class TomcatOneJarMain
|
|
|
|
|
|
+public class TomcatOnejarRunner
|
|
{
|
|
{
|
|
- //private static final String TEMP_WAR_FILE_NAME = "embed.war";
|
|
|
|
- private static final String KEYSTORE_ALIAS = "https";
|
|
|
|
|
|
+ final OnejarMain onejarMain;
|
|
|
|
|
|
- public static void main( final String[] args )
|
|
|
|
|
|
+ public TomcatOnejarRunner( final OnejarMain onejarMain )
|
|
{
|
|
{
|
|
- final ArgumentParser argumentParser = new ArgumentParser();
|
|
|
|
- TomcatConfig tomcatConfig = null;
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
- tomcatConfig = argumentParser.parseArguments( args );
|
|
|
|
- }
|
|
|
|
- catch ( ArgumentParserException | TomcatOneJarException e )
|
|
|
|
- {
|
|
|
|
- out( "error parsing command line: " + e.getMessage() );
|
|
|
|
- }
|
|
|
|
- if ( tomcatConfig != null )
|
|
|
|
- {
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
- startTomcat( tomcatConfig );
|
|
|
|
- }
|
|
|
|
- catch ( TomcatOneJarException | ServletException | IOException e )
|
|
|
|
- {
|
|
|
|
- out( "error starting tomcat: " + e.getMessage() );
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ this.onejarMain = onejarMain;
|
|
}
|
|
}
|
|
|
|
|
|
- private static File getWarFolder( final TomcatConfig tomcatConfig ) throws IOException
|
|
|
|
|
|
+ private void explodeWar( final OnejarConfig onejarConfig ) throws IOException
|
|
{
|
|
{
|
|
- return new File( tomcatConfig.getWorkingPath().getAbsoluteFile() + File.separator + "war" );
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private static File getKeystoreFile( final TomcatConfig tomcatConfig )
|
|
|
|
- {
|
|
|
|
- return new File( tomcatConfig.getWorkingPath().getAbsoluteFile() + File.separator + "keystore" );
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private static File getPwmAppPropertiesFile( final TomcatConfig tomcatConfig )
|
|
|
|
- {
|
|
|
|
- return new File( tomcatConfig.getWorkingPath().getAbsoluteFile() + File.separator + "application.properties" );
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- private static void explodeWar( final TomcatConfig tomcatConfig ) throws IOException
|
|
|
|
- {
|
|
|
|
- final InputStream warSource = tomcatConfig.getWar();
|
|
|
|
|
|
+ final InputStream warSource = onejarConfig.getWar();
|
|
final ZipInputStream zipInputStream = new ZipInputStream( warSource );
|
|
final ZipInputStream zipInputStream = new ZipInputStream( warSource );
|
|
- final File outputFolder = getWarFolder( tomcatConfig );
|
|
|
|
- outputFolder.mkdir();
|
|
|
|
|
|
+ final File outputFolder = onejarConfig.getWarFolder( );
|
|
|
|
+
|
|
|
|
+ ArgumentParser.mkdirs( outputFolder );
|
|
|
|
|
|
ZipEntry zipEntry = zipInputStream.getNextEntry();
|
|
ZipEntry zipEntry = zipInputStream.getNextEntry();
|
|
|
|
|
|
@@ -112,7 +83,7 @@ public class TomcatOneJarMain
|
|
|
|
|
|
if ( !zipEntry.isDirectory() )
|
|
if ( !zipEntry.isDirectory() )
|
|
{
|
|
{
|
|
- newFile.getParentFile().mkdirs();
|
|
|
|
|
|
+ ArgumentParser.mkdirs( newFile.getParentFile() );
|
|
Files.copy( zipInputStream, newFile.toPath() );
|
|
Files.copy( zipInputStream, newFile.toPath() );
|
|
}
|
|
}
|
|
zipEntry = zipInputStream.getNextEntry();
|
|
zipEntry = zipInputStream.getNextEntry();
|
|
@@ -120,98 +91,124 @@ public class TomcatOneJarMain
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private static void startTomcat( final TomcatConfig tomcatConfig ) throws ServletException, IOException, TomcatOneJarException
|
|
|
|
|
|
+ void startTomcat( final OnejarConfig onejarConfig )
|
|
|
|
+ throws ServletException, IOException, OnejarException
|
|
{
|
|
{
|
|
final Instant startTime = Instant.now();
|
|
final Instant startTime = Instant.now();
|
|
|
|
|
|
- purgeDirectory( tomcatConfig.getWorkingPath().toPath() );
|
|
|
|
|
|
+ purgeDirectory( onejarConfig.getWorkingPath().toPath() );
|
|
|
|
|
|
- explodeWar( tomcatConfig );
|
|
|
|
|
|
+ explodeWar( onejarConfig );
|
|
out( "deployed war" );
|
|
out( "deployed war" );
|
|
|
|
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- generatePwmKeystore( tomcatConfig );
|
|
|
|
|
|
+ generatePwmKeystore( onejarConfig );
|
|
out( "keystore generated" );
|
|
out( "keystore generated" );
|
|
}
|
|
}
|
|
catch ( Exception e )
|
|
catch ( Exception e )
|
|
{
|
|
{
|
|
- throw new TomcatOneJarException( "error generating keystore: " + e.getMessage() );
|
|
|
|
|
|
+ throw new OnejarException( "error generating keystore: " + e.getMessage() );
|
|
}
|
|
}
|
|
|
|
|
|
- outputPwmAppProperties( tomcatConfig );
|
|
|
|
|
|
+ outputPwmAppProperties( onejarConfig );
|
|
|
|
|
|
- setupEnv( tomcatConfig );
|
|
|
|
|
|
+ setupEnv( onejarConfig );
|
|
|
|
|
|
final Tomcat tomcat = new Tomcat();
|
|
final Tomcat tomcat = new Tomcat();
|
|
|
|
|
|
{
|
|
{
|
|
- final File basePath = new File( tomcatConfig.getWorkingPath().getPath() + File.separator + "b" );
|
|
|
|
- basePath.mkdir();
|
|
|
|
|
|
+ final File basePath = new File( onejarConfig.getWorkingPath().getPath() + File.separator + "b" );
|
|
|
|
+ ArgumentParser.mkdirs( basePath );
|
|
tomcat.setBaseDir( basePath.getAbsolutePath() );
|
|
tomcat.setBaseDir( basePath.getAbsolutePath() );
|
|
}
|
|
}
|
|
{
|
|
{
|
|
- final File basePath = new File( tomcatConfig.getWorkingPath().getPath() + File.separator + "a" );
|
|
|
|
- basePath.mkdir();
|
|
|
|
|
|
+ final File basePath = new File( onejarConfig.getWorkingPath().getPath() + File.separator + "a" );
|
|
|
|
+ ArgumentParser.mkdirs( basePath );
|
|
tomcat.getServer().setCatalinaBase( basePath );
|
|
tomcat.getServer().setCatalinaBase( basePath );
|
|
tomcat.getServer().setCatalinaHome( basePath );
|
|
tomcat.getServer().setCatalinaHome( basePath );
|
|
}
|
|
}
|
|
{
|
|
{
|
|
- final File workPath = new File( tomcatConfig.getWorkingPath().getPath() + File.separator + "w" );
|
|
|
|
- workPath.mkdir();
|
|
|
|
|
|
+ final File workPath = new File( onejarConfig.getWorkingPath().getPath() + File.separator + "w" );
|
|
|
|
+ ArgumentParser.mkdirs( workPath );
|
|
tomcat.getHost().setAppBase( workPath.getAbsolutePath() );
|
|
tomcat.getHost().setAppBase( workPath.getAbsolutePath() );
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
tomcat.getHost().setAutoDeploy( false );
|
|
tomcat.getHost().setAutoDeploy( false );
|
|
tomcat.getHost().setDeployOnStartup( false );
|
|
tomcat.getHost().setDeployOnStartup( false );
|
|
|
|
|
|
- final String warPath = getWarFolder( tomcatConfig ).getAbsolutePath();
|
|
|
|
- tomcat.addWebapp( "/" + tomcatConfig.getContext(), warPath );
|
|
|
|
|
|
+ deployRedirectConnector( tomcat, onejarConfig );
|
|
|
|
+
|
|
|
|
+ final String warPath = onejarConfig.getWarFolder().getAbsolutePath();
|
|
|
|
+ tomcat.addWebapp( "/" + onejarConfig.getContext(), warPath );
|
|
|
|
+
|
|
|
|
|
|
try
|
|
try
|
|
{
|
|
{
|
|
tomcat.start();
|
|
tomcat.start();
|
|
|
|
|
|
- tomcat.setConnector( makeConnector( tomcatConfig ) );
|
|
|
|
|
|
+ tomcat.setConnector( makeConnector( onejarConfig ) );
|
|
|
|
|
|
out( "tomcat started in " + Duration.between( Instant.now(), startTime ).toString() );
|
|
out( "tomcat started in " + Duration.between( Instant.now(), startTime ).toString() );
|
|
}
|
|
}
|
|
catch ( LifecycleException e )
|
|
catch ( LifecycleException e )
|
|
{
|
|
{
|
|
- throw new TomcatOneJarException( "unable to start tomcat: " + e.getMessage() );
|
|
|
|
|
|
+ throw new OnejarException( "unable to start tomcat: " + e.getMessage() );
|
|
}
|
|
}
|
|
-
|
|
|
|
tomcat.getServer().await();
|
|
tomcat.getServer().await();
|
|
|
|
|
|
- System.out.println( "\n" );
|
|
|
|
|
|
+ System.out.println( "\nexiting..." );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void deployRedirectConnector( final Tomcat tomcat, final OnejarConfig onejarConfig )
|
|
|
|
+ throws IOException, ServletException
|
|
|
|
+ {
|
|
|
|
+ final String srcRootWebXml = "ROOT-redirect-webapp/WEB-INF/web.xml";
|
|
|
|
+ final String srcRootIndex = "ROOT-redirect-webapp/WEB-INF/index.jsp";
|
|
|
|
+
|
|
|
|
+ final File redirBase = new File( onejarConfig.getWorkingPath().getAbsoluteFile() + File.separator + "redirectBase" );
|
|
|
|
+ ArgumentParser.mkdirs( redirBase );
|
|
|
|
+ {
|
|
|
|
+ ArgumentParser.mkdirs( new File ( redirBase.getAbsolutePath() + File.separator + "WEB-INF" ) );
|
|
|
|
+ copyFileAndReplace(
|
|
|
|
+ srcRootWebXml,
|
|
|
|
+ redirBase.getPath() + File.separator + "WEB-INF" + File.separator + "web.xml",
|
|
|
|
+ onejarConfig.getContext() );
|
|
|
|
+ copyFileAndReplace(
|
|
|
|
+ srcRootIndex,
|
|
|
|
+ redirBase.getPath() + File.separator + "WEB-INF" + File.separator + "index.jsp",
|
|
|
|
+ onejarConfig.getContext() );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ tomcat.addWebapp( "", redirBase.getAbsolutePath() );
|
|
}
|
|
}
|
|
|
|
|
|
- private static Connector makeConnector( final TomcatConfig tomcatConfig )
|
|
|
|
|
|
+
|
|
|
|
+ private Connector makeConnector( final OnejarConfig onejarConfig )
|
|
{
|
|
{
|
|
final Connector connector = new Connector( "HTTP/1.1" );
|
|
final Connector connector = new Connector( "HTTP/1.1" );
|
|
- connector.setPort( tomcatConfig.getPort() );
|
|
|
|
|
|
+ connector.setPort( onejarConfig.getPort() );
|
|
|
|
|
|
- if ( tomcatConfig.getLocalAddress() != null && !tomcatConfig.getLocalAddress().isEmpty() )
|
|
|
|
|
|
+ if ( onejarConfig.getLocalAddress() != null && !onejarConfig.getLocalAddress().isEmpty() )
|
|
{
|
|
{
|
|
- connector.setProperty( "address", tomcatConfig.getLocalAddress() );
|
|
|
|
|
|
+ connector.setProperty( "address", onejarConfig.getLocalAddress() );
|
|
}
|
|
}
|
|
connector.setSecure( true );
|
|
connector.setSecure( true );
|
|
connector.setScheme( "https" );
|
|
connector.setScheme( "https" );
|
|
connector.setAttribute( "SSLEnabled", "true" );
|
|
connector.setAttribute( "SSLEnabled", "true" );
|
|
- connector.setAttribute( "keystoreFile", getKeystoreFile( tomcatConfig ).getAbsolutePath() );
|
|
|
|
- connector.setAttribute( "keystorePass", tomcatConfig.getKeystorePass() );
|
|
|
|
- connector.setAttribute( "keyAlias", KEYSTORE_ALIAS );
|
|
|
|
|
|
+ connector.setAttribute( "keystoreFile", onejarConfig.getKeystoreFile().getAbsolutePath() );
|
|
|
|
+ connector.setAttribute( "keystorePass", onejarConfig.getKeystorePass() );
|
|
|
|
+ connector.setAttribute( "keyAlias", OnejarMain.KEYSTORE_ALIAS );
|
|
connector.setAttribute( "clientAuth", "false" );
|
|
connector.setAttribute( "clientAuth", "false" );
|
|
|
|
|
|
return connector;
|
|
return connector;
|
|
}
|
|
}
|
|
|
|
|
|
- static String getVersion( ) throws TomcatOneJarException
|
|
|
|
|
|
+ static String getVersion( ) throws OnejarException
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- final Class clazz = TomcatOneJarMain.class;
|
|
|
|
|
|
+ final Class clazz = TomcatOnejarRunner.class;
|
|
final String className = clazz.getSimpleName() + ".class";
|
|
final String className = clazz.getSimpleName() + ".class";
|
|
final String classPath = clazz.getResource( className ).toString();
|
|
final String classPath = clazz.getResource( className ).toString();
|
|
if ( !classPath.startsWith( "jar" ) )
|
|
if ( !classPath.startsWith( "jar" ) )
|
|
@@ -228,11 +225,11 @@ public class TomcatOneJarMain
|
|
}
|
|
}
|
|
catch ( IOException e )
|
|
catch ( IOException e )
|
|
{
|
|
{
|
|
- throw new TomcatOneJarException( "error reading internal version info: " + e.getMessage() );
|
|
|
|
|
|
+ throw new OnejarException( "error reading internal version info: " + e.getMessage() );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private static void purgeDirectory( final Path rootPath )
|
|
|
|
|
|
+ private void purgeDirectory( final Path rootPath )
|
|
throws IOException
|
|
throws IOException
|
|
{
|
|
{
|
|
System.out.println( "purging work directory: " + rootPath );
|
|
System.out.println( "purging work directory: " + rootPath );
|
|
@@ -244,54 +241,78 @@ public class TomcatOneJarMain
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- static void out( final String output )
|
|
|
|
|
|
+ void out( final String output )
|
|
{
|
|
{
|
|
- System.out.println( output );
|
|
|
|
|
|
+ onejarMain.out( output );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- static void generatePwmKeystore( final TomcatConfig tomcatConfig )
|
|
|
|
|
|
+ void generatePwmKeystore( final OnejarConfig onejarConfig )
|
|
throws IOException, ClassNotFoundException, IllegalAccessException, NoSuchMethodException, InvocationTargetException
|
|
throws IOException, ClassNotFoundException, IllegalAccessException, NoSuchMethodException, InvocationTargetException
|
|
{
|
|
{
|
|
- final File warPath = getWarFolder( tomcatConfig );
|
|
|
|
- final String keystoreFile = getKeystoreFile( tomcatConfig ).getAbsolutePath();
|
|
|
|
|
|
+ final File warPath = onejarConfig.getWarFolder();
|
|
|
|
+ final String keystoreFile = onejarConfig.getKeystoreFile().getAbsolutePath();
|
|
final File webInfPath = new File( warPath.getAbsolutePath() + File.separator + "WEB-INF" + File.separator + "lib" );
|
|
final File webInfPath = new File( warPath.getAbsolutePath() + File.separator + "WEB-INF" + File.separator + "lib" );
|
|
final File[] jarFiles = webInfPath.listFiles();
|
|
final File[] jarFiles = webInfPath.listFiles();
|
|
final List<URL> jarURLList = new ArrayList<>();
|
|
final List<URL> jarURLList = new ArrayList<>();
|
|
- for ( final File jarFile : jarFiles )
|
|
|
|
|
|
+ if ( jarFiles != null )
|
|
{
|
|
{
|
|
- jarURLList.add( jarFile.toURI().toURL() );
|
|
|
|
|
|
+ for ( final File jarFile : jarFiles )
|
|
|
|
+ {
|
|
|
|
+ jarURLList.add( jarFile.toURI().toURL() );
|
|
|
|
+ }
|
|
}
|
|
}
|
|
final URLClassLoader classLoader = URLClassLoader.newInstance( jarURLList.toArray( new URL[ jarURLList.size() ] ) );
|
|
final URLClassLoader classLoader = URLClassLoader.newInstance( jarURLList.toArray( new URL[ jarURLList.size() ] ) );
|
|
final Class pwmMainClass = classLoader.loadClass( "password.pwm.util.cli.MainClass" );
|
|
final Class pwmMainClass = classLoader.loadClass( "password.pwm.util.cli.MainClass" );
|
|
final Method mainMethod = pwmMainClass.getMethod( "main", String[].class );
|
|
final Method mainMethod = pwmMainClass.getMethod( "main", String[].class );
|
|
final String[] arguments = new String[] {
|
|
final String[] arguments = new String[] {
|
|
- "-applicationPath=" + tomcatConfig.getApplicationPath().getAbsolutePath(),
|
|
|
|
|
|
+ "-applicationPath=" + onejarConfig.getApplicationPath().getAbsolutePath(),
|
|
"ExportHttpsKeyStore",
|
|
"ExportHttpsKeyStore",
|
|
keystoreFile,
|
|
keystoreFile,
|
|
- KEYSTORE_ALIAS,
|
|
|
|
- tomcatConfig.getKeystorePass(),
|
|
|
|
|
|
+ OnejarMain.KEYSTORE_ALIAS,
|
|
|
|
+ onejarConfig.getKeystorePass(),
|
|
};
|
|
};
|
|
|
|
|
|
mainMethod.invoke( null, ( Object ) arguments );
|
|
mainMethod.invoke( null, ( Object ) arguments );
|
|
classLoader.close();
|
|
classLoader.close();
|
|
}
|
|
}
|
|
|
|
|
|
- static void setupEnv( final TomcatConfig tomcatConfig )
|
|
|
|
|
|
+ void setupEnv( final OnejarConfig onejarConfig )
|
|
{
|
|
{
|
|
final String envVarPrefix = Resource.envVarPrefix.getValue();
|
|
final String envVarPrefix = Resource.envVarPrefix.getValue();
|
|
- System.setProperty( envVarPrefix + "_APPLICATIONPATH", tomcatConfig.getApplicationPath().getAbsolutePath() );
|
|
|
|
|
|
+ System.setProperty( envVarPrefix + "_APPLICATIONPATH", onejarConfig.getApplicationPath().getAbsolutePath() );
|
|
System.setProperty( envVarPrefix + "_APPLICATIONFLAGS", "ManageHttps" );
|
|
System.setProperty( envVarPrefix + "_APPLICATIONFLAGS", "ManageHttps" );
|
|
- System.setProperty( envVarPrefix + "_APPLICATIONPARAMFILE", getPwmAppPropertiesFile( tomcatConfig ).getAbsolutePath() );
|
|
|
|
|
|
+ System.setProperty( envVarPrefix + "_APPLICATIONPARAMFILE", onejarConfig.getPwmAppPropertiesFile().getAbsolutePath() );
|
|
}
|
|
}
|
|
|
|
|
|
- static void outputPwmAppProperties( final TomcatConfig tomcatConfig ) throws IOException
|
|
|
|
|
|
+ void outputPwmAppProperties( final OnejarConfig onejarConfig ) throws IOException
|
|
{
|
|
{
|
|
final Properties properties = new Properties();
|
|
final Properties properties = new Properties();
|
|
- properties.setProperty( "AutoExportHttpsKeyStoreFile", getKeystoreFile( tomcatConfig ).getAbsolutePath() );
|
|
|
|
- properties.setProperty( "AutoExportHttpsKeyStorePassword", tomcatConfig.getKeystorePass() );
|
|
|
|
- properties.setProperty( "AutoExportHttpsKeyStoreAlias", KEYSTORE_ALIAS );
|
|
|
|
- final File propFile = getPwmAppPropertiesFile( tomcatConfig );
|
|
|
|
- properties.store( new FileWriter( propFile ), "auto-generated file" );
|
|
|
|
|
|
+ properties.setProperty( "AutoExportHttpsKeyStoreFile", onejarConfig.getKeystoreFile().getAbsolutePath() );
|
|
|
|
+ properties.setProperty( "AutoExportHttpsKeyStorePassword", onejarConfig.getKeystorePass() );
|
|
|
|
+ properties.setProperty( "AutoExportHttpsKeyStoreAlias", OnejarMain.KEYSTORE_ALIAS );
|
|
|
|
+ final File propFile = onejarConfig.getPwmAppPropertiesFile( );
|
|
|
|
+ try ( Writer writer = new OutputStreamWriter( new FileOutputStream( propFile ), StandardCharsets.UTF_8 ) )
|
|
|
|
+ {
|
|
|
|
+ properties.store( writer, "auto-generated file" );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void copyFileAndReplace(
|
|
|
|
+ final String srcPath,
|
|
|
|
+ final String destPath,
|
|
|
|
+ final String rootcontext
|
|
|
|
+ )
|
|
|
|
+ throws IOException
|
|
|
|
+ {
|
|
|
|
+ try ( InputStream inputStream = TomcatOnejarRunner.class.getClassLoader().getResourceAsStream( srcPath ) )
|
|
|
|
+ {
|
|
|
|
+ try ( BufferedReader reader = new BufferedReader( new InputStreamReader( inputStream, "UTF8" ) ) )
|
|
|
|
+ {
|
|
|
|
+ String contents = reader.lines().collect( Collectors.joining( "\n" ) );
|
|
|
|
+ contents = contents.replace( "[[[ROOT_CONTEXT]]]", rootcontext );
|
|
|
|
+ Files.write( Paths.get( destPath ), contents.getBytes( "UTF8" ) );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|