HHH-6038 - Migrate to use newly separated gradle-upload-auth-plugin
This commit is contained in:
parent
671ef3accd
commit
29e21e9b25
15
build.gradle
15
build.gradle
|
@ -10,6 +10,17 @@ allprojects {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenRepo name: 'jboss-nexus', urls: "https://repository.jboss.org/nexus/content/groups/public/"
|
||||||
|
mavenRepo name: "jboss-snapshots", urls: "http://snapshots.jboss.org/maven2/"
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath 'org.hibernate.build.gradle:gradle-upload-auth-plugin:1.0.0'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ideaProject {
|
ideaProject {
|
||||||
javaVersion = "1.6"
|
javaVersion = "1.6"
|
||||||
withXml { provider ->
|
withXml { provider ->
|
||||||
|
@ -86,11 +97,11 @@ subprojects { subProject ->
|
||||||
|
|
||||||
// minimize changes, at least for now (gradle uses 'build' by default)..
|
// minimize changes, at least for now (gradle uses 'build' by default)..
|
||||||
buildDir = "target"
|
buildDir = "target"
|
||||||
|
|
||||||
if ( ! subProject.name.startsWith( 'release' ) ) {
|
if ( ! subProject.name.startsWith( 'release' ) ) {
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'maven' // for install task as well as deploy dependencies
|
apply plugin: 'maven' // for install task as well as deploy dependencies
|
||||||
apply plugin: org.hibernate.build.gradle.upload.UploadAuthenticationManager
|
apply plugin: 'uploadAuth'
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
provided {
|
provided {
|
||||||
|
|
|
@ -1,90 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.hibernate.build.gradle.upload;
|
|
||||||
|
|
||||||
import org.apache.maven.artifact.ant.Authentication;
|
|
||||||
import org.apache.maven.artifact.ant.RemoteRepository;
|
|
||||||
import org.gradle.api.Action;
|
|
||||||
import org.gradle.api.DefaultTask;
|
|
||||||
import org.gradle.api.artifacts.maven.MavenDeployer;
|
|
||||||
import org.gradle.api.tasks.TaskAction;
|
|
||||||
import org.gradle.api.tasks.Upload;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Acts as the main authentication coordinator for the upload. It will delegate to all {@link AuthenticationProvider}
|
|
||||||
* instances registered with the {@link AuthenticationProviderRegistry} looking for any that provide
|
|
||||||
* {@link Authentication} against the given {@link RemoteRepository} defined for each upload task.
|
|
||||||
* <p/>
|
|
||||||
* IMPL NOTE : This will need to change drastically whenever Gradle moves to its {@code Publication} scheme for uploads.
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
public class AuthenticationHandler extends DefaultTask {
|
|
||||||
private AuthenticationProviderRegistry authenticationProviderRegistry;
|
|
||||||
private Upload uploadTask;
|
|
||||||
|
|
||||||
public void injectProviderRegistry(AuthenticationProviderRegistry authenticationProviderRegistry) {
|
|
||||||
this.authenticationProviderRegistry = authenticationProviderRegistry;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void injectUploadTask(Upload uploadTask) {
|
|
||||||
this.uploadTask = uploadTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
@TaskAction
|
|
||||||
public void configureUploadAuthentication() {
|
|
||||||
// todo : unfortunately I have no idea how to apply this to non MavenDeployer-type repos...
|
|
||||||
uploadTask.getRepositories().withType( MavenDeployer.class ).all(
|
|
||||||
new Action<MavenDeployer>() {
|
|
||||||
public void execute(MavenDeployer deployer) {
|
|
||||||
final RemoteRepository repository = deployer.getRepository();
|
|
||||||
if ( repository != null ) {
|
|
||||||
final Authentication authentication = locateAuthenticationDetails( repository );
|
|
||||||
if ( authentication != null ) {
|
|
||||||
repository.addAuthentication( authentication );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final RemoteRepository snapshotRepository = deployer.getSnapshotRepository();
|
|
||||||
if ( snapshotRepository != null ) {
|
|
||||||
final Authentication authentication = locateAuthenticationDetails( snapshotRepository );
|
|
||||||
if ( authentication != null ) {
|
|
||||||
snapshotRepository.addAuthentication( authentication );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Authentication locateAuthenticationDetails(RemoteRepository repository) {
|
|
||||||
for ( AuthenticationProvider provider : authenticationProviderRegistry.providers() ) {
|
|
||||||
Authentication authentication = provider.determineAuthentication( repository );
|
|
||||||
if ( authentication != null ) {
|
|
||||||
return authentication;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,45 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.build.gradle.upload;
|
|
||||||
|
|
||||||
import org.apache.maven.artifact.ant.Authentication;
|
|
||||||
import org.apache.maven.artifact.ant.RemoteRepository;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contract for providers of {@link Authentication} details for authenticating against remote repositories.
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
public interface AuthenticationProvider {
|
|
||||||
/**
|
|
||||||
* The contract method. Given a repository, determine the {@link Authentication} according to this provider's
|
|
||||||
* contract. Return {@literal null} to indicate no {@link Authentication} applied for this repository by this
|
|
||||||
* provider.
|
|
||||||
*
|
|
||||||
* @param remoteRepository The repository to check for authentication details.
|
|
||||||
*
|
|
||||||
* @return The authentication details, or {@literal null} to indicate none.
|
|
||||||
*/
|
|
||||||
public Authentication determineAuthentication(RemoteRepository remoteRepository);
|
|
||||||
}
|
|
|
@ -1,53 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.build.gradle.upload;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A registry of {@link AuthenticationProvider} instances.
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
public class AuthenticationProviderRegistry {
|
|
||||||
private final LinkedList<AuthenticationProvider> authenticationProviders = buildStandardAuthenticationProviders();
|
|
||||||
|
|
||||||
private static LinkedList<AuthenticationProvider> buildStandardAuthenticationProviders() {
|
|
||||||
LinkedList<AuthenticationProvider> providers = new LinkedList<AuthenticationProvider>();
|
|
||||||
providers.add( new StandardMavenAuthenticationProvider() );
|
|
||||||
return providers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void appendAuthenticationProvider(AuthenticationProvider provider) {
|
|
||||||
authenticationProviders.addLast( provider );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void prependAuthenticationProvider(AuthenticationProvider provider) {
|
|
||||||
authenticationProviders.addFirst( provider );
|
|
||||||
}
|
|
||||||
|
|
||||||
public Iterable<AuthenticationProvider> providers() {
|
|
||||||
return authenticationProviders;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,124 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.build.gradle.upload;
|
|
||||||
|
|
||||||
import org.apache.maven.artifact.ant.Authentication;
|
|
||||||
import org.apache.maven.artifact.ant.RemoteRepository;
|
|
||||||
import org.dom4j.Document;
|
|
||||||
import org.dom4j.DocumentException;
|
|
||||||
import org.dom4j.Element;
|
|
||||||
import org.dom4j.io.SAXReader;
|
|
||||||
import org.xml.sax.InputSource;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provider of {@link org.apache.maven.artifact.ant.RemoteRepository} {@link Authentication} based on standard Maven
|
|
||||||
* conventions using {@literal settings.xml}.
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
public class StandardMavenAuthenticationProvider implements AuthenticationProvider {
|
|
||||||
private static final Logger log = LoggerFactory.getLogger( StandardMavenAuthenticationProvider.class );
|
|
||||||
|
|
||||||
public static final String SETTINGS_LOCATION_OVERRIDE = "maven.settings";
|
|
||||||
|
|
||||||
private ConcurrentHashMap<String,Authentication> repositoryAuthenticationMap;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Authentication determineAuthentication(RemoteRepository remoteRepository) {
|
|
||||||
if ( repositoryAuthenticationMap == null ) {
|
|
||||||
loadRepositoryAuthenticationMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
return repositoryAuthenticationMap.get( remoteRepository.getId() );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadRepositoryAuthenticationMap() {
|
|
||||||
repositoryAuthenticationMap = new ConcurrentHashMap<String, Authentication>();
|
|
||||||
|
|
||||||
final File settingsFile = determineSettingsFileLocation();
|
|
||||||
try {
|
|
||||||
InputSource inputSource = new InputSource( new FileInputStream( settingsFile ) );
|
|
||||||
try {
|
|
||||||
final Document document = buildSAXReader().read( inputSource );
|
|
||||||
final Element settingsElement = document.getRootElement();
|
|
||||||
final Element serversElement = settingsElement.element( "servers" );
|
|
||||||
final Iterator serversIterator = serversElement.elementIterator( "server" );
|
|
||||||
while ( serversIterator.hasNext() ) {
|
|
||||||
final Element serverElement = (Element) serversIterator.next();
|
|
||||||
final String id = extractValue( serverElement.element( "id" ) );
|
|
||||||
if ( id == null ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
final Authentication authentication = new Authentication();
|
|
||||||
authentication.setUserName( extractValue( serverElement.element( "username" ) ) );
|
|
||||||
authentication.setPassword( extractValue( serverElement.element( "password" ) ) );
|
|
||||||
authentication.setPrivateKey( extractValue( serverElement.element( "privateKey" ) ) );
|
|
||||||
authentication.setPassphrase( extractValue( serverElement.element( "passphrase" ) ) );
|
|
||||||
repositoryAuthenticationMap.put( id, authentication );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (DocumentException e) {
|
|
||||||
log.error( "Error reading Maven settings.xml", e );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch ( FileNotFoundException e ) {
|
|
||||||
log.info( "Unable to locate Maven settings.xml" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String extractValue(Element element) {
|
|
||||||
if ( element == null ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String value = element.getTextTrim();
|
|
||||||
if ( value != null && value.length() == 0 ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private SAXReader buildSAXReader() {
|
|
||||||
SAXReader saxReader = new SAXReader();
|
|
||||||
saxReader.setMergeAdjacentText( true );
|
|
||||||
return saxReader;
|
|
||||||
}
|
|
||||||
|
|
||||||
private File determineSettingsFileLocation() {
|
|
||||||
final String overrideLocation = System.getProperty( SETTINGS_LOCATION_OVERRIDE );
|
|
||||||
return overrideLocation == null
|
|
||||||
? new File( new File( System.getProperty( "user.home" ), ".m2" ), "settings.xml" )
|
|
||||||
: new File( overrideLocation );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,68 +0,0 @@
|
||||||
/*
|
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
|
||||||
* indicated by the @author tags or express copyright attribution
|
|
||||||
* statements applied by the authors. All third-party contributions are
|
|
||||||
* distributed under license by Red Hat Inc.
|
|
||||||
*
|
|
||||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
|
||||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
|
||||||
* Lesser General Public License, as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
||||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this distribution; if not, write to:
|
|
||||||
* Free Software Foundation, Inc.
|
|
||||||
* 51 Franklin Street, Fifth Floor
|
|
||||||
* Boston, MA 02110-1301 USA
|
|
||||||
*/
|
|
||||||
package org.hibernate.build.gradle.upload;
|
|
||||||
|
|
||||||
import org.gradle.api.Action;
|
|
||||||
import org.gradle.api.Plugin;
|
|
||||||
import org.gradle.api.Project;
|
|
||||||
import org.gradle.api.tasks.Upload;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Manages authentication aspects of artifact uploading by delegation to registered {@link AuthenticationProvider}
|
|
||||||
* instances.
|
|
||||||
*
|
|
||||||
* @author Steve Ebersole
|
|
||||||
*/
|
|
||||||
public class UploadAuthenticationManager implements Plugin<Project> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void apply(final Project project) {
|
|
||||||
// todo : ideally the registry would be handled by a convention to allow configuration (aka, adding more providers)...
|
|
||||||
// for our purposes here in Hibernate we only care about the Maven settings.xml based way so we
|
|
||||||
// code for just that.
|
|
||||||
final AuthenticationProviderRegistry registry = new AuthenticationProviderRegistry();
|
|
||||||
|
|
||||||
project.getTasks().withType( Upload.class ).all(
|
|
||||||
new Action<Upload>() {
|
|
||||||
@Override
|
|
||||||
public void execute(final Upload uploadTask) {
|
|
||||||
// create a auth task for each upload task...
|
|
||||||
final AuthenticationHandler authenticationHandler = project.getTasks().add(
|
|
||||||
"uploadAuthenticationHandler-" + uploadTask.getName(),
|
|
||||||
AuthenticationHandler.class
|
|
||||||
);
|
|
||||||
|
|
||||||
// link the auth task with the upload task
|
|
||||||
authenticationHandler.injectUploadTask( uploadTask );
|
|
||||||
|
|
||||||
// todo: Also in conjunction, would be best to have the handler lookup the registry rather than pushing it
|
|
||||||
authenticationHandler.injectProviderRegistry( registry );
|
|
||||||
|
|
||||||
uploadTask.getDependsOn().add( authenticationHandler );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Reference in New Issue