use of com.google.startupos.tools.build_file_generator.Protos.BuildFile.JavaLibrary 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();
}
use of com.google.startupos.tools.build_file_generator.Protos.BuildFile.JavaLibrary in project startup-os by google.
the class BuildFileGenerator method getInternalProjectJavaClassToTargetNameMap.
private Map<String, String> getInternalProjectJavaClassToTargetNameMap() {
Map<String, String> result = new HashMap<>();
for (String absPath : getPathsContainJavaAndProtoFiles()) {
final String relPackagePath = "/" + absPath.replace(fileUtils.getCurrentWorkingDirectory(), "");
final String absBuildFilePath = fileUtils.joinPaths(absPath, "BUILD");
if (fileUtils.fileExists(absBuildFilePath)) {
BuildFile buildFile = buildFileParser.getBuildFile(absBuildFilePath);
for (JavaLibrary javaLibrary : buildFile.getJavaLibraryList()) {
if (javaLibrary.getSrcsCount() > 0) {
String absClassPath = fileUtils.joinPaths(absPath, javaLibrary.getSrcs(0));
try {
JavaClass javaClass = javaClassAnalyzer.getJavaClass(absClassPath);
final String projectPackageSuffix = buildFileGeneratorUtils.getProjectPackageSuffix(projectName, javaClass.getPackage());
String targetName = relPackagePath + ":" + javaLibrary.getName();
for (String src : javaLibrary.getSrcsList()) {
String fullClassName = (relPackagePath.replace("//", "") + "." + src).replace("/", ".");
if (!projectPackageSuffix.isEmpty()) {
fullClassName = projectPackageSuffix + "." + fullClassName;
}
result.put(fullClassName.replaceAll(".java$", ""), targetName);
}
} catch (IOException e) {
throw new RuntimeException("Can't find java class by path: " + absClassPath, e);
}
}
}
}
}
return result;
}
use of com.google.startupos.tools.build_file_generator.Protos.BuildFile.JavaLibrary in project startup-os by google.
the class BuildFileWriter method getJavaLibraries.
private String getJavaLibraries(List<JavaLibrary> javaLibraries, List<CheckstyleTestExtension> checkstyleTests) {
StringBuilder result = new StringBuilder();
for (JavaLibrary javaLibrary : javaLibraries) {
result.append("java_library(").append(System.lineSeparator()).append(String.format(" name = \"%s\",", javaLibrary.getName())).append(getArgument("srcs", javaLibrary.getSrcsList())).append(getArgument("deps", javaLibrary.getDepsList())).append(System.lineSeparator()).append(")").append(System.lineSeparator()).append(System.lineSeparator());
result.append(getCheckstyleTest(checkstyleTests, javaLibrary.getName()));
}
return result.toString();
}
Aggregations