-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#42: init implementation for yajsw #99
Open
sparsick
wants to merge
4
commits into
mojohaus:master
Choose a base branch
from
sparsick:issue-#42
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
312 changes: 312 additions & 0 deletions
312
.../codehaus/mojo/appassembler/daemon/yajsw/YetAnotherJavaServiceWrapperDaemonGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,312 @@ | ||
/** | ||
* | ||
* 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.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; | ||
|
||
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 | ||
* @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"); | ||
add("yajsw/hessian4.jar"); | ||
add("groovy/groovy-2.5.7.jar"); | ||
add("groovy/groovy-patch.jar"); | ||
} | ||
}; | ||
|
||
private static List<String> BAT_SCRIPTS = new ArrayList<String>() | ||
{ | ||
{ | ||
add("installService.bat"); | ||
add("runConsole.bat"); | ||
add("startService.bat"); | ||
add("stopService.bat"); | ||
add("uninstallService.bat"); | ||
add("setenv.bat"); | ||
add("wrapper.bat"); | ||
} | ||
}; | ||
|
||
private static List<String> SHELL_SCRIPTS = new ArrayList<String>() | ||
{ | ||
{ | ||
add("installDaemon.sh"); | ||
add("runConsole.sh"); | ||
add("startDaemon.sh"); | ||
add("stopDaemon.sh"); | ||
add("uninstallDaemon.sh"); | ||
add("setenv.sh"); | ||
add("wrapper.sh"); | ||
add("installDaemonNoPriv.sh"); | ||
add("uninstallDaemonNoPriv.sh"); | ||
add("startDaemonNoPriv.sh"); | ||
add("stopDaemonNoPriv.sh"); | ||
} | ||
}; | ||
|
||
private static List<String> GROOVY_SCRIPTS = new ArrayList<String>() | ||
{ | ||
{ | ||
add("trayMessage.gv"); | ||
} | ||
}; | ||
|
||
private static List<String> TEMPLATES = new ArrayList<String>() | ||
{ | ||
{ | ||
add("daemon.vm"); | ||
} | ||
}; | ||
|
||
@Override | ||
public void generate( DaemonGenerationRequest request ) throws DaemonGeneratorException | ||
{ | ||
Daemon daemon = request.getDaemon(); | ||
File outputDirectory = new File( request.getOutputDirectory(), daemon.getId() ); | ||
writeWrapperConfFile(outputDirectory, daemon, request); | ||
writeScripts(outputDirectory); | ||
writeLibraries(outputDirectory); | ||
} | ||
|
||
private void writeWrapperConfFile(File outputDirectory, Daemon daemon, DaemonGenerationRequest request) 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 ); | ||
} | ||
|
||
confFile.setProperty("wrapper.java.app.mainclass", daemon.getMainClass()); | ||
confFile.setProperty("wrapper.working.dir", "${wrapper_home}"); | ||
|
||
if( daemon.getJvmSettings() != null) | ||
{ | ||
confFile.setProperty("wrapper.java.initmemory", daemon.getJvmSettings().getInitialMemorySize()); | ||
confFile.setProperty("wrapper.java.maxmemory", daemon.getJvmSettings().getMaxMemorySize()); | ||
createAdditional(daemon, confFile); | ||
} | ||
createClasspath(daemon, request, confFile); | ||
|
||
|
||
ByteArrayOutputStream string = new ByteArrayOutputStream(); | ||
confFile.save( string ); | ||
|
||
writeFile(new File(outputDirectory, "conf/wrapper.conf"), new ByteArrayInputStream( string.toByteArray() )); | ||
|
||
} | ||
|
||
private void createClasspath(Daemon daemon, DaemonGenerationRequest request, FormattedProperties confFile) | ||
{ | ||
final String wrapperClassPathPrefix = "wrapper.java.classpath."; | ||
final String wrapperHome = "${wrapper_home}/"; | ||
final String repositoryName = daemon.getRepositoryName() + "/"; | ||
|
||
int counter = 1; | ||
confFile.setProperty( wrapperClassPathPrefix + counter++, wrapperHome + "wrapper.jar" ); | ||
|
||
MavenProject project = request.getMavenProject(); | ||
ArtifactRepositoryLayout layout = request.getRepositoryLayout(); | ||
|
||
confFile.setProperty( wrapperClassPathPrefix + counter++, wrapperHome + 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, wrapperHome + 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++ ) | ||
{ | ||
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) | ||
{ | ||
String batScriptPath = "bat/" + batScriptName; | ||
InputStream batScript = createInputStream(batScriptPath); | ||
writeFile(new File(outputDirectory, batScriptPath), batScript); | ||
} | ||
|
||
for(String shellScriptName : SHELL_SCRIPTS) | ||
{ | ||
String shellScriptPath = "bin/" + shellScriptName; | ||
InputStream shellScript = createInputStream(shellScriptPath); | ||
writeFile(new File(outputDirectory, shellScriptPath), shellScript); | ||
} | ||
|
||
for(String groovyScriptName : GROOVY_SCRIPTS) | ||
{ | ||
String groovyScriptPath = "scripts/" + groovyScriptName; | ||
InputStream groovyScript = createInputStream(groovyScriptPath); | ||
writeFile(new File(outputDirectory, groovyScriptPath), groovyScript); | ||
} | ||
|
||
for(String templateScriptName : TEMPLATES) { | ||
String templateScriptPath = "templates/" + templateScriptName; | ||
InputStream templateScript = createInputStream(templateScriptPath); | ||
writeFile(new File(outputDirectory, templateScriptPath), templateScript); | ||
} | ||
} | ||
|
||
private void writeLibraries(File outputDirectory) throws DaemonGeneratorException | ||
{ | ||
String wrapperJarName = "wrapper.jar"; | ||
InputStream wrapperJar = createInputStream(wrapperJarName); | ||
writeFile(new File(outputDirectory, wrapperJarName), wrapperJar); | ||
|
||
String wrapperAppJarName = "wrapperApp.jar"; | ||
InputStream wrapperAppJar = createInputStream(wrapperAppJarName); | ||
writeFile(new File(outputDirectory, wrapperAppJarName), wrapperAppJar); | ||
|
||
|
||
for (String core: CORE_LIBS) | ||
{ | ||
String coreLibName = "lib/core/" + core; | ||
InputStream coreLib = createInputStream(coreLibName); | ||
writeFile(new File(outputDirectory, coreLibName), coreLib); | ||
} | ||
|
||
for(String extended : EXTENDED_LIBS) | ||
{ | ||
String extendedLibName = "lib/extended/" + extended; | ||
InputStream extendedLib = createInputStream(extendedLibName); | ||
writeFile(new File(outputDirectory, extendedLibName), extendedLib); | ||
} | ||
} | ||
|
||
private InputStream createInputStream(String resourceName) throws DaemonGeneratorException | ||
{ | ||
InputStream resource = this.getClass().getResourceAsStream(resourceName); | ||
if (resource == null) | ||
{ | ||
throw new DaemonGeneratorException("Cannot load " + resourceName); | ||
} | ||
return resource; | ||
} | ||
|
||
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 ); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do all these libraries have to have hardocded versions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, yes, because the version number is part of their name in the path. These libs are part of the YAJSW jar, that I downloaded before. YAJSW needs these libs for working correctly. See also my comment in the issue about the structure of YAJSW
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get what you're saying, but each time there is an upgrade of the
yajsw
library, these lines (here and below) will have to be manually updated. Would it be possible to implement a cleaner way of doing this? For example, you can scan the directories for these jar files by a pattern and resolve the paths this way. I know it's a bit of extra work, but it will save a lot of work in the future when there's upgrades (and you know how error prone these manual "touches" tend to be)...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I completely with you. Maintenance will be very hard with this solution. I would spend more time for a better solution when one of maintainers give feedback whether I run in the right direction with this PR.
IMHO the best solution would be when YAJSW would provide a normal Maven artifact in Maven central.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do they have an issue open for this that would could link to, (or make some noise)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@khmarbaise ,
Any feedback on this pull request?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It exists an elder ticket, but it doesn't address our problem.
@carlspring could you open a ticket and link it in our original issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean. Perhaps it would be easier/clearer for you to do it?