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 to search in. 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 repositories from a bundle.
    41     *  In this case, the last argumnet specifies the bundle file to extract
    42     *  from. The repositories to be extracted are be specified with the '-b'
    43     *  arg. 
    44     *
    45     *  Packages can be deleted from a repository with '-d'. If the package
    46     *  has any subdirectores that contain packages, they will be left intact.
    47     *  After the package is deleted, if the package has no subdirectories
    48     *  with packages, empty directories that are part of the fully qualified
    49     *  package will be deleted, too.
    50     *
    51     *  Packages can be copied between repositories with '-c'. If the package
    52     *  being copied already exists in the destination repository, it will be
    53     *  deleted prior to being replaced.
    54     *
    55     *  The '-r' argument specifies a destination repository. If '-r' is
    56     *  omitted, the repository of the current package is used. If there is
    57     *  no current package, the current directory is used. 
    58     *
    59     *  When a package name is given, it can be specified in full, such as
    60     *  'ti.platforms.sim6xxx', or the wildcard characters '*' and '?' may be
    61     *  used, as in 'ti.platforms.*' or 'ti.catalog.c??00'. A version/key can
    62     *  also be attached to a package name in the following manner:
    63     *  'ti.platforms.c6000[1,0,0,0,313835]'.  A prefix of the full version/key
    64     *  may also be used: 'ti.platforms.c6000[1,0]'.
    65     *
    66     *  If a package name has multiple matches either with or without a
    67     *  version/key specified, the most recent will be selected. Wildcards may
    68     *  also be used when naming a package archive file.
    69     *  
    70     *  @a(Examples)
    71     *  xs xdc.tools.repoman -t
    72     *  @p(dlist)
    73     *  Displays all info on all archived packages in the current directory
    74     *  @p
    75     *    
    76     *  xs xdc.tools.repoman -t -p C:\xdc-o19\exports
    77     *  @p(dlist)
    78     *  Displays all info on all archived packages in C:\xdc-o19\exports
    79     *  @p
    80     *
    81     *  xs xdc.tools.repoman -t -p C:\xdc-o19\exports ti.platforms.*
    82     *  @p(dlist)
    83     *  Displays all info on archived packages whose names begin with
    84     *  ti.platforms. in C:\xdc-o19\exports
    85     *  @p
    86     *
    87     *  xs xdc.tools.repoman -t -p C:\xdc-o19\exports ti_platforms*.tar
    88     *  @p(dlist)
    89     *  Displays all info on packages in files that match ti_platforms*.tar
    90     *  in C:\xdc-o19\exports
    91     *  @p
    92     * 
    93     *  xs xdc.tools.repoman -t -p C:\xdc-o19\exports ti.catalog.c6000 ti.catalog.sim6xxx
    94     *  @p(dlist)
    95     *  Displays all info on archived packages ti.catalog.c6000 and
    96     *  ti.catalog.sim6xxx in C:\xdc-o19\exports
    97     *  @p
    98     * 
    99     *  xs xdc.tools.repoman -x 
   100     *  @p(dlist)
   101     *  Extracts all archived packages in the current directory to the current
   102     *  repository
   103     *  @p
   104     * 
   105     *  xs xdc.tools.repoman -x -r C:\myrepo\packages -p C:\exports
   106     *  @p(dlist)
   107     *  Extracts all archived packages in C:\exports to C:\myrepo\packages
   108     *  repository
   109     *  @p
   110     * 
   111     *  xs xdc.tools.repoman -x -r C:\myrepo\packages -p C:\exports ti.catalog.*
   112     *  @p(dlist)
   113     *  Extracts packages matching ti.catalog.* from c:\exports to
   114     *  c:\myrepo\packages
   115     *  @p
   116     * 
   117     *  xs xdc.tools.repoman -x -r C:\myrepo\packages C:\exports\ti_catalog*.tar
   118     *  @p(dlist)
   119     *  Extracts packages from files matching C:\exports\ti_catalog*.tar 
   120     *  to c:\myrepo\packages
   121     *  @p
   122     * 
   123     *  xs xdc.tools.repoman -x -r C:\myrepo\packages C:\exports\ti_catalog*.tar
   124     *  @p(dlist)
   125     *  Extracts packages from files matching C:\exports\ti_catalog*.tar 
   126     *  to c:\myrepo\packages
   127     *  @p
   128     *
   129     *  xs xdc.tools.repoman -x -R -r C:\myrepo -p C:\xdc-o19\exports ti.platforms.sim6xxx
   130     *  @p(dlist)
   131     *  Extracts the package ti.platforms.sim6xxx and all recursively
   132     *  dependent packages from C:\xdc-o19\exports to C:\myrepo
   133     *  @p
   134     * 
   135     *  xs xdc.tools.repoman -x -r C:\ -b packages C:\exports\xdc_core.tar.gz 
   136     *  @p(dlist)
   137     *  Extracts the repository 'packages' from bundle
   138     *  C:\exports\xdc_core.tar.gz to C:\
   139     *  @p
   140     * 
   141     *  xs xdc.tools.repoman -c -r C:\destdir\packages -p C:\srcdir\packages ti.catalog.c6000
   142     *  @p(dlist)
   143     *  Copies the package ti.catalog.c6000 from C:\srcdir\packages to
   144     *  C:\destdir\packages
   145     *  @p
   146     *
   147     *  xs xdc.tools.repoman --rsave -f c:/repoinfo.rmn -p c:/pkgarchives;c:/testpkgs c:/myrepo 
   148     *  @p(dlist)
   149     *  Saves package information for repository c:/myrepo to file c:/repoinfo.rmn.
   150     *  Also saves the search path c:/pkgarchives;c:/testpkgs
   151     *  @p
   152     *
   153     *  xs xdc.tools.repoman --rrestore -f c:/repoinfo.rmn -p c:/pkgarchives;c:/testpkgs
   154     *  @p(dlist)
   155     *  Restores all of the packages in the repository referenced in
   156     *  c:/repoinfo.rmn. Uses the search path c:/pkgarchives;c:/testpkgs to find
   157     *  and copy packages. Will create the repository if it doesn't exist.
   158     *  @p
   159     *
   160     *  xs xdc.tools.repoman --rcreate -f c:/repoinfo.rmn -p
   161     *                       c:/pkgarchives;c:/testpkgs c:/mynewrepo
   162     *  @p(dlist)
   163     *  Creates the new repository c:/mynewrepo from the repository referenced in
   164     *  the file c:/repoinfo.rmn.  Uses the search path c:/pkgarchives;c:/testpkgs
   165     *  to find and copy packages. If successful, the newly created repository
   166     *  will be identical to its predecessor referenced in c:/repoinfo.rmn.
   167     *  @p
   168     *
   169     *  xs xdc.tools.repoman --providerId my_codec_engine c:/codec_engine_2_23/mypackages
   170     *  @p(dlist)
   171     *  Assigns the providerId attribute in  c:/codec_engine_2_23/mypackages/.repo.xml
   172     *  the value my_codec_engine. If c:/codec_engine_2_23/mypackages/.repo.xml does not
   173     *  exist, it will be created.
   174     *  @p
   175     *
   176     */
   177    metaonly module Main inherits xdc.tools.ICmd {
   178    
   179        override config String usage[] = [
   180            '-t [-v] [-p pathname] [packagename...|packagefile...]',
   181            '-n [-v] [-p pathname] [packagename...|packagefile...]',
   182            '-x [-v] [-D] [-R] [-F] [-r destrepo] [-p path] [-b bundlerepository] [packagename...|packagefile...]',
   183            '-d [-v] [-F] [-r destrepo] packagename...',
   184            '-c [-v] [-F] [--provId providerId] [-r destrepo] [-p pathname] packagename...',
   185            '--rsave -f file [-p searchpath] repository...',
   186            '--rrestore -f file [-p searchpath] [index-spec]',
   187            '--rcreate -f file [-p searchpath] [index-spec] destrepository...',
   188            '[-F] --providerId providerId [repository...]'
   189        ];
   190    
   191       /*! represents a repository in a bundle */
   192        @XmlDtd 
   193        metaonly struct Repo {
   194            String name;
   195            String pkg[];
   196        }
   197    
   198        @XmlDtd
   199        metaonly struct Pkg {
   200            String name;
   201            String file;
   202            String release;
   203            String label;
   204            String version;
   205            String date;
   206            String buildable;
   207            String reqs[];
   208            String refs[];
   209            Repo repository[];
   210        }
   211       
   212        @XmlDtd
   213        metaonly struct Results {
   214            Pkg pkg[];         /*! array of package info structures */
   215        }
   216    
   217        @XmlDtd
   218        metaonly struct PkgName {
   219            String name;
   220            Repo repository[];
   221        }
   222    
   223        @XmlDtd
   224        metaonly struct NameResults {
   225            PkgName pkgName[];     /*! array of PkgName structures */
   226        }
   227    
   228    instance:
   229    
   230        //!Display package info
   231        @CommandOption('t')
   232        config Bool infoFlag = false;
   233    
   234        //!Display package names only
   235        @CommandOption('n')
   236        config Bool namesFlag = false;
   237    
   238        //!Extract package(s)
   239        @CommandOption('x')
   240        config Bool extractFlag = false;
   241    
   242        //!Delete package(s)
   243        @CommandOption('d')
   244        config Bool deleteFlag = false;
   245    
   246        //!Path arg
   247        @CommandOption('p')
   248        config String pathArg = null;
   249    
   250        //!Repository arg
   251        @CommandOption('r')
   252        config String repositoryArg = null;
   253    
   254        //!Include package dependencies
   255        @CommandOption('D')
   256        config Bool dependentFlag = false;
   257    
   258        //!Recursive include package dependencies
   259        @CommandOption('R')
   260        config Bool recursiveDepFlag = false;
   261    
   262        //!Return an array of strings
   263        @CommandOption('a')
   264        config Bool arrFlag = false;
   265    
   266        //!Return a Results struct as XML
   267        @CommandOption('X')
   268        config Bool xmlFlag = false;
   269    
   270        //!Print informative messages during execution
   271        @CommandOption('v')
   272        config Bool verboseFlag = false;
   273    
   274        //!Bundle repository arg
   275        @CommandOption('b')
   276        config String bundleRepositoryArg = null;
   277    
   278        //!Force incompatible packages
   279        @CommandOption('F')
   280        config Bool forceFlag = false;
   281    
   282        //!Copy package(s)
   283        @CommandOption('c')
   284        config Bool copyFlag = false;
   285    
   286        //!file arg to save/restore repository
   287        @CommandOption('f')
   288        config String fileArg = null;
   289    
   290        //!Save a repository's information to file
   291        @CommandOption('rsave')
   292        config Bool rsaveFlag = false;
   293    
   294        //!Restore one or more repositories from information in file
   295        @CommandOption('rrestore')
   296        config Bool rrestoreFlag = false;
   297    
   298        //!Create one or more repositories from information in file
   299        @CommandOption('rcreate')
   300        config Bool rcreateFlag = false;
   301    
   302        //! providerId for a repository
   303        @CommandOption('providerId')
   304        config string provIdArg = null;
   305    
   306    }
   307    
   308    
   309    /*
   310     *  @(#) xdc.tools.repoman; 1, 0, 0, 0,129; 6-9-2009 14:23:39; /db/ztree/library/trees/xdctools-c16x/src/
   311     */
   312