mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-06 23:30:55 +03:00
Build jar with correct version string automatically (Fixes #280)
This commit is contained in:
@@ -64,6 +64,15 @@ if (JavaVersion.current().isJava8Compatible()) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
task writeSshjVersionProperties << {
|
||||||
|
project.file("${project.buildDir}/resources/main").mkdirs()
|
||||||
|
project.file("${project.buildDir}/resources/main/sshj.properties").withWriter { w ->
|
||||||
|
w.append("sshj.version=${version}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jar.dependsOn writeSshjVersionProperties
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
manifest {
|
manifest {
|
||||||
instruction "Bundle-Description", "SSHv2 library for Java"
|
instruction "Bundle-Description", "SSHv2 library for Java"
|
||||||
|
|||||||
@@ -38,10 +38,8 @@ import net.schmizz.sshj.userauth.keyprovider.PKCS8KeyFile;
|
|||||||
import net.schmizz.sshj.userauth.keyprovider.PuTTYKeyFile;
|
import net.schmizz.sshj.userauth.keyprovider.PuTTYKeyFile;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.*;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link net.schmizz.sshj.Config} that is initialized as follows. Items marked with an asterisk are added to the config only if
|
* A {@link net.schmizz.sshj.Config} that is initialized as follows. Items marked with an asterisk are added to the config only if
|
||||||
@@ -68,13 +66,11 @@ import java.util.List;
|
|||||||
public class DefaultConfig
|
public class DefaultConfig
|
||||||
extends ConfigImpl {
|
extends ConfigImpl {
|
||||||
|
|
||||||
private static final String VERSION = "SSHJ_0_17_2";
|
|
||||||
|
|
||||||
private Logger log;
|
private Logger log;
|
||||||
|
|
||||||
public DefaultConfig() {
|
public DefaultConfig() {
|
||||||
setLoggerFactory(LoggerFactory.DEFAULT);
|
setLoggerFactory(LoggerFactory.DEFAULT);
|
||||||
setVersion(VERSION);
|
setVersion(readVersionFromProperties());
|
||||||
final boolean bouncyCastleRegistered = SecurityUtils.isBouncyCastleRegistered();
|
final boolean bouncyCastleRegistered = SecurityUtils.isBouncyCastleRegistered();
|
||||||
initKeyExchangeFactories(bouncyCastleRegistered);
|
initKeyExchangeFactories(bouncyCastleRegistered);
|
||||||
initRandomFactory(bouncyCastleRegistered);
|
initRandomFactory(bouncyCastleRegistered);
|
||||||
@@ -86,6 +82,18 @@ public class DefaultConfig
|
|||||||
setKeepAliveProvider(KeepAliveProvider.HEARTBEAT);
|
setKeepAliveProvider(KeepAliveProvider.HEARTBEAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String readVersionFromProperties() {
|
||||||
|
try {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("sshj.properties"));
|
||||||
|
String property = properties.getProperty("sshj.version");
|
||||||
|
return "SSHJ_" + property.replace('-', '_'); // '-' is a disallowed character, see RFC-4253#section-4.2
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Could not read the sshj.properties file, returning an 'unknown' version as fallback.");
|
||||||
|
return "SSHJ_VERSION_UNKNOWN";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLoggerFactory(LoggerFactory loggerFactory) {
|
public void setLoggerFactory(LoggerFactory loggerFactory) {
|
||||||
super.setLoggerFactory(loggerFactory);
|
super.setLoggerFactory(loggerFactory);
|
||||||
|
|||||||
17
src/test/resources/sshj.properties
Normal file
17
src/test/resources/sshj.properties
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C)2009 - SSHJ Contributors
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
|
||||||
|
sshj.version=0.18.0
|
||||||
Reference in New Issue
Block a user