Skip to content

Commit

Permalink
mojohaus#42: writing yajsw libs
Browse files Browse the repository at this point in the history
  • Loading branch information
sparsick committed Oct 30, 2019
1 parent de8a00e commit 57ce93c
Show file tree
Hide file tree
Showing 4 changed files with 534 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/**
*
* The MIT License
*
* Copyright 2006-2016 The MojoHaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.codehaus.mojo.appassembler.daemon.yajsw;

import org.apache.commons.io.FileUtils;
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.plexus.logging.AbstractLogEnabled;

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

/**
* @author Sandra Parsick
* @version $Id$
* @plexus.component role-hint="yajsw"
*/
public class YetAnotherJavaServiceWrapperDaemonGenerator
extends AbstractLogEnabled
implements DaemonGenerator
{

private static List<String> CORE_LIBS = new ArrayList<String>()
{
{
add("commons/commons-cli-1.4.jar");
add("commons/commons-collections-3.2.2.jar");
add("commons/commons-configuration2-2.3.jar");
add("commons/commons-io-2.6.jar");
add("commons/commons-lang3-3.8.1.jar");
add("commons/commons-lang-2.6.jar");
add("commons/commons-logging-1.1.jar");
add("commons/commons-text-1.6.jar");
add("commons/commons-vfs2-2.2.jar");
add("jna/jna-5.3.1.jar");
add("jna/jna-platform-5.3.1.jar");
add("netty/netty-all-4.1.36.Final.jar");
add("yajsw/ahessian.jar");
}
};

private static List<String> EXTENDED_LIBS = new ArrayList<String>()
{
{
add("velocity/velocity-1.7.jar");
}
};


@Override
public void generate( DaemonGenerationRequest request ) throws DaemonGeneratorException
{
Daemon daemon = request.getDaemon();

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

writeLibraries(outputDirectory);


}

private void writeLibraries(File outputDirectory) throws DaemonGeneratorException
{
InputStream wrapperJar = this.getClass().getResourceAsStream("wrapper.jar");
if(wrapperJar == null )
{
throw new DaemonGeneratorException("Cannot load " + wrapperJar);
}
writeFile(new File(outputDirectory, "wrapper.jar"), wrapperJar);

InputStream wrapperAppJar = this.getClass().getResourceAsStream("wrapperApp.jar");
if(wrapperAppJar == null )
{
throw new DaemonGeneratorException("Cannot load " + wrapperAppJar);
}
writeFile(new File(outputDirectory, "wrapperApp.jar"), wrapperAppJar);


for (String core: CORE_LIBS)
{
InputStream coreLib = this.getClass().getResourceAsStream("lib/core/" + core);
if(coreLib == null )
{
throw new DaemonGeneratorException("Cannot load " + core);
}
writeFile(new File(outputDirectory, "lib/core/" + core), coreLib);
}

for(String extended : EXTENDED_LIBS)
{
InputStream extendedLib = this.getClass().getResourceAsStream("lib/extended/" + extended);
if(extendedLib == null )
{
throw new DaemonGeneratorException("Cannot load " + extended);
}
writeFile(new File(outputDirectory, "lib/extended/" + extended), extendedLib);
}
}

private static void writeFile( File outputFile, InputStream inputStream )
throws DaemonGeneratorException
{
try
{
FileUtils.copyInputStreamToFile(inputStream, outputFile);
}
catch ( IOException e )
{
throw new DaemonGeneratorException( "Error writing output file: " + outputFile.getAbsolutePath(), e );
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
public class JavaServiceWrapperDaemonGeneratorTest
extends AbstractDaemonGeneratorTest
{

public void testGenerationWithAllInfoInDescriptor()
throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.codehaus.mojo.appassembler.daemon.yajsw;

import java.io.File;
import java.io.IOException;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;
import org.codehaus.mojo.appassembler.daemon.AbstractDaemonGeneratorTest;
import static org.codehaus.plexus.PlexusTestCase.getBasedir;
import static org.codehaus.plexus.PlexusTestCase.getTestFile;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringUtils;
import org.junit.Ignore;
import org.junit.Test;

/**
* @author Sandra Parsick
* @version $Id$
*/

public class YetAnotherJavaServiceWrapperDaemonGeneratorTest
extends AbstractDaemonGeneratorTest
{

public void testDefaultYAJSWFilesIfNoGeneratorConfigurationsIsSet()
throws Exception
{
runTest( "yajsw", "src/test/resources/project-5/pom.xml", "src/test/resources/project-5/descriptor.xml",
"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 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 ) );
//
// 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() );

assertFileExists( yajswDir, "wrapper.jar" );
assertFileExists( yajswDir, "wrapperApp.jar" );
assertFileExists( yajswDir, "lib/core/commons/commons-cli-1.4.jar" );
assertFileExists( yajswDir, "lib/core/commons/commons-collections-3.2.2.jar" );
assertFileExists( yajswDir, "lib/core/commons/commons-configuration2-2.3.jar" );
assertFileExists( yajswDir, "lib/core/commons/commons-io-2.6.jar" );
assertFileExists( yajswDir, "lib/core/commons/commons-lang3-3.8.1.jar" );
assertFileExists( yajswDir, "lib/core/commons/commons-lang-2.6.jar" );
assertFileExists( yajswDir, "lib/core/commons/commons-logging-1.1.jar" );
assertFileExists( yajswDir, "lib/core/commons/commons-text-1.6.jar" );
assertFileExists( yajswDir, "lib/core/commons/commons-vfs2-2.2.jar" );
assertFileExists( yajswDir, "lib/core/jna/jna-5.3.1.jar");
assertFileExists( yajswDir, "lib/core/jna/jna-platform-5.3.1.jar");
assertFileExists( yajswDir, "lib/core/jna/jna-platform-5.3.1.jar");
assertFileExists( yajswDir, "lib/core/netty/netty-all-4.1.36.Final.jar");
assertFileExists( yajswDir, "lib/core/yajsw/ahessian.jar");
assertFileExists( yajswDir, "lib/extended/velocity/velocity-1.7.jar");
}

private String normalizedLineEndingRead( String file )
throws IOException
{
String expected = FileUtils.fileRead( getTestFile( file ) );
return StringUtils.unifyLineSeparators( expected );
}

private static void assertFileExists( File jswDir, String file )
{
File wrapperJar = new File( jswDir, file );

assertTrue( "File is missing: " + wrapperJar.getAbsolutePath(), wrapperJar.isFile() );
}

private static void assertFileNotExists( File jswDir, String file )
{
File wrapperJar = new File( jswDir, file );

assertFalse( "File should be missing: " + wrapperJar.getAbsolutePath(), wrapperJar.isFile() );
}

}
Loading

0 comments on commit 57ce93c

Please sign in to comment.