// 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;
                try (PreparedStatement stmt = cnn.prepareStatement("INSERT INTO MAVEN_ARTIFACT(GROUP_ID, ARTIFACT_ID, VERSION, TYPE, CLASSIFIER) VALUES (?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
                    stmt.setString(1, groupId);
                    stmt.setString(2, artifactId);
                    stmt.setString(3, version);
                    stmt.setString(4, type);
                    stmt.setString(5, classifier);

                    stmt.execute();
                    artifactPrimaryKey = getGeneratedPrimaryKey(stmt, "ID");
                }
            }
            cnn.commit();
            return artifactPrimaryKey;
        } catch (SQLException e) {
            throw new RuntimeSqlException(e);
        }
    }

    protected synchronized void initializeDatabase() {
        try (Connection cnn = ds.getConnection()) {
            cnn.setAutoCommit(false);
            int initialSchemaVersion = getSchemaVersion(cnn);

            LOGGER.log(Level.FINE, "Initialise database. Current schema version: {0}", new Object[]{initialSchemaVersion});

            NumberFormat numberFormat = new DecimalFormat("00");
            int idx = initialSchemaVersion;
            while (true) {
                idx++;
                String sqlScriptPath = "sql/" + getJdbcScheme() + "/" + numberFormat.format(idx) + "_migration.sql";
// 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;

                try (PreparedStatement stmt = cnn.prepareStatement("INSERT INTO MAVEN_ARTIFACT(GROUP_ID, ARTIFACT_ID, VERSION, TYPE, CLASSIFIER) VALUES (?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
                    stmt.setString(1, groupId);
                    stmt.setString(2, artifactId);
                    stmt.setString(3, version);
                    stmt.setString(4, type);
                    stmt.setString(5, classifier);

                    stmt.execute();
                    artifactPrimaryKey = getGeneratedPrimaryKey(stmt, "ID");
                }
            }
            cnn.commit();
            return artifactPrimaryKey;
        } catch (SQLException e) {
            throw new RuntimeSqlException(e);
        }
    }

    protected synchronized void initializeDatabase() {
        try (Connection cnn = ds.getConnection()) {
            cnn.setAutoCommit(false);
            int initialSchemaVersion = getSchemaVersion(cnn);

            LOGGER.log(Level.FINE, "Initialise database. Current schema version: {0}", new Object[]{initialSchemaVersion});

            NumberFormat numberFormat = new DecimalFormat("00");
            int idx = initialSchemaVersion;
            while (true) {
                idx++;
                String sqlScriptPath = "sql/" + getJdbcScheme() + "/" + numberFormat.format(idx) + "_migration.sql";
                InputStream sqlScriptInputStream = ClassUtils.getResourceAsStream(sqlScriptPath);