1 // Copyright 2009 Google Inc. All Rights Reserved.
3 package com
.google
.appengine
.tools
.util
;
6 import java
.io
.IOException
;
7 import java
.util
.jar
.JarFile
;
8 import java
.util
.jar
.Manifest
;
9 import java
.util
.jar
.Attributes
;
12 * {@code ApiVersionFinder} extracts the {@code Specification-Version}
13 * from the Jar manifest of the specified jar file.
16 public class ApiVersionFinder
{
17 private static final String DESIRED_VENDOR_ID
= "com.google";
18 private static final String API_PACKAGE_NAME
= "com/google/appengine/api/";
20 public static void main(String
[] args
) throws IOException
{
21 ApiVersionFinder finder
= new ApiVersionFinder();
22 String apiVersion
= finder
.findApiVersion(args
[0]);
23 if (apiVersion
== null) {
27 System
.out
.println(apiVersion
);
31 public String
findApiVersion(String fileName
) throws IOException
{
32 return findApiVersion(new File(fileName
));
35 public String
findApiVersion(File inputJar
) throws IOException
{
36 JarFile jarFile
= new JarFile(inputJar
);
38 Manifest manifest
= jarFile
.getManifest();
40 if (manifest
!= null) {
41 Attributes attr
= manifest
.getAttributes(API_PACKAGE_NAME
);
43 String vendorId
= attr
.getValue(Attributes
.Name
.IMPLEMENTATION_VENDOR_ID
);
44 if (!DESIRED_VENDOR_ID
.equals(vendorId
)) {
48 return attr
.getValue(Attributes
.Name
.SPECIFICATION_VERSION
);
55 } catch (IOException ex
) {