1 19 20 package org.netbeans.nbbuild; 21 22 import java.io.File ; 23 import java.io.FileInputStream ; 24 import java.io.IOException ; 25 import java.util.Arrays ; 26 import java.util.StringTokenizer ; 27 import java.util.jar.Attributes ; 28 import java.util.jar.JarFile ; 29 import java.util.zip.CRC32 ; 30 import org.apache.tools.ant.BuildException; 31 import org.apache.tools.ant.DirectoryScanner; 32 import org.apache.tools.ant.Project; 33 import org.apache.tools.ant.Task; 34 import org.apache.tools.ant.types.FileSet; 35 36 40 public class MakeListOfNBM extends Task { 41 File outputFile = null; 42 String moduleName = null; 43 boolean pok = true; 44 FileSet fs = null; 45 46 47 public void setOutputfiledir(File s) { 48 outputFile = s; 49 log("Setting outputfile to " + s, Project.MSG_DEBUG); 50 } 51 52 public FileSet createFileSet() { 53 return (fs = new FileSet()); 54 } 55 56 57 public void setModule(String s) { 58 moduleName = s; 59 log("Setting moduleName to " + s, Project.MSG_DEBUG); 60 } 61 62 public void setTargetName(String t) { 63 pok = false; 64 log("<"+this.getTaskName()+"> attribute targetname has been DEPRECATED"); 65 } 66 67 public void execute () throws BuildException { 68 if (!pok) throw new BuildException("Use the fileset to specify the content of the NBM"); 69 if ( outputFile == null ) throw new BuildException( "You have to specify output directoty" ); 70 if ( moduleName == null ) throw new BuildException( "You have to specify the main module's file" ); 71 if ( fs == null ) throw new BuildException( "You have to specify the fileset of files included in this module" ); 72 73 log ("Generating information for Auto Update..."); 74 75 UpdateTracking track = new UpdateTracking( outputFile.getAbsolutePath() ); 76 Attributes attr; 77 JarFile jar = null; 78 File module = new File ( outputFile, moduleName ); 79 try { 80 jar = new JarFile (module); 81 attr = jar.getManifest().getMainAttributes(); 82 } catch (IOException ex) { 83 throw new BuildException("Can't get manifest attributes for module jar file "+module.getAbsolutePath(), ex, getLocation()); 84 } finally { 85 try { 86 if (jar != null) jar.close(); 87 } catch( IOException ex1 ) { 88 String exmsg = ex1.getMessage(); 89 if (exmsg == null) exmsg = "Unknown error"; 90 log("Caught I/O Exception (msg:\""+exmsg+"\") when trying to close jar file "+module.getAbsolutePath(),Project.MSG_WARN); 91 } 92 } 93 94 String codename = attr.getValue("OpenIDE-Module"); if (codename == null) { 96 throw new BuildException("Manifest in jar file "+module.getAbsolutePath()+" does not contain OpenIDE-Module", getLocation()); 97 } 98 99 String versionSpecNum = attr.getValue("OpenIDE-Module-Specification-Version"); if (versionSpecNum == null) { 101 log("Manifest in jar file "+module.getAbsolutePath()+" does not contain tag OpenIDE-Module-Specification-Version"); 102 return; 103 } 104 105 UpdateTracking.Version version = track.addNewModuleVersion( codename, versionSpecNum ); 106 107 fs.createInclude().setName("config" + File.separator + "Modules" + File.separator + track.getTrackingFileName()); 109 DirectoryScanner ds = fs.getDirectoryScanner( this.getProject() ); 111 ds.scan(); 112 113 String lmnl = this.getProject().getProperty("locmakenbm.locales"); String lmnb = this.getProject().getProperty("locmakenbm.brands"); 117 if ((!(lmnl == null)) && (!(lmnl.trim().equals("")))) { 121 java.util.StringTokenizer tokenizer = new StringTokenizer ( lmnl, ", ") ; int cntTok = tokenizer.countTokens(); 123 String [] lmnLocales = new String [cntTok]; 124 for (int j=0; j < cntTok; j++) { 125 String s = tokenizer.nextToken(); 126 lmnLocales[j] = s; 127 log(" lmnLocales[j] == "+lmnLocales[j], Project.MSG_DEBUG); } 129 130 String [] lmnBrands = null; 132 if ((!(lmnb == null)) && (!(lmnb.trim().equals("")))) { tokenizer = new StringTokenizer ( lmnb, ", ") ; cntTok = tokenizer.countTokens(); 135 lmnBrands = new String [cntTok]; 136 for (int j=0; j < cntTok; j++) { 137 String s = tokenizer.nextToken(); 138 lmnBrands[j] = s; 139 log(" lmnBrands[j] == "+lmnBrands[j], Project.MSG_DEBUG); } 141 } 142 143 145 String [] englishFiles = ds.getIncludedFiles(); 146 int sepPos, extPos; 147 String dirName, fname, filename, fext, newinc, ei_codename; 148 String moduleJar = null; 149 boolean skipLocaleDir = false; 150 for (int k=0; k < englishFiles.length; k++) { 151 if ((englishFiles[k].lastIndexOf("/locale/") >= 0) || (englishFiles[k].lastIndexOf(File.separator+"locale"+File.separator) >= 0)) { skipLocaleDir=true; 155 } else { 156 skipLocaleDir=false; 157 } 158 log("Examining file " + englishFiles[k], Project.MSG_DEBUG); 159 sepPos = englishFiles[k].lastIndexOf(File.separator); 160 if (sepPos < 0) { 161 dirName = ""; filename = englishFiles[k]; 163 } else { 164 dirName = englishFiles[k].substring(0,sepPos); 165 filename = englishFiles[k].substring(sepPos+File.separator.length()); 166 } 167 extPos = filename.lastIndexOf('.'); if (extPos < 0) { 169 fname = filename; 170 fext = ""; } else { 172 fname = filename.substring(0, extPos); 173 fext = filename.substring(extPos); 174 } 175 for (int j=0; j < lmnLocales.length; j++) { 176 if (skipLocaleDir) { 178 newinc = dirName + File.separator + fname + "_"+lmnLocales[j]+"*" + fext; } else { 180 newinc = dirName + File.separator + "locale" + File.separator + fname + "_"+lmnLocales[j]+"*" + fext; } 182 log(" adding include mask \""+newinc+"\"", Project.MSG_DEBUG); 183 fs.setIncludes( newinc ); 184 if (!(lmnBrands == null)) { 186 for (int i=0; i < lmnBrands.length; i++) { 187 if (skipLocaleDir) { 188 newinc = dirName + File.separator + fname + "_"+lmnBrands[i]+"_"+lmnLocales[j]+"*" + fext; } else { 190 newinc = dirName + File.separator + "locale" + File.separator + fname + "_"+lmnBrands[i]+"_"+lmnLocales[j]+"*" + fext; } 192 log(" adding include mask \""+newinc+"\"", Project.MSG_DEBUG); 193 fs.setIncludes( newinc ); 194 } 195 } 196 } 197 } 198 ds = fs.getDirectoryScanner(this.getProject()); 200 ds.scan(); 201 } 202 203 String include[] = ds.getIncludedFiles(); 204 log("Including files " + Arrays.toString(include), Project.MSG_VERBOSE); 205 for( int j=0; j < include.length; j++ ){ 206 try { 207 File inFile = new File ( ds.getBasedir(), include[j] ); 208 FileInputStream inFileStream = new FileInputStream ( inFile ); 209 byte array[] = new byte[ (int) inFile.length() ]; 210 CRC32 crc = new CRC32 (); 211 inFileStream.read( array ); 212 inFileStream.close(); 213 crc.update( array ); 214 String abs = inFile.getAbsolutePath(); 215 String prefix = ds.getBasedir().getAbsolutePath() + File.separatorChar; 216 if (! abs.startsWith(prefix)) throw new IllegalStateException (abs); 217 version.addFileWithCrc(abs.substring(prefix.length()).replace(File.separatorChar, '/'), Long.toString( crc.getValue() ) ); 218 } catch (IOException ex) { 219 log( ex.toString() ); 220 } 221 } 222 track.write(); 223 String moduleName = this.getProject().getProperty("module.name"); if (moduleName == null) { 225 return; 227 } 228 String [] inc = new String [include.length+2]; 229 for (int i=0; i < include.length; i++) 230 inc[i] = include[i]; 231 inc[include.length] = "config" + File.separator + "Modules" + File.separator + track.getTrackingFileName(); inc[include.length+1] = UpdateTracking.TRACKING_DIRECTORY + File.separator + track.getTrackingFileName(); 233 ModuleTracking moduleTracking = new ModuleTracking(outputFile.getParentFile().getAbsolutePath()); 235 String nbmfilename = this.getProject().getProperty("nbm"); String nbmhomepage = this.getProject().getProperty("nbm.homepage"); String nbmneedsrestart = this.getProject().getProperty("nbm.needs.restart"); String nbmreleasedate = this.getProject().getProperty("nbm.release.date"); String nbmmoduleauthor = this.getProject().getProperty("nbm.module.author"); String nbmisglobal = this.getProject().getProperty("nbm.is.global"); String nbmtargetcluster = this.getProject().getProperty("nbm.target.cluster"); moduleTracking.putModule(moduleName, codename, outputFile.getName(), nbmfilename, nbmhomepage, nbmneedsrestart, nbmreleasedate, nbmmoduleauthor, nbmisglobal, nbmtargetcluster, inc); 244 moduleTracking.write(); 245 } 246 } 247 | Popular Tags |