1    /* 
     2     *Copyright (c) 2008 Texas Instruments and others.
     3     *  All rights reserved. This program and the accompanying materials
     4     *  are made available under the terms of the Eclipse Public License v1.0
     5     *  which accompanies this distribution, and is available at
     6     *  http://www.eclipse.org/legal/epl-v10.html
     7     * 
     8     *  Contributors:
     9     *      Texas Instruments - initial implementation
    10     *
    11     * */
    12    
    13    package xdc.tools.repoman;
    14    
    15    /*!
    16     *  ======== xdc.tools.repoman.Main ========
    17     *  Repository Manager tool
    18     *
    19     *  This tool creates and manages package repositories.  It displays
    20     *  information about archived packages, extracts archived packages,
    21     *  extracts repositories from bundles and deletes packages from
    22     *  repositories.
    23     *
    24     *  Information about archived packages can be displayed with
    25     *  the '-t' and '-n' options. The '-p' argument is used to 
    26     *  specify a directory in which to search. If the '-p' arg is omitted,
    27     *  the current directory is searched. Specific packages can searched
    28     *  for by specifying one or more package names, or one or more package
    29     *  archives at the end of the command line.  If no packages are specified,
    30     *  information on all packages found in the search directory will be
    31     *  displayed.
    32     *  
    33     *  Archived packages can be extracted to a repository with the '-x' 
    34     *  option. '-x -D' will extract dependent packages, too. '-x -R' will
    35     *  recursively extract dependent packages. If any of the packages in 
    36     *  the specified package list are not compatible, the operation will
    37     *  be aborted. '-F' can be used to force all packages to be extracted,
    38     *  regardles of compatibility. The '-p' arg is used to specify a
    39     *  directory to search in. If not specified, the current directory will
    40     *  be searched. The '-x' option also extracts a repository or packages
    41     *  from a bundle. In this case, the last argument specifies the bundle
    42     *  from which to extract the repository. The repository to be extracted
    43     *  is specified with the '-b' arg. If just packages are to be extracted,
    44     *  one or more package names should follow the name of the repository
    45     *  that they should be extracted from.
    46     *
    47     *  Packages can be deleted from a repository with '-d'. If the package
    48     *  has any subdirectores that contain packages, they will be left intact.
    49     *  After the package is deleted, if the package has no subdirectories
    50     *  with packages, empty directories that are part of the fully qualified
    51     *  package will be deleted, too.
    52     *
    53     *  Packages can be copied between repositories with '-c'. If the package
    54     *  being copied already exists in the destination repository, it will be
    55     *  deleted prior to being replaced.
    56     *
    57     *  The '-r' argument specifies a destination repository. If '-r' is
    58     *  omitted, the repository of the current package is used. If there is
    59     *  no current package, the current directory is used. 
    60     *
    61     *  When a package name is given, it can be specified in full, such as
    62     *  'ti.platforms.sim6xxx', or the wildcard characters '*' and '?' may be
    63     *  used, as in 'ti.platforms.*' or 'ti.catalog.c??00'. A version/key can
    64     *  also be attached to a package name in the following manner:
    65     *  'ti.platforms.c6000[1,0,0,0,313835]'.  A prefix of the full version/key
    66     *  may also be used: 'ti.platforms.c6000[1,0]'.
    67     *
    68     *  If a package name has multiple matches either with or without a
    69     *  version/key specified, the most recent will be selected. Wildcards may
    70     *  also be used when naming a package archive file.
    71     *  
    72     *  @a(Examples)
    73     *  xs xdc.tools.repoman -t
    74     *  @p(dlist)
    75     *  Displays all info on all archived packages in the current directory
    76     *  @p
    77     *    
    78     *  xs xdc.tools.repoman -t -p C:\xdc-o19\exports
    79     *  @p(dlist)
    80     *  Displays all info on all archived packages in C:\xdc-o19\exports
    81     *  @p
    82     *
    83     *  xs xdc.tools.repoman -t -p C:\xdc-o19\exports ti.platforms.*
    84     *  @p(dlist)
    85     *  Displays all info on archived packages whose names begin with
    86     *  ti.platforms. in C:\xdc-o19\exports
    87     *  @p
    88     *
    89     *  xs xdc.tools.repoman -t -p C:\xdc-o19\exports ti_platforms*.tar
    90     *  @p(dlist)
    91     *  Displays all info on packages in files that match ti_platforms*.tar
    92     *  in C:\xdc-o19\exports
    93     *  @p
    94     * 
    95     *  xs xdc.tools.repoman -t -p C:\xdc-o19\exports ti.catalog.c6000 ti.catalog.sim6xxx
    96     *  @p(dlist)
    97     *  Displays all info on archived packages ti.catalog.c6000 and
    98     *  ti.catalog.sim6xxx in C:\xdc-o19\exports
    99     *  @p
   100     * 
   101     *  xs xdc.tools.repoman -t http://www.sanb.design.ti.com/ti_sdo_ce_wizards_genserver.tar
   102     *  @p(dlist)
   103     *  Displays all info on archived package ti_sdo_ce_wizards_genserver.tar
   104     *  at URL http://www.sanb.design.ti.com
   105     *  @p
   106     *
   107     *  xs xdc.tools.repoman -x 
   108     *  @p(dlist)
   109     *  Extracts all archived packages in the current directory to the current
   110     *  repository
   111     *  @p
   112     * 
   113     *  xs xdc.tools.repoman -x -r C:\myrepo\packages -p C:\exports
   114     *  @p(dlist)
   115     *  Extracts all archived packages in C:\exports to C:\myrepo\packages
   116     *  repository
   117     *  @p
   118     * 
   119     *  xs xdc.tools.repoman -x -r C:\myrepo\packages -p C:\exports ti.catalog.*
   120     *  @p(dlist)
   121     *  Extracts packages matching ti.catalog.* from c:\exports to
   122     *  c:\myrepo\packages
   123     *  @p
   124     * 
   125     *  xs xdc.tools.repoman -x -r C:\myrepo\packages C:\exports\ti_catalog*.tar
   126     *  @p(dlist)
   127     *  Extracts packages from files matching C:\exports\ti_catalog*.tar 
   128     *  to c:\myrepo\packages
   129     *  @p
   130     * 
   131     *  xs xdc.tools.repoman -x -r C:\myrepo\packages C:\exports\ti_catalog*.tar
   132     *  @p(dlist)
   133     *  Extracts packages from files matching C:\exports\ti_catalog*.tar 
   134     *  to c:\myrepo\packages
   135     *  @p
   136     *
   137     *  xs xdc.tools.repoman -x -R -r C:\myrepo -p C:\xdc-o19\exports ti.platforms.sim6xxx
   138     *  @p(dlist)
   139     *  Extracts the package ti.platforms.sim6xxx and all recursively
   140     *  dependent packages from C:\xdc-o19\exports to C:\myrepo
   141     *  @p
   142     * 
   143     *  xs xdc.tools.repoman -x -r C:\ -b packages C:\exports\xdc_core.tar.gz 
   144     *  @p(dlist)
   145     *  Extracts the repository 'packages' from bundle
   146     *  C:\exports\xdc_core.tar.gz to C:\
   147     *  @p
   148     * 
   149     *  xs xdc.tools.repoman -x -r C:\myrepo -b examples ti.xdais.dm.examples.videnc1_copy 
   150     *  C:\xdais_6_24.tar.gz
   151     *  @p(dlist)
   152     *  Extracts the package ti.xdais.dm.examples.videnc1_copy from repository
   153     *  'examples' in bundle
   154     *  C:\xdais_6_24.tar.gz to C:\myrepo
   155     *  @p
   156     * 
   157     *  xs xdc.tools.repoman -x -r C:\myrepo http://www.sanb.design.ti.com/ti_sdo_ce_wizards_genserver.tar
   158     *  @p(dlist)
   159     *  Extracts package ti_sdo_ce_wizards_genserver.tar at URL http://www.sanb.design.ti.com
   160     *  to c:\myrepo
   161     *  @p
   162     *
   163     *  xs xdc.tools.repoman -r C:\myrepo -b examples
   164     *  https://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/xdais/7_10/exports/xdais_7_10.tar.gz
   165     *  @p(dlist)
   166     *  Extracts all of the packages in repository 'examples' from bundle xdais_7_10.tar.gz at URL
   167     *  http://... to C:\myrepo
   168     *  @p
   169     *
   170     *  xs xdc.tools.repoman -x -r C:\myrepo -b examples ti.xdais.dm.examples.videnc1_copy
   171     *  https://software-dl.ti.com/dsps/dsps_public_sw/sdo_sb/targetcontent/xdais/6_24/exports/xdais_6_24.tar.gz
   172     *  @p(dlist)
   173     *  Extracts the package ti.xdais.dm.examples.videnc1_copy in repository
   174     *  'examples' from bundle xdais_7_10.tar.gz at URL http://... to C:\myrepo
   175     *  @p
   176     *
   177     *  xs xdc.tools.repoman -c -r C:\destdir\packages -p C:\srcdir\packages ti.catalog.c6000
   178     *  @p(dlist)
   179     *  Copies the package ti.catalog.c6000 from C:\srcdir\packages to
   180     *  C:\destdir\packages
   181     *  @p
   182     *
   183     *  xs xdc.tools.repoman --rsave -f c:/repoinfo.rmn -p c:/pkgarchives;c:/testpkgs c:/myrepo 
   184     *  @p(dlist)
   185     *  Saves package information for repository c:/myrepo to file c:/repoinfo.rmn.
   186     *  Also saves the search path c:/pkgarchives;c:/testpkgs
   187     *  @p
   188     *
   189     *  xs xdc.tools.repoman --rrestore -f c:/repoinfo.rmn -p c:/pkgarchives;c:/testpkgs
   190     *  @p(dlist)
   191     *  Restores all of the packages in the repository referenced in
   192     *  c:/repoinfo.rmn. Uses the search path c:/pkgarchives;c:/testpkgs to find
   193     *  and copy packages. Will create the repository if it doesn't exist.
   194     *  @p
   195     *
   196     *  xs xdc.tools.repoman --rcreate -f c:/repoinfo.rmn -p
   197     *                       c:/pkgarchives;c:/testpkgs c:/mynewrepo
   198     *  @p(dlist)
   199     *  Creates the new repository c:/mynewrepo from the repository referenced in
   200     *  the file c:/repoinfo.rmn.  Uses the search path c:/pkgarchives;c:/testpkgs
   201     *  to find and copy packages. If successful, the newly created repository
   202     *  will be identical to its predecessor referenced in c:/repoinfo.rmn.
   203     *  @p
   204     *
   205     *  xs xdc.tools.repoman --providerId my_codec_engine c:/codec_engine_2_23/mypackages
   206     *  @p(dlist)
   207     *  Assigns the providerId attribute in  c:/codec_engine_2_23/mypackages/.repo.xml
   208     *  the value my_codec_engine. If c:/codec_engine_2_23/mypackages/.repo.xml does not
   209     *  exist, it will be created.
   210     *  @p
   211     *
   212     */
   213    metaonly module Main inherits xdc.tools.ICmd {
   214    
   215        override config String usage[] = [
   216            '-t [-v] [-p pathname] [packagename...|packagefile...]',
   217            '-n [-v] [-p pathname] [packagename...|packagefile...]',
   218            '-x [-v] [-D] [-R] [-F] [-r destrepo] [-p path] packagename...|packagefile...',
   219            '-x [-v] [-D] [-R] [-F] [-r destrepo] [-p path] -b bundlerepository [packagename...] bundleFile',
   220            '-d [-v] [-F] [-r destrepo] packagename...',
   221            '-c [-v] [-F] [--providerId] [-r destrepo] [-p pathname] packagename...',
   222            '--rsave -f file [-p searchpath] repository...',
   223            '--rrestore -f file [-p searchpath] [index-spec]',
   224            '--rcreate -f file [-p searchpath] [index-spec] destrepository...',
   225            '[-F] --providerId providerId [repository...]'
   226        ];
   227    
   228       /*! represents a repository in a bundle */
   229        @XmlDtd 
   230        metaonly struct Repo {
   231            String name;
   232            String pkg[];
   233        }
   234    
   235        @XmlDtd
   236        metaonly struct Pkg {
   237            String name;
   238            String file;
   239            String release;
   240            String label;
   241            String version;
   242            String date;
   243            String buildable;
   244            String originalProviderId;
   245            String producerId;
   246            String reqs[];
   247            String refs[];
   248            Repo repository[];
   249        }
   250       
   251        @XmlDtd
   252        metaonly struct Results {
   253            String repository;
   254            String providerId;
   255            String producerId;
   256            Bool writable;
   257            Pkg pkg[];         /*! array of package info structures */
   258        }
   259    
   260        @XmlDtd
   261        metaonly struct PkgName {
   262            String name;
   263            Repo repository[];
   264        }
   265    
   266        @XmlDtd
   267        metaonly struct NameResults {
   268            PkgName pkgName[];     /*! array of PkgName structures */
   269        }
   270    
   271    instance:
   272    
   273        //!Display package info
   274        @CommandOption('t')
   275        config Bool infoFlag = false;
   276    
   277        //!Display package names only
   278        @CommandOption('n')
   279        config Bool namesFlag = false;
   280    
   281        //!Extract package(s)
   282        @CommandOption('x')
   283        config Bool extractFlag = false;
   284    
   285        //!Delete package(s)
   286        @CommandOption('d')
   287        config Bool deleteFlag = false;
   288    
   289        //!Path arg
   290        @CommandOption('p')
   291        config String pathArg = null;
   292    
   293        //!Repository arg
   294        @CommandOption('r')
   295        config String repositoryArg = null;
   296    
   297        //!Include package dependencies
   298        @CommandOption('D')
   299        config Bool dependentFlag = false;
   300    
   301        //!Recursive include package dependencies
   302        @CommandOption('R')
   303        config Bool recursiveDepFlag = false;
   304    
   305        //!Return an array of strings
   306        @CommandOption('a')
   307        config Bool arrFlag = false;
   308    
   309        //!Return a Results struct as XML
   310        @CommandOption('X')
   311        config Bool xmlFlag = false;
   312    
   313        //!Print informative messages during execution
   314        @CommandOption('v')
   315        config Bool verboseFlag = false;
   316    
   317        //!Bundle repository arg
   318        @CommandOption('b')
   319        config String bundleRepositoryArg = null;
   320    
   321        //!Force incompatible packages
   322        @CommandOption('F')
   323        config Bool forceFlag = false;
   324    
   325        //!Copy package(s)
   326        @CommandOption('c')
   327        config Bool copyFlag = false;
   328    
   329        //!file arg to save/restore repository
   330        @CommandOption('f')
   331        config String fileArg = null;
   332    
   333        //!Save a repository's information to file
   334        @CommandOption('rsave')
   335        config Bool rsaveFlag = false;
   336    
   337        //!Restore one or more repositories from information in file
   338        @CommandOption('rrestore')
   339        config Bool rrestoreFlag = false;
   340    
   341        //!Create one or more repositories from information in file
   342        @CommandOption('rcreate')
   343        config Bool rcreateFlag = false;
   344    
   345        //! providerId for a repository
   346        @CommandOption('providerId')
   347        config string provIdArg = null;
   348    
   349    }
   350    
   351    
   352    
   353    /*
   354     *  @(#) xdc.tools.repoman; 1, 0, 0,199; 4-27-2011 15:34:08; /db/ztree/library/trees/xdctools/xdctools-e14x/src/
   355     */
   356