Skip to content

Instantly share code, notes, and snippets.

@kaakaa
Created January 11, 2016 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaakaa/59c97694e5a40d0c0993 to your computer and use it in GitHub Desktop.
Save kaakaa/59c97694e5a40d0c0993 to your computer and use it in GitHub Desktop.
Manifest.mfを解析する
@Grapes(
@Grab(group='org.apache.ivy', module='ivy', version='2.3.0')
)
import org.apache.ivy.osgi.core.BundleInfo
import org.apache.ivy.osgi.core.ManifestParser
def root = /./ as File
def finder = new Finder()
finder.deepFind(root)
finder.analyze()
println finder.getDefines()
println finder.getDefines().size()
class Finder {
private static final manifestFilter = { it.isDirectory() && new File(it, 'META-INF/MANIFEST.MF').exists()} as FileFilter
private static final jardescFilter = { it.isFile() && it.name.equals('.jardesc') } as FileFilter
def projects = new ArrayList<Project>()
def deepFind(File dir) {
find(dir)
dir.listFiles({it.isDirectory()} as FileFilter).each { deepFind(it) }
}
private void find(File dir) {
dir.listFiles(manifestFilter).each { projects << new EclipsePluginProject(it.name, new File(it, 'META-INF/MANIFEST.MF')) }
dir.listFiles(jardescFilter).each { projects << new JavaProject(it.name, new File(it, '.jardesc')) }
}
def analyze(){
projects.each { it.analyze() }
}
def getDefines() {
return projects.collect { it.toString() }
}
}
interface Project {
public void analyze()
public String toString()
}
class JavaProject implements Project {
def name
def jardescFile
def JavaProject(String name, File jardesc) {
this.name = name
this.jardescFile = jardesc
}
public void analyze() {
}
public String toString() {
def builder = new StringBuilder()
// name
builder.append(this.name).append(',')
// jar name
return builder.toString()
}
}
class EclipsePluginProject implements Project {
def name
def manifestFile
def bundleInfo
def EclipsePluginProject(String name, File manifest) {
this.name = name
this.manifestFile = manifest
}
public void analyze() {
this.manifestFile.eachLine { line ->
if(line.startsWith('Bundle-Name: ')) { println line }
}
this.bundleInfo = ManifestParser.parseManifest(this.manifestFile)
}
// plugin name, description, symbolic name, version
public String toString() {
def builder = new StringBuilder()
// plugin name
builder.append(this.bundleInfo.getPresentationName()).append(',')
// description
builder.append(this.bundleInfo.getDescription()).append(',')
// symbolic name
builder.append(this.bundleInfo.getSymbolicName()).append(',')
// version
builder.append(this.bundleInfo.getVersion())
return builder.toString()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment