Skip to content

Commit

Permalink
mojohaus#42: wrapper.conf creation - jvmSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
sparsick committed Oct 31, 2019
1 parent 9de18ac commit b3f3ca0
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 11 deletions.
4 changes: 4 additions & 0 deletions appassembler-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@
<directory>target/dependency/yajsw-binaries/yajsw-stable-12.14/bin</directory>
<targetPath>org/codehaus/mojo/appassembler/daemon/yajsw/bin</targetPath>
</resource>
<resource>
<directory>target/dependency/yajsw-binaries/yajsw-stable-12.14/conf</directory>
<targetPath>org/codehaus/mojo/appassembler/daemon/yajsw/conf</targetPath>
</resource>
<resource>
<directory>target/dependency/yajsw-binaries/yajsw-stable-12.14/lib</directory>
<targetPath>org/codehaus/mojo/appassembler/daemon/yajsw/lib</targetPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@
import org.codehaus.mojo.appassembler.daemon.DaemonGenerator;
import org.codehaus.mojo.appassembler.daemon.DaemonGeneratorException;
import org.codehaus.mojo.appassembler.model.Daemon;
import org.codehaus.mojo.appassembler.util.FormattedProperties;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.IOUtil;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;

/**
* @author Sandra Parsick
Expand Down Expand Up @@ -103,12 +111,69 @@ public void generate( DaemonGenerationRequest request ) throws DaemonGeneratorEx

File outputDirectory = new File( request.getOutputDirectory(), daemon.getId() );

writeWrapperConfFile(outputDirectory, daemon);

writeScripts(outputDirectory);
writeLibraries(outputDirectory);


}

private void writeWrapperConfFile(File outputDirectory, Daemon daemon) throws DaemonGeneratorException
{
InputStream in = this.getClass().getResourceAsStream( "conf/wrapper.conf.default" );

if ( in == null )
{
throw new DaemonGeneratorException( "Could not load template." );
}

FormattedProperties confFile = new FormattedProperties();

try
{
confFile.read( in );
}
catch ( IOException e )
{
throw new DaemonGeneratorException( "Error reading template: " + e.getMessage(), e );
}
finally
{
IOUtil.close( in );
}

if( daemon.getJvmSettings() != null)
{
confFile.setProperty("wrapper.java.initmemory", daemon.getJvmSettings().getInitialMemorySize());
confFile.setProperty("wrapper.java.maxmemory", daemon.getJvmSettings().getMaxMemorySize());
createAdditional(daemon, confFile);
}


ByteArrayOutputStream string = new ByteArrayOutputStream();
confFile.save( string );

writeFile(new File(outputDirectory, "conf/wrapper.conf"), new ByteArrayInputStream( string.toByteArray() ));

}

private static void createAdditional( Daemon daemon, FormattedProperties confFile )
{
int count = 1;
for (Iterator i = daemon.getJvmSettings().getSystemProperties().iterator(); i.hasNext(); count++ )
{
String systemProperty = (String) i.next();
confFile.setProperty( "wrapper.java.additional." + count, "-D" + systemProperty );
}
for ( Iterator i = daemon.getJvmSettings().getExtraArguments().iterator(); i.hasNext(); count++ )
{
String extraArgument = (String) i.next();
confFile.setProperty( "wrapper.java.additional." + count, extraArgument );
}
}


private void writeScripts(File outputDirectory) throws DaemonGeneratorException
{
for (String batScriptName : BAT_SCRIPTS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public void testDefaultYAJSWFilesIfNoGeneratorConfigurationsIsSet()
"target/output-5-yajsw" );

File yajswDir = getTestFile( "target/output-5-yajsw/app" );
// File wrapper = new File( yajswDir, "conf/wrapper.conf" );
//
// assertTrue( "Wrapper file is missing: " + wrapper.getAbsolutePath(), wrapper.isFile() );
//
// assertEquals( normalizedLineEndingRead( "src/test/resources/org/codehaus/mojo/appassembler/daemon/yajsw/wrapper-5.conf" ),
// FileUtils.fileRead( wrapper ) );
File wrapper = new File( yajswDir, "conf/wrapper.conf" );

assertTrue( "Wrapper file is missing: " + wrapper.getAbsolutePath(), wrapper.isFile() );

assertEquals( normalizedLineEndingRead( "src/test/resources/org/codehaus/mojo/appassembler/daemon/yajsw/wrapper-5.conf" ),
FileUtils.fileRead( wrapper ) );
//
// File shellScript = new File( yajswDir, "bin/app" );
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ wrapper.working.dir=
# per default these are placed in jna.tmpdir.
# jna.tmpdir is set in setenv batch file to <yajsw>/tmp
#********************************************************************
wrapper.tmp.path = ${jna_tmpdir}
wrapper.tmp.path=${jna_tmpdir}


#********************************************************************
Expand Down Expand Up @@ -87,26 +87,31 @@ wrapper.java.app.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
# needed starting from 1
# YAJSW: all libs required by YAJSW are in the manifest of the wrapper.jar -> only classpath of your application is required
wrapper.java.classpath.1=./wrapper.jar
wrapper.java.classpath.2=${wrapper.working.dir}/org/codehaus/mojo/appassembler/project-5/1.0-SNAPSHOT/project-1-1.0-SNAPSHOT.jar
wrapper.java.classpath.3=${wrapper.working.dir}/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
wrapper.java.classpath.2=${wrapper.working.dir}/lib/org/codehaus/mojo/appassembler/project-5/1.0-SNAPSHOT/project-1-1.0-SNAPSHOT.jar
wrapper.java.classpath.3=${wrapper.working.dir}/lib//org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar

# Java Library Path
# YAJSW: required dll are encapsulated in jar files -> only library path of your application required
# wrapper.java.library.path.1=../lib

# Java Additional Parameters
#wrapper.java.additional.1=
wrapper.java.additional.1=-Dfoo=bar
wrapper.java.additional.2=-Dbar=foo
wrapper.java.additional.3=-splash:niceImage.png

# Initial Java Heap Size (in MB)
# alternative for wrapper.java.additional.<n>=-Xms
#wrapper.java.initmemory=3
wrapper.java.initmemory=345

# % of total RAM
#wrapper.java.initmemory.relative=10

# Maximum Java Heap Size (in MB)
# alternative for wrapper.java.additional.<n>=-Xmx
#wrapper.java.maxmemory=64
wrapper.java.maxmemory=234

# % of total RAM
#wrapper.java.maxmemory.relative=30
Expand Down Expand Up @@ -215,11 +220,11 @@ wrapper.daemon.run_level_dir=${if (new File('/etc/rc0.d').exists()) return '/etc
# Wrapper System Tray Properties
#********************************************************************
# enable system tray
wrapper.tray = true
wrapper.tray=true

# TCP/IP port. If none is defined multicast discovery is used to find the port
# Set the port in case multicast is not possible.
wrapper.tray.port = 15002
wrapper.tray.port=15002

# icon file to use, per default a console icon is used
#wrapper.tray.icon=
Expand Down

0 comments on commit b3f3ca0

Please sign in to comment.