CAY-2166 Auto-loading of Cayenne modules * auto-loading ProjectModule
Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/f6a58d68 Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/f6a58d68 Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/f6a58d68 Branch: refs/heads/master Commit: f6a58d6873979db2543da648929e9b62ecc3e114 Parents: 4e90ad4 Author: Andrus Adamchik <and...@objectstyle.com> Authored: Sun Dec 11 17:05:33 2016 +0300 Committer: Andrus Adamchik <and...@objectstyle.com> Committed: Sun Dec 11 21:27:29 2016 +0300 ---------------------------------------------------------------------- cayenne-project/pom.xml | 124 +++++++++++-------- .../cayenne/project/CayenneProjectModule.java | 55 +++----- .../apache/cayenne/project/ProjectModule.java | 44 +++++++ .../cayenne/project/ProjectModuleProvider.java | 46 +++++++ .../org.apache.cayenne.di.spi.ModuleProvider | 1 + .../project/ProjectModuleProviderTest.java | 30 +++++ docs/doc/src/main/resources/RELEASE-NOTES.txt | 1 + docs/doc/src/main/resources/UPGRADE.txt | 4 +- .../java/org/apache/cayenne/modeler/Main.java | 9 +- 9 files changed, 225 insertions(+), 89 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cayenne/blob/f6a58d68/cayenne-project/pom.xml ---------------------------------------------------------------------- diff --git a/cayenne-project/pom.xml b/cayenne-project/pom.xml index 2452cdb..4c2174c 100644 --- a/cayenne-project/pom.xml +++ b/cayenne-project/pom.xml @@ -1,62 +1,88 @@ <?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 +<!-- + 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"> + 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"> - <modelVersion>4.0.0</modelVersion> + <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.cayenne</groupId> - <artifactId>cayenne-parent</artifactId> - <version>4.0.M5-SNAPSHOT</version> - </parent> + <parent> + <groupId>org.apache.cayenne</groupId> + <artifactId>cayenne-parent</artifactId> + <version>4.0.M5-SNAPSHOT</version> + </parent> - <artifactId>cayenne-project</artifactId> - <name>cayenne-project: Cayenne Project</name> - <packaging>jar</packaging> + <artifactId>cayenne-project</artifactId> + <name>cayenne-project: Cayenne Project</name> + <packaging>jar</packaging> - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> + <dependencies> + <!-- Compile dependencies --> + <dependency> + <groupId>org.apache.cayenne</groupId> + <artifactId>cayenne-di</artifactId> + <version>${project.version}</version> + </dependency> - <dependency> - <groupId>org.apache.cayenne.build-tools</groupId> - <artifactId>cayenne-test-utilities</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> + <dependency> + <groupId>org.apache.cayenne</groupId> + <artifactId>cayenne-server</artifactId> + <version>${project.version}</version> + </dependency> - <dependency> - <groupId>org.apache.cayenne</groupId> - <artifactId>cayenne-di</artifactId> - <version>${project.version}</version> - </dependency> + <!-- Test dependencies --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.cayenne</groupId> + <artifactId>cayenne-server</artifactId> + <version>${project.version}</version> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.cayenne.build-tools</groupId> + <artifactId>cayenne-test-utilities</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <scope>test</scope> + </dependency> - <dependency> - <groupId>org.apache.cayenne</groupId> - <artifactId>cayenne-server</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> + </dependencies> - <build> - <plugins> - <!-- This ensures LICESNE and NOTICE inclusion in all jars --> + <build> + <plugins> + <!-- This ensures LICESNE and NOTICE inclusion in all jars --> <plugin> <artifactId>maven-remote-resources-plugin</artifactId> <executions> http://git-wip-us.apache.org/repos/asf/cayenne/blob/f6a58d68/cayenne-project/src/main/java/org/apache/cayenne/project/CayenneProjectModule.java ---------------------------------------------------------------------- diff --git a/cayenne-project/src/main/java/org/apache/cayenne/project/CayenneProjectModule.java b/cayenne-project/src/main/java/org/apache/cayenne/project/CayenneProjectModule.java index 6f31b9c..6642638 100644 --- a/cayenne-project/src/main/java/org/apache/cayenne/project/CayenneProjectModule.java +++ b/cayenne-project/src/main/java/org/apache/cayenne/project/CayenneProjectModule.java @@ -1,44 +1,27 @@ -/***************************************************************** - * 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 +/* + * 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 + * 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. - ****************************************************************/ + * 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.project; -import org.apache.cayenne.di.Binder; -import org.apache.cayenne.di.Module; -import org.apache.cayenne.project.upgrade.ProjectUpgrader; -import org.apache.cayenne.project.upgrade.v9.ProjectUpgrader_V9; -import org.apache.cayenne.project.validation.DefaultProjectValidator; -import org.apache.cayenne.project.validation.ProjectValidator; - /** - * A dependency injection (DI) module contributing configuration related to Cayenne - * mapping project manipulation to a DI container. - * * @since 3.1 + * @deprecated since 4.0 renamed to {@link ProjectModule}. */ -public class CayenneProjectModule implements Module { - - public void configure(Binder binder) { - binder.bind(ProjectLoader.class).to(DataChannelProjectLoader.class); - binder.bind(ProjectSaver.class).to(FileProjectSaver.class); - binder.bind(ProjectUpgrader.class).to(ProjectUpgrader_V9.class); - binder.bind(ProjectValidator.class).to(DefaultProjectValidator.class); - binder.bind(ConfigurationNodeParentGetter.class).to( - DefaultConfigurationNodeParentGetter.class); - } +@Deprecated +public class CayenneProjectModule extends ProjectModule { } http://git-wip-us.apache.org/repos/asf/cayenne/blob/f6a58d68/cayenne-project/src/main/java/org/apache/cayenne/project/ProjectModule.java ---------------------------------------------------------------------- diff --git a/cayenne-project/src/main/java/org/apache/cayenne/project/ProjectModule.java b/cayenne-project/src/main/java/org/apache/cayenne/project/ProjectModule.java new file mode 100644 index 0000000..a1eeb98 --- /dev/null +++ b/cayenne-project/src/main/java/org/apache/cayenne/project/ProjectModule.java @@ -0,0 +1,44 @@ +/***************************************************************** + * 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.project; + +import org.apache.cayenne.di.Binder; +import org.apache.cayenne.di.Module; +import org.apache.cayenne.project.upgrade.ProjectUpgrader; +import org.apache.cayenne.project.upgrade.v9.ProjectUpgrader_V9; +import org.apache.cayenne.project.validation.DefaultProjectValidator; +import org.apache.cayenne.project.validation.ProjectValidator; + +/** + * A dependency injection (DI) module contributing configuration related to Cayenne mapping project manipulation to a + * DI container. + * + * @since 4.0 + */ +public class ProjectModule implements Module { + + public void configure(Binder binder) { + binder.bind(ProjectLoader.class).to(DataChannelProjectLoader.class); + binder.bind(ProjectSaver.class).to(FileProjectSaver.class); + binder.bind(ProjectUpgrader.class).to(ProjectUpgrader_V9.class); + binder.bind(ProjectValidator.class).to(DefaultProjectValidator.class); + binder.bind(ConfigurationNodeParentGetter.class).to( + DefaultConfigurationNodeParentGetter.class); + } +} http://git-wip-us.apache.org/repos/asf/cayenne/blob/f6a58d68/cayenne-project/src/main/java/org/apache/cayenne/project/ProjectModuleProvider.java ---------------------------------------------------------------------- diff --git a/cayenne-project/src/main/java/org/apache/cayenne/project/ProjectModuleProvider.java b/cayenne-project/src/main/java/org/apache/cayenne/project/ProjectModuleProvider.java new file mode 100644 index 0000000..b5ae42b --- /dev/null +++ b/cayenne-project/src/main/java/org/apache/cayenne/project/ProjectModuleProvider.java @@ -0,0 +1,46 @@ +/* + * 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.project; + +import org.apache.cayenne.di.Module; +import org.apache.cayenne.di.spi.ModuleProvider; + +import java.util.Collection; +import java.util.Collections; + +/** + * @since 4.0 + */ +public class ProjectModuleProvider implements ModuleProvider { + + @Override + public Module module() { + return new ProjectModule(); + } + + @Override + public Class<? extends Module> moduleType() { + return ProjectModule.class; + } + + @Override + public Collection<Class<? extends Module>> overrides() { + return Collections.emptyList(); + } +} http://git-wip-us.apache.org/repos/asf/cayenne/blob/f6a58d68/cayenne-project/src/main/resources/META-INF/services/org.apache.cayenne.di.spi.ModuleProvider ---------------------------------------------------------------------- diff --git a/cayenne-project/src/main/resources/META-INF/services/org.apache.cayenne.di.spi.ModuleProvider b/cayenne-project/src/main/resources/META-INF/services/org.apache.cayenne.di.spi.ModuleProvider new file mode 100644 index 0000000..0d402c1 --- /dev/null +++ b/cayenne-project/src/main/resources/META-INF/services/org.apache.cayenne.di.spi.ModuleProvider @@ -0,0 +1 @@ +org.apache.cayenne.project.ProjectModuleProvider \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cayenne/blob/f6a58d68/cayenne-project/src/test/java/org/apache/cayenne/project/ProjectModuleProviderTest.java ---------------------------------------------------------------------- diff --git a/cayenne-project/src/test/java/org/apache/cayenne/project/ProjectModuleProviderTest.java b/cayenne-project/src/test/java/org/apache/cayenne/project/ProjectModuleProviderTest.java new file mode 100644 index 0000000..957e14c --- /dev/null +++ b/cayenne-project/src/test/java/org/apache/cayenne/project/ProjectModuleProviderTest.java @@ -0,0 +1,30 @@ +/* + * 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.project; + +import org.apache.cayenne.unit.util.ModuleProviderChecker; +import org.junit.Test; + +public class ProjectModuleProviderTest { + + @Test + public void testProviderPresent() { + ModuleProviderChecker.testProviderPresent(ProjectModuleProvider.class); + } +} http://git-wip-us.apache.org/repos/asf/cayenne/blob/f6a58d68/docs/doc/src/main/resources/RELEASE-NOTES.txt ---------------------------------------------------------------------- diff --git a/docs/doc/src/main/resources/RELEASE-NOTES.txt b/docs/doc/src/main/resources/RELEASE-NOTES.txt index d3a7af0..2e70762 100644 --- a/docs/doc/src/main/resources/RELEASE-NOTES.txt +++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt @@ -16,6 +16,7 @@ Changes/New Features: CAY-2163 Property.path() , ExpressionFactory.pathExp() CAY-2164 Relocate builder bootstrap methods from ServerRuntimeBuilder to ServerRuntime CAY-2165 Explicit "contribution" API for easier expansion of DI collections and maps +CAY-2166 Auto-loading of Cayenne modules Bug Fixes: http://git-wip-us.apache.org/repos/asf/cayenne/blob/f6a58d68/docs/doc/src/main/resources/UPGRADE.txt ---------------------------------------------------------------------- diff --git a/docs/doc/src/main/resources/UPGRADE.txt b/docs/doc/src/main/resources/UPGRADE.txt index 06be221..627e4d2 100644 --- a/docs/doc/src/main/resources/UPGRADE.txt +++ b/docs/doc/src/main/resources/UPGRADE.txt @@ -13,8 +13,8 @@ UPGRADING TO 4.0.M5 invoked explicitly when the stack assembly is performed, while modules can be written without any knowledge of the final stack. - Module Renaming and Explicit Loading of Modules. If you see compile errors (class not found for CayenneJodaModule, - CayenneJava8Module), just remove explicit loading of those modules. They will be autoloade if they are on classpath. - If you explicitly turned off auto-loading, use the new names for these modules: JodaModule and Java8Module. + CayenneJava8Module), just remove explicit loading of those modules. They will be auto-loaded if they are on classpath. + If you explicitly turn off auto-loading, use the new names for these modules: JodaModule and Java8Module. * Per CAY-2164, creating a ServerRuntimeBuilder is done via a static method on ServerRuntime ("ServerRuntime.builder()"). The previous style (ServerRuntimeBuilder.builder()) is deprecated and will soon be removed, so you should replace it http://git-wip-us.apache.org/repos/asf/cayenne/blob/f6a58d68/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Main.java ---------------------------------------------------------------------- diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Main.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Main.java index 1143d74..ed5882c 100644 --- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Main.java +++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Main.java @@ -28,7 +28,7 @@ import org.apache.cayenne.modeler.action.OpenProjectAction; import org.apache.cayenne.modeler.dialog.pref.GeneralPreferences; import org.apache.cayenne.modeler.init.CayenneModelerModule; import org.apache.cayenne.modeler.init.platform.PlatformInitializer; -import org.apache.cayenne.project.CayenneProjectModule; +import org.apache.cayenne.project.ProjectModule; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -66,6 +66,8 @@ public class Main { } protected void launch() { + + // TODO: use module auto-loading... final Injector injector = DIBootstrap .createInjector(appendModules(new ArrayList<Module>())); @@ -103,8 +105,11 @@ public class Main { } protected Collection<Module> appendModules(Collection<Module> modules) { + // TODO: this is dirty... "CayenneModeler" is not a project name, and ServerModule is out of place inside + // the Modeler... If we need ServerRuntime for certain operations, those should start their own stack... modules.add(new ServerModule("CayenneModeler")); - modules.add(new CayenneProjectModule()); + + modules.add(new ProjectModule()); modules.add(new DbSyncModule()); modules.add(new CayenneModelerModule());