// Path: jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/MavenDependency.java
// public class MavenDependency extends MavenArtifact {
// 
//     private String scope;
//     public boolean optional;
// 
//     @Nonnull
//     public String getScope() {
//         return scope == null ? "compile" : scope;
//     }
// 
//     public void setScope(String scope) {
//         this.scope = scope == null || scope.isEmpty() ? null : scope;
//     }
// 
//     @Override
//     public String toString() {
//         return "MavenDependency{" +
//                 getGroupId() + ":" +
//                 getArtifactId() + ":" +
//                 getType() +
//                 (getClassifier() == null ? "" : ":" + getClassifier()) + ":" +
//                 getBaseVersion() + ", " +
//                 "scope: " + scope + ", " +
//                 " optional: " + optional +
//                 " version: " + getVersion() +
//                 " snapshot: " + isSnapshot() +
//                 (getFile() == null ? "" : " " + getFile()) +
//                 '}';
//     }
// 
//     public MavenArtifact asMavenArtifact() {
//         MavenArtifact result = new MavenArtifact();
// 
//         result.setGroupId(getGroupId());
//         result.setArtifactId(getArtifactId());
//         result.setVersion(getVersion());
//         result.setBaseVersion(getBaseVersion());
//         result.setType(getType());
//         result.setClassifier(getClassifier());
//         result.setExtension(getExtension());
//         result.setFile(getFile());
//         result.setSnapshot(isSnapshot());
// 
//         return result;
//     }
// 
// 
//     @Override
//     public int hashCode() {
//         return Objects.hash(super.hashCode(), optional, scope);
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (this == obj)
//             return true;
//         if (!super.equals(obj))
//             return false;
//         if (getClass() != obj.getClass())
//             return false;
//         MavenDependency other = (MavenDependency) obj;
//         if (optional != other.optional)
//             return false;
//         if (scope == null) {
//             return other.scope == null;
//         } else return scope.equals(other.scope);
//     }
// }
// 
// Path: jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/util/ClassUtils.java
// public class ClassUtils {
// 
//     @Nullable
//     public static InputStream getResourceAsStream(@Nonnull String resourcePath) {
//         InputStream result = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourcePath);
//         if(result == null) {
//              result = ClassUtils.class.getClassLoader().getResourceAsStream(resourcePath);
//         }
//          return result;
//     }
// 
// }


import hudson.model.Item;
import hudson.model.Result;
import hudson.model.Run;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.h2.api.ErrorCode;
import org.jenkinsci.plugins.pipeline.maven.MavenArtifact;
import org.jenkinsci.plugins.pipeline.maven.MavenDependency;
import org.jenkinsci.plugins.pipeline.maven.db.migration.MigrationStep;
import org.jenkinsci.plugins.pipeline.maven.util.ClassUtils;
import org.jenkinsci.plugins.pipeline.maven.util.RuntimeIoException;
import org.jenkinsci.plugins.pipeline.maven.util.RuntimeSqlException;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.sql.DataSource;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
        initializeDatabase();
        testDatabase();
    }

    protected abstract void registerJdbcDriver();

    @Override
    public void recordDependency(String jobFullName, int buildNumber, String groupId, String artifactId, String version, String type, String scope, boolean ignoreUpstreamTriggers, String classifier) {
        LOGGER.log(Level.FINE, "recordDependency({0}#{1}, {2}:{3}:{4}:{5}, {6}, ignoreUpstreamTriggers:{7}})",
                new Object[]{jobFullName, buildNumber, groupId, artifactId, version, type, scope, ignoreUpstreamTriggers});
        long buildPrimaryKey = getOrCreateBuildPrimaryKey(jobFullName, buildNumber);
        long artifactPrimaryKey = getOrCreateArtifactPrimaryKey(groupId, artifactId, version, type, classifier);

        try (Connection cnn = ds.getConnection()) {
            cnn.setAutoCommit(false);
            try (PreparedStatement stmt = cnn.prepareStatement("INSERT INTO MAVEN_DEPENDENCY(ARTIFACT_ID, BUILD_ID, SCOPE, IGNORE_UPSTREAM_TRIGGERS) VALUES (?, ?, ?, ?)")) {
                stmt.setLong(1, artifactPrimaryKey);
                stmt.setLong(2, buildPrimaryKey);
                stmt.setString(3, scope);
                stmt.setBoolean(4, ignoreUpstreamTriggers);
                stmt.execute();
            }
            cnn.commit();
        } catch (SQLException e) {
            throw new RuntimeSqlException(e);
        }
    }

    @Nonnull
    @Override
