예제 #1
0
 /**
  * Gets the VCS version number of this file, or "unknown" if it was not specified in the manifest.
  * @return File version number or similar identifier.
  */
 public String getFileVersion()
 {
     return(XFUtil.nvl(getPropertyMap().get(ManifestBuilder.PROPERTY_NAME_FILE_VERSION), UNKNOWN_VERSION_STRING));
 }
예제 #2
0
        /**
         * Verifies the contents of this manifest file by resolving all its file references, checking that referenced loaders
         * exist, and optionally checking file hashes if required.
         * @param pScriptRunner ScriptRunner to use as the base directory for file checking.
         * @throws ExManifest If any manifest entry is invalid.
         */
        public void verifyManifest(ScriptRunner pScriptRunner)
        {
            //Verify the ScriptRunner versions are compatible (unless this behaviour is explicitly overriden)
            if (!pScriptRunner.hasCommandLineOption(CommandLineOption.SKIP_VERSION_CHECK))
            {
                String lCurrVersion     = ScriptRunnerVersion.getVersionNumber();
                String lManifestVersion = mPromotionPropertyMap.get(SCRIPTRUNNER_VERSION_PROPERTY);
                if (!lCurrVersion.equals(lManifestVersion))
                {
                    throw new ExManifest("Manifest version incompatible. Version " + lCurrVersion + " cannot safely execute a manifest built by version " + lManifestVersion);
                }
            }

            //Verify all loaders exist
            for (MetadataLoader lLoader : mLoaderMap.values())
            {
                try
                {
                    pScriptRunner.resolveFile(lLoader.getLoaderFilePath());
                }
                catch (FileNotFoundException e)
                {
                    throw new ExManifest("Loader file for loader " + lLoader.getName() + " cannot be located", e);
                }
            }

            Set <String> lAllFilePaths = pScriptRunner.allFilePathsInBaseDirectory();

            //Verify all files exist and they reference valid loaders
            for (PromotionFile lPromotionFile : getPromotionFileList())
            {
                //Check file existence
                File lFile;
                try
                {
                    lFile = pScriptRunner.resolveFile(lPromotionFile.getFilePath());
                }
                catch (FileNotFoundException e)
                {
                    throw new ExManifest("Promotion file " + lPromotionFile.getFilePath() + " cannot be located", e);
                }

                lAllFilePaths.remove(pScriptRunner.relativeFilePath(lFile));

                String lFileHash;
                try
                {
                    lFileHash = lPromotionFile.generateFileHash(pScriptRunner);
                }
                catch (IOException e)
                {
                    throw new ExManifest("Could not generate hash for file " + lPromotionFile.getFilePath(), e);
                }

                //Do a hash code check if required
                if (!pScriptRunner.hasCommandLineOption(CommandLineOption.SKIP_HASH_CHECK))
                {
                    String lPropertyHash = lPromotionFile.getPropertyMap().get(ManifestBuilder.PROPERTY_NAME_FILE_HASH);
                    if (XFUtil.isNull(lPropertyHash))
                    {
                        throw new ExManifest("Cannot perform hash check for " + lPromotionFile.getFilePath() + " as the " + ManifestBuilder.PROPERTY_NAME_FILE_HASH + " property is not specified");
                    }

                    if (!lPropertyHash.equals(lFileHash))
                    {
                        throw new ExManifest("Hash verification failed for file " + lPromotionFile.getFilePath() + " - expected " + lPropertyHash + " but got " + lFileHash);
                    }
                    Logger.logDebug("Hash check OK for file " + lPromotionFile.getFilePath());
                }
            }

            //If there are files in the archive that are not listed in the manifest we should issue a warning
            if (lAllFilePaths.size() > 0)
            {
                Logger.logWarning(lAllFilePaths.size() + " file(s) found in base directory but not listed in the manifest file:");
                for (String lPath : lAllFilePaths)
                {
                    Logger.logInfo(lPath);
                }
            }
        }