Skip to content

Commit fceb555

Browse files
committed
version 11
1 parent dc94981 commit fceb555

File tree

5 files changed

+36
-75
lines changed

5 files changed

+36
-75
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/test/resources/** linguist-vendored

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<modelVersion>4.0.0</modelVersion>
88
<groupId>org.pgcodekeeper</groupId>
99
<artifactId>pgcodekeeper-cli</artifactId>
10-
<version>11.0.0-rc.1</version>
10+
<version>11.0.0</version>
1111
<packaging>jar</packaging>
1212

1313
<name>pgcodekeeper-cli</name>
@@ -47,7 +47,7 @@
4747
<dependency>
4848
<groupId>org.pgcodekeeper</groupId>
4949
<artifactId>pgcodekeeper-core</artifactId>
50-
<version>11.0.0-rc.1</version>
50+
<version>11.0.0</version>
5151
</dependency>
5252
<dependency>
5353
<groupId>ch.qos.logback</groupId>

src/main/java/org/pgcodekeeper/cli/Application.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,33 @@
1919
*******************************************************************************/
2020
package org.pgcodekeeper.cli;
2121

22-
import java.io.FileNotFoundException;
23-
import java.io.IOException;
24-
import java.io.PrintWriter;
25-
import java.io.UnsupportedEncodingException;
26-
import java.nio.file.Path;
27-
import java.nio.file.Paths;
28-
import java.sql.SQLException;
29-
import java.text.MessageFormat;
30-
import java.util.List;
31-
import java.util.stream.Collectors;
32-
3322
import org.kohsuke.args4j.CmdLineException;
3423
import org.pgcodekeeper.cli.localizations.Messages;
24+
import org.pgcodekeeper.core.DangerStatement;
3525
import org.pgcodekeeper.core.PgCodekeeperException;
36-
import org.pgcodekeeper.core.UnixPrintWriter;
3726
import org.pgcodekeeper.core.loader.JdbcRunner;
3827
import org.pgcodekeeper.core.loader.TokenLoader;
3928
import org.pgcodekeeper.core.loader.UrlJdbcConnector;
4029
import org.pgcodekeeper.core.model.graph.DepcyFinder;
4130
import org.pgcodekeeper.core.model.graph.InsertWriter;
42-
import org.pgcodekeeper.core.parsers.antlr.ScriptParser;
31+
import org.pgcodekeeper.core.parsers.antlr.base.ScriptParser;
4332
import org.pgcodekeeper.core.schema.AbstractDatabase;
4433
import org.pgcodekeeper.core.utils.FileUtils;
45-
import org.pgcodekeeper.core.DangerStatement;
34+
import org.pgcodekeeper.core.utils.UnixPrintWriter;
4635
import org.slf4j.Logger;
4736
import org.slf4j.LoggerFactory;
4837

