Permalink
Browse files

New finer-grain data template and request builder generator classes a…

…nd structure.

RB=445269
R=gogenc,slim,xma,kvidhani
A=gogenc,xma
  • Loading branch information...
1 parent 4275178 commit 08745a7caac562f7083e0ec24160e930c9fe07ca @CrendKing CrendKing committed May 11, 2015
Showing with 5,452 additions and 3,877 deletions.
  1. +8 −1 CHANGELOG
  2. +2 −1 data-avro-generator/src/main/java/com/linkedin/data/avro/generator/AvroSchemaGenerator.java
  3. +1 −71 data/src/main/java/com/linkedin/data/schema/generator/AbstractGenerator.java
  4. +75 −4 data/src/main/java/com/linkedin/util/FileUtil.java
  5. +10 −3 data/src/test/java/com/linkedin/data/schema/generator/TestAbstractGenerator.java
  6. +1 −1 generator-test/build.gradle
  7. +3 −2 generator-test/src/test/java/com/linkedin/pegasus/generator/test/TestBadSchemas.java
  8. +2 −1 generator-test/src/test/java/com/linkedin/pegasus/generator/test/TestDeprecated.java
  9. 0 ...tor-test/src/test/pegasus/com/linkedin/pegasus/generator/test/{deprecated.pdsc → Deprecated.pdsc}
  10. +0 −263 generator/src/main/java/com/linkedin/pegasus/generator/CodeGenerator.java
  11. +124 −0 generator/src/main/java/com/linkedin/pegasus/generator/CodeUtil.java
  12. +324 −0 generator/src/main/java/com/linkedin/pegasus/generator/DataSchemaParser.java
  13. +0 −1,792 generator/src/main/java/com/linkedin/pegasus/generator/DataTemplateGenerator.java
  14. +58 −0 generator/src/main/java/com/linkedin/pegasus/generator/DefaultGeneratorResult.java
  15. +2 −2 generator/src/main/java/com/linkedin/pegasus/generator/GeneratorResult.java
  16. +155 −0 generator/src/main/java/com/linkedin/pegasus/generator/JavaCodeGeneratorBase.java
  17. +173 −0 generator/src/main/java/com/linkedin/pegasus/generator/JavaCodeUtil.java
  18. +953 −0 generator/src/main/java/com/linkedin/pegasus/generator/JavaDataTemplateGenerator.java
  19. +105 −62 generator/src/main/java/com/linkedin/pegasus/generator/PegasusDataTemplateGenerator.java
  20. +909 −0 generator/src/main/java/com/linkedin/pegasus/generator/TemplateSpecGenerator.java
  21. +72 −0 generator/src/main/java/com/linkedin/pegasus/generator/spec/ArrayTemplateSpec.java
  22. +157 −0 generator/src/main/java/com/linkedin/pegasus/generator/spec/ClassTemplateSpec.java
  23. +66 −0 generator/src/main/java/com/linkedin/pegasus/generator/spec/CustomInfoSpec.java
  24. +38 −0 generator/src/main/java/com/linkedin/pegasus/generator/spec/EnumTemplateSpec.java
  25. +38 −0 generator/src/main/java/com/linkedin/pegasus/generator/spec/FixedTemplateSpec.java
  26. +72 −0 generator/src/main/java/com/linkedin/pegasus/generator/spec/MapTemplateSpec.java
  27. +36 −0 generator/src/main/java/com/linkedin/pegasus/generator/spec/ModifierSpec.java
  28. +62 −0 generator/src/main/java/com/linkedin/pegasus/generator/spec/PrimitiveTemplateSpec.java
  29. +102 −0 generator/src/main/java/com/linkedin/pegasus/generator/spec/RecordTemplateSpec.java
  30. +38 −0 generator/src/main/java/com/linkedin/pegasus/generator/spec/TyperefTemplateSpec.java
  31. +98 −0 generator/src/main/java/com/linkedin/pegasus/generator/spec/UnionTemplateSpec.java
  32. +7 −13 gradle-plugins/src/main/groovy/com/linkedin/pegasus/gradle/PegasusPlugin.groovy
  33. +1 −1 gradle.properties
  34. +9 −8 restli-common/src/main/java/com/linkedin/restli/restspec/RestSpecCodec.java
  35. +1,561 −0 restli-tools/src/main/java/com/linkedin/restli/tools/clientgen/JavaRequestBuilderGenerator.java
  36. +66 −1,647 restli-tools/src/main/java/com/linkedin/restli/tools/clientgen/RestRequestBuilderGenerator.java
  37. +119 −0 restli-tools/src/main/java/com/linkedin/restli/tools/clientgen/RestSpecParser.java
  38. +5 −5 restli-tools/src/test/java/com/linkedin/restli/tools/clientgen/TestRestRequestBuilderGenerator.java
