Search in sources :

Example 1 with WorkspaceFile

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

the class HttpArchiveDepsTool method main.

public static void main(String[] args) throws IOException {
    Flags.parseCurrentPackage(args);
    HttpArchiveDepsTool.HttpArchiveDepsToolComponent component = DaggerHttpArchiveDepsTool_HttpArchiveDepsToolComponent.create();
    FileUtils fileUtils = component.getFileUtils();
    WorkspaceFile workspaceFile = component.getWorkspaceParser().getWorkspaceFile();
    HttpArchiveDepsList httpArchiveDepsList = component.getHttpArchiveDepsGenerator().getHttpArchiveDeps(workspaceFile, httpArchiveNames.get());
    if (!httpArchiveDepsList.getHttpArchiveDepsList().isEmpty()) {
        new HttpArchiveDepsTool().write(fileUtils, httpArchiveDepsList, fileUtils.joinPaths(fileUtils.getCurrentWorkingDirectory(), HttpArchiveDepsGenerator.HTTP_ARCHIVE_DEPS_FILENAME));
    }
}
Also used : FileUtils(com.google.startupos.common.FileUtils) WorkspaceFile(com.google.startupos.tools.build_file_generator.Protos.WorkspaceFile) HttpArchiveDepsList(com.google.startupos.tools.build_file_generator.Protos.HttpArchiveDepsList)

Example 2 with WorkspaceFile

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

the class HttpArchiveDepsGenerator method getHttpArchiveDeps.

public HttpArchiveDepsList getHttpArchiveDeps(WorkspaceFile workspaceFile, List<String> httpArchiveNames) throws IOException {
    HttpArchiveDepsList.Builder result = HttpArchiveDepsList.newBuilder();
    for (String httpArchiveName : httpArchiveNames) {
        WorkspaceFile.HttpArchive httpArchive = WorkspaceFile.HttpArchive.getDefaultInstance();
        for (WorkspaceFile.HttpArchive currentHttpArchive : workspaceFile.getHttpArchiveList()) {
            if (currentHttpArchive.getName().equals(httpArchiveName)) {
                httpArchive = currentHttpArchive;
            }
        }
        if (areCommitIdsTheSame(httpArchiveName, getCommitId(httpArchive.getStripPrefix()))) {
            log.atInfo().log("Commit id in WORKSPACE file and commit id in \'%s\' file for \'%s\' http_archive " + "are the same. Nothing to update.", HTTP_ARCHIVE_DEPS_FILENAME, httpArchiveName);
            continue;
        }
        if (httpArchive.getName().equals(httpArchiveName)) {
            HttpArchiveDeps.Builder builder = HttpArchiveDeps.newBuilder();
            String url = httpArchive.getUrls(0).split("/archive")[0] + ".git";
            String repoName = url.substring(url.lastIndexOf('/') + 1).replace(".git", "");
            GitRepo gitRepo = createRepo(url, repoName);
            switchToCommit(gitRepo, httpArchive.getStripPrefix());
            String absRepoPath = fileUtils.joinPaths(fileUtils.getCurrentWorkingDirectory(), BUILD_GENERATOR_TEMP_FOLDER, repoName);
            ImmutableList<String> buildFilesAbsPaths = getBuildFilesAbsPaths(absRepoPath);
            for (String path : buildFilesAbsPaths) {
                BuildFile buildFile = buildFileParser.getBuildFile(path);
                for (BuildFile.JavaLibrary javaLibrary : buildFile.getJavaLibraryList()) {
                    addDeps(absRepoPath, builder, path, javaLibrary.getSrcsList(), javaLibrary.getName());
                }
                for (BuildFile.JavaBinary javaBinary : buildFile.getJavaBinaryList()) {
                    addDeps(absRepoPath, builder, path, javaBinary.getSrcsList(), javaBinary.getName());
                }
                for (BuildFile.ProtoLibrary protoLibrary : buildFile.getProtoLibraryList()) {
                    String absProtoFilePath = path.replace("BUILD", protoLibrary.getSrcs(0));
                    for (BuildFile.JavaProtoLibrary javaProtoLibrary : buildFile.getJavaProtoLibraryList()) {
                        if (javaProtoLibrary.getDepsList().contains(":" + protoLibrary.getName())) {
                            ProtoFile protoFile = protoFileAnalyzer.getProtoFile(absProtoFilePath);
                            if ((!protoFile.getJavaPackage().isEmpty()) && (!protoFile.getJavaOuterClassname().isEmpty())) {
                                String fullJavaClassName = protoFile.getJavaPackage() + "." + protoFile.getJavaOuterClassname();
                                String target = path.replace(absRepoPath, "/").replace("/BUILD", ":") + javaProtoLibrary.getName();
                                builder.addHttpArchiveDep(HttpArchiveDep.newBuilder().setTarget(target).setJavaClass(fullJavaClassName).build());
                            }
                        }
                    }
                }
            }
            builder.setName(getCommitId(httpArchive.getName())).setCommitId(getCommitId(httpArchive.getStripPrefix()));
            result.addHttpArchiveDeps(builder.build());
            fileUtils.clearDirectoryUnchecked(fileUtils.joinPaths(fileUtils.getCurrentWorkingDirectory(), BUILD_GENERATOR_TEMP_FOLDER));
        } else {
            log.atWarning().log("Can't find http_archive with name: %s", httpArchiveName);
        }
    }
    fileUtils.deleteFileOrDirectoryIfExists(fileUtils.joinPaths(fileUtils.getCurrentWorkingDirectory(), BUILD_GENERATOR_TEMP_FOLDER));
    return result.build();
}
Also used : BuildFile(com.google.startupos.tools.build_file_generator.Protos.BuildFile) HttpArchiveDeps(com.google.startupos.tools.build_file_generator.Protos.HttpArchiveDeps) WorkspaceFile(com.google.startupos.tools.build_file_generator.Protos.WorkspaceFile) ProtoFile(com.google.startupos.tools.build_file_generator.Protos.ProtoFile) GitRepo(com.google.startupos.common.repo.GitRepo) HttpArchiveDepsList(com.google.startupos.tools.build_file_generator.Protos.HttpArchiveDepsList)

