def _main():
    usage="usage: %prog [options] metadata_path pom_path|<MVN spec> [jar_path]"
    parser = OptionParser(usage=usage)
    parser.add_option("-a","--append",type="str",
                      help="Additional depmaps to add (gid:aid)  [default: %default]")
    parser.add_option('-r', '--versions', type="str",
                      help='Additional versions to add for each depmap')
    parser.add_option('-n', '--namespace', type="str",
                      help='Namespace to use for generated fragments', default="")
    parser.add_option('--pom-base', type="str",
                      help='Base path under which POM files are installed', default="")
    parser.add_option('--jar-base', type="str",
                      help='Base path under which JAR files are installed', default="")

    parser.set_defaults(append=None)

    (options, args) = parser.parse_args()
    append_deps = options.append
    add_versions = options.versions
    namespace = options.namespace
    pom_base = options.pom_base
    jar_base = options.jar_base

    if len(args) < 2:
        parser.error("Incorrect number of arguments")
    # These will fail when incorrect number of arguments is given.
    metadata_path = args[0].strip()
    pom_path = args[1].strip()
    jar_path = None

    artifact = None
    have_pom = False

    if len(args) == 3:
        jar_path = args[2].strip()
        if ':' in pom_path:
            pom_str = pom_path.rsplit('/')[-1]
            artifact = MetadataArtifact.from_mvn_str(pom_str)
            artifact_ext = artifact.extension or "jar"
            file_ext = os.path.splitext(jar_path)[1][1:]
            if artifact_ext != file_ext:
                raise ExtensionsDontMatch(artifact_ext, file_ext)

            if artifact.extension == 'jar':
                artifact.extension = ''

            if not artifact.version:
                parser.error("Artifact definition has to include version")
        else:
            artifact = MetadataArtifact.from_pom(pom_path)
            ext = os.path.splitext(jar_path)[1][1:]
            if ext != "jar":
                artifact.extension = ext
            have_pom = True
        if artifact:
            inject_pom_properties(jar_path, artifact)
    else:
        # looks like POM only artifact
        if ':' not in pom_path:
            artifact = MetadataArtifact.from_pom(pom_path)
            have_pom = True

            if POM(pom_path).packaging != "pom":
                raise PackagingTypeMissingFile(pom_path)
        else:
            sys.exit("JAR file path must be specified when using artifact coordinates")


    # output file path for file lists
    print(metadata_path)

    artifact = add_compat_versions(artifact, add_versions)
    if add_versions:
        pom_path, jar_path = _make_files_versioned(add_versions, pom_path, jar_path, pom_base, jar_base)

    if namespace:
        artifact.namespace = namespace

    artifact.properties["xmvn.resolver.disableEffectivePom"] = "true"


    buildroot = os.environ.get('RPM_BUILD_ROOT')
    am = []
    if jar_path:
        metadata_jar_path = os.path.abspath(jar_path)
        artifact.path = metadata_jar_path.replace(buildroot, "") if buildroot else metadata_jar_path
        artifact = add_aliases(artifact, append_deps)
        if artifact.extension == "jar":
            artifact.extension = ""
        am.append(artifact.copy())
        # output file path for file list (if it's not versioned)
        if not add_versions:
            _print_path_with_dirs(jar_path, jar_base)
    if have_pom:
        metadata_pom_path = os.path.abspath(pom_path)
        artifact.path = metadata_pom_path.replace(buildroot, "") if buildroot else metadata_pom_path
        artifact.extension = "pom"
        artifact.aliases = None
        artifact = add_aliases(artifact, append_deps)
        am.append(artifact.copy())
        # output file path for file list (if it's not versioned)
        if not add_versions:
            _print_path_with_dirs(pom_path, pom_base)

    write_metadata(metadata_path, am)
