1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
10 * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar
11 *******************************************************************************/
12 package org.eclipse.jdt.internal.ui.jarpackagerfat;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.util.Iterator;
17 import java.util.List;
19 import java.util.jar.Attributes;
20 import java.util.jar.Manifest;
22 import org.eclipse.core.runtime.CoreException;
24 import org.eclipse.jdt.core.IPackageFragment;
26 import org.eclipse.jdt.ui.jarpackager.IManifestProvider;
27 import org.eclipse.jdt.ui.jarpackager.JarPackageData;
30 * A manifest provider creates manifest files for a fat jar.
34 public class FatJarManifestProvider implements IManifestProvider {
36 public static final String SEALED_VALUE= "true"; //$NON-NLS-1$
37 public static final String UNSEALED_VALUE= "false"; //$NON-NLS-1$
39 FatJarBuilder fBuilder;
41 public FatJarManifestProvider(FatJarBuilder builder) {
48 public Manifest create(JarPackageData jarPackage) throws CoreException {
50 Manifest ownManifest= createOwn(jarPackage);
51 return fBuilder.generated_4550296889019119873(this, jarPackage, ownManifest);
54 void setManifestClasspath(Manifest ownManifest, String manifestClasspath) {
55 if ((manifestClasspath != null) && !manifestClasspath.trim().equals("")) { //$NON-NLS-1$
56 Attributes mainAttr= ownManifest.getMainAttributes();
57 mainAttr.putValue("Class-Path", manifestClasspath); //$NON-NLS-1$
61 Manifest merge(Manifest ownManifest, List<Manifest> otherManifests) {
62 Manifest mergedManifest= new Manifest(ownManifest);
63 Map<String, Attributes> mergedEntries= mergedManifest.getEntries();
64 for (Iterator<Manifest> iter= otherManifests.iterator(); iter.hasNext();) {
65 Manifest otherManifest= iter.next();
66 Map<String, Attributes> otherEntries= otherManifest.getEntries();
67 for (Iterator<String> iterator= otherEntries.keySet().iterator(); iterator.hasNext();) {
68 String attributeName= iterator.next();
69 if (mergedEntries.containsKey(attributeName)) {
72 mergedEntries.put(attributeName, otherEntries.get(attributeName));
76 return mergedManifest;
79 private Manifest createOwn(JarPackageData jarPackage) throws CoreException {
80 return jarPackage.generated_6092720410613538293(this);
86 public Manifest createDefault(String manifestVersion) {
87 Manifest manifest= new Manifest();
88 manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, manifestVersion);
93 * Hook for subclasses to add additional manifest entries.
95 * @param manifest the manifest to which the entries should be added
96 * @param jarPackage the JAR package specification
98 protected void putAdditionalEntries(Manifest manifest, JarPackageData jarPackage) {
101 public Manifest createGeneratedManifest(JarPackageData jarPackage) {
102 Manifest manifest= jarPackage.generated_4521662842632988270(this);
103 putAdditionalEntries(manifest, jarPackage);
107 public void putVersion(Manifest manifest, JarPackageData jarPackage) {
108 manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, jarPackage.getManifestVersion());
111 public void putSealing(Manifest manifest, JarPackageData jarPackage) {
112 jarPackage.generated_5948248238074113241(manifest, this);
115 public void putMainClass(Manifest manifest, JarPackageData jarPackage) {
116 jarPackage.generated_4199067722412062797(manifest);
119 public String getInManifestFormat(IPackageFragment packageFragment) {
120 String name= packageFragment.getElementName();
121 return name.replace('.', '/') + '/';
124 public Manifest createSuppliedManifest(JarPackageData jarPackage) throws CoreException, IOException {
126 // No need to use buffer here because Manifest(...) does
127 InputStream stream= jarPackage.getManifestFile().getContents(false);
129 manifest= new Manifest(stream);