1 7 package org.mmbase.applications.packaging.projects.creators; 8 9 import java.io.FileOutputStream ; 10 import java.util.Date ; 11 import java.util.jar.JarOutputStream ; 12 import java.util.jar.Manifest ; 13 14 import org.mmbase.applications.packaging.ProviderManager; 15 import org.mmbase.applications.packaging.projects.Target; 16 import org.mmbase.applications.packaging.projects.packageStep; 17 import org.mmbase.util.XMLEntityResolver; 18 19 24 public class FunctionSetCreator extends BasicCreator implements CreatorInterface { 25 26 29 public final static String DTD_PACKAGING_FUNCTION_SET_1_0 = "packaging_function_set_1_0.dtd"; 30 33 public final static String PUBLIC_ID_PACKAGING_FUNCTION_SET_1_0 = "-//MMBase//DTD packaging_function_set config 1.0//EN"; 34 35 36 39 public static void registerPublicIDs() { 40 XMLEntityResolver.registerPublicID(PUBLIC_ID_PACKAGING_FUNCTION_SET_1_0, "DTD_PACKAGING_FUNCTION_SET_1_0", FunctionSetCreator.class); 41 } 42 43 44 47 public FunctionSetCreator() { 48 cl = FunctionSetCreator.class; 49 prefix = "packaging_function_set"; 50 } 51 52 53 60 public boolean createPackage(Target target, int newversion) { 61 62 clearPackageSteps(); 63 64 packageStep step = getNextPackageStep(); 66 step.setUserFeedBack("function/set packager started"); 67 68 String functionsetfile = target.getBaseDir() + getItemStringValue(target, "functionsetfile"); 69 String functionsetdir = target.getBaseDir() + getItemStringValue(target, "functionsetdir"); 70 71 step = getNextPackageStep(); 72 step.setUserFeedBack("used functionsetfile : " + functionsetfile); 73 step = getNextPackageStep(); 74 step.setUserFeedBack("used functionsetdir : " + functionsetdir); 75 76 String newfilename = getBuildPath() + getName(target).replace(' ', '_') + "@" + getMaintainer(target) + "_function_set_" + newversion; 77 try { 78 JarOutputStream jarfile = new JarOutputStream (new FileOutputStream (newfilename + ".tmp"), new Manifest ()); 79 80 step = getNextPackageStep(); 81 step.setUserFeedBack("creating package.xml file..."); 82 createPackageMetaFile(jarfile, target, newversion); 83 step.setUserFeedBack("creating package.xml file...done"); 84 step = getNextPackageStep(); 85 step.setUserFeedBack("creating depends.xml file..."); 86 createDependsMetaFile(jarfile, target); 87 step.setUserFeedBack("creating depends.xml file...done"); 88 89 addFile(jarfile, functionsetfile, "functionsetfile.xml", "functionset", ""); 90 91 int filecount = addFiles(jarfile, functionsetdir, "xml", "", "functionset", ""); 92 if (filecount == 0) { 93 step = getNextPackageStep(); 94 step.setUserFeedBack("did't add any function files, no files found"); 95 step.setType(packageStep.TYPE_WARNING); 96 } 97 jarfile.close(); 98 } catch (Exception e) { 99 e.printStackTrace(); 100 } 101 102 103 if (getErrorCount() == 0) { 105 if (renameTempFile(newfilename)) { 106 updatePackageTime(target, new Date (), newversion); 107 target.save(); 108 } 109 } 110 111 if (target.getPublishState()) { 113 ProviderManager.resetSleepCounter(); 114 step=getNextPackageStep(); 115 step.setUserFeedBack("publishing to provider : "+target.getPublishProvider()); 116 step=getNextPackageStep(); 117 step.setUserFeedBack("sending file : "+target.getId()+" ..."); 118 if (target.publish(newversion,step)) { 119 step.setUserFeedBack("sending file : "+target.getId()+" ... done"); 120 } else { 121 step.setUserFeedBack("sending file : "+target.getId()+" ... failed"); 122 } 123 } 124 125 step = getNextPackageStep(); 126 step.setUserFeedBack("function/set packager ended : " + getErrorCount() + " errors and " + getWarningCount() + " warnings"); 127 return true; 128 } 129 130 131 137 public boolean decodeItems(Target target) { 138 super.decodeItems(target); 139 decodeStringItem(target, "functionsetfile"); 140 decodeStringItem(target, "functionsetdir"); 141 return true; 142 } 143 144 145 151 public String getXMLFile(Target target) { 152 String body = getDefaultXMLHeader(target); 153 body += getDefaultXMLMetaInfo(target); 154 body += "\t<functionsetfile>" + getItemStringValue(target, "functionsetfile") + "</functionsetfile>\n"; 155 body += "\t<functionsetdir>" + getItemStringValue(target, "functionsetdir") + "</functionsetdir>\n"; 156 body += getPackageDependsXML(target); 157 body += getRelatedPeopleXML("initiators", "initiator", target); 158 body += getRelatedPeopleXML("supporters", "supporter", target); 159 body += getRelatedPeopleXML("developers", "developer", target); 160 body += getRelatedPeopleXML("contacts", "contact", target); 161 if (target.getPublishProvider()!=null) { 162 if (target.getPublishState()) { 163 body+="\t<publishprovider name=\""+target.getPublishProvider()+"\" state=\"active\" sharepassword=\""+target.getPublishSharePassword()+"\" />\n"; 164 } else { 165 body+="\t<publishprovider name=\""+target.getPublishProvider()+"\" state=\"inactive\" sharepassword=\""+target.getPublishSharePassword()+"\" />\n"; 166 } 167 } 168 body += getDefaultXMLFooter(target); 169 return body; 170 } 171 172 173 178 public void setDefaults(Target target) { 179 target.setItem("functionsetfile", "config/functions/functionsetfile.xml"); 180 target.setItem("functionsetdir", "config/functions/sets/"); 181 } 182 183 public String getDefaultTargetName() { 184 return "functionsets"; 185 } 186 187 } 188 189 | Popular Tags |