Search in sources :

Example 6 with Archive

use of org.revapi.Archive in project revapi by revapi.

the class Compiler method copyArchives.

private IdentityHashMap<Archive, File> copyArchives(Iterable<? extends Archive> archives, File parentDir, int startIdx, int prefixLength) {
    IdentityHashMap<Archive, File> ret = new IdentityHashMap<>();
    if (archives == null) {
        return ret;
    }
    for (Archive a : archives) {
        String name = formatName(startIdx++, prefixLength, a.getName());
        File f = new File(parentDir, name);
        ret.put(a, f);
        if (f.exists()) {
            LOG.warn("File " + f.getAbsolutePath() + " with the data of archive '" + a.getName() + "' already exists." + " Assume it already contains the bits we need.");
            continue;
        }
        Path target = new File(parentDir, name).toPath();
        try (InputStream data = a.openStream()) {
            Files.copy(data, target);
        } catch (IOException e) {
            throw new IllegalStateException("Failed to copy class path element: " + a.getName() + " to " + f.getAbsolutePath(), e);
        }
    }
    return ret;
}
Also used : Path(java.nio.file.Path) Archive(org.revapi.Archive) InputStream(java.io.InputStream) IOException(java.io.IOException) File(java.io.File)

Example 7 with Archive

use of org.revapi.Archive in project revapi by revapi.

the class BuildTimeReporter method getAllProblemsMessage.

public String getAllProblemsMessage() {
    StringBuilder errors = new StringBuilder("The following API problems caused the build to fail:\n");
    StringBuilder ignores = new StringBuilder();
    for (Report r : allProblems) {
        Element element = r.getNewElement();
        Archive archive;
        if (element == null) {
            element = r.getOldElement();
            assert element != null;
            archive = shouldOutputArchive(oldApi, element.getArchive()) ? element.getArchive() : null;
        } else {
            archive = shouldOutputArchive(newApi, element.getArchive()) ? element.getArchive() : null;
        }
        for (Difference d : r.getDifferences()) {
            if (isReportable(d)) {
                errors.append(d.code).append(": ").append(element.getFullHumanReadableString()).append(": ").append(d.description);
                if (archive != null) {
                    errors.append(" [").append(archive.getName()).append("]");
                }
                errors.append("\n");
                ignores.append("{\n");
                ignores.append("  \"code\": \"").append(escape(d.code)).append("\",\n");
                if (r.getOldElement() != null) {
                    ignores.append("  \"old\": \"").append(escape(r.getOldElement())).append("\",\n");
                }
                if (r.getNewElement() != null) {
                    ignores.append("  \"new\": \"").append(escape(r.getNewElement())).append("\",\n");
                }
                for (Map.Entry<String, String> e : d.attachments.entrySet()) {
                    ignores.append("  \"").append(escape(e.getKey())).append("\": \"").append(escape(e.getValue())).append("\",\n");
                }
                ignores.append("  \"justification\": <<<<< ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE" + " >>>>>\n");
                ignores.append("},\n");
            }
        }
    }
    if (errors.length() == 0) {
        return null;
    } else {
        ignores.replace(ignores.length() - 2, ignores.length(), "");
        return errors.toString() + "\nIf you're using the semver-ignore extension, update your module's version to one compatible " + "with the current changes (e.g. mvn package revapi:update-versions). If you want to " + "explicitly ignore this change and provide a justification for it, add the following JSON snippet " + "to your Revapi configuration under \"revapi.ignore\" path:\n" + ignores.toString();
    }
}
Also used : Archive(org.revapi.Archive) Report(org.revapi.Report) Element(org.revapi.Element) Difference(org.revapi.Difference) Map(java.util.Map)

Aggregations

Archive (org.revapi.Archive)7 IOException (java.io.IOException)4 File (java.io.File)3 InputStream (java.io.InputStream)3 Arrays (java.util.Arrays)2 Map (java.util.Map)2 Set (java.util.Set)2 Nonnull (javax.annotation.Nonnull)2 JavaFileObject (javax.tools.JavaFileObject)2 StandardJavaFileManager (javax.tools.StandardJavaFileManager)2 URI (java.net.URI)1 Path (java.nio.file.Path)1 AbstractMap (java.util.AbstractMap)1 ArrayDeque (java.util.ArrayDeque)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 EnumMap (java.util.EnumMap)1 EnumSet (java.util.EnumSet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1