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 bfafbab80 CAY-2785 Modeler: improve folder selection for cgen - JavaDocs - some more refactoring bfafbab80 is described below commit bfafbab802d693a1eda611b98d3d1b334c48a295 Author: Nikita Timofeev <stari...@gmail.com> AuthorDate: Thu Dec 8 09:58:28 2022 +0300 CAY-2785 Modeler: improve folder selection for cgen - JavaDocs - some more refactoring --- .../org/apache/cayenne/gen/CgenConfiguration.java | 39 ++++++++++++---------- .../apache/cayenne/gen/xml/CgenSaverDelegate.java | 4 +-- .../apache/cayenne/gen/CgenConfigurationTest.java | 32 +++++++++--------- .../cayenne/gen/xml/CgenSaverDelegateTest.java | 8 ++--- 4 files changed, 44 insertions(+), 39 deletions(-) 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 a0bbd5214..111f030dd 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 @@ -56,7 +56,7 @@ public class CgenConfiguration implements Serializable, XMLSerializable { * Target directory for generated classes, relative to the {@code rootProjectPath} * (if root path is set, and it's possible to relativize). */ - private Path cgenOutputRelativePath; + private Path cgenOutputPath; private Collection<Artifact> artifacts; private Set<String> entityArtifacts; @@ -194,42 +194,47 @@ public class CgenConfiguration implements Serializable, XMLSerializable { } /** + * Method returns output path as is, without any processing. * @return cgen output relative path + * @see #buildOutputPath() + * @since 5.0 renamed from {@code getRelPath()} */ - public Path getRelPath() { - return cgenOutputRelativePath; + public Path getRawOutputPath() { + return cgenOutputPath; } /** - * Method that calculates output path based on provided {@code Path} and {@code rootProjectPath} - * @param path to update relative path with + * Method that updates output path based on provided {@code Path} and {@code rootProjectPath} + * + * @param path to update output path with, could be an absolute path or a path + * relative to the {@code rootProjectPath} or cgen tool environment * @see #setRootPath(Path) * @since 5.0 */ public void updateOutputPath(Path path) { if (rootProjectPath != null) { if (path.isAbsolute() && rootProjectPath.getRoot().equals(path.getRoot())) { - this.cgenOutputRelativePath = rootProjectPath.relativize(path); + this.cgenOutputPath = rootProjectPath.relativize(path); return; } } - this.cgenOutputRelativePath = path; + this.cgenOutputPath = path; } /** * @return normalized relative path * @since 5.0 renamed from {@code buildRelPath()} and made package private */ - String getNormalizedRelativePath() { - if (cgenOutputRelativePath == null || cgenOutputRelativePath.toString().isEmpty()) { + String getNormalizedOutputPath() { + if (cgenOutputPath == null || cgenOutputPath.toString().isEmpty()) { return "."; } - return cgenOutputRelativePath.toString(); + return cgenOutputPath.toString(); } /** * This method calculates effective output directory for the class generator. - * It uses {@code rootProjectPath} and {@code cgenOutputRelativePath}. + * It uses {@code cgenOutputPath} and {@code rootProjectPath} (if set). * * @return calculated output directory * @see #setRootPath(Path) @@ -239,18 +244,18 @@ public class CgenConfiguration implements Serializable, XMLSerializable { public Path buildOutputPath() { if (rootProjectPath == null) { // this could be an unsaved project or direct usage in tools (Ant, Maven or Gradle) - return cgenOutputRelativePath; + return cgenOutputPath; } - if(cgenOutputRelativePath == null) { + if(cgenOutputPath == null) { // this case should be invalid, but let the caller deal with it return null; } - if(cgenOutputRelativePath.isAbsolute()) { - return cgenOutputRelativePath.normalize(); + if(cgenOutputPath.isAbsolute()) { + return cgenOutputPath.normalize(); } else { - return rootProjectPath.resolve(cgenOutputRelativePath).toAbsolutePath().normalize(); + return rootProjectPath.resolve(cgenOutputPath).toAbsolutePath().normalize(); } } @@ -457,7 +462,7 @@ public class CgenConfiguration implements Serializable, XMLSerializable { .simpleTag("name", this.name) .simpleTag("excludeEntities", getExcludeEntites()) .simpleTag("excludeEmbeddables", getExcludeEmbeddables()) - .simpleTag("destDir", separatorsToUnix(getNormalizedRelativePath())) + .simpleTag("destDir", separatorsToUnix(getNormalizedOutputPath())) .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/xml/CgenSaverDelegate.java b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenSaverDelegate.java index 1839f89f1..4e774502b 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 @@ -78,9 +78,9 @@ public class CgenSaverDelegate extends BaseSaverDelegate { if(prevOutputPath != null) { // Update relative path to match with the new root cgenConfiguration.updateOutputPath(prevOutputPath); - } else if(cgenConfiguration.getRelPath() == null) { + } else if(cgenConfiguration.buildOutputPath() == null) { // No path was set, and we are not in the Maven tree. - // Set output dir match with the root, nothing else we could do here + // Set output dir match with the root, nothing else we could do here. cgenConfiguration.updateOutputPath(baseDirectory); } } 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 55b5b3a99..319a74f4e 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 @@ -56,7 +56,7 @@ public class CgenConfigurationTest { Path relPath = Paths.get("C:\\test1\\test2\\test3"); configuration.updateOutputPath(relPath); - assertEquals(Paths.get(""), configuration.getRelPath()); + assertEquals(Paths.get(""), configuration.getRawOutputPath()); assertEquals(relPath, configuration.buildOutputPath()); } @@ -66,7 +66,7 @@ public class CgenConfigurationTest { Path relPath = Paths.get("C:\\test1\\test2\\testAnother"); configuration.updateOutputPath(relPath); - assertEquals(Paths.get("..\\testAnother"), configuration.getRelPath()); + assertEquals(Paths.get("..\\testAnother"), configuration.getRawOutputPath()); assertEquals(relPath, configuration.buildOutputPath()); } @@ -76,7 +76,7 @@ public class CgenConfigurationTest { Path relPath = Paths.get("C:\\"); configuration.updateOutputPath(relPath); - assertEquals(Paths.get(""), configuration.getRelPath()); + assertEquals(Paths.get(""), configuration.getRawOutputPath()); assertEquals(relPath, configuration.buildOutputPath()); } @@ -86,7 +86,7 @@ public class CgenConfigurationTest { Path relPath = Paths.get("E:\\test1\\test2\\test3"); configuration.updateOutputPath(relPath); - assertEquals(Paths.get("E:\\test1\\test2\\test3"), configuration.getRelPath()); + assertEquals(Paths.get("E:\\test1\\test2\\test3"), configuration.getRawOutputPath()); assertEquals(relPath, configuration.buildOutputPath()); } @@ -96,7 +96,7 @@ public class CgenConfigurationTest { Path relPath = Paths.get("E:\\test1\\test2\\testAnother"); configuration.updateOutputPath(relPath); - assertEquals(Paths.get("E:\\test1\\test2\\testAnother"), configuration.getRelPath()); + assertEquals(Paths.get("E:\\test1\\test2\\testAnother"), configuration.getRawOutputPath()); assertEquals(relPath, configuration.buildOutputPath()); } @@ -106,7 +106,7 @@ public class CgenConfigurationTest { Path relPath = Paths.get("E:\\"); configuration.updateOutputPath(relPath); - assertEquals(Paths.get("E:\\"), configuration.getRelPath()); + assertEquals(Paths.get("E:\\"), configuration.getRawOutputPath()); assertEquals(relPath, configuration.buildOutputPath()); } @@ -116,7 +116,7 @@ public class CgenConfigurationTest { Path relPath = Paths.get("E:\\"); configuration.updateOutputPath(relPath); - assertEquals(Paths.get("E:\\"), configuration.getRelPath()); + assertEquals(Paths.get("E:\\"), configuration.getRawOutputPath()); assertEquals(relPath, configuration.buildOutputPath()); } @@ -127,7 +127,7 @@ public class CgenConfigurationTest { configuration.updateOutputPath(relPath); - assertEquals(relPath, configuration.getRelPath()); + assertEquals(relPath, configuration.getRawOutputPath()); assertEquals(Paths.get("E:\\"), configuration.buildOutputPath()); } @@ -139,7 +139,7 @@ public class CgenConfigurationTest { @Test public void nullRootPath() { configuration.updateOutputPath(Path.of("C:\\test1\\test2\\test3")); - assertEquals(Paths.get("C:\\test1\\test2\\test3"), configuration.getRelPath()); + assertEquals(Paths.get("C:\\test1\\test2\\test3"), configuration.getRawOutputPath()); assertEquals(Paths.get("C:\\test1\\test2\\test3"), configuration.buildOutputPath()); } } @@ -165,7 +165,7 @@ public class CgenConfigurationTest { configuration.updateOutputPath(relPath); - assertEquals(Paths.get(""), configuration.getRelPath()); + assertEquals(Paths.get(""), configuration.getRawOutputPath()); assertEquals(relPath, configuration.buildOutputPath()); } @@ -175,7 +175,7 @@ public class CgenConfigurationTest { Path relPath = Paths.get("/test1/test2/testAnother"); configuration.updateOutputPath(relPath); - assertEquals(Paths.get("../testAnother"), configuration.getRelPath()); + assertEquals(Paths.get("../testAnother"), configuration.getRawOutputPath()); assertEquals(relPath, configuration.buildOutputPath()); } @@ -185,7 +185,7 @@ public class CgenConfigurationTest { Path relPath = Paths.get("/"); configuration.updateOutputPath(relPath); - assertEquals(Paths.get(""), configuration.getRelPath()); + assertEquals(Paths.get(""), configuration.getRawOutputPath()); assertEquals(relPath, configuration.buildOutputPath()); } @@ -195,7 +195,7 @@ public class CgenConfigurationTest { Path relPath = Paths.get("test1/test2/test3"); configuration.updateOutputPath(relPath); - assertEquals(Paths.get("test1/test2/test3"), configuration.getRelPath()); + assertEquals(Paths.get("test1/test2/test3"), configuration.getRawOutputPath()); assertEquals(Paths.get("/test1/test2/test3/test1/test2/test3"), configuration.buildOutputPath()); } @@ -205,7 +205,7 @@ public class CgenConfigurationTest { Path relPath = Paths.get("/"); configuration.updateOutputPath(relPath); - assertEquals(Paths.get("/"), configuration.getRelPath()); + assertEquals(Paths.get("/"), configuration.getRawOutputPath()); assertEquals(relPath, configuration.buildOutputPath()); } @@ -214,7 +214,7 @@ public class CgenConfigurationTest { configuration.setRootPath(Paths.get("/")); configuration.updateOutputPath(Paths.get("")); - assertEquals(Paths.get(""), configuration.getRelPath()); + assertEquals(Paths.get(""), configuration.getRawOutputPath()); assertEquals(Paths.get("/"), configuration.buildOutputPath()); } @@ -233,7 +233,7 @@ public class CgenConfigurationTest { @Test public void nullRootPath() { configuration.updateOutputPath(Paths.get("/test1/test2/test3")); - assertEquals(Paths.get("/test1/test2/test3"), configuration.getRelPath()); + assertEquals(Paths.get("/test1/test2/test3"), configuration.getRawOutputPath()); assertEquals(Paths.get("/test1/test2/test3"), configuration.buildOutputPath()); } } 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 8e5ee5e84..628ae8180 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 @@ -42,7 +42,7 @@ public class CgenSaverDelegateTest { CgenSaverDelegate.resolveOutputDir(baseURL, config); assertEquals(Paths.get("/tmp/src/main/resources").toAbsolutePath(), config.getRootPath()); - assertEquals(Paths.get(""), config.getRelPath()); // TODO: do we care about this case? + assertEquals(Paths.get(""), config.getRawOutputPath()); // TODO: do we care about this case? } @Test @@ -57,7 +57,7 @@ public class CgenSaverDelegateTest { CgenSaverDelegate.resolveOutputDir(baseURL, config); assertEquals(Paths.get("/tmp/src/main/resources").toAbsolutePath(), config.getRootPath()); - assertEquals(Paths.get("../java"), config.getRelPath()); + assertEquals(Paths.get("../java"), config.getRawOutputPath()); } @Test @@ -69,7 +69,7 @@ public class CgenSaverDelegateTest { CgenSaverDelegate.resolveOutputDir(baseURL, config); assertEquals(Paths.get("/tmp/src/main/resources").toAbsolutePath(), config.getRootPath()); - assertEquals(Paths.get("../java"), config.getRelPath()); + assertEquals(Paths.get("../java"), config.getRawOutputPath()); } @Test @@ -81,6 +81,6 @@ public class CgenSaverDelegateTest { CgenSaverDelegate.resolveOutputDir(baseURL, config); assertEquals(Paths.get("/tmp/somefolder").toAbsolutePath(), config.getRootPath()); - assertEquals(Paths.get(""), config.getRelPath()); + assertEquals(Paths.get(""), config.getRawOutputPath()); } } \ No newline at end of file