38+
import java.io.FileNotFoundException;
39+
import java.io.IOException;
40+
import java.io.PrintWriter;
41+
import java.io.UnsupportedEncodingException;
42+
import java.nio.file.Path;
43+
import java.nio.file.Paths;
44+
import java.sql.SQLException;
45+
import java.text.MessageFormat;
46+
import java.util.List;
47+
import java.util.stream.Collectors;
48+
4949
/**
5050
* Compares two PostgreSQL dumps and outputs information about differences in
5151
* the database schemas.

src/main/java/org/pgcodekeeper/cli/CliArgs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ public boolean isIgnoreColumnOrder() {
413413
}
414414

415415
@Override
416-
public boolean isConstraintNotValid() {
416+
public boolean isGenerateConstraintNotValid() {
417417
return generateConstraintNotValid;
418418
}
419419

src/main/java/org/pgcodekeeper/cli/PgDiffCli.java

Lines changed: 18 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,24 @@
1919
import org.pgcodekeeper.cli.localizations.Messages;
2020
import org.pgcodekeeper.core.PgCodekeeperException;
2121
import org.pgcodekeeper.core.PgDiff;
22+
import org.pgcodekeeper.core.api.DatabaseFactory;
23+
import org.pgcodekeeper.core.api.PgCodeKeeperApi;
2224
import org.pgcodekeeper.core.ignoreparser.IgnoreParser;
23-
import org.pgcodekeeper.core.loader.*;
24-
import org.pgcodekeeper.core.model.difftree.DiffTree;
25-
import org.pgcodekeeper.core.model.difftree.IgnoreList;
25+
import org.pgcodekeeper.core.loader.FullAnalyze;
26+
import org.pgcodekeeper.core.loader.LibraryLoader;
27+
import org.pgcodekeeper.core.loader.ProjectLoader;
2628
import org.pgcodekeeper.core.model.difftree.IgnoreSchemaList;
27-
import org.pgcodekeeper.core.model.difftree.TreeElement;
28-
import org.pgcodekeeper.core.model.exporter.ModelExporter;
2929
import org.pgcodekeeper.core.schema.AbstractDatabase;
3030
import org.pgcodekeeper.core.schema.PgOverride;
31-
import org.pgcodekeeper.core.utils.ProjectUpdater;
3231
import org.pgcodekeeper.core.xmlstore.DependenciesXmlStore;
3332

3433
import java.io.IOException;
3534
import java.nio.file.Paths;
3635
import java.util.Collection;
3736
import java.util.List;
3837

39-
4038
public final class PgDiffCli extends PgDiff {
4139

42-
4340
private final CliArgs arguments;
4441

4542
public PgDiffCli(CliArgs arguments) {
@@ -49,51 +46,22 @@ public PgDiffCli(CliArgs arguments) {
4946

5047
public void updateProject()
5148
throws IOException, InterruptedException, PgCodekeeperException {
52-
5349
AbstractDatabase oldDatabase = loadOldDatabaseWithLibraries();
5450
AbstractDatabase newDatabase = loadNewDatabaseWithLibraries();
55-
IgnoreList ignoreList = getIgnoreList();
56-
TreeElement root = DiffTree.create(oldDatabase, newDatabase, null);
57-
root.setAllChecked();
5851

59-
List<TreeElement> selected = getSelectedElements(root, ignoreList);
60-
61-
new ProjectUpdater(newDatabase, oldDatabase, selected, arguments.getDbType(),
62-
arguments.getOutCharsetName(), Paths.get(arguments.getOutputTarget()),
63-
false, settings).updatePartial();
52+
PgCodeKeeperApi.update(settings, oldDatabase, newDatabase,
53+
arguments.getOutputTarget(), arguments.getIgnoreLists(), null);
6454
}
6555

6656
public void exportProject() throws IOException, InterruptedException, PgCodekeeperException {
6757
AbstractDatabase newDb = loadNewDatabase();
68-
TreeElement root = DiffTree.create(newDb, null, null);
69-
root.setAllChecked();
70-
71-
IgnoreList ignoreList = getIgnoreList();
72-
List<TreeElement> selected = getSelectedElements(root, ignoreList);
73-
new ModelExporter(Paths.get(arguments.getOutputTarget()), newDb, null,
74-
arguments.getDbType(), selected, arguments.getOutCharsetName(), settings).exportProject();
75-
}
76-
77-
private IgnoreList getIgnoreList() throws IOException {
78-
IgnoreList ignoreList = new IgnoreList();
79-
IgnoreParser ignoreParser = new IgnoreParser(ignoreList);
80-
for (String listFilename : arguments.getIgnoreLists()) {
81-
ignoreParser.parse(Paths.get(listFilename));
82-
}
83-
return ignoreList;
58+
PgCodeKeeperApi.export(settings, newDb, arguments.getOutputTarget(), arguments.getIgnoreLists(), null);
8459
}
8560

8661
public String createDiff() throws InterruptedException, IOException, PgCodekeeperException {
8762
AbstractDatabase oldDatabase = loadOldDatabaseWithLibraries();
8863
AbstractDatabase newDatabase = loadNewDatabaseWithLibraries();
89-
IgnoreList ignoreList = new IgnoreList();
90-
IgnoreParser ignoreParser = new IgnoreParser(ignoreList);
91-
92-
for (String listFilename : arguments.getIgnoreLists()) {
93-
ignoreParser.parse(Paths.get(listFilename));
94-
}
95-
96-
return diff(oldDatabase, newDatabase, ignoreList);
64+
return PgCodeKeeperApi.diff(settings, oldDatabase, newDatabase, arguments.getIgnoreLists());
9765
}
9866

9967
public AbstractDatabase loadNewDatabaseWithLibraries()
@@ -176,16 +144,12 @@ private void loadLibraries(AbstractDatabase db, Collection<String> libXmls, Coll
176144

177145
private AbstractDatabase loadNewDatabase()
178146
throws IOException, InterruptedException, PgCodekeeperException {
179-
AbstractDatabase db = loadDatabaseSchema(arguments.getNewSrcFormat(), arguments.getNewSrc());
180-
assertErrors();
181-
return db;
147+
return loadDatabaseSchema(arguments.getNewSrcFormat(), arguments.getNewSrc());
182148
}
183149

184150
private AbstractDatabase loadOldDatabase()
185151
throws IOException, InterruptedException, PgCodekeeperException {
186-
AbstractDatabase db = loadDatabaseSchema(arguments.getOldSrcFormat(), arguments.getOldSrc());
187-
assertErrors();
188-
return db;
152+
return loadDatabaseSchema(arguments.getOldSrcFormat(), arguments.getOldSrc());
189153
}
190154

191155
/**
@@ -198,24 +162,20 @@ private AbstractDatabase loadOldDatabase()
198162
* @return the loaded database
199163
*/
200164
private AbstractDatabase loadDatabaseSchema(SourceFormat format, String srcPath)
201-
throws InterruptedException, IOException {
165+
throws InterruptedException, IOException, PgCodekeeperException {
202166
LOG.info(Messages.PgDiffCli_log_load_ignored_schemas);
203167
IgnoreSchemaList ignoreSchemaList = new IgnoreSchemaList();
204168
IgnoreParser ignoreParser = new IgnoreParser(ignoreSchemaList);
205169
if (arguments.getIgnoreSchemaList() != null) {
206170
ignoreParser.parse(Paths.get(arguments.getIgnoreSchemaList()));
207171
}
208-
DatabaseLoader loader = switch (format) {
209-
case DB -> LoaderFactory.createJdbcLoader(settings, srcPath, ignoreSchemaList);
210-
case DUMP -> new PgDumpLoader(Paths.get(srcPath), settings);
211-
case PARSED -> new ProjectLoader(srcPath, settings, null, errors, ignoreSchemaList);
212-
};
172+
var factory = new DatabaseFactory(settings, arguments.isIgnoreErrors(), false);
213173

214-
try {
215-
return loader.load();
216-
} finally {
217-
errors.addAll(loader.getErrors());
218-
}
174+
return switch (format) {
175+
case DB -> factory.loadFromJdbc(srcPath, arguments.getIgnoreSchemaList());
176+
case DUMP -> factory.loadFromDump(srcPath);
177+
case PARSED -> factory.loadFromProject(srcPath, arguments.getIgnoreSchemaList());
178+
};
219179
}
220180

221181
private void assertErrors() throws PgCodekeeperException {

0 commit comments

Comments
 (0)