Example #1
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)
Example #2
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)
Example #3
0
            art.extension = extension
    else:
        art.extension = "pom"

    if os.path.exists(config):
        xml = open(config).read()
        metadata = m.CreateFromDocument(xml)
    else:
        metadata = m.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)

    with open(config, 'w') as f:
        write_metadata(f, metadata)