View
@@ -1,11 +1,18 @@
-2.4.5
+2.5.1
+------
+
+
+2.5.0
------
(RB=475440 cont')
Make ChannelPoolHander iterate through all connection tokens.
(RB=438141)
Modify content-encoding and content-length headers when decompressing body.
+(RB=445269)
+New finer-grain data template and request builder generator classes and structure.
+
2.4.4
------
(RB=475440)
@@ -29,6 +29,7 @@
import com.linkedin.data.schema.RecordDataSchema;
import com.linkedin.data.schema.generator.AbstractGenerator;
import com.linkedin.data.schema.resolver.FileDataSchemaLocation;
+import com.linkedin.util.FileUtil;
import java.io.File;
import java.io.FileOutputStream;
@@ -164,7 +165,7 @@ private void generate(String targetDirectoryPath, String[] sources) throws IOExc
File targetDirectory = new File(targetDirectoryPath);
List<File> targetFiles = targetFiles(targetDirectory);
- if (upToDate(sourceFiles, targetFiles))
+ if (FileUtil.upToDate(sourceFiles, targetFiles))
{
_log.info("Target files are up-to-date: " + targetFiles);
return;
@@ -23,7 +23,6 @@
import com.linkedin.data.schema.NamedDataSchema;
import com.linkedin.data.schema.SchemaParser;
import com.linkedin.data.schema.SchemaParserFactory;
-
import com.linkedin.data.schema.resolver.DefaultDataSchemaResolver;
import com.linkedin.data.schema.resolver.FileDataSchemaLocation;
import com.linkedin.data.schema.resolver.FileDataSchemaResolver;
@@ -210,7 +209,7 @@ private void validateSchemaWithFilepath(File schemaSourceFile, DataSchema schema
NamedDataSchema namedDataSchema = (NamedDataSchema)schema;
String namespace = namedDataSchema.getNamespace();
- if(!removeFileExtension(schemaSourceFile.getName()).equalsIgnoreCase(namedDataSchema.getName()))
+ if(!FileUtil.removeFileExtension(schemaSourceFile.getName()).equalsIgnoreCase(namedDataSchema.getName()))
{
throw new IllegalArgumentException(namedDataSchema.getFullName() + " has name that does not match filename '" +
schemaSourceFile.getAbsolutePath() + "'");
@@ -225,19 +224,6 @@ private void validateSchemaWithFilepath(File schemaSourceFile, DataSchema schema
}
}
- private String removeFileExtension(String filename)
- {
- int idx = filename.lastIndexOf('.');
- if(idx == 0)
- {
- return filename;
- }
- else
- {
- return filename.substring(0, idx);
- }
- }
-
/**
* Whether a source file has already been resolved to data schemas.
*
@@ -317,60 +303,4 @@ protected void appendSourceFilesFromSchemaResolver(List<File> sourceFiles)
}
}
}
-
- /**
- * Compute the most recent last modified time of the provided files.
- *
- * @param files to compute most recent modified time from.
- * @return the most resent last modified of the provided files.
- */
- protected long mostRecentLastModified(List<File> files)
- {
- long mostRecent = 0L;
- for (File file : files)
- {
- long fileLastModified = file.lastModified();
- if (mostRecent < fileLastModified)
- {
- mostRecent = fileLastModified;
- }
- }
- return mostRecent;
- }
-
- /**
- * Determine whether the provided files has been modified more recently than the provided time.
- *
- * @param files whose last modified times will be compared to provided time.
- * @param time to compare the files' last modified times to.
- * @return true if the provided files has been modified more recently than the provided time.
- */
- protected boolean filesLastModifiedMoreRecentThan(List<File> files, long time)
- {
- for (File file : files)
- {
- if (! file.exists() || time >= file.lastModified())
- {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Whether the files that would be generated into the specified target directory
- * are more recent than the most recent source files.
- *
- * This used to check if the output file is already up-to-date and need not be
- * overwritten with generated output.
- *
- * @param sourceFiles provides the source files that were parsed.
- * @param targetFiles provides the files that would have been generated.
- * @return true if the files that would be generated are more recent than the most recent source files.
- */
- protected boolean upToDate(List<File> sourceFiles, List<File> targetFiles)
- {
- long sourceLastModified = mostRecentLastModified(sourceFiles);
- return filesLastModifiedMoreRecentThan(targetFiles, sourceLastModified);
- }
}
@@ -1,21 +1,24 @@
package com.linkedin.util;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import java.io.File;
import java.io.FileFilter;
import java.util.ArrayDeque;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* @author Keren Jin
*/
public class FileUtil
{
+ private static final Logger _log = LoggerFactory.getLogger(FileUtil.class);
+
public static class FileExtensionFilter implements FileFilter
{
public FileExtensionFilter(String extension)
@@ -90,5 +93,73 @@ public static String buildSystemIndependentPath(String ... pathPieces)
return sb.toString();
}
- private static final Logger _log = LoggerFactory.getLogger(FileUtil.class);
+ public static String removeFileExtension(String filename)
+ {
+ final int idx = filename.lastIndexOf('.');
+ if (idx == 0)
+ {
+ return filename;
+ }
+ else
+ {
+ return filename.substring(0, idx);
+ }
+ }
+
+ /**
+ * Whether the files that would be generated into the specified target directory are more recent than the most recent source files.
+ * <p/>
+ * This used to check if the output file is already up-to-date and need not be overwritten with generated output.
+ *
+ * @param sourceFiles provides the source files that were parsed.
+ * @param targetFiles provides the files that would have been generated.
+ *
+ * @return true if the files that would be generated are more recent than the most recent source files.
+ */
+ public static boolean upToDate(Collection<File> sourceFiles, Collection<File> targetFiles)
+ {
+ final long sourceLastModified = mostRecentLastModified(sourceFiles);
+ return filesLastModifiedMoreRecentThan(targetFiles, sourceLastModified);
+ }
+
+ /**
+ * Compute the most recent last modified time of the provided files.
+ *
+ * @param files to compute most recent modified time from.
+ *
+ * @return the most resent last modified of the provided files.
+ */
+ private static long mostRecentLastModified(Collection<File> files)
+ {
+ long mostRecent = 0L;
+ for (File file : files)
+ {
+ final long fileLastModified = file.lastModified();
+ if (mostRecent < fileLastModified)
+ {
+ mostRecent = fileLastModified;
+ }
+ }
+ return mostRecent;
+ }
+
+ /**
+ * Determine whether the provided files has been modified more recently than the provided time.
+ *
+ * @param files whose last modified times will be compared to provided time.
+ * @param time to compare the files' last modified times to.
+ *
+ * @return true if the provided files has been modified more recently than the provided time.
+ */
+ private static boolean filesLastModifiedMoreRecentThan(Collection<File> files, long time)
+ {
+ for (File file : files)
+ {
+ if (!file.exists() || time >= file.lastModified())
+ {
+ return false;
+ }
+ }
+ return true;
+ }
}
@@ -23,7 +23,7 @@
import com.linkedin.data.schema.DataSchema;
import com.linkedin.data.schema.NamedDataSchema;
import com.linkedin.data.template.DataTemplateUtil;
-import org.testng.annotations.Test;
+import com.linkedin.util.FileUtil;
import java.io.File;
import java.io.FileInputStream;
@@ -38,7 +38,14 @@
import java.util.Map;
import java.util.Set;
-import static com.linkedin.data.TestUtil.*;
+import org.testng.annotations.Test;
+
+import static com.linkedin.data.TestUtil.asMap;
+import static com.linkedin.data.TestUtil.computePathFromRelativePaths;
+import static com.linkedin.data.TestUtil.createJarsFromRelativePaths;
+import static com.linkedin.data.TestUtil.dataMapFromString;
+import static com.linkedin.data.TestUtil.ensureEmptyOutputDir;
+import static com.linkedin.data.TestUtil.out;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
@@ -97,7 +104,7 @@ private void generate(String targetDirectoryPath, String sources[]) throws IOExc
File targetDirectory = new File(targetDirectoryPath);
List<File> targetFiles = targetFiles(targetDirectory);
- if (upToDate(sourceFiles, targetFiles))
+ if (FileUtil.upToDate(sourceFiles, targetFiles))
{
if (_debug) out.println("Avro schemas are up-to-date: " + Arrays.toString(sources));
return;
@@ -31,7 +31,7 @@ project.sourceSets.all { SourceSet sourceSet ->
}
}
-// This module tests that deprecated types and fields in "deprecated.pdsc",
+// This module tests that deprecated types and fields in "Deprecated.pdsc",
// result in correctly generated classes and methods that are also marked as deprecated.
// Since the classes are generated, they cannot be marked with @SuppressWarnings("deprecated"), we must disable the 'deprecation' compiler warnings.
// For example, see: Deprecated.getSampleEnum()
@@ -19,12 +19,13 @@
import com.linkedin.data.TestUtil;
import com.linkedin.pegasus.generator.PegasusDataTemplateGenerator;
-import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
import java.util.Map;
+import org.testng.annotations.Test;
+
import static com.linkedin.data.TestUtil.asMap;
import static com.linkedin.data.TestUtil.ensureEmptyOutputDir;
import static org.testng.Assert.assertEquals;
@@ -70,7 +71,7 @@
"}"
),
IllegalArgumentException.class,
- "Java class name conflict detected, class name: com.linkedin.pegasus.generator.test.XArray, class already bound to schema: { \"type\" : \"array\", \"items\" : { \"type\" : \"enum\", \"name\" : \"X\", \"namespace\" : \"com.linkedin.pegasus.generator.test\", \"symbols\" : [ \"X\" ] } }, attempting to rebind to schema: { \"type\" : \"enum\", \"name\" : \"XArray\", \"namespace\" : \"com.linkedin.pegasus.generator.test\", \"symbols\" : [ \"Y\" ] }"
+ "Class name conflict detected, class name: com.linkedin.pegasus.generator.test.XArray, class already bound to schema: { \"type\" : \"array\", \"items\" : { \"type\" : \"enum\", \"name\" : \"X\", \"namespace\" : \"com.linkedin.pegasus.generator.test\", \"symbols\" : [ \"X\" ] } }, attempting to rebind to schema: { \"type\" : \"enum\", \"name\" : \"XArray\", \"namespace\" : \"com.linkedin.pegasus.generator.test\", \"symbols\" : [ \"Y\" ] }"
},
{
asMap(
@@ -18,12 +18,13 @@
import java.util.HashMap;
import java.util.Map;
+
import org.testng.Assert;
import org.testng.annotations.Test;
/**
- * Verify that deprecated annotations in "deprecated.pdsc" are correctly represented as @Deprecated
+ * Verify that deprecated annotations in "Deprecated.pdsc" are correctly represented as @Deprecated
* annotations on the generated java data templates.
*/
public class TestDeprecated
Oops, something went wrong.

0 comments on commit 08745a7

Please sign in to comment.