private File findResourceDir(CompilerConfiguration config) { if (config.isDebug()) { System.out.println("Looking for resourcesDir"); } Map compilerArguments = config.getCustomCompilerArguments(); String tempResourcesDirAsString = (String) compilerArguments.get("-resourceDir"); File filteredResourceDir = null; if (tempResourcesDirAsString != null) { filteredResourceDir = new File(tempResourcesDirAsString); if (config.isDebug()) { System.out.println("Found resourceDir at: " + filteredResourceDir.toString()); } } else { if (config.isDebug()) { System.out.println("No resourceDir was available."); } } return filteredResourceDir; }
private void addResourceArgs(CompilerConfiguration config, List args) { File filteredResourceDir = this.findResourceDir(config); if ((filteredResourceDir != null) && filteredResourceDir.exists()) { DirectoryScanner scanner = new DirectoryScanner(); scanner.setBasedir(filteredResourceDir); scanner.setIncludes(DEFAULT_INCLUDES); scanner.addDefaultExcludes(); scanner.scan(); List includedFiles = Arrays.asList(scanner.getIncludedFiles()); for (Iterator iter = includedFiles.iterator(); iter.hasNext(); ) { String name = (String) iter.next(); File filteredResource = new File(filteredResourceDir, name); String assemblyResourceName = this.convertNameToAssemblyResourceName(name); String argLine = "/resource:\"" + filteredResource + "\",\"" + assemblyResourceName + "\""; if (config.isDebug()) { System.out.println("adding resource arg line:" + argLine); } args.add(argLine); } } }
private String[] buildCompilerArguments(CompilerConfiguration config, String[] sourceFiles) throws CompilerException { List args = new ArrayList(); if (config.isDebug()) { args.add("/debug+"); } else { args.add("/debug-"); } // config.isShowWarnings() // config.getSourceVersion() // config.getTargetVersion() // config.getSourceEncoding() // ---------------------------------------------------------------------- // // ---------------------------------------------------------------------- for (Iterator it = config.getClasspathEntries().iterator(); it.hasNext(); ) { String element = (String) it.next(); File f = new File(element); if (!f.isFile()) { continue; } args.add("/reference:\"" + element + "\""); } // ---------------------------------------------------------------------- // Main class // ---------------------------------------------------------------------- Map compilerArguments = config.getCustomCompilerArguments(); String mainClass = (String) compilerArguments.get("-main"); if (!StringUtils.isEmpty(mainClass)) { args.add("/main:" + mainClass); } // ---------------------------------------------------------------------- // Xml Doc output // ---------------------------------------------------------------------- String doc = (String) compilerArguments.get("-doc"); if (!StringUtils.isEmpty(doc)) { args.add( "/doc:" + new File(config.getOutputLocation(), config.getOutputFileName() + ".xml") .getAbsolutePath()); } // ---------------------------------------------------------------------- // Xml Doc output // ---------------------------------------------------------------------- String nowarn = (String) compilerArguments.get("-nowarn"); if (!StringUtils.isEmpty(nowarn)) { args.add("/nowarn:" + nowarn); } // ---------------------------------------------------------------------- // Out - Override output name, this is required for generating the unit test dll // ---------------------------------------------------------------------- String out = (String) compilerArguments.get("-out"); if (!StringUtils.isEmpty(out)) { args.add("/out:" + new File(config.getOutputLocation(), out).getAbsolutePath()); } else { args.add( "/out:" + new File(config.getOutputLocation(), getOutputFile(config)).getAbsolutePath()); } // ---------------------------------------------------------------------- // Resource File - compile in a resource file into the assembly being created // ---------------------------------------------------------------------- String resourcefile = (String) compilerArguments.get("-resourcefile"); if (!StringUtils.isEmpty(resourcefile)) { String resourceTarget = (String) compilerArguments.get("-resourcetarget"); args.add("/res:" + new File(resourcefile).getAbsolutePath() + "," + resourceTarget); } // ---------------------------------------------------------------------- // Target - type of assembly to produce, lib,exe,winexe etc... // ---------------------------------------------------------------------- String target = (String) compilerArguments.get("-target"); if (StringUtils.isEmpty(target)) { args.add("/target:library"); } else { args.add("/target:" + target); } // ---------------------------------------------------------------------- // remove MS logo from output (not applicable for mono) // ---------------------------------------------------------------------- String nologo = (String) compilerArguments.get("-nologo"); if (!StringUtils.isEmpty(nologo)) { args.add("/nologo"); } // ---------------------------------------------------------------------- // add any resource files // ---------------------------------------------------------------------- this.addResourceArgs(config, args); // ---------------------------------------------------------------------- // add source files // ---------------------------------------------------------------------- for (int i = 0; i < sourceFiles.length; i++) { String sourceFile = sourceFiles[i]; args.add(sourceFile); } return (String[]) args.toArray(new String[args.size()]); }
public static String[] buildCompilerArguments( CompilerConfiguration config, String[] sourceFiles) { List args = new ArrayList(); // ---------------------------------------------------------------------- // Set output // ---------------------------------------------------------------------- File destinationDir = new File(config.getOutputLocation()); args.add("-d"); args.add(destinationDir.getAbsolutePath()); // ---------------------------------------------------------------------- // Set the class and source paths // ---------------------------------------------------------------------- List classpathEntries = config.getClasspathEntries(); if (classpathEntries != null && !classpathEntries.isEmpty()) { args.add("-classpath"); args.add(getPathString(classpathEntries)); } List sourceLocations = config.getSourceLocations(); if (sourceLocations != null && !sourceLocations.isEmpty()) { args.add("-sourcepath"); args.add(getPathString(sourceLocations)); } for (int i = 0; i < sourceFiles.length; i++) { args.add(sourceFiles[i]); } if (config.isOptimize()) { args.add("-O"); } if (config.isDebug()) { args.add("-g"); } if (config.isVerbose()) { args.add("-verbose"); } if (config.isShowDeprecation()) { args.add("-deprecation"); // This is required to actually display the deprecation messages config.setShowWarnings(true); } if (!config.isShowWarnings()) { args.add("-nowarn"); } // TODO: this could be much improved if (StringUtils.isEmpty(config.getTargetVersion())) { // Required, or it defaults to the target of your JDK (eg 1.5) args.add("-target"); args.add("1.1"); } else { args.add("-target"); args.add(config.getTargetVersion()); } if (!suppressSource(config) && StringUtils.isEmpty(config.getSourceVersion())) { // If omitted, later JDKs complain about a 1.1 target args.add("-source"); args.add("1.3"); } else if (!suppressSource(config)) { args.add("-source"); args.add(config.getSourceVersion()); } if (!suppressEncoding(config) && !StringUtils.isEmpty(config.getSourceEncoding())) { args.add("-encoding"); args.add(config.getSourceEncoding()); } for (Iterator it = config.getCustomCompilerArguments().entrySet().iterator(); it.hasNext(); ) { Map.Entry entry = (Map.Entry) it.next(); String key = (String) entry.getKey(); if (StringUtils.isEmpty(key)) { continue; } args.add(key); String value = (String) entry.getValue(); if (StringUtils.isEmpty(value)) { continue; } args.add(value); } return (String[]) args.toArray(new String[args.size()]); }