Exemple #1
0
    def _addArtifact(self, artifacts, groupId, artifactId, version, extsAndClass, suffix, url):
        pomMain = True
        # The pom is main only if no other main artifact is available
        if len(extsAndClass) > 1 and self._containsMainArtifact(extsAndClass) and "pom" in extsAndClass:
            pomMain = False

        artTypes = []
        for ext, classifiers in extsAndClass.iteritems():
            main = ext == "pom" and pomMain
            if not main:
                for classifier in classifiers:
                    extClassifier = "%s:%s" % (ext, classifier or "")
                    main = extClassifier not in self.notMainExtClassifiers
                    if main:
                        break
            artTypes.append(ArtifactType(ext, main, classifiers))

        mavenArtifact = MavenArtifact(groupId, artifactId, None, version)
        if suffix is not None:
            mavenArtifact.snapshotVersionSuffix = suffix
        if mavenArtifact in artifacts:
            artifacts[mavenArtifact].merge(ArtifactSpec(url, artTypes))
        else:
            logging.debug("Adding artifact %s", str(mavenArtifact))
            artifacts[mavenArtifact] = ArtifactSpec(url, artTypes)
 def _addArtifact(self, artifacts, groupId, artifactId, version,
                  extsAndClass, suffix, url):
     if len(extsAndClass) > 1 and self._containsNonPomWithoutClassifier(
             extsAndClass) and "pom" in extsAndClass:
         del extsAndClass["pom"]
     for ext in extsAndClass:
         mavenArtifact = MavenArtifact(groupId, artifactId, ext, version)
         if suffix is not None:
             mavenArtifact.snapshotVersionSuffix = suffix
         logging.debug("Adding artifact %s", str(mavenArtifact))
         artifacts[mavenArtifact] = ArtifactSpec(url, extsAndClass[ext])
