// enough alone. We copy the entire library over so the
// 'goog' dependencies will resolve without our help.
FileUtils.copyDirectory(new File(closureGoogSrcLibDirPath), new File(closureGoogTgtLibDirPath));
}
JSClosureCompilerWrapper compilerWrapper = new JSClosureCompilerWrapper();
GoogDepsWriter gdw = new GoogDepsWriter(intermediateDir, projectName, (JSGoogConfiguration) configuration);
try
{
StringBuilder depsFileData = new StringBuilder();
ok = gdw.generateDeps(problems, depsFileData);
if (!subsetGoog)
{
writeFile(depsTgtFilePath, depsFileData.toString(), false);
}
else
{
String s = depsFileData.toString();
int c = s.indexOf("'goog.");
ArrayList<String> googreqs = new ArrayList<String>();
while (c != -1)
{
int c2 = s.indexOf("'", c + 1);
String googreq = s.substring(c, c2 + 1);
googreqs.add(googreq);
c = s.indexOf("'goog.", c2);
}
HashMap<String, DependencyRecord> defmap = new HashMap<String, DependencyRecord>();
// read in goog's deps.js
FileInputStream fis = new FileInputStream(closureGoogSrcLibDirPath + "/deps.js");
Scanner scanner = new Scanner(fis, "UTF-8");
String addDependency = "goog.addDependency('";
int currentLine = 0;
while (scanner.hasNextLine())
{
String googline = scanner.nextLine();
if (googline.indexOf(addDependency) == 0)
{
int c1 = googline.indexOf("'", addDependency.length() + 1);
String googpath = googline.substring(addDependency.length(), c1);
String googdefs = googline.substring(googline.indexOf("[") + 1, googline.indexOf("]"));
String googdeps = googline.substring(googline.lastIndexOf("[") + 1, googline.lastIndexOf("]"));
String[] thedefs = googdefs.split(",");
DependencyRecord deprec = new DependencyRecord();
deprec.path = googpath;
deprec.deps = googdeps;
deprec.line = googline;
deprec.lineNumber = currentLine;
for (String def : thedefs)
{
def = def.trim();
defmap.put(def, deprec);
}
}
currentLine++;
}
// (erikdebruin) Prevent 'Resource leak' warning on line 212:
scanner.close();
ArrayList<DependencyRecord> subsetdeps = new ArrayList<DependencyRecord>();
HashMap<String, String> gotgoog = new HashMap<String, String>();
for (String req : googreqs)
{
DependencyRecord deprec = defmap.get(req);
// if we've already processed this file, skip
if (!gotgoog.containsKey(deprec.path))
{
gotgoog.put(deprec.path, null);
subsetdeps.add(deprec);
addDeps(subsetdeps, gotgoog, defmap, deprec.deps);
}
}
// now we should have the subset of files we need in the order needed
StringBuilder sb = new StringBuilder();
sb.append("goog.addDependency('base.js', ['goog'], []);\n");
File file = new File(closureGoogSrcLibDirPath + "/base.js");
FileUtils.copyFileToDirectory(file, new File(closureGoogTgtLibDirPath));
compilerWrapper.addJSSourceFile(file.getCanonicalPath());
Collections.sort(subsetdeps, new DependencyLineComparator());
for (DependencyRecord subsetdeprec : subsetdeps)
{
sb.append(subsetdeprec.line + "\n");
}
writeFile(depsTgtFilePath, sb.toString() + depsFileData.toString(), false);
// copy the required files
for (String googfn : gotgoog.keySet())
{
file = new File(closureGoogSrcLibDirPath + File.separator + googfn);
String dir = closureGoogTgtLibDirPath;
if (googfn.contains("/"))
{
dir += File.separator + googfn.substring(0, googfn.lastIndexOf("/"));
}
FileUtils.copyFileToDirectory(file, new File(dir));
compilerWrapper.addJSSourceFile(file.getCanonicalPath());
}
}
}
catch (InterruptedException e)
{
e.printStackTrace();
return false;
}
IOFileFilter pngSuffixFilter = FileFilterUtils.and(FileFileFilter.FILE,
FileFilterUtils.suffixFileFilter(".png"));
IOFileFilter gifSuffixFilter = FileFilterUtils.and(FileFileFilter.FILE,
FileFilterUtils.suffixFileFilter(".gif"));
IOFileFilter jpgSuffixFilter = FileFilterUtils.and(FileFileFilter.FILE,
FileFilterUtils.suffixFileFilter(".jpg"));
IOFileFilter assetFiles = FileFilterUtils.or(pngSuffixFilter,
jpgSuffixFilter, gifSuffixFilter);
FileUtils.copyDirectory(srcDir, intermediateDir, assetFiles);
FileUtils.copyDirectory(srcDir, releaseDir, assetFiles);
File srcDeps = new File(depsSrcFilePath);
writeHTML("intermediate", projectName, intermediateDirPath, gdw.additionalHTML);
writeHTML("release", projectName, releaseDirPath, gdw.additionalHTML);
writeCSS(projectName, intermediateDirPath);
writeCSS(projectName, releaseDirPath);
if (!subsetGoog)
{
// (erikdebruin) add 'goog' files
Collection<File> files = org.apache.commons.io.FileUtils.listFiles(new File(
closureGoogTgtLibDirPath), new RegexFileFilter("^.*(\\.js)"),
DirectoryFileFilter.DIRECTORY);
for (File file : files)
{
compilerWrapper.addJSSourceFile(file.getCanonicalPath());
}
}
// (erikdebruin) add project files
for (String filePath : gdw.filePathsInOrder)
{
compilerWrapper.addJSSourceFile(
new File(filePath).getCanonicalPath());
}
compilerWrapper.setOptions(
projectReleaseJSFilePath, useStrictPublishing);
// (erikdebruin) Include the 'goog' deps to allow the compiler to resolve
// dependencies.
compilerWrapper.addJSSourceFile(
closureGoogSrcLibDirPath + File.separator + "deps.js");
List<String> externs = ((JSGoogConfiguration)configuration).getExternalJSLib();
for (String extern : externs)
{
compilerWrapper.addJSExternsFile(extern);
}
compilerWrapper.targetFilePath = projectReleaseJSFilePath;
compilerWrapper.compile();
appendSourceMapLocation(projectReleaseJSFilePath, projectName);
if (!isMarmotinniRun)
{