Search in sources :

Example 1 with SCMProbe

use of jenkins.scm.api.SCMProbe in project gitea-plugin by jenkinsci.

the class GiteaSCMSource method createProbe.

@NonNull
@Override
protected SCMProbe createProbe(@NonNull final SCMHead head, SCMRevision revision) throws IOException {
    try {
        GiteaSCMFileSystem.BuilderImpl builder = ExtensionList.lookup(SCMFileSystem.Builder.class).get(GiteaSCMFileSystem.BuilderImpl.class);
        if (builder == null) {
            throw new AssertionError();
        }
        final SCMFileSystem fs = builder.build(this, head, revision);
        return new SCMProbe() {

            @NonNull
            @Override
            public SCMProbeStat stat(@NonNull String path) throws IOException {
                try {
                    return SCMProbeStat.fromType(fs.child(path).getType());
                } catch (InterruptedException e) {
                    throw new IOException("Interrupted", e);
                }
            }

            @Override
            public void close() throws IOException {
                fs.close();
            }

            @Override
            public String name() {
                return head.getName();
            }

            @Override
            public long lastModified() {
                try {
                    return fs.lastModified();
                } catch (IOException e) {
                    return 0L;
                } catch (InterruptedException e) {
                    return 0L;
                }
            }

            @Override
            public SCMFile getRoot() {
                return fs.getRoot();
            }
        };
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
}
Also used : SCMProbe(jenkins.scm.api.SCMProbe) UriTemplateBuilder(com.damnhandy.uri.template.UriTemplateBuilder) URIRequirementBuilder(com.cloudbees.plugins.credentials.domains.URIRequirementBuilder) SCMFileSystem(jenkins.scm.api.SCMFileSystem) NonNull(edu.umd.cs.findbugs.annotations.NonNull) IOException(java.io.IOException) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Aggregations

URIRequirementBuilder (com.cloudbees.plugins.credentials.domains.URIRequirementBuilder)1 UriTemplateBuilder (com.damnhandy.uri.template.UriTemplateBuilder)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 IOException (java.io.IOException)1 SCMFileSystem (jenkins.scm.api.SCMFileSystem)1 SCMProbe (jenkins.scm.api.SCMProbe)1