1 7 package org.mmbase.applications.packaging.projects; 8 9 import java.io.DataOutputStream ; 10 import java.io.File ; 11 import java.io.FileOutputStream ; 12 import java.util.ArrayList ; 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 16 import org.mmbase.applications.packaging.BundleManager; 17 import org.mmbase.applications.packaging.PackageManager; 18 import org.mmbase.applications.packaging.ProviderManager; 19 import org.mmbase.applications.packaging.bundlehandlers.BundleInterface; 20 import org.mmbase.applications.packaging.packagehandlers.PackageInterface; 21 import org.mmbase.applications.packaging.projects.creators.CreatorInterface; 22 import org.mmbase.applications.packaging.providerhandlers.ProviderInterface; 23 import org.mmbase.applications.packaging.util.ExtendedDocumentReader; 24 import org.mmbase.util.logging.Logger; 25 import org.mmbase.util.logging.Logging; 26 27 31 public class Target { 32 33 private static Logger log = Logging.getLoggerInstance(Target.class.getName()); 35 36 String name; 37 String depends; 38 String path; 39 String basedir = ""; 40 String type; 41 String publishprovider; 42 String publishsharepassword; 43 boolean publishstate; 44 boolean isbundle; 45 private ArrayList screenshots = new ArrayList (); 46 private ArrayList starturls = new ArrayList (); 47 HashMap items = new HashMap (); 48 ExtendedDocumentReader reader; 49 Project parent; 50 51 CreatorInterface creator; 52 53 54 59 public Target(Project parent,String name) { 60 this.name = name; 61 this.parent = parent; 62 depends = ""; 63 type = "basic/macro"; 64 isbundle = false; 65 } 66 67 68 73 public ExtendedDocumentReader getReader() { 74 return reader; 75 } 76 77 78 83 public String getName() { 84 return name; 85 } 86 87 88 93 public String getDepends() { 94 return depends; 95 } 96 97 public ArrayList getScreenshots() { 98 return screenshots; 99 } 100 101 public ArrayList getStarturls() { 102 return starturls; 103 } 104 105 110 public String getPath() { 111 return path; 112 } 113 114 public String getFullPath() { 115 return basedir+path; 116 } 117 118 119 124 public String getType() { 125 return type; 126 } 127 128 129 134 public void setBundle(boolean state) { 135 isbundle = state; 136 } 137 138 public String getState() { 139 return creator.getState(); 140 } 141 142 143 148 public boolean isBundle() { 149 return isbundle; 150 } 151 152 153 158 public void setCreator(CreatorInterface cr) { 159 creator = cr; 160 File file = new File (basedir + path); 161 if (file.exists()) { 162 reader = new ExtendedDocumentReader(basedir + path, creator.getClass()); 163 cr.decodeItems(this); 164 } 165 } 166 167 public CreatorInterface getCreator() { 168 return creator; 169 } 170 171 172 175 public void setDefaults() { 176 creator.setDefaults(this); 177 } 178 179 180 185 public void setDepends(String depends) { 186 this.depends = depends; 187 } 188 189 190 195 public void setBaseDir(String basedir) { 196 this.basedir = basedir; 197 } 198 199 200 205 public String getBaseDir() { 206 return basedir; 207 } 208 209 210 215 public void setPath(String path) { 216 path=path.replace('\\',File.separatorChar); 218 path=path.replace('/',File.separatorChar); 219 this.path = path; 220 } 221 222 223 228 public void setType(String type) { 229 this.type = type; 230 } 231 232 233 238 public int getLastVersion() { 239 return creator.getLastVersion(this); 240 } 241 242 243 248 public int getNextVersion() { 249 return creator.getNextVersion(this); 250 } 251 252 253 258 public String getLastDate() { 259 return creator.getLastDate(this); 260 } 261 262 public void createPackageThreaded(int version) { 263 creator.createPackageThreaded(this, version); 264 ProviderManager.resetSleepCounter(); 265 } 266 267 273 public boolean createPackage(int version) { 274 boolean result=creator.createPackage(this, version); 275 if (result) { 276 ProviderManager.resetSleepCounter(); 277 } 278 return result; 279 } 280 281 282 289 public boolean addPackageDepends(String packageid, String version) { 290 return creator.addPackageDepends(this, packageid, version); 291 } 292 293 public void addScreenshot(String name, String file, String description) { 294 screenshots.add(name); 295 screenshots.add(file); 296 screenshots.add(description); 297 } 298 299 300 public void addStarturl(String name, String link, String description) { 301 starturls.add(name); 302 starturls.add(link); 303 starturls.add(description); 304 } 305 306 307 308 316 public boolean delPackageDepends(String packageid, String version, String versionmode) { 317 return creator.delPackageDepends(this, packageid, version, versionmode); 318 } 319 320 321 331 public boolean setPackageDepends(String packageid, String oldversion, String oldversionmode, String newversion, String newversionmode) { 332 return creator.setPackageDepends(this, packageid, oldversion, oldversionmode, newversion, newversionmode); 333 } 334 335 336 341 public Iterator getPackageSteps() { 342 return creator.getPackageSteps(); 343 } 344 345 346 352 public Iterator getPackageSteps(int logid) { 353 return creator.getPackageSteps(logid); 354 } 355 356 357 360 public void clearPackageSteps() { 361 creator.clearPackageSteps(); 362 } 363 364 365 370 public String getMaintainer() { 371 return creator.getMaintainer(this); 372 } 373 374 375 380 public String getDescription() { 381 return creator.getDescription(this); 382 } 383 384 385 391 public boolean setDescription(String newdescription) { 392 return creator.setDescription(this, newdescription); 393 } 394 395 396 402 public boolean setName(String newname) { 403 return creator.setName(this, newname); 404 } 405 406 407 413 public boolean setMaintainer(String newmaintainer) { 414 return creator.setMaintainer(this, newmaintainer); 415 } 416 417 418 424 public boolean setLicenseVersion(String newlicenseversion) { 425 return creator.setLicenseVersion(this, newlicenseversion); 426 } 427 428 429 435 public boolean setLicenseType(String newlicensetype) { 436 return creator.setLicenseType(this, newlicensetype); 437 } 438 439 440 447 public boolean addPackageInitiator(String newname, String newcompany) { 448 return creator.addPackageInitiator(this, newname, newcompany); 449 } 450 451 452 461 public boolean setPackageInitiator(String oldname, String newname, String oldcompany, String newcompany) { 462 return creator.setPackageInitiator(this, oldname, newname, oldcompany, newcompany); 463 } 464 465 466 473 public boolean delPackageInitiator(String oldname, String oldcompany) { 474 return creator.delPackageInitiator(this, oldname, oldcompany); 475 } 476 477 478 486 public boolean addPackageContact(String newreason, String newname, String newemail) { 487 return creator.addPackageContact(this, newreason, newname, newemail); 488 } 489 490 491 502 public boolean setPackageContact(String oldreason, String newreason, String oldname, String newname, String oldemail, String newemail) { 503 return creator.setPackageContact(this, oldreason, newreason, oldname, newname, oldemail, newemail); 504 } 505 506 507 515 public boolean delPackageContact(String oldreason, String oldname, String oldemail) { 516 return creator.delPackageContact(this, oldreason, oldname, oldemail); 517 } 518 519 520 527 public boolean addPackageDeveloper(String newname, String newcompany) { 528 return creator.addPackageDeveloper(this, newname, newcompany); 529 } 530 531 532 541 public boolean setPackageDeveloper(String oldname, String newname, String oldcompany, String newcompany) { 542 return creator.setPackageDeveloper(this, oldname, newname, oldcompany, newcompany); 543 } 544 545 546 553 public boolean delPackageDeveloper(String oldname, String oldcompany) { 554 return creator.delPackageDeveloper(this, oldname, oldcompany); 555 } 556 557 558 564 public boolean addPackageSupporter(String newcompany) { 565 return creator.addPackageSupporter(this, newcompany); 566 } 567 568 569 576 public boolean setPackageSupporter(String oldcompany, String newcompany) { 577 return creator.setPackageSupporter(this, oldcompany, newcompany); 578 } 579 580 581 587 public boolean delPackageSupporter(String oldcompany) { 588 return creator.delPackageSupporter(this, oldcompany); 589 } 590 591 592 598 public boolean setLicenseName(String newlicensename) { 599 return creator.setLicenseName(this, newlicensename); 600 } 601 602 603 608 public String getReleaseNotes() { 609 return creator.getReleaseNotes(this); 610 } 611 612 613 618 public String getInstallationNotes() { 619 return creator.getInstallationNotes(this); 620 } 621 622 623 628 public String getPackageName() { 629 return creator.getName(this); 630 } 631 632 633 638 public String getLicenseType() { 639 return creator.getLicenseType(this); 640 } 641 642 643 648 public String getLicenseName() { 649 return creator.getLicenseName(this); 650 } 651 652 653 658 public String getLicenseVersion() { 659 return creator.getLicenseVersion(this); 660 } 661 662 663 669 public ArrayList getRelatedPeople(String type) { 670 return creator.getRelatedPeople(type, this); 671 } 672 673 674 679 public ArrayList getPackageDepends() { 680 return creator.getPackageDepends(this); 681 } 682 683 684 689 public ArrayList getIncludedPackages() { 690 if (isBundle()) { 691 return creator.getIncludedPackages(this); 692 } 693 return null; 694 } 695 696 697 703 public boolean addPackage(String newpackage) { 704 if (isBundle()) { 705 return creator.addPackage(this, newpackage); 706 } 707 return false; 708 } 709 710 711 718 public boolean setIncludedVersion(String id, String newversion) { 719 return creator.setIncludedVersion(this, id, newversion); 720 } 721 722 723 729 public boolean delIncludedPackage(String id) { 730 return creator.delIncludedPackage(this, id); 731 } 732 733 734 741 public boolean setItem(String name, Object item) { 742 items.put(name, item); 743 return true; 744 } 745 746 747 753 public Object getItem(String name) { 754 Object o = items.get(name); 755 return o; 756 } 757 758 759 764 public boolean save() { 765 String dirsp = basedir + path.substring(0, path.lastIndexOf(File.separator)); 767 File dirs = new File (dirsp); 768 if (!dirs.exists()) { 769 dirs.mkdirs(); 770 } 771 String body = creator.getXMLFile(this); 772 File sfile = new File (basedir + getPath()); 774 try { 775 DataOutputStream scan = new DataOutputStream (new FileOutputStream (sfile)); 776 scan.writeBytes(body); 777 scan.flush(); 778 scan.close(); 779 } catch (Exception e) { 780 log.error("Target can't save updated packaging file : "+basedir+getPath()); 781 } 782 return true; 783 } 784 785 786 791 public boolean hasSyntaxErrors() { 792 if (getDescription().equals("")) { 795 return true; 796 } 797 if (getMaintainer().equals("")) { 798 return true; 799 } 800 if (getDescription().equals("")) { 801 return true; 802 } 803 if (getRelatedPeople("initiators") == null || getRelatedPeople("initiators").size() == 0) { 804 return true; 805 } 806 if (getRelatedPeople("developers") == null || getRelatedPeople("developers").size() == 0) { 807 return true; 808 } 809 if (getRelatedPeople("contacts") == null || getRelatedPeople("contacts").size() == 0) { 810 return true; 811 } 812 return false; 813 } 814 815 public String getId() { 816 String id = getPackageName() + "@" + getMaintainer() + "_" + getType(); 817 id = id.replace(' ', '_'); 818 id = id.replace('/', '_'); 819 return id; 820 } 821 822 public void setPublishProvider(String publishprovider) { 823 this.publishprovider = publishprovider; 824 } 825 826 public void setPublishState(boolean publishstate) { 827 this.publishstate = publishstate; 828 } 829 830 public void setPublishSharePassword(String publishsharepassword) { 831 this.publishsharepassword = publishsharepassword; 832 } 833 834 public boolean getPublishState() { 835 return publishstate; 836 } 837 838 public String getPublishProvider() { 839 return publishprovider; 840 } 841 842 public String getPublishSharePassword() { 843 return publishsharepassword; 844 } 845 846 public boolean publish(int version,packageStep step) { 847 if (isBundle()) { 849 BundleInterface b = BundleManager.getBundle(getId(),""+version); 850 while (b==null) { 851 try { 855 Thread.sleep(1000); 856 } catch(Exception e) { 857 e.printStackTrace(); 858 } 859 b = BundleManager.getBundle(getId(),""+version); 860 } 861 ProviderInterface o=ProviderManager.getProvider(publishprovider); 862 if (o != null && b !=null) { 863 o.setPackageStep(step); 864 boolean result = o.publish(getCreator(),b,getPublishSharePassword()); 865 return result; 866 } 867 } else if (!isBundle()) { 868 PackageInterface p = PackageManager.getPackage(getId(),""+version); 869 while (p==null) { 870 try { 874 Thread.sleep(1000); 875 } catch(Exception e) { 876 e.printStackTrace(); 877 } 878 p = PackageManager.getPackage(getId(),""+version); 879 } 880 ProviderInterface o=ProviderManager.getProvider(publishprovider); 881 if (o != null && p !=null) { 882 o.setPackageStep(step); 883 boolean result = o.publish(getCreator(),p,getPublishSharePassword()); 884 return result; 885 } 886 } 887 return false; 888 } 889 890 public Project getParent() { 891 return parent; 892 } 893 894 public void addRelatedTargetsCreate(Target t) { 895 creator.addRelatedTargetsCreate(t); 896 } 897 898 public int getProgressBarValue() { 899 return creator.getProgressBarValue(); 900 } 901 902 public int getSubProgressBarValue() { 903 return creator.getSubProgressBarValue(); 904 } 905 906 } 907 908 | Popular Tags |