1 /**
2 * The MIT License
3 *
4 * Copyright 2006-2012 The Codehaus.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy of
7 * this software and associated documentation files (the "Software"), to deal in
8 * the Software without restriction, including without limitation the rights to
9 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10 * of the Software, and to permit persons to whom the Software is furnished to do
11 * so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24 package org.codehaus.mojo.appassembler;
25
26 import java.io.File;
27 import java.io.IOException;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.Collections;
31 import java.util.HashSet;
32 import java.util.Iterator;
33 import java.util.List;
34 import java.util.Map;
35 import java.util.Set;
36 import java.util.StringTokenizer;
37
38 import org.apache.maven.artifact.Artifact;
39 import org.apache.maven.artifact.installer.ArtifactInstallationException;
40 import org.apache.maven.artifact.installer.ArtifactInstaller;
41 import org.apache.maven.artifact.repository.ArtifactRepository;
42 import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
43 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
44 import org.apache.maven.plugin.MojoExecutionException;
45 import org.apache.maven.plugin.MojoFailureException;
46 import org.apache.maven.project.MavenProject;
47 import org.codehaus.mojo.appassembler.daemon.DaemonGenerationRequest;
48 import org.codehaus.mojo.appassembler.daemon.DaemonGeneratorException;
49 import org.codehaus.mojo.appassembler.daemon.DaemonGeneratorService;
50 import org.codehaus.mojo.appassembler.daemon.script.Platform;
51 import org.codehaus.mojo.appassembler.model.Classpath;
52 import org.codehaus.mojo.appassembler.model.Dependency;
53 import org.codehaus.mojo.appassembler.model.Directory;
54 import org.codehaus.mojo.appassembler.model.JvmSettings;
55 import org.codehaus.plexus.util.FileUtils;
56 import org.codehaus.plexus.util.StringUtils;
57
58 // @deprecated Use the generate-daemons goal instead
59
60 /**
61 * Assembles the artifacts and generates bin scripts for the configured
62 * applications
63 *
64 * @author <a href="mailto:kristian.nordal@gmail.com">Kristian Nordal</a>
65 * @version $Id: AssembleMojo.java 16492 2012-04-29 18:26:21Z khmarbaise $
66 * @goal assemble
67 * @requiresDependencyResolution runtime
68 * @phase package
69 * @threadsafe
70 */
71 public class AssembleMojo extends AbstractAppAssemblerMojo
72 {
73 // -----------------------------------------------------------------------
74 // Parameters
75 // -----------------------------------------------------------------------
76
77 /**
78 * The directory that will be used to assemble the artifacts in and place
79 * the bin scripts.
80 *
81 * @required
82 * @parameter expression="${assembleDirectory}"
83 * default-value="${project.build.directory}/appassembler"
84 */
85 private File assembleDirectory;
86
87 /**
88 * The set of Programs that bin files will be generated for.
89 *
90 * @required
91 * @parameter
92 */
93 private Set programs;
94
95 /**
96 * Define the name of binary folder.
97 *
98 * @parameter default-value="bin"
99 * @since 1.2
100 */
101 private String binFolder;
102
103 /**
104 * The name of the target directory for configuration files.
105 *
106 * @parameter default-value="etc"
107 */
108 private String configurationDirectory;
109
110 /**
111 * The name of the source directory for configuration files.
112 *
113 * @parameter default-value="src/main/config"
114 * @since 1.1
115 */
116 private File configurationSourceDirectory;
117
118 /**
119 * If the source configuration directory should be copied to the configured <code>configurationDirectory</code>.
120 *
121 * @parameter default-value="false"
122 * @since 1.1
123 */
124 private boolean copyConfigurationDirectory;
125
126 /**
127 * If the <code>configurationDirectory</code> (<code>etc</code> by default)
128 * should be included in the beginning of the classpath in the generated bin
129 * files.
130 *
131 * @parameter default-value="true"
132 */
133 private boolean includeConfigurationDirectoryInClasspath;
134
135 /**
136 * The layout of the generated Maven repository. Supported types - "default"
137 * (Maven2) | "legacy" (Maven1) | "flat" (flat <code>lib/</code> style). The
138 * style "legacy" is only supported if you are running under Maven 2.2.1 and
139 * before.
140 *
141 * @parameter default-value="default"
142 */
143 private String repositoryLayout;
144
145 /**
146 * Extra arguments that will be given to the JVM verbatim. If you define
147 * JvmSettings on the {@link Program#setJvmSettings(JvmSettings)} level this
148 * part will be overwritten by the given parameters on program level.
149 * Otherwise if {@link Program#setJvmSettings(JvmSettings)} is not given
150 * these settings will be used instead. This can be used to define some
151 * default values whereas by using the {@link Program#setJvmSettings(JvmSettings)} to overwrite the default
152 * settings. This is only valid for the extraJvmArguments not for the rest
153 * of the {@link JvmSettings#}.
154 *
155 * Since 1.2 it's possible to use place holder <code>@BASEDIR@</code> and <code>@REPO@</code> which will be expanded
156 * based on the platform for
157 * which the appropriate script will generated.
158 *
159 * @parameter
160 */
161 private String extraJvmArguments;
162
163 /**
164 * The default platforms the plugin will generate bin files for. Configure
165 * with string values - "all"(default/empty) | "windows" | "unix".
166 *
167 * @parameter
168 */
169 private Set platforms;
170
171 /**
172 * Setup file in $BASEDIR/bin to be called prior to execution.
173 *
174 * @parameter
175 */
176 private String environmentSetupFileName;
177
178 /**
179 * Set to false to skip repository generation.
180 *
181 * @parameter default-value="true"
182 */
183 private boolean generateRepository;
184
185 /**
186 * Path (relative to assembleDirectory) of the desired output repository.
187 *
188 * @parameter default-value="repo"
189 */
190 private String repositoryName;
191
192 /**
193 * This can be used to put the project artifact as the first entry in the
194 * classpath after the configuration folder (<code>etc</code> by default).
195 * The default behavior is to have the project artifact at the last position
196 * in classpath.
197 *
198 * @since 1.2.1
199 * @parameter default-value="false"
200 */
201 private boolean projectArtifactFirstInClassPath;
202
203 /**
204 * The following can be used to use all dependencies instead of the default
205 * behavior which represents runtime dependencies only.
206 *
207 * @since 1.2.1
208 * @parameter default-value="false"
209 */
210 private boolean useAllDependencies;
211
212 /**
213 * Sometimes it happens that you have many dependencies
214 * which means in other words having a very long classpath.
215 * And sometimes the classpath becomes too long (in particular
216 * on Windows based platforms). This option can help in such
217 * situation. If you activate that your classpath contains only a
218 * <a href=
219 * "http://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html"
220 * >classpath wildcard</a> (REPO/*). But be aware that this works only in combination
221 * with Java 1.6 and with {@link #repositoryLayout} <code>flat</code>.
222 * Otherwise this configuration will not work.
223 *
224 * @since 1.2.2
225 * @parameter default-value="false"
226 */
227 private boolean useAsterikClassPath;
228
229 /**
230 * The file extensions to use for bin files. The file extensions are stored
231 * in a Map that uses the platform name as key. To change the file extension
232 * for Unix bin files to ".sh" use this configuration:
233 *
234 * <pre>
235 * <binFileExtensions>
236 * <unix>.sh</unix>
237 * </binFileExtensions>
238 * </pre>
239 *
240 * @parameter
241 * @since 1.1
242 */
243 protected Map/* <String, String> */binFileExtensions;
244
245 // -----------------------------------------------------------------------
246 // Read-only Parameters
247 // -----------------------------------------------------------------------
248
249 /**
250 * @readonly
251 * @parameter expression="${project}"
252 */
253 private MavenProject mavenProject;
254
255 /**
256 * @readonly
257 * @parameter expression="${project.runtimeArtifacts}"
258 */
259 private List artifacts;
260
261 /**
262 * @readonly
263 * @parameter expression="${project.artifact}"
264 */
265 private Artifact projectArtifact;
266
267 /**
268 * @readonly
269 * @parameter expression="${localRepository}"
270 */
271 private ArtifactRepository localRepository;
272
273 /**
274 * Show console window when execute this application.
275 *
276 * @parameter default-value="true"
277 */
278 private boolean showConsoleWindow;
279
280 /**
281 * You can define a license header file which will be used instead the
282 * default header in the generated scripts.
283 *
284 * @parameter
285 * @since 1.2
286 */
287 private File licenseHeaderFile;
288
289 // -----------------------------------------------------------------------
290 // Components
291 // -----------------------------------------------------------------------
292
293 /**
294 * @component
295 */
296 private ArtifactRepositoryFactory artifactRepositoryFactory;
297
298 /**
299 * @component
300 */
301 private ArtifactInstaller artifactInstaller;
302
303 /**
304 * @component
305 */
306 private DaemonGeneratorService daemonGeneratorService;
307
308 /**
309 * @component role=
310 * "org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout"
311 */
312 private Map availableRepositoryLayouts;
313
314 // ----------------------------------------------------------------------
315 // CONSTANTS
316 // ----------------------------------------------------------------------
317
318 private static final Set VALID_PLATFORMS = Collections
319 .unmodifiableSet ( new HashSet ( Arrays.asList ( new String[] {
320 "unix",
321 "windows"
322 } ) ) );
323
324 // ----------------------------------------------------------------------
325 // Validate
326 // ----------------------------------------------------------------------
327
328 private void validate ( Set defaultPlatforms ) throws MojoFailureException,
329 MojoExecutionException
330 {
331 // ----------------------------------------------------------------------
332 // Validate Programs
333 // ----------------------------------------------------------------------
334
335 ArrayList programNames = new ArrayList ( );
336
337 for ( Iterator i = programs.iterator ( ); i.hasNext ( ); )
338 {
339 Program program = ( Program ) i.next ( );
340
341 if ( program.getMainClass ( ) == null
342 || program.getMainClass ( ).trim ( ).equals ( "" ) )
343 {
344 throw new MojoFailureException (
345 "Missing main class in Program configuration" );
346 }
347
348 // FIXME: After migration to Java 1.5 the following check could be
349 // done simpler!
350 if ( !programNames.contains ( program.getName ( ) ) )
351 {
352 programNames.add ( program.getName ( ) );
353 }
354 else
355 {
356 throw new MojoFailureException ( "The program name: "
357 + program.getName ( ) + " exists more than once!" );
358 }
359
360 // platforms
361 program.setPlatforms ( validatePlatforms ( program.getPlatforms ( ),
362 defaultPlatforms ) );
363 }
364
365 }
366
367 // ----------------------------------------------------------------------
368 // Execute
369 // ----------------------------------------------------------------------
370
371 /*
372 * (non-Javadoc)
373 * @see org.apache.maven.plugin.AbstractMojo#execute()
374 */
375 public void execute () throws MojoExecutionException, MojoFailureException
376 {
377 Set defaultPlatforms = validatePlatforms ( platforms, VALID_PLATFORMS );
378
379 // validate input and set defaults
380 validate ( defaultPlatforms );
381
382 if ( isUseAsterikClassPath ( )
383 && !repositoryLayout.equalsIgnoreCase ( "flat" ) )
384 {
385 throw new MojoExecutionException (
386 "The useAsterikClassPath works only in combination with repositoryLayout flat." );
387 }
388
389 // Set the extensions for bin files for the different platforms
390 setBinFileExtensions ( );
391
392 ArtifactRepositoryLayout artifactRepositoryLayout = ( ArtifactRepositoryLayout ) availableRepositoryLayouts
393 .get ( repositoryLayout );
394 if ( artifactRepositoryLayout == null )
395 {
396 throw new MojoFailureException ( "Unknown repository layout '"
397 + repositoryLayout + "'." );
398 }
399
400 if ( isUseAllDependencies ( ) )
401 {
402 // TODO: This should be made different. We have to think about using
403 // a default ArtifactFilter
404 Set dependencyArtifacts = mavenProject.getDependencyArtifacts ( );
405 artifacts = new ArrayList ( );
406 for ( Iterator it = dependencyArtifacts.iterator ( ); it.hasNext ( ); )
407 {
408 Artifact artifact = ( Artifact ) it.next ( );
409 artifacts.add ( artifact );
410 }
411 }
412
413 // ----------------------------------------------------------------------
414 // Install dependencies in the new repository
415 // ----------------------------------------------------------------------
416 if ( generateRepository )
417 {
418 // The repo where the jar files will be installed
419 ArtifactRepository artifactRepository = artifactRepositoryFactory
420 .createDeploymentArtifactRepository ( "appassembler",
421 "file://" + assembleDirectory.getAbsolutePath ( )
422 + "/" + repositoryName,
423 artifactRepositoryLayout, false );
424
425 for ( Iterator it = artifacts.iterator ( ); it.hasNext ( ); )
426 {
427 Artifact artifact = ( Artifact ) it.next ( );
428
429 installArtifact ( artifactRepository, artifact );
430 }
431
432 // install the project's artifact in the new repository
433 installArtifact ( artifactRepository, projectArtifact );
434 }
435
436 // ----------------------------------------------------------------------
437 // Setup
438 // ----------------------------------------------------------------------
439
440 setUpWorkingArea ( );
441
442 // ----------------------------------------------------------------------
443 // Create bin files
444 // ----------------------------------------------------------------------
445
446 for ( Iterator it = programs.iterator ( ); it.hasNext ( ); )
447 {
448 Program program = ( Program ) it.next ( );
449
450 Set validatedPlatforms = validatePlatforms ( program.getPlatforms ( ),
451 defaultPlatforms );
452
453 for ( Iterator platformIt = validatedPlatforms.iterator ( ); platformIt
454 .hasNext ( ); )
455 {
456 String platform = ( String ) platformIt.next ( );
457
458 // TODO: seems like a bug in the generator that the request is
459 // modified
460 org.codehaus.mojo.appassembler.model.Daemon daemon = programToDaemon (
461 program, artifactRepositoryLayout );
462 DaemonGenerationRequest request = new DaemonGenerationRequest (
463 daemon, mavenProject, localRepository,
464 assembleDirectory, binFolder );
465 request.setStubDaemon ( request.getDaemon ( ) );
466
467 request.setPlatform ( platform );
468
469 try
470 {
471 daemonGeneratorService.generateDaemon ( request );
472 }
473 catch ( DaemonGeneratorException e )
474 {
475 throw new MojoExecutionException (
476 "Error while generating script for the program '"
477 + program.getName ( )
478 + "' for the platform '" + platform + "': "
479 + e.getMessage ( ), e );
480 }
481 }
482 }
483
484 // ----------------------------------------------------------------------
485 // Copy configuration directory
486 // ----------------------------------------------------------------------
487
488 if ( copyConfigurationDirectory )
489 {
490 copyConfigurationDirectory ( );
491 }
492 }
493
494 private org.codehaus.mojo.appassembler.model.Daemon programToDaemon (
495 Program program, ArtifactRepositoryLayout artifactRepositoryLayout )
496 {
497 org.codehaus.mojo.appassembler.model.Daemon daemon = new org.codehaus.mojo.appassembler.model.Daemon ( );
498
499 daemon.setId ( program.getName ( ) );
500 daemon.setMainClass ( program.getMainClass ( ) );
501 daemon.setShowConsoleWindow ( showConsoleWindow );
502 daemon.setCommandLineArguments ( program.getCommandLineArguments ( ) );
503
504 if ( program.getLicenseHeaderFile ( ) != null )
505 {
506 getLog ( ).debug (
507 "Using the program specific license header. :"
508 + program.getLicenseHeaderFile ( ) );
509 daemon.setLicenseHeaderFile ( program.getLicenseHeaderFile ( )
510 .getPath ( ) );
511 }
512 else
513 {
514 getLog ( ).debug (
515 "Using the global defined license header. :"
516 + licenseHeaderFile );
517
518 if ( licenseHeaderFile != null )
519 {
520 daemon.setLicenseHeaderFile ( this.licenseHeaderFile
521 .getAbsolutePath ( ) );
522 }
523 else
524 {
525 daemon.setLicenseHeaderFile ( null );
526 }
527 }
528
529 List directories = new ArrayList ( );
530
531 if ( includeConfigurationDirectoryInClasspath )
532 {
533 Directory directory = new Directory ( );
534 directory.setRelativePath ( configurationDirectory );
535 directories.add ( directory );
536 }
537
538 if ( daemon.getClasspath ( ) == null )
539 {
540 daemon.setClasspath ( new Classpath ( ) );
541 }
542
543 daemon.getClasspath ( ).setDirectories ( directories );
544
545 daemon.setRepositoryName ( repositoryName );
546
547 List dependencies = new ArrayList ( );
548
549 // TODO: This should be done in a more elegant way for 2.0
550 // TODO: Check if the classpath wildcard could be used for Daemons as well?
551 if ( isUseAsterikClassPath ( ) )
552 {
553 Dependency dependency = new Dependency ( );
554 dependency.setGroupId ( "" );
555 dependency.setArtifactId ( "" );
556 dependency.setVersion ( "" );
557 dependency.setRelativePath ( "*" );
558 dependencies.add ( dependency );
559 }
560 else
561 {
562 List classPathArtifacts = new ArrayList ( );
563
564 if ( isProjectArtifactFirstInClassPath ( ) )
565 {
566 classPathArtifacts.add ( projectArtifact );
567 classPathArtifacts.addAll ( artifacts );
568 }
569 else
570 {
571 classPathArtifacts.addAll ( artifacts );
572 classPathArtifacts.add ( projectArtifact );
573 }
574
575 for ( Iterator it = classPathArtifacts.iterator ( ); it.hasNext ( ); )
576 {
577 Artifact artifact = ( Artifact ) it.next ( );
578 Dependency dependency = new Dependency ( );
579 dependency.setGroupId ( artifact.getGroupId ( ) );
580 dependency.setArtifactId ( artifact.getArtifactId ( ) );
581 dependency.setVersion ( artifact.getVersion ( ) );
582 dependency.setRelativePath ( artifactRepositoryLayout
583 .pathOf ( artifact ) );
584 dependencies.add ( dependency );
585 }
586
587 }
588
589 daemon.getClasspath ( ).setDependencies ( dependencies );
590
591 daemon.setJvmSettings ( convertToJvmSettingsWithDefaultHandling ( program ) );
592
593 daemon.setEnvironmentSetupFileName ( this.environmentSetupFileName );
594
595 return daemon;
596 }
597
598 private JvmSettings convertToJvmSettingsWithDefaultHandling ( Program program )
599 {
600 JvmSettings jvmSettings = new JvmSettings ( );
601
602 if ( program.getJvmSettings ( ) != null )
603 {
604 // Some kind of settings done on per program base so they take
605 // precendence.
606 jvmSettings = program.getJvmSettings ( );
607 }
608 else
609 {
610 // No settings in the program done so we use the default behaviour
611 if ( StringUtils.isNotBlank ( this.extraJvmArguments ) )
612 {
613 jvmSettings
614 .setExtraArguments ( parseTokens ( this.extraJvmArguments ) );
615 }
616 }
617
618 return jvmSettings;
619 }
620
621 // ----------------------------------------------------------------------
622 // Install artifacts into the assemble repository
623 // ----------------------------------------------------------------------
624
625 private void installArtifact ( ArtifactRepository artifactRepository,
626 Artifact artifact ) throws MojoExecutionException
627 {
628 try
629 {
630 // Necessary for the artifact's baseVersion to be set correctly
631 // See:
632 // http://mail-archives.apache.org/mod_mbox/maven-dev/200511.mbox/%3c437288F4.4080003@apache.org%3e
633 artifact.isSnapshot ( );
634
635 if ( artifact.getFile ( ) != null )
636 {
637 getLog ( ).debug (
638 "installArtifact: scope:" + artifact.getScope ( )
639 + " id:" + artifact.getId ( ) );
640 artifactInstaller.install ( artifact.getFile ( ), artifact,
641 artifactRepository );
642 }
643 }
644 catch ( ArtifactInstallationException e )
645 {
646 throw new MojoExecutionException ( "Failed to copy artifact.", e );
647 }
648 }
649
650 // ----------------------------------------------------------------------
651 // Set up the assemble environment
652 // ----------------------------------------------------------------------
653
654 private void setUpWorkingArea () throws MojoFailureException
655 {
656 // create (if necessary) directory for bin files
657 File binDir = new File ( assembleDirectory.getAbsolutePath ( ),
658 binFolder.toString ( ) );
659
660 if ( !binDir.exists ( ) )
661 {
662
663 boolean success = binDir.mkdirs ( );
664
665 if ( !success )
666 {
667 throw new MojoFailureException (
668 "Failed to create directory for bin files." );
669 }
670 }
671 }
672
673 private void copyConfigurationDirectory () throws MojoFailureException
674 {
675 if ( !configurationSourceDirectory.exists ( ) )
676 {
677 throw new MojoFailureException (
678 "The source directory for configuration files does not exist: "
679 + configurationSourceDirectory.getAbsolutePath ( ) );
680 }
681
682 File configurationTargetDirectory = new File (
683 assembleDirectory.getAbsolutePath ( ), configurationDirectory );
684 if ( !configurationTargetDirectory.exists ( ) )
685 {
686 // Create (if necessary) target directory for configuration files
687 boolean success = configurationTargetDirectory.mkdirs ( );
688
689 if ( !success )
690 {
691 throw new MojoFailureException (
692 "Failed to create the target directory for configuration files: "
693 + configurationTargetDirectory
694 .getAbsolutePath ( ) );
695 }
696
697 try
698 {
699 getLog ( ).debug (
700 "Will try to copy configuration files from "
701 + configurationSourceDirectory
702 .getAbsolutePath ( )
703 + " to "
704 + configurationTargetDirectory
705 .getAbsolutePath ( ) );
706 FileUtils.copyDirectory ( configurationSourceDirectory,
707 configurationTargetDirectory, null,
708 getDefaultExcludesAsCommaSeparatedString ( ) );
709 }
710 catch ( IOException e )
711 {
712 throw new MojoFailureException (
713 "Failed to copy the configuration files." );
714 }
715 }
716 }
717
718 private String getDefaultExcludesAsCommaSeparatedString ()
719 {
720 StringBuffer defaultExcludes = new StringBuffer ( );
721
722 List defaultExcludesAsList = FileUtils.getDefaultExcludesAsList ( );
723 Iterator iterator = defaultExcludesAsList.iterator ( );
724 while ( iterator.hasNext ( ) )
725 {
726 String exclude = ( String ) iterator.next ( );
727 defaultExcludes.append ( exclude );
728 if ( iterator.hasNext ( ) )
729 {
730 defaultExcludes.append ( "," );
731 }
732 }
733
734 return defaultExcludes.toString ( );
735 }
736
737 private Set validatePlatforms ( Set platformsToValidate, Set defaultPlatforms )
738 throws MojoFailureException
739 {
740 if ( platformsToValidate == null )
741 {
742 return defaultPlatforms;
743 }
744
745 if ( platformsToValidate.size ( ) == 1
746 && platformsToValidate.iterator ( ).next ( ).equals ( "all" ) )
747 {
748 return VALID_PLATFORMS;
749 }
750
751 if ( !VALID_PLATFORMS.containsAll ( platformsToValidate ) )
752 {
753 throw new MojoFailureException (
754 "Non-valid default platform declared, supported types are: "
755 + VALID_PLATFORMS );
756 }
757
758 return platformsToValidate;
759 }
760
761 /**
762 * This will tokenize the given argument or give the extraJvmArguments back
763 * if the given argument is empty.
764 *
765 * @param arg
766 * The argument to parse.
767 * @return List of arguments.
768 */
769 public static List parseTokens ( String arg )
770 {
771 List extraJvmArguments = new ArrayList ( );
772
773 if ( StringUtils.isEmpty ( arg ) )
774 {
775 return extraJvmArguments;
776 }
777
778 StringTokenizer tokenizer = new StringTokenizer ( arg );
779
780 String argument = null;
781
782 while ( tokenizer.hasMoreTokens ( ) )
783 {
784 String token = tokenizer.nextToken ( );
785
786 if ( argument != null )
787 {
788 if ( token.length ( ) == 0 )
789 {
790 // ignore it
791 continue;
792 }
793
794 int length = token.length ( );
795
796 if ( token.charAt ( length - 1 ) == '\"' )
797 {
798 extraJvmArguments.add ( argument + " "
799 + token.substring ( 0, length - 1 ) );
800 argument = null;
801 }
802 else
803 {
804 argument += " " + token;
805 }
806 }
807 else
808 {
809 // If the token starts with a ", save it
810 if ( token.charAt ( 0 ) == '\"' )
811 {
812 argument = token.substring ( 1 );
813 }
814 else
815 {
816 extraJvmArguments.add ( token );
817 }
818 }
819 }
820
821 return extraJvmArguments;
822 }
823
824 /**
825 * Set the available repository layouts.
826 *
827 * @param availableRepositoryLayouts
828 * The repository layouts which are available.
829 */
830 public void setAvailableRepositoryLayouts ( Map availableRepositoryLayouts )
831 {
832 this.availableRepositoryLayouts = availableRepositoryLayouts;
833 }
834
835 /**
836 * Set the extensions for bin files for the supported platforms. The values
837 * are taken from the Mojo's <code>binFileExtensions</code> parameter.
838 */
839 private void setBinFileExtensions () throws MojoFailureException
840 {
841 if ( binFileExtensions != null )
842 {
843 Set keySet = binFileExtensions.keySet ( );
844 Iterator iterator = keySet.iterator ( );
845 while ( iterator.hasNext ( ) )
846 {
847 String platformName = ( String ) iterator.next ( );
848 if ( !VALID_PLATFORMS.contains ( platformName ) )
849 {
850 getLog ( ).warn (
851 "Bin file extension configured for a non-valid platform ("
852 + platformName
853 + "), supported platforms are: "
854 + VALID_PLATFORMS );
855 }
856 else
857 {
858 try
859 {
860 Platform platform = Platform.getInstance ( platformName );
861 platform.setBinFileExtension ( ( String ) binFileExtensions
862 .get ( platformName ) );
863 }
864 catch ( DaemonGeneratorException e )
865 {
866 getLog ( ).warn (
867 "Unable to set the bin file extension for "
868 + platformName, e );
869 }
870 }
871 }
872 }
873 }
874
875 /**
876 * Be the project the first artifact in classpath or not.
877 *
878 * @return true if the project should be the first artifact in classpath false otherwise.
879 */
880 public boolean isProjectArtifactFirstInClassPath ()
881 {
882 return projectArtifactFirstInClassPath;
883 }
884
885 /**
886 * Set if the project should be the artifact at first position or not.
887 *
888 * @param projectArtifactFirstInClassPath
889 * true if the project artifact will be first false otherwise.
890 */
891 public void setProjectArtifactFirstInClassPath (
892 boolean projectArtifactFirstInClassPath )
893 {
894 this.projectArtifactFirstInClassPath = projectArtifactFirstInClassPath;
895 }
896
897 /**
898 * Should all dependencies be used incl. system scoped.
899 *
900 * @return true if set to yes false otherwise.
901 */
902 public boolean isUseAllDependencies ()
903 {
904 return useAllDependencies;
905 }
906
907 /**
908 * Define if all dependencies should be used or not.
909 *
910 * @param useAllDependencies
911 * true to activate false otherwise.
912 */
913 public void setUseAllDependencies ( boolean useAllDependencies )
914 {
915 this.useAllDependencies = useAllDependencies;
916 }
917
918 /**
919 * Should the /* part for the classpath be used or not.
920 *
921 * @return true if the asterik-classpath will be used false otherwise.
922 */
923 public boolean isUseAsterikClassPath ()
924 {
925 return useAsterikClassPath;
926 }
927
928 /**
929 * Use asterik-classpath or not.
930 *
931 * @param useAsterikClassPath
932 * true to use asterik classpath false otherwise.
933 */
934 public void setUseAsterikClassPath ( boolean useAsterikClassPath )
935 {
936 this.useAsterikClassPath = useAsterikClassPath;
937 }
938 }