Esempio n. 1
0
 def Run(self, staging_area, jar_file, app_dir):
     # Logic is simple: copy the jar in the staged area, and create a simple
     # file app.yaml for runtime: java11.
     shutil.copy2(jar_file, staging_area)
     files.WriteFileContents(os.path.join(staging_area, 'app.yaml'),
                             'runtime: java11\n',
                             private=True)
     manifest = jarfile.ReadManifest(jar_file)
     if manifest:
         main_entry = manifest.main_section.get('Main-Class')
         if main_entry is None:
             raise NoMainClassError()
         classpath_entry = manifest.main_section.get('Class-Path')
         if classpath_entry:
             libs = classpath_entry.split()
             for lib in libs:
                 dependent_file = os.path.join(app_dir, lib)
                 # We copy the dep jar in the correct staging sub directories
                 # and only if it exists,
                 if os.path.isfile(dependent_file):
                     destination = os.path.join(staging_area, lib)
                     files.MakeDir(
                         os.path.abspath(
                             os.path.join(destination, os.pardir)))
                     if hasattr(os, 'symlink'):
                         os.symlink(dependent_file, destination)
                     else:
                         shutil.copy(dependent_file, destination)
     return staging_area
Esempio n. 2
0
 def testManifestFromJar(self):
   # exploded_jar has a complex MANIFEST.MF entry used for testing.
   dir_name = self.Resource('tests', 'unit', 'surface', 'app', 'test_data',
                            'exploded_jar')
   with file_utils.TemporaryDirectory() as tmp_dir:
     jar_file = os.path.join(tmp_dir, 'foo.jar')
     shutil.make_archive(jar_file, 'zip', dir_name)
     manifest = jarfile.ReadManifest(jar_file + '.zip')
     self.assertIn('Manifest-Version', manifest.main_section)
     self.assertEqual(manifest.main_section['Implementation-Title'], 'Ludo')
     libs = manifest.main_section['Class-Path'].split()
     # Test only the first 3 classpath entries to validate the parsing.
     self.assertEqual(len(libs), 32)
     self.assertEqual(libs[0], 'lib/dependent.jar')
     self.assertEqual(libs[1], 'lib/google-cloud-datastore-1.6.0.jar')
     self.assertEqual(libs[2],
                      'lib/com.google.cloud.google-cloud-core-1.64.0.jar')