KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > util > BundledOptPkgHasDependencies


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * JarFileDependsOnOutsidePackage.java
26  *
27  * Created on August 30, 2004, 10:16 AM
28  */

29
30 package com.sun.enterprise.tools.verifier.tests.util;
31
32 import com.sun.enterprise.tools.verifier.Result;
33 import java.io.File JavaDoc;
34 import java.io.FileInputStream JavaDoc;
35 import java.util.StringTokenizer JavaDoc;
36 import java.util.jar.Attributes JavaDoc;
37 import java.util.jar.JarFile JavaDoc;
38 import java.util.jar.Manifest JavaDoc;
39
40 /**
41  *
42  * @author ss141213
43  * This as per J2EE 1.4 spec section#8.2. Contents from spec is given below...
44  * Only Jar format files containing class files or resources to be loaded directly
45  * by a standard ClassLoader should be the target of a Class-Path reference;
46  * such files are always named with a .jar extension.
47  * Top level Jar files that are processed by a deployment tool
48  * should not contain Class-Path entries;
49  * such entries would, by definition,
50  * reference other files external to the deployment unit.
51  * A deployment tool is not required to process such external references.
52   */

53 public class BundledOptPkgHasDependencies {
54     public static void test(String JavaDoc explodedJarPath, Result result){
55         try{
56             boolean failed=false;
57             Manifest JavaDoc manifest=new Manifest JavaDoc(new FileInputStream JavaDoc(new File JavaDoc(explodedJarPath+File.separator+JarFile.MANIFEST_NAME)));
58             String JavaDoc depClassPath=manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
59             if(depClassPath!=null){
60                 for(StringTokenizer JavaDoc st=new StringTokenizer JavaDoc(depClassPath);st.hasMoreTokens();){
61                     String JavaDoc entry=st.nextToken();
62                     String JavaDoc entryPath=new File JavaDoc(explodedJarPath).getParent()+File.separator+entry;
63                     File JavaDoc bundledOptPkg=new File JavaDoc(entryPath);
64                     if(!bundledOptPkg.isDirectory()){
65                         Manifest JavaDoc bundledManifest=new JarFile JavaDoc(bundledOptPkg).getManifest();
66                         String JavaDoc bundledCP=bundledManifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
67                         if(bundledCP!=null && bundledCP.length()!=0){
68                             failed=true;
69                             result.failed(entry + " contains Class-Path in it's manifest.");
70                         }
71                     }
72                 }
73             }//if
74
if(!failed){
75                 result.setStatus(Result.PASSED);
76             }
77         }catch(Exception JavaDoc e){
78             result.failed(e.toString());
79         }
80     }
81 }
82
Popular Tags