This is an automated email from the ASF dual-hosted git repository. ntimofeev pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cayenne.git
The following commit(s) were added to refs/heads/master by this push: new 2be41da52 CAY-2785 Modeler: improve folder selection for cgen - refactor output-dir related methods in cgen 2be41da52 is described below commit 2be41da52d17993550fe126a1bb0571dd45fbc59 Author: Nikita Timofeev <stari...@gmail.com> AuthorDate: Tue Dec 6 18:52:12 2022 +0300 CAY-2785 Modeler: improve folder selection for cgen - refactor output-dir related methods in cgen --- .../apache/cayenne/tools/CayenneGeneratorTask.java | 4 +- .../org/apache/cayenne/gen/CgenConfiguration.java | 78 +++++++++++++--------- .../apache/cayenne/gen/ClassGenerationAction.java | 6 +- .../apache/cayenne/gen/xml/CgenConfigHandler.java | 2 +- .../apache/cayenne/gen/xml/CgenSaverDelegate.java | 4 +- .../cayenne/gen/BaseTemplatesGenerationTest.java | 2 +- .../apache/cayenne/gen/CgenConfigurationTest.java | 72 ++++++++++---------- .../cayenne/gen/ClassGenerationActionTest.java | 4 +- .../cayenne/gen/xml/CgenSaverDelegateTest.java | 16 +++-- .../org/apache/cayenne/crypto/db/auto/_Table1.java | 2 + .../org/apache/cayenne/crypto/db/auto/_Table2.java | 2 + .../org/apache/cayenne/crypto/db/auto/_Table3.java | 2 + .../org/apache/cayenne/crypto/db/auto/_Table4.java | 2 + .../org/apache/cayenne/crypto/db/auto/_Table5.java | 2 + .../org/apache/cayenne/crypto/db/auto/_Table6.java | 2 + .../org/apache/cayenne/crypto/db/auto/_Table7.java | 2 + .../org/apache/cayenne/crypto/db/auto/_Table8.java | 2 + .../java/org/apache/cayenne/tools/CgenTask.java | 6 +- .../apache/cayenne/tools/CayenneGeneratorMojo.java | 5 +- .../editor/cgen/CodeGeneratorController.java | 6 +- .../modeler/editor/cgen/GeneratorController.java | 2 +- .../editor/cgen/GeneratorControllerPanel.java | 3 +- 22 files changed, 137 insertions(+), 89 deletions(-) diff --git a/cayenne-ant/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java b/cayenne-ant/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java index aca2070a4..fda3473f2 100644 --- a/cayenne-ant/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java +++ b/cayenne-ant/src/main/java/org/apache/cayenne/tools/CayenneGeneratorTask.java @@ -184,7 +184,9 @@ public class CayenneGeneratorTask extends CayenneTask { private CgenConfiguration cgenConfigFromPom(DataMap dataMap){ CgenConfiguration cgenConfiguration = new CgenConfiguration(); cgenConfiguration.setDataMap(dataMap); - cgenConfiguration.setRelPath(destDir != null ? destDir.toPath() : cgenConfiguration.getRelPath()); + if(destDir != null) { + cgenConfiguration.setRelativePath(destDir.toPath()); + } cgenConfiguration.setEncoding(encoding != null ? encoding : cgenConfiguration.getEncoding()); cgenConfiguration.setMakePairs(makepairs != null ? makepairs : cgenConfiguration.isMakePairs()); if(mode != null && mode.equals("datamap")) { diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenConfiguration.java b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenConfiguration.java index 92a827735..8bdaeb67f 100644 --- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenConfiguration.java +++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/CgenConfiguration.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; +import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; @@ -173,23 +174,36 @@ public class CgenConfiguration implements Serializable, XMLSerializable { return rootPath; } + /** + * @param rootPath absolute target path for the cgen generation + */ public void setRootPath(Path rootPath) { + if (!Objects.requireNonNull(rootPath).isAbsolute()) { + throw new ValidationException("Root path : " + '"' + rootPath + '"' + "should be absolute"); + } this.rootPath = rootPath; } - public void setRelPath(Path relPath) { + /** + * Directly set relative (to {@code rootPath}) output directory + * @param relPath to set + * @since 5.0 renamed from {@code setRelPath()} + */ + public void setRelativePath(Path relPath) { this.relPath = relPath; } - public void setRelPath(String pathStr) { - Path path = Paths.get(pathStr); + public Path getRelPath() { + return relPath; + } + /** + * @param pathStr to update relative path with + * @since 5.0 renamed from {@code setRelPath()} + */ + public void updateRelativeOutputPath(String pathStr) { + Path path = Paths.get(pathStr); if (rootPath != null) { - - if (!rootPath.isAbsolute()) { - throw new ValidationException("Root path : " + '"' + rootPath + '"' + "should be absolute"); - } - if (path.isAbsolute() && rootPath.getRoot().equals(path.getRoot())) { this.relPath = rootPath.relativize(path); return; @@ -198,6 +212,31 @@ public class CgenConfiguration implements Serializable, XMLSerializable { this.relPath = path; } + /** + * @return normalized relative path + * @since 5.0 renamed from {@code buildRelPath()} and made package private + */ + String getNormalizedRelativePath() { + if (relPath == null || relPath.toString().isEmpty()) { + return "."; + } + return relPath.toString(); + } + + /** + * @return calculated output directory + * @since 5.0 renamed from {@code buildPath()} + */ + public Path buildOutputPath() { + if (rootPath == null) { + return relPath; + } + if (relPath == null) { + return rootPath; + } + return rootPath.resolve(relPath).toAbsolutePath().normalize(); + } + public boolean isOverwrite() { return overwrite; } @@ -310,17 +349,6 @@ public class CgenConfiguration implements Serializable, XMLSerializable { this.createPKProperties = createPKProperties; } - public Path getRelPath() { - return relPath; - } - - public String buildRelPath() { - if (relPath == null || relPath.toString().isEmpty()) { - return "."; - } - return relPath.toString(); - } - Collection<Artifact> getArtifacts() { return artifacts; } @@ -345,16 +373,6 @@ public class CgenConfiguration implements Serializable, XMLSerializable { artifacts.add(artifact); } - public Path buildPath() { - if (rootPath == null) { - return relPath; - } - if (relPath == null) { - return rootPath; - } - return rootPath.resolve(relPath).toAbsolutePath().normalize(); - } - public void loadEntity(ObjEntity entity) { if (!entity.isGeneric()) { entityArtifacts.add(entity.getName()); @@ -422,7 +440,7 @@ public class CgenConfiguration implements Serializable, XMLSerializable { .simpleTag("name", this.name) .simpleTag("excludeEntities", getExcludeEntites()) .simpleTag("excludeEmbeddables", getExcludeEmbeddables()) - .simpleTag("destDir", separatorsToUnix(buildRelPath())) + .simpleTag("destDir", separatorsToUnix(getNormalizedRelativePath())) .simpleTag("mode", this.artifactsGenerationMode.getLabel()) .start("template").cdata(this.template.getData(), !this.template.isFile()).end() .start("superTemplate").cdata(this.superTemplate.getData(), !this.superTemplate.isFile()).end() diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java index 0f828f5f6..1d7c5c8ae 100644 --- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java +++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java @@ -274,7 +274,7 @@ public class ClassGenerationAction { * Called internally from "execute". */ protected void validateAttributes() { - Path dir = cgenConfiguration.buildPath(); + Path dir = cgenConfiguration.buildOutputPath(); if (dir == null) { throw new CayenneRuntimeException("Output directory is not set."); } @@ -330,7 +330,7 @@ public class ClassGenerationAction { String className = (String) context.get(Artifact.SUPER_CLASS_KEY); String filename = StringUtils.getInstance().replaceWildcardInStringWithString(WILDCARD, cgenConfiguration.getOutputPattern(), className); - File dest = new File(mkpath(new File(cgenConfiguration.buildPath().toString()), packageName), filename); + File dest = new File(mkpath(new File(cgenConfiguration.buildOutputPath().toString()), packageName), filename); if (dest.exists() && !fileNeedUpdate(dest, cgenConfiguration.getSuperTemplate().getData())) { return null; @@ -349,7 +349,7 @@ public class ClassGenerationAction { String className = (String) context.get(Artifact.SUB_CLASS_KEY); String filename = StringUtils.getInstance().replaceWildcardInStringWithString(WILDCARD, cgenConfiguration.getOutputPattern(), className); - File dest = new File(mkpath(new File(Objects.requireNonNull(cgenConfiguration.buildPath()).toString()), packageName), filename); + File dest = new File(mkpath(new File(Objects.requireNonNull(cgenConfiguration.buildOutputPath()).toString()), packageName), filename); if (dest.exists()) { // no overwrite of subclasses diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenConfigHandler.java b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenConfigHandler.java index 77fa050cf..038bb6f4f 100644 --- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenConfigHandler.java +++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenConfigHandler.java @@ -151,7 +151,7 @@ public class CgenConfigHandler extends NamespaceAwareNestedTagHandler { if (path.trim().length() == 0) { return; } - configuration.setRelPath(Paths.get(path)); + configuration.setRelativePath(Paths.get(path)); } private void createGenerationMode(String mode) { diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenSaverDelegate.java b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenSaverDelegate.java index a5d85fd14..3f40e0658 100644 --- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenSaverDelegate.java +++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenSaverDelegate.java @@ -80,14 +80,14 @@ public class CgenSaverDelegate extends BaseSaverDelegate { cgenConfiguration.setRootPath(cgenPath); } - Path prevPath = cgenConfiguration.buildPath(); + Path prevPath = cgenConfiguration.buildOutputPath(); if(prevPath != null) { if(prevPath.isAbsolute()) { Path relPath = prevPath; if (resourcePath.getRoot().equals(prevPath.getRoot())) { relPath = resourcePath.relativize(prevPath).normalize(); } - cgenConfiguration.setRelPath(relPath); + cgenConfiguration.setRelativePath(relPath); } } cgenConfiguration.setRootPath(resourcePath); diff --git a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/BaseTemplatesGenerationTest.java b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/BaseTemplatesGenerationTest.java index 61a50253e..5911d69e8 100644 --- a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/BaseTemplatesGenerationTest.java +++ b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/BaseTemplatesGenerationTest.java @@ -145,7 +145,7 @@ public class BaseTemplatesGenerationTest { cgenConfiguration.addArtifact(artifact); cgenConfiguration.setRootPath(folder.getRoot().toPath()); - cgenConfiguration.setRelPath(Paths.get(".")); + cgenConfiguration.setRelativePath(Paths.get(".")); cgenConfiguration.loadEntity(objEntity); cgenConfiguration.setDataMap(dataMap); diff --git a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/CgenConfigurationTest.java b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/CgenConfigurationTest.java index 5d4a580ce..23f5c3397 100644 --- a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/CgenConfigurationTest.java +++ b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/CgenConfigurationTest.java @@ -54,70 +54,70 @@ public class CgenConfigurationTest { public void equalRootsEqualDirectories() { configuration.setRootPath(Paths.get("C:\\test1\\test2\\test3")); Path relPath = Paths.get("C:\\test1\\test2\\test3"); - configuration.setRelPath(relPath.toString()); + configuration.updateRelativeOutputPath(relPath.toString()); assertEquals(Paths.get(""), configuration.getRelPath()); - assertEquals(relPath, configuration.buildPath()); + assertEquals(relPath, configuration.buildOutputPath()); } @Test public void equalRootsNotEqualDirectories() { configuration.setRootPath(Paths.get("C:\\test1\\test2\\test3")); Path relPath = Paths.get("C:\\test1\\test2\\testAnother"); - configuration.setRelPath(relPath.toString()); + configuration.updateRelativeOutputPath(relPath.toString()); assertEquals(Paths.get("..\\testAnother"), configuration.getRelPath()); - assertEquals(relPath, configuration.buildPath()); + assertEquals(relPath, configuration.buildOutputPath()); } @Test public void equalRootsEmptyDirectories() { configuration.setRootPath(Paths.get("C:\\")); Path relPath = Paths.get("C:\\"); - configuration.setRelPath(relPath.toString()); + configuration.updateRelativeOutputPath(relPath.toString()); assertEquals(Paths.get(""), configuration.getRelPath()); - assertEquals(relPath, configuration.buildPath()); + assertEquals(relPath, configuration.buildOutputPath()); } @Test public void notEqualRootsEqualDirectories() { configuration.setRootPath(Paths.get("C:\\test1\\test2\\test3")); Path relPath = Paths.get("E:\\test1\\test2\\test3"); - configuration.setRelPath(relPath.toString()); + configuration.updateRelativeOutputPath(relPath.toString()); assertEquals(Paths.get("E:\\test1\\test2\\test3"), configuration.getRelPath()); - assertEquals(relPath, configuration.buildPath()); + assertEquals(relPath, configuration.buildOutputPath()); } @Test public void notEqualRootsNotEqualDirectories() { configuration.setRootPath(Paths.get("C:\\test1\\test2\\test3")); Path relPath = Paths.get("E:\\test1\\test2\\testAnother"); - configuration.setRelPath(relPath.toString()); + configuration.updateRelativeOutputPath(relPath.toString()); assertEquals(Paths.get("E:\\test1\\test2\\testAnother"), configuration.getRelPath()); - assertEquals(relPath, configuration.buildPath()); + assertEquals(relPath, configuration.buildOutputPath()); } @Test public void notEqualRootsEmptyDirectories() { configuration.setRootPath(Paths.get("C:\\")); Path relPath = Paths.get("E:\\"); - configuration.setRelPath(relPath.toString()); + configuration.updateRelativeOutputPath(relPath.toString()); assertEquals(Paths.get("E:\\"), configuration.getRelPath()); - assertEquals(relPath, configuration.buildPath()); + assertEquals(relPath, configuration.buildOutputPath()); } @Test(expected = ValidationException.class) public void emptyRootNotEmptyRelPath() { configuration.setRootPath(Paths.get("")); Path relPath = Paths.get("E:\\"); - configuration.setRelPath(relPath.toString()); + configuration.updateRelativeOutputPath(relPath.toString()); assertEquals(Paths.get("E:\\"), configuration.getRelPath()); - assertEquals(relPath, configuration.buildPath()); + assertEquals(relPath, configuration.buildOutputPath()); } @Test @@ -125,29 +125,29 @@ public class CgenConfigurationTest { configuration.setRootPath(Paths.get("E:\\")); Path relPath = Paths.get(""); - configuration.setRelPath(relPath); + configuration.setRelativePath(relPath); assertEquals(relPath, configuration.getRelPath()); - assertEquals(Paths.get("E:\\"), configuration.buildPath()); + assertEquals(Paths.get("E:\\"), configuration.buildOutputPath()); } @Test(expected = InvalidPathException.class) public void invalidRelPath() { configuration.setRootPath(Paths.get("C:\\test1\\test2\\test3")); - configuration.setRelPath("invalidRoot:\\test"); + configuration.updateRelativeOutputPath("invalidRoot:\\test"); } @Test(expected = InvalidPathException.class) public void invalidRootPath() { configuration.setRootPath(Paths.get("invalidRoot:\\test")); - configuration.setRelPath("C:\\test1\\test2\\test3"); + configuration.updateRelativeOutputPath("C:\\test1\\test2\\test3"); } @Test public void nullRootPath() { - configuration.setRelPath("C:\\test1\\test2\\test3"); + configuration.updateRelativeOutputPath("C:\\test1\\test2\\test3"); assertEquals(Paths.get("C:\\test1\\test2\\test3"), configuration.getRelPath()); - assertEquals(Paths.get("C:\\test1\\test2\\test3"), configuration.buildPath()); + assertEquals(Paths.get("C:\\test1\\test2\\test3"), configuration.buildOutputPath()); } } @@ -169,79 +169,79 @@ public class CgenConfigurationTest { public void equalRootsEqualDirectories() { configuration.setRootPath(Paths.get("/test1/test2/test3")); Path relPath = Paths.get("/test1/test2/test3"); - configuration.setRelPath(relPath.toString()); + configuration.updateRelativeOutputPath(relPath.toString()); assertEquals(Paths.get(""), configuration.getRelPath()); - assertEquals(relPath, configuration.buildPath()); + assertEquals(relPath, configuration.buildOutputPath()); } @Test public void equalRootsNotEqualDirectories() { configuration.setRootPath(Paths.get("/test1/test2/test3")); Path relPath = Paths.get("/test1/test2/testAnother"); - configuration.setRelPath(relPath.toString()); + configuration.updateRelativeOutputPath(relPath.toString()); assertEquals(Paths.get("../testAnother"), configuration.getRelPath()); - assertEquals(relPath, configuration.buildPath()); + assertEquals(relPath, configuration.buildOutputPath()); } @Test public void equalRootsEmptyDirectories() { configuration.setRootPath(Paths.get("/")); Path relPath = Paths.get("/"); - configuration.setRelPath(relPath.toString()); + configuration.updateRelativeOutputPath(relPath.toString()); assertEquals(Paths.get(""), configuration.getRelPath()); - assertEquals(relPath, configuration.buildPath()); + assertEquals(relPath, configuration.buildOutputPath()); } @Test public void concatCorrectRootPathAndRelPath() { configuration.setRootPath(Paths.get("/test1/test2/test3")); Path relPath = Paths.get("test1/test2/test3"); - configuration.setRelPath(relPath.toString()); + configuration.updateRelativeOutputPath(relPath.toString()); assertEquals(Paths.get("test1/test2/test3"), configuration.getRelPath()); - assertEquals(Paths.get("/test1/test2/test3/test1/test2/test3"), configuration.buildPath()); + assertEquals(Paths.get("/test1/test2/test3/test1/test2/test3"), configuration.buildOutputPath()); } @Test(expected = ValidationException.class) public void emptyRootNotEmptyRelPath() { configuration.setRootPath(Paths.get("")); Path relPath = Paths.get("/"); - configuration.setRelPath(relPath.toString()); + configuration.updateRelativeOutputPath(relPath.toString()); assertEquals(Paths.get("/"), configuration.getRelPath()); - assertEquals(relPath, configuration.buildPath()); + assertEquals(relPath, configuration.buildOutputPath()); } @Test public void notEmptyRootEmptyRelPath() { configuration.setRootPath(Paths.get("/")); - configuration.setRelPath(""); + configuration.updateRelativeOutputPath(""); assertEquals(Paths.get(""), configuration.getRelPath()); - assertEquals(Paths.get("/"), configuration.buildPath()); + assertEquals(Paths.get("/"), configuration.buildOutputPath()); } @Test(expected = ValidationException.class) public void invalidRootPath() { configuration.setRootPath(Paths.get("invalidRoot:/test")); - configuration.setRelPath("/test1/test2/test3"); + configuration.updateRelativeOutputPath("/test1/test2/test3"); } @Test(expected = ValidationException.class) public void concatInvalidRootPathAndRelPath() { configuration.setRootPath(Paths.get("invalidRoot:/test")); - configuration.setRelPath("test1/test2/test3"); + configuration.updateRelativeOutputPath("test1/test2/test3"); } @Test public void nullRootPath() { - configuration.setRelPath("/test1/test2/test3"); + configuration.updateRelativeOutputPath("/test1/test2/test3"); assertEquals(Paths.get("/test1/test2/test3"), configuration.getRelPath()); - assertEquals(Paths.get("/test1/test2/test3"), configuration.buildPath()); + assertEquals(Paths.get("/test1/test2/test3"), configuration.buildOutputPath()); } } diff --git a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java index 296e15295..d5c8544b0 100644 --- a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java +++ b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java @@ -268,7 +268,7 @@ public class ClassGenerationActionTest extends CgenCase { TemplateType templateType = TemplateType.DATAMAP_SUPERCLASS; cgenConfiguration.setRootPath(tempFolder.getRoot().toPath()); - cgenConfiguration.setRelPath("."); + cgenConfiguration.updateRelativeOutputPath("."); action = new ClassGenerationAction(cgenConfiguration); ObjEntity testEntity1 = new ObjEntity("TEST"); testEntity1.setClassName("TestClass1"); @@ -290,7 +290,7 @@ public class ClassGenerationActionTest extends CgenCase { TemplateType templateType = TemplateType.DATAMAP_SINGLE_CLASS; cgenConfiguration.setRootPath(tempFolder.getRoot().toPath()); - cgenConfiguration.setRelPath("."); + cgenConfiguration.updateRelativeOutputPath("."); action = new ClassGenerationAction(cgenConfiguration); ObjEntity testEntity1 = new ObjEntity("TEST"); testEntity1.setClassName("TestClass1"); diff --git a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/xml/CgenSaverDelegateTest.java b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/xml/CgenSaverDelegateTest.java index ef05d1ce3..12780ebf3 100644 --- a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/xml/CgenSaverDelegateTest.java +++ b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/xml/CgenSaverDelegateTest.java @@ -50,7 +50,7 @@ public class CgenSaverDelegateTest { CgenConfiguration config = new CgenConfiguration(); config.setRootPath(Paths.get("/tmp/src/main/java").toAbsolutePath()); - config.setRelPath(Paths.get("")); + config.setRelativePath(Paths.get("")); URL baseURL = Paths.get("/tmp/src/main/resources").toUri().toURL(); @@ -61,7 +61,7 @@ public class CgenSaverDelegateTest { } @Test - public void testEmptyRoot() throws Exception { + public void testEmptyRootInMavenTree() throws Exception { CgenConfiguration config = new CgenConfiguration(); URL baseURL = Paths.get("/tmp/src/main/resources").toUri().toURL(); @@ -69,12 +69,18 @@ public class CgenSaverDelegateTest { CgenSaverDelegate.resolveOutputDir(baseURL, config); assertEquals(Paths.get("/tmp/src/main/resources").toAbsolutePath(), config.getRootPath()); - assertEquals(Paths.get(""), config.getRelPath()); + assertEquals(Paths.get("../java"), config.getRelPath()); } + @Test + public void testEmptyRoot() throws Exception { + CgenConfiguration config = new CgenConfiguration(); + URL baseURL = Paths.get("/tmp/somefolder").toUri().toURL(); + CgenSaverDelegate.resolveOutputDir(baseURL, config); - - + assertEquals(Paths.get("/tmp/somefolder").toAbsolutePath(), config.getRootPath()); + assertEquals(Paths.get(""), config.getRelPath()); + } } \ No newline at end of file diff --git a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table1.java b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table1.java index 1c938419f..5f769c951 100644 --- a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table1.java +++ b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table1.java @@ -10,6 +10,7 @@ import org.apache.cayenne.crypto.db.Table1; import org.apache.cayenne.crypto.db.Table7; import org.apache.cayenne.exp.property.EntityProperty; import org.apache.cayenne.exp.property.ListProperty; +import org.apache.cayenne.exp.property.NumericIdProperty; import org.apache.cayenne.exp.property.NumericProperty; import org.apache.cayenne.exp.property.PropertyFactory; import org.apache.cayenne.exp.property.StringProperty; @@ -26,6 +27,7 @@ public abstract class _Table1 extends BaseDataObject { public static final EntityProperty<Table1> SELF = PropertyFactory.createSelf(Table1.class); + public static final NumericIdProperty<Integer> ID_PK_PROPERTY = PropertyFactory.createNumericId("ID", "Table1", Integer.class); public static final String ID_PK_COLUMN = "ID"; public static final NumericProperty<Integer> CRYPTO_INT = PropertyFactory.createNumeric("cryptoInt", Integer.class); diff --git a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table2.java b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table2.java index c828f07d1..7ccd3e5d9 100644 --- a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table2.java +++ b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table2.java @@ -8,6 +8,7 @@ import org.apache.cayenne.BaseDataObject; import org.apache.cayenne.crypto.db.Table2; import org.apache.cayenne.exp.property.BaseProperty; import org.apache.cayenne.exp.property.EntityProperty; +import org.apache.cayenne.exp.property.NumericIdProperty; import org.apache.cayenne.exp.property.PropertyFactory; /** @@ -22,6 +23,7 @@ public abstract class _Table2 extends BaseDataObject { public static final EntityProperty<Table2> SELF = PropertyFactory.createSelf(Table2.class); + public static final NumericIdProperty<Integer> ID_PK_PROPERTY = PropertyFactory.createNumericId("ID", "Table2", Integer.class); public static final String ID_PK_COLUMN = "ID"; public static final BaseProperty<byte[]> CRYPTO_BYTES = PropertyFactory.createBase("cryptoBytes", byte[].class); diff --git a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table3.java b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table3.java index 38859faff..bc9e6957f 100644 --- a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table3.java +++ b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table3.java @@ -7,6 +7,7 @@ import java.io.ObjectOutputStream; import org.apache.cayenne.BaseDataObject; import org.apache.cayenne.crypto.db.Table3; import org.apache.cayenne.exp.property.EntityProperty; +import org.apache.cayenne.exp.property.NumericIdProperty; import org.apache.cayenne.exp.property.PropertyFactory; import org.apache.cayenne.exp.property.StringProperty; @@ -22,6 +23,7 @@ public abstract class _Table3 extends BaseDataObject { public static final EntityProperty<Table3> SELF = PropertyFactory.createSelf(Table3.class); + public static final NumericIdProperty<Integer> ID_PK_PROPERTY = PropertyFactory.createNumericId("ID", "Table3", Integer.class); public static final String ID_PK_COLUMN = "ID"; public static final StringProperty<String> CRYPTO_STRING = PropertyFactory.createString("cryptoString", String.class); diff --git a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table4.java b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table4.java index c40e33530..862d1105f 100644 --- a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table4.java +++ b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table4.java @@ -7,6 +7,7 @@ import java.io.ObjectOutputStream; import org.apache.cayenne.BaseDataObject; import org.apache.cayenne.crypto.db.Table4; import org.apache.cayenne.exp.property.EntityProperty; +import org.apache.cayenne.exp.property.NumericIdProperty; import org.apache.cayenne.exp.property.NumericProperty; import org.apache.cayenne.exp.property.PropertyFactory; import org.apache.cayenne.exp.property.StringProperty; @@ -23,6 +24,7 @@ public abstract class _Table4 extends BaseDataObject { public static final EntityProperty<Table4> SELF = PropertyFactory.createSelf(Table4.class); + public static final NumericIdProperty<Integer> ID_PK_PROPERTY = PropertyFactory.createNumericId("ID", "Table4", Integer.class); public static final String ID_PK_COLUMN = "ID"; public static final NumericProperty<Integer> PLAIN_INT = PropertyFactory.createNumeric("plainInt", Integer.class); diff --git a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table5.java b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table5.java index a633adf79..f5cd4d8bf 100644 --- a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table5.java +++ b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table5.java @@ -7,6 +7,7 @@ import java.io.ObjectOutputStream; import org.apache.cayenne.BaseDataObject; import org.apache.cayenne.crypto.db.Table5; import org.apache.cayenne.exp.property.EntityProperty; +import org.apache.cayenne.exp.property.NumericIdProperty; import org.apache.cayenne.exp.property.NumericProperty; import org.apache.cayenne.exp.property.PropertyFactory; @@ -22,6 +23,7 @@ public abstract class _Table5 extends BaseDataObject { public static final EntityProperty<Table5> SELF = PropertyFactory.createSelf(Table5.class); + public static final NumericIdProperty<Integer> ID_PK_PROPERTY = PropertyFactory.createNumericId("ID", "Table5", Integer.class); public static final String ID_PK_COLUMN = "ID"; public static final NumericProperty<Integer> CRYPTO_INT1 = PropertyFactory.createNumeric("cryptoInt1", Integer.class); diff --git a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table6.java b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table6.java index 597deb9ee..9404fd8a5 100644 --- a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table6.java +++ b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table6.java @@ -7,6 +7,7 @@ import java.io.ObjectOutputStream; import org.apache.cayenne.BaseDataObject; import org.apache.cayenne.crypto.db.Table6; import org.apache.cayenne.exp.property.EntityProperty; +import org.apache.cayenne.exp.property.NumericIdProperty; import org.apache.cayenne.exp.property.NumericProperty; import org.apache.cayenne.exp.property.PropertyFactory; @@ -22,6 +23,7 @@ public abstract class _Table6 extends BaseDataObject { public static final EntityProperty<Table6> SELF = PropertyFactory.createSelf(Table6.class); + public static final NumericIdProperty<Integer> ID_PK_PROPERTY = PropertyFactory.createNumericId("ID", "Table6", Integer.class); public static final String ID_PK_COLUMN = "ID"; public static final NumericProperty<Long> CRYPTO_INT1 = PropertyFactory.createNumeric("cryptoInt1", Long.class); diff --git a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table7.java b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table7.java index 3ba44f90a..ef0cc9e27 100644 --- a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table7.java +++ b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table7.java @@ -8,6 +8,7 @@ import org.apache.cayenne.BaseDataObject; import org.apache.cayenne.crypto.db.Table1; import org.apache.cayenne.crypto.db.Table7; import org.apache.cayenne.exp.property.EntityProperty; +import org.apache.cayenne.exp.property.NumericIdProperty; import org.apache.cayenne.exp.property.NumericProperty; import org.apache.cayenne.exp.property.PropertyFactory; import org.apache.cayenne.exp.property.StringProperty; @@ -24,6 +25,7 @@ public abstract class _Table7 extends BaseDataObject { public static final EntityProperty<Table7> SELF = PropertyFactory.createSelf(Table7.class); + public static final NumericIdProperty<Integer> ID_PK_PROPERTY = PropertyFactory.createNumericId("ID", "Table7", Integer.class); public static final String ID_PK_COLUMN = "ID"; public static final NumericProperty<Integer> CRYPTO_INT = PropertyFactory.createNumeric("cryptoInt", Integer.class); diff --git a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table8.java b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table8.java index 5b39f9007..1003a6fbe 100644 --- a/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table8.java +++ b/cayenne-crypto/src/test/java/org/apache/cayenne/crypto/db/auto/_Table8.java @@ -7,6 +7,7 @@ import java.io.ObjectOutputStream; import org.apache.cayenne.BaseDataObject; import org.apache.cayenne.crypto.db.Table8; import org.apache.cayenne.exp.property.EntityProperty; +import org.apache.cayenne.exp.property.NumericIdProperty; import org.apache.cayenne.exp.property.PropertyFactory; import org.apache.cayenne.exp.property.StringProperty; @@ -22,6 +23,7 @@ public abstract class _Table8 extends BaseDataObject { public static final EntityProperty<Table8> SELF = PropertyFactory.createSelf(Table8.class); + public static final NumericIdProperty<Integer> ID_PK_PROPERTY = PropertyFactory.createNumericId("ID", "Table8", Integer.class); public static final String ID_PK_COLUMN = "ID"; public static final StringProperty<String> CRYPTO_STRING = PropertyFactory.createString("cryptoString", String.class); diff --git a/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/CgenTask.java b/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/CgenTask.java index 7340a6e57..0d9c6eba4 100644 --- a/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/CgenTask.java +++ b/cayenne-gradle-plugin/src/main/java/org/apache/cayenne/tools/CgenTask.java @@ -341,7 +341,7 @@ public class CgenTask extends BaseCayenneTask { } else { getLogger().info("Using default cgen config."); cgenConfiguration = new CgenConfiguration(); - cgenConfiguration.setRelPath(getDestDirFile().getPath()); + cgenConfiguration.updateRelativeOutputPath(getDestDirFile().getPath()); cgenConfiguration.setDataMap(dataMap); return Collections.singletonList(cgenConfiguration); } @@ -350,7 +350,9 @@ public class CgenTask extends BaseCayenneTask { private CgenConfiguration cgenConfigFromPom(DataMap dataMap) { CgenConfiguration cgenConfiguration = new CgenConfiguration(); cgenConfiguration.setDataMap(dataMap); - cgenConfiguration.setRelPath(getDestDirFile() != null ? getDestDirFile().toPath() : cgenConfiguration.getRelPath()); + if(getDestDirFile() != null) { + cgenConfiguration.setRelativePath(getDestDirFile().toPath()); + } cgenConfiguration.setEncoding(encoding != null ? encoding : cgenConfiguration.getEncoding()); cgenConfiguration.setMakePairs(makePairs != null ? makePairs : cgenConfiguration.isMakePairs()); if (mode != null && mode.equals("datamap")) { diff --git a/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java b/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java index aa370476e..305b1bc47 100644 --- a/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java +++ b/maven-plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java @@ -348,7 +348,7 @@ public class CayenneGeneratorMojo extends AbstractMojo { logger.info("Using default cgen config."); CgenConfiguration cgenConfiguration = new CgenConfiguration(); cgenConfiguration.setDataMap(dataMap); - cgenConfiguration.setRelPath(defaultDir.getPath()); + cgenConfiguration.updateRelativeOutputPath(defaultDir.getPath()); return Collections.singletonList(cgenConfiguration); } } @@ -356,7 +356,8 @@ public class CayenneGeneratorMojo extends AbstractMojo { private CgenConfiguration cgenConfigFromPom(DataMap dataMap) { CgenConfiguration cgenConfiguration = new CgenConfiguration(); cgenConfiguration.setDataMap(dataMap); - cgenConfiguration.setRelPath(destDir != null ? destDir.getPath() : defaultDir.getPath()); + // TODO: check this call, CayenneGeneratorTask and CgenTask use setRelPath() + cgenConfiguration.updateRelativeOutputPath(destDir != null ? destDir.getPath() : defaultDir.getPath()); cgenConfiguration.setEncoding(encoding != null ? encoding : cgenConfiguration.getEncoding()); cgenConfiguration.setMakePairs(makePairs != null ? makePairs : cgenConfiguration.isMakePairs()); if (mode != null && mode.equals("datamap")) { diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorController.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorController.java index 7ab00e356..b4f14d2d1 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorController.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorController.java @@ -531,7 +531,11 @@ public class CodeGeneratorController extends CayenneController implements ObjEnt */ public void onProjectSaved(ProjectSavedEvent e) { // update path input - getStandardModeController().getView().getOutputFolder().setText(cgenConfiguration.getRootPath().toString()); + if(getStandardModeController() != null + && getStandardModeController().getView() != null + && cgenConfiguration != null) { + getStandardModeController().getView().getOutputFolder().setText(cgenConfiguration.getRootPath().toString()); + } } private final Predicate<ConfigurationNode> defaultPredicate = o -> o.acceptVisitor(new BaseConfigurationNodeVisitor<Boolean>() { diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorController.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorController.java index 5346e2aba..af69dcee2 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorController.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorController.java @@ -64,7 +64,7 @@ public abstract class GeneratorController extends CayenneController { this.cgenConfiguration = cgenConfiguration; if (cgenConfiguration.getRootPath() != null) { - getView().getOutputFolder().setText(cgenConfiguration.buildPath().toString()); + getView().getOutputFolder().setText(cgenConfiguration.buildOutputPath().toString()); } if(cgenConfiguration.getArtifactsGenerationMode().equalsIgnoreCase("all")) { getParentController().setCurrentClass(cgenConfiguration.getDataMap()); diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorControllerPanel.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorControllerPanel.java index 90f418b10..ccf8d1ee8 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorControllerPanel.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/GeneratorControllerPanel.java @@ -27,7 +27,6 @@ import org.apache.cayenne.validation.ValidationException; import javax.swing.JButton; import javax.swing.JPanel; import javax.swing.JTextField; -import java.nio.file.Path; import java.nio.file.Paths; /** @@ -55,7 +54,7 @@ public class GeneratorControllerPanel extends JPanel { if (cgenByDataMap.getRootPath() == null && !Paths.get(text).isAbsolute()) { throw new ValidationException("You should save project to use rel path as output directory "); } - cgenByDataMap.setRelPath(text); + cgenByDataMap.updateRelativeOutputPath(text); checkConfigDirty(); } }