Example 3 with WorkspaceFile

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

the class WorkspaceParser method getWorkspaceFile.

public WorkspaceFile getWorkspaceFile() {
    WorkspaceFile.Builder result = WorkspaceFile.newBuilder();
    String absWorkspacePath = fileUtils.joinPaths(fileUtils.getCurrentWorkingDirectory(), "WORKSPACE");
    for (HttpArchive httpArchive : getHttpArchives(fileUtils.readFileUnchecked(absWorkspacePath))) {
        result.addHttpArchive(httpArchive);
    }
    return result.build();
}
Also used : WorkspaceFile(com.google.startupos.tools.build_file_generator.Protos.WorkspaceFile) HttpArchive(com.google.startupos.tools.build_file_generator.Protos.WorkspaceFile.HttpArchive)

Aggregations

WorkspaceFile (com.google.startupos.tools.build_file_generator.Protos.WorkspaceFile)3 HttpArchiveDepsList (com.google.startupos.tools.build_file_generator.Protos.HttpArchiveDepsList)2 FileUtils (com.google.startupos.common.FileUtils)1 GitRepo (com.google.startupos.common.repo.GitRepo)1 BuildFile (com.google.startupos.tools.build_file_generator.Protos.BuildFile)1 HttpArchiveDeps (com.google.startupos.tools.build_file_generator.Protos.HttpArchiveDeps)1 ProtoFile (com.google.startupos.tools.build_file_generator.Protos.ProtoFile)1 HttpArchive (com.google.startupos.tools.build_file_generator.Protos.WorkspaceFile.HttpArchive)1