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