Revision 42881 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.installer/org.gvsig.installer.lib/org.gvsig.installer.lib.impl/src/main/java/org/gvsig/installer/lib/impl/DefaultPackageInfo.java

View differences:

DefaultPackageInfo.java
36 36
import java.util.ArrayList;
37 37
import java.util.Iterator;
38 38
import java.util.List;
39
import org.apache.commons.lang3.StringUtils;
39 40

  
40 41
import org.gvsig.installer.lib.api.Dependencies;
41 42
import org.gvsig.installer.lib.api.InstallerLocator;
......
79 80
    private Boolean broken = false;
80 81

  
81 82
    private String state = STATE.DEVEL;
82
    private String operatingSystem = OS.ALL;
83
//    private String operatingSystem = OS.ALL;
84
    private String operatingSystemFamily = OS.ALL;
85
    private String operatingSystemName = null;
86
    private String operatingSystemVersion = null;
87
    
83 88
    private String architecture = ARCH.ALL;
84 89
    private String javaVM = JVM.J1_5;
85 90

  
......
239 244
        this.official = official;
240 245
    }
241 246

  
247
    @Override
242 248
    public String getOperatingSystem() {
243
        return operatingSystem;
249
        StringBuilder operatingSystem = new StringBuilder();
250
        operatingSystem.append(this.operatingSystemFamily);
251
        if( !StringUtils.isEmpty(this.operatingSystemName) ) {
252
            operatingSystem.append("_");
253
            operatingSystem.append(this.operatingSystemName);
254
            if( !StringUtils.isEmpty(this.operatingSystemVersion) ) {
255
                operatingSystem.append("_");
256
                operatingSystem.append(this.operatingSystemVersion);
257
            }
258
        }
259
        return operatingSystem.toString();
244 260
    }
245 261

  
262
    @Override
246 263
    public void setOperatingSystem(String operatingSystem) {
247
        this.operatingSystem = operatingSystem;
264
    	if( StringUtils.isEmpty(operatingSystem) ) {
265
    		this.operatingSystemFamily = OS.ALL;
266
    		this.operatingSystemName = null;
267
    		this.operatingSystemVersion = null;
268
    	} else {
269
            if( operatingSystem.contains("_") ) {
270
                String s[] = operatingSystem.split("_");
271
                switch(s.length) {
272
                    case 2:
273
                        this.operatingSystemFamily = s[0];
274
                        this.operatingSystemName = s[1];
275
                        break;
276
                    case 3:
277
                        this.operatingSystemFamily = s[0];
278
                        this.operatingSystemName = s[1];
279
                        this.operatingSystemVersion = s[2];
280
                        break;
281
                    default:
282
                        throw new IllegalArgumentException("Can't parse OS '"+operatingSystem+"'.");
283
                }
284
            } else {
285
                this.operatingSystemFamily = operatingSystem;
286
            }
287
    	}
248 288
    }
289
    
290
    @Override
291
    public String getOperatingSystemFamily() {
292
        return this.operatingSystemFamily;
293
    }
294
    
295
    @Override
296
    public String getOperatingSystemName() {
297
        return this.operatingSystemName;
298
    }
299
    
300
    @Override
301
    public String getOperatingSystemVersion() {
302
        return this.operatingSystemVersion;
303
    }
249 304

  
305
    public void setOperatingSystemFamily(String operatingSystemFamily) {
306
        this.operatingSystemFamily = operatingSystemFamily;
307
    }
308
    
309
    public void setOperatingSystemName(String operatingSystemName) {
310
        this.operatingSystemName = operatingSystemName;
311
    }
312
    
313
    public void setOperatingSystemVersion(String operatingSystemVersion) {
314
        this.operatingSystemVersion = operatingSystemVersion;
315
    }
316

  
250 317
    public String getArchitecture() {
251 318
        return architecture;
252 319
    }
......
408 475
            .format(
409 476
                "%1$-8.8s %2$-40s %3$-20.20s %4$-5.5s %5$-5.5s %6$-6.6s %7$-5.5s %8$s %8$s",
410 477
                this.type, this.code, this.version, this.state,
411
                this.operatingSystem, this.architecture, this.javaVM,
478
                this.getOperatingSystem(), this.architecture, this.javaVM,
412 479
                this.dependencies, this.getAliasAsString());
413 480
    }
414 481

  
......
560 627
        return delete.delete(folder);
561 628
    }
562 629

  
630
    @Override
