1 23 24 25 package com.sun.enterprise.tools.verifier.tests.persistence; 26 27 import com.sun.enterprise.deployment.Descriptor; 28 import com.sun.enterprise.deployment.PersistenceUnitDescriptor; 29 import com.sun.enterprise.tools.verifier.Result; 30 import com.sun.enterprise.tools.verifier.tests.VerifierCheck; 31 import com.sun.enterprise.tools.verifier.tests.VerifierTest; 32 import com.sun.enterprise.util.io.FileUtils; 33 34 import java.io.File ; 35 import java.util.ArrayList ; 36 import java.util.List ; 37 38 44 public class JarNotFound extends VerifierTest implements VerifierCheck { 45 public Result check(Descriptor descriptor) { 46 Result result = getInitializedResult(); 47 result.setStatus(Result.PASSED); 48 addErrorDetails(result, 49 getVerifierContext().getComponentNameConstructor()); 50 PersistenceUnitDescriptor pu = PersistenceUnitDescriptor.class.cast( 51 descriptor); 52 File absolutePURootFile = getAbsolutePuRootFile(pu); 53 logger.fine("Absolute PU Root: " + absolutePURootFile); 54 String absolutePuRoot = absolutePURootFile.getAbsolutePath(); 55 List <String > jarFileNames = new ArrayList <String >(pu.getJarFiles()); 56 for (String jarFileName : jarFileNames) { 57 62 String nativeJarFileName = jarFileName.replace('/', 64 File.separatorChar); 65 final File parentFile = new File (absolutePuRoot).getParentFile(); 66 File jarFile = new File (parentFile, nativeJarFileName); 68 if (!jarFile.exists()) { 69 73 String pathComponent = ""; 79 String nameComponent = jarFileName; 80 if(jarFileName.lastIndexOf("../") != -1) { 81 final int separatorIndex = jarFileName.lastIndexOf("../")+3; 82 pathComponent = jarFileName.substring(0,separatorIndex); 83 nameComponent = jarFileName.substring(separatorIndex); 84 } 85 logger.fine("For jar-file="+ jarFileName+ ", " + 86 "pathComponent=" +pathComponent + 87 ", nameComponent=" + nameComponent); 88 jarFile = new File (new File (parentFile, pathComponent), 89 FileUtils.makeFriendlyFileName(nameComponent)); 90 if (!jarFile.exists()) { 91 result.failed(smh.getLocalString( 92 getClass().getName() + "failed", 93 "[ {0} ] specified in persistence.xml does not exist in the application.", 94 new Object []{jarFileName})); 95 } 96 } 97 } 98 return result; 99 } 100 101 private File getAbsolutePuRootFile( 102 PersistenceUnitDescriptor persistenceUnitDescriptor) { 103 final String applicationLocation = 104 getVerifierContext().getAbstractArchive().getArchiveUri(); 105 File absolutePuRootFile = new File (applicationLocation, 106 persistenceUnitDescriptor.getAbsolutePuRoot().replace('/', 107 File.separatorChar)); 108 if (!absolutePuRootFile.exists()) { 109 throw new RuntimeException ( 110 absolutePuRootFile.getAbsolutePath() + " does not exist!"); 111 } 112 return absolutePuRootFile; 113 } 114 115 } 116 | Popular Tags |