Coverage Report - org.codehaus.plexus.compiler.csharp.CSharpCompiler
 
Classes in this File Line Coverage Branch Coverage Complexity
CSharpCompiler
5%
10/191
3%
4/102
4,941
 
 1  
 package org.codehaus.plexus.compiler.csharp;
 2  
 
 3  
 /*
 4  
  * Copyright 2005 The Apache Software Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *      http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import org.codehaus.plexus.compiler.AbstractCompiler;
 20  
 import org.codehaus.plexus.compiler.CompilerConfiguration;
 21  
 import org.codehaus.plexus.compiler.CompilerException;
 22  
 import org.codehaus.plexus.compiler.CompilerMessage;
 23  
 import org.codehaus.plexus.compiler.CompilerOutputStyle;
 24  
 import org.codehaus.plexus.compiler.CompilerResult;
 25  
 import org.codehaus.plexus.util.DirectoryScanner;
 26  
 import org.codehaus.plexus.util.IOUtil;
 27  
 import org.codehaus.plexus.util.Os;
 28  
 import org.codehaus.plexus.util.StringUtils;
 29  
 import org.codehaus.plexus.util.cli.CommandLineException;
 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  
 import org.codehaus.plexus.util.cli.WriterStreamConsumer;
 34  
 
 35  
 import java.io.BufferedReader;
 36  
 import java.io.File;
 37  
 import java.io.FileWriter;
 38  
 import java.io.IOException;
 39  
 import java.io.PrintWriter;
 40  
 import java.io.StringReader;
 41  
 import java.io.StringWriter;
 42  
 import java.io.Writer;
 43  
 import java.nio.file.Paths;
 44  
 import java.util.ArrayList;
 45  
 import java.util.Arrays;
 46  
 import java.util.HashSet;
 47  
 import java.util.List;
 48  
 import java.util.Map;
 49  
 import java.util.Set;
 50  
 
 51  
 /**
 52  
  * @author <a href="mailto:gdodinet@karmicsoft.com">Gilles Dodinet</a>
 53  
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
 54  
  * @author <a href="mailto:matthew.pocock@ncl.ac.uk">Matthew Pocock</a>
 55  
  * @author <a href="mailto:chris.stevenson@gmail.com">Chris Stevenson</a>
 56  
  * @plexus.component role="org.codehaus.plexus.compiler.Compiler"
 57  
  * role-hint="csharp"
 58  
  */
 59  
 public class CSharpCompiler
 60  
     extends AbstractCompiler
 61  
 {
 62  
     private static final String JAR_SUFFIX = ".jar";
 63  
     private static final String DLL_SUFFIX = ".dll";
 64  
     private static final String NET_SUFFIX = ".net";
 65  
     
 66  
     private static final String ARGUMENTS_FILE_NAME = "csharp-arguments";
 67  
 
 68  1
     private static final String[] DEFAULT_INCLUDES = { "**/**" };
 69  
 
 70  
     // ----------------------------------------------------------------------
 71  
     //
 72  
     // ----------------------------------------------------------------------
 73  
 
 74  
     public CSharpCompiler()
 75  
     {
 76  0
         super( CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES, ".cs", null, null );
 77  0
     }
 78  
 
 79  
     // ----------------------------------------------------------------------
 80  
     // Compiler Implementation
 81  
     // ----------------------------------------------------------------------
 82  
 
 83  
     public boolean canUpdateTarget( CompilerConfiguration configuration )
 84  
         throws CompilerException
 85  
     {
 86  0
         return false;
 87  
     }
 88  
 
 89  
     public String getOutputFile( CompilerConfiguration configuration )
 90  
         throws CompilerException
 91  
     {
 92  0
         return configuration.getOutputFileName() + "." + getTypeExtension( configuration );
 93  
     }
 94  
 
 95  
     public CompilerResult performCompile( CompilerConfiguration config )
 96  
         throws CompilerException
 97  
     {
 98  0
         File destinationDir = new File( config.getOutputLocation() );
 99  
 
 100  0
         if ( !destinationDir.exists() )
 101  
         {
 102  0
             destinationDir.mkdirs();
 103  
         }
 104  
 
 105  0
         config.setSourceFiles( null );
 106  
 
 107  0
         String[] sourceFiles = CSharpCompiler.getSourceFiles( config );
 108  
 
 109  0
         if ( sourceFiles.length == 0 )
 110  
         {
 111  0
             return new CompilerResult().success( true );
 112  
         }
 113  
 
 114  0
         System.out.println( "Compiling " + sourceFiles.length + " " + "source file" +
 115  0
                                 ( sourceFiles.length == 1 ? "" : "s" ) + " to " + destinationDir.getAbsolutePath() );
 116  
 
 117  0
         String[] args = buildCompilerArguments( config, sourceFiles );
 118  
 
 119  
         List<CompilerMessage> messages;
 120  
 
 121  0
         if ( config.isFork() )
 122  
         {
 123  0
             messages =
 124  0
                 compileOutOfProcess( config.getWorkingDirectory(), config.getBuildDirectory(), findExecutable( config ),
 125  
                                      args );
 126  
         }
 127  
         else
 128  
         {
 129  0
             throw new CompilerException( "This compiler doesn't support in-process compilation." );
 130  
         }
 131  
 
 132  0
         return new CompilerResult().compilerMessages( messages );
 133  
     }
 134  
 
 135  
     public String[] createCommandLine( CompilerConfiguration config )
 136  
         throws CompilerException
 137  
     {
 138  0
         return buildCompilerArguments( config, CSharpCompiler.getSourceFiles( config ) );
 139  
     }
 140  
 
 141  
     // ----------------------------------------------------------------------
 142  
     //
 143  
     // ----------------------------------------------------------------------
 144  
 
 145  
     private String findExecutable( CompilerConfiguration config )
 146  
     {
 147  0
         String executable = config.getExecutable();
 148  
 
 149  0
         if ( !StringUtils.isEmpty( executable ) )
 150  
         {
 151  0
             return executable;
 152  
         }
 153  
 
 154  0
         if ( Os.isFamily( "windows" ) )
 155  
         {
 156  0
             return "csc";
 157  
         }
 158  
 
 159  0
         return "mcs";
 160  
     }
 161  
 
 162  
     /*
 163  
 $ mcs --help
 164  
 Mono C# compiler, (C) 2001 - 2003 Ximian, Inc.
 165  
 mcs [options] source-files
 166  
    --about            About the Mono C# compiler
 167  
    -addmodule:MODULE  Adds the module to the generated assembly
 168  
    -checked[+|-]      Set default context to checked
 169  
    -codepage:ID       Sets code page to the one in ID (number, utf8, reset)
 170  
    -clscheck[+|-]     Disables CLS Compliance verifications
 171  
    -define:S1[;S2]    Defines one or more symbols (short: /d:)
 172  
    -debug[+|-], -g    Generate debugging information
 173  
    -delaysign[+|-]    Only insert the public key into the assembly (no signing)
 174  
    -doc:FILE          XML Documentation file to generate
 175  
    -keycontainer:NAME The key pair container used to strongname the assembly
 176  
    -keyfile:FILE      The strongname key file used to strongname the assembly
 177  
    -langversion:TEXT  Specifies language version modes: ISO-1 or Default
 178  
    -lib:PATH1,PATH2   Adds the paths to the assembly link path
 179  
    -main:class        Specified the class that contains the entry point
 180  
    -noconfig[+|-]     Disables implicit references to assemblies
 181  
    -nostdlib[+|-]     Does not load core libraries
 182  
    -nowarn:W1[,W2]    Disables one or more warnings
 183  
    -optimize[+|-]     Enables code optimalizations
 184  
    -out:FNAME         Specifies output file
 185  
    -pkg:P1[,Pn]       References packages P1..Pn
 186  
    -recurse:SPEC      Recursively compiles the files in SPEC ([dir]/file)
 187  
    -reference:ASS     References the specified assembly (-r:ASS)
 188  
    -target:KIND       Specifies the target (KIND is one of: exe, winexe,
 189  
                       library, module), (short: /t:)
 190  
    -unsafe[+|-]       Allows unsafe code
 191  
    -warnaserror[+|-]  Treat warnings as errors
 192  
    -warn:LEVEL        Sets warning level (the highest is 4, the default is 2)
 193  
    -help2             Show other help flags
 194  
 
 195  
 Resources:
 196  
    -linkresource:FILE[,ID] Links FILE as a resource
 197  
    -resource:FILE[,ID]     Embed FILE as a resource
 198  
    -win32res:FILE          Specifies Win32 resource file (.res)
 199  
    -win32icon:FILE         Use this icon for the output
 200  
    @file                   Read response file for more options
 201  
 
 202  
 Options can be of the form -option or /option
 203  
     */
 204  
 
 205  
     private String[] buildCompilerArguments( CompilerConfiguration config, String[] sourceFiles )
 206  
         throws CompilerException
 207  
     {
 208  0
         List<String> args = new ArrayList<String>();
 209  
 
 210  0
         if ( config.isDebug() )
 211  
         {
 212  0
             args.add( "/debug+" );
 213  
         }
 214  
         else
 215  
         {
 216  0
             args.add( "/debug-" );
 217  
         }
 218  
 
 219  
         // config.isShowWarnings()
 220  
         // config.getSourceVersion()
 221  
         // config.getTargetVersion()
 222  
         // config.getSourceEncoding()
 223  
 
 224  
         // ----------------------------------------------------------------------
 225  
         //
 226  
         // ----------------------------------------------------------------------
 227  
 
 228  0
         for ( String element : config.getClasspathEntries() )
 229  
         {
 230  0
             File f = new File( element );
 231  
 
 232  0
             if ( !f.isFile() )
 233  
             {
 234  0
                 continue;
 235  
             }
 236  
             
 237  0
             if (element.endsWith(JAR_SUFFIX)) {
 238  
                 try 
 239  
                 {
 240  0
                     File dllDir = new File(element + NET_SUFFIX);
 241  0
                     if (!dllDir.exists())
 242  
                     {
 243  0
                         dllDir.mkdir();
 244  
                     }
 245  0
                     JarUtil.extract(dllDir, new File(element));
 246  0
                     for (String tmpfile : dllDir.list()) 
 247  
                     {
 248  0
                         if ( tmpfile.endsWith(DLL_SUFFIX) )
 249  
                         {
 250  0
                             String dll = Paths.get(dllDir.getAbsolutePath(), tmpfile).toString();
 251  0
                             args.add( "/reference:\"" + dll + "\"" );
 252  
                         }
 253  
                     }
 254  
                 }
 255  0
                 catch ( IOException e )
 256  
                 {
 257  0
                     throw new CompilerException( e.toString(), e );
 258  0
                 }
 259  
             }
 260  
             else
 261  
             {
 262  0
                 args.add( "/reference:\"" + element + "\"" );
 263  
             }
 264  0
         }
 265  
 
 266  
         // ----------------------------------------------------------------------
 267  
         // Main class
 268  
         // ----------------------------------------------------------------------
 269  
 
 270  0
         Map<String, String> compilerArguments = config.getCustomCompilerArguments();
 271  
 
 272  0
         String mainClass = compilerArguments.get( "-main" );
 273  
 
 274  0
         if ( !StringUtils.isEmpty( mainClass ) )
 275  
         {
 276  0
             args.add( "/main:" + mainClass );
 277  
         }
 278  
 
 279  
         // ----------------------------------------------------------------------
 280  
         // Xml Doc output
 281  
         // ----------------------------------------------------------------------
 282  
 
 283  0
         String doc = compilerArguments.get( "-doc" );
 284  
 
 285  0
         if ( !StringUtils.isEmpty( doc ) )
 286  
         {
 287  0
             args.add( "/doc:" + new File( config.getOutputLocation(),
 288  0
                                           config.getOutputFileName() + ".xml" ).getAbsolutePath() );
 289  
         }
 290  
 
 291  
         // ----------------------------------------------------------------------
 292  
         // Xml Doc output
 293  
         // ----------------------------------------------------------------------
 294  
 
 295  0
         String nowarn = compilerArguments.get( "-nowarn" );
 296  
 
 297  0
         if ( !StringUtils.isEmpty( nowarn ) )
 298  
         {
 299  0
             args.add( "/nowarn:" + nowarn );
 300  
         }
 301  
 
 302  
         // ----------------------------------------------------------------------
 303  
         // Out - Override output name, this is required for generating the unit test dll
 304  
         // ----------------------------------------------------------------------
 305  
 
 306  0
         String out = compilerArguments.get( "-out" );
 307  
 
 308  0
         if ( !StringUtils.isEmpty( out ) )
 309  
         {
 310  0
             args.add( "/out:" + new File( config.getOutputLocation(), out ).getAbsolutePath() );
 311  
         }
 312  
         else
 313  
         {
 314  0
             args.add( "/out:" + new File( config.getOutputLocation(), getOutputFile( config ) ).getAbsolutePath() );
 315  
         }
 316  
 
 317  
         // ----------------------------------------------------------------------
 318  
         // Resource File - compile in a resource file into the assembly being created
 319  
         // ----------------------------------------------------------------------
 320  0
         String resourcefile = compilerArguments.get( "-resourcefile" );
 321  
 
 322  0
         if ( !StringUtils.isEmpty( resourcefile ) )
 323  
         {
 324  0
             String resourceTarget = (String) compilerArguments.get( "-resourcetarget" );
 325  0
             args.add( "/res:" + new File( resourcefile ).getAbsolutePath() + "," + resourceTarget );
 326  
         }
 327  
 
 328  
         // ----------------------------------------------------------------------
 329  
         // Target - type of assembly to produce, lib,exe,winexe etc... 
 330  
         // ----------------------------------------------------------------------
 331  
 
 332  0
         String target = compilerArguments.get( "-target" );
 333  
 
 334  0
         if ( StringUtils.isEmpty( target ) )
 335  
         {
 336  0
             args.add( "/target:library" );
 337  
         }
 338  
         else
 339  
         {
 340  0
             args.add( "/target:" + target );
 341  
         }
 342  
 
 343  
         // ----------------------------------------------------------------------
 344  
         // remove MS logo from output (not applicable for mono)
 345  
         // ----------------------------------------------------------------------
 346  0
         String nologo = compilerArguments.get( "-nologo" );
 347  
 
 348  0
         if ( !StringUtils.isEmpty( nologo ) )
 349  
         {
 350  0
             args.add( "/nologo" );
 351  
         }
 352  
 
 353  
         // ----------------------------------------------------------------------
 354  
         // add any resource files
 355  
         // ----------------------------------------------------------------------
 356  0
         this.addResourceArgs( config, args );
 357  
 
 358  
         // ----------------------------------------------------------------------
 359  
         // add source files
 360  
         // ----------------------------------------------------------------------
 361  0
         for ( String sourceFile : sourceFiles )
 362  
         {
 363  0
             args.add( sourceFile );
 364  
         }
 365  
 
 366  0
         return args.toArray( new String[args.size()] );
 367  
     }
 368  
 
 369  
     private void addResourceArgs( CompilerConfiguration config, List<String> args )
 370  
     {
 371  0
         File filteredResourceDir = this.findResourceDir( config );
 372  0
         if ( ( filteredResourceDir != null ) && filteredResourceDir.exists() )
 373  
         {
 374  0
             DirectoryScanner scanner = new DirectoryScanner();
 375  0
             scanner.setBasedir( filteredResourceDir );
 376  0
             scanner.setIncludes( DEFAULT_INCLUDES );
 377  0
             scanner.addDefaultExcludes();
 378  0
             scanner.scan();
 379  
 
 380  0
             List<String> includedFiles = Arrays.asList( scanner.getIncludedFiles() );
 381  0
             for ( String name : includedFiles )
 382  
             {
 383  0
                 File filteredResource = new File( filteredResourceDir, name );
 384  0
                 String assemblyResourceName = this.convertNameToAssemblyResourceName( name );
 385  0
                 String argLine = "/resource:\"" + filteredResource + "\",\"" + assemblyResourceName + "\"";
 386  0
                 if ( config.isDebug() )
 387  
                 {
 388  0
                     System.out.println( "adding resource arg line:" + argLine );
 389  
                 }
 390  0
                 args.add( argLine );
 391  
 
 392  0
             }
 393  
         }
 394  0
     }
 395  
 
 396  
     private File findResourceDir( CompilerConfiguration config )
 397  
     {
 398  0
         if ( config.isDebug() )
 399  
         {
 400  0
             System.out.println( "Looking for resourcesDir" );
 401  
         }
 402  0
         Map<String, String> compilerArguments = config.getCustomCompilerArguments();
 403  0
         String tempResourcesDirAsString = (String) compilerArguments.get( "-resourceDir" );
 404  0
         File filteredResourceDir = null;
 405  0
         if ( tempResourcesDirAsString != null )
 406  
         {
 407  0
             filteredResourceDir = new File( tempResourcesDirAsString );
 408  0
             if ( config.isDebug() )
 409  
             {
 410  0
                 System.out.println( "Found resourceDir at: " + filteredResourceDir.toString() );
 411  
             }
 412  
         }
 413  
         else
 414  
         {
 415  0
             if ( config.isDebug() )
 416  
             {
 417  0
                 System.out.println( "No resourceDir was available." );
 418  
             }
 419  
         }
 420  0
         return filteredResourceDir;
 421  
     }
 422  
 
 423  
     private String convertNameToAssemblyResourceName( String name )
 424  
     {
 425  0
         return name.replace( File.separatorChar, '.' );
 426  
     }
 427  
 
 428  
     @SuppressWarnings( "deprecation" )
 429  
     private List<CompilerMessage> compileOutOfProcess( File workingDirectory, File target, String executable,
 430  
                                                        String[] args )
 431  
         throws CompilerException
 432  
     {
 433  
         // ----------------------------------------------------------------------
 434  
         // Build the @arguments file
 435  
         // ----------------------------------------------------------------------
 436  
 
 437  
         File file;
 438  
 
 439  0
         PrintWriter output = null;
 440  
 
 441  
         try
 442  
         {
 443  0
             file = new File( target, ARGUMENTS_FILE_NAME );
 444  
 
 445  0
             output = new PrintWriter( new FileWriter( file ) );
 446  
 
 447  0
             for ( String arg : args )
 448  
             {
 449  0
                 output.println( arg );
 450  
             }
 451  
         }
 452  0
         catch ( IOException e )
 453  
         {
 454  0
             throw new CompilerException( "Error writing arguments file.", e );
 455  
         }
 456  
         finally
 457  
         {
 458  0
             IOUtil.close( output );
 459  0
         }
 460  
 
 461  
         // ----------------------------------------------------------------------
 462  
         // Execute!
 463  
         // ----------------------------------------------------------------------
 464  
 
 465  0
         Commandline cli = new Commandline();
 466  
 
 467  0
         cli.setWorkingDirectory( workingDirectory.getAbsolutePath() );
 468  
 
 469  0
         cli.setExecutable( executable );
 470  
 
 471  0
         cli.createArgument().setValue( "@" + file.getAbsolutePath() );
 472  
 
 473  0
         Writer stringWriter = new StringWriter();
 474  
 
 475  0
         StreamConsumer out = new WriterStreamConsumer( stringWriter );
 476  
 
 477  0
         StreamConsumer err = new WriterStreamConsumer( stringWriter );
 478  
 
 479  
         int returnCode;
 480  
 
 481  
         List<CompilerMessage> messages;
 482  
 
 483  
         try
 484  
         {
 485  0
             returnCode = CommandLineUtils.executeCommandLine( cli, out, err );
 486  
 
 487  0
             messages = parseCompilerOutput( new BufferedReader( new StringReader( stringWriter.toString() ) ) );
 488  
         }
 489  0
         catch ( CommandLineException e )
 490  
         {
 491  0
             throw new CompilerException( "Error while executing the external compiler.", e );
 492  
         }
 493  0
         catch ( IOException e )
 494  
         {
 495  0
             throw new CompilerException( "Error while executing the external compiler.", e );
 496  0
         }
 497  
 
 498  0
         if ( returnCode != 0 && messages.isEmpty() )
 499  
         {
 500  
             // TODO: exception?
 501  0
             messages.add( new CompilerMessage(
 502  0
                 "Failure executing the compiler, but could not parse the error:" + EOL + stringWriter.toString(),
 503  
                 true ) );
 504  
         }
 505  
 
 506  0
         return messages;
 507  
     }
 508  
 
 509  
     public static List<CompilerMessage> parseCompilerOutput( BufferedReader bufferedReader )
 510  
         throws IOException
 511  
     {
 512  3
         List<CompilerMessage> messages = new ArrayList<CompilerMessage>();
 513  
 
 514  3
         String line = bufferedReader.readLine();
 515  
 
 516  48
         while ( line != null )
 517  
         {
 518  45
             CompilerMessage compilerError = DefaultCSharpCompilerParser.parseLine( line );
 519  
 
 520  45
             if ( compilerError != null )
 521  
             {
 522  43
                 messages.add( compilerError );
 523  
             }
 524  
 
 525  45
             line = bufferedReader.readLine();
 526  45
         }
 527  
 
 528  3
         return messages;
 529  
     }
 530  
 
 531  
     private String getType( Map<String, String> compilerArguments )
 532  
     {
 533  0
         String type = compilerArguments.get( "-target" );
 534  
 
 535  0
         if ( StringUtils.isEmpty( type ) )
 536  
         {
 537  0
             return "library";
 538  
         }
 539  
 
 540  0
         return type;
 541  
     }
 542  
 
 543  
     private String getTypeExtension( CompilerConfiguration configuration )
 544  
         throws CompilerException
 545  
     {
 546  0
         String type = getType( configuration.getCustomCompilerArguments() );
 547  
 
 548  0
         if ( "exe".equals( type ) || "winexe".equals( type ) )
 549  
         {
 550  0
             return "exe";
 551  
         }
 552  
 
 553  0
         if ( "library".equals( type ) || "module".equals( type ) )
 554  
         {
 555  0
             return "dll";
 556  
         }
 557  
 
 558  0
         throw new CompilerException( "Unrecognized type '" + type + "'." );
 559  
     }
 560  
 
 561  
     // added for debug purposes.... 
 562  
     protected static String[] getSourceFiles( CompilerConfiguration config )
 563  
     {
 564  0
         Set<String> sources = new HashSet<String>();
 565  
 
 566  
         //Set sourceFiles = null;
 567  
         //was:
 568  0
         Set<File> sourceFiles = config.getSourceFiles();
 569  
 
 570  0
         if ( sourceFiles != null && !sourceFiles.isEmpty() )
 571  
         {
 572  0
             for ( File sourceFile : sourceFiles )
 573  
             {
 574  0
                 sources.add( sourceFile.getAbsolutePath() );
 575  0
             }
 576  
         }
 577  
         else
 578  
         {
 579  0
             for ( String sourceLocation : config.getSourceLocations() )
 580  
             {
 581  0
                 if (!new File(sourceLocation).exists())
 582  
                 {
 583  0
                     if ( config.isDebug() )
 584  
                     {
 585  0
                         System.out.println( "Ignoring not found sourceLocation at: " + sourceLocation );
 586  
                     }
 587  
                     continue;
 588  
                 }
 589  0
                 sources.addAll( getSourceFilesForSourceRoot( config, sourceLocation ) );
 590  0
             }
 591  
         }
 592  
 
 593  
         String[] result;
 594  
 
 595  0
         if ( sources.isEmpty() )
 596  
         {
 597  0
             result = new String[0];
 598  
         }
 599  
         else
 600  
         {
 601  0
             result = (String[]) sources.toArray( new String[sources.size()] );
 602  
         }
 603  
 
 604  0
         return result;
 605  
     }
 606  
 
 607  
     /**
 608  
      * This method is just here to maintain the public api. This is now handled in the parse
 609  
      * compiler output function.
 610  
      *
 611  
      * @author Chris Stevenson
 612  
      * @deprecated
 613  
      */
 614  
     public static CompilerMessage parseLine( String line )
 615  
     {
 616  0
         return DefaultCSharpCompilerParser.parseLine( line );
 617  
     }
 618  
 
 619  
     protected static Set<String> getSourceFilesForSourceRoot( CompilerConfiguration config, String sourceLocation )
 620  
     {
 621  0
         DirectoryScanner scanner = new DirectoryScanner();
 622  
 
 623  0
         scanner.setBasedir( sourceLocation );
 624  
 
 625  0
         Set<String> includes = config.getIncludes();
 626  
 
 627  0
         if ( includes != null && !includes.isEmpty() )
 628  
         {
 629  0
             String[] inclStrs = includes.toArray( new String[includes.size()] );
 630  0
             scanner.setIncludes( inclStrs );
 631  0
         }
 632  
         else
 633  
         {
 634  0
             scanner.setIncludes( new String[]{ "**/*.cs" } );
 635  
         }
 636  
 
 637  0
         Set<String> excludes = config.getExcludes();
 638  
 
 639  0
         if ( excludes != null && !excludes.isEmpty() )
 640  
         {
 641  0
             String[] exclStrs = excludes.toArray( new String[excludes.size()] );
 642  0
             scanner.setIncludes( exclStrs );
 643  
         }
 644  
 
 645  0
         scanner.scan();
 646  
 
 647  0
         String[] sourceDirectorySources = scanner.getIncludedFiles();
 648  
 
 649  0
         Set<String> sources = new HashSet<String>();
 650  
 
 651  0
         for ( String source : sourceDirectorySources )
 652  
         {
 653  0
             File f = new File( sourceLocation, source );
 654  
 
 655  0
             sources.add( f.getPath() );
 656  
         }
 657  
 
 658  0
         return sources;
 659  
     }
 660  
 }