Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / build / android / gyp / javac.py
index 9dabf70..6a3024b 100755 (executable)
@@ -10,6 +10,7 @@ import os
 import shutil
 import re
 import sys
+import textwrap
 
 from util import build_utils
 from util import md5_check
@@ -62,13 +63,6 @@ def DoJavac(
   checking will be enabled.
   """
 
-  # Compiling guava with certain orderings of input files causes a compiler
-  # crash... Sorted order works, so use that.
-  # See https://code.google.com/p/guava-libraries/issues/detail?id=950
-  # TODO(cjhopman): Remove this when we have update guava or the compiler to a
-  # version without this problem.
-  java_files.sort()
-
   jar_inputs = []
   for path in classpath:
     if os.path.exists(path + '.TOC'):
@@ -78,8 +72,8 @@ def DoJavac(
 
   javac_args = [
       '-g',
-      '-source', '1.5',
-      '-target', '1.5',
+      '-source', '1.7',
+      '-target', '1.7',
       '-classpath', ':'.join(classpath),
       '-d', classes_dir]
   if chromium_code:
@@ -106,6 +100,43 @@ def DoJavac(
       input_strings=javac_cmd)
 
 
+_MAX_MANIFEST_LINE_LEN = 72
+
+
+def CreateManifest(manifest_path, classpath, main_class=None):
+  """Creates a manifest file with the given parameters.
+
+  This generates a manifest file that compiles with the spec found at
+  http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#JAR_Manifest
+
+  Args:
+    manifest_path: The path to the manifest file that should be created.
+    classpath: The JAR files that should be listed on the manifest file's
+      classpath.
+    main_class: If present, the class containing the main() function.
+
+  """
+  output = ['Manifest-Version: 1.0']
+  if main_class:
+    output.append('Main-Class: %s' % main_class)
+  if classpath:
+    sanitized_paths = []
+    for path in classpath:
+      sanitized_paths.append(os.path.basename(path.strip('"')))
+    output.append('Class-Path: %s' % ' '.join(sanitized_paths))
+  output.append('Created-By: ')
+  output.append('')
+
+  wrapper = textwrap.TextWrapper(break_long_words=True,
+                                 drop_whitespace=False,
+                                 subsequent_indent=' ',
+                                 width=_MAX_MANIFEST_LINE_LEN - 2)
+  output = '\r\n'.join(w for l in output for w in wrapper.wrap(l))
+
+  with open(manifest_path, 'w') as f:
+    f.write(output)
+
+
 def main(argv):
   colorama.init()
 
@@ -146,11 +177,17 @@ def main(argv):
       '--classes-dir',
       help='Directory for compiled .class files.')
   parser.add_option('--jar-path', help='Jar output path.')
+  parser.add_option(
+      '--main-class',
+      help='The class containing the main method.')
 
   parser.add_option('--stamp', help='Path to touch on success.')
 
   options, args = parser.parse_args(argv)
 
+  if options.main_class and not options.jar_path:
+    parser.error('--main-class requires --jar-path')
+
   classpath = []
   for arg in options.classpath:
     classpath += build_utils.ParseGypList(arg)
@@ -172,7 +209,7 @@ def main(argv):
       java_dir = os.path.join(temp_dir, 'java')
       os.makedirs(java_dir)
       for srcjar in java_srcjars:
-        build_utils.ExtractAll(srcjar, path=java_dir)
+        build_utils.ExtractAll(srcjar, path=java_dir, pattern='*.java')
       java_files += build_utils.FindInDirectory(java_dir, '*.java')
 
     if options.javac_includes:
@@ -192,9 +229,16 @@ def main(argv):
         java_files)
 
     if options.jar_path:
+      if options.main_class:
+        manifest_file = os.path.join(temp_dir, 'manifest')
+        CreateManifest(manifest_file, classpath,
+                       options.main_class)
+      else:
+        manifest_file = None
       jar.JarDirectory(classes_dir,
                        build_utils.ParseGypList(options.jar_excluded_classes),
-                       options.jar_path)
+                       options.jar_path,
+                       manifest_file=manifest_file)
 
     if options.classes_dir:
       # Delete the old classes directory. This ensures that all .class files in