use of java.nio.file.Files in project rest.li by linkedin.
the class PegasusPlugin method configureAvroSchemaGeneration.
@SuppressWarnings("deprecation")
protected void configureAvroSchemaGeneration(Project project, SourceSet sourceSet) {
File dataSchemaDir = project.file(getDataSchemaPath(project, sourceSet));
File avroDir = project.file(getGeneratedDirPath(project, sourceSet, AVRO_SCHEMA_GEN_TYPE) + File.separatorChar + "avro");
// generate avro schema files from data schema
Task generateAvroSchemaTask = project.getTasks().create(sourceSet.getTaskName("generate", "avroSchema"), GenerateAvroSchemaTask.class, task -> {
task.setInputDir(dataSchemaDir);
task.setDestinationDir(avroDir);
task.setResolverPath(getDataModelConfig(project, sourceSet));
task.setCodegenClasspath(project.getConfigurations().getByName(PEGASUS_PLUGIN_CONFIGURATION));
if (isPropertyTrue(project, ENABLE_ARG_FILE)) {
task.setEnableArgFile(true);
}
task.onlyIf(t -> {
if (task.getInputDir().exists()) {
@SuppressWarnings("unchecked") Map<String, PegasusOptions> pegasusOptions = (Map<String, PegasusOptions>) project.getExtensions().getExtraProperties().get("pegasus");
if (pegasusOptions.get(sourceSet.getName()).hasGenerationMode(PegasusOptions.GenerationMode.AVRO)) {
return true;
}
}
return !project.getConfigurations().getByName("avroSchemaGenerator").isEmpty();
});
task.doFirst(new CacheableAction<>(t -> deleteGeneratedDir(project, sourceSet, AVRO_SCHEMA_GEN_TYPE)));
});
project.getTasks().getByName(sourceSet.getCompileJavaTaskName()).dependsOn(generateAvroSchemaTask);
// create avro schema jar file
Task avroSchemaJarTask = project.getTasks().create(sourceSet.getName() + "AvroSchemaJar", Jar.class, task -> {
// add path prefix to each file in the data schema directory
task.from(avroDir, copySpec -> copySpec.eachFile(fileCopyDetails -> fileCopyDetails.setPath("avro" + File.separatorChar + fileCopyDetails.getPath())));
// FIXME change to #getArchiveAppendix().set(...); breaks backwards-compatibility before 5.1
task.setAppendix(getAppendix(sourceSet, "avro-schema"));
task.setDescription("Generate an avro schema jar");
});
if (!isTestSourceSet(sourceSet)) {
project.getArtifacts().add("avroSchema", avroSchemaJarTask);
} else {
project.getArtifacts().add("testAvroSchema", avroSchemaJarTask);
}
}
use of java.nio.file.Files in project rest.li by linkedin.
the class PegasusPlugin method configureConversionUtilities.
protected void configureConversionUtilities(Project project, SourceSet sourceSet) {
File dataSchemaDir = project.file(getDataSchemaPath(project, sourceSet));
boolean reverse = isPropertyTrue(project, CONVERT_TO_PDL_REVERSE);
boolean keepOriginal = isPropertyTrue(project, CONVERT_TO_PDL_KEEP_ORIGINAL);
boolean skipVerification = isPropertyTrue(project, CONVERT_TO_PDL_SKIP_VERIFICATION);
String preserveSourceCmd = getNonEmptyProperty(project, CONVERT_TO_PDL_PRESERVE_SOURCE_CMD);
// Utility task for migrating between PDSC and PDL.
project.getTasks().create(sourceSet.getTaskName("convert", "ToPdl"), TranslateSchemasTask.class, task -> {
task.setInputDir(dataSchemaDir);
task.setDestinationDir(dataSchemaDir);
task.setResolverPath(getDataModelConfig(project, sourceSet));
task.setCodegenClasspath(project.getConfigurations().getByName(PEGASUS_PLUGIN_CONFIGURATION));
task.setPreserveSourceCmd(preserveSourceCmd);
if (reverse) {
task.setSourceFormat(SchemaFileType.PDL);
task.setDestinationFormat(SchemaFileType.PDSC);
} else {
task.setSourceFormat(SchemaFileType.PDSC);
task.setDestinationFormat(SchemaFileType.PDL);
}
task.setKeepOriginal(keepOriginal);
task.setSkipVerification(skipVerification);
if (isPropertyTrue(project, ENABLE_ARG_FILE)) {
task.setEnableArgFile(true);
}
task.onlyIf(t -> task.getInputDir().exists());
task.doLast(new CacheableAction<>(t -> {
project.getLogger().lifecycle("Pegasus schema conversion complete.");
project.getLogger().lifecycle("All pegasus schema files in " + dataSchemaDir + " have been converted");
project.getLogger().lifecycle("You can use '-PconvertToPdl.reverse=true|false' to change the direction of conversion.");
}));
});
// Helper task for reformatting existing PDL schemas by generating them again.
project.getTasks().create(sourceSet.getTaskName("reformat", "Pdl"), TranslateSchemasTask.class, task -> {
task.setInputDir(dataSchemaDir);
task.setDestinationDir(dataSchemaDir);
task.setResolverPath(getDataModelConfig(project, sourceSet));
task.setCodegenClasspath(project.getConfigurations().getByName(PEGASUS_PLUGIN_CONFIGURATION));
task.setSourceFormat(SchemaFileType.PDL);
task.setDestinationFormat(SchemaFileType.PDL);
task.setKeepOriginal(true);
task.setSkipVerification(true);
if (isPropertyTrue(project, ENABLE_ARG_FILE)) {
task.setEnableArgFile(true);
}
task.onlyIf(t -> task.getInputDir().exists());
task.doLast(new CacheableAction<>(t -> project.getLogger().lifecycle("PDL reformat complete.")));
});
}
use of java.nio.file.Files in project rest.li by linkedin.
the class TestDataSchemaParser method testParseResultToGetBaseSchemas.
@Test(dataProvider = "ERFilesForBaseSchema")
public void testParseResultToGetBaseSchemas(String[] files, String[] expectedSchemaNames) throws Exception {
String pegasusWithFS = TEST_RESOURCES_DIR + FS;
String resolverPath = pegasusWithFS + "extensionSchemas/extensions:" + pegasusWithFS + "extensionSchemas/others:" + pegasusWithFS + "extensionSchemas/pegasus";
DataSchemaParser parser = new DataSchemaParser.Builder(resolverPath).build();
String[] schemaFiles = Arrays.stream(files).map(casename -> TEST_RESOURCES_DIR + FS + "extensionSchemas" + FS + casename).toArray(String[]::new);
DataSchemaParser.ParseResult parseResult = parser.parseSources(schemaFiles);
Map<DataSchema, DataSchemaLocation> bases = parseResult.getBaseDataSchemaAndLocations();
assertEquals(bases.size(), expectedSchemaNames.length);
Set<String> actualNames = bases.keySet().stream().map(dataSchema -> (NamedDataSchema) dataSchema).map(NamedDataSchema::getName).collect(Collectors.toSet());
assertEquals(actualNames, Arrays.stream(expectedSchemaNames).collect(Collectors.toSet()));
}
use of java.nio.file.Files in project rest.li by linkedin.
the class TestPegasusDataTemplateGenerator method generatePegasusDataTemplates.
/**
* Given a source schema filename, generate Java data templates for all types within this schema.
* @param pegasusFilename source schema filename
* @return mapping from generated type name to generated file
*/
private Map<String, File> generatePegasusDataTemplates(String pegasusFilename) throws IOException {
String tempDirectoryPath = _tempDir.getAbsolutePath();
File pegasusFile = new File(pegasusDir + FS + pegasusFilename);
PegasusDataTemplateGenerator.main(new String[] { tempDirectoryPath, pegasusFile.getAbsolutePath() });
File[] generatedFiles = _tempDir.listFiles((File dir, String name) -> name.endsWith(".java"));
Assert.assertNotNull(generatedFiles, "Found no generated Java files.");
return Arrays.stream(generatedFiles).collect(Collectors.toMap(file -> file.getName().replace(".java", ""), Function.identity()));
}
use of java.nio.file.Files in project alluxio by Alluxio.
the class SimpleFileManagerTest method testFailedCreate.
@Test
public void testFailedCreate() {
try (MockedStatic<Files> mock = Mockito.mockStatic(Files.class)) {
mock.when(() -> Files.createFile(any(), any())).thenThrow(new IOException("Failed to set permissions!"));
assertFalse(mFileManager.addFile("test", "0644", "test".getBytes()));
}
}
Aggregations