Compare archive against unexpected artifacts.

@param  array $unexpectedArtifacts The unexpected artifacts.
@throws \Stolt\LeanPackage\Exceptions\NoLicenseFilePresent
@return array
351120
public function compareArchive(array $unexpectedArtifacts)
    {
        $foundUnexpectedArtifacts = [];
        $archive = new PharData($this->getFilename());
        $hasLicenseFile = false;

        foreach ($archive as $archiveFile) {
            if ($archiveFile instanceof \SplFileInfo) {
                if ($archiveFile->isDir()) {
                    $file = basename($archiveFile) . '/';
                    if (in_array($file, $unexpectedArtifacts)) {
                        $foundUnexpectedArtifacts[] = $file;
                    }
                    continue;
                }

                $file = basename($archiveFile);
                if ($this->validateLicenseFilePresence()) {
                    if (preg_match('/(License.*)/i', $file)) {
                        $hasLicenseFile = true;
                    }
                }

                if (in_array($file, $unexpectedArtifacts)) {
                    $foundUnexpectedArtifacts[] = $file;
                }
            }
        }

        if ($this->validateLicenseFilePresence() && $hasLicenseFile === false) {
            throw new NoLicenseFilePresent('No license file present in archive.');
        }

        sort($foundUnexpectedArtifacts, SORT_STRING | SORT_FLAG_CASE);

        return $foundUnexpectedArtifacts;
    }
221827
public function getIncludedDirectories()
    {
        if ($this->dirsIncluded === null) {
            throw new UnexpectedValueException('Must call scan() first');
        }

        sort($this->dirsIncluded);

        return $this->dirsIncluded;
    }
113894
public function getAcceptedFileTypes($includeDot = false)
    {
        $types = $this->fileTypes;

        if ($types === false) {
            $isImage = starts_with($this->getDisplayMode(), 'image');
            $types = implode(',', FileDefinitions::get($isImage ? 'imageExtensions' : 'defaultExtensions'));
        }

        if (!$types || $types == '*') {
            return null;
        }

        if (!is_array($types)) {
            $types = explode(',', $types);
        }

        $types = array_map(function ($value) use ($includeDot) {
            $value = trim($value);

            if (substr($value, 0, 1) == '.') {
                $value = substr($value, 1);
            }

            if ($includeDot) {
                $value = '.'.$value;
            }

            return $value;
        }, $types);

        return implode(',', $types);
    }
509416
private function deDupePaths(array $rawExcludePaths)
    {
        $filteredArray = $rawExcludePaths;
        $count = count($filteredArray);
        for ($i = 0; $count > $i; $i++) {
            if (!isset($filteredArray[$i])) {
                continue;
            }
            $item = $filteredArray[$i];
            $filteredArray = array_filter(
                $filteredArray,
                function ($value) use ($item) {
                    return !(strlen($value) !== strlen($item) && strpos($value, $item) === 0);
                }
            );
        }
        $filteredArray = array_values($filteredArray);

        return $filteredArray;
    }
739058
public function getSupportedCollations()
    {
        if ($this->supportedCollations === null) {
            $supportedCollations = [];
            $rs = $this->executeQuery('SHOW COLLATION');
            while (($row = $rs->fetch(PDO::FETCH_ASSOC)) !== false) {
                if (!isset($row['Collation']) || !isset($row['Charset'])) {
                    throw new Exception(t('Unrecognized result of the "%s" database query.', 'SHOW COLLATION'));
                }
                $supportedCollations[strtolower($row['Collation'])] = strtolower($row['Charset']);
            }
            $this->supportedCollations = $supportedCollations;
        }

        return $this->supportedCollations;
    }
1051219
public function normalize($object, $format = null, array $context = [])
    {
        if (null !== $outputClass = $this->getOutputClass($this->getObjectClass($object), $context)) {
            return parent::normalize($object, $format, $context);
        }

        $data = parent::normalize($object, $format, $context);
        if (!\is_array($data)) {
            throw new UnexpectedValueException('Expected data to be an array');
        }

        $data[self::ITEM_RESOURCE_CLASS_KEY] = $this->getObjectClass($object);
        $data[self::ITEM_IDENTIFIERS_KEY] = $this->identifiersExtractor->getIdentifiersFromItem($object);

        return $data;
    }
365613
public static function assertEquals($actual, $expected, Throwable $exception)
    {
        static::makeAssertion($actual === $expected, $exception);
        return $actual;
    }
6793
public function transform($collection)
    {
        if (null === $collection) {
            return null;
        }

        if (!($collection instanceof Collection)) {
            throw new UnexpectedTypeException($collection, 'Doctrine\Common\Collection\Collection');
        }

        $results = array();
        foreach ($collection as $entity) {
            $results[] = array(
                $this->arrayIdentifierName => $this->displayValue(
                    $this->accessor->getValue($entity, $this->identifier)
                ),
                $this->arrayLabelName => $this->displayValue($this->extractLabel($entity)),
            );
        }

        //Here, do not put the result in the cache because we must check the value in
        //reverseTransform (by QueryBuilder)
        return json_encode($results);
    }
576938
public function executeNewBuilds()
    {
        $returnCode = 0;
        $output     = array();

        $files = $this->getNewBuilds();
        foreach ($files as $file) {
            if (!is_executable($file)) {
                $message = sprintf('File "%s" must be executable', $file);
                throw new \UnexpectedValueException($message);
            }

            $fileReturnCode = 0;
            $fileOutput     = array($file . ':');
            exec($file, $fileOutput, $fileReturnCode);

            $output[] = $fileOutput;
            if ($fileReturnCode > 0) {
                $returnCode = $fileReturnCode;
                break;
            }

            $latestBuildName = pathinfo($file, PATHINFO_FILENAME);
            $this->writeLatestBuildName($latestBuildName);
        }

        return new Result($returnCode, $output);
    }
