mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-30 21:08:30 +08:00
Add the "server" parameter (alternative to jdbcUser and jdbcPassword)
Add the "server" parameter (the id of a <server> from settings.xml) as an alternative to jdbcUser and jdbcPassword parameters.
This commit is contained in:
parent
a736bde0f0
commit
ef0c19c07b
@ -19,10 +19,12 @@ import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.apache.maven.artifact.manager.WagonManager;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
import org.apache.maven.wagon.authentication.AuthenticationInfo;
|
||||
|
||||
import com.mysema.codegen.model.SimpleType;
|
||||
import com.querydsl.codegen.BeanSerializer;
|
||||
@ -48,6 +50,18 @@ public class AbstractMetaDataExportMojo extends AbstractMojo {
|
||||
*/
|
||||
private MavenProject project;
|
||||
|
||||
/**
|
||||
* The Maven Wagon manager to use when obtaining server authentication details.
|
||||
* @component
|
||||
*/
|
||||
private WagonManager wagonManager;
|
||||
|
||||
/**
|
||||
* The server id in settings.xml to use as an alternative to jdbcUser and jdbcPassword
|
||||
* @parameter
|
||||
*/
|
||||
private String server;
|
||||
|
||||
/**
|
||||
* JDBC driver class name
|
||||
* @parameter required=true
|
||||
@ -475,7 +489,28 @@ public class AbstractMetaDataExportMojo extends AbstractMojo {
|
||||
exporter.setConfiguration(configuration);
|
||||
|
||||
Class.forName(jdbcDriver);
|
||||
Connection conn = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPassword);
|
||||
final String user;
|
||||
final String password;
|
||||
if (server ==null) {
|
||||
user = jdbcUser;
|
||||
password = jdbcPassword;
|
||||
} else {
|
||||
final AuthenticationInfo info = wagonManager.getAuthenticationInfo(server);
|
||||
if ( info == null ) {
|
||||
throw new MojoExecutionException("No authentication info for server " + server);
|
||||
}
|
||||
|
||||
user = info.getUserName();
|
||||
if (user == null) {
|
||||
throw new MojoExecutionException("Missing username from server " + server);
|
||||
}
|
||||
|
||||
password = info.getPassword();
|
||||
if (password == null) {
|
||||
throw new MojoExecutionException("Missing password from server " + server);
|
||||
}
|
||||
}
|
||||
final Connection conn = DriverManager.getConnection(jdbcUrl, user, password);
|
||||
try {
|
||||
exporter.export(conn.getMetaData());
|
||||
} finally {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user