Skip to content

Commit 4109ec4

Browse files
committed
Merge branch 'version-11' into 'master'
version 11 See merge request codekeeper/pgcodekeeper-cli!6
2 parents dc94981 + bd21a58 commit 4109ec4

File tree

5 files changed

+35
-83
lines changed

5 files changed

+35
-83
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: 17 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,22 @@
1919
import org.pgcodekeeper.cli.localizations.Messages;
2020
import org.pgcodekeeper.core.PgCodekeeperException;
2121
import org.pgcodekeeper.core.PgDiff;
22-
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;
26-
import org.pgcodekeeper.core.model.difftree.IgnoreSchemaList;
27-
import org.pgcodekeeper.core.model.difftree.TreeElement;
28-
import org.pgcodekeeper.core.model.exporter.ModelExporter;
22+
import org.pgcodekeeper.core.api.DatabaseFactory;
23+
import org.pgcodekeeper.core.api.PgCodeKeeperApi;
24+
import org.pgcodekeeper.core.loader.FullAnalyze;
25+
import org.pgcodekeeper.core.loader.LibraryLoader;
26+
import org.pgcodekeeper.core.loader.ProjectLoader;
2927
import org.pgcodekeeper.core.schema.AbstractDatabase;
3028
import org.pgcodekeeper.core.schema.PgOverride;
31-
import org.pgcodekeeper.core.utils.ProjectUpdater;
3229
import org.pgcodekeeper.core.xmlstore.DependenciesXmlStore;
3330

3431
import java.io.IOException;
3532
import java.nio.file.Paths;
3633
import java.util.Collection;
3734
import java.util.List;
3835

39-
4036
public final class PgDiffCli extends PgDiff {
4137

42-
4338
private final CliArgs arguments;
4439

4540
public PgDiffCli(CliArgs arguments) {
@@ -49,51 +44,22 @@ public PgDiffCli(CliArgs arguments) {
4944

5045
public void updateProject()
5146
throws IOException, InterruptedException, PgCodekeeperException {
52-
5347
AbstractDatabase oldDatabase = loadOldDatabaseWithLibraries();
5448
AbstractDatabase newDatabase = loadNewDatabaseWithLibraries();
55-
IgnoreList ignoreList = getIgnoreList();
56-
TreeElement root = DiffTree.create(oldDatabase, newDatabase, null);
57-
root.setAllChecked();
5849

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();
50+
PgCodeKeeperApi.update(settings, oldDatabase, newDatabase,
51+
arguments.getOutputTarget(), arguments.getIgnoreLists(), null);
6452
}
6553

6654
public void exportProject() throws IOException, InterruptedException, PgCodekeeperException {
6755
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;
56+
PgCodeKeeperApi.export(settings, newDb, arguments.getOutputTarget(), arguments.getIgnoreLists(), null);
8457
}
8558

8659
public String createDiff() throws InterruptedException, IOException, PgCodekeeperException {
8760
AbstractDatabase oldDatabase = loadOldDatabaseWithLibraries();
8861
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);
62+
return PgCodeKeeperApi.diff(settings, oldDatabase, newDatabase, arguments.getIgnoreLists());
9763
}
9864

9965
public AbstractDatabase loadNewDatabaseWithLibraries()
@@ -176,16 +142,12 @@ private void loadLibraries(AbstractDatabase db, Collection<String> libXmls, Coll
176142

177143
private AbstractDatabase loadNewDatabase()
178144
throws IOException, InterruptedException, PgCodekeeperException {
179-
AbstractDatabase db = loadDatabaseSchema(arguments.getNewSrcFormat(), arguments.getNewSrc());
180-
assertErrors();
181-
return db;
145+
return loadDatabaseSchema(arguments.getNewSrcFormat(), arguments.getNewSrc());
182146
}
183147

184148
private AbstractDatabase loadOldDatabase()
185149
throws IOException, InterruptedException, PgCodekeeperException {
186-
AbstractDatabase db = loadDatabaseSchema(arguments.getOldSrcFormat(), arguments.getOldSrc());
187-
assertErrors();
188-
return db;
150+
return loadDatabaseSchema(arguments.getOldSrcFormat(), arguments.getOldSrc());
189151
}
190152

191153
/**
@@ -198,24 +160,13 @@ private AbstractDatabase loadOldDatabase()
198160
* @return the loaded database
199161
*/
200162
private AbstractDatabase loadDatabaseSchema(SourceFormat format, String srcPath)
201-
throws InterruptedException, IOException {
202-
LOG.info(Messages.PgDiffCli_log_load_ignored_schemas);
203-
IgnoreSchemaList ignoreSchemaList = new IgnoreSchemaList();
204-
IgnoreParser ignoreParser = new IgnoreParser(ignoreSchemaList);
205-
if (arguments.getIgnoreSchemaList() != null) {
206-
ignoreParser.parse(Paths.get(arguments.getIgnoreSchemaList()));
207-
}
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);
163+
throws InterruptedException, IOException, PgCodekeeperException {
164+
var factory = new DatabaseFactory(settings, arguments.isIgnoreErrors(), false);
165+
return switch (format) {
166+
case DB -> factory.loadFromJdbc(srcPath, arguments.getIgnoreSchemaList());
167+
case DUMP -> factory.loadFromDump(srcPath);
168+
case PARSED -> factory.loadFromProject(srcPath, arguments.getIgnoreSchemaList());
212169
};
213-
214-
try {
215-
return loader.load();
216-
} finally {
217-
errors.addAll(loader.getErrors());
218-
}
219170
}
220171

221172
private void assertErrors() throws PgCodekeeperException {

0 commit comments

Comments
 (0)