List of usage examples for com.google.gson GsonBuilder create
public Gson create()
From source file:com.android.build.gradle.internal.pipeline.SubStream.java
License:Apache License
public static void save(@NonNull Collection<SubStream> subStreams, @NonNull File rootFolder) throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(SubStream.class, new SubStreamAdapter()); Gson gson = gsonBuilder.create(); // just in case FileUtils.mkdirs(rootFolder);/*from w w w . ja v a 2 s . c o m*/ Files.write(gson.toJson(subStreams), new File(rootFolder, FN_FOLDER_CONTENT), Charsets.UTF_8); }
From source file:com.android.build.gradle.internal.scope.BuildOutputs.java
License:Apache License
/** * Persists the passed output types and split output to a {@link String} using gson. * * @param projectPath path to relativize output file paths against. * @param outputTypes the output types to persist. * @param splitOutputs the outputs organized per output type * @return a json String./*from w w w. jav a 2s.co m*/ */ public static String persist(Path projectPath, ImmutableList<VariantScope.OutputType> outputTypes, SetMultimap<VariantScope.OutputType, BuildOutput> splitOutputs) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(ApkInfo.class, new BuildOutputs.ApkInfoAdapter()); gsonBuilder.registerTypeAdapter(VariantScope.TaskOutputType.class, new BuildOutputs.OutputTypeTypeAdapter()); gsonBuilder.registerTypeAdapter(VariantScope.AnchorOutputType.class, new BuildOutputs.OutputTypeTypeAdapter()); Gson gson = gsonBuilder.create(); // flatten and relativize the file paths to be persisted. List<BuildOutput> buildOutputs = outputTypes.stream().map(splitOutputs::get).flatMap(Collection::stream) .map(buildOutput -> new BuildOutput(buildOutput.getType(), buildOutput.getApkInfo(), projectPath.relativize(buildOutput.getOutputPath()), buildOutput.getProperties())) .collect(Collectors.toList()); return gson.toJson(buildOutputs); }
From source file:com.android.build.gradle.internal.scope.BuildOutputs.java
License:Apache License
@NonNull private static Collection<BuildOutput> load(@NonNull Path projectPath, @NonNull Reader reader) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(ApkInfo.class, new ApkInfoAdapter()); gsonBuilder.registerTypeAdapter(VariantScope.OutputType.class, new OutputTypeTypeAdapter()); Gson gson = gsonBuilder.create(); Type recordType = new TypeToken<List<BuildOutput>>() { }.getType();/*from w w w.java 2s .co m*/ Collection<BuildOutput> buildOutputs = gson.fromJson(reader, recordType); // resolve the file path to the current project location. return buildOutputs.stream() .map(buildOutput -> new BuildOutput(buildOutput.getType(), buildOutput.getApkInfo(), projectPath.resolve(buildOutput.getOutputPath()), buildOutput.getProperties())) .collect(Collectors.toList()); }
From source file:com.android.build.gradle.internal.scope.InstantAppOutputScope.java
License:Apache License
public void save(@NonNull File outputDirectory) throws IOException { File outputFile = new File(outputDirectory, PERSISTED_FILE_NAME); GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.create(); FileUtils.write(outputFile, gson.toJson(this)); }
From source file:com.android.build.gradle.internal.scope.InstantAppOutputScope.java
License:Apache License
@Nullable public static InstantAppOutputScope load(@NonNull File directory) { File input = new File(directory, PERSISTED_FILE_NAME); if (!input.exists()) { return null; }/*from ww w . j a va 2s .c o m*/ GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.create(); try { return gson.fromJson(new FileReader(input), InstantAppOutputScope.class); } catch (FileNotFoundException e) { return null; // This should never happen. } }
From source file:com.android.build.gradle.internal.tasks.ApplicationId.java
License:Apache License
@NonNull public static ApplicationId load(@NonNull File input) throws FileNotFoundException { if (!input.getName().equals(PERSISTED_FILE_NAME)) { throw new FileNotFoundException("No application declaration present."); }/*from ww w .j a v a 2s. com*/ GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.create(); return gson.fromJson(new FileReader(input), ApplicationId.class); }
From source file:com.android.build.gradle.internal.tasks.featuresplit.FeatureSplitDeclaration.java
License:Apache License
@NonNull public static FeatureSplitDeclaration load(@NonNull File input) throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.create(); try (FileReader fileReader = new FileReader(input)) { return gson.fromJson(fileReader, FeatureSplitDeclaration.class); }/* w ww. ja v a 2s . c o m*/ }
From source file:com.android.build.gradle.internal.tasks.featuresplit.FeatureSplitPackageIds.java
License:Apache License
public void save(@NonNull File outputDirectory) throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.create(); File outputFile = getOutputFile(outputDirectory); Files.write(gson.toJson(featureSplits), outputFile, Charsets.UTF_8); }
From source file:com.android.build.gradle.internal.tasks.featuresplit.FeatureSplitPackageIds.java
License:Apache License
@NonNull public static FeatureSplitPackageIds load(@NonNull File input) throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); Gson gson = gsonBuilder.create(); Type typeToken = new TypeToken<HashSet<SplitPackageId>>() { }.getType();/* w ww .j a v a 2 s . co m*/ try (FileReader fileReader = new FileReader(input)) { Set<SplitPackageId> featureIds = gson.fromJson(fileReader, typeToken); return new FeatureSplitPackageIds(featureIds); } }
From source file:com.android.ide.common.blame.output.GradleMessageRewriter.java
License:Apache License
private static Gson createGson() { GsonBuilder gsonBuilder = new GsonBuilder(); MessageJsonSerializer.registerTypeAdapters(gsonBuilder); return gsonBuilder.create(); }