Search in sources :

Example 1 with CompatibilityLogChecker

use of com.linkedin.pegasus.gradle.internal.CompatibilityLogChecker in project rest.li by linkedin.

the class CheckIdlTask method check.

@TaskAction
public void check() {
    getProject().getLogger().info("Checking interface compatibility with API ...");
    List<String> errorFilePairs = findErrorFilePairs();
    CompatibilityLogChecker logChecker = new CompatibilityLogChecker();
    FileCollection _pathedCodegenClasspath;
    try {
        _pathedCodegenClasspath = PathingJarUtil.generatePathingJar(getProject(), getName(), _codegenClasspath, false);
    } catch (IOException e) {
        throw new GradleException("Error occurred generating pathing JAR.", e);
    }
    getProject().javaexec(javaExecSpec -> {
        String resolverPathArg = _resolverPath.getAsPath();
        if (isEnableArgFile()) {
            resolverPathArg = ArgumentFileGenerator.getArgFileSyntax(ArgumentFileGenerator.createArgFile("checkIdl_resolverPath", Collections.singletonList(resolverPathArg), getTemporaryDir()));
        }
        javaExecSpec.setMain("com.linkedin.restli.tools.idlcheck.RestLiResourceModelCompatibilityChecker");
        javaExecSpec.setClasspath(_pathedCodegenClasspath);
        javaExecSpec.jvmArgs("-Dgenerator.resolver.path=" + resolverPathArg);
        javaExecSpec.args("--compat", _idlCompatLevel);
        javaExecSpec.args("--report");
        javaExecSpec.args(errorFilePairs);
        javaExecSpec.setStandardOutput(logChecker);
    });
    _modelCompatible = logChecker.isModelCompatible();
    _restSpecCompatible = logChecker.isRestSpecCompatible();
    _equivalent = logChecker.getModelCompatibility().isEmpty() && logChecker.getRestSpecCompatibility().isEmpty();
    _wholeMessage = logChecker.getWholeText();
    IOUtil.writeText(_summaryTarget, _wholeMessage);
    if (!_modelCompatible || !_restSpecCompatible) {
        throw new GradleException("See output for " + getPath() + ". Summary written to " + _summaryTarget.getAbsolutePath());
    }
}
Also used : CompatibilityLogChecker(com.linkedin.pegasus.gradle.internal.CompatibilityLogChecker) GradleException(org.gradle.api.GradleException) IOException(java.io.IOException) FileCollection(org.gradle.api.file.FileCollection) TaskAction(org.gradle.api.tasks.TaskAction)

Example 2 with CompatibilityLogChecker

use of com.linkedin.pegasus.gradle.internal.CompatibilityLogChecker in project rest.li by linkedin.

the class CheckRestModelTask method check.

@TaskAction
public void check() {
    getProject().getLogger().info("Checking interface compatibility with API ...");
    List<String> argFiles = new ArrayList<>();
    argFiles.addAll(findMatchingFiles(PegasusPlugin.SNAPSHOT_FILE_SUFFIX, _currentSnapshotFiles, getProject().fileTree(_previousSnapshotDirectory), false));
    // We don't pass matching IDL files to RestLiSnapshotCompatibilityChecker. We only specify added or deleted IDL
    // files, for which the checker will generate appropriate message.
    argFiles.addAll(findMatchingFiles(PegasusPlugin.IDL_FILE_SUFFIX, _currentIdlFiles, getProject().fileTree(_previousIdlDirectory), true));
    if (argFiles.isEmpty()) {
        return;
    }
    CompatibilityLogChecker logChecker = new CompatibilityLogChecker();
    FileCollection _pathedCodegenClasspath;
    try {
        _pathedCodegenClasspath = PathingJarUtil.generatePathingJar(getProject(), getName(), _codegenClasspath, false);
    } catch (IOException e) {
        throw new GradleException("Error occurred generating pathing JAR.", e);
    }
    getProject().javaexec(javaExecSpec -> {
        javaExecSpec.setMain("com.linkedin.restli.tools.snapshot.check.RestLiSnapshotCompatibilityChecker");
        javaExecSpec.setClasspath(_pathedCodegenClasspath);
        javaExecSpec.args("--compat", _modelCompatLevel.toLowerCase());
        javaExecSpec.args("--report");
        javaExecSpec.args(argFiles);
        javaExecSpec.setStandardOutput(logChecker);
    });
    _modelCompatible = logChecker.isModelCompatible();
    _restSpecCompatible = logChecker.isRestSpecCompatible();
    _equivalent = logChecker.getModelCompatibility().isEmpty() && logChecker.getRestSpecCompatibility().isEmpty();
    _restSpecEquivalent = logChecker.getRestSpecCompatibility().isEmpty();
    _wholeMessage = logChecker.getWholeText();
    IOUtil.writeText(_summaryTarget, _wholeMessage);
    if (!_modelCompatible || !_restSpecCompatible) {
        throw new GradleException("See output for " + getPath() + ". Summary written to " + _summaryTarget.getAbsolutePath());
    }
}
Also used : CompatibilityLogChecker(com.linkedin.pegasus.gradle.internal.CompatibilityLogChecker) GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileCollection(org.gradle.api.file.FileCollection) TaskAction(org.gradle.api.tasks.TaskAction)

Example 3 with CompatibilityLogChecker

