forked from prospero238/liquibase-runner
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Db doc generation documentation regarding documenttion generation
- Loading branch information
1 parent
693a367
commit c1aae6e
Showing
17 changed files
with
380 additions
and
56 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
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
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
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
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
118 changes: 118 additions & 0 deletions
118
src/main/java/org/jenkinsci/plugins/liquibase/evaluator/DatabaseDocBuilder.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,118 @@ | ||
package org.jenkinsci.plugins.liquibase.evaluator; | ||
|
||
import hudson.Extension; | ||
import hudson.FilePath; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.Descriptor; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import hudson.remoting.VirtualChannel; | ||
import hudson.tasks.Builder; | ||
import liquibase.Contexts; | ||
import liquibase.LabelExpression; | ||
import liquibase.Liquibase; | ||
import liquibase.exception.LiquibaseException; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import org.jenkinsci.remoting.RoleChecker; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
|
||
public class DatabaseDocBuilder extends AbstractLiquibaseBuilder { | ||
|
||
private String outputDirectory; | ||
|
||
@Extension | ||
public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl(); | ||
|
||
@DataBoundConstructor | ||
public DatabaseDocBuilder(String outputDirectory) { | ||
this.outputDirectory = outputDirectory; | ||
} | ||
|
||
@Override | ||
public void runPerform(Run<?, ?> build, | ||
TaskListener listener, | ||
Liquibase liquibase, | ||
Contexts contexts, | ||
LabelExpression labelExpression, | ||
ExecutedChangesetAction executedChangesetAction, FilePath workspace) | ||
throws InterruptedException, IOException, LiquibaseException { | ||
|
||
|
||
executedChangesetAction.setNoExecutionsExpected(true); | ||
FilePath filePath = workspace.child(outputDirectory); | ||
|
||
listener.getLogger().println("Generating Liquibase dbDoc in directory '" + outputDirectory + "'"); | ||
|
||
FilePath.FileCallable callable = new DatabaseDocGenerationCallback(liquibase, contexts, labelExpression); | ||
|
||
filePath.act(callable); | ||
|
||
} | ||
private static class DatabaseDocGenerationCallback implements FilePath.FileCallable<Void> { | ||
|
||
Liquibase liquibase; | ||
Contexts contexts; | ||
LabelExpression labelExpression; | ||
|
||
public DatabaseDocGenerationCallback(Liquibase liquibase, Contexts contexts, LabelExpression labelExpression) { | ||
this.liquibase = liquibase; | ||
this.contexts = contexts; | ||
this.labelExpression = labelExpression; | ||
} | ||
|
||
@Override | ||
public Void invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { | ||
f.mkdirs(); | ||
try { | ||
liquibase.generateDocumentation(f.getAbsolutePath(), contexts, labelExpression); | ||
} catch (LiquibaseException e) { | ||
throw new IOException("Error generating documentation", e); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public void checkRoles(RoleChecker roleChecker) throws SecurityException { | ||
|
||
} | ||
} | ||
|
||
@DataBoundSetter | ||
public void setOutputDirectory(String outputDirectory) { | ||
this.outputDirectory = outputDirectory; | ||
} | ||
|
||
public String getOutputDirectory() { | ||
return outputDirectory; | ||
} | ||
|
||
@Override | ||
public Descriptor<Builder> getDescriptor() { | ||
return DESCRIPTOR; | ||
} | ||
|
||
public static class DescriptorImpl extends AbstractLiquibaseDescriptor { | ||
|
||
public DescriptorImpl() { | ||
load(); | ||
} | ||
|
||
public DescriptorImpl(Class<? extends DatabaseDocBuilder> clazz) { | ||
super(clazz); | ||
} | ||
|
||
@Override | ||
public boolean isApplicable(Class<? extends AbstractProject> jobType) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Generate Liquibase dbDoc"; | ||
} | ||
} | ||
} |
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
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
67 changes: 67 additions & 0 deletions
67
src/main/java/org/jenkinsci/plugins/liquibase/workflow/DbDocBuildStep.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,67 @@ | ||
package org.jenkinsci.plugins.liquibase.workflow; | ||
|
||
import hudson.Extension; | ||
import hudson.model.Project; | ||
import hudson.util.ListBoxModel; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import org.jenkinsci.plugins.workflow.steps.AbstractStepDescriptorImpl; | ||
import org.kohsuke.stapler.AncestorInPath; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
|
||
import com.cloudbees.plugins.credentials.CredentialsProvider; | ||
import com.cloudbees.plugins.credentials.common.StandardListBoxModel; | ||
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials; | ||
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; | ||
|
||
import static com.cloudbees.plugins.credentials.CredentialsMatchers.anyOf; | ||
import static com.cloudbees.plugins.credentials.CredentialsMatchers.instanceOf; | ||
|
||
public class DbDocBuildStep extends AbstractLiquibaseStep { | ||
private String outputDirectory = ""; | ||
|
||
|
||
@DataBoundConstructor | ||
public DbDocBuildStep(String changeLogFile) { | ||
super(changeLogFile); | ||
} | ||
|
||
@DataBoundSetter | ||
public void setOutputDirectory(String outputDirectory) { | ||
this.outputDirectory = outputDirectory; | ||
} | ||
|
||
public String getOutputDirectory() { | ||
return outputDirectory; | ||
} | ||
|
||
|
||
@Extension | ||
public static final class DescriptorImpl extends AbstractStepDescriptorImpl { | ||
|
||
public DescriptorImpl() { | ||
super(DbDocExecution.class); | ||
} | ||
|
||
@Override | ||
public String getFunctionName() { | ||
return "liquibaseDbDoc"; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getDisplayName() { | ||
return "Generate Liquibase DbDoc"; | ||
} | ||
|
||
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Project project) { | ||
return new StandardListBoxModel() | ||
.withEmptySelection() | ||
.withMatching(anyOf( | ||
instanceOf(UsernamePasswordCredentials.class)), | ||
CredentialsProvider.lookupCredentials(StandardUsernameCredentials.class, project)); | ||
} | ||
} | ||
} |
Oops, something went wrong.