LUCENE-4476: stage-maven-artifacts: prompt for credentials by default, rather than reading from settings.xml; and stop requiring (grand-)parent POMs' presence in the maven local repository

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1402630 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Steven Rowe 2012-10-26 19:39:31 +00:00
parent 42f27adc1a
commit 064d8a392b
2 changed files with 97 additions and 37 deletions

View File

@ -12,6 +12,10 @@
# 2. The pathname of the Ant build script to be built.
# 3. The pathname of common-build.xml, which will be imported
# in the Ant build script to be built.
# 4. Whether to prompt for credentials, rather than consulting
# settings.xml: boolean, e.g. "true" or "false"
# 5. The ID of the target repository
# 6. The URL to the target repository
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
@ -33,33 +37,72 @@ use strict;
use warnings;
use File::Basename;
use File::Find;
use Cwd 'abs_path';
use File::Path qw(make_path);
my $num_artifacts = 0;
my $maven_dist_dir = $ARGV[0];
my $maven_dist_dir = abs_path($ARGV[0]);
my $output_build_xml_file = $ARGV[1];
my $common_build_xml = $ARGV[2];
my $m2_credentials_prompt = $ARGV[3];
my $m2_repository_id = $ARGV[4];
my $m2_repository_url = $ARGV[5];
if ($^O eq 'cygwin') { # Make sure Cygwin Perl can find the output path
$output_build_xml_file = `cygpath -u "$output_build_xml_file"`;
$output_build_xml_file =~ s/\s+$//; # Trim trailing whitespace
$output_build_xml_file =~ s/^\s+//; # Trim leading whitespace
}
my ($output_file, $output_dir) = fileparse($output_build_xml_file);
my @basepaths = ();
my $grandparent_pom = '';
my @parent_poms = ();
sub find_poms;
File::Find::find({follow => 1, wanted => \&find_poms}, $maven_dist_dir);
my $parent_pom_targets = '';
if (@parent_poms) {
$parent_pom_targets = "<parent-poms>\n";
if ($grandparent_pom) {
$parent_pom_targets .= qq! <artifact:pom id="grandparent" file="$grandparent_pom"/>\n!;
}
my $n = 0;
for my $parent_pom (@parent_poms) {
$parent_pom_targets .= qq! <artifact:pom id="parent.$n" file="$parent_pom"/>\n!;
++$n;
}
$parent_pom_targets .= " </parent-poms>\n";
}
make_path($output_dir);
open my $output_build_xml, ">$output_build_xml_file"
or die "ERROR opening '$ARGV[1]' for writing: $!";
print $output_build_xml qq!<?xml version="1.0"?>
<project>
<project xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<import file="${common_build_xml}"/>
<target name="stage-maven" depends="install-maven-tasks">
<sequential>
!;
sub wanted;
my $credentials = '';
if ($m2_credentials_prompt !~ /\A(?s:f(?:alse)?|no?)\z/) {
print $output_build_xml qq!
<input message="Enter $m2_repository_id username: >" addproperty="m2.repository.username"/>
<echo>WARNING: ON SOME PLATFORMS YOUR PASSPHRASE WILL BE ECHOED BACK\!\!\!\!\!</echo>
<input message="Enter $m2_repository_id password: >" addproperty="m2.repository.password">
<handler type="secure"/>
</input>\n!;
File::Find::find({follow => 1, wanted => \&wanted}, $maven_dist_dir);
$credentials = q!<credentials>
<authentication username="${m2.repository.username}" password="${m2.repository.password}"/>
</credentials>!;
}
for my $basepath (@basepaths) {
output_deploy_stanza($basepath);
}
print $output_build_xml q!
</sequential>
@ -72,7 +115,7 @@ close $output_build_xml;
print "Wrote '$output_build_xml_file' to stage $num_artifacts Maven artifacts.\n";
exit;
sub wanted {
sub find_poms {
/^(.*)\.pom\z/s && do {
my $pom_dir = $File::Find::dir;
if ($^O eq 'cygwin') { # Output windows-style paths on Windows
@ -83,21 +126,36 @@ sub wanted {
my $basefile = $_;
$basefile =~ s/\.pom\z//;
my $basepath = "$pom_dir/$basefile";
my $pom_file = "$basepath.pom";
my $jar_file = "$basepath.jar";
my $war_file = "$basepath.war";
push @basepaths, $basepath;
if (-f $war_file) {
print $output_build_xml qq!
if ($basefile =~ /grandparent/) {
$grandparent_pom = "$basepath.pom";
} elsif ($basefile =~ /parent/) {
push @parent_poms, "$basepath.pom";
}
}
}
sub output_deploy_stanza {
my $basepath = shift;
my $pom_file = "$basepath.pom";
my $jar_file = "$basepath.jar";
my $war_file = "$basepath.war";
if (-f $war_file) {
print $output_build_xml qq!
<m2-deploy pom.xml="${pom_file}" jar.file="${war_file}">
$parent_pom_targets
<artifact-attachments>
<attach file="${pom_file}.asc" type="pom.asc"/>
<attach file="${war_file}.asc" type="war.asc"/>
</artifact-attachments>
$credentials
</m2-deploy>\n!;
} elsif (-f $jar_file) {
print $output_build_xml qq!
} elsif (-f $jar_file) {
print $output_build_xml qq!
<m2-deploy pom.xml="${pom_file}" jar.file="${jar_file}">
$parent_pom_targets
<artifact-attachments>
<attach file="${basepath}-sources.jar" classifier="sources"/>
<attach file="${basepath}-javadoc.jar" classifier="javadoc"/>
@ -106,16 +164,18 @@ sub wanted {
<attach file="${basepath}-sources.jar.asc" classifier="sources" type="jar.asc"/>
<attach file="${basepath}-javadoc.jar.asc" classifier="javadoc" type="jar.asc"/>
</artifact-attachments>
$credentials
</m2-deploy>\n!;
} else {
print $output_build_xml qq!
} else {
print $output_build_xml qq!
<m2-deploy pom.xml="${pom_file}">
$parent_pom_targets
<artifact-attachments>
<attach file="${pom_file}.asc" type="pom.asc"/>
</artifact-attachments>
$credentials
</m2-deploy>\n!;
}
}
++$num_artifacts;
};
++$num_artifacts;
}

View File

@ -181,6 +181,7 @@
<makeurl file="${maven.dist.dir}" property="m2.repository.url" validate="false"/>
<property name="m2.repository.private.key" value="${user.home}/.ssh/id_dsa"/>
<property name="m2.repository.id" value="local"/>
<property name="m2.credentials.prompt" value="true"/>
<property name="jflex.home" location="${common.dir}"/>
@ -458,37 +459,24 @@
<macrodef name="m2-deploy" description="Builds a Maven artifact">
<element name="artifact-attachments" optional="yes"/>
<element name="parent-poms" optional="yes"/>
<element name="credentials" optional="yes"/>
<attribute name="pom.xml"/>
<attribute name="jar.file" default="${build.dir}/${final.name}.jar"/>
<sequential>
<artifact:install-provider artifactId="wagon-ssh" version="1.0-beta-7"/>
<parent-poms/>
<artifact:pom id="maven.project" file="@{pom.xml}"/>
<artifact:deploy file="@{jar.file}">
<artifact-attachments/>
<remoteRepository id="${m2.repository.id}" url="${m2.repository.url}"/>
<remoteRepository id="${m2.repository.id}" url="${m2.repository.url}">
<credentials/>
</remoteRepository>
<pom refid="maven.project"/>
</artifact:deploy>
</sequential>
</macrodef>
<macrodef name="m2-deploy-with-pom-template" description="Builds a Maven artifact given a POM template">
<attribute name="pom.xml"/>
<attribute name="jar.file"/>
<sequential>
<copy file="@{pom.xml}" tofile="${maven.build.dir}/pom.xml" overwrite="true">
<filterset begintoken="@" endtoken="@">
<filter token="version" value="${version}"/>
</filterset>
</copy>
<artifact:install-provider artifactId="wagon-ssh" version="1.0-beta-7"/>
<artifact:pom id="maven.project" file="${maven.build.dir}/pom.xml" />
<artifact:deploy file="@{jar.file}">
<remoteRepository id="${m2.repository.id}" url="${m2.repository.url}"/>
<pom refid="maven.project"/>
</artifact:deploy>
</sequential>
</macrodef>
<!-- validate maven dependencies -->
<macrodef name="m2-validate-dependencies">
<attribute name="pom.xml"/>
@ -1391,14 +1379,25 @@ ${tests-output}/junit4-*.suites - per-JVM executed suites
<sequential>
<property name="output.build.xml" location="${build.dir}/stage_maven_build.xml"/>
<property name="dev-tools.scripts.dir" value="../dev-tools/scripts"/>
<exec dir="." executable="${perl.exe}" failonerror="true" outputproperty="stage.maven.script.output">
<exec dir="." executable="${perl.exe}" failonerror="false" outputproperty="stage.maven.script.output"
resultproperty="stage.maven.script.success">
<arg value="-CSD"/>
<arg value="${dev-tools.scripts.dir}/write.stage.maven.build.xml.pl"/>
<arg value="${maven.dist.dir}"/> <!-- Maven distribution artifacts directory -->
<arg value="${output.build.xml}"/> <!-- Ant build file to be written -->
<arg value="${common.dir}/common-build.xml"/> <!-- Imported from the ant file to be written -->
<arg value="${m2.credentials.prompt}"/>
<arg value="${m2.repository.id}"/>
<arg value="${m2.repository.url}"/>
</exec>
<echo message="${stage.maven.script.output}"/>
<fail message="maven stage script failed!">
<condition>
<not>
<equals arg1="${stage.maven.script.success}" arg2="0"/>
</not>
</condition>
</fail>
</sequential>
<echo>Invoking target stage-maven in ${output.build.xml} now...</echo>
<ant target="stage-maven" antfile="${output.build.xml}" inheritall="false">
@ -1808,6 +1807,7 @@ ${tests-output}/junit4-*.suites - per-JVM executed suites
<available property="gpg.input.handler" classname="org.apache.tools.ant.input.SecureInputHandler"
value="org.apache.tools.ant.input.SecureInputHandler"/>
<!--else:--><property name="gpg.input.handler" value="org.apache.tools.ant.input.DefaultInputHandler"/>
<echo>WARNING: ON SOME PLATFORMS YOUR PASSPHRASE WILL BE ECHOED BACK!!!!!</echo>
<input message="Enter GPG keystore password: >" addproperty="gpg.passphrase">
<handler classname="${gpg.input.handler}" />
</input>