📄 librarymanifestapiimporthelper.java
字号:
/**
* Copyright (c) 2003-2005 Craig Setera
* All Rights Reserved.
* Licensed under the Eclipse Public License - v 1.0
* For more information see http://www.eclipse.org/legal/epl-v10.html
*/
package eclipseme.core.importer;
import java.io.File;
import java.io.IOException;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import eclipseme.core.model.API;
import eclipseme.core.model.APIType;
import eclipseme.core.model.Version;
/**
* A helper class that will introspect a file looking for
* API information in the manifest file within the archive.
* <p />
* Copyright (c) 2003-2005 Craig Setera<br>
* All Rights Reserved.<br>
* Licensed under the Eclipse Public License - v 1.0<p/>
* <br>
* $Revision: 1.2 $
* <br>
* $Date: 2006/02/13 01:16:52 $
* <br>
* @author Craig Setera
*/
class LibraryManifestAPIImportHelper implements ILibraryAPIImportHelper {
// private static final String DEPENDENCIES = "API-Dependencies";
private static final String VERSION = "API-Specification-Version";
private static final String IDENTIFIER = "API";
private static final String NAME = "API-Name";
private static final String TYPE = "API-Type";
private static final String TYPE_PROFILE = "Profile";
private static final String TYPE_CONFIGURATION = "Configuration";
private static final String TYPE_OPTIONAL = "Optional";
/**
* Construct a new manifest API importer.
*/
LibraryManifestAPIImportHelper() {
super();
}
/**
* @see eclipseme.core.importer.ILibraryAPIImportHelper#getAPIs(java.io.File)
*/
public API[] getAPIs(File libraryFile) {
API api = null;
Attributes attributes = getAttributes(libraryFile);
if (attributes != null) {
String identifier = attributes.getValue(IDENTIFIER);
if (identifier != null) {
api = new API();
api.setIdentifier(identifier);
api.setName(attributes.getValue(NAME));
api.setType(getType(attributes));
api.setVersion(getVersion(attributes));
}
}
return (api == null) ? null : new API[] { api };
}
/**
* Return the manifest attributes for the library file or
* <code>null</code> if they could not be located.
*
* @param libraryFile
* @return
*/
private Attributes getAttributes(File libraryFile) {
Attributes attributes = null;
try {
JarFile jarFile = new JarFile(libraryFile);
if (jarFile != null) {
Manifest manifest = jarFile.getManifest();
if (manifest != null) {
attributes = manifest.getMainAttributes();
}
}
} catch (IOException e) {
}
return attributes;
}
/**
* Return the integer type of the value specified
* in the manifest.
*
* @param attributes
* @return
*/
private APIType getType(Attributes attributes) {
APIType type = APIType.UNKNOWN;
String typeString = attributes.getValue(TYPE);
if (typeString.equalsIgnoreCase(TYPE_OPTIONAL)) {
type = APIType.OPTIONAL;
} else if (typeString.equalsIgnoreCase(TYPE_PROFILE)) {
type = APIType.PROFILE;
} else if (typeString.equalsIgnoreCase(TYPE_CONFIGURATION)) {
type = APIType.CONFIGURATION;
}
return type;
}
/**
* Return the version of the API as found in the
* attributes.
*
* @param attributes
* @return
*/
private Version getVersion(Attributes attributes) {
Version version = null;
String versionString = attributes.getValue(VERSION);
if (versionString != null) {
version = new Version(versionString);
} else {
version = new Version("0.0.0");
}
return version;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -