Esempio n. 1
0
void ResourceManager::addManifestFromArchive(IPropertyTree *archive)
{
    if (!archive)
        return;
    if (finalized)
        throwError1(HQLERR_ResourceAddAfterFinalManifest, "MANIFEST");
    ensureManifestInfo();
    Owned<IPropertyTreeIterator> manifests = archive->getElements("AdditionalFiles/Manifest");
    ForEach(*manifests)
    {
        const char *xml = manifests->query().queryProp(NULL);
        Owned<IPropertyTree> manifestSrc = createPTreeFromXMLString(xml);
        Owned<IAttributeIterator> aiter = manifestSrc->getAttributes();
        ForEach (*aiter)
            manifest->setProp(aiter->queryName(), aiter->queryValue());
        StringBuffer manifestDir;
        if (manifestSrc->hasProp("@originalFilename"))
            splitDirTail(manifestSrc->queryProp("@originalFilename"), manifestDir);

        Owned<IPropertyTreeIterator> iter = manifestSrc->getElements("*");
        ForEach(*iter)
        {
            IPropertyTree &item = iter->query();
            if (streq(item.queryName(), "Resource") && item.hasProp("@filename"))
            {
                if (!item.hasProp("@type"))
                    item.setProp("@type", "UNKNOWN");
                const char *filename;
                if (item.hasProp("@originalFilename"))
                    filename = item.queryProp("@originalFilename");
                else
                    filename = item.queryProp("@filename");
                int id;
                if (getDuplicateResourceId(item.queryProp("@type"), NULL, filename, id))
                {
                    item.setPropInt("@id", (int)id);
                    manifest->addPropTree("Resource", LINK(&item));
                }
                else
                {
                    VStringBuffer xpath("AdditionalFiles/Resource[@originalFilename=\"%s\"]", filename);
                    MemoryBuffer content;
                    archive->getPropBin(xpath.str(), content);
                    addCompress(item.queryProp("@type"), content.length(), content.toByteArray(), &item);
                }
            }
            else
                manifest->addPropTree(item.queryName(), LINK(&item));
        }
    }
}
Esempio n. 2
0
void ResourceManager::addManifest(const char *filename)
{
    if (finalized)
        throwError1(HQLERR_ResourceAddAfterFinalManifest, "MANIFEST");
    Owned<IPropertyTree> manifestSrc = createPTreeFromXMLFile(filename);

    StringBuffer dir; 
    splitDirTail(filename, dir);

    ensureManifestInfo();
    Owned<IAttributeIterator> aiter = manifestSrc->getAttributes();
    ForEach (*aiter)
        manifest->setProp(aiter->queryName(), aiter->queryValue());
    Owned<IPropertyTreeIterator> iter = manifestSrc->getElements("*");
    ForEach(*iter)
    {
        IPropertyTree &item = iter->query();
        if (streq(item.queryName(), "Resource") && item.hasProp("@filename"))
        {
            if (!item.hasProp("@type"))
                item.setProp("@type", "UNKNOWN");
            const char *filename = item.queryProp("@filename");
            int id;
            if (getDuplicateResourceId(item.queryProp("@type"), filename, id))
            {
                item.setPropInt("@id", id);
                manifest->addPropTree("Resource", LINK(&item));
            }
            else
            {
                StringBuffer fullpath;
                if (!isAbsolutePath(filename))
                    fullpath.append(dir);
                fullpath.append(filename);

                MemoryBuffer content;
                loadResource(fullpath.str(), content);
                addCompress(item.queryProp("@type"), content.length(), content.toByteArray(), &item);
            }
        }
        else
            manifest->addPropTree(item.queryName(), LINK(&item));
    }
}
Esempio n. 3
0
void CEnvGen::addUpdateTaskFromFile(const char * inFile)
{
   Owned<IPropertyTree> inPTree;

   if ((String(inFile).toLowerCase())->endsWith(".json"))
   {
      StringBuffer sbFile;
      sbFile.loadFile(inFile);
      inPTree.setown(createPTreeFromJSONString(sbFile.str()));
   }
   else
   {
       inPTree.setown(createPTreeFromXMLFile(inFile));
   }

   // add Config attributies to params
   IPropertyTree *pCfg = m_params->queryPropTree("Config");
   assert(pCfg);
   Owned<IAttributeIterator> attrIter = inPTree->getAttributes();
   ForEach(*attrIter)
   {
      const char* propName = attrIter->queryName();
      if (!(*propName)) continue;
      pCfg->setProp(propName, attrIter->queryValue());

   }

   // add Tasks to params
   Owned<IPropertyTreeIterator> taskIter = inPTree->getElements("Task");
   ForEach(*taskIter)
   {
      IPropertyTree* task = &taskIter->query();
      StringBuffer sb;
      toXML(task, sb);
      pCfg->addPropTree("Task", createPTreeFromXMLString(sb.str()));

   }

}
Esempio n. 4
0
void ResourceManager::addManifestFile(const char *filename)
{
    Owned<IPropertyTree> manifestSrc = createPTreeFromXMLFile(filename);

    StringBuffer dir; 
    splitDirTail(filename, dir);

    ensureManifestInfo();
    Owned<IAttributeIterator> aiter = manifestSrc->getAttributes();
    ForEach (*aiter)
        manifest->setProp(aiter->queryName(), aiter->queryValue());
    Owned<IPropertyTreeIterator> iter = manifestSrc->getElements("*");
    ForEach(*iter)
    {
        IPropertyTree &item = iter->query();
        if (streq(item.queryName(), "Include") && item.hasProp("@filename"))
            addManifestInclude(item, dir.str());
        else if (streq(item.queryName(), "Resource") && item.hasProp("@filename"))
        {
            StringBuffer filepath;
            StringBuffer respath;
            makeAbsolutePath(item.queryProp("@filename"), dir.str(), filepath);
            makePathUniversal(filepath.str(), respath);

            item.setProp("@originalFilename", filepath.str());
            item.setProp("@resourcePath", respath.str());

            if (containsFileWildcard(filepath))
            {
                StringBuffer wildpath;
                const char *tail = splitDirTail(filepath, wildpath);
                expandManifestDirectory(manifestSrc, item, dir, wildpath, tail, item.getPropBool("@recursive"));
                manifestSrc->removeTree(&item);
            }

        }
        else
            manifest->addPropTree(item.queryName(), LINK(&item));
    }

    Owned<IPropertyTreeIterator> resources = manifestSrc->getElements("Resource[@filename]");
    ForEach(*resources)
    {
        IPropertyTree &item = resources->query();

        if (!item.hasProp("@type"))
            item.setProp("@type", "UNKNOWN");
        int id;
        if (getDuplicateResourceId(item.queryProp("@type"), item.queryProp("@resourcePath"), NULL, id))
        {
            item.setPropInt("@id", id);
            manifest->addPropTree("Resource", LINK(&item));
        }
        else
        {
            MemoryBuffer content;
            loadResource(item.queryProp("@originalFilename"), content);
            addCompress(item.queryProp("@type"), content.length(), content.toByteArray(), &item);
        }
    }
}