Exemple #2
0
def _main():
    usage = "usage: %prog [options] metadata_path pom_path|<MVN spec> [jar_path]"
    parser = OptionParser(usage=usage)
    parser.add_option(
        "-a",
        "--append",
        type="str",
        help="Additional depmaps to add (gid:aid)  [default: %default]")
    parser.add_option('-r',
                      '--versions',
                      type="str",
                      help='Additional versions to add for each depmap')
    parser.add_option('-n',
                      '--namespace',
                      type="str",
                      help='Namespace to use for generated fragments',
                      default="")
    parser.add_option('--pom-base',
                      type="str",
                      help='Base path under which POM files are installed',
                      default="")
    parser.add_option('--jar-base',
                      type="str",
                      help='Base path under which JAR files are installed',
                      default="")

    parser.set_defaults(append=None)

    (options, args) = parser.parse_args()
    append_deps = options.append
    add_versions = options.versions
    namespace = options.namespace
    pom_base = options.pom_base
    jar_base = options.jar_base

    if len(args) < 2:
        parser.error("Incorrect number of arguments")
    # These will fail when incorrect number of arguments is given.
    metadata_path = args[0].strip()
    pom_path = args[1].strip()
    jar_path = None

    artifact = None
    have_pom = False

    if len(args) == 3:
        jar_path = args[2].strip()
        if ':' in pom_path:
            pom_str = pom_path.rsplit('/')[-1]
            artifact = MetadataArtifact.from_mvn_str(pom_str)
            artifact_ext = artifact.extension or "jar"
            file_ext = os.path.splitext(jar_path)[1][1:]
            if artifact_ext != file_ext:
                raise ExtensionsDontMatch(artifact_ext, file_ext)

            if artifact.extension == 'jar':
                artifact.extension = ''

            if not artifact.version:
                parser.error("Artifact definition has to include version")
        else:
            artifact = MetadataArtifact.from_pom(pom_path)
            ext = os.path.splitext(jar_path)[1][1:]
            if ext != "jar":
                artifact.extension = ext
            have_pom = True
        if artifact:
            inject_pom_properties(jar_path, artifact)
    else:
        # looks like POM only artifact
        if ':' not in pom_path:
            artifact = MetadataArtifact.from_pom(pom_path)
            have_pom = True

            if POM(pom_path).packaging != "pom":
                raise PackagingTypeMissingFile(pom_path)
        else:
            sys.exit(
                "JAR file path must be specified when using artifact coordinates"
            )

    # output file path for file lists
    print(metadata_path)

    artifact = add_compat_versions(artifact, add_versions)
    if add_versions:
        pom_path, jar_path = _make_files_versioned(add_versions, pom_path,
                                                   jar_path, pom_base,
                                                   jar_base)

    if namespace:
        artifact.namespace = namespace

    artifact.properties["xmvn.resolver.disableEffectivePom"] = "true"

    buildroot = os.environ.get('RPM_BUILD_ROOT')
    am = []
    if jar_path:
        metadata_jar_path = os.path.abspath(jar_path)
        artifact.path = metadata_jar_path.replace(
            buildroot, "") if buildroot else metadata_jar_path
        artifact = add_aliases(artifact, append_deps)
        if artifact.extension == "jar":
            artifact.extension = ""
        am.append(artifact.copy())
        # output file path for file list (if it's not versioned)
        if not add_versions:
            _print_path_with_dirs(jar_path, jar_base)
    if have_pom:
        metadata_pom_path = os.path.abspath(pom_path)
        artifact.path = metadata_pom_path.replace(
            buildroot, "") if buildroot else metadata_pom_path
        artifact.extension = "pom"
        artifact.aliases = None
        artifact = add_aliases(artifact, append_deps)
        am.append(artifact.copy())
        # output file path for file list (if it's not versioned)
        if not add_versions:
            _print_path_with_dirs(pom_path, pom_base)

    write_metadata(metadata_path, am)
        parser.error("Incorrect number of arguments")
    # These will fail when incorrect number of arguments is given.
    metadata_path = args[0].strip()
    pom_path = args[1].strip()
    jar_path = None

    artifact = None
    have_pom = False

    if len(args) == 3:
        jar_path = args[2].strip()
        local = None
        fragment = None
        if ':' in pom_path:
            pom_str = pom_path.rsplit('/')[-1]
            artifact = MetadataArtifact.from_mvn_str(pom_str)
            artifact_ext = artifact.extension or "jar"
            file_ext = os.path.splitext(jar_path)[1][1:]
            if artifact_ext != file_ext:
                raise ExtensionsDontMatch(artifact_ext, file_ext)

            if artifact.extension == 'jar':
                artifact.extension = ''

            if not artifact.version:
                parser.error("Artifact definition has to include version")
        else:
            artifact = MetadataArtifact.from_pom(pom_path)
            ext = os.path.splitext(jar_path)[1][1:]
            if ext != "jar":
                artifact.extension = ext