// Path: jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/MavenDependency.java
// public class MavenDependency extends MavenArtifact {
// 
//     private String scope;
//     public boolean optional;
// 
//     @Nonnull
//     public String getScope() {
//         return scope == null ? "compile" : scope;
//     }
// 
//     public void setScope(String scope) {
//         this.scope = scope == null || scope.isEmpty() ? null : scope;
//     }
// 
//     @Override
//     public String toString() {
//         return "MavenDependency{" +
//                 getGroupId() + ":" +
//                 getArtifactId() + ":" +
//                 getType() +
//                 (getClassifier() == null ? "" : ":" + getClassifier()) + ":" +
//                 getBaseVersion() + ", " +
//                 "scope: " + scope + ", " +
//                 " optional: " + optional +
//                 " version: " + getVersion() +
//                 " snapshot: " + isSnapshot() +
//                 (getFile() == null ? "" : " " + getFile()) +
//                 '}';
//     }
// 
//     public MavenArtifact asMavenArtifact() {
//         MavenArtifact result = new MavenArtifact();
// 
//         result.setGroupId(getGroupId());
//         result.setArtifactId(getArtifactId());
//         result.setVersion(getVersion());
//         result.setBaseVersion(getBaseVersion());
//         result.setType(getType());
//         result.setClassifier(getClassifier());
//         result.setExtension(getExtension());
//         result.setFile(getFile());
//         result.setSnapshot(isSnapshot());
// 
//         return result;
//     }
// 
// 
//     @Override
//     public int hashCode() {
//         return Objects.hash(super.hashCode(), optional, scope);
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (this == obj)
//             return true;
//         if (!super.equals(obj))
//             return false;
//         if (getClass() != obj.getClass())
//             return false;
//         MavenDependency other = (MavenDependency) obj;
//         if (optional != other.optional)
//             return false;
//         if (scope == null) {
//             return other.scope == null;
//         } else return scope.equals(other.scope);
//     }
// }
// 
// Path: jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/util/ClassUtils.java
// public class ClassUtils {
// 
//     @Nullable
//     public static InputStream getResourceAsStream(@Nonnull String resourcePath) {
//         InputStream result = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourcePath);
//         if(result == null) {
//              result = ClassUtils.class.getClassLoader().getResourceAsStream(resourcePath);
//         }
//          return result;
//     }
// 
// }


// Path: jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/dao/AbstractPipelineMavenPluginDao.java
import hudson.model.Item;
import hudson.model.Result;
import hudson.model.Run;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.h2.api.ErrorCode;
import org.jenkinsci.plugins.pipeline.maven.MavenArtifact;
import org.jenkinsci.plugins.pipeline.maven.MavenDependency;
import org.jenkinsci.plugins.pipeline.maven.db.migration.MigrationStep;
import org.jenkinsci.plugins.pipeline.maven.util.ClassUtils;
import org.jenkinsci.plugins.pipeline.maven.util.RuntimeIoException;
import org.jenkinsci.plugins.pipeline.maven.util.RuntimeSqlException;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.sql.DataSource;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;

        initializeDatabase();
        testDatabase();
    }

    protected abstract void registerJdbcDriver();

    @Override
    public void recordDependency(String jobFullName, int buildNumber, String groupId, String artifactId, String version, String type, String scope, boolean ignoreUpstreamTriggers, String classifier) {
        LOGGER.log(Level.FINE, "recordDependency({0}#{1}, {2}:{3}:{4}:{5}, {6}, ignoreUpstreamTriggers:{7}})",
                new Object[]{jobFullName, buildNumber, groupId, artifactId, version, type, scope, ignoreUpstreamTriggers});
        long buildPrimaryKey = getOrCreateBuildPrimaryKey(jobFullName, buildNumber);
        long artifactPrimaryKey = getOrCreateArtifactPrimaryKey(groupId, artifactId, version, type, classifier);

        try (Connection cnn = ds.getConnection()) {
            cnn.setAutoCommit(false);
            try (PreparedStatement stmt = cnn.prepareStatement("INSERT INTO MAVEN_DEPENDENCY(ARTIFACT_ID, BUILD_ID, SCOPE, IGNORE_UPSTREAM_TRIGGERS) VALUES (?, ?, ?, ?)")) {
                stmt.setLong(1, artifactPrimaryKey);
                stmt.setLong(2, buildPrimaryKey);
                stmt.setString(3, scope);
                stmt.setBoolean(4, ignoreUpstreamTriggers);
                stmt.execute();
            }
            cnn.commit();
        } catch (SQLException e) {
            throw new RuntimeSqlException(e);
        }
    }

    @Nonnull
    @Override
    public List<MavenDependency> listDependencies(@Nonnull String jobFullName, int buildNumber) {