Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add static method to use Liquify as library #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ version '1.0'

apply plugin: 'java'

sourceCompatibility = 1.6
sourceCompatibility = 1.7

repositories {
mavenLocal()
Expand Down
30 changes: 19 additions & 11 deletions src/main/java/com/refactify/Liquify.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,26 @@ public class Liquify {

public static void main(final String[] args) {
ConversionArguments conversionArguments = parser.parseArguments(args);
if(conversionArguments.areValid()) {
if (conversionArguments.areValid()) {
convertDatabaseChangeLog(conversionArguments);
}
else {
} else {
usagePrinter.printUsage();
}
}

public static void convertDatabaseChangeLog(String source, String type, String database) {
ConversionArguments conversionArguments = new ConversionArguments(
source,
ConversionArguments.ConversionType.fromString(type),
database
);
if (conversionArguments.areValid()) {
convertDatabaseChangeLog(conversionArguments);
} else {
throw new Error("Invalid conversion arguments");
}
}

private static void convertDatabaseChangeLog(final ConversionArguments conversionArguments) {
String targetFileName = targetFileNameBuilder.buildFilename(conversionArguments);
try {
Expand All @@ -46,16 +58,13 @@ private static void convertDatabaseChangeLog(final ConversionArguments conversio
set.setFilePath(targetFileName);
}
serializer.write(changeLog.getChangeSets(), new FileOutputStream(targetFileName));
}
catch (LiquibaseException e) {
} catch (LiquibaseException e) {
System.out.println("There was a problem parsing the source file.");
deleteTargetFile(targetFileName);
}
catch (IOException e) {
} catch (IOException e) {
System.out.println("There was a problem serializing the source file.");
deleteTargetFile(targetFileName);
}
catch(IllegalStateException e) {
} catch (IllegalStateException e) {
System.out.println(String.format("Database generator for type '%s' was not found.",
conversionArguments.getDatabase()));
deleteTargetFile(targetFileName);
Expand All @@ -65,8 +74,7 @@ private static void convertDatabaseChangeLog(final ConversionArguments conversio
private static void deleteTargetFile(final String targetFileName) {
try {
Files.deleteIfExists(Paths.get(targetFileName));
}
catch (IOException ioe) {
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ public class ConversionArguments {
new String[] {"db2", "derby", "firebird", "h2", "hsql", "informix", "mssql", "mariadb", "mysql", "oracle",
"postgresql", "sqlite", "asany", "sybase"};

public ConversionArguments() {
}

public ConversionArguments(String source, ConversionType type, String database) {
this.source = source;
this.type = type;
this.database = database;
}

public String getSource() {
return source;
}
Expand Down