Beispiel #1
0
    def test_add_license(self):
        f = FilteredJavaFile(
            os.path.join('sample', 'VersionInfoBeanLicensed.java'))
        f.load()
        self.assertEqual('package it.is.just.a.test;', f.contents[0].strip())

        first_line = f.contents[0]
        license = ['this', 'is', 'it']
        f.add_license(license)
        for i in range(0, len(license)):
            self.assertEqual(license[i], f.contents[i])
        self.assertEqual(first_line, f.contents[3])
Beispiel #2
0
        license_file.file_name))
    sys.exit(2)

# Load the java file
java_file = FilteredJavaFile(src_file)
try:
    java_file.load()
except:
    print('Java file {} could not be loaded.'.format(java_file.file_name))
    sys.exit(3)
if len(java_file.contents) == 0:
    print('The Java file {} is empty or broken.'.format(java_file.file_name))
    sys.exit(4)

# Save the backup file
try:
    java_file.save(java_file.file_name + '.bak')
except:
    print('Unable to create the backup for the file {}.'.format(
        java_file.file_name))
    sys.exit(5)

# Add the license and save the result
java_file.add_license(license_file.contents)
try:
    java_file.save()
except:
    print('Unable save the new version of the file {}.'.format(
        java_file.file_name))
    sys.exit(5)