You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2017/01/31 07:38:09 UTC
[8/8] cayenne git commit: CAY-2214 cdbimport: rename
maven-cayenne-plugin - change module and folder name to
"cayenne-maven-plugin" - artifactId still is "maven-cayenne-plugin"
CAY-2214 cdbimport: rename maven-cayenne-plugin
- change module and folder name to "cayenne-maven-plugin"
- artifactId still is "maven-cayenne-plugin"
Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/2cddff91
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/2cddff91
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/2cddff91
Branch: refs/heads/master
Commit: 2cddff91a9ec6d86a9de510a46118780e2131846
Parents: a148a28
Author: Nikita Timofeev <st...@gmail.com>
Authored: Tue Jan 31 10:35:33 2017 +0300
Committer: Nikita Timofeev <st...@gmail.com>
Committed: Tue Jan 31 10:35:33 2017 +0300
----------------------------------------------------------------------
plugins/cayenne-maven-plugin/pom.xml | 186 ++++++++
.../cayenne/tools/CayenneGeneratorMojo.java | 293 +++++++++++++
.../apache/cayenne/tools/DbGeneratorMojo.java | 192 +++++++++
.../cayenne/tools/DbImportDataSourceConfig.java | 62 +++
.../apache/cayenne/tools/DbImporterMojo.java | 211 +++++++++
.../org/apache/cayenne/tools/MavenLogger.java | 105 +++++
.../META-INF/m2e/lifecycle-mapping-metadata.xml | 32 ++
.../cayenne/tools/CayenneGeneratorMojoTest.java | 78 ++++
.../tools/DbImporterMojoConfigurationTest.java | 125 ++++++
.../cayenne/tools/DbImporterMojoTest.java | 431 +++++++++++++++++++
.../org/apache/cayenne/tools/DerbyManager.java | 63 +++
.../test/resources/cgen/cayenne-testDomain.xml | 5 +
.../test/resources/cgen/project-to-test/pom.xml | 56 +++
.../resources/cgen/testAdditionalMap.map.xml | 18 +
.../test/resources/cgen/testDomainMap.map.xml | 45 ++
.../org/apache/cayenne/tools/config/pom-01.xml | 99 +++++
.../tools/config/pom-catalog-and-schema.xml | 84 ++++
.../apache/cayenne/tools/config/pom-catalog.xml | 87 ++++
.../tools/config/pom-default-package.xml | 38 ++
.../apache/cayenne/tools/config/pom-flat.xml | 78 ++++
.../apache/cayenne/tools/config/pom-mapping.xml | 67 +++
.../cayenne/tools/config/pom-schema-2.xml | 41 ++
.../apache/cayenne/tools/config/pom-schema.xml | 87 ++++
.../config/pom-skip-primary-key-loading.xml | 39 ++
.../config/pom-skip-relationships-loading.xml | 39 ++
.../cayenne/tools/config/pom-table-types.xml | 41 ++
.../dbimport/testComplexChangeOrder-pom.xml | 44 ++
.../dbimport/testComplexChangeOrder.map.xml | 64 +++
.../testComplexChangeOrder.map.xml-result | 53 +++
.../tools/dbimport/testComplexChangeOrder.sql | 34 ++
.../testCustomObjectLayerSettings-pom.xml | 51 +++
.../testCustomObjectLayerSettings.map.xml | 30 ++
...testCustomObjectLayerSettings.map.xml-result | 46 ++
.../dbimport/testCustomObjectLayerSettings.sql | 36 ++
.../dbimport/testDbAttributeChange-pom.xml | 47 ++
.../dbimport/testDbAttributeChange.map.xml | 62 +++
.../testDbAttributeChange.map.xml-result | 62 +++
.../tools/dbimport/testDbAttributeChange.sql | 46 ++
.../tools/dbimport/testDefaultPackage-pom.xml | 47 ++
.../dbimport/testDefaultPackage.map.xml-result | 52 +++
.../tools/dbimport/testDefaultPackage.sql | 40 ++
.../dbimport/testFilteringWithSchema-pom.xml | 45 ++
.../testFilteringWithSchema.map.xml-result | 51 +++
.../tools/dbimport/testFilteringWithSchema.sql | 64 +++
.../dbimport/testFkAttributeRename-pom.xml | 49 +++
.../dbimport/testFkAttributeRename.map.xml | 44 ++
.../testFkAttributeRename.map.xml-result | 45 ++
.../tools/dbimport/testFkAttributeRename.sql | 33 ++
...tFlattensManyToManyWithRecursiveLink-pom.xml | 44 ++
...nsManyToManyWithRecursiveLink.map.xml-result | 48 +++
.../testFlattensManyToManyWithRecursiveLink.sql | 31 ++
.../dbimport/testForceDataMapSchema-pom.xml | 50 +++
.../dbimport/testForceDataMapSchema.map.xml | 26 ++
.../testForceDataMapSchema.map.xml-result | 52 +++
.../tools/dbimport/testForceDataMapSchema.sql | 40 ++
.../testImportAddTableAndColumn-pom.xml | 41 ++
.../testImportAddTableAndColumn.map.xml | 37 ++
.../testImportAddTableAndColumn.map.xml-result | 50 +++
.../dbimport/testImportAddTableAndColumn.sql | 37 ++
.../tools/dbimport/testImportNewDataMap-pom.xml | 41 ++
.../testImportNewDataMap.map.xml-result | 37 ++
.../tools/dbimport/testImportNewDataMap.sql | 27 ++
.../dbimport/testImportWithoutChanges-pom.xml | 41 ++
.../dbimport/testImportWithoutChanges.map.xml | 37 ++
.../testImportWithoutChanges.map.xml-result | 37 ++
.../tools/dbimport/testImportWithoutChanges.sql | 27 ++
.../cayenne/tools/dbimport/testOneToOne-pom.xml | 41 ++
.../tools/dbimport/testOneToOne.map.xml-result | 58 +++
.../cayenne/tools/dbimport/testOneToOne.sql | 41 ++
.../testPreserveCustomObjMappings-pom.xml | 47 ++
.../testPreserveCustomObjMappings.map.xml | 33 ++
...testPreserveCustomObjMappings.map.xml-result | 35 ++
.../dbimport/testPreserveCustomObjMappings.sql | 28 ++
.../dbimport/testPreserveRelationships-pom.xml | 45 ++
.../dbimport/testPreserveRelationships.map.xml | 44 ++
.../testPreserveRelationships.map.xml-result | 34 ++
.../dbimport/testPreserveRelationships.sql | 28 ++
.../dbimport/testSchemasAndTableExclude-pom.xml | 48 +++
.../testSchemasAndTableExclude.map.xml-result | 38 ++
.../dbimport/testSchemasAndTableExclude.sql | 64 +++
.../dbimport/testSkipPrimaryKeyLoading-pom.xml | 45 ++
.../dbimport/testSkipPrimaryKeyLoading.map.xml | 35 ++
.../testSkipPrimaryKeyLoading.map.xml-result | 41 ++
.../dbimport/testSkipPrimaryKeyLoading.sql | 30 ++
.../testSkipRelationshipsLoading-pom.xml | 45 ++
.../testSkipRelationshipsLoading.map.xml | 55 +++
.../testSkipRelationshipsLoading.map.xml-result | 55 +++
.../dbimport/testSkipRelationshipsLoading.sql | 36 ++
...SupportsCatalogsOnReverseEngineering-pom.xml | 50 +++
...SupportsCatalogsOnReverseEngineering.map.xml | 25 ++
.../tools/dbimport/testTableTypes-pom.xml | 45 ++
.../dbimport/testTableTypes.map.xml-result | 29 ++
.../cayenne/tools/dbimport/testTableTypes.sql | 25 ++
.../dbimport/testUnFlattensManyToMany-pom.xml | 44 ++
.../dbimport/testUnFlattensManyToMany.map.xml | 55 +++
.../testUnFlattensManyToMany.map.xml-result | 88 ++++
.../tools/dbimport/testUnFlattensManyToMany.sql | 64 +++
.../tools/dbimport/testViewsExclude-pom.xml | 45 ++
.../dbimport/testViewsExclude.map.xml-result | 43 ++
.../cayenne/tools/dbimport/testViewsExclude.sql | 30 ++
.../apache/cayenne/tools/dbimporter-pom1.xml | 37 ++
.../apache/cayenne/tools/dbimporter-pom2.xml | 39 ++
.../apache/cayenne/tools/dbimporter-pom3.xml | 39 ++
plugins/maven-cayenne-plugin/pom.xml | 186 --------
.../cayenne/tools/CayenneGeneratorMojo.java | 293 -------------
.../apache/cayenne/tools/DbGeneratorMojo.java | 192 ---------
.../cayenne/tools/DbImportDataSourceConfig.java | 62 ---
.../apache/cayenne/tools/DbImporterMojo.java | 211 ---------
.../org/apache/cayenne/tools/MavenLogger.java | 105 -----
.../META-INF/m2e/lifecycle-mapping-metadata.xml | 32 --
.../cayenne/tools/CayenneGeneratorMojoTest.java | 78 ----
.../tools/DbImporterMojoConfigurationTest.java | 125 ------
.../cayenne/tools/DbImporterMojoTest.java | 431 -------------------
.../org/apache/cayenne/tools/DerbyManager.java | 63 ---
.../test/resources/cgen/cayenne-testDomain.xml | 5 -
.../test/resources/cgen/project-to-test/pom.xml | 56 ---
.../resources/cgen/testAdditionalMap.map.xml | 18 -
.../test/resources/cgen/testDomainMap.map.xml | 45 --
.../org/apache/cayenne/tools/config/pom-01.xml | 99 -----
.../tools/config/pom-catalog-and-schema.xml | 84 ----
.../apache/cayenne/tools/config/pom-catalog.xml | 87 ----
.../tools/config/pom-default-package.xml | 38 --
.../apache/cayenne/tools/config/pom-flat.xml | 78 ----
.../apache/cayenne/tools/config/pom-mapping.xml | 67 ---
.../cayenne/tools/config/pom-schema-2.xml | 41 --
.../apache/cayenne/tools/config/pom-schema.xml | 87 ----
.../config/pom-skip-primary-key-loading.xml | 39 --
.../config/pom-skip-relationships-loading.xml | 39 --
.../cayenne/tools/config/pom-table-types.xml | 41 --
.../dbimport/testComplexChangeOrder-pom.xml | 44 --
.../dbimport/testComplexChangeOrder.map.xml | 64 ---
.../testComplexChangeOrder.map.xml-result | 53 ---
.../tools/dbimport/testComplexChangeOrder.sql | 34 --
.../testCustomObjectLayerSettings-pom.xml | 51 ---
.../testCustomObjectLayerSettings.map.xml | 30 --
...testCustomObjectLayerSettings.map.xml-result | 46 --
.../dbimport/testCustomObjectLayerSettings.sql | 36 --
.../dbimport/testDbAttributeChange-pom.xml | 47 --
.../dbimport/testDbAttributeChange.map.xml | 62 ---
.../testDbAttributeChange.map.xml-result | 62 ---
.../tools/dbimport/testDbAttributeChange.sql | 46 --
.../tools/dbimport/testDefaultPackage-pom.xml | 47 --
.../dbimport/testDefaultPackage.map.xml-result | 52 ---
.../tools/dbimport/testDefaultPackage.sql | 40 --
.../dbimport/testFilteringWithSchema-pom.xml | 45 --
.../testFilteringWithSchema.map.xml-result | 51 ---
.../tools/dbimport/testFilteringWithSchema.sql | 64 ---
.../dbimport/testFkAttributeRename-pom.xml | 49 ---
.../dbimport/testFkAttributeRename.map.xml | 44 --
.../testFkAttributeRename.map.xml-result | 45 --
.../tools/dbimport/testFkAttributeRename.sql | 33 --
...tFlattensManyToManyWithRecursiveLink-pom.xml | 44 --
...nsManyToManyWithRecursiveLink.map.xml-result | 48 ---
.../testFlattensManyToManyWithRecursiveLink.sql | 31 --
.../dbimport/testForceDataMapSchema-pom.xml | 50 ---
.../dbimport/testForceDataMapSchema.map.xml | 26 --
.../testForceDataMapSchema.map.xml-result | 52 ---
.../tools/dbimport/testForceDataMapSchema.sql | 40 --
.../testImportAddTableAndColumn-pom.xml | 41 --
.../testImportAddTableAndColumn.map.xml | 37 --
.../testImportAddTableAndColumn.map.xml-result | 50 ---
.../dbimport/testImportAddTableAndColumn.sql | 37 --
.../tools/dbimport/testImportNewDataMap-pom.xml | 41 --
.../testImportNewDataMap.map.xml-result | 37 --
.../tools/dbimport/testImportNewDataMap.sql | 27 --
.../dbimport/testImportWithoutChanges-pom.xml | 41 --
.../dbimport/testImportWithoutChanges.map.xml | 37 --
.../testImportWithoutChanges.map.xml-result | 37 --
.../tools/dbimport/testImportWithoutChanges.sql | 27 --
.../cayenne/tools/dbimport/testOneToOne-pom.xml | 41 --
.../tools/dbimport/testOneToOne.map.xml-result | 58 ---
.../cayenne/tools/dbimport/testOneToOne.sql | 41 --
.../testPreserveCustomObjMappings-pom.xml | 47 --
.../testPreserveCustomObjMappings.map.xml | 33 --
...testPreserveCustomObjMappings.map.xml-result | 35 --
.../dbimport/testPreserveCustomObjMappings.sql | 28 --
.../dbimport/testPreserveRelationships-pom.xml | 45 --
.../dbimport/testPreserveRelationships.map.xml | 44 --
.../testPreserveRelationships.map.xml-result | 34 --
.../dbimport/testPreserveRelationships.sql | 28 --
.../dbimport/testSchemasAndTableExclude-pom.xml | 48 ---
.../testSchemasAndTableExclude.map.xml-result | 38 --
.../dbimport/testSchemasAndTableExclude.sql | 64 ---
.../dbimport/testSkipPrimaryKeyLoading-pom.xml | 45 --
.../dbimport/testSkipPrimaryKeyLoading.map.xml | 35 --
.../testSkipPrimaryKeyLoading.map.xml-result | 41 --
.../dbimport/testSkipPrimaryKeyLoading.sql | 30 --
.../testSkipRelationshipsLoading-pom.xml | 45 --
.../testSkipRelationshipsLoading.map.xml | 55 ---
.../testSkipRelationshipsLoading.map.xml-result | 55 ---
.../dbimport/testSkipRelationshipsLoading.sql | 36 --
...SupportsCatalogsOnReverseEngineering-pom.xml | 50 ---
...SupportsCatalogsOnReverseEngineering.map.xml | 25 --
.../tools/dbimport/testTableTypes-pom.xml | 45 --
.../dbimport/testTableTypes.map.xml-result | 29 --
.../cayenne/tools/dbimport/testTableTypes.sql | 25 --
.../dbimport/testUnFlattensManyToMany-pom.xml | 44 --
.../dbimport/testUnFlattensManyToMany.map.xml | 55 ---
.../testUnFlattensManyToMany.map.xml-result | 88 ----
.../tools/dbimport/testUnFlattensManyToMany.sql | 64 ---
.../tools/dbimport/testViewsExclude-pom.xml | 45 --
.../dbimport/testViewsExclude.map.xml-result | 43 --
.../cayenne/tools/dbimport/testViewsExclude.sql | 30 --
.../apache/cayenne/tools/dbimporter-pom1.xml | 37 --
.../apache/cayenne/tools/dbimporter-pom2.xml | 39 --
.../apache/cayenne/tools/dbimporter-pom3.xml | 39 --
plugins/pom.xml | 2 +-
207 files changed, 5935 insertions(+), 5935 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cayenne/blob/2cddff91/plugins/cayenne-maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/cayenne-maven-plugin/pom.xml b/plugins/cayenne-maven-plugin/pom.xml
new file mode 100644
index 0000000..bebdcf4
--- /dev/null
+++ b/plugins/cayenne-maven-plugin/pom.xml
@@ -0,0 +1,186 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
+ license agreements. See the NOTICE file distributed with this work for additional
+ information regarding copyright ownership. The ASF licenses this file to
+ you under the Apache License, Version 2.0 (the "License"); you may not use
+ this file except in compliance with the License. You may obtain a copy of
+ the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
+ by applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ OF ANY KIND, either express or implied. See the License for the specific
+ language governing permissions and limitations under the License. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <artifactId>cayenne-plugins-parent</artifactId>
+ <groupId>org.apache.cayenne.plugins</groupId>
+ <version>4.0.M5-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>maven-cayenne-plugin</artifactId>
+ <packaging>maven-plugin</packaging>
+ <name>maven-cayenne-plugin: Cayenne Maven Plugin</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-artifact</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-tools-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-compat</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-interpolation</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-container-default</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.cayenne</groupId>
+ <artifactId>cayenne-project</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.cayenne</groupId>
+ <artifactId>cayenne-server</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.cayenne</groupId>
+ <artifactId>cayenne-tools</artifactId>
+ <version>${project.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>foundrylogic.vpp</groupId>
+ <artifactId>vpp</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <!-- Test deps -->
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven.plugin-testing</groupId>
+ <artifactId>maven-plugin-testing-harness</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>xmlunit</groupId>
+ <artifactId>xmlunit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.cayenne</groupId>
+ <artifactId>cayenne-server</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ <type>test-jar</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.cayenne</groupId>
+ <artifactId>cayenne-tools</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ <type>test-jar</type>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.cayenne.build-tools</groupId>
+ <artifactId>cayenne-test-utilities</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </reporting>
+
+ <profiles>
+ <profile>
+ <id>code-quality</id>
+
+ <activation>
+ <property>
+ <name>!fast-and-dirty</name>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <!--<configuration>
+ <suppressionsLocation>${project.basedir}/cayenne-checkstyle-suppression.xml</suppressionsLocation>
+ </configuration>-->
+ </plugin>
+ <plugin>
+ <artifactId>maven-pmd-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
+
http://git-wip-us.apache.org/repos/asf/cayenne/blob/2cddff91/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java b/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
new file mode 100644
index 0000000..46a7cb5
--- /dev/null
+++ b/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/CayenneGeneratorMojo.java
@@ -0,0 +1,293 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.tools;
+
+import org.apache.cayenne.dbsync.filter.NamePatternMatcher;
+import org.apache.cayenne.gen.ClassGenerationAction;
+import org.apache.cayenne.gen.ClientClassGenerationAction;
+import org.apache.cayenne.map.DataMap;
+import org.apache.commons.logging.Log;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+import java.io.File;
+import java.io.FilenameFilter;
+
+/**
+ * Maven mojo to perform class generation from data map. This class is an Maven
+ * adapter to DefaultClassGenerator class.
+ *
+ * @since 3.0
+ *
+ * @phase generate-sources
+ * @goal cgen
+ */
+public class CayenneGeneratorMojo extends AbstractMojo {
+
+ public static final File[] NO_FILES = new File[0];
+ /**
+ * Path to additional DataMap XML files to use for class generation.
+ *
+ * @parameter additionalMaps="additionalMaps"
+ */
+ private File additionalMaps;
+
+ /**
+ * Whether we are generating classes for the client tier in a Remote Object
+ * Persistence application. Default is <code>false</code>.
+ *
+ * @parameter client="client" default-value="false"
+ */
+ private boolean client;
+
+ /**
+ * Destination directory for Java classes (ignoring their package names).
+ *
+ * @parameter destDir="destDir" default-value="${project.build.sourceDirectory}"
+ */
+ private File destDir;
+
+ /**
+ * Specify generated file encoding if different from the default on current
+ * platform. Target encoding must be supported by the JVM running Maven
+ * build. Standard encodings supported by Java on all platforms are
+ * US-ASCII, ISO-8859-1, UTF-8, UTF-16BE, UTF-16LE, UTF-16. See Sun Java
+ * Docs for java.nio.charset.Charset for more information.
+ *
+ * @parameter encoding="encoding"
+ */
+ private String encoding;
+
+ /**
+ * Entities (expressed as a perl5 regex) to exclude from template
+ * generation. (Default is to include all entities in the DataMap).
+ *
+ * @parameter excludeEntities="excludeEntities"
+ */
+ private String excludeEntities;
+
+ /**
+ * Entities (expressed as a perl5 regex) to include in template generation.
+ * (Default is to include all entities in the DataMap).
+ *
+ * @parameter includeEntities="includeEntities"
+ */
+ private String includeEntities;
+
+ /**
+ * If set to <code>true</code>, will generate subclass/superclass pairs,
+ * with all generated code included in superclass (default is
+ * <code>true</code>).
+ *
+ * @parameter makePairs="makePairs" default-value="true"
+ */
+ private boolean makePairs;
+
+ /**
+ * DataMap XML file to use as a base for class generation.
+ *
+ * @parameter map="map"
+ * @required
+ */
+ private File map;
+
+ /**
+ * Specifies generator iteration target. "entity" performs one
+ * iteration for each selected entity. "datamap" performs one
+ * iteration per datamap (This is always one iteration since cgen currently
+ * supports specifying one-and-only-one datamap). (Default is
+ * "entity")
+ *
+ * @parameter mode="mode" default-value="entity"
+ */
+ private String mode;
+
+ /**
+ * Name of file for generated output. (Default is "*.java")
+ *
+ * @parameter outputPattern="outputPattern" default-value="*.java"
+ */
+ private String outputPattern;
+
+ /**
+ * If set to <code>true</code>, will overwrite older versions of generated
+ * classes. Ignored unless makepairs is set to <code>false</code>.
+ *
+ * @parameter overwrite="overwrite" default-value="false"
+ */
+ private boolean overwrite;
+
+ /**
+ * Java package name of generated superclasses. Ignored unless
+ * <code>makepairs</code> set to <code>true</code>. If omitted, each
+ * superclass will be assigned the same package as subclass. Note that
+ * having superclass in a different package would only make sense when
+ * <code>usepkgpath</code> is set to <code>true</code>. Otherwise classes
+ * from different packages will end up in the same directory.
+ *
+ * @parameter superPkg="superPkg"
+ */
+ private String superPkg;
+
+ /**
+ * Location of Velocity template file for Entity superclass generation.
+ * Ignored unless <code>makepairs</code> set to <code>true</code>. If
+ * omitted, default template is used.
+ *
+ * @parameter superTemplate="superTemplate"
+ */
+ private String superTemplate;
+
+ /**
+ * Location of Velocity template file for Entity class generation. If
+ * omitted, default template is used.
+ *
+ * @parameter template="template"
+ */
+ private String template;
+
+ /**
+ * Location of Velocity template file for Embeddable superclass generation.
+ * Ignored unless <code>makepairs</code> set to <code>true</code>. If
+ * omitted, default template is used.
+ *
+ * @parameter embeddableSuperTemplate="embeddableSuperTemplate"
+ */
+ private String embeddableSuperTemplate;
+
+ /**
+ * Location of Velocity template file for Embeddable class generation. If
+ * omitted, default template is used.
+ *
+ * @parameter embeddableTemplate="embeddableTemplate"
+ */
+ private String embeddableTemplate;
+
+ /**
+ * If set to <code>true</code> (default), a directory tree will be generated
+ * in "destDir" corresponding to the class package structure, if set to
+ * <code>false</code>, classes will be generated in "destDir"
+ * ignoring their package.
+ *
+ * @parameter usePkgPath="usePkgPath" default-value="true"
+ */
+ private boolean usePkgPath;
+
+ /**
+ * If set to <code>true</code>, will generate String Property names.
+ * Default is <code>false</code>.
+ *
+ * @parameter createPropertyNames="createPropertyNames" default-value="false"
+ */
+ private boolean createPropertyNames;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ // Create the destination directory if necessary.
+ // TODO: (KJM 11/2/06) The destDir really should be added as a
+ // compilation resource for maven.
+ if (!destDir.exists()) {
+ destDir.mkdirs();
+ }
+
+ Log logger = new MavenLogger(this);
+ CayenneGeneratorMapLoaderAction loaderAction = new CayenneGeneratorMapLoaderAction();
+ loaderAction.setMainDataMapFile(map);
+
+ CayenneGeneratorEntityFilterAction filterAction = new CayenneGeneratorEntityFilterAction();
+ filterAction.setClient(client);
+ filterAction.setNameFilter(NamePatternMatcher.build(logger, includeEntities, excludeEntities));
+
+ try {
+ loaderAction.setAdditionalDataMapFiles(convertAdditionalDataMaps());
+
+ DataMap dataMap = loaderAction.getMainDataMap();
+
+ ClassGenerationAction generator = createGenerator();
+ generator.setLogger(logger);
+ generator.setTimestamp(map.lastModified());
+ generator.setDataMap(dataMap);
+ generator.addEntities(filterAction.getFilteredEntities(dataMap));
+ // ksenia khailenko 15.10.2010
+ // TODO add the "includeEmbeddables" and "excludeEmbeddables"
+ // attributes
+ generator.addEmbeddables(dataMap.getEmbeddables());
+ // TODO add the "includeQueries" and "excludeQueries" attributes
+ generator.addQueries(dataMap.getQueryDescriptors());
+ generator.execute();
+ } catch (Exception e) {
+ throw new MojoExecutionException("Error generating classes: ", e);
+ }
+ }
+
+ /**
+ * Loads and returns DataMap based on <code>map</code> attribute.
+ */
+ protected File[] convertAdditionalDataMaps() throws Exception {
+
+ if (additionalMaps == null) {
+ return NO_FILES;
+ }
+
+ if (!additionalMaps.isDirectory()) {
+ throw new MojoFailureException(
+ "'additionalMaps' must be a directory.");
+ }
+
+ FilenameFilter mapFilter = new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return name != null &&
+ name.toLowerCase().endsWith(".map.xml");
+ }
+ };
+ return additionalMaps.listFiles(mapFilter);
+ }
+
+ /**
+ * Factory method to create internal class generator. Called from
+ * constructor.
+ */
+ protected ClassGenerationAction createGenerator() {
+
+ ClassGenerationAction action;
+ if (client) {
+ action = new ClientClassGenerationAction();
+ } else {
+ action = new ClassGenerationAction();
+ }
+
+ action.setDestDir(destDir);
+ action.setEncoding(encoding);
+ action.setMakePairs(makePairs);
+ action.setArtifactsGenerationMode(mode);
+ action.setOutputPattern(outputPattern);
+ action.setOverwrite(overwrite);
+ action.setSuperPkg(superPkg);
+ action.setSuperTemplate(superTemplate);
+ action.setTemplate(template);
+ action.setEmbeddableSuperTemplate(embeddableSuperTemplate);
+ action.setEmbeddableTemplate(embeddableTemplate);
+ action.setUsePkgPath(usePkgPath);
+ action.setCreatePropertyNames(createPropertyNames);
+
+ return action;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/2cddff91/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbGeneratorMojo.java
----------------------------------------------------------------------
diff --git a/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbGeneratorMojo.java b/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbGeneratorMojo.java
new file mode 100644
index 0000000..72c524f
--- /dev/null
+++ b/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbGeneratorMojo.java
@@ -0,0 +1,192 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.tools;
+
+import org.apache.cayenne.access.DbGenerator;
+import org.apache.cayenne.datasource.DriverDataSource;
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.dba.JdbcAdapter;
+import org.apache.cayenne.dbsync.DbSyncModule;
+import org.apache.cayenne.di.AdhocObjectFactory;
+import org.apache.cayenne.di.DIBootstrap;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.log.NoopJdbcEventLogger;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.MapLoader;
+import org.apache.cayenne.tools.configuration.ToolsModule;
+import org.apache.cayenne.util.Util;
+import org.apache.commons.logging.Log;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.xml.sax.InputSource;
+
+import java.io.File;
+import java.sql.Driver;
+
+/**
+ * Maven mojo to perform class generation from data map. This class is a Maven
+ * adapter to DefaultClassGenerator class.
+ *
+ * @since 3.0
+ *
+ * @phase pre-integration-test
+ * @goal cdbgen
+ */
+public class DbGeneratorMojo extends AbstractMojo {
+
+ /**
+ * DataMap XML file to use as a schema descriptor.
+ *
+ * @parameter map="map"
+ * @required
+ */
+ private File map;
+
+ /**
+ * Java class implementing org.apache.cayenne.dba.DbAdapter. While this
+ * attribute is optional (a generic JdbcAdapter is used if not set), it is
+ * highly recommended to specify correct target adapter.
+ *
+ * @parameter adapter="adapter"
+ */
+ private String adapter;
+
+ /**
+ * A class of JDBC driver to use for the target database.
+ *
+ * @parameter driver="driver"
+ * @required
+ */
+ private String driver;
+
+ /**
+ * JDBC connection URL of a target database.
+ *
+ * @parameter url="url"
+ * @required
+ */
+ private String url;
+
+ /**
+ * Database user name.
+ *
+ * @parameter username="username"
+ */
+ private String username;
+
+ /**
+ * Database user password.
+ *
+ * @parameter password="password"
+ */
+ private String password;
+
+ /**
+ * Defines whether cdbgen should drop the tables before attempting to create
+ * new ones. Default is <code>false</code>.
+ *
+ * @parameter dropTables="dropTables" default-value="false"
+ */
+ private boolean dropTables;
+
+ /**
+ * Defines whether cdbgen should drop Cayenne primary key support objects.
+ * Default is <code>false</code>.
+ *
+ * @parameter dropPK="dropPK" default-value="false"
+ */
+ private boolean dropPK;
+
+ /**
+ * Defines whether cdbgen should create new tables. Default is
+ * <code>true</code>.
+ *
+ * @parameter createTables="createTables" default-value="true"
+ */
+ private boolean createTables;
+
+ /**
+ * Defines whether cdbgen should create Cayenne-specific auto PK objects.
+ * Default is <code>true</code>.
+ *
+ * @parameter createPK="createPK" default-value="true"
+ */
+ private boolean createPK;
+
+ /**
+ * Defines whether cdbgen should create foreign key copnstraints. Default is
+ * <code>true</code>.
+ *
+ * @parameter createFK="createFK" default-value="true"
+ */
+ private boolean createFK;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+
+ Log logger = new MavenLogger(this);
+ Injector injector = DIBootstrap.createInjector(new DbSyncModule(), new ToolsModule(logger));
+ AdhocObjectFactory objectFactory = injector.getInstance(AdhocObjectFactory.class);
+
+ logger.info(String.format("connection settings - [driver: %s, url: %s, username: %s]", driver, url, username));
+
+ logger.info(String.format(
+ "generator options - [dropTables: %s, dropPK: %s, createTables: %s, createPK: %s, createFK: %s]",
+ dropTables, dropPK, createTables, createPK, createFK));
+
+ try {
+ final DbAdapter adapterInst = (adapter == null) ? (DbAdapter) objectFactory.newInstance(DbAdapter.class,
+ JdbcAdapter.class.getName()) : (DbAdapter) objectFactory.newInstance(DbAdapter.class, adapter);
+
+ // Load the data map and run the db generator.
+ DataMap dataMap = loadDataMap();
+ DbGenerator generator = new DbGenerator(adapterInst, dataMap, NoopJdbcEventLogger.getInstance());
+ generator.setShouldCreateFKConstraints(createFK);
+ generator.setShouldCreatePKSupport(createPK);
+ generator.setShouldCreateTables(createTables);
+ generator.setShouldDropPKSupport(dropPK);
+ generator.setShouldDropTables(dropTables);
+
+ // load driver taking custom CLASSPATH into account...
+ DriverDataSource dataSource = new DriverDataSource((Driver) Class.forName(driver).newInstance(), url,
+ username, password);
+
+ generator.runGenerator(dataSource);
+ } catch (Exception ex) {
+ Throwable th = Util.unwindException(ex);
+
+ String message = "Error generating database";
+
+ if (th.getLocalizedMessage() != null) {
+ message += ": " + th.getLocalizedMessage();
+ }
+
+ logger.error(message);
+ throw new MojoExecutionException(message, th);
+ }
+ }
+
+ /** Loads and returns DataMap based on <code>map</code> attribute. */
+ protected DataMap loadDataMap() throws Exception {
+ InputSource in = new InputSource(map.getCanonicalPath());
+ return new MapLoader().loadDataMap(in);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/2cddff91/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbImportDataSourceConfig.java
----------------------------------------------------------------------
diff --git a/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbImportDataSourceConfig.java b/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbImportDataSourceConfig.java
new file mode 100644
index 0000000..8fa4b56
--- /dev/null
+++ b/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbImportDataSourceConfig.java
@@ -0,0 +1,62 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.tools;
+
+/**
+ * @since 4.0
+ */
+public class DbImportDataSourceConfig {
+
+ /**
+ * A class of JDBC driver to use for the target database.
+ */
+ private String driver;
+
+ /**
+ * JDBC connection URL of a target database.
+ */
+ private String url;
+
+ /**
+ * Database user name.
+ */
+ private String username;
+
+ /**
+ * Database user password.
+ */
+ private String password;
+
+ public String getDriver() {
+ return driver;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/2cddff91/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
----------------------------------------------------------------------
diff --git a/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java b/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
new file mode 100644
index 0000000..9c9cddf
--- /dev/null
+++ b/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/DbImporterMojo.java
@@ -0,0 +1,211 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+package org.apache.cayenne.tools;
+
+import org.apache.cayenne.dbimport.ReverseEngineering;
+import org.apache.cayenne.dbsync.DbSyncModule;
+import org.apache.cayenne.dbsync.reverse.filters.FiltersConfigBuilder;
+import org.apache.cayenne.di.DIBootstrap;
+import org.apache.cayenne.di.Injector;
+import org.apache.cayenne.tools.configuration.ToolsModule;
+import org.apache.cayenne.tools.dbimport.DbImportAction;
+import org.apache.cayenne.tools.dbimport.DbImportConfiguration;
+import org.apache.cayenne.tools.dbimport.DbImportModule;
+import org.apache.cayenne.util.Util;
+import org.apache.commons.logging.Log;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+
+import java.io.File;
+
+/**
+ * Maven mojo to reverse engineer datamap from DB.
+ *
+ * @since 3.0
+ */
+@Mojo(name = "cdbimport", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
+public class DbImporterMojo extends AbstractMojo {
+
+ /**
+ * Java class implementing org.apache.cayenne.dba.DbAdapter. This attribute
+ * is optional, the default is AutoAdapter, i.e. Cayenne would try to guess
+ * the DB type.
+ */
+ @Parameter(defaultValue = "org.apache.cayenne.dba.AutoAdapter")
+ private String adapter;
+
+ /**
+ * Connection properties.
+ *
+ * @see DbImportDataSourceConfig
+ * @since 4.0
+ */
+ @Parameter(required = true)
+ private DbImportDataSourceConfig dataSource = new DbImportDataSourceConfig();
+
+ /**
+ * DataMap XML file to use as a base for DB importing.
+ */
+ @Parameter(required = true)
+ private File map;
+
+ /**
+ * An object that contains reverse engineering rules.
+ */
+ @Parameter(name = "dbimport", property = "dbimport", alias = "dbImport")
+ private ReverseEngineering dbImportConfig = new ReverseEngineering();
+
+ /**
+ * @deprecated use {@code <dataSource>} tag to set connection properties
+ */
+ @Deprecated @Parameter(name = "url", property = "url")
+ private final String oldUrl = ""; // TODO remove in 4.0.BETA
+
+ /**
+ * @deprecated moved to {@code <dbimport>} section
+ */
+ @Deprecated @Parameter(name = "meaningfulPkTables", property = "meaningfulPkTables")
+ private final String oldMeaningfulPkTables = ""; // TODO remove in 4.0.BETA
+
+ /**
+ * @deprecated use {@code <dataSource>} tag to set connection properties
+ */
+ @Deprecated @Parameter(name = "driver", property = "driver")
+ private final String oldDriver = ""; // TODO remove in 4.0.BETA
+
+ /**
+ * @deprecated moved to {@code <dbimport>} section
+ */
+ @Deprecated @Parameter(name = "defaultPackage", property = "defaultPackage")
+ private final String oldDefaultPackage = ""; // TODO remove in 4.0.BETA
+
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+
+ Log logger = new MavenLogger(this);
+
+ DbImportConfiguration config = createConfig(logger);
+ Injector injector = DIBootstrap.createInjector(
+ new DbSyncModule(), new ToolsModule(logger), new DbImportModule());
+
+ DbImportConfigurationValidator validator = new DbImportConfigurationValidator(
+ dbImportConfig, config, injector);
+ try {
+ validator.validate();
+ } catch (Exception ex) {
+ throw new MojoExecutionException(ex.getMessage(), ex);
+ }
+
+ try {
+ injector.getInstance(DbImportAction.class).execute(config);
+ } catch (Exception ex) {
+ Throwable th = Util.unwindException(ex);
+
+ String message = "Error importing database schema";
+
+ if (th.getLocalizedMessage() != null) {
+ message += ": " + th.getLocalizedMessage();
+ }
+
+ getLog().error(message);
+ throw new MojoExecutionException(message, th);
+ }
+ }
+
+ DbImportConfiguration createConfig(Log logger) {
+
+ DbImportConfiguration config = new DbImportConfiguration();
+ config.setAdapter(adapter);
+ config.setDefaultPackage(dbImportConfig.getDefaultPackage());
+ config.setDriver(dataSource.getDriver());
+ config.setFiltersConfig(new FiltersConfigBuilder(dbImportConfig).build());
+ config.setForceDataMapCatalog(dbImportConfig.isForceDataMapCatalog());
+ config.setForceDataMapSchema(dbImportConfig.isForceDataMapSchema());
+ config.setLogger(logger);
+ config.setMeaningfulPkTables(dbImportConfig.getMeaningfulPkTables());
+ config.setNamingStrategy(dbImportConfig.getNamingStrategy());
+ config.setPassword(dataSource.getPassword());
+ config.setSkipRelationshipsLoading(dbImportConfig.getSkipRelationshipsLoading());
+ config.setSkipPrimaryKeyLoading(dbImportConfig.getSkipPrimaryKeyLoading());
+ config.setStripFromTableNames(dbImportConfig.getStripFromTableNames());
+ config.setTableTypes(dbImportConfig.getTableTypes());
+ config.setTargetDataMap(map);
+ config.setUrl(dataSource.getUrl());
+ config.setUsername(dataSource.getUsername());
+ config.setUsePrimitives(dbImportConfig.isUsePrimitives());
+
+ return config;
+ }
+
+ public File getMap() {
+ return map;
+ }
+
+ /**
+ * Used only in tests, Maven will inject value directly into the "map" field
+ */
+ public void setMap(File map) {
+ this.map = map;
+ }
+
+ /**
+ * This setter is used by Maven when defined {@code <dbimport>} tag
+ */
+ public void setDbimport(ReverseEngineering dbImportConfig) {
+ this.dbImportConfig = dbImportConfig;
+ }
+
+ /**
+ * This setter is used by Maven {@code <dbImport>} tag
+ */
+ public void setDbImport(ReverseEngineering dbImportConfig) {
+ this.dbImportConfig = dbImportConfig;
+ }
+
+ public ReverseEngineering getReverseEngineering() {
+ return dbImportConfig;
+ }
+
+ // TODO \u2b07\u2b07\u2b07 All following setters should be removed in 4.0.BETA \u2b07\u2b07\u2b07
+ @Deprecated
+ public void setUrl(String url) {
+ throw new UnsupportedOperationException("Connection properties were replaced with <dataSource> tag since 4.0.M5.\n\tFor additional information see http://cayenne.apache.org/docs/4.0/cayenne-guide/including-cayenne-in-project.html#maven-projects");
+ }
+
+ @Deprecated
+ public void setDriver(String driver) {
+ throw new UnsupportedOperationException("Connection properties were replaced with <dataSource> tag since 4.0.M5.\n\tFor additional information see http://cayenne.apache.org/docs/4.0/cayenne-guide/including-cayenne-in-project.html#maven-projects");
+ }
+
+ @Deprecated
+ public void setMeaningfulPkTables(String meaningfulPkTables) {
+ throw new UnsupportedOperationException("meaningfulPkTables property has been moved to <dbimport> tag since 4.0.M5.\n\tFor additional information see http://cayenne.apache.org/docs/4.0/cayenne-guide/including-cayenne-in-project.html#maven-projects");
+ }
+
+ @Deprecated
+ public void setDefaultPackage(String defaultPackage) {
+ throw new UnsupportedOperationException("defaultPackage property has been deprecated since 4.0.M5.\n\tFor additional information see http://cayenne.apache.org/docs/4.0/cayenne-guide/including-cayenne-in-project.html#maven-projects");
+ }
+}
+
+
http://git-wip-us.apache.org/repos/asf/cayenne/blob/2cddff91/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/MavenLogger.java
----------------------------------------------------------------------
diff --git a/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/MavenLogger.java b/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/MavenLogger.java
new file mode 100644
index 0000000..c439f98
--- /dev/null
+++ b/plugins/cayenne-maven-plugin/src/main/java/org/apache/cayenne/tools/MavenLogger.java
@@ -0,0 +1,105 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+package org.apache.cayenne.tools;
+
+import org.apache.maven.plugin.AbstractMojo;
+
+/**
+ * @since 3.0
+ */
+class MavenLogger implements org.apache.commons.logging.Log {
+
+ private org.apache.maven.plugin.logging.Log logger;
+
+ public MavenLogger(AbstractMojo parent) {
+ this.logger = parent.getLog();
+ }
+
+ public void debug(Object message, Throwable th) {
+ logger.debug(String.valueOf(message), th);
+ }
+
+ public void debug(Object message) {
+ logger.debug(String.valueOf(message));
+ }
+
+ public void error(Object message, Throwable th) {
+ logger.error(String.valueOf(message), th);
+ }
+
+ public void error(Object message) {
+ logger.error(String.valueOf(message));
+ }
+
+ public void fatal(Object message, Throwable th) {
+ logger.error(String.valueOf(message), th);
+ }
+
+ public void fatal(Object message) {
+ logger.error(String.valueOf(message));
+ }
+
+ public void info(Object message, Throwable th) {
+ logger.info(String.valueOf(message), th);
+ }
+
+ public void info(Object message) {
+ logger.info(String.valueOf(message));
+ }
+
+ public boolean isDebugEnabled() {
+ return logger.isDebugEnabled();
+ }
+
+ public boolean isErrorEnabled() {
+ return logger.isErrorEnabled();
+ }
+
+ public boolean isFatalEnabled() {
+ return logger.isErrorEnabled();
+ }
+
+ public boolean isInfoEnabled() {
+ return logger.isInfoEnabled();
+ }
+
+ public boolean isTraceEnabled() {
+ return logger.isDebugEnabled();
+ }
+
+ public boolean isWarnEnabled() {
+ return logger.isWarnEnabled();
+ }
+
+ public void trace(Object message, Throwable th) {
+ logger.debug(String.valueOf(message), th);
+ }
+
+ public void trace(Object message) {
+ logger.debug(String.valueOf(message));
+ }
+
+ public void warn(Object message, Throwable th) {
+ logger.warn(String.valueOf(message), th);
+ }
+
+ public void warn(Object message) {
+ logger.warn(String.valueOf(message));
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/2cddff91/plugins/cayenne-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
----------------------------------------------------------------------
diff --git a/plugins/cayenne-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml b/plugins/cayenne-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
new file mode 100644
index 0000000..e5de2d0
--- /dev/null
+++ b/plugins/cayenne-maven-plugin/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml
@@ -0,0 +1,32 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to you under the Apache License, Version
+ 2.0 (the "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0 Unless required by
+ applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+ CONDITIONS OF ANY KIND, either express or implied. See the License for
+ the specific language governing permissions and limitations under the
+ License.
+-->
+<lifecycleMappingMetadata>
+ <pluginExecutions>
+ <pluginExecution>
+ <pluginExecutionFilter>
+ <goals>
+ <goal>cgen</goal>
+ </goals>
+ </pluginExecutionFilter>
+ <action>
+ <execute>
+ <runOnIncremental>true</runOnIncremental>
+ <runOnConfiguration>true</runOnConfiguration>
+ </execute>
+ </action>
+ </pluginExecution>
+ </pluginExecutions>
+</lifecycleMappingMetadata>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cayenne/blob/2cddff91/plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java
----------------------------------------------------------------------
diff --git a/plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java b/plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java
new file mode 100644
index 0000000..734e93c
--- /dev/null
+++ b/plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/CayenneGeneratorMojoTest.java
@@ -0,0 +1,78 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+package org.apache.cayenne.tools;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+
+import java.io.File;
+
+public class CayenneGeneratorMojoTest extends AbstractMojoTestCase {
+
+ public void testCgenExecution() throws Exception {
+
+ File pom = getTestFile("src/test/resources/cgen/project-to-test/pom.xml");
+ assertNotNull(pom);
+ assertTrue(pom.exists());
+
+ CayenneGeneratorMojo myMojo = (CayenneGeneratorMojo) lookupMojo("cgen",
+ pom);
+ assertNotNull(myMojo);
+ myMojo.execute();
+
+ File superTestEntity = new File(
+ "target/cayenneGeneratedClasses/superPkg/_TestEntity.txt");
+ File testEntity = new File(
+ "target/cayenneGeneratedClasses/pack/TestEntity.txt");
+
+ File superEmbeddable = new File(
+ "target/cayenneGeneratedClasses/superPkg/_Embeddable.txt");
+ File embeddable = new File(
+ "target/cayenneGeneratedClasses/pack/Embeddable.txt");
+
+ File superNotIncludedEntity = new File(
+ "target/cayenneGeneratedClasses/pack/_NotIncludedEntity.txt");
+
+ File notIncludedEntity = new File(
+ "target/cayenneGeneratedClasses/pack/NotIncludedEntity.txt");
+
+ File superExcludedEntity = new File(
+ "target/cayenneGeneratedClasses/pack/_TestExcludedEntity.txt");
+ File excludedEntity = new File(
+ "target/cayenneGeneratedClasses/pack/TestExcludedEntity.txt");
+
+ assertTrue(superTestEntity.exists());
+ assertTrue(testEntity.exists());
+
+ assertTrue(superEmbeddable.exists());
+ assertTrue(embeddable.exists());
+
+ assertFalse(superNotIncludedEntity.exists());
+ assertFalse(notIncludedEntity.exists());
+
+ assertFalse(superExcludedEntity.exists());
+ assertFalse(excludedEntity.exists());
+
+ String content = FileUtils.readFileToString(superTestEntity);
+ assertTrue(content.contains("public static final Property<List<TestRelEntity>> ADDITIONAL_REL = Property.create(\"additionalRel\", List.class);"));
+ assertTrue(content.contains("public void addToAdditionalRel(TestRelEntity obj)"));
+ assertTrue(content.contains("public void removeFromAdditionalRel(TestRelEntity obj)"));
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/2cddff91/plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoConfigurationTest.java
----------------------------------------------------------------------
diff --git a/plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoConfigurationTest.java b/plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoConfigurationTest.java
new file mode 100644
index 0000000..5b871f6
--- /dev/null
+++ b/plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoConfigurationTest.java
@@ -0,0 +1,125 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+package org.apache.cayenne.tools;
+
+import org.apache.cayenne.dbimport.Catalog;
+import org.apache.cayenne.dbimport.Schema;
+import org.apache.cayenne.dbsync.reverse.filters.FiltersConfig;
+import org.apache.cayenne.dbsync.reverse.filters.IncludeTableFilter;
+import org.apache.cayenne.dbsync.reverse.filters.PatternFilter;
+import org.apache.cayenne.dbsync.reverse.filters.TableFilter;
+import org.apache.cayenne.tools.dbimport.DbImportConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.regex.Pattern;
+
+import static org.apache.cayenne.dbimport.DefaultReverseEngineeringLoaderTest.assertCatalog;
+import static org.apache.cayenne.dbimport.DefaultReverseEngineeringLoaderTest.assertCatalogAndSchema;
+import static org.apache.cayenne.dbimport.DefaultReverseEngineeringLoaderTest.assertFlat;
+import static org.apache.cayenne.dbimport.DefaultReverseEngineeringLoaderTest.assertSchemaContent;
+import static org.apache.cayenne.dbimport.DefaultReverseEngineeringLoaderTest.assertSkipPrimaryKeyLoading;
+import static org.apache.cayenne.dbimport.DefaultReverseEngineeringLoaderTest.assertSkipRelationshipsLoading;
+import static org.apache.cayenne.dbimport.DefaultReverseEngineeringLoaderTest.assertTableTypes;
+import static org.mockito.Mockito.mock;
+
+public class DbImporterMojoConfigurationTest extends AbstractMojoTestCase {
+
+ @Test
+ public void testLoadCatalog() throws Exception {
+ Map<String, Catalog> catalogs = new HashMap<>();
+ for (Catalog c : getCdbImport("pom-catalog.xml").getReverseEngineering().getCatalogs()) {
+ catalogs.put(c.getName(), c);
+ }
+
+ assertEquals(3, catalogs.size());
+ Catalog c3 = catalogs.get("catalog-name-03");
+ assertNotNull(c3);
+ assertCatalog(c3);
+ }
+
+ @Test
+ public void testLoadSchema() throws Exception {
+ Map<String, Schema> schemas = new HashMap<>();
+ for (Schema s : getCdbImport("pom-schema.xml").getReverseEngineering().getSchemas()) {
+ schemas.put(s.getName(), s);
+ }
+
+ assertEquals(3, schemas.size());
+ Schema s3 = schemas.get("schema-name-03");
+ assertNotNull(s3);
+ assertSchemaContent(s3);
+ }
+
+ @Test
+ public void testLoadSchema2() throws Exception {
+ FiltersConfig filters = getCdbImport("pom-schema-2.xml").createConfig(mock(Log.class))
+ .getDbLoaderConfig().getFiltersConfig();
+
+ TreeSet<IncludeTableFilter> includes = new TreeSet<>();
+ includes.add(new IncludeTableFilter(null, new PatternFilter().exclude("^ETL_.*")));
+
+ TreeSet<Pattern> excludes = new TreeSet<>(PatternFilter.PATTERN_COMPARATOR);
+ excludes.add(PatternFilter.pattern("^ETL_.*"));
+
+ assertEquals(filters.tableFilter(null, "NHL_STATS"),
+ new TableFilter(includes, excludes));
+ }
+
+ @Test
+ public void testLoadCatalogAndSchema() throws Exception {
+ assertCatalogAndSchema(getCdbImport("pom-catalog-and-schema.xml").getReverseEngineering());
+ }
+
+ @Test
+ public void testDefaultPackage() throws Exception {
+ DbImportConfiguration config = getCdbImport("pom-default-package.xml").createConfig(mock(Log.class));
+ assertEquals("com.example.test", config.getDefaultPackage());
+ }
+
+ @Test
+ public void testLoadFlat() throws Exception {
+ assertFlat(getCdbImport("pom-flat.xml").getReverseEngineering());
+ }
+
+ @Test
+ public void testSkipRelationshipsLoading() throws Exception {
+ assertSkipRelationshipsLoading(getCdbImport("pom-skip-relationships-loading.xml").getReverseEngineering());
+ }
+
+ @Test
+ public void testSkipPrimaryKeyLoading() throws Exception {
+ assertSkipPrimaryKeyLoading(getCdbImport("pom-skip-primary-key-loading.xml").getReverseEngineering());
+ }
+
+ @Test
+ public void testTableTypes() throws Exception {
+ assertTableTypes(getCdbImport("pom-table-types.xml").getReverseEngineering());
+ }
+
+ private DbImporterMojo getCdbImport(String pomFileName) throws Exception {
+ return (DbImporterMojo) lookupMojo("cdbimport",
+ getTestFile("src/test/resources/org/apache/cayenne/tools/config/" + pomFileName));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/2cddff91/plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
----------------------------------------------------------------------
diff --git a/plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java b/plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
new file mode 100644
index 0000000..7d8cbfe
--- /dev/null
+++ b/plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/DbImporterMojoTest.java
@@ -0,0 +1,431 @@
+/*****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ****************************************************************/
+package org.apache.cayenne.tools;
+
+import org.apache.cayenne.dbimport.Catalog;
+import org.apache.cayenne.dbimport.IncludeTable;
+import org.apache.cayenne.dbimport.Schema;
+import org.apache.cayenne.test.jdbc.SQLReader;
+import org.apache.cayenne.test.resource.ResourceUtil;
+import org.apache.cayenne.tools.dbimport.DbImportConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.testing.AbstractMojoTestCase;
+import org.codehaus.plexus.util.FileUtils;
+import org.custommonkey.xmlunit.DetailedDiff;
+import org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.ElementNameAndAttributeQualifier;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.URL;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Iterator;
+import java.util.Objects;
+
+import static org.apache.commons.lang.StringUtils.isBlank;
+import static org.mockito.Mockito.mock;
+
+
+public class DbImporterMojoTest extends AbstractMojoTestCase {
+
+ private static DerbyManager derbyAssembly;
+
+ static {
+ XMLUnit.setIgnoreWhitespace(true);
+ }
+
+ @BeforeClass
+ public static void beforeClass() throws IOException, SQLException {
+ derbyAssembly = new DerbyManager("target/derby");
+ }
+
+ @AfterClass
+ public static void afterClass() throws IOException, SQLException {
+ derbyAssembly.shutdown();
+ derbyAssembly = null;
+ }
+
+ @Test
+ public void testToParameters_MeaningfulPkTables() throws Exception {
+
+ DbImportConfiguration parameters1 = getCdbImport("dbimporter-pom1.xml").createConfig(mock(Log.class));
+ assertNull(parameters1.getMeaningfulPkTables());
+ assertPathEquals("target/test/org/apache/cayenne/tools/dbimporter-map1.map.xml", parameters1.getTargetDataMap()
+ .getPath());
+
+ assertEquals("x,b*", getCdbImport("dbimporter-pom2.xml").createConfig(mock(Log.class)).getMeaningfulPkTables());
+ assertEquals("*", getCdbImport("dbimporter-pom3.xml").createConfig(mock(Log.class)).getMeaningfulPkTables());
+ }
+
+ public void testToParameters_Map() throws Exception {
+
+ DbImportConfiguration parameters1 = getCdbImport("dbimporter-pom1.xml").createConfig(mock(Log.class));
+ assertNotNull(parameters1.getTargetDataMap());
+ assertPathEquals("target/test/org/apache/cayenne/tools/dbimporter-map1.map.xml", parameters1.getTargetDataMap()
+ .getPath());
+
+ assertNull(getCdbImport("dbimporter-pom2.xml").createConfig(mock(Log.class)).getTargetDataMap());
+ }
+
+ private DbImporterMojo getCdbImport(String pomFileName) throws Exception {
+ return (DbImporterMojo) lookupMojo("cdbimport",
+ getTestFile("src/test/resources/org/apache/cayenne/tools/" + pomFileName));
+ }
+
+ private void assertPathEquals(String expectedPath, String actualPath) {
+ assertEquals(new File(expectedPath), new File(actualPath));
+ }
+
+ @Test
+ public void testImportNewDataMap() throws Exception {
+ test("testImportNewDataMap");
+ }
+
+ @Test
+ public void testImportWithoutChanges() throws Exception {
+ test("testImportWithoutChanges");
+ }
+
+ @Test
+ public void testImportAddTableAndColumn() throws Exception {
+ test("testImportAddTableAndColumn");
+ }
+
+ @Test
+ public void testFilteringWithSchema() throws Exception {
+ test("testFilteringWithSchema");
+ }
+
+ @Test
+ public void testSchemasAndTableExclude() throws Exception {
+ test("testSchemasAndTableExclude");
+ }
+
+ @Test
+ public void testViewsExclude() throws Exception {
+ test("testViewsExclude");
+ }
+
+ @Test
+ public void testTableTypes() throws Exception {
+ test("testTableTypes");
+ }
+
+ @Test
+ public void testDefaultPackage() throws Exception {
+ test("testDefaultPackage");
+ }
+
+ @Test
+ public void testSkipRelationshipsLoading() throws Exception {
+ test("testSkipRelationshipsLoading");
+ }
+
+ @Test
+ public void testSkipPrimaryKeyLoading() throws Exception {
+ test("testSkipPrimaryKeyLoading");
+ }
+
+ @Test
+ public void testOneToOne() throws Exception {
+ test("testOneToOne");
+ }
+
+ /**
+ * Q: what happens if an attribute or relationship is unmapped in the object layer, but then the underlying table
+ * changes.
+ * A: it should not recreate unmapped attributes/relationships. Only add an attribute for the new column.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testPreserveCustomObjMappings() throws Exception {
+ test("testPreserveCustomObjMappings");
+ }
+
+ /**
+ * Q: what happens if a relationship existed over a column that was later deleted? and \u2018skipRelLoading\u2019 is true
+ * A: it should remove relationship and column
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testPreserveRelationships() throws Exception {
+ test("testPreserveRelationships");
+ }
+
+ /**
+ * By default many-to-many are flattened during reverse engineering.
+ * But if a user un-flattens a given N:M manually, we\u2019d like this choice to be preserved on the next run
+ */
+ @Test
+ public void testUnFlattensManyToMany() throws Exception {
+ // TODO: this should be "xYs" : <db-relationship name="xIes"
+ test("testUnFlattensManyToMany");
+ }
+
+ /**
+ * Make sure any merges preserve custom object layer settings, like "usePrimitives", PK mapping as attribute, etc.
+ */
+ @Test
+ public void testCustomObjectLayerSettings() throws Exception {
+ test("testCustomObjectLayerSettings");
+ }
+
+ @Test
+ public void testDbAttributeChange() throws Exception {
+ test("testDbAttributeChange");
+ }
+
+ @Test
+ public void testForceDataMapSchema() throws Exception {
+ test("testForceDataMapSchema");
+ }
+
+ @Test
+ public void testComplexChangeOrder() throws Exception {
+ test("testComplexChangeOrder");
+ }
+
+ /**
+ * CREATE TABLE APP.A (
+ * id INTEGER NOT NULL,
+ * <p>
+ * PRIMARY KEY (id)
+ * );
+ * <p>
+ * CREATE TABLE APP.A_A (
+ * A1_ID INTEGER NOT NULL,
+ * A2_ID INTEGER NOT NULL,
+ * <p>
+ * PRIMARY KEY (A1_ID, A2_ID),
+ * CONSTRAINT A_A1 FOREIGN KEY (A1_ID) REFERENCES APP.A (ID),
+ * CONSTRAINT A_A2 FOREIGN KEY (A2_ID) REFERENCES APP.A (ID)
+ * );
+ * <p>
+ * If one table has many-to-many relationship with it self ObjEntity should have two
+ * collection attributes in both directions
+ *
+ * @throws Exception
+ */
+ @Test
+ @Ignore("Investigate why on different environment entity relationships order are different.")
+ public void te_stFlattensManyToManyWithRecursiveLink() throws Exception {
+ test("testFlattensManyToManyWithRecursiveLink");
+ }
+
+ @Test
+ public void testFkAttributeRename() throws Exception {
+ test("testFkAttributeRename");
+ }
+
+ @Test
+ public void testFilteringConfig() throws Exception {
+ DbImporterMojo cdbImport = getCdbImport("config/pom-01.xml");
+
+ assertEquals(2, cdbImport.getReverseEngineering().getCatalogs().size());
+ Iterator<Catalog> iterator = cdbImport.getReverseEngineering().getCatalogs().iterator();
+ assertEquals("catalog-name-01", iterator.next().getName());
+
+ Catalog catalog = iterator.next();
+ assertEquals("catalog-name-02", catalog.getName());
+ Iterator<Schema> schemaIterator = catalog.getSchemas().iterator();
+
+ assertEquals("schema-name-01", schemaIterator.next().getName());
+
+ Schema schema = schemaIterator.next();
+ assertEquals("schema-name-02", schema.getName());
+
+ Iterator<IncludeTable> includeTableIterator = schema.getIncludeTables().iterator();
+ assertEquals("incTable-01", includeTableIterator.next().getPattern());
+
+ IncludeTable includeTable = includeTableIterator.next();
+ assertEquals("incTable-02", includeTable.getPattern());
+ assertEquals("includeColumn-01", includeTable.getIncludeColumns().iterator().next().getPattern());
+ assertEquals("excludeColumn-01", includeTable.getExcludeColumns().iterator().next().getPattern());
+
+ assertEquals("includeColumn-02", schema.getIncludeColumns().iterator().next().getPattern());
+ assertEquals("excludeColumn-02", schema.getExcludeColumns().iterator().next().getPattern());
+
+ assertEquals("includeColumn-03", catalog.getIncludeColumns().iterator().next().getPattern());
+ assertEquals("excludeColumn-03", catalog.getExcludeColumns().iterator().next().getPattern());
+
+ schemaIterator = cdbImport.getReverseEngineering().getSchemas().iterator();
+ schema = schemaIterator.next();
+ assertEquals("schema-name-03", schema.getName());
+
+ schema = schemaIterator.next();
+ assertEquals("schema-name-04", schema.getName());
+
+ includeTableIterator = schema.getIncludeTables().iterator();
+ assertEquals("incTable-04", includeTableIterator.next().getPattern());
+ assertEquals("excTable-04", schema.getExcludeTables().iterator().next().getPattern());
+
+ includeTable = includeTableIterator.next();
+ assertEquals("incTable-05", includeTable.getPattern());
+ assertEquals("includeColumn-04", includeTable.getIncludeColumns().iterator().next().getPattern());
+ assertEquals("excludeColumn-04", includeTable.getExcludeColumns().iterator().next().getPattern());
+
+ assertEquals("includeColumn-04", schema.getIncludeColumns().iterator().next().getPattern());
+ assertEquals("excludeColumn-04", schema.getExcludeColumns().iterator().next().getPattern());
+
+ assertEquals("includeColumn-03", catalog.getIncludeColumns().iterator().next().getPattern());
+ assertEquals("excludeColumn-03", catalog.getExcludeColumns().iterator().next().getPattern());
+ }
+
+ @Test
+ public void testSupportsCatalogsOnReverseEngineering() throws Exception {
+ DbImporterMojo cdbImport = getCdbImport("dbimport/testSupportsCatalogsOnReverseEngineering-pom.xml");
+ cdbImport.getReverseEngineering().addCatalog(new Catalog("DbImporterMojoTest2"));
+
+ Exception exceptedException = null;
+ String exceptedMessage = "Your database does not support catalogs on reverse engineering. " +
+ "It allows to connect to only one at the moment. Please don't note catalogs in <dbimport> configuration.";
+
+ try {
+ cdbImport.execute();
+ } catch (MojoExecutionException ex) {
+ exceptedException = ex;
+ }
+
+ assertNotNull(exceptedException);
+ assertEquals(exceptedMessage, exceptedException.getCause().getMessage());
+ }
+
+ private void test(String name) throws Exception {
+ DbImporterMojo cdbImport = getCdbImport("dbimport/" + name + "-pom.xml");
+ File mapFile = cdbImport.getMap();
+ File mapFileCopy = new File(mapFile.getParentFile(), "copy-" + mapFile.getName());
+ if (mapFile.exists()) {
+ FileUtils.copyFile(mapFile, mapFileCopy);
+ cdbImport.setMap(mapFileCopy);
+ } else {
+ mapFileCopy = mapFile;
+ }
+
+ DbImportConfiguration parameters = cdbImport.createConfig(mock(Log.class));
+ prepareDatabase(name, parameters);
+
+ try {
+ cdbImport.execute();
+ verifyResult(mapFile, mapFileCopy);
+ } finally {
+ cleanDb(parameters);
+ }
+ }
+
+ private void cleanDb(DbImportConfiguration dbImportConfiguration) throws Exception {
+
+ // TODO: refactor to common DB management code... E.g. bootique-jdbc-test?
+ // TODO: with in-memory Derby, it is easier to just stop and delete the database.. again see bootique-jdbc-test
+
+ Class.forName(dbImportConfiguration.getDriver()).newInstance();
+
+ try (Connection connection = DriverManager.getConnection(dbImportConfiguration.getUrl())) {
+
+ try (Statement stmt = connection.createStatement()) {
+
+ try (ResultSet views = connection.getMetaData().getTables(null, null, null, new String[]{"VIEW"})) {
+ while (views.next()) {
+ String schema = views.getString("TABLE_SCHEM");
+ execute(stmt, "DROP VIEW " + (isBlank(schema) ? "" : schema + ".") + views.getString("TABLE_NAME"));
+ }
+ }
+
+ try (ResultSet tables = connection.getMetaData().getTables(null, null, null, new String[]{"TABLE"})) {
+ while (tables.next()) {
+ String schema = tables.getString("TABLE_SCHEM");
+ String tableName = tables.getString("TABLE_NAME");
+ String tableNameFull = (isBlank(schema) ? "" : schema + ".") + tableName;
+
+ ResultSet keys = connection.getMetaData().getExportedKeys(null, schema, tableName);
+ while (keys.next()) {
+ String fkTableSchem = keys.getString("FKTABLE_SCHEM");
+ String fkTableName = keys.getString("FKTABLE_NAME");
+ String fkTableNameFull = (isBlank(fkTableSchem) ? "" : fkTableSchem + ".") + fkTableName;
+ execute(stmt, "ALTER TABLE " + fkTableNameFull + " DROP CONSTRAINT " + keys.getString("FK_NAME"));
+ }
+
+ String sql = "DROP TABLE " + tableNameFull;
+ execute(stmt, sql);
+ }
+ }
+
+ try (ResultSet schemas = connection.getMetaData().getSchemas()) {
+ while (schemas.next()) {
+ String schem = schemas.getString("TABLE_SCHEM");
+ if (schem.startsWith("SCHEMA")) {
+ execute(stmt, "DROP SCHEMA " + schem + " RESTRICT");
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private void execute(Statement stmt, String sql) throws SQLException {
+ stmt.execute(sql);
+ }
+
+ private void verifyResult(File map, File mapFileCopy) {
+ try {
+ FileReader control = new FileReader(map.getAbsolutePath() + "-result");
+ FileReader test = new FileReader(mapFileCopy);
+
+ Diff prototype = new Diff(control, test);
+ prototype.overrideElementQualifier(new ElementNameAndAttributeQualifier());
+ DetailedDiff diff = new DetailedDiff(prototype);
+
+ if (!diff.similar()) {
+ fail(diff.toString());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ private void prepareDatabase(String sqlFile, DbImportConfiguration dbImportConfiguration) throws Exception {
+
+ URL sqlUrl = Objects.requireNonNull(ResourceUtil.getResource(getClass(), "dbimport/" + sqlFile + ".sql"));
+
+ // TODO: refactor to common DB management code... E.g. bootique-jdbc-test?
+
+ Class.forName(dbImportConfiguration.getDriver()).newInstance();
+
+ try (Connection connection = DriverManager.getConnection(dbImportConfiguration.getUrl())) {
+ try (Statement stmt = connection.createStatement();) {
+ for (String sql : SQLReader.statements(sqlUrl, ";")) {
+ stmt.execute(sql);
+ }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/2cddff91/plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/DerbyManager.java
----------------------------------------------------------------------
diff --git a/plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/DerbyManager.java b/plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/DerbyManager.java
new file mode 100644
index 0000000..82faace
--- /dev/null
+++ b/plugins/cayenne-maven-plugin/src/test/java/org/apache/cayenne/tools/DerbyManager.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cayenne.tools;
+
+/**
+ * @since 4.0
+ */
+
+import org.apache.commons.io.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+public class DerbyManager {
+
+ public static final OutputStream DEV_NULL = new OutputStream() {
+
+ @Override
+ public void write(int b) {
+ }
+ };
+
+ DerbyManager(String location) {
+
+ System.setProperty("derby.stream.error.field", DerbyManager.class.getName() + ".DEV_NULL");
+
+ File derbyDir = new File(location);
+ if (derbyDir.isDirectory()) {
+ try {
+ FileUtils.deleteDirectory(derbyDir);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ void shutdown() {
+ try {
+ DriverManager.getConnection("jdbc:derby:;shutdown=true");
+ } catch (SQLException e) {
+ // the exception is actually expected on shutdown... go figure...
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/2cddff91/plugins/cayenne-maven-plugin/src/test/resources/cgen/cayenne-testDomain.xml
----------------------------------------------------------------------
diff --git a/plugins/cayenne-maven-plugin/src/test/resources/cgen/cayenne-testDomain.xml b/plugins/cayenne-maven-plugin/src/test/resources/cgen/cayenne-testDomain.xml
new file mode 100644
index 0000000..3f63c14
--- /dev/null
+++ b/plugins/cayenne-maven-plugin/src/test/resources/cgen/cayenne-testDomain.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<domain project-version="6">
+ <map name="testDomainMap"/>
+ <map name="testAdditionalMap"/>
+</domain>
http://git-wip-us.apache.org/repos/asf/cayenne/blob/2cddff91/plugins/cayenne-maven-plugin/src/test/resources/cgen/project-to-test/pom.xml
----------------------------------------------------------------------
diff --git a/plugins/cayenne-maven-plugin/src/test/resources/cgen/project-to-test/pom.xml b/plugins/cayenne-maven-plugin/src/test/resources/cgen/project-to-test/pom.xml
new file mode 100644
index 0000000..41d545c
--- /dev/null
+++ b/plugins/cayenne-maven-plugin/src/test/resources/cgen/project-to-test/pom.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <name>Test CayenneGeneratorMojo</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-cayenne-plugin</artifactId>
+ <configuration>
+ <map>src/test/resources/cgen/testDomainMap.map.xml</map>
+ <destDir>target/cayenneGeneratedClasses</destDir>
+ <additionalMaps>src/test/resources/cgen/</additionalMaps>
+ <outputPattern>*.txt</outputPattern>
+ <makePairs>true</makePairs>
+ <usePkgPath>true</usePkgPath>
+ <superPkg>superPkg</superPkg>
+ <encoding>UTF-8</encoding>
+ <includeEntities>Test*</includeEntities>
+ <excludeEntities>TestExcludedEntity</excludeEntities>
+ <mode>all</mode>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/cayenne/blob/2cddff91/plugins/cayenne-maven-plugin/src/test/resources/cgen/testAdditionalMap.map.xml
----------------------------------------------------------------------
diff --git a/plugins/cayenne-maven-plugin/src/test/resources/cgen/testAdditionalMap.map.xml b/plugins/cayenne-maven-plugin/src/test/resources/cgen/testAdditionalMap.map.xml
new file mode 100644
index 0000000..f9a80fb
--- /dev/null
+++ b/plugins/cayenne-maven-plugin/src/test/resources/cgen/testAdditionalMap.map.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap http://cayenne.apache.org/schema/3.0/modelMap.xsd"
+ project-version="6">
+ <property name="defaultPackage" value="pack"/>
+ <db-entity name="TestRelEntity">
+ <db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
+ <db-attribute name="NAME" type="VARCHAR" length="200"/>
+ </db-entity>
+ <obj-entity name="TestRelEntity" className="pack.TestRelEntity" dbEntityName="TestRelEntity">
+ <obj-attribute name="name" type="java.lang.String" db-attribute-path="NAME"/>
+ </obj-entity>
+ <db-relationship name="additionalRel" source="TestRelEntity" target="TestEntity" toMany="false">
+ <db-attribute-pair source="ID" target="TestRelEntity_ID"/>
+ </db-relationship>
+ <obj-relationship name="additionalRel" source="TestRelEntity" target="TestEntity" deleteRule="Nullify" db-relationship-path="additionalRel"/>
+</data-map>
\ No newline at end of file