| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.codehaus.mojo.nbm; |
| 18 | |
|
| 19 | |
import java.io.File; |
| 20 | |
import java.util.List; |
| 21 | |
import java.util.ArrayList; |
| 22 | |
import org.apache.maven.plugin.AbstractMojo; |
| 23 | |
import org.apache.maven.plugin.MojoExecutionException; |
| 24 | |
import org.apache.maven.plugin.MojoFailureException; |
| 25 | |
import org.apache.maven.plugins.annotations.Mojo; |
| 26 | |
import org.apache.maven.plugins.annotations.Parameter; |
| 27 | |
import org.apache.maven.plugins.annotations.ResolutionScope; |
| 28 | |
import org.apache.maven.project.MavenProject; |
| 29 | |
import org.codehaus.plexus.util.Os; |
| 30 | |
import org.codehaus.plexus.util.cli.CommandLineUtils; |
| 31 | |
import org.codehaus.plexus.util.cli.Commandline; |
| 32 | |
import org.codehaus.plexus.util.cli.StreamConsumer; |
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
@Mojo(name="run-platform", requiresDependencyResolution= ResolutionScope.RUNTIME ) |
| 41 | 0 | public class RunPlatformAppMojo |
| 42 | |
extends AbstractMojo |
| 43 | |
{ |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
@Parameter(required=true, property="netbeans.branding.token") |
| 49 | |
protected String brandingToken; |
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
@Parameter(required=true, defaultValue="${project.build.directory}") |
| 54 | |
private File outputDirectory; |
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
@Parameter(required=true, defaultValue="${project.build.directory}/userdir", property="netbeans.userdir") |
| 60 | |
protected File netbeansUserdir; |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
@Parameter(property="netbeans.run.params") |
| 66 | |
protected String additionalArguments; |
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
@Parameter(property="netbeans.run.params.debug") |
| 76 | |
protected String debugAdditionalArguments; |
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
@Parameter(required=true, readonly=true, property="project") |
| 83 | |
private MavenProject project; |
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
public void execute() |
| 91 | |
throws MojoExecutionException, MojoFailureException |
| 92 | |
{ |
| 93 | 0 | if ( !"nbm-application".equals( project.getPackaging() ) ) |
| 94 | |
{ |
| 95 | 0 | throw new MojoFailureException( "The nbm:run-platform goal shall be used within a NetBeans Application project only ('nbm-application' packaging)"); |
| 96 | |
} |
| 97 | |
|
| 98 | 0 | netbeansUserdir.mkdirs(); |
| 99 | |
|
| 100 | 0 | File appbasedir = new File( outputDirectory, brandingToken ); |
| 101 | |
|
| 102 | 0 | if ( !appbasedir.exists() ) |
| 103 | |
{ |
| 104 | 0 | throw new MojoExecutionException( "The directory that shall contain built application, doesn't exist (" |
| 105 | |
+ appbasedir.getAbsolutePath() + ")\n Please invoke 'mvn install' on the project first" ); |
| 106 | |
} |
| 107 | |
|
| 108 | 0 | boolean windows = Os.isFamily( "windows" ); |
| 109 | |
|
| 110 | 0 | Commandline cmdLine = new Commandline(); |
| 111 | |
File exec; |
| 112 | 0 | if ( windows ) |
| 113 | |
{ |
| 114 | 0 | exec = new File( appbasedir, "bin" + brandingToken + "_w.exe" ); |
| 115 | 0 | if ( !exec.exists() ) |
| 116 | |
{ |
| 117 | 0 | exec = new File( appbasedir, "bin\\" + brandingToken + ".exe" ); |
| 118 | |
|
| 119 | 0 | String jdkHome = System.getenv( "JAVA_HOME" ); |
| 120 | 0 | if ( jdkHome != null ) |
| 121 | |
{ |
| 122 | 0 | if ( new File( jdkHome, "jre\\lib\\amd64\\jvm.cfg" ).exists() ) |
| 123 | |
{ |
| 124 | 0 | File exec64 = new File( appbasedir, "bin\\" + brandingToken + "64.exe" ); |
| 125 | 0 | if ( exec64.isFile() ) |
| 126 | |
{ |
| 127 | 0 | exec = exec64; |
| 128 | |
} |
| 129 | |
} |
| 130 | |
} |
| 131 | 0 | cmdLine.addArguments( new String[] { "--console", "suppress" } ); |
| 132 | 0 | } |
| 133 | |
} |
| 134 | |
else |
| 135 | |
{ |
| 136 | 0 | exec = new File( appbasedir, "bin/" + brandingToken ); |
| 137 | |
} |
| 138 | |
|
| 139 | 0 | cmdLine.setExecutable( exec.getAbsolutePath() ); |
| 140 | |
|
| 141 | |
try |
| 142 | |
{ |
| 143 | |
|
| 144 | 0 | List<String> args = new ArrayList<String>(); |
| 145 | 0 | args.add( "--userdir" ); |
| 146 | 0 | args.add( netbeansUserdir.getAbsolutePath() ); |
| 147 | 0 | args.add( "-J-Dnetbeans.logger.console=true" ); |
| 148 | 0 | args.add( "-J-ea" ); |
| 149 | 0 | args.add( "--branding" ); |
| 150 | 0 | args.add( brandingToken ); |
| 151 | |
|
| 152 | |
|
| 153 | 0 | if ( System.getenv( "JAVA_HOME" ) != null ) |
| 154 | |
{ |
| 155 | 0 | args.add( "--jdkhome" ); |
| 156 | 0 | args.add( System.getenv( "JAVA_HOME" ) ); |
| 157 | |
} |
| 158 | |
|
| 159 | 0 | cmdLine.addArguments( args.toArray( new String[0] ) ); |
| 160 | 0 | cmdLine.addArguments( CommandLineUtils.translateCommandline( additionalArguments ) ); |
| 161 | 0 | cmdLine.addArguments( CommandLineUtils.translateCommandline( getDebugAdditionalArguments() ) ); |
| 162 | 0 | getLog().info( "Executing: " + cmdLine.toString() ); |
| 163 | 0 | StreamConsumer out = new StreamConsumer() |
| 164 | 0 | { |
| 165 | |
|
| 166 | |
public void consumeLine( String line ) |
| 167 | |
{ |
| 168 | 0 | getLog().info( line ); |
| 169 | 0 | } |
| 170 | |
}; |
| 171 | 0 | CommandLineUtils.executeCommandLine( cmdLine, out, out ); |
| 172 | |
} |
| 173 | 0 | catch ( Exception e ) |
| 174 | |
{ |
| 175 | 0 | throw new MojoExecutionException( "Failed executing NetBeans", e ); |
| 176 | 0 | } |
| 177 | 0 | } |
| 178 | |
|
| 179 | |
private String getDebugAdditionalArguments() |
| 180 | |
{ |
| 181 | 0 | if ( "true".equals( debugAdditionalArguments ) ) |
| 182 | |
{ |
| 183 | 0 | return "-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"; |
| 184 | |
} |
| 185 | 0 | return debugAdditionalArguments; |
| 186 | |
} |
| 187 | |
} |