Skip to content

Instantly share code, notes, and snippets.

@jetgeng
Created October 17, 2012 13:56
Show Gist options
  • Save jetgeng/3905638 to your computer and use it in GitHub Desktop.
Save jetgeng/3905638 to your computer and use it in GitHub Desktop.
Generator pom.xml for tycho
'''
Created on Oct 17, 2012
@author: gengjet
'''
from mako.template import Template
import os
import re
BundleName = "Bundle-Name"
BundleSymbolicName = "Bundle-SymbolicName"
BundleVersion = "Bundle-Version"
pomContent = '''
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>parent</artifactId>
<groupId>com.easyway.esuite</groupId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../ESuite-SDK/pom.xml</relativePath>
</parent>
<groupId>${BundleSymbolicName}</groupId>
<artifactId>${BundleSymbolicName}</artifactId>
<version>${BundleVersion}</version>
<packaging>eclipse-plugin</packaging>
<name>${BundleName}</name>
</project>
'''
pomTemplate = Template(pomContent)
FilterPattern = re.compile(';.*')
def walk_dir(dir):
for path in os.listdir(dir):
bundinfo = ParseManifestFile( os.path.join(dir,path,"META-INF" , "MANIFEST.MF") )
if len(bundinfo) > 0 :
#Generator pom file and save it to the os.path.join(dir,path)
pomFile = open(os.path.join(dir,path,"pom.xml"),'w')
pomFile.write(pomTemplate.render(**bundinfo))
pomFile.close()
def ParseManifestFile(fileName):
info = {}
if os.path.isfile(fileName) :
manifestFile = open(fileName, "r")
for line in manifestFile:
if line.startswith((BundleName , BundleSymbolicName , BundleVersion)) :
bundleInfo = line.split(": ")
info[bundleInfo[0].replace('-','') ] = FilterPattern.sub('' , bundleInfo[1]).strip()
manifestFile.close()
return info
if __name__ == '__main__':
walk_dir("./plugins")
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment