summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--srcgen/Android.bp22
-rwxr-xr-xsrcgen/generate_android_src.sh15
-rw-r--r--srcgen/src/main/java/com/android/bouncycastle/srcgen/BouncyCastleTransform.java142
3 files changed, 8 insertions, 171 deletions
diff --git a/srcgen/Android.bp b/srcgen/Android.bp
deleted file mode 100644
index c5ec8f9b..00000000
--- a/srcgen/Android.bp
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright (C) 2018 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-// Build the bouncycastle srcgen jar
-// ============================================================
-
-java_library_host {
- name: "android_bouncycastle_srcgen",
- libs: ["currysrc"],
- srcs: ["src/**/*.java"],
-}
diff --git a/srcgen/generate_android_src.sh b/srcgen/generate_android_src.sh
index 76db9797..ffdeeb3d 100755
--- a/srcgen/generate_android_src.sh
+++ b/srcgen/generate_android_src.sh
@@ -5,11 +5,11 @@ if [ -z "$ANDROID_BUILD_TOP" ]; then
exit 1
fi
-CLASSPATH=${ANDROID_HOST_OUT}/framework/currysrc.jar:${ANDROID_HOST_OUT}/framework/android_bouncycastle_srcgen.jar
+CLASSPATH=${ANDROID_HOST_OUT}/framework/currysrc.jar
BOUNCY_CASTLE_DIR=${ANDROID_BUILD_TOP}/external/bouncycastle
cd ${ANDROID_BUILD_TOP}
-make -j15 currysrc android_bouncycastle_srcgen
+make -j15 currysrc
CORE_PLATFORM_API_FILE=${BOUNCY_CASTLE_DIR}/srcgen/core-platform-api.txt
UNSUPPORTED_APP_USAGE_FILE=${BOUNCY_CASTLE_DIR}/srcgen/unsupported-app-usage.json
@@ -25,11 +25,12 @@ function do_transform() {
rm -rf ${SRC_OUT_DIR}
mkdir -p ${SRC_OUT_DIR}
- java -cp ${CLASSPATH} com.android.bouncycastle.srcgen.BouncyCastleTransform \
- ${SRC_IN_DIR} \
- ${SRC_OUT_DIR} \
- ${CORE_PLATFORM_API_FILE} \
- ${UNSUPPORTED_APP_USAGE_FILE}
+ java -cp ${CLASSPATH} com.google.currysrc.aosp.RepackagingTransform \
+ --source-dir ${SRC_IN_DIR} \
+ --target-dir ${SRC_OUT_DIR} \
+ --package-transformation "org.bouncycastle:com.android.org.bouncycastle" \
+ --core-platform-api-file ${CORE_PLATFORM_API_FILE} \
+ --unsupported-app-usage-file ${UNSUPPORTED_APP_USAGE_FILE}
}
BCPROV_SRC_IN_DIR=${BOUNCY_CASTLE_DIR}/bcprov/src/main/java
diff --git a/srcgen/src/main/java/com/android/bouncycastle/srcgen/BouncyCastleTransform.java b/srcgen/src/main/java/com/android/bouncycastle/srcgen/BouncyCastleTransform.java
deleted file mode 100644
index cef22c80..00000000
--- a/srcgen/src/main/java/com/android/bouncycastle/srcgen/BouncyCastleTransform.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.bouncycastle.srcgen;
-
-import static com.google.currysrc.api.process.Rules.createMandatoryRule;
-import static com.google.currysrc.api.process.Rules.createOptionalRule;
-
-import com.google.currysrc.Main;
-import com.google.currysrc.aosp.Annotations;
-import com.google.currysrc.api.RuleSet;
-import com.google.currysrc.api.input.DirectoryInputFileGenerator;
-import com.google.currysrc.api.input.InputFileGenerator;
-import com.google.currysrc.api.output.BasicOutputSourceFileGenerator;
-import com.google.currysrc.api.output.OutputSourceFileGenerator;
-import com.google.currysrc.api.process.Rule;
-import com.google.currysrc.api.process.ast.BodyDeclarationLocators;
-import com.google.currysrc.api.process.ast.TypeLocator;
-import com.google.currysrc.processors.AddMarkerAnnotation;
-import com.google.currysrc.processors.HidePublicClasses;
-import com.google.currysrc.processors.InsertHeader;
-import com.google.currysrc.processors.ModifyQualifiedNames;
-import com.google.currysrc.processors.ModifyStringLiterals;
-import com.google.currysrc.processors.RenamePackage;
-import java.io.File;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
-
-/**
- * Generates bouncycastle sources in the com.android.org.bouncycastle package.
- */
-public class BouncyCastleTransform {
- static final String ORIGINAL_PACKAGE = "org.bouncycastle";
- static final String ANDROID_PACKAGE = "com.android.org.bouncycastle";
-
- /**
- * Usage:
- * java BouncyCastleTransform {source dir} {target dir}
- */
- public static void main(String[] args) throws Exception {
- if (args.length != 4) {
- throw new IllegalArgumentException(
- "Usage: " + BouncyCastleTransform.class.getCanonicalName()
- + " <source-dir>"
- + " <target-dir>"
- + " <core-platform-api-file>"
- + " <unsupported-app-usage-file>");
- }
- String sourceDir = args[0];
- String targetDir = args[1];
- Path corePlatformApiFile = Paths.get(args[2]);
- Path unsupportedAppUsageFile = Paths.get(args[3]);
-
- Map<String, String> options = JavaCore.getOptions();
- options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_8);
- options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_8);
- options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
- options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, JavaCore.SPACE);
- options.put(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE, "4");
-
- new Main(false /* debug */)
- .setJdtOptions(options)
- .execute(new TransformRuleSet(sourceDir, targetDir, corePlatformApiFile,
- unsupportedAppUsageFile));
- }
-
- static class TransformRuleSet implements RuleSet {
- private final String sourceDir;
- private final String targetDir;
- private final Path corePlatformApiFile;
- private final Path unsupportedAppUsageFile;
-
- TransformRuleSet(String sourceDir, String targetDir, Path corePlatformApiFile,
- Path unsupportedAppUsageFile) {
- this.sourceDir = sourceDir;
- this.targetDir = targetDir;
- this.corePlatformApiFile = corePlatformApiFile;
- this.unsupportedAppUsageFile = unsupportedAppUsageFile;
- }
-
- @Override
- public InputFileGenerator getInputFileGenerator() {
- return new DirectoryInputFileGenerator(new File(sourceDir));
- }
-
- @Override
- public List<Rule> getRuleList(File ignored) {
- return Arrays.asList(
- // Doc change: Insert a warning about the source code being generated.
- createMandatoryRule(
- new InsertHeader("/* GENERATED SOURCE. DO NOT MODIFY. */\n")),
- // AST change: Change the package of each CompilationUnit
- createMandatoryRule(new RenamePackage(ORIGINAL_PACKAGE, ANDROID_PACKAGE)),
- // AST change: Change all qualified names in code and javadoc.
- createOptionalRule(new ModifyQualifiedNames(ORIGINAL_PACKAGE, ANDROID_PACKAGE)),
- // AST change: Change all string literals containing package names in code.
- createOptionalRule(new ModifyStringLiterals(ORIGINAL_PACKAGE, ANDROID_PACKAGE)),
- // Doc change: Insert @hide on all public classes.
- createHidePublicClassesRule(),
- // AST change: Add CorePlatformApi to specified classes and members
- createOptionalRule(new AddMarkerAnnotation("libcore.api.CorePlatformApi",
- BodyDeclarationLocators.readBodyDeclarationLocators(corePlatformApiFile))),
- // AST Change: Add UnsupportedAppUsage to specified class members.
- createOptionalRule(
- Annotations.addUnsupportedAppUsage(unsupportedAppUsageFile))
- );
- }
-
- private static Rule createHidePublicClassesRule() {
- List<TypeLocator> publicApiClassesWhitelist = Collections.emptyList();
- return createOptionalRule(new HidePublicClasses(publicApiClassesWhitelist,
- "This class is not part of the Android public SDK API"));
- }
-
- @Override
- public OutputSourceFileGenerator getOutputSourceFileGenerator() {
- File outputDir = new File(targetDir);
- return new BasicOutputSourceFileGenerator(outputDir);
- }
- }
-
- private BouncyCastleTransform() {
- }
-}