Skip to content

More convenient to use #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions generator/src/com/foxykeep/cpcodegenerator/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@
public class Main {

public static void main(final String[] args) {

final File fileInputDir = new File("input");
final String dir = System.getProperty("user.dir");
System.out.println("current dir = " + dir);
File fileInputDir;
if (args.length > 0) {
fileInputDir = new File(args[0]);
if (!fileInputDir.isAbsolute()) {
fileInputDir = new File(dir + File.separator + args[0]);
}
} else {
fileInputDir = new File(dir + File.separator + "example");
}
if (!fileInputDir.exists() || !fileInputDir.isDirectory()) {
return;
}
Expand All @@ -48,6 +57,9 @@ public static void main(final String[] args) {
// For each file in the input folder
for (File file : fileInputDir.listFiles()) {
final String fileName = file.getName();
if ("format.json".equals(fileName)) {
continue;
}
System.out.println("Generating code for " + fileName);

final char[] buffer = new char[2048];
Expand All @@ -73,7 +85,8 @@ public static void main(final String[] args) {
return;
}

final String content = sb.toString();
String content = sb.toString();
content = content.substring(content.indexOf("{"));
if (content.length() == 0) {
System.out.println("file is empty.");
return;
Expand All @@ -84,8 +97,7 @@ public static void main(final String[] args) {
final JSONObject jsonDatabase = root.getJSONObject("database");

// Classes generation
String classPackage, classesPrefix, contentClassesPrefix, dbAuthorityPackage,
providerFolder;
String classPackage, classesPrefix, contentClassesPrefix, dbAuthorityPackage, providerFolder;
int dbVersion;
boolean hasProviderSubclasses;
classPackage = jsonDatabase.getString("package");
Expand All @@ -97,17 +109,19 @@ public static void main(final String[] args) {
dbVersion = jsonDatabase.getInt("version");
hasProviderSubclasses = jsonDatabase.optBoolean("has_subclasses");

ArrayList<TableData> classDataList = TableData.getClassesData(root.getJSONArray(
"tables"), contentClassesPrefix, dbVersion);
ArrayList<TableData> classDataList = TableData.getClassesData(
root.getJSONArray("tables"), contentClassesPrefix, dbVersion);

// Database generation
DatabaseGenerator.generate(fileName, classPackage, dbVersion, dbAuthorityPackage,
classesPrefix, classDataList, providerFolder, hasProviderSubclasses);

FileCache.saveFile(PathUtils.getAndroidFullPath(fileName, classPackage,
providerFolder + "." + PathUtils.UTIL) + "ColumnMetadata.java",
String.format(columnMetadataText, classPackage,
providerFolder + "." + PathUtils.UTIL));
FileCache.saveFile(
PathUtils.getAndroidFullPath(fileName, classPackage, providerFolder + "."
+ PathUtils.UTIL)
+ "ColumnMetadata.java",
String.format(columnMetadataText, classPackage, providerFolder + "."
+ PathUtils.UTIL));

} catch (JSONException e) {
e.printStackTrace();
Expand Down