You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by ro...@apache.org on 2009/03/11 04:34:56 UTC
svn commit: r752361 - in /cayenne/main/trunk:
docs/doc/src/main/resources/RELEASE-NOTES.txt
framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java
Author: robertdzeigler
Date: Wed Mar 11 03:34:55 2009
New Revision: 752361
URL: http://svn.apache.org/viewvc?rev=752361&view=rev
Log:
CAY-1181 Default class generation folder is wrong.
Applied Dima's patch with some cleanups to account for cayenne.cgen.destdir system property and to get rid of hard-coded unix-style path separators.
Modified:
cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java
Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=752361&r1=752360&r2=752361&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Wed Mar 11 03:34:55 2009
@@ -29,6 +29,7 @@
CAY-1161 Deprecate SelectQuery custom columns feature
CAY-1174 Modeler: support optional meaningful PK mapping during reverse engineering
CAY-1175 Replace String column name capitalization property with an enum
+CAY-1181 Default class generation folder is wrong
CAY-1184 Callback methods should default to usable names
Bug Fixes Since M5:
Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java?rev=752361&r1=752360&r2=752361&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java Wed Mar 11 03:34:55 2009
@@ -19,7 +19,6 @@
package org.apache.cayenne.modeler.dialog.codegen;
-import java.awt.Component;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
@@ -71,17 +70,8 @@
}
protected void initBindings(BindingBuilder bindingBuilder) {
- if (preferences.getOutputPath() == null) {
- // init default directory..
- FSPath lastPath = Application
- .getInstance()
- .getFrameController()
- .getLastDirectory();
- File lastDir = (lastPath != null)
- ? lastPath.getExistingDirectory(false)
- : null;
- preferences.setOutputPath(lastDir != null ? lastDir.getAbsolutePath() : null);
- }
+
+ initOutputFolder();
JTextField outputFolder = ((GeneratorControllerPanel) getView())
.getOutputFolder();
@@ -436,7 +426,64 @@
// update model
String path = selected.getAbsolutePath();
outputFolder.setText(path);
+ //be sure to update the destdir property, if it's not null.
+ //this ensures that if the user selected a /different/ dir than the system-property default,
+ //they get back that directory throughought the session.
+ if (System.getProperty("cayenne.cgen.destdir") != null) {
+ System.setProperty("cayenne.cgen.destdir",path);
+ }
preferences.setOutputPath(path);
}
}
+
+ private void initOutputFolder(){
+
+ String path = null;
+ if (System.getProperty("cayenne.cgen.destdir") != null) {
+ preferences.setOutputPath(System.getProperty("cayenne.cgen.destdir"));
+ return;
+ }
+ if (preferences.getOutputPath() == null) {
+ // init default directory..
+ FSPath lastPath = Application
+ .getInstance()
+ .getFrameController()
+ .getLastDirectory();
+
+ path = checkDefaultMavenResourceDir(lastPath,"test");
+
+ if (path != null || (path=checkDefaultMavenResourceDir(lastPath,"main")) != null) {
+ preferences.setOutputPath(path);
+ } else {
+ File lastDir = (lastPath != null)
+ ? lastPath.getExistingDirectory(false)
+ : null;
+ preferences.setOutputPath(lastDir != null ? lastDir.getAbsolutePath() : null);
+ }
+ }
+ }
+
+ private String checkDefaultMavenResourceDir(FSPath lastPath, String dirType) {
+ String path = lastPath.getPath();
+ String resourcePath = buildFilePath("src",dirType,"resources");
+ int idx = path.indexOf(resourcePath);
+ if (idx < 0) {
+ return null;
+ }
+ return path.substring(0,idx)
+ + buildFilePath("src",dirType,"java") +
+ path.substring(idx+resourcePath.length());
+ }
+
+ private static final String buildFilePath(String... pathElements) {
+ if (pathElements.length == 0) {
+ return "";
+ }
+ StringBuilder path = new StringBuilder(pathElements[0]);
+ for(int i=1;i<pathElements.length;i++) {
+ path.append(File.separator).append( pathElements[i]);
+ }
+ return path.toString();
+ }
+
}