Beispiel #1
0
def write_metadata(metadata_file, artifacts):
    if os.path.exists(metadata_file):
        metadata = Metadata.create_from_file(metadata_file)
    else:
        metadata = Metadata()

    # pylint:disable=E1103
    metadata.artifacts += deepcopy(artifacts)

    metadata.write_to_file(metadata_file)
Beispiel #2
0
def write_metadata(metadata_file, artifacts):
    if os.path.exists(metadata_file):
        metadata = Metadata.create_from_file(metadata_file)
    else:
        metadata = Metadata()

    # pylint:disable=E1103
    metadata.artifacts += deepcopy(artifacts)

    metadata.write_to_file(metadata_file)
def get_parent_pom(pom):
    try:
        metadata = Metadata.create_from_file(config)
        known_artifacts = metadata.get_provided_artifacts()
        # TODO: implement __hash__() and __cmp__() in MetadataArtifact
        for artifact in known_artifacts:
            if (
                artifact.extension == "pom"
                and artifact.groupId == pom.groupId
                and artifact.artifactId == pom.artifactId
            ):
                return POM(artifact.path)
    except IOError:
        pass

    req = ResolutionRequest(pom.groupId, pom.artifactId, extension="pom", version=pom.version)
    result = XMvnResolve.process_raw_request([req])[0]
    if not result:
        raise XMvnResolveException(
            "Unable to resolve parent POM {g}:{a}:{e}:{v}".format(
                g=pom.groupId, a=pom.artifactId, e="pom", v=pom.version
            )
        )

    return POM(result.artifactPath)
Beispiel #4
0
def get_parent_pom(pom):
    try:
        metadata = Metadata(config)
        known_artifacts = metadata.get_provided_artifacts()
        # TODO: implement __hash__() and __cmp__() in MetadataArtifact
        for artifact in known_artifacts:
            if (artifact.extension == "pom" and
               artifact.groupId == pom.groupId and
               artifact.artifactId == pom.artifactId):
                return POM(artifact.path)
    except IOError:
        pass

    req = ResolutionRequest(pom.groupId, pom.artifactId,
                            extension="pom", version=pom.version)
    result = XMvnResolve.process_raw_request([req])[0]
    if not result:
        raise Exception("Unable to resolve parent POM")

    return POM(result.artifactPath)
Beispiel #5
0
    def _process_buildroot(self):
        # "path: Metadata" mapping
        cache = {}

        metadata_paths = self._find_paths()
        for path in metadata_paths:
            try:
                metadata = Metadata.create_from_file(path)
                if metadata:
                    cache.update({path: metadata})
            except MetadataLoadingException:
                continue

        return cache
Beispiel #6
0
    def _process_buildroot(self):
        # "path: Metadata" mapping
        cache = {}

        metadata_paths = self._find_paths()
        for path in metadata_paths:
            try:
                metadata = Metadata(path)
                if metadata:
                    cache.update({path: metadata})
            except MetadataLoadingException:
                continue

        return cache
Beispiel #7
0
 def test_decorated(self, *args, **kwargs):
     main_dir = os.path.dirname(os.path.realpath(__file__))
     fn(self, Metadata.create_from_file(os.path.join(main_dir, "data", fname)))
