Coverage Report - org.codehaus.plexus.compiler.CompilerConfiguration
 
Classes in this File Line Coverage Branch Coverage Complexity
CompilerConfiguration
12%
20/159
10%
2/20
1,12
CompilerConfiguration$CompilerReuseStrategy
77%
7/9
N/A
1,12
 
 1  
 package org.codehaus.plexus.compiler;
 2  
 
 3  
 /**
 4  
  * The MIT License
 5  
  *
 6  
  * Copyright (c) 2004, The Codehaus
 7  
  *
 8  
  * Permission is hereby granted, free of charge, to any person obtaining a copy of
 9  
  * this software and associated documentation files (the "Software"), to deal in
 10  
  * the Software without restriction, including without limitation the rights to
 11  
  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 12  
  * of the Software, and to permit persons to whom the Software is furnished to do
 13  
  * so, subject to the following conditions:
 14  
  *
 15  
  * The above copyright notice and this permission notice shall be included in all
 16  
  * copies or substantial portions of the Software.
 17  
  *
 18  
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 19  
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 20  
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 21  
  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 22  
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 23  
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 24  
  * SOFTWARE.
 25  
  */
 26  
 
 27  
 import java.io.File;
 28  
 import java.util.AbstractMap;
 29  
 import java.util.ArrayList;
 30  
 import java.util.Collection;
 31  
 import java.util.Collections;
 32  
 import java.util.HashSet;
 33  
 import java.util.LinkedHashMap;
 34  
 import java.util.LinkedList;
 35  
 import java.util.List;
 36  
 import java.util.Map;
 37  
 import java.util.Set;
 38  
 
 39  
 /**
 40  
  * @author jdcasey
 41  
  */
 42  1
 public class CompilerConfiguration
 43  
 {
 44  
     private String outputLocation;
 45  
 
 46  1
     private List<String> classpathEntries = new LinkedList<>();
 47  
 
 48  1
     private List<String> modulepathEntries = new LinkedList<>();
 49  
 
 50  
     // ----------------------------------------------------------------------
 51  
     // Source Files
 52  
     // ----------------------------------------------------------------------
 53  
 
 54  1
     private Set<File> sourceFiles = new HashSet<>();
 55  
 
 56  1
     private List<String> sourceLocations = new LinkedList<>();
 57  
 
 58  1
     private Set<String> includes = new HashSet<>();
 59  
 
 60  1
     private Set<String> excludes = new HashSet<>();
 61  
 
 62  
     // ----------------------------------------------------------------------
 63  
     // Compiler Settings
 64  
     // ----------------------------------------------------------------------
 65  
 
 66  
     private boolean debug;
 67  
 
 68  
     private String debugLevel;
 69  
 
 70  1
     private boolean showWarnings = true;
 71  
     
 72  
     /**
 73  
      * -Werror argument as supported since Java 1.7
 74  
      */
 75  
     private boolean failOnWarning;
 76  
 
 77  
     private boolean showDeprecation;
 78  
 
 79  
     private String sourceVersion;
 80  
 
 81  
     private String targetVersion;
 82  
     
 83  
     /**
 84  
      * value of -release parameter in java 9+
 85  
      */
 86  
     private String releaseVersion;
 87  
 
 88  
     private String sourceEncoding;
 89  
 
 90  
     /**
 91  
      * value of --module-version parameter in java 9+
 92  
      */
 93  
     private String moduleVersion;
 94  
 
 95  1
     private Collection<Map.Entry<String,String>> customCompilerArguments = new ArrayList<>();
 96  
 
 97  
     private boolean fork;
 98  
 
 99  
     private boolean optimize;
 100  
 
 101  
     private String meminitial;
 102  
 
 103  
     private String maxmem;
 104  
 
 105  
     private String executable;
 106  
 
 107  
     private File workingDirectory;
 108  
 
 109  
     private String compilerVersion;
 110  
 
 111  1
     private boolean verbose = false;
 112  
 
 113  
     /**
 114  
      * @since 2.8.2
 115  
      */
 116  
     private boolean parameters;
 117  
 
 118  
     /**
 119  
      * A build temporary directory, eg target/.
 120  
      * <p/>
 121  
      * Used by the compiler implementation to put temporary files.
 122  
      */
 123  
     private File buildDirectory;
 124  
 
 125  
     /**
 126  
      * Used to control the name of the output file when compiling a set of
 127  
      * sources to a single file.
 128  
      */
 129  
     private String outputFileName;
 130  
 
 131  
     /**
 132  
      * in jdk 1.6+, used to hold value of the -s path parameter.
 133  
      */
 134  
     private File generatedSourcesDirectory;
 135  
 
 136  
     /**
 137  
      * value of the -proc parameter in jdk 1.6+
 138  
      */
 139  
     private String proc;
 140  
 
 141  
     /**
 142  
      * -processor parameters in jdk 1.6+
 143  
      */
 144  
     private String[] annotationProcessors;
 145  
 
 146  
     /**
 147  
      * -processorpath parameter in jdk 1.6+. If specified, annotation processors are only searched in the processor
 148  
      * path. Otherwise they are searched in the classpath.
 149  
      */
 150  
     private List<String> processorPathEntries;
 151  
 
 152  
     /**
 153  
      * default value {@link CompilerReuseStrategy#ReuseCreated}
 154  
      *
 155  
      * @since 1.9
 156  
      */
 157  1
     private CompilerReuseStrategy compilerReuseStrategy = CompilerReuseStrategy.ReuseCreated;
 158  
 
 159  
     /**
 160  
      * force usage of old JavacCompiler even if javax.tools is detected
 161  
      * @since 2.0
 162  
      */
 163  1
     private boolean forceJavacCompilerUse=false;
 164  
 
 165  
     // ----------------------------------------------------------------------
 166  
     //
 167  
     // ----------------------------------------------------------------------
 168  
 
 169  
     public void setOutputLocation( String outputLocation )
 170  
     {
 171  0
         this.outputLocation = outputLocation;
 172  0
     }
 173  
 
 174  
     public String getOutputLocation()
 175  
     {
 176  0
         return outputLocation;
 177  
     }
 178  
 
 179  
     // ----------------------------------------------------------------------
 180  
     // Class path
 181  
     // ----------------------------------------------------------------------
 182  
 
 183  
     public void addClasspathEntry( String classpathEntry )
 184  
     {
 185  0
         classpathEntries.add( classpathEntry );
 186  0
     }
 187  
 
 188  
     public void setClasspathEntries( List<String> classpathEntries )
 189  
     {
 190  0
         if ( classpathEntries == null )
 191  
         {
 192  0
             this.classpathEntries = Collections.emptyList();
 193  
         }
 194  
         else
 195  
         {
 196  0
             this.classpathEntries = new LinkedList<>( classpathEntries );
 197  
         }
 198  0
     }
 199  
 
 200  
     public List<String> getClasspathEntries()
 201  
     {
 202  0
         return Collections.unmodifiableList( classpathEntries );
 203  
     }
 204  
 
 205  
     // ----------------------------------------------------------------------
 206  
     // Module path
 207  
     // ----------------------------------------------------------------------
 208  
 
 209  
     public void addModulepathEntry( String modulepathEntry )
 210  
     {
 211  0
         modulepathEntries.add( modulepathEntry );
 212  0
     }
 213  
 
 214  
     public void setModulepathEntries( List<String> modulepathEntries )
 215  
     {
 216  0
         if ( modulepathEntries == null )
 217  
         {
 218  0
             this.modulepathEntries = Collections.emptyList();
 219  
         }
 220  
         else
 221  
         {
 222  0
             this.modulepathEntries = new LinkedList<>( modulepathEntries );
 223  
         }
 224  0
     }
 225  
 
 226  
     public List<String> getModulepathEntries()
 227  
     {
 228  0
         return Collections.unmodifiableList( modulepathEntries );
 229  
     }
 230  
 
 231  
     // ----------------------------------------------------------------------
 232  
     // Source files
 233  
     // ----------------------------------------------------------------------
 234  
 
 235  
     public void setSourceFiles( Set<File> sourceFiles )
 236  
     {
 237  0
         if ( sourceFiles == null )
 238  
         {
 239  0
             this.sourceFiles = Collections.emptySet();
 240  
         }
 241  
         else
 242  
         {
 243  0
             this.sourceFiles = new HashSet<>( sourceFiles );
 244  
         }
 245  0
     }
 246  
 
 247  
     public Set<File> getSourceFiles()
 248  
     {
 249  0
         return sourceFiles;
 250  
     }
 251  
 
 252  
     public void addSourceLocation( String sourceLocation )
 253  
     {
 254  0
         sourceLocations.add( sourceLocation );
 255  0
     }
 256  
 
 257  
     public void setSourceLocations( List<String> sourceLocations )
 258  
     {
 259  0
         if ( sourceLocations == null )
 260  
         {
 261  0
             this.sourceLocations = Collections.emptyList();
 262  
         }
 263  
         else
 264  
         {
 265  0
             this.sourceLocations = new LinkedList<>( sourceLocations );
 266  
         }
 267  0
     }
 268  
 
 269  
     public List<String> getSourceLocations()
 270  
     {
 271  0
         return Collections.unmodifiableList( sourceLocations );
 272  
     }
 273  
 
 274  
     public void addInclude( String include )
 275  
     {
 276  0
         includes.add( include );
 277  0
     }
 278  
 
 279  
     public void setIncludes( Set<String> includes )
 280  
     {
 281  0
         if ( includes == null )
 282  
         {
 283  0
             this.includes = Collections.emptySet();
 284  
         }
 285  
         else
 286  
         {
 287  0
             this.includes = new HashSet<>( includes );
 288  
         }
 289  0
     }
 290  
 
 291  
     public Set<String> getIncludes()
 292  
     {
 293  0
         return Collections.unmodifiableSet( includes );
 294  
     }
 295  
 
 296  
     public void addExclude( String exclude )
 297  
     {
 298  0
         excludes.add( exclude );
 299  0
     }
 300  
 
 301  
     public void setExcludes( Set<String> excludes )
 302  
     {
 303  0
         if ( excludes == null )
 304  
         {
 305  0
             this.excludes = Collections.emptySet();
 306  
         }
 307  
         else
 308  
         {
 309  0
             this.excludes = new HashSet<>( excludes );
 310  
         }
 311  0
     }
 312  
 
 313  
     public Set<String> getExcludes()
 314  
     {
 315  0
         return Collections.unmodifiableSet( excludes );
 316  
     }
 317  
 
 318  
     // ----------------------------------------------------------------------
 319  
     // Compiler Settings
 320  
     // ----------------------------------------------------------------------
 321  
 
 322  
     public void setDebug( boolean debug )
 323  
     {
 324  0
         this.debug = debug;
 325  0
     }
 326  
 
 327  
     public boolean isDebug()
 328  
     {
 329  0
         return debug;
 330  
     }
 331  
 
 332  
     public void setDebugLevel( String debugLevel )
 333  
     {
 334  0
         this.debugLevel = debugLevel;
 335  0
     }
 336  
 
 337  
     public String getDebugLevel()
 338  
     {
 339  0
         return debugLevel;
 340  
     }
 341  
 
 342  
     public void setShowWarnings( boolean showWarnings )
 343  
     {
 344  0
         this.showWarnings = showWarnings;
 345  0
     }
 346  
 
 347  
     public boolean isShowWarnings()
 348  
     {
 349  0
         return showWarnings;
 350  
     }
 351  
 
 352  
     public boolean isShowDeprecation()
 353  
     {
 354  0
         return showDeprecation;
 355  
     }
 356  
 
 357  
     public void setShowDeprecation( boolean showDeprecation )
 358  
     {
 359  0
         this.showDeprecation = showDeprecation;
 360  0
     }
 361  
     
 362  
     public boolean isFailOnWarning()
 363  
     {
 364  0
         return failOnWarning;
 365  
     }
 366  
     
 367  
     public void setFailOnWarning( boolean failOnWarnings )
 368  
     {
 369  0
         this.failOnWarning = failOnWarnings;
 370  0
     }
 371  
 
 372  
     public String getSourceVersion()
 373  
     {
 374  0
         return sourceVersion;
 375  
     }
 376  
 
 377  
     public void setSourceVersion( String sourceVersion )
 378  
     {
 379  0
         this.sourceVersion = sourceVersion;
 380  0
     }
 381  
 
 382  
     public String getTargetVersion()
 383  
     {
 384  0
         return targetVersion;
 385  
     }
 386  
 
 387  
     public void setTargetVersion( String targetVersion )
 388  
     {
 389  0
         this.targetVersion = targetVersion;
 390  0
     }
 391  
     
 392  
     public String getReleaseVersion()
 393  
     {
 394  0
         return releaseVersion;
 395  
     }
 396  
 
 397  
     public void setReleaseVersion( String releaseVersion )
 398  
     {
 399  0
         this.releaseVersion = releaseVersion;
 400  0
     }
 401  
 
 402  
     public String getSourceEncoding()
 403  
     {
 404  0
         return sourceEncoding;
 405  
     }
 406  
 
 407  
     public void setSourceEncoding( String sourceEncoding )
 408  
     {
 409  0
         this.sourceEncoding = sourceEncoding;
 410  0
     }
 411  
 
 412  
     public String getModuleVersion()
 413  
     {
 414  0
         return moduleVersion;
 415  
     }
 416  
 
 417  
     public void setModuleVersion( String moduleVersion )
 418  
     {
 419  0
         this.moduleVersion = moduleVersion;
 420  0
     }
 421  
 
 422  
     public void addCompilerCustomArgument( String customArgument, String value )
 423  
     {
 424  2
         customCompilerArguments.add( new AbstractMap.SimpleImmutableEntry<>( customArgument, value ) );
 425  2
     }
 426  
 
 427  
     /**
 428  
      * @deprecated will be removed in 2.X use #getCustomCompilerArgumentsAsMap
 429  
      * @return
 430  
      */
 431  
     @Deprecated
 432  
     public LinkedHashMap<String, String> getCustomCompilerArguments()
 433  
     {
 434  0
         LinkedHashMap<String, String> arguments = new LinkedHashMap<>( customCompilerArguments.size() );
 435  0
         for ( Map.Entry<String, String> entry : customCompilerArguments )
 436  
         {
 437  0
             arguments.put( entry.getKey(), entry.getValue() );
 438  0
         }
 439  0
         return arguments;
 440  
     }
 441  
 
 442  
     /**
 443  
      * @deprecated will be removed in 2.X use #setCustomCompilerArgumentsAsMap
 444  
      * @param customCompilerArguments
 445  
      */
 446  
     @Deprecated
 447  
     public void setCustomCompilerArguments( LinkedHashMap<String, String> customCompilerArguments )
 448  
     {
 449  0
         setCustomCompilerArgumentsAsMap( customCompilerArguments );
 450  0
     }
 451  
 
 452  
     /**
 453  
      * Get all unique argument keys and their value. In case of duplicate keys, last one added wins.
 454  
      * 
 455  
      * @return
 456  
      * @see CompilerConfiguration#getCustomCompilerArgumentsEntries()
 457  
      */
 458  
     public Map<String, String> getCustomCompilerArgumentsAsMap()
 459  
     {
 460  2
         LinkedHashMap<String, String> arguments = new LinkedHashMap<>( customCompilerArguments.size() );
 461  2
         for ( Map.Entry<String, String> entry : customCompilerArguments )
 462  
         {
 463  4
             arguments.put( entry.getKey(), entry.getValue() );
 464  4
         }
 465  2
         return arguments;
 466  
     }
 467  
 
 468  
     public void setCustomCompilerArgumentsAsMap( Map<String, String> customCompilerArguments )
 469  
     {
 470  0
         this.customCompilerArguments = new ArrayList<>();
 471  0
         if ( customCompilerArguments != null )
 472  
         {
 473  0
             this.customCompilerArguments.addAll( customCompilerArguments.entrySet() );
 474  
         }
 475  0
     }
 476  
     
 477  
     /**
 478  
      * In case argument keys are not unique, this will return all entries
 479  
      * 
 480  
      * @return
 481  
      */
 482  
     public Collection<Map.Entry<String,String>> getCustomCompilerArgumentsEntries()
 483  
     {
 484  2
         return customCompilerArguments;
 485  
     }
 486  
 
 487  
     public boolean isFork()
 488  
     {
 489  0
         return fork;
 490  
     }
 491  
 
 492  
     public void setFork( boolean fork )
 493  
     {
 494  0
         this.fork = fork;
 495  0
     }
 496  
 
 497  
     public String getMeminitial()
 498  
     {
 499  0
         return meminitial;
 500  
     }
 501  
 
 502  
     public void setMeminitial( String meminitial )
 503  
     {
 504  0
         this.meminitial = meminitial;
 505  0
     }
 506  
 
 507  
     public String getMaxmem()
 508  
     {
 509  0
         return maxmem;
 510  
     }
 511  
 
 512  
     public void setMaxmem( String maxmem )
 513  
     {
 514  0
         this.maxmem = maxmem;
 515  0
     }
 516  
 
 517  
     public String getExecutable()
 518  
     {
 519  0
         return executable;
 520  
     }
 521  
 
 522  
     public void setExecutable( String executable )
 523  
     {
 524  0
         this.executable = executable;
 525  0
     }
 526  
 
 527  
     public File getWorkingDirectory()
 528  
     {
 529  0
         return workingDirectory;
 530  
     }
 531  
 
 532  
     public void setWorkingDirectory( File workingDirectory )
 533  
     {
 534  0
         this.workingDirectory = workingDirectory;
 535  0
     }
 536  
 
 537  
     public File getBuildDirectory()
 538  
     {
 539  0
         return buildDirectory;
 540  
     }
 541  
 
 542  
     public void setBuildDirectory( File buildDirectory )
 543  
     {
 544  0
         this.buildDirectory = buildDirectory;
 545  0
     }
 546  
 
 547  
     public String getOutputFileName()
 548  
     {
 549  0
         return outputFileName;
 550  
     }
 551  
 
 552  
     public void setOutputFileName( String outputFileName )
 553  
     {
 554  0
         this.outputFileName = outputFileName;
 555  0
     }
 556  
 
 557  
     public boolean isOptimize()
 558  
     {
 559  0
         return optimize;
 560  
     }
 561  
 
 562  
     public void setOptimize( boolean optimize )
 563  
     {
 564  0
         this.optimize = optimize;
 565  0
     }
 566  
 
 567  
     public String getCompilerVersion()
 568  
     {
 569  0
         return compilerVersion;
 570  
     }
 571  
 
 572  
     public void setCompilerVersion( String compilerVersion )
 573  
     {
 574  0
         this.compilerVersion = compilerVersion;
 575  0
     }
 576  
 
 577  
     public boolean isVerbose()
 578  
     {
 579  0
         return verbose;
 580  
     }
 581  
 
 582  
     public void setVerbose( boolean verbose )
 583  
     {
 584  0
         this.verbose = verbose;
 585  0
     }
 586  
 
 587  
     public boolean isParameters()
 588  
     {
 589  0
         return parameters;
 590  
     }
 591  
 
 592  
     public void setParameters(boolean parameters)
 593  
     {
 594  0
         this.parameters = parameters;
 595  0
     }
 596  
 
 597  
     public void setProc(String proc )
 598  
     {
 599  0
         this.proc = proc;
 600  0
     }
 601  
 
 602  
     public void setGeneratedSourcesDirectory( File generatedSourcesDirectory )
 603  
     {
 604  0
         this.generatedSourcesDirectory = generatedSourcesDirectory;
 605  0
     }
 606  
 
 607  
     public File getGeneratedSourcesDirectory()
 608  
     {
 609  0
         return generatedSourcesDirectory;
 610  
     }
 611  
 
 612  
     public String getProc()
 613  
     {
 614  0
         return proc;
 615  
     }
 616  
 
 617  
     public void setAnnotationProcessors( String[] annotationProcessors )
 618  
     {
 619  0
         this.annotationProcessors = annotationProcessors;
 620  0
     }
 621  
 
 622  
     public String[] getAnnotationProcessors()
 623  
     {
 624  0
         return annotationProcessors;
 625  
     }
 626  
 
 627  
     /**
 628  
      * -processorpath parameter in jdk 1.6+. If specified, annotation processors are only searched in the processor
 629  
      * path. Otherwise they are searched in the classpath.
 630  
      *
 631  
      * @param entry processor path entry to add
 632  
      */
 633  
     public void addProcessorPathEntry(String entry) {
 634  0
         if ( processorPathEntries == null ) {
 635  0
             processorPathEntries = new LinkedList<>();
 636  
         }
 637  
 
 638  0
         processorPathEntries.add( entry );
 639  0
     }
 640  
 
 641  
     /**
 642  
      * -processorpath parameter in jdk 1.6+. If specified, annotation processors are only searched in the processor
 643  
      * path. Otherwise they are searched in the classpath.
 644  
      *
 645  
      * @return the processorPathEntries
 646  
      */
 647  
     public List<String> getProcessorPathEntries() {
 648  0
         return processorPathEntries;
 649  
     }
 650  
 
 651  
     /**
 652  
      * -processorpath parameter in jdk 1.6+. If specified, annotation processors are only searched in the processor
 653  
      * path. Otherwise they are searched in the classpath.
 654  
      *
 655  
      * @param processorPathEntries the processorPathEntries to set
 656  
      */
 657  
     public void setProcessorPathEntries(List<String> processorPathEntries) {
 658  0
         this.processorPathEntries = processorPathEntries;
 659  0
     }
 660  
 
 661  
     public CompilerReuseStrategy getCompilerReuseStrategy()
 662  
     {
 663  0
         return compilerReuseStrategy;
 664  
     }
 665  
 
 666  
     public void setCompilerReuseStrategy( CompilerReuseStrategy compilerReuseStrategy )
 667  
     {
 668  0
         this.compilerReuseStrategy = compilerReuseStrategy;
 669  0
     }
 670  
 
 671  
     /**
 672  
      * Re-use strategy of the compiler (implement for java only).
 673  
      */
 674  1
     public enum CompilerReuseStrategy
 675  
     {
 676  
         /**
 677  
          * Always reuse the same.
 678  
          * <b>Default strategy.</b>
 679  
          */
 680  1
         ReuseSame( "reuseSame" ),
 681  
         /**
 682  
          * Re-create a new compiler for each use.
 683  
          */
 684  1
         AlwaysNew( "alwaysNew" ),
 685  
         /**
 686  
          * Re-use already created compiler, create new one if non already exists.
 687  
          * <b>Will mimic a kind of pool to prevent different threads use the same.</b>
 688  
          */
 689  1
         ReuseCreated( "reuseCreated" );
 690  
 
 691  
         private String strategy;
 692  
 
 693  
         CompilerReuseStrategy( String strategy )
 694  3
         {
 695  3
             this.strategy = strategy;
 696  3
         }
 697  
 
 698  
         public String getStrategy()
 699  
         {
 700  0
             return strategy;
 701  
         }
 702  
 
 703  
         @Override
 704  
         public String toString()
 705  
         {
 706  0
             return "CompilerReuseStrategy:" + this.strategy;
 707  
         }
 708  
     }
 709  
 
 710  
     public boolean isForceJavacCompilerUse()
 711  
     {
 712  0
         return forceJavacCompilerUse;
 713  
     }
 714  
 
 715  
     public void setForceJavacCompilerUse( boolean forceJavacCompilerUse )
 716  
     {
 717  0
         this.forceJavacCompilerUse = forceJavacCompilerUse;
 718  0
     }
 719  
 }