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 originalProviderId;
   219            String producerId;
   220            String reqs[];
   221            String refs[];
   222            Repo repository[];
   223        }
   224       
   225        @XmlDtd
   226        metaonly struct Results {
   227            String repository;
   228            String providerId;
   229            String producerId;
   230            Bool writable;
   231            Pkg pkg[];         /*! array of package info structures */
   232        }
   233    
   234        @XmlDtd
   235        metaonly struct PkgName {
   236            String name;
   237            Repo repository[];
   238        }
   239    
   240        @XmlDtd
   241        metaonly struct NameResults {
   242            PkgName pkgName[];     /*! array of PkgName structures */
   243        }
   244    
   245    instance:
   246    
   247        //!Display package info
   248        @CommandOption('t')
   249        config Bool infoFlag = false;
   250    
   251        //!Display package names only
   252        @CommandOption('n')
   253        config Bool namesFlag = false;
   254    
   255        //!Extract package(s)
   256        @CommandOption('x')
   257        config Bool extractFlag = false;
   258    
   259        //!Delete package(s)
   260        @CommandOption('d')
   261        config Bool deleteFlag = false;
   262    
   263        //!Path arg
   264        @CommandOption('p')
   265        config String pathArg = null;
   266    
   267        //!Repository arg
   268        @CommandOption('r')
   269        config String repositoryArg = null;
   270    
   271        //!Include package dependencies
   272        @CommandOption('D')
   273        config Bool dependentFlag = false;
   274    
   275        //!Recursive include package dependencies
   276        @CommandOption('R')
   277        config Bool recursiveDepFlag = false;
   278    
   279        //!Return an array of strings
   280        @CommandOption('a')
   281        config Bool arrFlag = false;
   282    
   283        //!Return a Results struct as XML
   284        @CommandOption('X')
   285        config Bool xmlFlag = false;
   286    
   287        //!Print informative messages during execution
   288        @CommandOption('v')
   289        config Bool verboseFlag = false;
   290    
   291        //!Bundle repository arg
   292        @CommandOption('b')
   293        config String bundleRepositoryArg = null;
   294    
   295        //!Force incompatible packages
   296        @CommandOption('F')
   297        config Bool forceFlag = false;
   298    
   299        //!Copy package(s)
   300        @CommandOption('c')
   301        config Bool copyFlag = false;
   302    
   303        //!file arg to save/restore repository
   304        @CommandOption('f')
   305        config String fileArg = null;
   306    
   307        //!Save a repository's information to file
   308        @CommandOption('rsave')
   309        config Bool rsaveFlag = false;
   310    
   311        //!Restore one or more repositories from information in file
   312        @CommandOption('rrestore')
   313        config Bool rrestoreFlag = false;
   314    
   315        //!Create one or more repositories from information in file
   316        @CommandOption('rcreate')
   317        config Bool rcreateFlag = false;
   318    
   319        //! providerId for a repository
   320        @CommandOption('providerId')
   321        config string provIdArg = null;
   322    
   323    }
   324    
   325    
   326    
   327    /*
   328     *  @(#) xdc.tools.repoman; 1, 0, 0,172; 5-28-2010 18:10:30; /db/ztree/library/trees/xdctools/xdctools-d31x/src/
   329     */
   330