Search in sources :

Example 1 with JavaTest

use of com.google.startupos.tools.build_file_generator.Protos.BuildFile.JavaTest in project startup-os by google.

the class BuildFileGenerator method generateBuildFile.

private BuildFile generateBuildFile(String packagePath, List<ProtoFile> wholeProjectProtoFiles, List<ThirdPartyDep> thirdPartyDeps, HttpArchiveDepsList httpArchiveDepsList, Map<String, String> internalProjectDeps) throws IOException {
    BuildFile.Builder buildFile = BuildFile.newBuilder();
    List<String> protoFilenames = getFilesByExtension(packagePath, ".proto");
    List<ProtoFile> protoFiles = new ArrayList<>();
    for (String protoFileName : protoFilenames) {
        ProtoFile protoFile = protoFileAnalyzer.getProtoFile(fileUtils.joinPaths(packagePath, protoFileName));
        protoFiles.add(protoFile);
        ProtoLibrary protoLibrary = getProtoLibrary(protoFile);
        buildFile.addProtoLibrary(protoLibrary);
        buildFile.addJavaProtoLibrary(getJavaProtoLibrary(protoLibrary.getName()));
        if (!protoFile.getServicesList().isEmpty()) {
            buildFile.addJavaGrpcLibrary(getJavaGrpcLibrary(protoFile));
            LoadExtensionStatement javaGrpcLibrary = getLoadExtensionStatement(JAVA_GRPC_LIBRARY_BZL_FILE_PATH, JAVA_GRPC_LIBRARY_SYMBOL);
            if (!buildFile.getExtensionList().contains(javaGrpcLibrary)) {
                buildFile.addExtension(javaGrpcLibrary);
            }
        }
    }
    List<String> javaClasses = getFilesByExtension(packagePath, ".java");
    if (!javaClasses.isEmpty()) {
        buildFile.addExtension(getLoadExtensionStatement(CHECKSTYLE_BZL_FILE_PATH, CHECKSTYLE_SYMBOL));
        for (String javaClassName : javaClasses) {
            JavaClass javaClass = javaClassAnalyzer.getJavaClass(fileUtils.joinPaths(packagePath, javaClassName));
            String targetName;
            if (javaClass.getHasMainMethod()) {
                JavaBinary javaBinary = getJavaBinary(javaClass, thirdPartyDeps, httpArchiveDepsList, protoFiles, wholeProjectProtoFiles, internalProjectDeps);
                targetName = javaBinary.getName();
                buildFile.addJavaBinary(javaBinary);
            } else if (javaClass.getIsTestClass()) {
                JavaTest javaTest = getJavaTest(javaClass, packagePath, thirdPartyDeps, httpArchiveDepsList, protoFiles, wholeProjectProtoFiles, internalProjectDeps);
                targetName = javaTest.getName();
                buildFile.addJavaTest(javaTest);
            } else {
                JavaLibrary javaLibrary = getJavaLibrary(javaClass, thirdPartyDeps, httpArchiveDepsList, protoFiles, wholeProjectProtoFiles, internalProjectDeps);
                targetName = javaLibrary.getName();
                buildFile.addJavaLibrary(javaLibrary);
            }
            buildFile.addCheckstyleTest(getCheckstyleTest(targetName));
        }
    }
    return buildFile.build();
}
Also used : BuildFile(com.google.startupos.tools.build_file_generator.Protos.BuildFile) ProtoFile(com.google.startupos.tools.build_file_generator.Protos.ProtoFile) ArrayList(java.util.ArrayList) JavaBinary(com.google.startupos.tools.build_file_generator.Protos.BuildFile.JavaBinary) JavaProtoLibrary(com.google.startupos.tools.build_file_generator.Protos.BuildFile.JavaProtoLibrary) ProtoLibrary(com.google.startupos.tools.build_file_generator.Protos.BuildFile.ProtoLibrary) JavaClass(com.google.startupos.tools.build_file_generator.Protos.JavaClass) JavaLibrary(com.google.startupos.tools.build_file_generator.Protos.BuildFile.JavaLibrary) JavaTest(com.google.startupos.tools.build_file_generator.Protos.BuildFile.JavaTest) LoadExtensionStatement(com.google.startupos.tools.build_file_generator.Protos.BuildFile.LoadExtensionStatement)

Example 2 with JavaTest

use of com.google.startupos.tools.build_file_generator.Protos.BuildFile.JavaTest in project startup-os by google.

the class BuildFileWriter method getJavaTests.

private String getJavaTests(List<JavaTest> javaTests, List<CheckstyleTestExtension> checkstyleTests) {
    StringBuilder result = new StringBuilder();
    for (JavaTest javaTest : javaTests) {
        result.append("java_test(").append(System.lineSeparator()).append(String.format("  name = \"%s\",", javaTest.getName())).append(getArgument("srcs", javaTest.getSrcsList())).append(getArgument("resources", javaTest.getResourcesList())).append(System.lineSeparator()).append(String.format("  test_class = \"%s\",", javaTest.getTestClass())).append(getArgument("deps", javaTest.getDepsList())).append(System.lineSeparator()).append(")").append(System.lineSeparator()).append(System.lineSeparator());
        result.append(getCheckstyleTest(checkstyleTests, javaTest.getName()));
    }
    return result.toString();
}
Also used : JavaTest(com.google.startupos.tools.build_file_generator.Protos.BuildFile.JavaTest)

Aggregations

JavaTest (com.google.startupos.tools.build_file_generator.Protos.BuildFile.JavaTest)2 BuildFile (com.google.startupos.tools.build_file_generator.Protos.BuildFile)1 JavaBinary (com.google.startupos.tools.build_file_generator.Protos.BuildFile.JavaBinary)1 JavaLibrary (com.google.startupos.tools.build_file_generator.Protos.BuildFile.JavaLibrary)1 JavaProtoLibrary (com.google.startupos.tools.build_file_generator.Protos.BuildFile.JavaProtoLibrary)1 LoadExtensionStatement (com.google.startupos.tools.build_file_generator.Protos.BuildFile.LoadExtensionStatement)1 ProtoLibrary (com.google.startupos.tools.build_file_generator.Protos.BuildFile.ProtoLibrary)1 JavaClass (com.google.startupos.tools.build_file_generator.Protos.JavaClass)1 ProtoFile (com.google.startupos.tools.build_file_generator.Protos.ProtoFile)1 ArrayList (java.util.ArrayList)1