wuget.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include "jlib.hpp"
  14. #include "thorplugin.hpp"
  15. #include "workunit.hpp"
  16. void usage(const char *progname)
  17. {
  18. printf("%s - extract workunit information from query dll.\nUsage: %s [-m] [-w] filename\n", progname, progname);
  19. printf("Options:\n");
  20. printf(" -m Display manifest information\n");
  21. printf(" -w Display embedded workunit\n");
  22. printf("/nIf no options specified, -w is assumed\n");
  23. }
  24. int main(int argc, char **argv)
  25. {
  26. InitModuleObjects();
  27. bool doManifestInfo = false;
  28. bool doWorkunit = false;
  29. for (int i = 1; i < argc; i++)
  30. {
  31. if (argv[i][0]=='-')
  32. {
  33. if (strcmp(argv[i], "-m")==0)
  34. doManifestInfo = true;
  35. else if (strcmp(argv[i], "-w")==0)
  36. doWorkunit = true;
  37. else
  38. {
  39. usage(argv[0]);
  40. return 1;
  41. }
  42. }
  43. }
  44. int filesSeen = 0;
  45. int errors = 0;
  46. for (int i = 1; i < argc; i++)
  47. {
  48. if (argv[i][0]!='-')
  49. {
  50. try
  51. {
  52. filesSeen++;
  53. if (doWorkunit || !doManifestInfo)
  54. {
  55. StringBuffer xml;
  56. if (getWorkunitXMLFromFile(argv[i], xml))
  57. {
  58. Owned<ILocalWorkUnit> wu = createLocalWorkUnit(xml);
  59. exportWorkUnitToXML(wu, xml.clear(), true, false, true);
  60. printf("%s\n", xml.str());
  61. }
  62. else
  63. {
  64. fprintf(stderr, "Could not load workunit from %s\n", argv[i]);
  65. errors++;
  66. }
  67. }
  68. if (doManifestInfo)
  69. {
  70. StringBuffer xml;
  71. if (getManifestXMLFromFile(argv[i], xml))
  72. {
  73. printf("%s\n", xml.str());
  74. }
  75. else
  76. {
  77. fprintf(stderr, "Could not load manifest from %s\n", argv[i]);
  78. errors++;
  79. }
  80. }
  81. }
  82. catch (IException *E)
  83. {
  84. StringBuffer msg;
  85. fprintf(stderr, "Exception %d: %s processing argument %s\n", E->errorCode(), E->errorMessage(msg).str(), argv[i]);
  86. errors++;
  87. E->Release();
  88. }
  89. }
  90. }
  91. if (!filesSeen)
  92. {
  93. fprintf(stderr, "No files specified\n");
  94. errors++;
  95. }
  96. return errors ? 1 : 0;
  97. }