@@ -0,0 +1,2219 @@
+/*******************************************************************************%0A * Copyright (c) 2015 IBH SYSTEMS GmbH.%0A * All rights reserved. This program and the accompanying materials%0A * are made available under the terms of the Eclipse Public License v1.0%0A * which accompanies this distribution, and is available at%0A * http://www.eclipse.org/legal/epl-v10.html%0A *%0A * Contributors:%0A *     IBH SYSTEMS GmbH - initial API and implementation%0A *******************************************************************************/%0Apackage org.eclipse.packagedrone.utils;%0A%0Aimport java.io.Closeable;%0Aimport java.util.LinkedList;%0Aimport java.util.function.BiFunction;%0Aimport java.util.function.Function;%0A%0Apublic class Suppressed%3CT extends Exception%3E implements AutoCloseable%0A%7B%0A    @FunctionalInterface%0A    public interface VoidOperation%0A    %7B%0A        public void run () throws Throwable;%0A    %7D%0A%0A    private final Function%3CThrowable, T%3E rootCreator;%0A%0A    private final LinkedList%3CThrowable%3E errors = new LinkedList%3C%3E ();%0A%0A    public Suppressed ( final Function%3CThrowable, T%3E rootCreator )%0A    %7B%0A        this.rootCreator = rootCreator;%0A    %7D%0A%0A    public Suppressed ( final String message, final BiFunction%3CString, Throwable, T%3E rootCreator )%0A    %7B%0A        this.rootCreator = e -%3E rootCreator.apply ( message, e );%0A    %7D%0A%0A    public void close ( final Closeable closeable )%0A    %7B%0A        try%0A        %7B%0A            closeable.close ();%0A        %7D%0A        catch ( final Exception e )%0A        %7B%0A            this.errors.add ( e );%0A        %7D%0A    %7D%0A%0A    public void run ( final VoidOperation op )%0A    %7B%0A        try%0A        %7B%0A            op.run ();%0A        %7D%0A        catch ( final Throwable e )%0A        %7B%0A            this.errors.add ( e );%0A        %7D%0A    %7D%0A%0A    private void complete () throws T%0A    %7B%0A        if ( this.errors.isEmpty () )%0A        %7B%0A            return;%0A        %7D%0A%0A        final Throwable e = this.errors.pollFirst ();%0A        final T root = this.rootCreator.apply ( e );%0A        for ( final Throwable sup : this.errors )%0A        %7B%0A            root.addSuppressed ( sup );%0A        %7D%0A%0A        this.errors.clear ();%0A%0A        throw root;%0A    %7D%0A%0A    @Override%0A    public void close () throws T%0A    %7B%0A        complete ();%0A    %7D%0A%7D%0A

add a helper to work with suppressed exceptions