Search in sources :

Example 26 with Attributes

use of java.util.jar.Attributes in project intellij-community by JetBrains.

the class JarLoader method getAttributes.

@Nullable
private static Map<Resource.Attribute, String> getAttributes(ZipFile zipFile) {
    ZipEntry entry = zipFile.getEntry(JarFile.MANIFEST_NAME);
    if (entry == null)
        return null;
    Map<Resource.Attribute, String> map = null;
    try {
        InputStream stream = zipFile.getInputStream(entry);
        try {
            Attributes attributes = new Manifest(stream).getMainAttributes();
            for (Pair<Resource.Attribute, Attributes.Name> p : PACKAGE_FIELDS) {
                String value = attributes.getValue(p.second);
                if (value != null) {
                    if (map == null)
                        map = new EnumMap<Resource.Attribute, String>(Resource.Attribute.class);
                    map.put(p.first, value);
                }
            }
        } finally {
            stream.close();
        }
    } catch (Exception ignored) {
    }
    return map;
}
Also used : InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Example 27 with Attributes

use of java.util.jar.Attributes in project intellij-community by JetBrains.

the class PrepareToDeployAction method createOrFindManifest.

public static Manifest createOrFindManifest(final PluginBuildConfiguration pluginModuleBuildProperties) throws IOException {
    final Manifest manifest = new Manifest();
    final VirtualFile vManifest = pluginModuleBuildProperties.getManifest();
    if (pluginModuleBuildProperties.isUseUserManifest() && vManifest != null) {
        InputStream in = null;
        try {
            in = new BufferedInputStream(vManifest.getInputStream());
            manifest.read(in);
        } finally {
            if (in != null)
                in.close();
        }
    } else {
        Attributes mainAttributes = manifest.getMainAttributes();
        ManifestBuilder.setGlobalAttributes(mainAttributes);
    }
    return manifest;
}
Also used : Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest)

Example 28 with Attributes

use of java.util.jar.Attributes 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;
}
Also used : Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest) MClient(org.compiere.model.MClient)

Example 29 with Attributes

use of java.util.jar.Attributes in project sling by apache.

the class BSNRenamer method processManifest.

protected Manifest processManifest(Manifest inputMF) {
    Attributes inputAttrs = inputMF.getMainAttributes();
    String orgBSN = inputAttrs.getValue(BUNDLE_SYMBOLIC_NAME);
    Manifest newMF = new Manifest(inputMF);
    Attributes outputAttrs = newMF.getMainAttributes();
    outputAttrs.putValue(BUNDLE_SYMBOLIC_NAME, newBSN);
    outputAttrs.putValue(X_ORIG_BSN, orgBSN);
    return newMF;
}
Also used : Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest)

Example 30 with Attributes

use of java.util.jar.Attributes in project sling by apache.

the class BundleFileProcessorTest method testBSNRenaming.

@Test
public void testBSNRenaming() throws IOException {
    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    // Just take any bundle from the maven deps as an example...
    File originalFile = getMavenArtifactFile(getMavenRepoRoot(), "com.google.guava", "guava", "15.0");
    File generatedFile = new BSNRenamer(originalFile, tempDir, "org.acme.baklava.guava").process();
    try {
        compareJarContents(originalFile, generatedFile);
        JarFile jfOrg = null;
        JarFile jfNew = null;
        try {
            jfOrg = new JarFile(originalFile);
            jfNew = new JarFile(generatedFile);
            Manifest mfOrg = jfOrg.getManifest();
            Manifest mfNew = jfNew.getManifest();
            Attributes orgAttrs = mfOrg.getMainAttributes();
            Attributes newAttrs = mfNew.getMainAttributes();
            for (Object key : orgAttrs.keySet()) {
                String orgVal = orgAttrs.getValue(key.toString());
                String newVal = newAttrs.getValue(key.toString());
                if ("Bundle-SymbolicName".equals(key.toString())) {
                    assertEquals("Should have recorded the original Bundle-SymbolicName", orgVal, newAttrs.getValue("X-Original-Bundle-SymbolicName"));
                    assertEquals("org.acme.baklava.guava", newVal);
                } else {
                    assertEquals("Different keys: " + key, orgVal, newVal);
                }
            }
        } finally {
            closeQuietly(jfOrg);
            closeQuietly(jfNew);
        }
    } finally {
        assertTrue("Unable to delete temporary file", generatedFile.delete());
    }
}
Also used : Attributes(java.util.jar.Attributes) JarFile(java.util.jar.JarFile) Manifest(java.util.jar.Manifest) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Aggregations

Attributes (java.util.jar.Attributes)631 Manifest (java.util.jar.Manifest)358 IOException (java.io.IOException)152 File (java.io.File)143 JarFile (java.util.jar.JarFile)106 URL (java.net.URL)92 Map (java.util.Map)78 InputStream (java.io.InputStream)62 HashMap (java.util.HashMap)62 Jar (aQute.bnd.osgi.Jar)49 Builder (aQute.bnd.osgi.Builder)43 ArrayList (java.util.ArrayList)43 ByteArrayOutputStream (java.io.ByteArrayOutputStream)42 Test (org.junit.Test)41 ZipEntry (java.util.zip.ZipEntry)39 FileOutputStream (java.io.FileOutputStream)37 JarOutputStream (java.util.jar.JarOutputStream)36 ByteArrayInputStream (java.io.ByteArrayInputStream)33 FileInputStream (java.io.FileInputStream)33 JarEntry (java.util.jar.JarEntry)32