Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
187 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
liquibase-maven-plugin/src/main/java/org/liquibase/maven/plugins/LiquibaseCommandMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package org.liquibase.maven.plugins; | ||
|
||
import liquibase.Scope; | ||
import liquibase.command.CommandDefinition; | ||
import liquibase.command.CommandFactory; | ||
import liquibase.command.CommandResults; | ||
import liquibase.command.CommandScope; | ||
import liquibase.integration.commandline.Main; | ||
import liquibase.util.StringUtil; | ||
import org.apache.maven.execution.MavenSession; | ||
import org.apache.maven.plugin.AbstractMojo; | ||
import org.apache.maven.plugin.MojoExecution; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.apache.maven.plugin.descriptor.Parameter; | ||
import org.apache.maven.project.MavenProject; | ||
import org.codehaus.plexus.component.MapOrientedComponent; | ||
import org.codehaus.plexus.component.configurator.ComponentConfigurationException; | ||
import org.codehaus.plexus.component.repository.ComponentRequirement; | ||
|
||
import java.io.File; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
public class LiquibaseCommandMojo extends AbstractMojo implements MapOrientedComponent { | ||
|
||
private String goal; | ||
private Map<String, Object> configuration; | ||
private ClassLoader classloader; | ||
// private List<Parameter> goalParameters; | ||
|
||
public LiquibaseCommandMojo() { | ||
} | ||
|
||
@Override | ||
public void addComponentRequirement(ComponentRequirement componentRequirement, Object o) throws ComponentConfigurationException { | ||
System.out.println("Add compp"); | ||
} | ||
|
||
@Override | ||
public void setComponentConfiguration(Map<?, ?> map) throws ComponentConfigurationException { | ||
MojoExecution mojoExecution = (MojoExecution) map.get("mojoExecution"); | ||
MavenProject project = (MavenProject) map.get("project"); | ||
|
||
this.goal = mojoExecution.getGoal(); | ||
|
||
|
||
try { | ||
List classpathElements = project.getCompileClasspathElements(); | ||
classpathElements.add(project.getBuild().getOutputDirectory()); | ||
URL urls[] = new URL[classpathElements.size()]; | ||
for (int i = 0; i < classpathElements.size(); ++i) { | ||
urls[i] = new File((String) classpathElements.get(i)).toURI().toURL(); | ||
} | ||
this.classloader = new URLClassLoader(urls, MavenUtils.getArtifactClassloader(project, | ||
true, | ||
true, | ||
getClass(), | ||
getLog(), | ||
false)); | ||
|
||
this.configuration = new HashMap<>(); | ||
for (Map.Entry entry : map.entrySet()) { | ||
Object value = entry.getValue(); | ||
if (value == null) { | ||
continue; | ||
} | ||
if (value.getClass().getName().startsWith("org.apache")) { | ||
continue; | ||
} | ||
this.configuration.put(String.valueOf(entry.getKey()), entry.getValue()); | ||
} | ||
|
||
Properties userProperties = ((MavenSession) map.get("session")).getUserProperties(); | ||
for (Map.Entry<Object, Object> entry : userProperties.entrySet()) { | ||
this.configuration.put(String.valueOf(entry.getKey()), entry.getValue()); | ||
} | ||
} catch (Exception e) { | ||
throw new ComponentConfigurationException(e.getMessage(), e); | ||
} | ||
} | ||
|
||
@Override | ||
public void execute() throws MojoExecutionException, MojoFailureException { | ||
// System.out.println("EXECUTE COMMAND MOJO!!!"+goal); | ||
// System.out.println(StringUtil.join(configuration, ",")); | ||
Main.runningFromNewCli = true; | ||
|
||
try { | ||
CommandScope commandScope = new CommandScope(goal); | ||
|
||
CommandFactory commandFactory = Scope.getCurrentScope().getSingleton(CommandFactory.class); | ||
CommandDefinition commandDef = commandFactory.getCommandDefinition(goal); | ||
for (String argName : commandDef.getArguments().keySet()) { | ||
Object value = configuration.get(argName); | ||
if (value != null) { | ||
commandScope.addArgumentValue(argName, value); | ||
} | ||
} | ||
|
||
Map<String, Object> scopeValues = new HashMap<>(); | ||
scopeValues.put(Scope.Attr.resourceAccessor.name(), new MavenResourceAccessor(classloader)); | ||
Scope.child(scopeValues, () -> { | ||
commandScope.execute(); | ||
}); | ||
} catch (Exception e) { | ||
throw new MojoExecutionException(e.getMessage(), e); | ||
} | ||
} | ||
|
||
|
||
// public static void setField(Object field) { | ||
// System.out.println("setting"); | ||
// } | ||
} |
26 changes: 26 additions & 0 deletions
26
...aven-plugin/src/main/java/org/liquibase/maven/plugins/LiquibaseComponentConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.liquibase.maven.plugins; | ||
|
||
import org.codehaus.plexus.classworlds.realm.ClassRealm; | ||
import org.codehaus.plexus.component.configurator.ComponentConfigurationException; | ||
import org.codehaus.plexus.component.configurator.ComponentConfigurator; | ||
import org.codehaus.plexus.component.configurator.ConfigurationListener; | ||
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; | ||
import org.codehaus.plexus.configuration.PlexusConfiguration; | ||
|
||
public class LiquibaseComponentConfigurator implements ComponentConfigurator { | ||
|
||
@Override | ||
public void configureComponent(Object o, PlexusConfiguration plexusConfiguration, ClassRealm classRealm) throws ComponentConfigurationException { | ||
|
||
} | ||
|
||
@Override | ||
public void configureComponent(Object o, PlexusConfiguration plexusConfiguration, ExpressionEvaluator expressionEvaluator, ClassRealm classRealm) throws ComponentConfigurationException { | ||
|
||
} | ||
|
||
@Override | ||
public void configureComponent(Object o, PlexusConfiguration plexusConfiguration, ExpressionEvaluator expressionEvaluator, ClassRealm classRealm, ConfigurationListener configurationListener) throws ComponentConfigurationException { | ||
|
||
} | ||
} |