422573
public function assertionsFromRawCliConfig(array $rawAssertions)
    {
        $assertions = [];

        foreach ($rawAssertions as $rawAssertion) {
            $config = $this->jsonDecoder->decode($rawAssertion);
            $assertions[] = new AssertionMetadata($config);
        }

        return $assertions;
    }
1148652
@Override
	public Result<Artifacts> fromArtifacts(Result<List<Data>> lArtiDAO) {
		if(lArtiDAO.isOK()) {
			Artifacts artis = new Artifacts();
			for(ArtiDAO.Data arti : lArtiDAO.value) {
				Artifact a = new Artifact();
				a.setMechid(arti.mechid);
				a.setMachine(arti.machine);
				a.setSponsor(arti.sponsor);
				a.setAppName(arti.appName);
				a.setCa(arti.ca);
				a.setDir(arti.dir);
				a.getType().addAll(arti.type(false));
				a.setOsUser(arti.os_user);
				a.setRenewDays(arti.renewDays);
				a.setNotification(arti.notify);
				artis.getArtifact().add(a);
			}
			return Result.ok(artis);
		} else {
			return Result.err(lArtiDAO);
		}
	}
970446
protected function loadExistingArchiveIdFromDb()
    {
        $noArchiveFound = array(false, false, false);

        // see isArchiveTemporary()
        $minDatetimeArchiveProcessedUTC = $this->getMinTimeArchiveProcessed();

        if ($this->isArchivingForcedToTrigger()) {
            return $noArchiveFound;
        }

        $idAndVisits = ArchiveSelector::getArchiveIdAndVisits($this->params, $minDatetimeArchiveProcessedUTC);

        if (!$idAndVisits) {
            return $noArchiveFound;
        }

        return $idAndVisits;
    }
222764
private File getArtifactFile(MavenBuild build, MavenArtifact mavenArtifact) throws IOException {
        String fileName = mavenArtifact.fileName;
        if (isArchiveJenkinsVersion) {
            fileName = mavenArtifact.canonicalName;
        }
        File file = new File(new File(new File(new File(build.getArtifactsDir(), mavenArtifact.groupId),
                mavenArtifact.artifactId), mavenArtifact.version), fileName);
        if (!file.exists()) {
            throw new FileNotFoundException("Archived artifact is missing: " + file + " " + getAdditionalMessage());
        }
        return file;
    }
764843
function () {
      var doUniqueArtifactIdsCheck = function (artifactsIds) {
        var duplicateArtifactIds = [];
        artifactsIds.forEach(function (artifactId) {
          var artifactIdUnderTest = artifactId;

          function filterById (id) {
            return id === artifactIdUnderTest;
          }

          var arrayByUniqueArtifactIds = artifactsIds.filter(filterById);
          if (arrayByUniqueArtifactIds.length > 1 && duplicateArtifactIds.indexOf(artifactIdUnderTest) < 0) {
            duplicateArtifactIds.push(artifactIdUnderTest);
          }
        });
        duplicateArtifactIds.forEach(function (artifactId) {
          errors.push(
            'RuleViolation identified: WebPackage contains multiple artifacts with \'artifactId\'=\'' +
            artifactId + '\'');
        });
      };
      //
      var collectArtifactIds = function (next) {
        var artifactsIds = [];
        if (doc.artifacts) {
          Object.keys(doc.artifacts).forEach(function (artifactType) {
            doc.artifacts[ artifactType ].forEach(function (artifact) {
              artifactsIds.push(artifact.artifactId);
            });
          });
        }
        next(artifactsIds);
      };
      collectArtifactIds(doUniqueArtifactIdsCheck);
    }
51591
protected function getFileDescriptor($element)
    {
        $fileDescriptor = $element instanceof FileDescriptor
            ? $element
            : $element->getFile();

        if (!$fileDescriptor instanceof FileDescriptor) {
            throw new \UnexpectedValueException('An element should always have a file associated with it');
        }

        return $fileDescriptor;
    }
312657
private function initTableTypeExtensions()
    {
        $this->tableTypeExtensions = [];

        foreach ($this->loadTableTypeExtensions() as $extension) {
            if (!$extension instanceof TableTypeExtensionInterface) {
                throw new UnexpectedTypeException($extension, TableTypeExtensionInterface::class);
            }

            $type = $extension->getExtendedType();

            $this->tableTypeExtensions[$type][] = $extension;
        }
    }
551226
def DumpArtifactsToYaml(self, sort_by_os=True):
    """"""
    artifact_list = self.GetArtifacts()
    if sort_by_os:
      # Sort so its easier to split these if necessary.
      yaml_list = []
      done_set = set()
      for os_name in rdf_artifacts.Artifact.SUPPORTED_OS_LIST:
        done_set = set(a for a in artifact_list if a.supported_os == [os_name])
        # Separate into knowledge_base and non-kb for easier sorting.
        done_set = sorted(done_set, key=lambda x: x.name)
        yaml_list.extend(x.ToYaml() for x in done_set if x.provides)
        yaml_list.extend(x.ToYaml() for x in done_set if not x.provides)
        artifact_list = artifact_list.difference(done_set)
      yaml_list.extend(x.ToYaml() for x in artifact_list)  # The rest.
    else:
      yaml_list = [x.ToYaml() for x in artifact_list]

    return "---\n\n".join(yaml_list)