563 631
    public boolean matchID(String string) {
632
        final int PART_CODE = 0;
633
        final int PART_VERSION = 1;
634
        final int PART_OS = 2;
635
        final int PART_ARCH = 3;
636
        
564 637
        String id = this.getID();
565
        String[] stringParts = string.split("#");
638
        String[] parts = string.split("#");
566 639

  
567
        switch (stringParts.length) {
640
        switch (parts.length) {
568 641
        case 1:
569
            if (stringParts[0].equals(this.getCode())) {
642
            if (parts[PART_CODE].equals(this.getCode())) {
570 643
                return true;
571 644
            } else {
572 645
                return false;
573 646
            }
574 647
        case 2:
575
            if (!stringParts[0].equals(this.getCode())) {
648
            if (!parts[PART_CODE].equals(this.getCode())) {
576 649
                return false;
577 650
            }
578 651
            Version version = new DefaultVersion();
579 652
            try {
580
                version.parse(stringParts[1]);
653
                version.parse(parts[PART_VERSION]);
581 654
            } catch (InvalidParameterException ex) {
582 655
                return false;
583 656
            }
......
587 660
            }
588 661
            return false;
589 662
        case 4: // id, version, os, arch
590
            if (!stringParts[0].equals(this.getCode())) {
663
            if (!parts[PART_CODE].equals(this.getCode())) {
591 664
                return false;
592 665
            }
593
            if( !"any".equalsIgnoreCase(stringParts[1]) ) {
666
            if( !"any".equalsIgnoreCase(parts[PART_VERSION]) ) {
594 667
                version = new org.gvsig.tools.packageutils.impl.DefaultVersion();
595 668
                try {
596
                    version.parse(stringParts[1]);
669
                    version.parse(parts[PART_VERSION]);
597 670
                } catch (InvalidParameterException ex) {
598 671
                    return false;
599 672
                }
......
602 675
                    return false;
603 676
                }
604 677
            }
605
            if( !"any".equalsIgnoreCase(stringParts[2]) ) {
606
                if( "current".equalsIgnoreCase(stringParts[2]) ) {
607
                    if( !this.getOperatingSystem().equalsIgnoreCase(this.getPackageManager().getOperatingSystem()) ) {
678
            if( !"any".equalsIgnoreCase(parts[PART_OS]) ) {
679
                if( "current".equalsIgnoreCase(parts[PART_OS]) ) {
680
                    if( !this.getOperatingSystemFamily().equalsIgnoreCase(this.getPackageManager().getOperatingSystemFamily()) ) {
608 681
                        return false;
609 682
                    }
610
                } else if( !this.getOperatingSystem().equalsIgnoreCase(stringParts[2]) ) {
683
                    if( !StringUtils.isEmpty(this.getOperatingSystemName())) {
684
                        if( !this.getOperatingSystemName().equalsIgnoreCase(this.getPackageManager().getOperatingSystemName()) ) {
685
                            return false;
686
                        }
687
                        if( !StringUtils.isEmpty(this.getOperatingSystemVersion())) {
688
                            if( !this.getOperatingSystemVersion().equalsIgnoreCase(this.getPackageManager().getOperatingSystemVersion()) ) {
689
                                return false;
690
                            }
691
                        }
692
                    }
693
                        
694
                } else if( !this.getOperatingSystem().equalsIgnoreCase(parts[PART_OS]) ) {
611 695
                    return false;
612 696
                }
613 697
            }
614
            if( !"any".equalsIgnoreCase(stringParts[3]) ) {
615
                if( "current".equalsIgnoreCase(stringParts[3]) ) {
698
            if( !"any".equalsIgnoreCase(parts[PART_ARCH]) ) {
699
                if( "current".equalsIgnoreCase(parts[PART_ARCH]) ) {
616 700
                    if( !this.getArchitecture().equalsIgnoreCase(this.getPackageManager().getArchitecture()) ) {
617 701
                        return false;
618 702
                    }
619
                } else if( !this.getArchitecture().equalsIgnoreCase(stringParts[3]) ) {
703
                } else if( !this.getArchitecture().equalsIgnoreCase(parts[3]) ) {
620 704
                    return false;
621 705
                }
622 706
            }
......
665 749
        if (!version.check("=", other.getVersion())) {
666 750
            return false;
667 751
        }
668
        if (!operatingSystem.equalsIgnoreCase(other.getOperatingSystem())) {
752
        if (!getOperatingSystem().equalsIgnoreCase(other.getOperatingSystem())) {
669 753
            return false;
670 754
        }
671 755
        if (!gvSIGVersion.equalsIgnoreCase(other.getGvSIGVersion())) {

Also available in: Unified diff