def depListToArtifactList(depList):
    """Convert the maven GAV to a URL relative path"""
    regexComment = re.compile('#.*$')
    #regexLog = re.compile('^\[\w*\]')
    regexGAV = re.compile('(([\w\-.]+:){3}[\w\-.]+)(:[\w]*\S)?')
    artifactList = []
    for nextLine in depList:
        nextLine = regexComment.sub('', nextLine)
        nextLine = nextLine.strip()
        gav = regexGAV.search(nextLine)
        if gav:
            artifactList.append(MavenArtifact(gav.group(0)))
    return artifactList
    def _filterExcludedRepositories(self, artifactList, threadnum):
        """
        Filter artifactList removing artifacts existing in specified repositories.

        :param artifactList: artifactList to be filtered.
        :returns: artifactList without artifacts that exists in specified repositories.
        """

        logging.debug(
            "Filtering artifacts contained in excluded repositories.")

        pool = ThreadPool(threadnum)
        # Contains artifact to be removed
        delArtifacts = []
        for ga in artifactList.keys():
            groupId = ga.split(':')[0]
            artifactId = ga.split(':')[1]
            for priority in artifactList[ga].keys():
                for version in artifactList[ga][priority].keys():
                    artifact = MavenArtifact(groupId, artifactId, "pom",
                                             version)
                    pool.apply_async(_artifactInRepos, [
                        self.config.excludedRepositories, artifact, priority,
                        delArtifacts
                    ])

        # Close the pool and wait for the workers to finnish
        pool.close()
        pool.join()
        for artifact, priority in delArtifacts:
            ga = artifact.getGA()
            logging.debug(
                "Dropping GAV %s:%s from priority %i because it was found in an excluded repository.",
                ga, artifact.version, priority)
            del artifactList[ga][priority][artifact.version]
            if not artifactList[ga][priority]:
                logging.debug(
                    "Dropping GA %s from priority %i because of no version left.",
                    ga, priority)
                del artifactList[ga][priority]
            if not artifactList[ga]:
                logging.debug("Dropping GA %s because of no priority left.",
                              ga)
                del artifactList[ga]

        return artifactList
    def _filterExcludedRepositories(self, artifactList):
        """
        Filter artifactList removing artifacts existing in specified repositories.

        :param artifactList: artifactList to be filtered.
        :returns: artifactList without arifacts that exists in specified repositories.
        """

        logging.debug("Filtering artifacts contained in excluded repositories.")

        pool = ThreadPool(maven_repo_util.MAX_THREADS)
        # Contains artifact to be removed
        delArtifacts = []
        for gat in artifactList.keys():
            groupId = gat.split(':')[0]
            artifactId = gat.split(':')[1]
            artifactType = gat.split(':')[2]
            for priority in artifactList[gat].keys():
                for version in artifactList[gat][priority].keys():
                    artifact = MavenArtifact(groupId, artifactId, artifactType, version)
                    pool.apply_async(
                        _artifactInRepos,
                        [self.config.excludedRepositories, artifact, priority, delArtifacts]
                    )
                if not artifactList[gat][priority]:
                    del artifactList[gat][priority]
            if not artifactList[gat]:
                del artifactList[gat]

        # Close the pool and wait for the workers to finnish
        pool.close()
        pool.join()
        for artifact, priority in delArtifacts:
            del artifactList[artifact.getGAT()][priority][artifact.version]

        return artifactList
    def _filterExcludedTypes(self, artifactList):
        '''
        Filter artifactList removing GAVs with specified main types only, otherwise keeping GAVs with
        not-excluded artifact types only.

        :param artifactList: artifactList to be filtered.
        :param exclTypes: list of excluded types
        :returns: artifactList without artifacts that matched specified types and had no other main types.
        '''
        logging.debug("Filtering artifacts with excluded types.")
        regExps = maven_repo_util.getRegExpsFromStrings(
            self.config.gatcvWhitelist)
        exclTypes = self.config.excludedTypes
        for ga in artifactList.keys():
            for priority in artifactList[ga].keys():
                for version in artifactList[ga][priority].keys():
                    artSpec = artifactList[ga][priority][version]
                    for artType in list(artSpec.artTypes.keys()):
                        if artType in exclTypes:
                            artTypeObj = artSpec.artTypes[artType]
                            classifiers = artTypeObj.classifiers
                            (groupId, artifactId) = ga.split(':')
                            for classifier in list(classifiers):
                                art = MavenArtifact(groupId, artifactId,
                                                    artType, version,
                                                    classifier)
                                gatcv = art.getGATCV()
                                if not maven_repo_util.somethingMatch(
                                        regExps, gatcv):
                                    logging.debug(
                                        "Dropping classifier \"%s\" of %s:%s:%s from priority %i because of "
                                        "excluded type.", classifier, ga,
                                        artType, version, priority)
                                    classifiers.remove(classifier)
                                else:
                                    logging.debug(
                                        "Skipping drop of %s:%s:%s:%s from priority %i because it matches a "
                                        "whitelist pattern.", ga, artType,
                                        classifier, version, priority)
                            if not classifiers:
                                logging.debug(
                                    "Dropping %s:%s:%s from priority %i because of no classifier left.",
                                    ga, artType, version, priority)
                                del (artSpec.artTypes[artType])
                    noMain = True
                    for artType in artSpec.artTypes.keys():
                        artTypeObj = artSpec.artTypes[artType]
                        if artTypeObj.mainType:
                            noMain = False
                            break
                    if not artSpec.artTypes or noMain:
                        if noMain:
                            logging.debug(
                                "Dropping GAV %s:%s from priority %i because of no main artifact left.",
                                ga, version, priority)
                        else:
                            logging.debug(
                                "Dropping GAV %s:%s from priority %i because of no artifact type left.",
                                ga, version, priority)
                        del artifactList[ga][priority][version]
                if not artifactList[ga][priority]:
                    logging.debug(
                        "Dropping GA %s from priority %i because of no version left.",
                        ga, priority)
                    del artifactList[ga][priority]
            if not artifactList[ga]:
                logging.debug("Dropping GA %s because of no priority left.",
                              ga)
                del artifactList[ga]
        return artifactList