Skip to content

Commit

Permalink
mojohaus#42: wrapper.conf creation - classpath
Browse files Browse the repository at this point in the history
  • Loading branch information
sparsick committed Nov 1, 2019
1 parent 2620913 commit 85758f6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@
package org.codehaus.mojo.appassembler.daemon.yajsw;

import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.project.MavenProject;
import org.codehaus.mojo.appassembler.daemon.DaemonGenerationRequest;
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.DependencyFactory;
import org.codehaus.mojo.appassembler.util.FormattedProperties;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.IOUtil;
Expand Down Expand Up @@ -111,15 +115,15 @@ public void generate( DaemonGenerationRequest request ) throws DaemonGeneratorEx

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

writeWrapperConfFile(outputDirectory, daemon);
writeWrapperConfFile(outputDirectory, daemon, request);

writeScripts(outputDirectory);
writeLibraries(outputDirectory);


}

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

Expand Down Expand Up @@ -151,6 +155,7 @@ private void writeWrapperConfFile(File outputDirectory, Daemon daemon) throws Da
confFile.setProperty("wrapper.java.maxmemory", daemon.getJvmSettings().getMaxMemorySize());
createAdditional(daemon, confFile);
}
createClasspath(daemon, request, confFile);


ByteArrayOutputStream string = new ByteArrayOutputStream();
Expand All @@ -160,7 +165,36 @@ private void writeWrapperConfFile(File outputDirectory, Daemon daemon) throws Da

}

private static void createAdditional( Daemon daemon, FormattedProperties confFile )
private void createClasspath(Daemon daemon, DaemonGenerationRequest request, FormattedProperties confFile)
{
final String wrapperClassPathPrefix = "wrapper.java.classpath.";
final String wrapperWorkingDirVariable = "${wrapper.working.dir}/";
final String repositoryName = daemon.getRepositoryName() + "/";

int counter = 1;
confFile.setProperty( wrapperClassPathPrefix + counter++, wrapperWorkingDirVariable + "wrapper.jar" );

MavenProject project = request.getMavenProject();
ArtifactRepositoryLayout layout = request.getRepositoryLayout();

confFile.setProperty( wrapperClassPathPrefix + counter++, wrapperWorkingDirVariable + repositoryName
+ DependencyFactory.create( project.getArtifact(), layout, true,
request.getOutputFileNameMapping() ).getRelativePath() );

Iterator j = project.getRuntimeArtifacts().iterator();
while ( j.hasNext() )
{
Artifact artifact = (Artifact) j.next();

confFile.setProperty( wrapperClassPathPrefix + counter, wrapperWorkingDirVariable + repositoryName
+ DependencyFactory.create( artifact, layout, daemon.isUseTimestampInSnapshotFileName(),
request.getOutputFileNameMapping() ).getRelativePath() );
counter++;
}

}

private void createAdditional( Daemon daemon, FormattedProperties confFile )
{
int count = 1;
for (Iterator i = daemon.getJvmSettings().getSystemProperties().iterator(); i.hasNext(); count++ )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import java.io.File;
import java.io.IOException;
import java.util.List;

import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;
import org.codehaus.mojo.appassembler.daemon.AbstractDaemonGeneratorTest;
Expand Down Expand Up @@ -38,25 +40,7 @@ public void testDefaultYAJSWFilesIfNoGeneratorConfigurationsIsSet()
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" );
//
// assertTrue( "Shell script file is missing: " + shellScript.getAbsolutePath(), shellScript.isFile() );
//
// assertEquals( FileUtils.fileRead( getTestFile( "src/test/resources/org/codehaus/mojo/appassembler/daemon/jsw/no-generator-configurations-run.sh" ) ),
// FileUtils.fileRead( shellScript ) );
//
// File batchFile = new File( yajswDir, "bin/app.bat" );
//
// assertTrue( "Batch file is missing: " + batchFile.getAbsolutePath(), batchFile.isFile() );
//
// assertEquals( FileUtils.fileRead( getTestFile( "src/test/resources/org/codehaus/mojo/appassembler/daemon/jsw/no-generator-configurations-run.bat" ) ),
// FileUtils.fileRead( batchFile ) );ore yajsw resources download
//
// assertEquals( ( new File( getBasedir()
// + "/target/classes/org/codehaus/mojo/appassembler/daemon/jsw/bin/wrapper-linux-x86-32" ) ).length(),
// ( new File( yajswDir, "bin/wrapper-linux-x86-32" ) ).length() );
trimWhitespacePerLine(wrapper));

assertFileExists(yajswDir, "bat/runConsole.bat");
assertFileExists(yajswDir, "bat/startService.bat");
Expand Down Expand Up @@ -86,6 +70,18 @@ public void testDefaultYAJSWFilesIfNoGeneratorConfigurationsIsSet()
assertFileExists( yajswDir, "lib/extended/velocity/velocity-1.7.jar");
}

private String trimWhitespacePerLine(File wrapper) throws IOException {
List<String> readLines = org.apache.commons.io.FileUtils.readLines(wrapper);

StringBuilder file = new StringBuilder();
for(String line : readLines) {
String trimmedLine = line.trim();
file.append(trimmedLine);
file.append("\n");
}
return file.toString();
}

private String normalizedLineEndingRead( String file )
throws IOException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ wrapper.java.app.mainclass=com.westerngeco.example.App
# Java Classpath (include wrapper.jar) Add class path elements as
# 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}/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
#wrapper.java.classpath.1=
wrapper.java.classpath.1=${wrapper.working.dir}/wrapper.jar
wrapper.java.classpath.2=${wrapper.working.dir}/lib/org/codehaus/mojo/appassembler/project-1/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
Expand Down

0 comments on commit 85758f6

Please sign in to comment.