use of com.linkedin.pegasus.gradle.internal.CompatibilityLogChecker in project rest.li by linkedin.

the class CheckPegasusSnapshotTask method checkPegasusSnapshot.

@TaskAction
public void checkPegasusSnapshot() {
    getLogger().info("Checking pegasus schema compatibility ...");
    FileCollection pathedCodegenClasspath;
    try {
        pathedCodegenClasspath = PathingJarUtil.generatePathingJar(getProject(), getName(), _codegenClasspath, false);
    } catch (IOException e) {
        throw new GradleException("Error occurred generating pathing JAR.", e);
    }
    File reportOutput = new File(getProject().getBuildDir(), _isExtensionSchema ? PEGASUS_EXTENSION_SCHEMA_COMPATIBILITY_SUMMARY_FILE : PEGASUS_SCHEMA_COMPATIBILITY_SUMMARY_FILE);
    reportOutput.getParentFile().mkdirs();
    getProject().javaexec(javaExecSpec -> {
        javaExecSpec.setMain("com.linkedin.restli.tools.snapshot.check.PegasusSchemaSnapshotCompatibilityChecker");
        javaExecSpec.setClasspath(pathedCodegenClasspath);
        javaExecSpec.args("--compatLevel", _compatibilityLevel);
        javaExecSpec.args("--compatMode", _compatibilityMode);
        javaExecSpec.args("--report", reportOutput);
        javaExecSpec.args(_previousSnapshotDirectory);
        javaExecSpec.args(_currentSnapshotDirectory);
        if (_isExtensionSchema) {
            javaExecSpec.args("--extensionSchema");
        } else if (hasSchemaAnnotationHandler()) {
            javaExecSpec.args("--handlerJarPath", _handlerJarPath);
            javaExecSpec.args("--handlerClassName", String.join(File.pathSeparator, _handlerClassNames));
        }
    });
    CompatibilityLogChecker logChecker = new CompatibilityLogChecker();
    try {
        logChecker.write(Files.readAllBytes(reportOutput.toPath()));
    } catch (IOException e) {
        throw new GradleException("Error while processing compatibility report: " + e.getMessage());
    }
    if (!logChecker.isModelCompatible() || !logChecker.isAnnotationCompatible()) {
        throw new GradleException("There are incompatible changes, find details in " + reportOutput.getAbsolutePath());
    }
}
Also used : CompatibilityLogChecker(com.linkedin.pegasus.gradle.internal.CompatibilityLogChecker) GradleException(org.gradle.api.GradleException) IOException(java.io.IOException) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File) TaskAction(org.gradle.api.tasks.TaskAction)

Example 4 with CompatibilityLogChecker

use of com.linkedin.pegasus.gradle.internal.CompatibilityLogChecker in project rest.li by linkedin.

the class CheckSnapshotTask method check.

@TaskAction
public void check() {
    getProject().getLogger().info("Checking interface compatibility with API ...");
    List<String> argFiles = new ArrayList<>();
    checkSnapshotCompatibility(getProject(), _currentSnapshotFiles, _previousSnapshotDirectory, SNAPSHOT_FILTER, argFiles);
    if (argFiles.isEmpty()) {
        return;
    }
    CompatibilityLogChecker logChecker = new CompatibilityLogChecker();
    FileCollection _pathedCodegenClasspath;
    try {
        _pathedCodegenClasspath = PathingJarUtil.generatePathingJar(getProject(), getName(), _codegenClasspath, false);
    } catch (IOException e) {
        throw new GradleException("Error occurred generating pathing JAR.", e);
    }
    getProject().javaexec(javaExecSpec -> {
        javaExecSpec.setMain("com.linkedin.restli.tools.snapshot.check.RestLiSnapshotCompatibilityChecker");
        javaExecSpec.setClasspath(_pathedCodegenClasspath);
        javaExecSpec.args("--compat", _snapshotCompatLevel);
        javaExecSpec.args("--report");
        javaExecSpec.args(argFiles);
        javaExecSpec.setStandardOutput(logChecker);
    });
    _modelCompatible = logChecker.isModelCompatible();
    _restSpecCompatible = logChecker.isRestSpecCompatible();
    _equivalent = logChecker.getModelCompatibility().isEmpty() && logChecker.getRestSpecCompatibility().isEmpty();
    _restSpecEquivalent = logChecker.getRestSpecCompatibility().isEmpty();
    _wholeMessage = logChecker.getWholeText();
    IOUtil.writeText(_summaryTarget, _wholeMessage);
    if (!_modelCompatible || !_restSpecCompatible) {
        throw new GradleException("See output for " + getPath() + ". Summary written to " + _summaryTarget.getAbsolutePath());
    }
}
Also used : CompatibilityLogChecker(com.linkedin.pegasus.gradle.internal.CompatibilityLogChecker) GradleException(org.gradle.api.GradleException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileCollection(org.gradle.api.file.FileCollection) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

CompatibilityLogChecker (com.linkedin.pegasus.gradle.internal.CompatibilityLogChecker)4 IOException (java.io.IOException)4 GradleException (org.gradle.api.GradleException)4 FileCollection (org.gradle.api.file.FileCollection)4 TaskAction (org.gradle.api.tasks.TaskAction)4 ArrayList (java.util.ArrayList)2 File (java.io.File)1