use of java.util.jar.Manifest in project intellij-community by JetBrains.
the class JarsBuilder method loadManifest.
@Nullable
private Manifest loadManifest(JarInfo jar, List<String> packedFilePaths) throws IOException {
for (Pair<String, Object> pair : jar.getContent()) {
if (pair.getSecond() instanceof ArtifactRootDescriptor) {
final String rootPath = pair.getFirst();
if (!JarFile.MANIFEST_NAME.startsWith(rootPath)) {
continue;
}
final String manifestPath = JpsArtifactPathUtil.trimForwardSlashes(JarFile.MANIFEST_NAME.substring(rootPath.length()));
final ArtifactRootDescriptor descriptor = (ArtifactRootDescriptor) pair.getSecond();
if (descriptor instanceof FileBasedArtifactRootDescriptor) {
final File manifestFile = new File(descriptor.getRootFile(), manifestPath);
if (manifestFile.exists()) {
final String fullManifestPath = FileUtil.toSystemIndependentName(manifestFile.getAbsolutePath());
packedFilePaths.add(fullManifestPath);
//noinspection IOResourceOpenedButNotSafelyClosed
return createManifest(new FileInputStream(manifestFile), manifestFile);
}
} else {
final Ref<Manifest> manifestRef = Ref.create(null);
((JarBasedArtifactRootDescriptor) descriptor).processEntries(new JarBasedArtifactRootDescriptor.EntryProcessor() {
@Override
public void process(@Nullable InputStream inputStream, @NotNull String relativePath, ZipEntry entry) throws IOException {
if (manifestRef.isNull() && relativePath.equals(manifestPath) && inputStream != null) {
manifestRef.set(createManifest(inputStream, descriptor.getRootFile()));
}
}
});
if (!manifestRef.isNull()) {
return manifestRef.get();
}
}
}
}
return null;
}
use of java.util.jar.Manifest in project intellij-community by JetBrains.
the class CommandLineWrapper method loadMainClassFromClasspathJar.
private static AppData loadMainClassFromClasspathJar(File jarFile, String[] args) throws Exception {
List properties = Collections.EMPTY_LIST;
String[] mainArgs;
JarInputStream inputStream = new JarInputStream(new FileInputStream(jarFile));
try {
Manifest manifest = inputStream.getManifest();
String vmOptions = manifest != null ? manifest.getMainAttributes().getValue("VM-Options") : null;
if (vmOptions != null) {
properties = splitBySpaces(vmOptions);
}
String programParameters = manifest != null ? manifest.getMainAttributes().getValue("Program-Parameters") : null;
if (programParameters == null) {
mainArgs = new String[args.length - 2];
System.arraycopy(args, 2, mainArgs, 0, mainArgs.length);
} else {
List list = splitBySpaces(programParameters);
mainArgs = (String[]) list.toArray(new String[list.size()]);
}
} finally {
inputStream.close();
jarFile.deleteOnExit();
}
return new AppData(properties, Class.forName(args[1]), mainArgs);
}
use of java.util.jar.Manifest in project intellij-community by JetBrains.
the class AbstractEclipseClasspathReader method readRequiredBundles.
protected void readRequiredBundles(T rootModel, Set<String> refsToModules) throws ConversionException {
if (myModuleNames == null) {
return;
}
final File manifestFile = new File(myRootPath, "META-INF/MANIFEST.MF");
if (!manifestFile.exists()) {
return;
}
InputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(manifestFile));
final Manifest manifest = new Manifest(in);
final String attributes = manifest.getMainAttributes().getValue("Require-Bundle");
if (!StringUtil.isEmpty(attributes)) {
final StringTokenizer tokenizer = new StringTokenizer(attributes, ",");
while (tokenizer.hasMoreTokens()) {
String bundle = tokenizer.nextToken().trim();
if (!bundle.isEmpty()) {
final int constraintIndex = bundle.indexOf(';');
if (constraintIndex != -1) {
bundle = bundle.substring(0, constraintIndex).trim();
}
if (myModuleNames.contains(bundle)) {
refsToModules.add(bundle);
addInvalidModuleEntry(rootModel, false, bundle);
}
}
}
}
} catch (IOException e) {
throw new ConversionException(e.getMessage());
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ignored) {
}
}
}
}
use of java.util.jar.Manifest in project intellij-community by JetBrains.
the class AbstractConfigUtils method getSDKJarVersion.
/**
* Return value of Implementation-Version attribute in jar manifest
* <p/>
*
* @param jarPath directory containing jar file
* @param jarPattern filename pattern for jar file
* @param manifestPath path to manifest file in jar file
* @param versionGroup group number to get from matcher
* @return value of Implementation-Version attribute, null if not found
*/
@Nullable
public static String getSDKJarVersion(String jarPath, final Pattern jarPattern, String manifestPath, int versionGroup) {
try {
File[] jars = LibrariesUtil.getFilesInDirectoryByPattern(jarPath, jarPattern);
if (jars.length != 1) {
return null;
}
JarFile jarFile = new JarFile(jars[0]);
try {
JarEntry jarEntry = jarFile.getJarEntry(manifestPath);
if (jarEntry == null) {
return null;
}
final InputStream inputStream = jarFile.getInputStream(jarEntry);
Manifest manifest;
try {
manifest = new Manifest(inputStream);
} finally {
inputStream.close();
}
final String version = manifest.getMainAttributes().getValue(Attributes.Name.IMPLEMENTATION_VERSION);
if (version != null) {
return version;
}
final Matcher matcher = jarPattern.matcher(jars[0].getName());
if (matcher.matches() && matcher.groupCount() >= versionGroup) {
return matcher.group(versionGroup);
}
return null;
} finally {
jarFile.close();
}
} catch (Exception e) {
return null;
}
}
use of java.util.jar.Manifest in project adempiere by adempiere.
the class CLogMgt method getInfo.
// printProperties
/**
* Get Adempiere System Info
* @param sb buffer to append or null
* @return Info as multiple Line String
*/
public static StringBuffer getInfo(StringBuffer sb) {
if (sb == null)
sb = new StringBuffer();
final String eq = " = ";
sb.append(getMsg("Host")).append(eq).append(getServerInfo()).append(NL);
sb.append(getMsg("Database")).append(eq).append(getDatabaseInfo()).append(NL);
sb.append(getMsg("Schema")).append(eq).append(CConnection.get().getDbUid()).append(NL);
//
sb.append(getMsg("AD_User_ID")).append(eq).append(Env.getContext(Env.getCtx(), "#AD_User_Name")).append(NL);
sb.append(getMsg("AD_Role_ID")).append(eq).append(Env.getContext(Env.getCtx(), "#AD_Role_Name")).append(NL);
//
sb.append(getMsg("AD_Client_ID")).append(eq).append(Env.getContext(Env.getCtx(), "#AD_Client_Name")).append(NL);
sb.append(getMsg("AD_Org_ID")).append(eq).append(Env.getContext(Env.getCtx(), "#AD_Org_Name")).append(NL);
//
sb.append(getMsg("Date")).append(eq).append(Env.getContext(Env.getCtx(), "#Date")).append(NL);
sb.append(getMsg("Printer")).append(eq).append(Env.getContext(Env.getCtx(), "#Printer")).append(NL);
//
Manifest mf = ZipUtil.getManifest("CClient.jar");
if (mf == null)
mf = ZipUtil.getManifest("CTools.jar");
if (mf != null) {
Attributes atts = mf.getMainAttributes();
if (atts != null) {
Iterator<?> it = atts.keySet().iterator();
while (it.hasNext()) {
Object key = it.next();
if (key.toString().startsWith("Impl") || key.toString().startsWith("Spec"))
sb.append(key).append(eq).append(atts.get(key)).append(NL);
}
}
}
// Show Implementation Vendor / Version - teo_sarca, [ 1622855 ]
sb.append(getMsg("ImplementationVendor")).append(eq).append(org.compiere.Adempiere.getImplementationVendor()).append(NL);
sb.append(getMsg("ImplementationVersion")).append(eq).append(org.compiere.Adempiere.getImplementationVersion()).append(NL);
//
sb.append("AdempiereHome = ").append(Adempiere.getAdempiereHome()).append(NL);
sb.append("AdempiereProperties = ").append(Ini.getPropertyFileName()).append(NL);
sb.append(Env.getLanguage(Env.getCtx())).append(NL);
MClient client = MClient.get(Env.getCtx());
sb.append(client).append(NL);
sb.append(getMsg("IsMultiLingualDocument")).append(eq).append(client.isMultiLingualDocument()).append(NL);
sb.append("BaseLanguage = ").append(Env.isBaseLanguage(Env.getCtx(), "AD_Window")).append("/").append(Env.isBaseLanguage(Env.getCtx(), "C_UOM")).append(NL);
sb.append(Adempiere.getJavaInfo()).append(NL);
sb.append("java.io.tmpdir=" + System.getProperty("java.io.tmpdir")).append(NL);
sb.append(Adempiere.getOSInfo()).append(NL);
//report memory info
Runtime runtime = Runtime.getRuntime();
//max heap size
sb.append("Max Heap = " + formatMemoryInfo(runtime.maxMemory())).append(NL);
//allocated heap size
sb.append("Allocated Heap = " + formatMemoryInfo(runtime.totalMemory())).append(NL);
//free heap size
sb.append("Free Heap = " + formatMemoryInfo(runtime.freeMemory())).append(NL);
//
//thread info
sb.append("Active Threads = " + Thread.activeCount());
//
return sb;
}
Aggregations