Source Code Cross Referenced for ManifestModifier.java in  » IDE-Eclipse » Eclipse-plug-in-development » org » eclipse » pde » internal » build » tasks » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » Eclipse plug in development » org.eclipse.pde.internal.build.tasks 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         * 
008:         * Contributors:
009:         *     IBM - Initial API and implementation
010:         *******************************************************************************/package org.eclipse.pde.internal.build.tasks;
011:
012:        import java.io.*;
013:        import java.util.*;
014:        import java.util.jar.Attributes;
015:        import java.util.jar.Manifest;
016:        import java.util.jar.Attributes.Name;
017:        import org.apache.tools.ant.BuildException;
018:        import org.apache.tools.ant.Task;
019:
020:        /**
021:         * Internal task. 
022:         * Add, change or remove the keys from a manifest.mf.
023:         * @since 3.0 
024:         */
025:        public class ManifestModifier extends Task {
026:            private String manifestLocation;
027:            private Map newValues = new HashMap();
028:            private static String DELIM = "#|"; //$NON-NLS-1$
029:            private Manifest manifest = null;
030:            private boolean contentChanged = false;
031:
032:            /**
033:             * Indicate new values to add to the manifest. The format of the parameter is key|value#key|value#...
034:             * If a value is specified to null, the key will be removed from the manifest. 
035:             * @param values
036:             */
037:            public void setKeyValue(String values) {
038:                StringTokenizer tokenizer = new StringTokenizer(values, DELIM,
039:                        false);
040:                while (tokenizer.hasMoreElements()) {
041:                    String key = tokenizer.nextToken();
042:                    String value = tokenizer.nextToken();
043:                    if (value.equals("null")) //$NON-NLS-1$
044:                        value = null;
045:                    newValues.put(key, value);
046:                }
047:            }
048:
049:            public void execute() {
050:                loadManifest();
051:
052:                applyChanges();
053:
054:                writeManifest();
055:            }
056:
057:            private void writeManifest() {
058:                if (!contentChanged)
059:                    return;
060:
061:                OutputStream os = null;
062:                try {
063:                    os = new BufferedOutputStream(new FileOutputStream(
064:                            manifestLocation));
065:                    try {
066:                        manifest.write(os);
067:                    } finally {
068:                        os.close();
069:                    }
070:                } catch (IOException e1) {
071:                    new BuildException(
072:                            "Problem writing the content of the manifest : " + manifestLocation); //$NON-NLS-1$
073:                }
074:            }
075:
076:            private void applyChanges() {
077:                for (Iterator iter = newValues.entrySet().iterator(); iter
078:                        .hasNext();) {
079:                    Map.Entry entry = (Map.Entry) iter.next();
080:                    String key = (String) entry.getKey();
081:                    String value = (String) entry.getValue();
082:                    if (value == null) {
083:                        removeAttribute(key);
084:                    } else {
085:                        changeValue(key, value);
086:                    }
087:                }
088:                //force a manifest version if none exists
089:                if (!manifest.getMainAttributes().containsKey(
090:                        Name.MANIFEST_VERSION)) {
091:                    contentChanged = true;
092:                    manifest.getMainAttributes().put(Name.MANIFEST_VERSION,
093:                            "1.0"); //$NON-NLS-1$
094:                }
095:
096:            }
097:
098:            private void loadManifest() {
099:                try {
100:                    InputStream is = new BufferedInputStream(
101:                            new FileInputStream(manifestLocation));
102:                    try {
103:                        manifest = new Manifest(is);
104:                    } finally {
105:                        is.close();
106:                    }
107:                } catch (IOException e) {
108:                    new BuildException(
109:                            "Problem reading the content of the manifest : " + manifestLocation); //$NON-NLS-1$
110:                }
111:            }
112:
113:            private void changeValue(String key, String value) {
114:                if (manifest.getMainAttributes().getValue(key).equals(value))
115:                    return;
116:                contentChanged = true;
117:                manifest.getMainAttributes().put(new Attributes.Name(key),
118:                        value);
119:            }
120:
121:            private void removeAttribute(String key) {
122:                contentChanged = true;
123:                manifest.getMainAttributes().remove(new Attributes.Name(key));
124:            }
125:
126:            /**
127:             * 
128:             * @param path
129:             */
130:            public void setManifestLocation(String path) {
131:                manifestLocation = path;
132:            }
133:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.