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 -x 
   102     *  @p(dlist)
   103     *  Extracts all archived packages in the current directory to the current
   104     *  repository
   105     *  @p
   106     * 
   107     *  xs xdc.tools.repoman -x -r C:\myrepo\packages -p C:\exports
   108     *  @p(dlist)
   109     *  Extracts all archived packages in C:\exports to C:\myrepo\packages
   110     *  repository
   111     *  @p
   112     * 
   113     *  xs xdc.tools.repoman -x -r C:\myrepo\packages -p C:\exports ti.catalog.*
   114     *  @p(dlist)
   115     *  Extracts packages matching ti.catalog.* from c:\exports to
   116     *  c:\myrepo\packages
   117     *  @p
   118     * 
   119     *  xs xdc.tools.repoman -x -r C:\myrepo\packages C:\exports\ti_catalog*.tar
   120     *  @p(dlist)
   121     *  Extracts packages from files matching C:\exports\ti_catalog*.tar 
   122     *  to 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 -r C:\myrepo -p C:\xdc-o19\exports ti.platforms.sim6xxx
   132     *  @p(dlist)
   133     *  Extracts the package ti.platforms.sim6xxx and all recursively
   134     *  dependent packages from C:\xdc-o19\exports to C:\myrepo
   135     *  @p
   136     * 
   137     *  xs xdc.tools.repoman -x -r C:\ -b packages C:\exports\xdc_core.tar.gz 
   138     *  @p(dlist)
   139     *  Extracts the repository 'packages' from bundle
   140     *  C:\exports\xdc_core.tar.gz to C:\
   141     *  @p
   142     * 
   143     *  xs xdc.tools.repoman -x -r C:\myrepo -b examples ti.xdais.dm.examples.videnc1_copy 
   144     *  C:\xdais_6_24.tar.gz
   145     *  @p(dlist)
   146     *  Extracts the package ti.xdais.dm.examples.videnc1_copy from repository
   147     *  'examples' in bundle
   148     *  C:\xdais_6_24.tar.gz to C:\myrepo
   149     *  @p
   150     * 
   151     *  xs xdc.tools.repoman -c -r C:\destdir\packages -p C:\srcdir\packages ti.catalog.c6000
   152     *  @p(dlist)
   153     *  Copies the package ti.catalog.c6000 from C:\srcdir\packages to
   154     *  C:\destdir\packages
   155     *  @p
   156     *
   157     *  xs xdc.tools.repoman --rsave -f c:/repoinfo.rmn -p c:/pkgarchives;c:/testpkgs c:/myrepo 
   158     *  @p(dlist)
   159     *  Saves package information for repository c:/myrepo to file c:/repoinfo.rmn.
   160     *  Also saves the search path c:/pkgarchives;c:/testpkgs
   161     *  @p
   162     *
   163     *  xs xdc.tools.repoman --rrestore -f c:/repoinfo.rmn -p c:/pkgarchives;c:/testpkgs
   164     *  @p(dlist)
   165     *  Restores all of the packages in the repository referenced in
   166     *  c:/repoinfo.rmn. Uses the search path c:/pkgarchives;c:/testpkgs to find
   167     *  and copy packages. Will create the repository if it doesn't exist.
   168     *  @p
   169     *
   170     *  xs xdc.tools.repoman --rcreate -f c:/repoinfo.rmn -p
   171     *                       c:/pkgarchives;c:/testpkgs c:/mynewrepo
   172     *  @p(dlist)
   173     *  Creates the new repository c:/mynewrepo from the repository referenced in
   174     *  the file c:/repoinfo.rmn.  Uses the search path c:/pkgarchives;c:/testpkgs
   175     *  to find and copy packages. If successful, the newly created repository
   176     *  will be identical to its predecessor referenced in c:/repoinfo.rmn.
   177     *  @p
   178     *
   179     *  xs xdc.tools.repoman --providerId my_codec_engine c:/codec_engine_2_23/mypackages
   180     *  @p(dlist)
   181     *  Assigns the providerId attribute in  c:/codec_engine_2_23/mypackages/.repo.xml
   182     *  the value my_codec_engine. If c:/codec_engine_2_23/mypackages/.repo.xml does not
   183     *  exist, it will be created.
   184     *  @p
   185     *
   186     */
   187    metaonly module Main inherits xdc.tools.ICmd {
   188    
   189        override config String usage[] = [
   190            '-t [-v] [-p pathname] [packagename...|packagefile...]',
   191            '-n [-v] [-p pathname] [packagename...|packagefile...]',
   192            '-x [-v] [-D] [-R] [-F] [-r destrepo] [-p path] packagename...|packagefile...',
   193            '-x [-v] [-D] [-R] [-F] [-r destrepo] [-p path] -b bundlerepository [packagename...] bundleFile',
   194            '-d [-v] [-F] [-r destrepo] packagename...',
   195            '-c [-v] [-F] [--providerId] [-r destrepo] [-p pathname] packagename...',
   196            '--rsave -f file [-p searchpath] repository...',
   197            '--rrestore -f file [-p searchpath] [index-spec]',
   198            '--rcreate -f file [-p searchpath] [index-spec] destrepository...',
   199            '[-F] --providerId providerId [repository...]'
   200        ];
   201    
   202       /*! represents a repository in a bundle */
   203        @XmlDtd 
   204        metaonly struct Repo {
   205            String name;
   206            String pkg[];
   207        }
   208    
   209        @XmlDtd
   210        metaonly struct Pkg {
   211            String name;
   212            String file;
   213            String release;
   214            String label;
   215            String version;
   216            String date;
   217            String buildable;
   218            String reqs[];
   219            String refs[];
   220            Repo repository[];
   221        }
   222       
   223        @XmlDtd
   224        metaonly struct Results {
   225            String repository;
   226            String providerId;
   227            String producerId;
   228            Bool writable;
   229            Pkg pkg[];         /*! array of package info structures */
   230        }
   231    
   232        @XmlDtd
   233        metaonly struct PkgName {
   234            String name;
   235            Repo repository[];
   236        }
   237    
   238        @XmlDtd
   239        metaonly struct NameResults {
   240            PkgName pkgName[];     /*! array of PkgName structures */
   241        }
   242    
   243    instance:
   244    
   245        //!Display package info
   246        @CommandOption('t')
   247        config Bool infoFlag = false;
   248    
   249        //!Display package names only
   250        @CommandOption('n')
   251        config Bool namesFlag = false;
   252    
   253        //!Extract package(s)
   254        @CommandOption('x')
   255        config Bool extractFlag = false;
   256    
   257        //!Delete package(s)
   258        @CommandOption('d')
   259        config Bool deleteFlag = false;
   260    
   261        //!Path arg
   262        @CommandOption('p')
   263        config String pathArg = null;
   264    
   265        //!Repository arg
   266        @CommandOption('r')
   267        config String repositoryArg = null;
   268    
   269        //!Include package dependencies
   270        @CommandOption('D')
   271        config Bool dependentFlag = false;
   272    
   273        //!Recursive include package dependencies
   274        @CommandOption('R')
   275        config Bool recursiveDepFlag = false;
   276    
   277        //!Return an array of strings
   278        @CommandOption('a')
   279        config Bool arrFlag = false;
   280    
   281        //!Return a Results struct as XML
   282        @CommandOption('X')
   283        config Bool xmlFlag = false;
   284    
   285        //!Print informative messages during execution
   286        @CommandOption('v')
   287        config Bool verboseFlag = false;
   288    
   289        //!Bundle repository arg
   290        @CommandOption('b')
   291        config String bundleRepositoryArg = null;
   292    
   293        //!Force incompatible packages
   294        @CommandOption('F')
   295        config Bool forceFlag = false;
   296    
   297        //!Copy package(s)
   298        @CommandOption('c')
   299        config Bool copyFlag = false;
   300    
   301        //!file arg to save/restore repository
   302        @CommandOption('f')
   303        config String fileArg = null;
   304    
   305        //!Save a repository's information to file
   306        @CommandOption('rsave')
   307        config Bool rsaveFlag = false;
   308    
   309        //!Restore one or more repositories from information in file
   310        @CommandOption('rrestore')
   311        config Bool rrestoreFlag = false;
   312    
   313        //!Create one or more repositories from information in file
   314        @CommandOption('rcreate')
   315        config Bool rcreateFlag = false;
   316    
   317        //! providerId for a repository
   318        @CommandOption('providerId')
   319        config string provIdArg = null;
   320    
   321    }
   322    
   323    
   324    
   325    /*
   326     *  @(#) xdc.tools.repoman; 1, 0, 0, 0,147; 11-20-2009 13:27:53; /db/ztree/library/trees/xdctools/xdctools-d08x/src/
   327     */
   328