Beispiel #8
0
def _main():
    OptionParser.format_epilog = lambda self, formatter: self.epilog
    parser = OptionParser(usage=usage, epilog=epilog)
    parser.add_option("--skip-dependencies",
                      action="store_true",
                      default=False,
                      help="skip dependencies section in resulting metadata")
    parser.add_option("-D",
                      action="append",
                      type="str",
                      help="add artifact property",
                      metavar="property=value")

    sys.argv = args_to_unicode(sys.argv)

    (options, args) = parser.parse_args()
    if len(args) < 1:
        parser.error("At least 1 argument is required")

    try:
        uart = Artifact.from_mvn_str(args[0])
        uart.validate(allow_backref=False)
        if len(args) == 1:
            parser.error(
                "When using artifact specification artifact path must be "
                "provided")
        if not (uart.groupId and uart.artifactId and uart.version):
            parser.error("Defined artifact has to include at least groupId, "
                         "artifactId and version")
    except (ArtifactFormatException):
        if is_it_ivy_file(args[0]):
            uart = IvyFile(args[0])
        else:
            # it should be good old POM file
            uart = POM(args[0])
        pom_path = args[0]
    else:
        pom_path = None

    art = MetadataArtifact(uart.groupId, uart.artifactId, version=uart.version)
    if hasattr(uart, "extension") and uart.extension:
        art.extension = uart.extension
    if hasattr(uart, "classifier") and uart.classifier:
        art.classifier = uart.classifier

    jar_path = None
    if len(args) > 1:
        jar_path = args[1]
        extension = (os.path.splitext(jar_path)[1])[1:]
        if hasattr(
                art, "extension"
        ) and art.extension and art.extension != extension and not pom_path:
            raise ExtensionsDontMatch("Extensions don't match: '%s' != '%s'" %
                                      (art.extension, extension))
        else:
            art.extension = extension
    else:
        art.extension = "pom"

    if os.path.exists(config):
        metadata = Metadata.create_from_file(config)
    else:
        metadata = Metadata()

    if (not options.skip_dependencies and pom_path
            and not is_it_ivy_file(pom_path)):
        deps = []
        mvn_deps = gather_dependencies(pom_path)
        for d in mvn_deps:
            deps.append(MetadataDependency.from_mvn_dependency(d))
        if deps:
            art.dependencies = set(deps)
    else:
        art.properties["xmvn.resolver.disableEffectivePom"] = "true"

    if options.D:
        for d_opt in options.D:
            key, value = d_opt.split("=")
            art.properties[key] = value

    add_artifact_elements(metadata, art, pom_path, jar_path)

    metadata.write_to_file(config)
def _main():
    OptionParser.format_epilog = lambda self, formatter: self.epilog
    parser = OptionParser(usage=usage, epilog=epilog)
    parser.add_option(
        "--skip-dependencies",
        action="store_true",
        default=False,
        help="skip dependencies section in resulting metadata",
    )
    parser.add_option("-D", action="append", type="str", help="add artifact property", metavar="property=value")

    sys.argv = args_to_unicode(sys.argv)

    (options, args) = parser.parse_args()
    if len(args) < 1:
        parser.error("At least 1 argument is required")

    try:
        uart = Artifact.from_mvn_str(args[0])
        uart.validate(allow_backref=False)
        if len(args) == 1:
            parser.error("When using artifact specification artifact path must be " "provided")
        if not (uart.groupId and uart.artifactId and uart.version):
            parser.error("Defined artifact has to include at least groupId, " "artifactId and version")
    except (ArtifactFormatException):
        if is_it_ivy_file(args[0]):
            uart = IvyFile(args[0])
        else:
            # it should be good old POM file
            uart = POM(args[0])
        pom_path = args[0]
    else:
        pom_path = None

    art = MetadataArtifact(uart.groupId, uart.artifactId, version=uart.version)
    if hasattr(uart, "extension") and uart.extension:
        art.extension = uart.extension
    if hasattr(uart, "classifier") and uart.classifier:
        art.classifier = uart.classifier

    jar_path = None
    if len(args) > 1:
        jar_path = args[1]
        extension = (os.path.splitext(jar_path)[1])[1:]
        if hasattr(art, "extension") and art.extension and art.extension != extension and not pom_path:
            raise ExtensionsDontMatch("Extensions don't match: '%s' != '%s'" % (art.extension, extension))
        else:
            art.extension = extension
    else:
        art.extension = "pom"

    if os.path.exists(config):
        metadata = Metadata.create_from_file(config)
    else:
        metadata = Metadata()

    if not options.skip_dependencies and pom_path and not is_it_ivy_file(pom_path):
        deps = []
        mvn_deps = gather_dependencies(pom_path)
        for d in mvn_deps:
            deps.append(MetadataDependency.from_mvn_dependency(d))
        if deps:
            art.dependencies = set(deps)
    else:
        art.properties["xmvn.resolver.disableEffectivePom"] = "true"

    if options.D:
        for d_opt in options.D:
            key, value = d_opt.split("=")
            art.properties[key] = value

    add_artifact_elements(metadata, art, pom_path, jar_path)

    metadata.write_to_file(config)