mirror of
https://github.com/ethauvin/bld.git
synced 2025-04-26 08:37:11 -07:00
Better error reporting when internet is not accessible, added support for offline mode that will not access the internet for any reason.
This commit is contained in:
parent
8e02a3ac7e
commit
d904fd22b7
6 changed files with 112 additions and 59 deletions
Binary file not shown.
|
@ -485,8 +485,13 @@ public class BaseProject extends BuildExecutor {
|
||||||
@BuildCommand(value = "dependency-tree", help = DependencyTreeHelp.class)
|
@BuildCommand(value = "dependency-tree", help = DependencyTreeHelp.class)
|
||||||
public void dependencyTree()
|
public void dependencyTree()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
if (isOffline()) {
|
||||||
|
System.out.println("Offline mode: dependency-tree is disabled");
|
||||||
|
}
|
||||||
|
else {
|
||||||
dependencyTreeOperation().executeOnce(() -> dependencyTreeOperation().fromProject(this));
|
dependencyTreeOperation().executeOnce(() -> dependencyTreeOperation().fromProject(this));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard build command, downloads all dependencies of the project.
|
* Standard build command, downloads all dependencies of the project.
|
||||||
|
@ -496,8 +501,13 @@ public class BaseProject extends BuildExecutor {
|
||||||
@BuildCommand(help = DownloadHelp.class)
|
@BuildCommand(help = DownloadHelp.class)
|
||||||
public void download()
|
public void download()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
if (isOffline()) {
|
||||||
|
System.out.println("Offline mode: download is disabled");
|
||||||
|
}
|
||||||
|
else {
|
||||||
downloadOperation().executeOnce(() -> downloadOperation().fromProject(this));
|
downloadOperation().executeOnce(() -> downloadOperation().fromProject(this));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard build command, purges all unused artifacts from the project.
|
* Standard build command, purges all unused artifacts from the project.
|
||||||
|
@ -507,8 +517,13 @@ public class BaseProject extends BuildExecutor {
|
||||||
@BuildCommand(help = PurgeHelp.class)
|
@BuildCommand(help = PurgeHelp.class)
|
||||||
public void purge()
|
public void purge()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
if (isOffline()) {
|
||||||
|
System.out.println("Offline mode: purge is disabled");
|
||||||
|
}
|
||||||
|
else {
|
||||||
purgeOperation().executeOnce(() -> purgeOperation().fromProject(this));
|
purgeOperation().executeOnce(() -> purgeOperation().fromProject(this));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard build command, runs the project.
|
* Standard build command, runs the project.
|
||||||
|
@ -1674,7 +1689,8 @@ public class BaseProject extends BuildExecutor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int execute(String[] arguments) {
|
public int execute(String[] arguments) {
|
||||||
if (autoDownloadPurge()) {
|
if (!isOffline() &&
|
||||||
|
autoDownloadPurge()) {
|
||||||
performAutoDownloadPurge();
|
performAutoDownloadPurge();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ public class BuildExecutor {
|
||||||
public static final String BLD_PROPERTIES = "bld.properties";
|
public static final String BLD_PROPERTIES = "bld.properties";
|
||||||
public static final String LOCAL_PROPERTIES = "local.properties";
|
public static final String LOCAL_PROPERTIES = "local.properties";
|
||||||
|
|
||||||
|
private static final String ARG_OFFLINE = "--offline";
|
||||||
private static final String ARG_HELP1 = "--help";
|
private static final String ARG_HELP1 = "--help";
|
||||||
private static final String ARG_HELP2 = "-h";
|
private static final String ARG_HELP2 = "-h";
|
||||||
private static final String ARG_HELP3 = "-?";
|
private static final String ARG_HELP3 = "-?";
|
||||||
|
@ -42,6 +43,7 @@ public class BuildExecutor {
|
||||||
|
|
||||||
private final HierarchicalProperties properties_;
|
private final HierarchicalProperties properties_;
|
||||||
private List<String> arguments_ = Collections.emptyList();
|
private List<String> arguments_ = Collections.emptyList();
|
||||||
|
private boolean offline_ = false;
|
||||||
private Map<String, CommandDefinition> buildCommands_ = null;
|
private Map<String, CommandDefinition> buildCommands_ = null;
|
||||||
private Map<String, String> buildAliases_ = null;
|
private Map<String, String> buildAliases_ = null;
|
||||||
private final AtomicReference<String> currentCommandName_ = new AtomicReference<>();
|
private final AtomicReference<String> currentCommandName_ = new AtomicReference<>();
|
||||||
|
@ -126,7 +128,18 @@ public class BuildExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the properties uses by this conversation.
|
* Returns whether the bld execution is intended to be offline.
|
||||||
|
*
|
||||||
|
* @return {@code true} if the execution is intended to be offline;
|
||||||
|
* or {@code false} otherwise
|
||||||
|
* @since 2.0
|
||||||
|
*/
|
||||||
|
public boolean isOffline() {
|
||||||
|
return offline_;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the properties uses for bld execution.
|
||||||
*
|
*
|
||||||
* @return the instance of {@code HierarchicalProperties} that is used
|
* @return the instance of {@code HierarchicalProperties} that is used
|
||||||
* by this build executor
|
* by this build executor
|
||||||
|
@ -275,6 +288,11 @@ public class BuildExecutor {
|
||||||
* @since 1.5.1
|
* @since 1.5.1
|
||||||
*/
|
*/
|
||||||
public void start(String[] arguments) {
|
public void start(String[] arguments) {
|
||||||
|
if (arguments.length > 0 && arguments[0].equals(ARG_OFFLINE)) {
|
||||||
|
offline_ = true;
|
||||||
|
arguments = Arrays.copyOfRange(arguments, 1, arguments.length);
|
||||||
|
}
|
||||||
|
|
||||||
System.exit(execute(arguments));
|
System.exit(execute(arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -191,8 +191,13 @@ public class Project extends BaseProject {
|
||||||
jar();
|
jar();
|
||||||
jarSources();
|
jarSources();
|
||||||
jarJavadoc();
|
jarJavadoc();
|
||||||
|
if (isOffline()) {
|
||||||
|
System.out.println("Offline mode: publish is disabled");
|
||||||
|
}
|
||||||
|
else {
|
||||||
publishOperation().executeOnce(() -> publishOperation().fromProject(this));
|
publishOperation().executeOnce(() -> publishOperation().fromProject(this));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard publish-local command, transfers artifacts to the local maven repository.
|
* Standard publish-local command, transfers artifacts to the local maven repository.
|
||||||
|
|
|
@ -155,6 +155,7 @@ public class HelpOperation {
|
||||||
|
|
||||||
System.err.println("""
|
System.err.println("""
|
||||||
|
|
||||||
|
--offline Work without internet (only as first argument)
|
||||||
--json Output help in JSON format
|
--json Output help in JSON format
|
||||||
-?, -h, --help Shows this help message
|
-?, -h, --help Shows this help message
|
||||||
-D<name>=<value> Set a JVM system property
|
-D<name>=<value> Set a JVM system property
|
||||||
|
|
|
@ -41,6 +41,7 @@ public class Wrapper {
|
||||||
|
|
||||||
public static final String BUILD_ARGUMENT = "--build";
|
public static final String BUILD_ARGUMENT = "--build";
|
||||||
public static final String JSON_ARGUMENT = "--json";
|
public static final String JSON_ARGUMENT = "--json";
|
||||||
|
public static final String OFFLINE_ARGUMENT = "--offline";
|
||||||
public static final String HELP_COMMAND = "help";
|
public static final String HELP_COMMAND = "help";
|
||||||
|
|
||||||
static final String MAVEN_CENTRAL = "https://repo1.maven.org/maven2/";
|
static final String MAVEN_CENTRAL = "https://repo1.maven.org/maven2/";
|
||||||
|
@ -79,6 +80,7 @@ public class Wrapper {
|
||||||
|
|
||||||
private File currentDir_ = new File(System.getProperty("user.dir"));
|
private File currentDir_ = new File(System.getProperty("user.dir"));
|
||||||
private LaunchMode launchMode_ = LaunchMode.Cli;
|
private LaunchMode launchMode_ = LaunchMode.Cli;
|
||||||
|
private boolean offline_ = false;
|
||||||
|
|
||||||
private final Properties jvmProperties_ = new Properties();
|
private final Properties jvmProperties_ = new Properties();
|
||||||
private final Properties wrapperProperties_ = new Properties();
|
private final Properties wrapperProperties_ = new Properties();
|
||||||
|
@ -389,6 +391,15 @@ public class Wrapper {
|
||||||
arguments.remove(0);
|
arguments.remove(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// first argument after the --build argument is the main build file
|
||||||
|
// arguments.get(0)
|
||||||
|
|
||||||
|
// check if the next argument enables offline mode
|
||||||
|
if (arguments.size() >= 2 &&
|
||||||
|
OFFLINE_ARGUMENT.equals(arguments.get(1))) {
|
||||||
|
offline_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
var help_index = arguments.indexOf(HELP_COMMAND);
|
var help_index = arguments.indexOf(HELP_COMMAND);
|
||||||
if (help_index != -1) {
|
if (help_index != -1) {
|
||||||
try {
|
try {
|
||||||
|
@ -405,12 +416,7 @@ public class Wrapper {
|
||||||
try {
|
try {
|
||||||
extractJvmProperties(arguments);
|
extractJvmProperties(arguments);
|
||||||
initWrapperProperties(getVersion());
|
initWrapperProperties(getVersion());
|
||||||
File distribution;
|
var distribution = installDistribution();
|
||||||
try {
|
|
||||||
distribution = installDistribution();
|
|
||||||
} catch (IOException e) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return launchMain(distribution, arguments);
|
return launchMain(distribution, arguments);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -513,16 +519,19 @@ public class Wrapper {
|
||||||
var download_version = version;
|
var download_version = version;
|
||||||
var is_snapshot = isSnapshot(version);
|
var is_snapshot = isSnapshot(version);
|
||||||
var is_local = false;
|
var is_local = false;
|
||||||
|
if (offline_) {
|
||||||
|
System.out.println("Offline mode: no artifacts will be checked nor downloaded");
|
||||||
|
System.out.flush();
|
||||||
|
}
|
||||||
|
else {
|
||||||
if (is_snapshot) {
|
if (is_snapshot) {
|
||||||
var meta_data = "";
|
var meta_data = "";
|
||||||
try {
|
try {
|
||||||
meta_data = readString(version, new URL(downloadUrl(version, "maven-metadata.xml")));
|
meta_data = readString(version, new URL(downloadUrl(version, "maven-metadata.xml")));
|
||||||
}
|
} catch (IOException e) {
|
||||||
catch (IOException e) {
|
|
||||||
try {
|
try {
|
||||||
meta_data = readString(version, new URL(downloadUrl(version, "maven-metadata-local.xml")));
|
meta_data = readString(version, new URL(downloadUrl(version, "maven-metadata-local.xml")));
|
||||||
}
|
} catch (IOException e2) {
|
||||||
catch (IOException e2) {
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -535,10 +544,12 @@ public class Wrapper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var distribution_file = new File(DISTRIBUTIONS_DIR, bldFileName(version));
|
var distribution_file = new File(DISTRIBUTIONS_DIR, bldFileName(version));
|
||||||
var distribution_sources_file = new File(DISTRIBUTIONS_DIR, bldSourcesFileName(version));
|
var distribution_sources_file = new File(DISTRIBUTIONS_DIR, bldSourcesFileName(version));
|
||||||
|
|
||||||
|
if (!offline_) {
|
||||||
// if this is a snapshot and the distribution file exists,
|
// if this is a snapshot and the distribution file exists,
|
||||||
// ensure that it's the latest by comparing hashes
|
// ensure that it's the latest by comparing hashes
|
||||||
if (is_snapshot && distribution_file.exists()) {
|
if (is_snapshot && distribution_file.exists()) {
|
||||||
|
@ -575,6 +586,7 @@ public class Wrapper {
|
||||||
// this is not critical, ignore
|
// this is not critical, ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// find the wrapper classloader in the hierarchy and add the bld jar to it
|
// find the wrapper classloader in the hierarchy and add the bld jar to it
|
||||||
classloader_ = new WrapperClassLoader();
|
classloader_ = new WrapperClassLoader();
|
||||||
|
@ -618,7 +630,8 @@ public class Wrapper {
|
||||||
|
|
||||||
private void resolveExtensions() {
|
private void resolveExtensions() {
|
||||||
if (null == classloader_ ||
|
if (null == classloader_ ||
|
||||||
null == wrapperPropertiesFile_) {
|
null == wrapperPropertiesFile_ ||
|
||||||
|
offline_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue