From fc42044949bcc34e8dcfbf767c979f2b93561c79 Mon Sep 17 00:00:00 2001 From: napoly Date: Sat, 6 May 2023 14:04:39 +0200 Subject: [PATCH 01/31] Remove edit button for BSQ offers --- .../main/offer/offerbook/OfferBookView.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java index 197e4842835..bf3ecb76fa7 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBookView.java @@ -1169,13 +1169,18 @@ public void updateItem(final OfferBookListItem item, boolean empty) { button.setStyle(CssTheme.isDarkTheme() ? "-fx-text-fill: white" : "-fx-text-fill: #444444"); button.setOnAction(e -> onRemoveOpenOffer(offer)); - iconView2.setId("image-edit"); - button2.updateText(Res.get("shared.edit")); - button2.setId(null); - button2.setStyle(CssTheme.isDarkTheme() ? "-fx-text-fill: white" : "-fx-text-fill: #444444"); - button2.setOnAction(e -> onEditOpenOffer(offer)); - button2.setManaged(true); - button2.setVisible(true); + if (offer.isBsqSwapOffer()) { + button2.setManaged(false); + button2.setVisible(false); + } else { + iconView2.setId("image-edit"); + button2.updateText(Res.get("shared.edit")); + button2.setId(null); + button2.setStyle(CssTheme.isDarkTheme() ? "-fx-text-fill: white" : "-fx-text-fill: #444444"); + button2.setOnAction(e -> onEditOpenOffer(offer)); + button2.setManaged(true); + button2.setVisible(true); + } } else { boolean isSellOffer = OfferViewUtil.isShownAsSellOffer(offer); iconView.setId(isSellOffer ? "image-buy-white" : "image-sell-white"); From 8024b728600f1ed03699009e627e7f95af45854a Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Mon, 26 Jun 2023 13:31:55 -0500 Subject: [PATCH 02/31] Add burned BSQ column in monthly burningman status report. --- .../burningman/BurningManPresentationService.java | 13 +++++++++++++ .../main/dao/burnbsq/burningman/BurningManView.java | 13 ++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/bisq/core/dao/burningman/BurningManPresentationService.java b/core/src/main/java/bisq/core/dao/burningman/BurningManPresentationService.java index d32843536cf..b78fce15aa9 100644 --- a/core/src/main/java/bisq/core/dao/burningman/BurningManPresentationService.java +++ b/core/src/main/java/bisq/core/dao/burningman/BurningManPresentationService.java @@ -45,12 +45,14 @@ import com.google.common.annotations.VisibleForTesting; import java.util.Collection; +import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import java.util.stream.LongStream; import lombok.extern.slf4j.Slf4j; @@ -359,6 +361,17 @@ public long getTotalAmountOfBurnedBsq() { .sum(); } + public long getBsqBurnedByMonth(Date dateFilter) { + Set defaultZeroBurn = new HashSet<>(); + defaultZeroBurn.add(new BurnOutputModel(0, 0, 0, "", 0L, 0)); + Map burningMen = getBurningManCandidatesByName(); + return burningMen.values().stream() + .map(burningMan -> burningMan.getBurnOutputModelsByMonth().getOrDefault(dateFilter, defaultZeroBurn).stream() + .mapToLong(BurnOutputModel::getAmount)) + .mapToLong(LongStream::sum) + .sum(); + } + public String getGenesisTxId() { return daoStateService.getGenesisTxId(); } diff --git a/desktop/src/main/java/bisq/desktop/main/dao/burnbsq/burningman/BurningManView.java b/desktop/src/main/java/bisq/desktop/main/dao/burnbsq/burningman/BurningManView.java index dd2acd47eac..4bbfdefcfac 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/burnbsq/burningman/BurningManView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/burnbsq/burningman/BurningManView.java @@ -675,7 +675,7 @@ private void onUpdateAvailableBalance(Coin availableBalance) { private void exportToCSV() { List result = new ArrayList<>(); String separator = "~"; - String tableColumns = "Month~BTC Fees~Fees as BSQ~DPT as BTC~DPT as BSQ~Distributed BTC~Distributed BTC as BSQ"; + String tableColumns = "Month~BTC Fees~Fees as BSQ~DPT as BTC~DPT as BSQ~Distributed BTC~Distributed BTC as BSQ~BSQ burned"; CSVEntryConverter headerConverter = item -> tableColumns.split(separator); CSVEntryConverter contentConverter = item -> item.split(separator); Date now = new Date(); @@ -686,6 +686,7 @@ private void exportToCSV() { long feeAsBsqSum = 0; long dptAsBsqSum = 0; long distributedBtcAsBsqSum = 0; + long bsqBurnedSum = 0; long feeAsBsq, dptAsBsq, distributedBtcAsBsq; int year = 2023; int month = 0; @@ -697,7 +698,7 @@ private void exportToCSV() { Map averageBsqPriceByMonth = burningManAccountingService.getAverageBsqPriceByMonth(); Optional price = Optional.ofNullable(averageBsqPriceByMonth.get(date)); - + long bsqBurned = burningManPresentationService.getBsqBurnedByMonth(date); List distributedBtcBalanceByMonth = burningManAccountingService.getDistributedBtcBalanceByMonth(date) .collect(Collectors.toList()); long feeAsBtc = distributedBtcBalanceByMonth.stream() @@ -726,7 +727,7 @@ private void exportToCSV() { feeAsBsqSum += feeAsBsq; dptAsBsqSum += dptAsBsq; distributedBtcAsBsqSum += distributedBtcAsBsq; - + bsqBurnedSum += bsqBurned; line = new SimpleDateFormat("MMM yyyy", Locale.ENGLISH).format(date) + separator + btcFormatter.formatCoin(Coin.valueOf(feeAsBtc)) @@ -734,7 +735,8 @@ private void exportToCSV() { + separator + btcFormatter.formatCoin(Coin.valueOf(dptAsBtc)) + separator + bsqFormatter.formatCoin(Coin.valueOf(dptAsBsq)) + separator + btcFormatter.formatCoin(Coin.valueOf(distributedBtc)) - + separator + bsqFormatter.formatCoin(Coin.valueOf(distributedBtcAsBsq)); + + separator + bsqFormatter.formatCoin(Coin.valueOf(distributedBtcAsBsq)) + + separator + bsqFormatter.formatCoin(Coin.valueOf(bsqBurned)); result.add(line); if (++month > 11) { month = 0; @@ -750,7 +752,8 @@ private void exportToCSV() { + separator + btcFormatter.formatCoin(Coin.valueOf(dptAsBtcSum)) + separator + bsqFormatter.formatCoin(Coin.valueOf(dptAsBsqSum)) + separator + btcFormatter.formatCoin(Coin.valueOf(distributedBtcSum)) - + separator + bsqFormatter.formatCoin(Coin.valueOf(distributedBtcAsBsqSum)); + + separator + bsqFormatter.formatCoin(Coin.valueOf(distributedBtcAsBsqSum)) + + separator + bsqFormatter.formatCoin(Coin.valueOf(bsqBurnedSum)); result.add(line); GUIUtil.exportCSV("Burningman_dao_revenue.csv", headerConverter, contentConverter, From aa79b01fd301dbc696780adcc0207ba7f714a5ca Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Mon, 26 Jun 2023 18:20:13 -0500 Subject: [PATCH 03/31] Add CSV export for Proof of Burn table. --- .../burnbsq/proofofburn/ProofOfBurnView.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/desktop/src/main/java/bisq/desktop/main/dao/burnbsq/proofofburn/ProofOfBurnView.java b/desktop/src/main/java/bisq/desktop/main/dao/burnbsq/proofofburn/ProofOfBurnView.java index dc506d25386..034495b8a94 100644 --- a/desktop/src/main/java/bisq/desktop/main/dao/burnbsq/proofofburn/ProofOfBurnView.java +++ b/desktop/src/main/java/bisq/desktop/main/dao/burnbsq/proofofburn/ProofOfBurnView.java @@ -51,10 +51,15 @@ import org.bitcoinj.core.InsufficientMoneyException; import org.bitcoinj.core.Transaction; +import com.googlecode.jcsv.writer.CSVEntryConverter; + import javax.inject.Inject; import javax.inject.Named; +import javafx.stage.Stage; + import javafx.scene.control.Button; +import javafx.scene.control.Hyperlink; import javafx.scene.control.TableCell; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; @@ -62,6 +67,9 @@ import javafx.scene.control.Tooltip; import javafx.scene.layout.GridPane; +import javafx.geometry.HPos; +import javafx.geometry.Insets; + import javafx.beans.InvalidationListener; import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.beans.value.ChangeListener; @@ -72,7 +80,10 @@ import javafx.util.Callback; + +import java.util.ArrayList; import java.util.Comparator; +import java.util.List; import java.util.stream.Collectors; import static bisq.desktop.util.FormBuilder.addButtonAfterGroup; @@ -95,6 +106,7 @@ public class ProofOfBurnView extends ActivatableView implements private Button burnButton; private TableView myItemsTableView; private TableView allTxsTableView; + private Hyperlink exportAsCSVHyperlink; private final ObservableList myItemsObservableList = FXCollections.observableArrayList(); private final SortedList myItemsSortedList = new SortedList<>(myItemsObservableList); @@ -153,6 +165,14 @@ public void initialize() { createColumnsForAllTxs(); allTxsTableView.setItems(allItemsSortedList); + exportAsCSVHyperlink = new Hyperlink(Res.get("shared.exportCSV")); + GridPane.setRowIndex(exportAsCSVHyperlink, ++gridRow); + GridPane.setColumnIndex(exportAsCSVHyperlink, 0); + GridPane.setMargin(exportAsCSVHyperlink, new Insets(-5, 0, 0, 0)); + GridPane.setHalignment(exportAsCSVHyperlink, HPos.RIGHT); + root.getChildren().add(exportAsCSVHyperlink); + exportAsCSVHyperlink.setOnAction(e -> exportToCSV()); + createListeners(); } @@ -301,6 +321,27 @@ private void doPublishFeeTx(Transaction transaction, String preImageAsString) { preImageTextField.resetValidation(); } + private void exportToCSV() { + List result = new ArrayList<>(); + String separator = "~"; + String tableColumns = "Amount~Date~Hash~TxId~Pubkey"; + CSVEntryConverter headerConverter = item -> tableColumns.split(separator); + CSVEntryConverter contentConverter = item -> item.split(separator); + for (ProofOfBurnListItem item: allItemsSortedList) { + String line = bsqFormatter.formatCoin(item.getAmount()) + + separator + item.getDateAsString() + + separator + item.getHashAsHex() + + separator + item.getTxId() + + separator + item.getPubKey(); + result.add(line); + } + GUIUtil.exportCSV("proofOfBurnTransactions.csv", + headerConverter, + contentConverter, + "", + result, + (Stage) root.getScene().getWindow()); + } /////////////////////////////////////////////////////////////////////////////////////////// // Table columns From a9bc45c173e6c4d5fbfebd592c5bb8353333963e Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Fri, 30 Jun 2023 10:10:23 -0500 Subject: [PATCH 04/31] Seednode accounting set by command line, overrides UserPreferences. --- core/src/main/java/bisq/core/user/Preferences.java | 6 ++++-- core/src/test/java/bisq/core/user/PreferencesTest.java | 2 +- .../src/test/java/bisq/desktop/maker/PreferenceMakers.java | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/bisq/core/user/Preferences.java b/core/src/main/java/bisq/core/user/Preferences.java index 6a312de449a..d3630dacc74 100644 --- a/core/src/main/java/bisq/core/user/Preferences.java +++ b/core/src/main/java/bisq/core/user/Preferences.java @@ -172,7 +172,7 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid private final String btcNodesFromOptions, referralIdFromOptions, rpcUserFromOptions, rpcPwFromOptions; private final int blockNotifyPortFromOptions; - private final boolean fullDaoNodeFromOptions; + private final boolean fullDaoNodeFromOptions, fullAccountingNodeFromOptions; @Getter private final BooleanProperty useStandbyModeProperty = new SimpleBooleanProperty(prefPayload.isUseStandbyMode()); @@ -189,6 +189,7 @@ public Preferences(PersistenceManager persistenceManager, @Named(Config.BTC_NODES) String btcNodesFromOptions, @Named(Config.REFERRAL_ID) String referralId, @Named(Config.FULL_DAO_NODE) boolean fullDaoNode, + @Named(Config.IS_BM_FULL_NODE) boolean fullAccountingNode, @Named(Config.RPC_USER) String rpcUser, @Named(Config.RPC_PASSWORD) String rpcPassword, @Named(Config.RPC_BLOCK_NOTIFICATION_PORT) int rpcBlockNotificationPort) { @@ -200,6 +201,7 @@ public Preferences(PersistenceManager persistenceManager, this.btcNodesFromOptions = btcNodesFromOptions; this.referralIdFromOptions = referralId; this.fullDaoNodeFromOptions = fullDaoNode; + this.fullAccountingNodeFromOptions = fullAccountingNode; this.rpcUserFromOptions = rpcUser; this.rpcPwFromOptions = rpcPassword; this.blockNotifyPortFromOptions = rpcBlockNotificationPort; @@ -1018,7 +1020,7 @@ public List getDefaultTxBroadcastServices() { } public boolean isProcessBurningManAccountingData() { - return prefPayload.isProcessBurningManAccountingData(); + return fullAccountingNodeFromOptions || prefPayload.isProcessBurningManAccountingData(); } diff --git a/core/src/test/java/bisq/core/user/PreferencesTest.java b/core/src/test/java/bisq/core/user/PreferencesTest.java index 8a5516abbb3..d56ce3d4e53 100644 --- a/core/src/test/java/bisq/core/user/PreferencesTest.java +++ b/core/src/test/java/bisq/core/user/PreferencesTest.java @@ -62,7 +62,7 @@ public void setUp() { LocalBitcoinNode localBitcoinNode = new LocalBitcoinNode(config); preferences = new Preferences( persistenceManager, config, null, localBitcoinNode, null, null, Config.DEFAULT_FULL_DAO_NODE, - null, null, Config.UNSPECIFIED_PORT); + false, null, null, Config.UNSPECIFIED_PORT); } @Test diff --git a/desktop/src/test/java/bisq/desktop/maker/PreferenceMakers.java b/desktop/src/test/java/bisq/desktop/maker/PreferenceMakers.java index daba0458a1d..a6bbab9f547 100644 --- a/desktop/src/test/java/bisq/desktop/maker/PreferenceMakers.java +++ b/desktop/src/test/java/bisq/desktop/maker/PreferenceMakers.java @@ -47,7 +47,7 @@ public class PreferenceMakers { lookup.valueOf(localBitcoinNode, new SameValueDonor(null)), lookup.valueOf(useTorFlagFromOptions, new SameValueDonor(null)), lookup.valueOf(referralID, new SameValueDonor(null)), - Config.DEFAULT_FULL_DAO_NODE, null, null, Config.UNSPECIFIED_PORT); + Config.DEFAULT_FULL_DAO_NODE, false, null, null, Config.UNSPECIFIED_PORT); public static final Preferences empty = make(a(Preferences)); From 1ebc92e5b890e2b24d9b954eba657163abeed900 Mon Sep 17 00:00:00 2001 From: HenrikJannsen Date: Thu, 22 Jun 2023 19:10:04 +0200 Subject: [PATCH 05/31] Add reset buttons for BM accounting --- .../BurningManAccountingService.java | 9 ++ .../node/AccountingNodeProvider.java | 13 +- .../storage/BurningManAccountingStore.java | 10 ++ .../BurningManAccountingStoreService.java | 21 +++ .../main/java/bisq/core/user/Preferences.java | 15 +- .../bisq/core/user/PreferencesPayload.java | 10 +- .../resources/i18n/displayStrings.properties | 22 +++ .../settings/preferences/PreferencesView.java | 131 +++++++++++++++--- proto/src/main/proto/pb.proto | 1 + 9 files changed, 204 insertions(+), 28 deletions(-) diff --git a/core/src/main/java/bisq/core/dao/burningman/accounting/BurningManAccountingService.java b/core/src/main/java/bisq/core/dao/burningman/accounting/BurningManAccountingService.java index 3605eb981de..bf5138e91fc 100644 --- a/core/src/main/java/bisq/core/dao/burningman/accounting/BurningManAccountingService.java +++ b/core/src/main/java/bisq/core/dao/burningman/accounting/BurningManAccountingService.java @@ -271,6 +271,15 @@ public Stream getDistributedBtcBalanceByMonth(Date mont } + public void resyncAccountingDataFromScratch(Runnable resultHandler) { + burningManAccountingStoreService.removeAllBlocks(resultHandler); + } + + public void resyncAccountingDataFromResources() { + burningManAccountingStoreService.deleteStorageFile(); + } + + /////////////////////////////////////////////////////////////////////////////////////////// // Delegates /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/main/java/bisq/core/dao/burningman/accounting/node/AccountingNodeProvider.java b/core/src/main/java/bisq/core/dao/burningman/accounting/node/AccountingNodeProvider.java index b138067e762..cdfde45a6e8 100644 --- a/core/src/main/java/bisq/core/dao/burningman/accounting/node/AccountingNodeProvider.java +++ b/core/src/main/java/bisq/core/dao/burningman/accounting/node/AccountingNodeProvider.java @@ -38,15 +38,16 @@ public class AccountingNodeProvider { @Inject public AccountingNodeProvider(AccountingLiteNode liteNode, AccountingFullNode fullNode, - @Named(Config.IS_BM_FULL_NODE) boolean isBmFullNode, + @Named(Config.IS_BM_FULL_NODE) boolean isBmFullNodeFromOptions, Preferences preferences) { - boolean rpcDataSet = preferences.getRpcUser() != null && - !preferences.getRpcUser().isEmpty() - && preferences.getRpcPw() != null && - !preferences.getRpcPw().isEmpty() && + String rpcUser = preferences.getRpcUser(); + String rpcPw = preferences.getRpcPw(); + boolean rpcDataSet = rpcUser != null && !rpcUser.isEmpty() && + rpcPw != null && !rpcPw.isEmpty() && preferences.getBlockNotifyPort() > 0; - if (isBmFullNode && rpcDataSet) { + boolean fullBMAccountingNode = preferences.isFullBMAccountingNode(); + if ((fullBMAccountingNode || isBmFullNodeFromOptions) && rpcDataSet) { accountingNode = fullNode; } else { accountingNode = liteNode; diff --git a/core/src/main/java/bisq/core/dao/burningman/accounting/storage/BurningManAccountingStore.java b/core/src/main/java/bisq/core/dao/burningman/accounting/storage/BurningManAccountingStore.java index 50b456cbe40..cc80331f926 100644 --- a/core/src/main/java/bisq/core/dao/burningman/accounting/storage/BurningManAccountingStore.java +++ b/core/src/main/java/bisq/core/dao/burningman/accounting/storage/BurningManAccountingStore.java @@ -81,6 +81,16 @@ public void purgeLastTenBlocks() { } } + public void removeAllBlocks() { + Lock writeLock = readWriteLock.writeLock(); + writeLock.lock(); + try { + blocks.clear(); + } finally { + writeLock.unlock(); + } + } + public Optional getLastBlock() { Lock readLock = readWriteLock.readLock(); readLock.lock(); diff --git a/core/src/main/java/bisq/core/dao/burningman/accounting/storage/BurningManAccountingStoreService.java b/core/src/main/java/bisq/core/dao/burningman/accounting/storage/BurningManAccountingStoreService.java index 98aa41a7bae..d35f816c595 100644 --- a/core/src/main/java/bisq/core/dao/burningman/accounting/storage/BurningManAccountingStoreService.java +++ b/core/src/main/java/bisq/core/dao/burningman/accounting/storage/BurningManAccountingStoreService.java @@ -49,6 +49,7 @@ @Singleton public class BurningManAccountingStoreService extends StoreService { private static final String FILE_NAME = "BurningManAccountingStore_v2"; + private volatile boolean removeAllBlocksCalled; @Inject public BurningManAccountingStoreService(ResourceDataStoreService resourceDataStoreService, @@ -82,6 +83,9 @@ public void requestPersistence() { } public void addIfNewBlock(AccountingBlock block) throws BlockHashNotConnectingException, BlockHeightNotConnectingException { + if (removeAllBlocksCalled) { + return; + } store.addIfNewBlock(block); requestPersistence(); } @@ -91,10 +95,27 @@ public void forEachBlock(Consumer consumer) { } public void purgeLastTenBlocks() { + if (removeAllBlocksCalled) { + return; + } store.purgeLastTenBlocks(); requestPersistence(); } + public void removeAllBlocks(Runnable resultHandler) { + removeAllBlocksCalled = true; + store.removeAllBlocks(); + persistenceManager.persistNow(resultHandler); + } + + public void deleteStorageFile() { + try { + FileUtil.deleteFileIfExists(Path.of(absolutePathOfStorageDir, FILE_NAME).toFile()); + } catch (IOException e) { + e.printStackTrace(); + } + } + public Optional getLastBlock() { return store.getLastBlock(); } diff --git a/core/src/main/java/bisq/core/user/Preferences.java b/core/src/main/java/bisq/core/user/Preferences.java index d3630dacc74..3da0cdd85d9 100644 --- a/core/src/main/java/bisq/core/user/Preferences.java +++ b/core/src/main/java/bisq/core/user/Preferences.java @@ -772,7 +772,7 @@ public void setTakeOfferSelectedPaymentAccountId(String value) { public void setDaoFullNode(boolean value) { // We only persist if we have not set the program argument - if (config.fullDaoNodeOptionSetExplicitly) { + if (!config.fullDaoNodeOptionSetExplicitly) { prefPayload.setDaoFullNode(value); requestPersistence(); } @@ -853,6 +853,11 @@ public void setProcessBurningManAccountingData(boolean processBurningManAccounti requestPersistence(); } + public void setFullBMAccountingNode(boolean isFullBMAccountingNode) { + prefPayload.setFullBMAccountingNode(isFullBMAccountingNode); + requestPersistence(); + } + /////////////////////////////////////////////////////////////////////////////////////////// // Getter @@ -1023,6 +1028,10 @@ public boolean isProcessBurningManAccountingData() { return fullAccountingNodeFromOptions || prefPayload.isProcessBurningManAccountingData(); } + public boolean isFullBMAccountingNode() { + return prefPayload.isFullBMAccountingNode(); + } + /////////////////////////////////////////////////////////////////////////////////////////// // Private @@ -1145,6 +1154,8 @@ private interface ExcludesDelegateMethods { boolean isProcessBurningManAccountingData(); + boolean isFullBMAccountingNode(); + void setDaoFullNode(boolean value); void setRpcUser(String value); @@ -1190,5 +1201,7 @@ private interface ExcludesDelegateMethods { void setUserHasRaisedTradeLimit(boolean userHasRaisedTradeLimit); void setProcessBurningManAccountingData(boolean processBurningManAccountingData); + + void setFullBMAccountingNode(boolean isFullBMAccountingNode); } } diff --git a/core/src/main/java/bisq/core/user/PreferencesPayload.java b/core/src/main/java/bisq/core/user/PreferencesPayload.java index eb74be1b6ef..761f9c89344 100644 --- a/core/src/main/java/bisq/core/user/PreferencesPayload.java +++ b/core/src/main/java/bisq/core/user/PreferencesPayload.java @@ -148,6 +148,10 @@ public final class PreferencesPayload implements PersistableEnvelope { // Added at 1.9.11 private boolean processBurningManAccountingData = false; + // Added at 1.9.11 + private boolean isFullBMAccountingNode = false; + + /////////////////////////////////////////////////////////////////////////////////////////// // Constructor /////////////////////////////////////////////////////////////////////////////////////////// @@ -220,7 +224,8 @@ public Message toProtoMessage() { .setUseBitcoinUrisInQrCodes(useBitcoinUrisInQrCodes) .setUserDefinedTradeLimit(userDefinedTradeLimit) .setUserHasRaisedTradeLimit(userHasRaisedTradeLimit) - .setProcessBurningManAccountingData(processBurningManAccountingData); + .setProcessBurningManAccountingData(processBurningManAccountingData) + .setIsFullBMAccountingNode(isFullBMAccountingNode); Optional.ofNullable(backupDirectory).ifPresent(builder::setBackupDirectory); Optional.ofNullable(preferredTradeCurrency).ifPresent(e -> builder.setPreferredTradeCurrency((protobuf.TradeCurrency) e.toProtoMessage())); @@ -328,7 +333,8 @@ public static PreferencesPayload fromProto(protobuf.PreferencesPayload proto, Co proto.getUseBitcoinUrisInQrCodes(), proto.getUserHasRaisedTradeLimit() ? proto.getUserDefinedTradeLimit() : Preferences.INITIAL_TRADE_LIMIT, proto.getUserHasRaisedTradeLimit(), - proto.getProcessBurningManAccountingData() + proto.getProcessBurningManAccountingData(), + proto.getIsFullBMAccountingNode() ); } } diff --git a/core/src/main/resources/i18n/displayStrings.properties b/core/src/main/resources/i18n/displayStrings.properties index a2e5bb9393b..abfc4a6e876 100644 --- a/core/src/main/resources/i18n/displayStrings.properties +++ b/core/src/main/resources/i18n/displayStrings.properties @@ -1427,6 +1427,28 @@ setting.preferences.resetAllFlags=Reset all \"Don't show again\" flags settings.preferences.languageChange=To apply the language change to all screens requires a restart. settings.preferences.supportLanguageWarning=In case of a dispute, please note that mediation is handled in {0} and arbitration in {1}. setting.preferences.daoOptions=DAO options + +setting.preferences.dao.resyncBMAccFromScratch=Resync from scratch +setting.preferences.dao.resyncBMAccFromScratch.popup=To resync the Burningmen accounting data from scratch you need to run a full Bitcoin node.\n\ + It will take considerable time and CPU resources as it resyncs from 2020 when legacy BM started. Depending on your CPU resources that can take 20-40 hours.\n\n\ + Are you sure you want to do that?\n\n\ + Mostly a resync from latest resource files is sufficient and much faster.\n\n\ + If you proceed, after an application restart the Burningmen accounting data will be rebuild from the transactions requested from your Bitcoin node. +setting.preferences.dao.resyncBMAccFromScratch.resync=Resync from scratch and shutdown +setting.preferences.dao.isFullBMAccountingNode=Full BM accounting node +setting.preferences.dao.resyncBMAccFromResources=Resync from resources +setting.preferences.dao.resyncBMAccFromResources.popup=To resync the Burningmen accounting data from resources you \ + will reapply the data from resources of your last downloaded Bisq version and load the missing data from the network.\n\ + Depending on the age of your last Bisq download that might take a while.\n\n\ + Are you sure you want to do that? +setting.preferences.dao.resyncBMAccFromResources.resync=Resync from resources and shutdown + +setting.preferences.dao.useFullBMAccountingNode.noDaoMode.popup=To run as full Burningmen accounting node you need to run as full DAO node as well.\n\n\ + Please enable first the Full-DAO mode option and config RPC. +setting.preferences.dao.useFullBMAccountingNode.enabledDaoMode.popup=To run as full Burningmen accounting node can take considerable time and CPU resources.\n\n\ + A restart is required to enable that change.\n\n\ + Do you want to enable full Burningmen accounting mode?. + setting.preferences.dao.resyncFromGenesis.label=Rebuild DAO state from genesis tx setting.preferences.dao.resyncFromResources.label=Rebuild DAO state from resources setting.preferences.dao.resyncFromResources.popup=After an application restart the Bisq network governance data will be reloaded from \ diff --git a/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java b/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java index b3c640df040..b2227ff8e93 100644 --- a/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java +++ b/desktop/src/main/java/bisq/desktop/main/settings/preferences/PreferencesView.java @@ -35,6 +35,7 @@ import bisq.core.btc.wallet.Restrictions; import bisq.core.dao.DaoFacade; +import bisq.core.dao.burningman.accounting.BurningManAccountingService; import bisq.core.dao.governance.asset.AssetService; import bisq.core.filter.Filter; import bisq.core.filter.FilterManager; @@ -122,6 +123,7 @@ @FxmlView public class PreferencesView extends ActivatableViewAndModel { private final User user; + private final BurningManAccountingService burningManAccountingService; private final CoinFormatter formatter; private TextField btcExplorerTextField, bsqExplorerTextField; private ComboBox userLanguageComboBox; @@ -131,7 +133,8 @@ public class PreferencesView extends ActivatableViewAndModel fiatCurrenciesListView; @@ -154,6 +158,7 @@ public class PreferencesView extends ActivatableViewAndModel cryptoCurrenciesListView; private ComboBox cryptoCurrenciesComboBox; private Button resetDontShowAgainButton, resyncDaoFromGenesisButton, resyncDaoFromResourcesButton, + resyncBMAccFromScratchButton, resyncBMAccFromResourcesButton, editCustomBtcExplorer, editCustomBsqExplorer; private ObservableList languageCodes; private ObservableList countries; @@ -169,7 +174,7 @@ public class PreferencesView extends ActivatableViewAndModel deviationFocusedListener, bsqAverageTrimThresholdFocusedListener; private ChangeListener useCustomFeeCheckboxListener; private ChangeListener transactionFeeChangeListener; - private final boolean daoOptionsSet; + private final boolean daoFullModeFromOptionsSet; private final boolean displayStandbyModeFeature; private ChangeListener filterChangeListener; @@ -188,13 +193,16 @@ public PreferencesView(PreferencesViewModel model, DaoFacade daoFacade, Config config, User user, + BurningManAccountingService burningManAccountingService, @Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter, + @Named(Config.IS_BM_FULL_NODE) boolean isBmFullNodeFromOptions, @Named(Config.RPC_USER) String rpcUser, @Named(Config.RPC_PASSWORD) String rpcPassword, @Named(Config.RPC_BLOCK_NOTIFICATION_PORT) int rpcBlockNotificationPort, @Named(Config.STORAGE_DIR) File storageDir) { super(model); this.user = user; + this.burningManAccountingService = burningManAccountingService; this.formatter = formatter; this.preferences = preferences; this.feeService = feeService; @@ -202,11 +210,12 @@ public PreferencesView(PreferencesViewModel model, this.offerFilterService = offerFilterService; this.filterManager = filterManager; this.daoFacade = daoFacade; + this.isBmFullNodeFromOptions = isBmFullNodeFromOptions; this.storageDir = storageDir; - daoOptionsSet = config.fullDaoNodeOptionSetExplicitly && - !rpcUser.isEmpty() && - !rpcPassword.isEmpty() && - rpcBlockNotificationPort != Config.UNSPECIFIED_PORT; + daoFullModeFromOptionsSet = config.fullDaoNodeOptionSetExplicitly && + rpcUser != null && !rpcUser.isEmpty() && + rpcPassword != null && !rpcPassword.isEmpty() && + rpcBlockNotificationPort > Config.UNSPECIFIED_PORT; this.displayStandbyModeFeature = Utilities.isLinux() || Utilities.isOSX() || Utilities.isWindows(); } @@ -676,12 +685,27 @@ private void initializeDisplayOptions() { } private void initializeDaoOptions() { - int rowSpan = 6; - daoOptionsTitledGroupBg = addTitledGroupBg(root, ++gridRow, rowSpan, + daoOptionsTitledGroupBg = addTitledGroupBg(root, ++gridRow, 8, Res.get("setting.preferences.daoOptions"), Layout.GROUP_DISTANCE); processBurningManAccountingDataToggleButton = addSlideToggleButton(root, gridRow, Res.get("setting.preferences.dao.processBurningManAccountingData"), Layout.FIRST_ROW_AND_GROUP_DISTANCE); + isFullBMAccountingDataNodeToggleButton = addSlideToggleButton(root, ++gridRow, Res.get("setting.preferences.dao.isFullBMAccountingNode")); + isFullBMAccountingDataNodeToggleButton.setManaged(preferences.isProcessBurningManAccountingData()); + isFullBMAccountingDataNodeToggleButton.setVisible(preferences.isProcessBurningManAccountingData()); + + resyncBMAccFromScratchButton = addButton(root, ++gridRow, Res.get("setting.preferences.dao.resyncBMAccFromScratch")); + resyncBMAccFromScratchButton.setMaxWidth(Double.MAX_VALUE); + GridPane.setHgrow(resyncBMAccFromScratchButton, Priority.ALWAYS); + resyncBMAccFromScratchButton.setManaged(preferences.isProcessBurningManAccountingData()); + resyncBMAccFromScratchButton.setVisible(preferences.isProcessBurningManAccountingData()); + + resyncBMAccFromResourcesButton = addButton(root, ++gridRow, Res.get("setting.preferences.dao.resyncBMAccFromResources")); + resyncBMAccFromResourcesButton.setMaxWidth(Double.MAX_VALUE); + GridPane.setHgrow(resyncBMAccFromResourcesButton, Priority.ALWAYS); + resyncBMAccFromResourcesButton.setManaged(preferences.isProcessBurningManAccountingData()); + resyncBMAccFromResourcesButton.setVisible(preferences.isProcessBurningManAccountingData()); + fullModeDaoMonitorToggleButton = addSlideToggleButton(root, ++gridRow, Res.get("setting.preferences.dao.fullModeDaoMonitor")); @@ -1118,6 +1142,36 @@ private void activateDaoPreferences() { } }); + boolean isDaoModeEnabled = isDaoModeEnabled(); + boolean isFullBMAccountingNode = (isBmFullNodeFromOptions || preferences.isFullBMAccountingNode()) && isDaoModeEnabled; + preferences.setFullBMAccountingNode(isFullBMAccountingNode); + isFullBMAccountingDataNodeToggleButton.setSelected(isFullBMAccountingNode); + + isFullBMAccountingDataNodeToggleButton.setOnAction(e -> { + if (isFullBMAccountingDataNodeToggleButton.isSelected()) { + if (isDaoModeEnabled()) { + new Popup().attention(Res.get("setting.preferences.dao.useFullBMAccountingNode.enabledDaoMode.popup")) + .actionButtonText(Res.get("shared.yes")) + .onAction(() -> { + preferences.setFullBMAccountingNode(true); + UserThread.runAfter(BisqApp.getShutDownHandler(), 500, TimeUnit.MILLISECONDS); + }) + .closeButtonText(Res.get("shared.cancel")) + .onClose(() -> isFullBMAccountingDataNodeToggleButton.setSelected(false)) + .show(); + } else { + new Popup().attention(Res.get("setting.preferences.dao.useFullBMAccountingNode.noDaoMode.popup")) + .actionButtonText(Res.get("shared.ok")) + .onAction(() -> isFullBMAccountingDataNodeToggleButton.setSelected(false)) + .onClose(() -> isFullBMAccountingDataNodeToggleButton.setSelected(false)) + .show(); + } + } else { + preferences.setFullBMAccountingNode(false); + } + }); + + fullModeDaoMonitorToggleButton.setSelected(preferences.isUseFullModeDaoMonitor()); fullModeDaoMonitorToggleButton.setOnAction(e -> { preferences.setUseFullModeDaoMonitor(fullModeDaoMonitorToggleButton.isSelected()); @@ -1133,8 +1187,7 @@ private void activateDaoPreferences() { } }); - boolean daoFullNode = preferences.isDaoFullNode(); - isDaoFullNodeToggleButton.setSelected(daoFullNode); + isDaoFullNodeToggleButton.setSelected(isDaoModeEnabled); bsqAverageTrimThresholdTextField.textProperty().addListener(bsqAverageTrimThresholdListener); bsqAverageTrimThresholdTextField.focusedProperty().addListener(bsqAverageTrimThresholdFocusedListener); @@ -1142,9 +1195,10 @@ private void activateDaoPreferences() { String rpcUser = preferences.getRpcUser(); String rpcPw = preferences.getRpcPw(); int blockNotifyPort = preferences.getBlockNotifyPort(); - if (daoFullNode && (rpcUser == null || rpcUser.isEmpty() || - rpcPw == null || rpcPw.isEmpty() || - blockNotifyPort <= 0)) { + boolean rpcDataFromPrefSet = rpcUser != null && !rpcUser.isEmpty() && + rpcPw != null && !rpcPw.isEmpty() && + blockNotifyPort > 0; + if (!daoFullModeFromOptionsSet && !rpcDataFromPrefSet) { log.warn("You have full DAO node selected but have not provided the rpc username, password and " + "block notify port. We reset daoFullNode to false"); isDaoFullNodeToggleButton.setSelected(false); @@ -1175,6 +1229,23 @@ private void activateDaoPreferences() { .closeButtonText(Res.get("shared.cancel")) .show()); + resyncBMAccFromScratchButton.setOnAction(e -> + new Popup().attention(Res.get("setting.preferences.dao.resyncBMAccFromScratch.popup")) + .actionButtonText(Res.get("setting.preferences.dao.resyncBMAccFromScratch.resync")) + .onAction(() -> burningManAccountingService.resyncAccountingDataFromScratch(BisqApp::getShutDownHandler)) + .closeButtonText(Res.get("shared.cancel")) + .show()); + + resyncBMAccFromResourcesButton.setOnAction(e -> + new Popup().attention(Res.get("setting.preferences.dao.resyncBMAccFromResources.popup")) + .actionButtonText(Res.get("setting.preferences.dao.resyncBMAccFromResources.resync")) + .onAction(() -> { + burningManAccountingService.resyncAccountingDataFromResources(); + UserThread.runAfter(BisqApp.getShutDownHandler(), 500, TimeUnit.MILLISECONDS); + }) + .closeButtonText(Res.get("shared.cancel")) + .show()); + isDaoFullNodeToggleButton.setOnAction(e -> { String key = "daoFullModeInfoShown"; if (isDaoFullNodeToggleButton.isSelected() && preferences.showAgain(key)) { @@ -1191,7 +1262,6 @@ private void activateDaoPreferences() { .width(800) .show(); } - updateDaoFields(); }); @@ -1200,6 +1270,17 @@ private void activateDaoPreferences() { blockNotifyPortTextField.textProperty().addListener(blockNotifyPortListener); } + private boolean isDaoModeEnabled() { + String rpcUser = preferences.getRpcUser(); + String rpcPw = preferences.getRpcPw(); + int blockNotifyPort = preferences.getBlockNotifyPort(); + boolean rpcDataFromPrefSet = rpcUser != null && !rpcUser.isEmpty() && + rpcPw != null && !rpcPw.isEmpty() && + blockNotifyPort > 0; + boolean daoFullModeFromPrefSet = rpcDataFromPrefSet && preferences.isDaoFullNode(); + return daoFullModeFromPrefSet || daoFullModeFromOptionsSet; + } + private void activateAutoConfirmPreferences() { preferences.findAutoConfirmSettings("XMR").ifPresent(autoConfirmSettings -> { autoConfirmXmrToggle.setSelected(autoConfirmSettings.isEnabled()); @@ -1240,7 +1321,14 @@ private void activateTradeLimitPreferences() { private void updateDaoFields() { boolean isDaoFullNode = isDaoFullNodeToggleButton.isSelected(); - GridPane.setRowSpan(daoOptionsTitledGroupBg, isDaoFullNode ? 9 : 6); + int rowSpan = 9; + if (isDaoFullNode) { + rowSpan += 3; + } + if (preferences.isProcessBurningManAccountingData()) { + rowSpan += 3; + } + GridPane.setRowSpan(daoOptionsTitledGroupBg, rowSpan); rpcUserTextField.setVisible(isDaoFullNode); rpcUserTextField.setManaged(isDaoFullNode); rpcPwTextField.setVisible(isDaoFullNode); @@ -1252,12 +1340,14 @@ private void updateDaoFields() { rpcUserTextField.clear(); rpcPwTextField.clear(); blockNotifyPortTextField.clear(); + preferences.setFullBMAccountingNode(false); + isFullBMAccountingDataNodeToggleButton.setSelected(false); } - isDaoFullNodeToggleButton.setDisable(daoOptionsSet); - rpcUserTextField.setDisable(daoOptionsSet); - rpcPwTextField.setDisable(daoOptionsSet); - blockNotifyPortTextField.setDisable(daoOptionsSet); + isDaoFullNodeToggleButton.setDisable(daoFullModeFromOptionsSet); + rpcUserTextField.setDisable(daoFullModeFromOptionsSet); + rpcPwTextField.setDisable(daoFullModeFromOptionsSet); + blockNotifyPortTextField.setDisable(daoFullModeFromOptionsSet); } @@ -1304,9 +1394,12 @@ private void deactivateDisplayPreferences() { private void deactivateDaoPreferences() { processBurningManAccountingDataToggleButton.setOnAction(null); + isFullBMAccountingDataNodeToggleButton.setOnAction(null); fullModeDaoMonitorToggleButton.setOnAction(null); resyncDaoFromResourcesButton.setOnAction(null); resyncDaoFromGenesisButton.setOnAction(null); + resyncBMAccFromScratchButton.setOnAction(null); + resyncBMAccFromResourcesButton.setOnAction(null); bsqAverageTrimThresholdTextField.textProperty().removeListener(bsqAverageTrimThresholdListener); bsqAverageTrimThresholdTextField.focusedProperty().removeListener(bsqAverageTrimThresholdFocusedListener); isDaoFullNodeToggleButton.setOnAction(null); diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index 2d276a327a4..0de2b62a6e5 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -1972,6 +1972,7 @@ message PreferencesPayload { int64 user_defined_trade_limit = 67; bool user_has_raised_trade_limit = 68; bool process_burning_man_accounting_data = 69; + bool is_full_b_m_accounting_node = 70; } message AutoConfirmSettings { From 2b9c56b1d54309224645e897885847fc8bbecedc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Jul 2023 14:01:34 +0000 Subject: [PATCH 06/31] Bump gradle/gradle-build-action from 2.4.2 to 2.5.1 Bumps [gradle/gradle-build-action](https://github.com/gradle/gradle-build-action) from 2.4.2 to 2.5.1. - [Release notes](https://github.com/gradle/gradle-build-action/releases) - [Commits](https://github.com/gradle/gradle-build-action/compare/v2.4.2...v2.5.1) --- updated-dependencies: - dependency-name: gradle/gradle-build-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1c29bec9432..f474e0f06a8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,6 +26,6 @@ jobs: distribution: 'zulu' - name: Build with Gradle - uses: gradle/gradle-build-action@v2.4.2 + uses: gradle/gradle-build-action@v2.5.1 with: arguments: build --scan From 089d4e923790905b4e571ffd6ce4cd88cfc1f42b Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Mon, 3 Jul 2023 13:44:07 -0500 Subject: [PATCH 07/31] Show more available UTXOs in Send Funds screen. --- .../main/funds/withdrawal/WithdrawalView.java | 46 +++++++------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/main/funds/withdrawal/WithdrawalView.java b/desktop/src/main/java/bisq/desktop/main/funds/withdrawal/WithdrawalView.java index 1934b1cc5a2..ab2f519d970 100644 --- a/desktop/src/main/java/bisq/desktop/main/funds/withdrawal/WithdrawalView.java +++ b/desktop/src/main/java/bisq/desktop/main/funds/withdrawal/WithdrawalView.java @@ -24,7 +24,6 @@ import bisq.desktop.components.ExternalHyperlink; import bisq.desktop.components.HyperlinkWithIcon; import bisq.desktop.components.InputTextField; -import bisq.desktop.components.TitledGroupBg; import bisq.desktop.components.list.FilterBox; import bisq.desktop.main.overlays.popups.Popup; import bisq.desktop.main.overlays.windows.TxDetails; @@ -53,6 +52,7 @@ import bisq.network.p2p.P2PService; import bisq.common.UserThread; +import bisq.common.util.Tuple2; import bisq.common.util.Tuple3; import bisq.common.util.Tuple4; @@ -130,7 +130,8 @@ public class WithdrawalView extends ActivatableView { private RadioButton useAllInputsRadioButton, useCustomInputsRadioButton, feeExcludedRadioButton, feeIncludedRadioButton; private Label amountLabel; - private TextField amountTextField, withdrawFromTextField, withdrawToTextField, withdrawMemoTextField, transactionFeeInputTextField; + private TextField amountTextField, withdrawToTextField, withdrawMemoTextField, transactionFeeInputTextField; + private String withdrawFromAddresses = ""; private final BtcWalletService btcWalletService; private final TradeManager tradeManager; @@ -188,8 +189,6 @@ private WithdrawalView(BtcWalletService btcWalletService, @Override public void initialize() { filterBox.initialize(filteredList, tableView); - final TitledGroupBg titledGroupBg = addTitledGroupBg(gridPane, rowIndex, 4, Res.get("funds.deposit.withdrawFromWallet")); - titledGroupBg.getStyleClass().add("last"); inputsToggleGroup = new ToggleGroup(); inputsToggleGroupListener = (observable, oldValue, newValue) -> { @@ -202,7 +201,7 @@ public void initialize() { Res.get("funds.withdrawal.inputs"), Res.get("funds.withdrawal.useAllInputs"), Res.get("funds.withdrawal.useCustomInputs"), - Layout.FIRST_ROW_DISTANCE); + 0); useAllInputsRadioButton = labelRadioButtonRadioButtonTuple3.second; useCustomInputsRadioButton = labelRadioButtonRadioButtonTuple3.third; @@ -222,14 +221,13 @@ public void initialize() { feeExcludedRadioButton = feeTuple3.third; feeIncludedRadioButton = feeTuple3.fourth; - withdrawFromTextField = addTopLabelTextField(gridPane, ++rowIndex, - Res.get("funds.withdrawal.fromLabel", Res.getBaseCurrencyCode())).second; - - withdrawToTextField = addTopLabelInputTextField(gridPane, ++rowIndex, - Res.get("funds.withdrawal.toLabel", Res.getBaseCurrencyCode())).second; - - withdrawMemoTextField = addTopLabelInputTextField(gridPane, ++rowIndex, - Res.get("funds.withdrawal.memoLabel", Res.getBaseCurrencyCode())).second; + Tuple2 x = addInputTextFieldInputTextField(gridPane, ++rowIndex, + Res.get("funds.withdrawal.toLabel", Res.getBaseCurrencyCode()), + Res.get("funds.withdrawal.memoLabel", Res.getBaseCurrencyCode())); + withdrawToTextField = x.first; + withdrawMemoTextField = x.second; + withdrawToTextField.setPrefWidth(Layout.MIN_WINDOW_WIDTH); + withdrawMemoTextField.setPrefWidth(Layout.MIN_WINDOW_WIDTH); Tuple3 customFeeTuple = addTopLabelInputTextFieldSlideToggleButtonRight(gridPane, ++rowIndex, Res.get("funds.withdrawal.txFee"), Res.get("funds.withdrawal.useCustomFeeValue")); @@ -442,7 +440,7 @@ private void onWithdraw() { String messageText = Res.get("shared.sendFundsDetailsWithFee", formatter.formatCoinWithCode(sendersAmount), - withdrawFromTextField.getText(), + withdrawFromAddresses, withdrawToAddress, formatter.formatCoinWithCode(fee), (double) fee.longValue() / txVsize, // no risk of div/0 since txVsize is always positive @@ -522,25 +520,17 @@ private void selectForWithdrawal(WithdrawalListItem item) { amountAsCoin = Coin.ZERO; totalAvailableAmountOfSelectedItems = Coin.ZERO; amountTextField.setText(""); - withdrawFromTextField.setText(""); + withdrawFromAddresses = ""; } if (selectedItems.size() == 1) { - withdrawFromTextField.setText(selectedItems.stream().findAny().get().getAddressEntry().getAddressString()); - withdrawFromTextField.setTooltip(null); + withdrawFromAddresses = selectedItems.stream().findAny().get().getAddressEntry().getAddressString(); } else { int abbr = Math.max(10, 66 / selectedItems.size()); String addressesShortened = selectedItems.stream() .map(e -> StringUtils.abbreviate(e.getAddressString(), abbr)) .collect(Collectors.joining(", ")); - String text = Res.get("funds.withdrawal.withdrawMultipleAddresses", addressesShortened); - withdrawFromTextField.setText(text); - - String addresses = selectedItems.stream() - .map(WithdrawalListItem::getAddressString) - .collect(Collectors.joining(",\n")); - String tooltipText = Res.get("funds.withdrawal.withdrawMultipleAddresses.tooltip", addresses); - withdrawFromTextField.setTooltip(new Tooltip(tooltipText)); + withdrawFromAddresses = Res.get("funds.withdrawal.withdrawMultipleAddresses", addressesShortened); } } else { reset(); @@ -605,9 +595,7 @@ private void sendFunds(Coin amount, Coin fee, KeyParameter aesKey, FutureCallbac } private void reset() { - withdrawFromTextField.setText(""); - withdrawFromTextField.setPromptText(Res.get("funds.withdrawal.selectAddress")); - withdrawFromTextField.setTooltip(null); + withdrawFromAddresses = ""; totalAvailableAmountOfSelectedItems = Coin.ZERO; amountAsCoin = Coin.ZERO; @@ -752,5 +740,3 @@ public void updateItem(final WithdrawalListItem item, boolean empty) { }); } } - - From 0fb9e36eff9648b7d35b347d20473227d1d0dd16 Mon Sep 17 00:00:00 2001 From: AllyKaz Date: Tue, 6 Jun 2023 18:03:32 +0100 Subject: [PATCH 08/31] Fix bisq.properties pickup in ApiTest Copy 'bisq.properties' file in apitest/src/main/resources to each instance's DataDir on startup to allow pickup by the instance. --- .../src/main/java/bisq/apitest/Scaffold.java | 35 ++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/apitest/src/main/java/bisq/apitest/Scaffold.java b/apitest/src/main/java/bisq/apitest/Scaffold.java index 3ffb4ff3eb5..4ed19fd80ea 100644 --- a/apitest/src/main/java/bisq/apitest/Scaffold.java +++ b/apitest/src/main/java/bisq/apitest/Scaffold.java @@ -29,6 +29,7 @@ import java.io.FileNotFoundException; import java.io.IOException; +import java.util.Arrays; import java.util.Objects; import java.util.Optional; import java.util.concurrent.CountDownLatch; @@ -242,28 +243,52 @@ public void installDaoSetupDirectories() { log.info("Copied all dao-setup files to {}", buildDataDir); + // Copy 'bisq.properties' file from 'src/main/resources' to each + // Bisq instance's DataDir + copyBisqPropertiesFileToAppDataDir(); + // Try to avoid confusion about which 'bisq.properties' file is or was loaded // by a Bisq instance: delete the 'bisq.properties' file automatically copied // to the 'apitest/build/resources/main' directory during IDE or Gradle build. // Note: there is no way to prevent this deleted file from being re-copied // from 'src/main/resources' to the buildDataDir each time you hit the build // button in the IDE. - BashCommand rmRedundantBisqPropertiesFile = - new BashCommand("rm -rf " + buildDataDir + "/bisq.properties"); - if (rmRedundantBisqPropertiesFile.run().getExitStatus() != 0) - throw new IllegalStateException("Could not delete redundant bisq.properties file"); + deleteRedundantBisqPropertiesFile(); // Copy the blocknotify script from the src resources dir to the build // resources dir. Users may want to edit comment out some lines when all // the default block notifcation ports being will not be used (to avoid // seeing rpc notifcation warnings in log files). installBitcoinBlocknotify(); - } catch (IOException | InterruptedException ex) { throw new IllegalStateException("Could not install dao-setup files from " + daoSetupDir, ex); } } + private void copyBisqPropertiesFileToAppDataDir() throws IOException, InterruptedException { + copyBisqPropertiesFileToAppDataDir(alicedaemon); + copyBisqPropertiesFileToAppDataDir(bobdaemon); + } + private void copyBisqPropertiesFileToAppDataDir(BisqAppConfig bisqAppConfig) throws IOException, InterruptedException { + String instanceDataDir = config.rootAppDataDir + "/" + bisqAppConfig.appName; + + BashCommand moveToDataDir = + new BashCommand("cp " + config.baseSrcResourcesDir + "/bisq.properties " + instanceDataDir); + + if(moveToDataDir.run().getExitStatus() !=0) + throw new IllegalStateException("Could not copy bisq.properties to " + instanceDataDir); + + log.debug("bisq.properties copied to " + instanceDataDir); + } + + private void deleteRedundantBisqPropertiesFile() throws IOException, InterruptedException { + BashCommand rmRedundantBisqPropertiesFile = + new BashCommand("rm -rf " + config.rootAppDataDir.getAbsolutePath() + "/bisq.properties"); + + if (rmRedundantBisqPropertiesFile.run().getExitStatus() != 0) + throw new IllegalStateException("Could not delete redundant bisq.properties file"); + } + private void cleanDaoSetupDirectories() { String buildDataDir = config.rootAppDataDir.getAbsolutePath(); log.info("Cleaning dao-setup data in {}", buildDataDir); From a2ef728ee0e0542d5b645e510aa5ca7ecca4505f Mon Sep 17 00:00:00 2001 From: AllyKaz Date: Wed, 21 Jun 2023 20:35:32 +0100 Subject: [PATCH 09/31] Refactor dao-setup.gradle Remove redundant directory moving and renaming. Make buildResourcesDir property less brittle. --- apitest/dao-setup.gradle | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/apitest/dao-setup.gradle b/apitest/dao-setup.gradle index 12b9e7188e8..16b1694c650 100644 --- a/apitest/dao-setup.gradle +++ b/apitest/dao-setup.gradle @@ -11,14 +11,14 @@ // // The :apitest subproject will not run on Windows, and these tasks have not been // tested on Windows. -def buildResourcesDir = project(":apitest").buildDir.path + '/resources/main' +def buildResourcesDir = project(":apitest").sourceSets.main.resources.srcDirs.first().path // This task requires ant in the system $PATH. task installDaoSetup(dependsOn: 'cleanDaoSetup') { doLast { println "Installing dao-setup directories in build dir $buildResourcesDir ..." def src = 'https://github.com/bisq-network/bisq/raw/master/docs/dao-setup.zip' - def destfile = project.rootDir.path + '/apitest/src/main/resources/dao-setup.zip' + def destfile = buildResourcesDir + '/dao-setup.zip' def url = new URL(src) def f = new File(destfile) if (f.exists()) { @@ -48,21 +48,14 @@ task installDaoSetup(dependsOn: 'cleanDaoSetup') { } // Copy files from unzip target dir 'dao-setup' to build/resources/main. - def daoSetupSrc = project.rootDir.path + '/apitest/src/main/resources/dao-setup' - def daoSetupDest = buildResourcesDir + '/dao-setup' + def daoSetupSrc = buildResourcesDir + '/dao-setup' + def daoSetupDest = buildResourcesDir println "Copying $daoSetupSrc to $daoSetupDest ..." copy { from daoSetupSrc into daoSetupDest } - // Move dao-setup files from build/resources/main/dao-setup to build/resources/main - file(buildResourcesDir + '/dao-setup/Bitcoin-regtest') - .renameTo(file(buildResourcesDir + '/Bitcoin-regtest')) - file(buildResourcesDir + '/dao-setup/bisq-BTC_REGTEST_Alice_dao') - .renameTo(file(buildResourcesDir + '/bisq-BTC_REGTEST_Alice_dao')) - file(buildResourcesDir + '/dao-setup/bisq-BTC_REGTEST_Bob_dao') - .renameTo(file(buildResourcesDir + '/bisq-BTC_REGTEST_Bob_dao')) delete file(buildResourcesDir + '/dao-setup') } } From 1a931b815f5a8fb87684ad137051ef26a2730e51 Mon Sep 17 00:00:00 2001 From: AllyKaz Date: Thu, 22 Jun 2023 21:48:31 +0100 Subject: [PATCH 10/31] Stop deletion of original bisq.properties during test harness setup Stop the deletion of the original bisq.properties file after it's copied into the instances data directories. --- .../src/main/java/bisq/apitest/Scaffold.java | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/apitest/src/main/java/bisq/apitest/Scaffold.java b/apitest/src/main/java/bisq/apitest/Scaffold.java index 4ed19fd80ea..47cd1d42cf6 100644 --- a/apitest/src/main/java/bisq/apitest/Scaffold.java +++ b/apitest/src/main/java/bisq/apitest/Scaffold.java @@ -29,7 +29,6 @@ import java.io.FileNotFoundException; import java.io.IOException; -import java.util.Arrays; import java.util.Objects; import java.util.Optional; import java.util.concurrent.CountDownLatch; @@ -247,14 +246,6 @@ public void installDaoSetupDirectories() { // Bisq instance's DataDir copyBisqPropertiesFileToAppDataDir(); - // Try to avoid confusion about which 'bisq.properties' file is or was loaded - // by a Bisq instance: delete the 'bisq.properties' file automatically copied - // to the 'apitest/build/resources/main' directory during IDE or Gradle build. - // Note: there is no way to prevent this deleted file from being re-copied - // from 'src/main/resources' to the buildDataDir each time you hit the build - // button in the IDE. - deleteRedundantBisqPropertiesFile(); - // Copy the blocknotify script from the src resources dir to the build // resources dir. Users may want to edit comment out some lines when all // the default block notifcation ports being will not be used (to avoid @@ -269,25 +260,18 @@ private void copyBisqPropertiesFileToAppDataDir() throws IOException, Interrupte copyBisqPropertiesFileToAppDataDir(alicedaemon); copyBisqPropertiesFileToAppDataDir(bobdaemon); } + private void copyBisqPropertiesFileToAppDataDir(BisqAppConfig bisqAppConfig) throws IOException, InterruptedException { - String instanceDataDir = config.rootAppDataDir + "/" + bisqAppConfig.appName; + if (!new File(config.baseSrcResourcesDir + "/bisq.properties").exists()) return; + String instanceDataDir = config.rootAppDataDir + "/" + bisqAppConfig.appName; BashCommand moveToDataDir = new BashCommand("cp " + config.baseSrcResourcesDir + "/bisq.properties " + instanceDataDir); - - if(moveToDataDir.run().getExitStatus() !=0) + if (moveToDataDir.run().getExitStatus() != 0) throw new IllegalStateException("Could not copy bisq.properties to " + instanceDataDir); - log.debug("bisq.properties copied to " + instanceDataDir); } - private void deleteRedundantBisqPropertiesFile() throws IOException, InterruptedException { - BashCommand rmRedundantBisqPropertiesFile = - new BashCommand("rm -rf " + config.rootAppDataDir.getAbsolutePath() + "/bisq.properties"); - - if (rmRedundantBisqPropertiesFile.run().getExitStatus() != 0) - throw new IllegalStateException("Could not delete redundant bisq.properties file"); - } private void cleanDaoSetupDirectories() { String buildDataDir = config.rootAppDataDir.getAbsolutePath(); From 6026e6fb78aa2bd194613530485b8c40ca581873 Mon Sep 17 00:00:00 2001 From: AllyKaz Date: Fri, 2 Jun 2023 14:43:13 +0100 Subject: [PATCH 11/31] xRemove hardcoding of enableBisqDebugging in ApiTest Remove hardcoding of value to prevent it being set as a command line option that then overides the option being set from apitest.properties file preventing it from being altered without altering code. Redundant as false is the default. --- apitest/src/test/java/bisq/apitest/ApiTestCase.java | 3 +-- .../apitest/method/CallRateMeteringInterceptorTest.java | 1 - .../src/test/java/bisq/apitest/method/MethodTest.java | 9 ++------- .../bisq/apitest/method/offer/AbstractOfferTest.java | 5 ----- .../java/bisq/apitest/method/offer/BsqSwapOfferTest.java | 4 ---- .../trade/TakeBuyBTCOfferWithNationalBankAcctTest.java | 4 ---- .../bisq/apitest/method/trade/TakeSellXMROfferTest.java | 2 +- .../java/bisq/apitest/method/wallet/BsqWalletTest.java | 1 - .../bisq/apitest/method/wallet/BtcTxFeeRateTest.java | 1 - .../java/bisq/apitest/method/wallet/BtcWalletTest.java | 1 - .../src/test/java/bisq/apitest/scenario/OfferTest.java | 5 ----- .../src/test/java/bisq/apitest/scenario/StartupTest.java | 1 - .../src/test/java/bisq/apitest/scenario/WalletTest.java | 1 - 13 files changed, 4 insertions(+), 34 deletions(-) diff --git a/apitest/src/test/java/bisq/apitest/ApiTestCase.java b/apitest/src/test/java/bisq/apitest/ApiTestCase.java index 315561cbb6f..97732712f27 100644 --- a/apitest/src/test/java/bisq/apitest/ApiTestCase.java +++ b/apitest/src/test/java/bisq/apitest/ApiTestCase.java @@ -87,8 +87,7 @@ public static void setUpScaffold(Enum... supportingApps) throws InterruptedException, ExecutionException, IOException { String[] params = new String[]{ "--supportingApps", stream(supportingApps).map(Enum::name).collect(Collectors.joining(",")), - "--callRateMeteringConfigPath", getTestRateMeterInterceptorConfig().getAbsolutePath(), - "--enableBisqDebugging", "false" + "--callRateMeteringConfigPath", getTestRateMeterInterceptorConfig().getAbsolutePath() }; setUpScaffold(params); } diff --git a/apitest/src/test/java/bisq/apitest/method/CallRateMeteringInterceptorTest.java b/apitest/src/test/java/bisq/apitest/method/CallRateMeteringInterceptorTest.java index f7a076a9f96..e26ee2548c1 100644 --- a/apitest/src/test/java/bisq/apitest/method/CallRateMeteringInterceptorTest.java +++ b/apitest/src/test/java/bisq/apitest/method/CallRateMeteringInterceptorTest.java @@ -45,7 +45,6 @@ public class CallRateMeteringInterceptorTest extends MethodTest { @BeforeAll public static void setUp() { startSupportingApps(false, - false, bitcoind, alicedaemon); } diff --git a/apitest/src/test/java/bisq/apitest/method/MethodTest.java b/apitest/src/test/java/bisq/apitest/method/MethodTest.java index 8ac98eee751..a1afd5c99f7 100644 --- a/apitest/src/test/java/bisq/apitest/method/MethodTest.java +++ b/apitest/src/test/java/bisq/apitest/method/MethodTest.java @@ -70,13 +70,11 @@ public class MethodTest extends ApiTestCase { public static void startSupportingApps(File callRateMeteringConfigFile, boolean generateBtcBlock, - boolean startSupportingAppsInDebugMode, Enum... supportingApps) { try { setUpScaffold(new String[]{ "--supportingApps", toNameList.apply(supportingApps), "--callRateMeteringConfigPath", callRateMeteringConfigFile.getAbsolutePath(), - "--enableBisqDebugging", startSupportingAppsInDebugMode ? "true" : "false" }); doPostStartup(generateBtcBlock); } catch (Exception ex) { @@ -84,16 +82,13 @@ public static void startSupportingApps(File callRateMeteringConfigFile, } } - public static void startSupportingApps(boolean generateBtcBlock, - boolean startSupportingAppsInDebugMode, - Enum... supportingApps) { + public static void startSupportingApps(boolean generateBtcBlock, Enum... supportingApps) { try { // Disable call rate metering where there is no callRateMeteringConfigFile. File callRateMeteringConfigFile = getTestRateMeterInterceptorConfig(); setUpScaffold(new String[]{ "--supportingApps", toNameList.apply(supportingApps), - "--callRateMeteringConfigPath", callRateMeteringConfigFile.getAbsolutePath(), - "--enableBisqDebugging", startSupportingAppsInDebugMode ? "true" : "false" + "--callRateMeteringConfigPath", callRateMeteringConfigFile.getAbsolutePath() }); doPostStartup(generateBtcBlock); } catch (Exception ex) { diff --git a/apitest/src/test/java/bisq/apitest/method/offer/AbstractOfferTest.java b/apitest/src/test/java/bisq/apitest/method/offer/AbstractOfferTest.java index 627c1befe3b..2275d1b003b 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/AbstractOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/AbstractOfferTest.java @@ -77,12 +77,7 @@ public abstract class AbstractOfferTest extends MethodTest { @BeforeAll public static void setUp() { - setUp(false); - } - - public static void setUp(boolean startSupportingAppsInDebugMode) { startSupportingApps(true, - startSupportingAppsInDebugMode, bitcoind, seednode, arbdaemon, diff --git a/apitest/src/test/java/bisq/apitest/method/offer/BsqSwapOfferTest.java b/apitest/src/test/java/bisq/apitest/method/offer/BsqSwapOfferTest.java index e1824f8c91a..81022eaf572 100644 --- a/apitest/src/test/java/bisq/apitest/method/offer/BsqSwapOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/offer/BsqSwapOfferTest.java @@ -44,10 +44,6 @@ @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class BsqSwapOfferTest extends AbstractOfferTest { - @BeforeAll - public static void setUp() { - AbstractOfferTest.setUp(false); - } @BeforeEach public void generateBtcBlock() { diff --git a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferWithNationalBankAcctTest.java b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferWithNationalBankAcctTest.java index 9c1a1f99ebe..2d51648d963 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferWithNationalBankAcctTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferWithNationalBankAcctTest.java @@ -78,10 +78,6 @@ public class TakeBuyBTCOfferWithNationalBankAcctTest extends AbstractTradeTest { private static PaymentAccount alicesPaymentAccount; private static PaymentAccount bobsPaymentAccount; - @BeforeAll - public static void setUp() { - setUp(false); - } @Test @Order(1) diff --git a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellXMROfferTest.java b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellXMROfferTest.java index ad9162d09af..ef322d7e18c 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeSellXMROfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeSellXMROfferTest.java @@ -60,7 +60,7 @@ public class TakeSellXMROfferTest extends AbstractTradeTest { @BeforeAll public static void setUp() { - AbstractOfferTest.setUp(false); + AbstractOfferTest.setUp(); createXmrPaymentAccounts(); EXPECTED_PROTOCOL_STATUS.init(); } diff --git a/apitest/src/test/java/bisq/apitest/method/wallet/BsqWalletTest.java b/apitest/src/test/java/bisq/apitest/method/wallet/BsqWalletTest.java index 010f0fe0d26..757bcd28443 100644 --- a/apitest/src/test/java/bisq/apitest/method/wallet/BsqWalletTest.java +++ b/apitest/src/test/java/bisq/apitest/method/wallet/BsqWalletTest.java @@ -48,7 +48,6 @@ public class BsqWalletTest extends MethodTest { @BeforeAll public static void setUp() { startSupportingApps(true, - false, bitcoind, seednode, arbdaemon, diff --git a/apitest/src/test/java/bisq/apitest/method/wallet/BtcTxFeeRateTest.java b/apitest/src/test/java/bisq/apitest/method/wallet/BtcTxFeeRateTest.java index 1925b4452c5..ff3861b5894 100644 --- a/apitest/src/test/java/bisq/apitest/method/wallet/BtcTxFeeRateTest.java +++ b/apitest/src/test/java/bisq/apitest/method/wallet/BtcTxFeeRateTest.java @@ -36,7 +36,6 @@ public class BtcTxFeeRateTest extends MethodTest { @BeforeAll public static void setUp() { startSupportingApps(false, - true, bitcoind, seednode, alicedaemon); diff --git a/apitest/src/test/java/bisq/apitest/method/wallet/BtcWalletTest.java b/apitest/src/test/java/bisq/apitest/method/wallet/BtcWalletTest.java index 59eeab906ab..00de34c0c08 100644 --- a/apitest/src/test/java/bisq/apitest/method/wallet/BtcWalletTest.java +++ b/apitest/src/test/java/bisq/apitest/method/wallet/BtcWalletTest.java @@ -41,7 +41,6 @@ public class BtcWalletTest extends MethodTest { @BeforeAll public static void setUp() { startSupportingApps(false, - false, bitcoind, seednode, alicedaemon, diff --git a/apitest/src/test/java/bisq/apitest/scenario/OfferTest.java b/apitest/src/test/java/bisq/apitest/scenario/OfferTest.java index 492378c3e57..558108b15a8 100644 --- a/apitest/src/test/java/bisq/apitest/scenario/OfferTest.java +++ b/apitest/src/test/java/bisq/apitest/scenario/OfferTest.java @@ -43,11 +43,6 @@ @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class OfferTest extends AbstractOfferTest { - @BeforeAll - public static void setUp() { - setUp(false); // Use setUp(true) for running API daemons in remote debug mode. - } - @Test @Order(1) public void testCreateOfferValidation() { diff --git a/apitest/src/test/java/bisq/apitest/scenario/StartupTest.java b/apitest/src/test/java/bisq/apitest/scenario/StartupTest.java index 74df4f78a56..d0bb08087ae 100644 --- a/apitest/src/test/java/bisq/apitest/scenario/StartupTest.java +++ b/apitest/src/test/java/bisq/apitest/scenario/StartupTest.java @@ -57,7 +57,6 @@ public static void setUp() { try { callRateMeteringConfigFile = getTestRateMeterInterceptorConfig(); startSupportingApps(callRateMeteringConfigFile, - false, false, bitcoind, seednode, arbdaemon, alicedaemon); } catch (Exception ex) { diff --git a/apitest/src/test/java/bisq/apitest/scenario/WalletTest.java b/apitest/src/test/java/bisq/apitest/scenario/WalletTest.java index 17b88eca5bc..ae8fe053c5b 100644 --- a/apitest/src/test/java/bisq/apitest/scenario/WalletTest.java +++ b/apitest/src/test/java/bisq/apitest/scenario/WalletTest.java @@ -53,7 +53,6 @@ public class WalletTest extends MethodTest { @BeforeAll public static void setUp() { startSupportingApps(true, - false, bitcoind, seednode, arbdaemon, From b5b68b52ced9143fab9e45004b45b7d78fb1e6ce Mon Sep 17 00:00:00 2001 From: AllyKaz Date: Sat, 10 Jun 2023 11:39:44 +0100 Subject: [PATCH 12/31] Suspend instances in Apitest by CSV list in apitest.properties Enable instances to be suspended in debugging mode by the inclusion of the instance name in a CSV list in apitest.properties --- .../main/java/bisq/apitest/config/ApiTestConfig.java | 11 +++++++++++ .../src/main/java/bisq/apitest/linux/BisqProcess.java | 6 ++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/apitest/src/main/java/bisq/apitest/config/ApiTestConfig.java b/apitest/src/main/java/bisq/apitest/config/ApiTestConfig.java index ec2076e885e..1526e5d6698 100644 --- a/apitest/src/main/java/bisq/apitest/config/ApiTestConfig.java +++ b/apitest/src/main/java/bisq/apitest/config/ApiTestConfig.java @@ -85,6 +85,8 @@ public class ApiTestConfig { static final String ENABLE_BISQ_DEBUGGING = "enableBisqDebugging"; static final String REGISTER_DISPUTE_AGENTS = "registerDisputeAgents"; + static final String SUSPEND_INSTANCE = "suspendInstance"; + // Default values for certain options static final String DEFAULT_CONFIG_FILE_NAME = "apitest.properties"; @@ -126,6 +128,8 @@ public class ApiTestConfig { public final String baseBuildResourcesDir; public final String baseSrcResourcesDir; + public final String suspendedInstances; + // The parser that will be used to parse both cmd line and config file options private final OptionParser parser = new OptionParser(); @@ -261,6 +265,12 @@ public ApiTestConfig(String... args) { .withRequiredArg() .ofType(Boolean.class) .defaultsTo(true); + + ArgumentAcceptingOptionSpec suspendInstancesOpt = + parser.accepts(SUSPEND_INSTANCE, "Suspended the given instances when debugging") + .withRequiredArg() + .ofType(String.class) + .defaultsTo(EMPTY); try { CompositeOptionSet options = new CompositeOptionSet(); @@ -319,6 +329,7 @@ public ApiTestConfig(String... args) { this.callRateMeteringConfigPath = options.valueOf(callRateMeteringConfigPathOpt); this.enableBisqDebugging = options.valueOf(enableBisqDebuggingOpt); this.registerDisputeAgents = options.valueOf(registerDisputeAgentsOpt); + this.suspendedInstances = options.valueOf(suspendInstancesOpt); // Assign values to special-case static fields. BASH_PATH_VALUE = bashPath; diff --git a/apitest/src/main/java/bisq/apitest/linux/BisqProcess.java b/apitest/src/main/java/bisq/apitest/linux/BisqProcess.java index a3a9374d0b5..971cd3742f4 100644 --- a/apitest/src/main/java/bisq/apitest/linux/BisqProcess.java +++ b/apitest/src/main/java/bisq/apitest/linux/BisqProcess.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import lombok.extern.slf4j.Slf4j; @@ -66,8 +67,9 @@ public BisqProcess(BisqAppConfig bisqAppConfig, ApiTestConfig config) { this.useDevPrivilegeKeys = true; this.findBisqPidScript = (config.isRunningTest ? "." : "./apitest") + "/scripts/get-bisq-pid.sh"; - this.debugOpts = config.enableBisqDebugging - ? " -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:" + bisqAppConfig.remoteDebugPort + this.debugOpts = config.enableBisqDebugging ? " -agentlib:jdwp=transport=dt_socket,server=y," + + "suspend=" + (Arrays.asList(config.suspendedInstances.split(",")).contains(bisqAppConfig.name()) ? "y" : "n") + + ",address=*:" + bisqAppConfig.remoteDebugPort : ""; } From d2f9172a50f84f46fa223f494e831a1fe628306a Mon Sep 17 00:00:00 2001 From: AllyKaz Date: Wed, 14 Jun 2023 15:18:50 +0100 Subject: [PATCH 13/31] Fix failing TakeBuyBTCOfferTest Fix failing test by setting amount and minAmount to the maxTradeLimit for fiat accounts (0.1 BTC) --- .../java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java index 4872c21032b..594b746b476 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java @@ -59,8 +59,8 @@ public void testTakeAlicesBuyOffer(final TestInfo testInfo) { PaymentAccount alicesUsdAccount = createDummyF2FAccount(aliceClient, "US"); var alicesOffer = aliceClient.createMarketBasedPricedOffer(BUY.name(), USD, - 12_500_000L, - 12_500_000L, // min-amount = amount + 10_000_000L, + 10_000_000L, // min-amount = amount 0.00, defaultBuyerSecurityDepositPct.get(), alicesUsdAccount.getId(), From 03b205a597431e2de0e14d5f4adebe8208aa79fb Mon Sep 17 00:00:00 2001 From: AllyKaz Date: Wed, 14 Jun 2023 20:00:15 +0100 Subject: [PATCH 14/31] Refactor TakeBuyBTCOfferTest to replace sleep with loops Replace the use of Thread.sleep in the tests with loops --- .../method/trade/TakeBuyBTCOfferTest.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java index 4872c21032b..1e2cef78179 100644 --- a/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java +++ b/apitest/src/test/java/bisq/apitest/method/trade/TakeBuyBTCOfferTest.java @@ -19,8 +19,13 @@ import bisq.core.payment.PaymentAccount; +import bisq.proto.grpc.OfferInfo; + import io.grpc.StatusRuntimeException; +import java.util.List; +import java.util.concurrent.TimeoutException; + import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Disabled; @@ -71,19 +76,34 @@ public void testTakeAlicesBuyOffer(final TestInfo testInfo) { // Wait for Alice's AddToOfferBook task. // Wait times vary; my logs show >= 2-second delay. - sleep(3_000); // TODO loop instead of hard code a wait time - var alicesUsdOffers = aliceClient.getMyOffersSortedByDate(BUY.name(), USD); + var timeout = System.currentTimeMillis() + 3000; + while (bobClient.getOffersSortedByDate(USD, true).size() < 1) { + sleep(100); + if (System.currentTimeMillis() > timeout) + fail(new TimeoutException("Timed out waiting for Offer to be added to OfferBook")); + } + + List alicesUsdOffers = aliceClient.getMyOffersSortedByDate(BUY.name(), USD); assertEquals(1, alicesUsdOffers.size()); PaymentAccount bobsUsdAccount = createDummyF2FAccount(bobClient, "US"); var ignoredTakeOfferAmountParam = 0L; + var trade = takeAlicesOffer(offerId, bobsUsdAccount.getId(), TRADE_FEE_CURRENCY_CODE, ignoredTakeOfferAmountParam, false); - sleep(2_500); // Allow available offer to be removed from offer book. - alicesUsdOffers = aliceClient.getMyOffersSortedByDate(BUY.name(), USD); + + // Allow available offer to be removed from offer book. + timeout = System.currentTimeMillis() + 2500; + do { + alicesUsdOffers = aliceClient.getMyOffersSortedByDate(BUY.name(), USD); + sleep(100); + if (System.currentTimeMillis() > timeout) + fail(new TimeoutException("Timed out waiting for Offer to be removed from OfferBook")); + } while (alicesUsdOffers.size() > 0); + assertEquals(0, alicesUsdOffers.size()); trade = bobClient.getTrade(tradeId); From d50df8f49f32396681b548658003e4bb6fce1e37 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Thu, 6 Jul 2023 17:51:05 +0200 Subject: [PATCH 15/31] Add JaCoCo Gradle Plugin to all modules Co-authored-by: napoly --- .../main/groovy/bisq.java-conventions.gradle | 8 +++ gradle/verification-metadata.xml | 69 +++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/build-logic/commons/src/main/groovy/bisq.java-conventions.gradle b/build-logic/commons/src/main/groovy/bisq.java-conventions.gradle index 87449d028eb..91bb9781914 100644 --- a/build-logic/commons/src/main/groovy/bisq.java-conventions.gradle +++ b/build-logic/commons/src/main/groovy/bisq.java-conventions.gradle @@ -1,5 +1,6 @@ plugins { id 'java' + id 'jacoco' } repositories { @@ -31,3 +32,10 @@ dependencies { test { useJUnitPlatform() } + +jacocoTestReport { + reports { + html.required = false + xml.required = true + } +} diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index 78be5ce9392..4e74fc28728 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -1197,6 +1197,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1717,6 +1754,14 @@ + + + + + + + + @@ -1725,6 +1770,14 @@ + + + + + + + + @@ -1733,6 +1786,14 @@ + + + + + + + + @@ -1741,6 +1802,14 @@ + + + + + + + + From 1045511049cd63d49ca4bb632ffb72c77e56578e Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Thu, 6 Jul 2023 17:52:54 +0200 Subject: [PATCH 16/31] Create standalone code coverage aggregation module Co-authored-by: napoly --- code-coverage-report/build.gradle | 26 ++++++++++++++++++++++++++ settings.gradle | 1 + 2 files changed, 27 insertions(+) create mode 100644 code-coverage-report/build.gradle diff --git a/code-coverage-report/build.gradle b/code-coverage-report/build.gradle new file mode 100644 index 00000000000..5bb79dba625 --- /dev/null +++ b/code-coverage-report/build.gradle @@ -0,0 +1,26 @@ +plugins { + id 'base' + id 'jacoco-report-aggregation' +} + +repositories { + mavenCentral() + maven { url "https://jitpack.io" } +} + +dependencies { + jacocoAggregation project(':apitest') + jacocoAggregation project(':cli') + jacocoAggregation project(':daemon') + jacocoAggregation project(':desktop') + jacocoAggregation project(':seednode') + jacocoAggregation project(':statsnode') +} + +reporting { + reports { + testCodeCoverageReport(JacocoCoverageReport) { + testType = TestSuiteType.UNIT_TEST + } + } +} diff --git a/settings.gradle b/settings.gradle index 530d25e2f17..558941e4ec1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,5 +16,6 @@ include 'desktop' include 'seednode' include 'statsnode' include 'apitest' +include 'code-coverage-report' rootProject.name = 'bisq' From 6c81985d4175f838af360d8c57af18217842fdf0 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Thu, 6 Jul 2023 17:52:54 +0200 Subject: [PATCH 17/31] Create standalone code coverage aggregation module Co-authored-by: napoly --- code-coverage-report/build.gradle | 26 ++++++++++++++++++++++++++ settings.gradle | 1 + 2 files changed, 27 insertions(+) create mode 100644 code-coverage-report/build.gradle diff --git a/code-coverage-report/build.gradle b/code-coverage-report/build.gradle new file mode 100644 index 00000000000..5bb79dba625 --- /dev/null +++ b/code-coverage-report/build.gradle @@ -0,0 +1,26 @@ +plugins { + id 'base' + id 'jacoco-report-aggregation' +} + +repositories { + mavenCentral() + maven { url "https://jitpack.io" } +} + +dependencies { + jacocoAggregation project(':apitest') + jacocoAggregation project(':cli') + jacocoAggregation project(':daemon') + jacocoAggregation project(':desktop') + jacocoAggregation project(':seednode') + jacocoAggregation project(':statsnode') +} + +reporting { + reports { + testCodeCoverageReport(JacocoCoverageReport) { + testType = TestSuiteType.UNIT_TEST + } + } +} diff --git a/settings.gradle b/settings.gradle index 530d25e2f17..558941e4ec1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,5 +16,6 @@ include 'desktop' include 'seednode' include 'statsnode' include 'apitest' +include 'code-coverage-report' rootProject.name = 'bisq' From feca0fb6beff5859560a80482ad14e6d849adc6b Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Wed, 31 May 2023 10:28:04 +0200 Subject: [PATCH 18/31] GitHub Actions: Create aggregated JaCoCo coverage report Co-authored-by: napoly --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f474e0f06a8..7283a45b52c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,4 +28,4 @@ jobs: - name: Build with Gradle uses: gradle/gradle-build-action@v2.5.1 with: - arguments: build --scan + arguments: build jacocoTestReport testCodeCoverageReport --scan From 0b0dbe8af2b4517fa37c3a6c2dcae8914434f726 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Sun, 2 Jul 2023 17:30:41 +0200 Subject: [PATCH 19/31] java-conventions: Remove duplicate repositories block --- .../commons/src/main/groovy/bisq.java-conventions.gradle | 5 ----- 1 file changed, 5 deletions(-) diff --git a/build-logic/commons/src/main/groovy/bisq.java-conventions.gradle b/build-logic/commons/src/main/groovy/bisq.java-conventions.gradle index 87449d028eb..888429237cb 100644 --- a/build-logic/commons/src/main/groovy/bisq.java-conventions.gradle +++ b/build-logic/commons/src/main/groovy/bisq.java-conventions.gradle @@ -10,11 +10,6 @@ repositories { sourceCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11 -repositories { - mavenCentral() - maven { url 'https://jitpack.io' } -} - tasks.withType(JavaCompile) { options.encoding = 'UTF-8' } From 78a742695c726a670badded7fb4f913121010f98 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Sun, 2 Jul 2023 18:28:25 +0200 Subject: [PATCH 20/31] Declare global protobuf-java in Java Platform Plugin The constraints in the platform module apply to all libraries (including to transitively included libraries). --- build.gradle | 16 ++++++---------- platform/build.gradle | 9 +++++++++ proto/build.gradle | 1 + settings.gradle | 1 + 4 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 platform/build.gradle diff --git a/build.gradle b/build.gradle index 407c14ea8ea..a9ce58f05d6 100644 --- a/build.gradle +++ b/build.gradle @@ -130,6 +130,7 @@ configure(project(':common')) { "Implementation-Version": getHash()) dependencies { + implementation enforcedPlatform(project(':platform')) implementation project(':proto') annotationProcessor libs.lombok compileOnly libs.javax.annotation @@ -142,7 +143,6 @@ configure(project(':common')) { exclude(module: 'jsr305') exclude(module: 'okhttp') exclude(module: 'okio') - exclude(module: 'protobuf-java') exclude(module: 'slf4j-api') } implementation libs.google.findbugs @@ -151,7 +151,6 @@ configure(project(':common')) { implementation(libs.google.guice) { exclude(module: 'guava') } - implementation libs.protobuf.java implementation libs.commons.io implementation libs.jopt implementation libs.apache.commons.lang3 @@ -176,12 +175,12 @@ configure(project(':p2p')) { } dependencies { + implementation enforcedPlatform(project(':platform')) implementation project(':proto') implementation project(':common') annotationProcessor libs.lombok compileOnly libs.lombok implementation libs.google.guava - implementation libs.protobuf.java implementation libs.fxmisc.easybind implementation libs.slf4j.api implementation(libs.netlayer.tor.external) { @@ -196,7 +195,6 @@ configure(project(':p2p')) { exclude(module: 'jsr305') exclude(module: 'okhttp') exclude(module: 'okio') - exclude(module: 'protobuf-java') exclude(module: 'slf4j-api') } implementation(libs.google.guice) { @@ -223,6 +221,7 @@ configure(project(':core')) { } dependencies { + implementation enforcedPlatform(project(':platform')) implementation project(':proto') implementation project(':assets') implementation project(':common') @@ -237,7 +236,6 @@ configure(project(':core')) { implementation libs.google.findbugs implementation libs.google.gson implementation libs.google.guava - implementation libs.protobuf.java implementation libs.commons.codec implementation libs.commons.io implementation libs.jopt @@ -261,7 +259,6 @@ configure(project(':core')) { exclude(module: 'jsr305') exclude(module: 'okhttp') exclude(module: 'okio') - exclude(module: 'protobuf-java') exclude(module: 'slf4j-api') } implementation(libs.jsonrpc4j) { @@ -313,6 +310,7 @@ configure(project(':desktop')) { sourceSets.main.resources.srcDirs += ['src/main/java'] // to copy fxml and css files dependencies { + implementation enforcedPlatform(project(':platform')) implementation project(':assets') implementation project(':common') implementation project(':proto') @@ -324,7 +322,6 @@ configure(project(':desktop')) { implementation libs.logback.core implementation libs.google.gson implementation libs.google.guava - implementation libs.protobuf.java implementation libs.jcsv implementation libs.jfoenix implementation libs.commons.io @@ -343,7 +340,6 @@ configure(project(':desktop')) { exclude(module: 'jsr305') exclude(module: 'okhttp') exclude(module: 'okio') - exclude(module: 'protobuf-java') exclude(module: 'slf4j-api') } implementation(libs.google.guice) { @@ -373,6 +369,7 @@ configure(project(':seednode')) { mainClassName = 'bisq.seednode.SeedNodeMain' dependencies { + implementation enforcedPlatform(project(':platform')) implementation project(':common') implementation project(':proto') implementation project(':p2p') @@ -465,6 +462,7 @@ configure(project(':apitest')) { } dependencies { + implementation enforcedPlatform(project(':platform')) implementation project(':proto') implementation project(':common') implementation project(':core') @@ -479,7 +477,6 @@ configure(project(':apitest')) { implementation libs.logback.core implementation libs.google.gson implementation libs.google.guava - implementation libs.protobuf.java implementation libs.jopt implementation libs.apache.commons.lang3 implementation libs.slf4j.api @@ -489,7 +486,6 @@ configure(project(':apitest')) { exclude(module: 'jsr305') exclude(module: 'okhttp') exclude(module: 'okio') - exclude(module: 'protobuf-java') exclude(module: 'slf4j-api') } implementation(libs.grpc.protobuf) { diff --git a/platform/build.gradle b/platform/build.gradle new file mode 100644 index 00000000000..5036fd8e6aa --- /dev/null +++ b/platform/build.gradle @@ -0,0 +1,9 @@ +plugins { + id 'java-platform' +} + +dependencies { + constraints { + api libs.protobuf.java + } +} diff --git a/proto/build.gradle b/proto/build.gradle index a52ad806fa4..215197d6b48 100644 --- a/proto/build.gradle +++ b/proto/build.gradle @@ -5,6 +5,7 @@ plugins { apply plugin: 'com.google.protobuf' dependencies { + implementation enforcedPlatform(project(':platform')) annotationProcessor libs.lombok compileOnly libs.javax.annotation compileOnly libs.lombok diff --git a/settings.gradle b/settings.gradle index 530d25e2f17..0446e19e70c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,5 +16,6 @@ include 'desktop' include 'seednode' include 'statsnode' include 'apitest' +include 'platform' rootProject.name = 'bisq' From d9056fa2beb28bfb3e29b0c9ef95cd7e6c6b5bdd Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Sun, 2 Jul 2023 18:29:17 +0200 Subject: [PATCH 21/31] Declare protoc version in proto module --- build.gradle | 1 - proto/build.gradle | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 407c14ea8ea..9ba7f6e1dc3 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,6 @@ configure(subprojects) { ext { // in alphabetical order grpcVersion = '1.42.1' javafxVersion = '16' - protocVersion = '3.19.1' os = osdetector.os == 'osx' ? 'mac' : osdetector.os == 'windows' ? 'win' : osdetector.os } diff --git a/proto/build.gradle b/proto/build.gradle index a52ad806fa4..ce8025c1d61 100644 --- a/proto/build.gradle +++ b/proto/build.gradle @@ -30,7 +30,7 @@ sourceSets.main.java.srcDirs += [ protobuf { protoc { - artifact = "com.google.protobuf:protoc:${protocVersion}" + artifact = "com.google.protobuf:protoc:3.19.1" } plugins { grpc { From e5e1ec092d0849856ecc4bfff97c7f5f352f1e06 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Sun, 2 Jul 2023 18:29:53 +0200 Subject: [PATCH 22/31] Declare grpc compiler version in proto module --- build.gradle | 1 - proto/build.gradle | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 407c14ea8ea..e8eda376416 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,6 @@ configure(subprojects) { apply plugin: 'com.google.osdetector' ext { // in alphabetical order - grpcVersion = '1.42.1' javafxVersion = '16' protocVersion = '3.19.1' diff --git a/proto/build.gradle b/proto/build.gradle index a52ad806fa4..383c69736d6 100644 --- a/proto/build.gradle +++ b/proto/build.gradle @@ -34,7 +34,7 @@ protobuf { } plugins { grpc { - artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" + artifact = "io.grpc:protoc-gen-grpc-java:1.42.1" } } generateProtoTasks { From 2bbed1f60f63dc11e6f96aca7f442f3ba8477f02 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Sun, 2 Jul 2023 18:31:25 +0200 Subject: [PATCH 23/31] proto: Apply proto tasks only to main source set --- proto/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto/build.gradle b/proto/build.gradle index a52ad806fa4..43772cfda11 100644 --- a/proto/build.gradle +++ b/proto/build.gradle @@ -38,6 +38,6 @@ protobuf { } } generateProtoTasks { - all()*.plugins { grpc {} } + ofSourceSet('main')*.plugins { grpc {} } } } From 56e196944464f231f54b72e18ea3086687b9c4e3 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Sun, 2 Jul 2023 18:36:38 +0200 Subject: [PATCH 24/31] proto: Add idea plugin The protobuf-gradle-plugin automatically registers proto files and generated Java code as sources to the idea plugin. --- proto/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/proto/build.gradle b/proto/build.gradle index a52ad806fa4..6122d78099d 100644 --- a/proto/build.gradle +++ b/proto/build.gradle @@ -3,6 +3,7 @@ plugins { } apply plugin: 'com.google.protobuf' +apply plugin: 'idea' dependencies { annotationProcessor libs.lombok From f6dff320d5c3a7fae9a16ec9ddfe64ce0b83956f Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Sun, 2 Jul 2023 18:54:45 +0200 Subject: [PATCH 25/31] proto: Remove redundant 'sourceSets.main.java.srcDirs += ' --- proto/build.gradle | 5 ----- 1 file changed, 5 deletions(-) diff --git a/proto/build.gradle b/proto/build.gradle index a52ad806fa4..5d3a8929b9b 100644 --- a/proto/build.gradle +++ b/proto/build.gradle @@ -23,11 +23,6 @@ dependencies { } } -sourceSets.main.java.srcDirs += [ - 'build/generated/source/proto/main/grpc', - 'build/generated/source/proto/main/java' -] - protobuf { protoc { artifact = "com.google.protobuf:protoc:${protocVersion}" From b17603eec935fd3403f794a7e04f08f9bf3b1ab8 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Sun, 2 Jul 2023 19:27:01 +0200 Subject: [PATCH 26/31] Remove Java Installation Scripts The scripts are outdated and install the wrong Java version anyway. --- scripts/install_java.bat | 56 ------------- scripts/install_java.sh | 82 ------------------- scripts/install_java_linux.sh | 143 ---------------------------------- scripts/install_java_macos.sh | 60 -------------- 4 files changed, 341 deletions(-) delete mode 100755 scripts/install_java.bat delete mode 100755 scripts/install_java.sh delete mode 100755 scripts/install_java_linux.sh delete mode 100755 scripts/install_java_macos.sh diff --git a/scripts/install_java.bat b/scripts/install_java.bat deleted file mode 100755 index 184afbb52fb..00000000000 --- a/scripts/install_java.bat +++ /dev/null @@ -1,56 +0,0 @@ -:: This script will download and install the appropriate JDK for use with Bisq development. -:: It will also configure it as the default system JDK. -:: If you need to change to another default JDK for another purpose later, you just need to -:: change the JAVA_HOME environment variable. For example, use the following command: -:: setx /M JAVA_HOME "" - -@echo off - -:: Ensure we have administrative privileges in order to install files and set environment variables ->nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" -if '%errorlevel%' == '0' ( - ::If no error is encountered, we have administrative privileges - goto GotAdminPrivileges -) -echo Requesting administrative privileges... -echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadminprivileges.vbs" -set params = %*:"="" -echo UAC.ShellExecute "%~s0", "%params%", "", "runas", 1 >> "%temp%\getadminprivileges.vbs" -"%temp%\getadminprivileges.vbs" -exit /B -:GotAdminPrivileges -if exist "%temp%\getadminprivileges.vbs" ( del "%temp%\getadminprivileges.vbs" ) -pushd "%CD%" -cd /D "%~dp0" - -title Install Java - -set jdk_version=11.0.2 -set jdk_filename=openjdk-%jdk_version%_windows-x64_bin -set jdk_url=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_windows-x64_bin.zip - -if exist "%PROGRAMFILES%\Java\openjdk\jdk-%jdk_version%" ( - echo %PROGRAMFILES%\Java\openjdk\jdk-%jdk_version% already exists, skipping install - goto SetEnvVars -) - -echo Downloading required files to %TEMP% -powershell -Command "Invoke-WebRequest %jdk_url% -OutFile $env:temp\%jdk_filename%.zip" - -echo Extracting and installing JDK to %PROGRAMFILES%\Java\openjdk\jdk-%jdk_version% -powershell -Command "Expand-Archive $env:temp\%jdk_filename%.zip -DestinationPath %TEMP%\openjdk-%jdk_version% -Force" -md "%PROGRAMFILES%\Java\openjdk" -move "%TEMP%\openjdk-%jdk_version%\jdk-%jdk_version%" "%PROGRAMFILES%\Java\openjdk" - -echo Removing downloaded files -rmdir /S /Q %TEMP%\openjdk-%jdk_version% -del /Q %TEMP%\%jdk_filename%.zip - -:SetEnvVars -echo Setting environment variables -powershell -Command "[Environment]::SetEnvironmentVariable('JAVA_HOME', '%PROGRAMFILES%\Java\openjdk\jdk-%jdk_version%', 'Machine')" -set java_bin=%%JAVA_HOME%%\bin -echo %PATH%|find /i "%java_bin%">nul || powershell -Command "[Environment]::SetEnvironmentVariable('PATH', '%PATH%;%java_bin%', 'Machine')" - -echo Done! -pause diff --git a/scripts/install_java.sh b/scripts/install_java.sh deleted file mode 100755 index 5b06dfe3a8d..00000000000 --- a/scripts/install_java.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env bash -# This script will download and install the appropriate JDK for use with Bisq development. -# It will also configure it as the default system JDK. -# If you need to change to another default JDK for another purpose later, you can use the -# following commands and select the default JDK: -# Linux: -# update-alternatives --config java -# update-alternatives --config javac -# MacOS: -# echo 'export JAVA_HOME=/Library/Java/JavaVirtualMachines//Contents/Home' >>~/.bash_profile -# echo 'export PATH=$JAVA_HOME/bin:$PATH' >>~/.bash_profile -# source ~/.bash_profile -set -e - -unameOut="$(uname -s)" -case "${unameOut}" in - Linux*) - JAVA_HOME=/usr/lib/jvm/openjdk-11.0.2 - JDK_FILENAME=openjdk-11.0.2_linux-x64_bin.tar.gz - JDK_URL=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz - - # Determine which package manager to use depending on the distribution - declare -A osInfo; - osInfo[/etc/redhat-release]=yum - osInfo[/etc/arch-release]=pacman - osInfo[/etc/gentoo-release]=emerge - osInfo[/etc/SuSE-release]=zypp - osInfo[/etc/debian_version]=apt-get - - for f in "${!osInfo[@]}" - do - if [[ -f $f ]]; then - PACKAGE_MANAGER=${osInfo[$f]} - break - fi - done - - if [ ! -d "$JAVA_HOME" ]; then - # Ensure curl is installed since it may not be - $PACKAGE_MANAGER -y install curl - - curl -L -O $JDK_URL - mkdir -p $JAVA_HOME - tar -zxf $JDK_FILENAME -C $JAVA_HOME --strip 1 - rm $JDK_FILENAME - - update-alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 2000 - update-alternatives --install /usr/bin/javac javac $JAVA_HOME/bin/javac 2000 - fi - - update-alternatives --set java $JAVA_HOME/bin/java - update-alternatives --set javac $JAVA_HOME/bin/javac - ;; - Darwin*) - JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home - JDK_FILENAME=openjdk-11.0.2_osx-x64_bin.tar.gz - JDK_URL=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_osx-x64_bin.tar.gz - if [ ! -d "$JAVA_HOME" ]; then - if [[ $(command -v brew) == "" ]]; then - echo "Installing Homebrew" - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - else - echo "Updating Homebrew" - brew update - fi - - brew install curl - curl -L -O $JDK_URL - sudo mkdir /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk | sudo bash - gunzip -c $JDK_FILENAME | tar xopf - - sudo mv jdk-11.0.2.jdk/* /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk - sudo rmdir jdk-11.0.2.jdk - rm $JDK_FILENAME - fi - - echo export JAVA_HOME=$JAVA_HOME >>~/.bash_profile - echo export PATH=$JAVA_HOME/bin:"$PATH" >>~/.bash_profile - source "$HOME/.bash_profile" - ;; - *) -esac -java -version diff --git a/scripts/install_java_linux.sh b/scripts/install_java_linux.sh deleted file mode 100755 index ebb541b8db1..00000000000 --- a/scripts/install_java_linux.sh +++ /dev/null @@ -1,143 +0,0 @@ -#!/bin/bash - -# Install OpenJDK 11.0.2 on Linux - -set -eu - -# Download and install locations -JDK_URL=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz -JAVA_HOME_DIR=/usr/lib/jvm/openjdk-11.0.2 - -alpine_openjdk_package=openjdk11 -alpine_openjdk_location=/usr/lib/jvm/java-11-openjdk - - -OS=$(uname) -if [ "$OS" != Linux ] -then - echo This script supports Linux only >&2 - exit 1 -fi - -PACKAGE_MANAGER= -for tool in apk yum pacman emerge zypper apt-get dnf -do - if command -v $tool >/dev/null - then - PACKAGE_MANAGER=$tool - break - fi -done - -if [ -z "$PACKAGE_MANAGER" ] -then - echo "Unknown OS" >&2 -fi - -missing= -for cmd in curl tar gzip -do - if ! command -v $cmd >/dev/null - then - missing="${missing+$missing }$cmd" - if [ "$cmd" = curl ] - then - missing="$missing ca-certificates" - fi - fi -done - -sudo_exec () { - if [ "${EID-500}" -eq 0 ] || [ "${HOME-/home}" = /root ] - then - "$@" - elif command -v sudo - then - sudo "$@" - else - echo "Can't execute with elevated priviliges: $*" >&2 - exit 1 - fi -} - -# Install missing packages -if [ -n "$missing" ] -then - case "$PACKAGE_MANAGER" in - apk) - : no need to install missing packages, because - : we will install OpenJDK using apk - ;; - pacman) - sudo_exec pacman -Syy --noconfirm "$missing" - ;; - apt-get) - sudo_exec apt-get update - # shellcheck disable=SC2086 - sudo_exec apt-get install -y --no-install-recommends $missing - ;; - dnf|emerge|yum|zypper) - sudo_exec "$PACKAGE_MANAGER" update - # shellcheck disable=SC2086 - sudo_exec "$PACKAGE_MANAGER" install -y $missing - ;; - *) - echo "The following packages are missing from your system: $missing" >&2 - echo "Please install these packages before proceeding" >&2 - exit 1; - ;; - esac -fi - -if [ "$PACKAGE_MANAGER" = apk ] -then - if sudo_exec apk add --no-cache ${alpine_openjdk_package} - then - echo "Installed Java to $alpine_openjdk_location" - echo "To start using 'javac', add $alpine_openjdk_location/bin to your PATH:" - echo "export PATH=$alpine_openjdk_location/bin:\$PATH" - fi - exit -fi - - -JDK_FILENAME=$(basename "$JDK_URL") -tmpdir=$(mktemp -d) -trap -- 'rm -rf "$tmpdir"' EXIT - -mkdir "$tmpdir/JAVA_HOME_DIR" -curl -L -o "$tmpdir/$JDK_FILENAME" "$JDK_URL" -tar -xf "$tmpdir/$JDK_FILENAME" -C "$tmpdir/JAVA_HOME_DIR" --strip-components=1 - -if [ -d "$tmpdir/JAVA_HOME_DIR/bin" ] -then - sudo_exec rm -rf "$JAVA_HOME_DIR" - sudo_exec mkdir -p "$(dirname "$JAVA_HOME_DIR")" - sudo_exec mv "$tmpdir/JAVA_HOME_DIR" "$JAVA_HOME_DIR" -else - echo "Error extracting archive contents" >&2 - exit 1 -fi - -echo "Java has been installed in $JAVA_HOME_DIR" - -if command -v update-alternatives >/dev/null -then - update-alternatives --install /usr/bin/java java "$JAVA_HOME_DIR/bin/java" 2000 - update-alternatives --install /usr/bin/javac javac "$JAVA_HOME_DIR/bin/javac" 2000 - update-alternatives --set java "$JAVA_HOME_DIR/bin/java" - update-alternatives --set javac "$JAVA_HOME_DIR/bin/javac" - - echo "and configured as the default JDK using 'update-alternatives'." - echo "If you need to change to another JDK later, you can do so like so:" - echo " update-alternatives --config java" - echo " update-alternatives --config javac" -else - echo "To start using it, please set/update your 'JAVA_HOME' and 'PATH' environment variables like so:" - echo - echo "export JAVA_HOME=\"$JAVA_HOME_DIR\"" - echo "export PATH=\"$JAVA_HOME_DIR/bin:\$PATH\"" - echo - echo "Consider adding the above lines to one of your personal initialization files" - echo " like ~/.bashrc, ~/.bash_profile, ~/.profile, or similar." -fi diff --git a/scripts/install_java_macos.sh b/scripts/install_java_macos.sh deleted file mode 100755 index d672e34d133..00000000000 --- a/scripts/install_java_macos.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash - -# Install OpenJDK 11.0.2 on macOS - -set -eu - -# Download and install locations -JDK_URL=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_osx-x64_bin.tar.gz -JAVA_HOME_DIR=/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk - - -OS=$(uname) -if [[ $OS != Darwin ]] -then - echo This script supports macOS only >&2 - exit 1 -fi - -command -v curl >/dev/null || { echo "cURL is not available" >&2; exit 1; } -command -v tar >/dev/null || { echo "tar is not available" >&2; exit 1; } - -sudo_exec () { - if [[ $EUID -eq 0 ]] - then - "$@" - else - sudo "$@" - fi -} - -JDK_FILENAME=$(basename "$JDK_URL") - -tmpdir=$(mktemp -d) -trap -- 'rm -rf "$tmpdir"' EXIT - -mkdir "$tmpdir/JAVA_HOME_DIR" -curl -L -o "$tmpdir/$JDK_FILENAME" "$JDK_URL" -tar -xf "$tmpdir/$JDK_FILENAME" -C "$tmpdir/JAVA_HOME_DIR" --strip-components=2 - -if [[ -d "$tmpdir/JAVA_HOME_DIR/Contents" ]] -then - sudo_exec rm -rf "$JAVA_HOME_DIR" - sudo_exec mkdir -p "$(dirname "$JAVA_HOME_DIR")" - sudo_exec mv "$tmpdir/JAVA_HOME_DIR" "$JAVA_HOME_DIR" -else - echo "Error extracting archive contents" >&2 - exit 1 -fi - -echo "Java has been installed in $JAVA_HOME_DIR" -echo "To start using it, please set/update your 'JAVA_HOME' and 'PATH' environment variables like so:" -echo -echo " export JAVA_HOME=\"$JAVA_HOME_DIR/Contents/Home\"" -echo " export PATH=\"$JAVA_HOME_DIR/Contents/Home/bin:\$PATH\"" -echo -echo "Consider adding the above lines to one of your personal initialization files." -echo "(~/.bashrc, ~/.bash_profile, ~/.profile, or similar)." - -export JAVA_HOME="$JAVA_HOME_DIR/Contents/Home" -export PATH="$JAVA_HOME_DIR/Contents/Home/bin":$PATH From aaafdd399b02de74c58ab5038cfd02bd70d5150e Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Sun, 2 Jul 2023 19:27:01 +0200 Subject: [PATCH 27/31] Remove Java Installation Scripts The scripts are outdated and install the wrong Java version anyway. --- scripts/install_java.bat | 56 ------------- scripts/install_java.sh | 82 ------------------- scripts/install_java_linux.sh | 143 ---------------------------------- scripts/install_java_macos.sh | 60 -------------- 4 files changed, 341 deletions(-) delete mode 100755 scripts/install_java.bat delete mode 100755 scripts/install_java.sh delete mode 100755 scripts/install_java_linux.sh delete mode 100755 scripts/install_java_macos.sh diff --git a/scripts/install_java.bat b/scripts/install_java.bat deleted file mode 100755 index 184afbb52fb..00000000000 --- a/scripts/install_java.bat +++ /dev/null @@ -1,56 +0,0 @@ -:: This script will download and install the appropriate JDK for use with Bisq development. -:: It will also configure it as the default system JDK. -:: If you need to change to another default JDK for another purpose later, you just need to -:: change the JAVA_HOME environment variable. For example, use the following command: -:: setx /M JAVA_HOME "" - -@echo off - -:: Ensure we have administrative privileges in order to install files and set environment variables ->nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" -if '%errorlevel%' == '0' ( - ::If no error is encountered, we have administrative privileges - goto GotAdminPrivileges -) -echo Requesting administrative privileges... -echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadminprivileges.vbs" -set params = %*:"="" -echo UAC.ShellExecute "%~s0", "%params%", "", "runas", 1 >> "%temp%\getadminprivileges.vbs" -"%temp%\getadminprivileges.vbs" -exit /B -:GotAdminPrivileges -if exist "%temp%\getadminprivileges.vbs" ( del "%temp%\getadminprivileges.vbs" ) -pushd "%CD%" -cd /D "%~dp0" - -title Install Java - -set jdk_version=11.0.2 -set jdk_filename=openjdk-%jdk_version%_windows-x64_bin -set jdk_url=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_windows-x64_bin.zip - -if exist "%PROGRAMFILES%\Java\openjdk\jdk-%jdk_version%" ( - echo %PROGRAMFILES%\Java\openjdk\jdk-%jdk_version% already exists, skipping install - goto SetEnvVars -) - -echo Downloading required files to %TEMP% -powershell -Command "Invoke-WebRequest %jdk_url% -OutFile $env:temp\%jdk_filename%.zip" - -echo Extracting and installing JDK to %PROGRAMFILES%\Java\openjdk\jdk-%jdk_version% -powershell -Command "Expand-Archive $env:temp\%jdk_filename%.zip -DestinationPath %TEMP%\openjdk-%jdk_version% -Force" -md "%PROGRAMFILES%\Java\openjdk" -move "%TEMP%\openjdk-%jdk_version%\jdk-%jdk_version%" "%PROGRAMFILES%\Java\openjdk" - -echo Removing downloaded files -rmdir /S /Q %TEMP%\openjdk-%jdk_version% -del /Q %TEMP%\%jdk_filename%.zip - -:SetEnvVars -echo Setting environment variables -powershell -Command "[Environment]::SetEnvironmentVariable('JAVA_HOME', '%PROGRAMFILES%\Java\openjdk\jdk-%jdk_version%', 'Machine')" -set java_bin=%%JAVA_HOME%%\bin -echo %PATH%|find /i "%java_bin%">nul || powershell -Command "[Environment]::SetEnvironmentVariable('PATH', '%PATH%;%java_bin%', 'Machine')" - -echo Done! -pause diff --git a/scripts/install_java.sh b/scripts/install_java.sh deleted file mode 100755 index 5b06dfe3a8d..00000000000 --- a/scripts/install_java.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env bash -# This script will download and install the appropriate JDK for use with Bisq development. -# It will also configure it as the default system JDK. -# If you need to change to another default JDK for another purpose later, you can use the -# following commands and select the default JDK: -# Linux: -# update-alternatives --config java -# update-alternatives --config javac -# MacOS: -# echo 'export JAVA_HOME=/Library/Java/JavaVirtualMachines//Contents/Home' >>~/.bash_profile -# echo 'export PATH=$JAVA_HOME/bin:$PATH' >>~/.bash_profile -# source ~/.bash_profile -set -e - -unameOut="$(uname -s)" -case "${unameOut}" in - Linux*) - JAVA_HOME=/usr/lib/jvm/openjdk-11.0.2 - JDK_FILENAME=openjdk-11.0.2_linux-x64_bin.tar.gz - JDK_URL=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz - - # Determine which package manager to use depending on the distribution - declare -A osInfo; - osInfo[/etc/redhat-release]=yum - osInfo[/etc/arch-release]=pacman - osInfo[/etc/gentoo-release]=emerge - osInfo[/etc/SuSE-release]=zypp - osInfo[/etc/debian_version]=apt-get - - for f in "${!osInfo[@]}" - do - if [[ -f $f ]]; then - PACKAGE_MANAGER=${osInfo[$f]} - break - fi - done - - if [ ! -d "$JAVA_HOME" ]; then - # Ensure curl is installed since it may not be - $PACKAGE_MANAGER -y install curl - - curl -L -O $JDK_URL - mkdir -p $JAVA_HOME - tar -zxf $JDK_FILENAME -C $JAVA_HOME --strip 1 - rm $JDK_FILENAME - - update-alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 2000 - update-alternatives --install /usr/bin/javac javac $JAVA_HOME/bin/javac 2000 - fi - - update-alternatives --set java $JAVA_HOME/bin/java - update-alternatives --set javac $JAVA_HOME/bin/javac - ;; - Darwin*) - JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home - JDK_FILENAME=openjdk-11.0.2_osx-x64_bin.tar.gz - JDK_URL=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_osx-x64_bin.tar.gz - if [ ! -d "$JAVA_HOME" ]; then - if [[ $(command -v brew) == "" ]]; then - echo "Installing Homebrew" - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" - else - echo "Updating Homebrew" - brew update - fi - - brew install curl - curl -L -O $JDK_URL - sudo mkdir /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk | sudo bash - gunzip -c $JDK_FILENAME | tar xopf - - sudo mv jdk-11.0.2.jdk/* /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk - sudo rmdir jdk-11.0.2.jdk - rm $JDK_FILENAME - fi - - echo export JAVA_HOME=$JAVA_HOME >>~/.bash_profile - echo export PATH=$JAVA_HOME/bin:"$PATH" >>~/.bash_profile - source "$HOME/.bash_profile" - ;; - *) -esac -java -version diff --git a/scripts/install_java_linux.sh b/scripts/install_java_linux.sh deleted file mode 100755 index ebb541b8db1..00000000000 --- a/scripts/install_java_linux.sh +++ /dev/null @@ -1,143 +0,0 @@ -#!/bin/bash - -# Install OpenJDK 11.0.2 on Linux - -set -eu - -# Download and install locations -JDK_URL=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz -JAVA_HOME_DIR=/usr/lib/jvm/openjdk-11.0.2 - -alpine_openjdk_package=openjdk11 -alpine_openjdk_location=/usr/lib/jvm/java-11-openjdk - - -OS=$(uname) -if [ "$OS" != Linux ] -then - echo This script supports Linux only >&2 - exit 1 -fi - -PACKAGE_MANAGER= -for tool in apk yum pacman emerge zypper apt-get dnf -do - if command -v $tool >/dev/null - then - PACKAGE_MANAGER=$tool - break - fi -done - -if [ -z "$PACKAGE_MANAGER" ] -then - echo "Unknown OS" >&2 -fi - -missing= -for cmd in curl tar gzip -do - if ! command -v $cmd >/dev/null - then - missing="${missing+$missing }$cmd" - if [ "$cmd" = curl ] - then - missing="$missing ca-certificates" - fi - fi -done - -sudo_exec () { - if [ "${EID-500}" -eq 0 ] || [ "${HOME-/home}" = /root ] - then - "$@" - elif command -v sudo - then - sudo "$@" - else - echo "Can't execute with elevated priviliges: $*" >&2 - exit 1 - fi -} - -# Install missing packages -if [ -n "$missing" ] -then - case "$PACKAGE_MANAGER" in - apk) - : no need to install missing packages, because - : we will install OpenJDK using apk - ;; - pacman) - sudo_exec pacman -Syy --noconfirm "$missing" - ;; - apt-get) - sudo_exec apt-get update - # shellcheck disable=SC2086 - sudo_exec apt-get install -y --no-install-recommends $missing - ;; - dnf|emerge|yum|zypper) - sudo_exec "$PACKAGE_MANAGER" update - # shellcheck disable=SC2086 - sudo_exec "$PACKAGE_MANAGER" install -y $missing - ;; - *) - echo "The following packages are missing from your system: $missing" >&2 - echo "Please install these packages before proceeding" >&2 - exit 1; - ;; - esac -fi - -if [ "$PACKAGE_MANAGER" = apk ] -then - if sudo_exec apk add --no-cache ${alpine_openjdk_package} - then - echo "Installed Java to $alpine_openjdk_location" - echo "To start using 'javac', add $alpine_openjdk_location/bin to your PATH:" - echo "export PATH=$alpine_openjdk_location/bin:\$PATH" - fi - exit -fi - - -JDK_FILENAME=$(basename "$JDK_URL") -tmpdir=$(mktemp -d) -trap -- 'rm -rf "$tmpdir"' EXIT - -mkdir "$tmpdir/JAVA_HOME_DIR" -curl -L -o "$tmpdir/$JDK_FILENAME" "$JDK_URL" -tar -xf "$tmpdir/$JDK_FILENAME" -C "$tmpdir/JAVA_HOME_DIR" --strip-components=1 - -if [ -d "$tmpdir/JAVA_HOME_DIR/bin" ] -then - sudo_exec rm -rf "$JAVA_HOME_DIR" - sudo_exec mkdir -p "$(dirname "$JAVA_HOME_DIR")" - sudo_exec mv "$tmpdir/JAVA_HOME_DIR" "$JAVA_HOME_DIR" -else - echo "Error extracting archive contents" >&2 - exit 1 -fi - -echo "Java has been installed in $JAVA_HOME_DIR" - -if command -v update-alternatives >/dev/null -then - update-alternatives --install /usr/bin/java java "$JAVA_HOME_DIR/bin/java" 2000 - update-alternatives --install /usr/bin/javac javac "$JAVA_HOME_DIR/bin/javac" 2000 - update-alternatives --set java "$JAVA_HOME_DIR/bin/java" - update-alternatives --set javac "$JAVA_HOME_DIR/bin/javac" - - echo "and configured as the default JDK using 'update-alternatives'." - echo "If you need to change to another JDK later, you can do so like so:" - echo " update-alternatives --config java" - echo " update-alternatives --config javac" -else - echo "To start using it, please set/update your 'JAVA_HOME' and 'PATH' environment variables like so:" - echo - echo "export JAVA_HOME=\"$JAVA_HOME_DIR\"" - echo "export PATH=\"$JAVA_HOME_DIR/bin:\$PATH\"" - echo - echo "Consider adding the above lines to one of your personal initialization files" - echo " like ~/.bashrc, ~/.bash_profile, ~/.profile, or similar." -fi diff --git a/scripts/install_java_macos.sh b/scripts/install_java_macos.sh deleted file mode 100755 index d672e34d133..00000000000 --- a/scripts/install_java_macos.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash - -# Install OpenJDK 11.0.2 on macOS - -set -eu - -# Download and install locations -JDK_URL=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_osx-x64_bin.tar.gz -JAVA_HOME_DIR=/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk - - -OS=$(uname) -if [[ $OS != Darwin ]] -then - echo This script supports macOS only >&2 - exit 1 -fi - -command -v curl >/dev/null || { echo "cURL is not available" >&2; exit 1; } -command -v tar >/dev/null || { echo "tar is not available" >&2; exit 1; } - -sudo_exec () { - if [[ $EUID -eq 0 ]] - then - "$@" - else - sudo "$@" - fi -} - -JDK_FILENAME=$(basename "$JDK_URL") - -tmpdir=$(mktemp -d) -trap -- 'rm -rf "$tmpdir"' EXIT - -mkdir "$tmpdir/JAVA_HOME_DIR" -curl -L -o "$tmpdir/$JDK_FILENAME" "$JDK_URL" -tar -xf "$tmpdir/$JDK_FILENAME" -C "$tmpdir/JAVA_HOME_DIR" --strip-components=2 - -if [[ -d "$tmpdir/JAVA_HOME_DIR/Contents" ]] -then - sudo_exec rm -rf "$JAVA_HOME_DIR" - sudo_exec mkdir -p "$(dirname "$JAVA_HOME_DIR")" - sudo_exec mv "$tmpdir/JAVA_HOME_DIR" "$JAVA_HOME_DIR" -else - echo "Error extracting archive contents" >&2 - exit 1 -fi - -echo "Java has been installed in $JAVA_HOME_DIR" -echo "To start using it, please set/update your 'JAVA_HOME' and 'PATH' environment variables like so:" -echo -echo " export JAVA_HOME=\"$JAVA_HOME_DIR/Contents/Home\"" -echo " export PATH=\"$JAVA_HOME_DIR/Contents/Home/bin:\$PATH\"" -echo -echo "Consider adding the above lines to one of your personal initialization files." -echo "(~/.bashrc, ~/.bash_profile, ~/.profile, or similar)." - -export JAVA_HOME="$JAVA_HOME_DIR/Contents/Home" -export PATH="$JAVA_HOME_DIR/Contents/Home/bin":$PATH From 516df168fd01619bc9432b4e40edb58f6c03d3e7 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Sun, 2 Jul 2023 19:36:18 +0200 Subject: [PATCH 28/31] Move bisq-* scripts from root directory to scripts directory --- .gitignore | 2 ++ Makefile | 10 +++++----- build.gradle | 14 +++++++------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 25ccd9afd15..3e187d24ddb 100644 --- a/.gitignore +++ b/.gitignore @@ -23,7 +23,9 @@ build *.~ava /bundles /bisq-* +/scripts/bisq-* /lib +/scripts/lib /xchange desktop.ini */target/* diff --git a/Makefile b/Makefile index 935fe586bf0..0c04df0004e 100644 --- a/Makefile +++ b/Makefile @@ -190,7 +190,7 @@ bitcoind: .localnet -blocknotify='.localnet/bitcoind/blocknotify %s' seednode: seednode/build - ./bisq-seednode \ + ./scripts/bisq-seednode \ --baseCurrencyNetwork=BTC_REGTEST \ --useLocalhostForP2P=true \ --useDevPrivilegeKeys=true \ @@ -203,7 +203,7 @@ seednode: seednode/build --appName=seednode seednode2: seednode/build - ./bisq-seednode \ + ./scripts/bisq-seednode \ --baseCurrencyNetwork=BTC_REGTEST \ --useLocalhostForP2P=true \ --useDevPrivilegeKeys=true \ @@ -216,7 +216,7 @@ seednode2: seednode/build --appName=seednode2 mediator: desktop/build - ./bisq-desktop \ + ./scripts/bisq-desktop \ --baseCurrencyNetwork=BTC_REGTEST \ --useLocalhostForP2P=true \ --useDevPrivilegeKeys=true \ @@ -225,7 +225,7 @@ mediator: desktop/build --appName=Mediator alice: setup - ./bisq-desktop \ + ./scripts/bisq-desktop \ --baseCurrencyNetwork=BTC_REGTEST \ --useLocalhostForP2P=true \ --useDevPrivilegeKeys=true \ @@ -240,7 +240,7 @@ alice: setup --appName=Alice bob: setup - ./bisq-desktop \ + ./scripts/bisq-desktop \ --baseCurrencyNetwork=BTC_REGTEST \ --useLocalhostForP2P=true \ --useDevPrivilegeKeys=true \ diff --git a/build.gradle b/build.gradle index 1be40c69ac0..677630b0244 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ configure(rootProject) { // remove the 'bisq-*' scripts and 'lib' dir generated by the 'installDist' task task clean { doLast { - delete fileTree(dir: rootProject.projectDir, include: 'bisq-*'), 'lib' + delete fileTree(dir: "$rootProject.projectDir/scripts", include: 'bisq-*'), "$rootProject.projectDir/scripts/lib" } } } @@ -59,27 +59,27 @@ configure([project(':cli'), copy { from "$destinationDir/bin" - into rootProject.projectDir + into "$rootProject.projectDir/scripts" } // copy libs required for generated shell script classpaths to 'lib' dir under // the project root directory copy { from "$destinationDir/lib" - into "${rootProject.projectDir}/lib" + into "${rootProject.projectDir}/scripts/lib" } // edit generated shell scripts such that they expect to be executed in the // project root dir as opposed to a 'bin' subdirectory - def windowsScriptFile = file("${rootProject.projectDir}/bisq-${applicationName}.bat") + def windowsScriptFile = file("${rootProject.projectDir}/scripts/bisq-${applicationName}.bat") windowsScriptFile.text = windowsScriptFile.text.replace( 'set APP_HOME=%DIRNAME%..', 'set APP_HOME=%DIRNAME%') - def unixScriptFile = file("${rootProject.projectDir}/bisq-$applicationName") + def unixScriptFile = file("${rootProject.projectDir}/scripts/bisq-$applicationName") unixScriptFile.text = unixScriptFile.text.replace( 'APP_HOME=$( cd "${APP_HOME:-./}.." && pwd -P ) || exit', 'APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit') if (applicationName == 'desktop') { - def script = file("${rootProject.projectDir}/bisq-$applicationName") + def script = file("${rootProject.projectDir}/scripts/bisq-$applicationName") script.text = script.text.replace( 'DEFAULT_JVM_OPTS=""', 'DEFAULT_JVM_OPTS="-XX:MaxRAM=8g -Xss1280k -XX:+UseG1GC ' + '-XX:MaxHeapFreeRatio=10 -XX:MinHeapFreeRatio=5 -XX:+UseStringDeduplication ' + @@ -90,7 +90,7 @@ configure([project(':cli'), // Pass the logback config file as a system property to avoid chatty // logback startup due to multiple logback.xml files in the classpath // (:daemon & :cli). - def script = file("${rootProject.projectDir}/bisq-$applicationName") + def script = file("${rootProject.projectDir}/scripts/bisq-$applicationName") script.text = script.text.replace( 'DEFAULT_JVM_OPTS=""', 'DEFAULT_JVM_OPTS="' + '-Dlogback.configurationFile=apitest/build/resources/main/logback.xml"') From b9d20d2da1d89e121b474d2dd2040428bfccfe65 Mon Sep 17 00:00:00 2001 From: Alva Swanson Date: Wed, 12 Jul 2023 11:36:25 +0200 Subject: [PATCH 29/31] GitHub Actions: Upload Coverage Report to Codacy Co-authored-by: napoly --- .github/workflows/build.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7283a45b52c..44dbd92fcb5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,3 +29,25 @@ jobs: uses: gradle/gradle-build-action@v2.5.1 with: arguments: build jacocoTestReport testCodeCoverageReport --scan + + - name: Upload coverage report + uses: actions/upload-artifact@v3 + with: + name: coverage-report + path: code-coverage-report/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml + + publish_coverage: + name: Publish coverage + runs-on: ubuntu-latest + needs: build + steps: + - name: Download coverage report + uses: actions/download-artifact@v3 + with: + name: coverage-report + path: code-coverage-report/build/reports/jacoco/testCodeCoverageReport + - name: Run codacy-coverage-reporter + uses: codacy/codacy-coverage-reporter-action@v1.3.0 + with: + project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} + coverage-reports: ${{ github.workspace }}/code-coverage-report/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml From e5aef09e9615f2ce37ba02db29c8d3f3e704b194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Garc=C3=ADa?= <117378669+alejandrogarcia83@users.noreply.github.com> Date: Wed, 12 Jul 2023 13:53:13 +0000 Subject: [PATCH 30/31] Revert "Move bisq-* scripts from root directory to scripts directory" --- .gitignore | 2 -- Makefile | 10 +++++----- build.gradle | 14 +++++++------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 3e187d24ddb..25ccd9afd15 100644 --- a/.gitignore +++ b/.gitignore @@ -23,9 +23,7 @@ build *.~ava /bundles /bisq-* -/scripts/bisq-* /lib -/scripts/lib /xchange desktop.ini */target/* diff --git a/Makefile b/Makefile index 0c04df0004e..935fe586bf0 100644 --- a/Makefile +++ b/Makefile @@ -190,7 +190,7 @@ bitcoind: .localnet -blocknotify='.localnet/bitcoind/blocknotify %s' seednode: seednode/build - ./scripts/bisq-seednode \ + ./bisq-seednode \ --baseCurrencyNetwork=BTC_REGTEST \ --useLocalhostForP2P=true \ --useDevPrivilegeKeys=true \ @@ -203,7 +203,7 @@ seednode: seednode/build --appName=seednode seednode2: seednode/build - ./scripts/bisq-seednode \ + ./bisq-seednode \ --baseCurrencyNetwork=BTC_REGTEST \ --useLocalhostForP2P=true \ --useDevPrivilegeKeys=true \ @@ -216,7 +216,7 @@ seednode2: seednode/build --appName=seednode2 mediator: desktop/build - ./scripts/bisq-desktop \ + ./bisq-desktop \ --baseCurrencyNetwork=BTC_REGTEST \ --useLocalhostForP2P=true \ --useDevPrivilegeKeys=true \ @@ -225,7 +225,7 @@ mediator: desktop/build --appName=Mediator alice: setup - ./scripts/bisq-desktop \ + ./bisq-desktop \ --baseCurrencyNetwork=BTC_REGTEST \ --useLocalhostForP2P=true \ --useDevPrivilegeKeys=true \ @@ -240,7 +240,7 @@ alice: setup --appName=Alice bob: setup - ./scripts/bisq-desktop \ + ./bisq-desktop \ --baseCurrencyNetwork=BTC_REGTEST \ --useLocalhostForP2P=true \ --useDevPrivilegeKeys=true \ diff --git a/build.gradle b/build.gradle index 677630b0244..1be40c69ac0 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ configure(rootProject) { // remove the 'bisq-*' scripts and 'lib' dir generated by the 'installDist' task task clean { doLast { - delete fileTree(dir: "$rootProject.projectDir/scripts", include: 'bisq-*'), "$rootProject.projectDir/scripts/lib" + delete fileTree(dir: rootProject.projectDir, include: 'bisq-*'), 'lib' } } } @@ -59,27 +59,27 @@ configure([project(':cli'), copy { from "$destinationDir/bin" - into "$rootProject.projectDir/scripts" + into rootProject.projectDir } // copy libs required for generated shell script classpaths to 'lib' dir under // the project root directory copy { from "$destinationDir/lib" - into "${rootProject.projectDir}/scripts/lib" + into "${rootProject.projectDir}/lib" } // edit generated shell scripts such that they expect to be executed in the // project root dir as opposed to a 'bin' subdirectory - def windowsScriptFile = file("${rootProject.projectDir}/scripts/bisq-${applicationName}.bat") + def windowsScriptFile = file("${rootProject.projectDir}/bisq-${applicationName}.bat") windowsScriptFile.text = windowsScriptFile.text.replace( 'set APP_HOME=%DIRNAME%..', 'set APP_HOME=%DIRNAME%') - def unixScriptFile = file("${rootProject.projectDir}/scripts/bisq-$applicationName") + def unixScriptFile = file("${rootProject.projectDir}/bisq-$applicationName") unixScriptFile.text = unixScriptFile.text.replace( 'APP_HOME=$( cd "${APP_HOME:-./}.." && pwd -P ) || exit', 'APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit') if (applicationName == 'desktop') { - def script = file("${rootProject.projectDir}/scripts/bisq-$applicationName") + def script = file("${rootProject.projectDir}/bisq-$applicationName") script.text = script.text.replace( 'DEFAULT_JVM_OPTS=""', 'DEFAULT_JVM_OPTS="-XX:MaxRAM=8g -Xss1280k -XX:+UseG1GC ' + '-XX:MaxHeapFreeRatio=10 -XX:MinHeapFreeRatio=5 -XX:+UseStringDeduplication ' + @@ -90,7 +90,7 @@ configure([project(':cli'), // Pass the logback config file as a system property to avoid chatty // logback startup due to multiple logback.xml files in the classpath // (:daemon & :cli). - def script = file("${rootProject.projectDir}/scripts/bisq-$applicationName") + def script = file("${rootProject.projectDir}/bisq-$applicationName") script.text = script.text.replace( 'DEFAULT_JVM_OPTS=""', 'DEFAULT_JVM_OPTS="' + '-Dlogback.configurationFile=apitest/build/resources/main/logback.xml"') From 08e0259a810c4d833325032295c9cc26723f00ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Garc=C3=ADa?= <117378669+alejandrogarcia83@users.noreply.github.com> Date: Wed, 12 Jul 2023 13:54:21 +0000 Subject: [PATCH 31/31] Revert "Remove Java Installation Scripts" --- scripts/install_java.bat | 56 +++++++++++++ scripts/install_java.sh | 82 +++++++++++++++++++ scripts/install_java_linux.sh | 143 ++++++++++++++++++++++++++++++++++ scripts/install_java_macos.sh | 60 ++++++++++++++ 4 files changed, 341 insertions(+) create mode 100755 scripts/install_java.bat create mode 100755 scripts/install_java.sh create mode 100755 scripts/install_java_linux.sh create mode 100755 scripts/install_java_macos.sh diff --git a/scripts/install_java.bat b/scripts/install_java.bat new file mode 100755 index 00000000000..184afbb52fb --- /dev/null +++ b/scripts/install_java.bat @@ -0,0 +1,56 @@ +:: This script will download and install the appropriate JDK for use with Bisq development. +:: It will also configure it as the default system JDK. +:: If you need to change to another default JDK for another purpose later, you just need to +:: change the JAVA_HOME environment variable. For example, use the following command: +:: setx /M JAVA_HOME "" + +@echo off + +:: Ensure we have administrative privileges in order to install files and set environment variables +>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" +if '%errorlevel%' == '0' ( + ::If no error is encountered, we have administrative privileges + goto GotAdminPrivileges +) +echo Requesting administrative privileges... +echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadminprivileges.vbs" +set params = %*:"="" +echo UAC.ShellExecute "%~s0", "%params%", "", "runas", 1 >> "%temp%\getadminprivileges.vbs" +"%temp%\getadminprivileges.vbs" +exit /B +:GotAdminPrivileges +if exist "%temp%\getadminprivileges.vbs" ( del "%temp%\getadminprivileges.vbs" ) +pushd "%CD%" +cd /D "%~dp0" + +title Install Java + +set jdk_version=11.0.2 +set jdk_filename=openjdk-%jdk_version%_windows-x64_bin +set jdk_url=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_windows-x64_bin.zip + +if exist "%PROGRAMFILES%\Java\openjdk\jdk-%jdk_version%" ( + echo %PROGRAMFILES%\Java\openjdk\jdk-%jdk_version% already exists, skipping install + goto SetEnvVars +) + +echo Downloading required files to %TEMP% +powershell -Command "Invoke-WebRequest %jdk_url% -OutFile $env:temp\%jdk_filename%.zip" + +echo Extracting and installing JDK to %PROGRAMFILES%\Java\openjdk\jdk-%jdk_version% +powershell -Command "Expand-Archive $env:temp\%jdk_filename%.zip -DestinationPath %TEMP%\openjdk-%jdk_version% -Force" +md "%PROGRAMFILES%\Java\openjdk" +move "%TEMP%\openjdk-%jdk_version%\jdk-%jdk_version%" "%PROGRAMFILES%\Java\openjdk" + +echo Removing downloaded files +rmdir /S /Q %TEMP%\openjdk-%jdk_version% +del /Q %TEMP%\%jdk_filename%.zip + +:SetEnvVars +echo Setting environment variables +powershell -Command "[Environment]::SetEnvironmentVariable('JAVA_HOME', '%PROGRAMFILES%\Java\openjdk\jdk-%jdk_version%', 'Machine')" +set java_bin=%%JAVA_HOME%%\bin +echo %PATH%|find /i "%java_bin%">nul || powershell -Command "[Environment]::SetEnvironmentVariable('PATH', '%PATH%;%java_bin%', 'Machine')" + +echo Done! +pause diff --git a/scripts/install_java.sh b/scripts/install_java.sh new file mode 100755 index 00000000000..5b06dfe3a8d --- /dev/null +++ b/scripts/install_java.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash +# This script will download and install the appropriate JDK for use with Bisq development. +# It will also configure it as the default system JDK. +# If you need to change to another default JDK for another purpose later, you can use the +# following commands and select the default JDK: +# Linux: +# update-alternatives --config java +# update-alternatives --config javac +# MacOS: +# echo 'export JAVA_HOME=/Library/Java/JavaVirtualMachines//Contents/Home' >>~/.bash_profile +# echo 'export PATH=$JAVA_HOME/bin:$PATH' >>~/.bash_profile +# source ~/.bash_profile +set -e + +unameOut="$(uname -s)" +case "${unameOut}" in + Linux*) + JAVA_HOME=/usr/lib/jvm/openjdk-11.0.2 + JDK_FILENAME=openjdk-11.0.2_linux-x64_bin.tar.gz + JDK_URL=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz + + # Determine which package manager to use depending on the distribution + declare -A osInfo; + osInfo[/etc/redhat-release]=yum + osInfo[/etc/arch-release]=pacman + osInfo[/etc/gentoo-release]=emerge + osInfo[/etc/SuSE-release]=zypp + osInfo[/etc/debian_version]=apt-get + + for f in "${!osInfo[@]}" + do + if [[ -f $f ]]; then + PACKAGE_MANAGER=${osInfo[$f]} + break + fi + done + + if [ ! -d "$JAVA_HOME" ]; then + # Ensure curl is installed since it may not be + $PACKAGE_MANAGER -y install curl + + curl -L -O $JDK_URL + mkdir -p $JAVA_HOME + tar -zxf $JDK_FILENAME -C $JAVA_HOME --strip 1 + rm $JDK_FILENAME + + update-alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 2000 + update-alternatives --install /usr/bin/javac javac $JAVA_HOME/bin/javac 2000 + fi + + update-alternatives --set java $JAVA_HOME/bin/java + update-alternatives --set javac $JAVA_HOME/bin/javac + ;; + Darwin*) + JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home + JDK_FILENAME=openjdk-11.0.2_osx-x64_bin.tar.gz + JDK_URL=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_osx-x64_bin.tar.gz + if [ ! -d "$JAVA_HOME" ]; then + if [[ $(command -v brew) == "" ]]; then + echo "Installing Homebrew" + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + else + echo "Updating Homebrew" + brew update + fi + + brew install curl + curl -L -O $JDK_URL + sudo mkdir /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk | sudo bash + gunzip -c $JDK_FILENAME | tar xopf - + sudo mv jdk-11.0.2.jdk/* /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk + sudo rmdir jdk-11.0.2.jdk + rm $JDK_FILENAME + fi + + echo export JAVA_HOME=$JAVA_HOME >>~/.bash_profile + echo export PATH=$JAVA_HOME/bin:"$PATH" >>~/.bash_profile + source "$HOME/.bash_profile" + ;; + *) +esac +java -version diff --git a/scripts/install_java_linux.sh b/scripts/install_java_linux.sh new file mode 100755 index 00000000000..ebb541b8db1 --- /dev/null +++ b/scripts/install_java_linux.sh @@ -0,0 +1,143 @@ +#!/bin/bash + +# Install OpenJDK 11.0.2 on Linux + +set -eu + +# Download and install locations +JDK_URL=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz +JAVA_HOME_DIR=/usr/lib/jvm/openjdk-11.0.2 + +alpine_openjdk_package=openjdk11 +alpine_openjdk_location=/usr/lib/jvm/java-11-openjdk + + +OS=$(uname) +if [ "$OS" != Linux ] +then + echo This script supports Linux only >&2 + exit 1 +fi + +PACKAGE_MANAGER= +for tool in apk yum pacman emerge zypper apt-get dnf +do + if command -v $tool >/dev/null + then + PACKAGE_MANAGER=$tool + break + fi +done + +if [ -z "$PACKAGE_MANAGER" ] +then + echo "Unknown OS" >&2 +fi + +missing= +for cmd in curl tar gzip +do + if ! command -v $cmd >/dev/null + then + missing="${missing+$missing }$cmd" + if [ "$cmd" = curl ] + then + missing="$missing ca-certificates" + fi + fi +done + +sudo_exec () { + if [ "${EID-500}" -eq 0 ] || [ "${HOME-/home}" = /root ] + then + "$@" + elif command -v sudo + then + sudo "$@" + else + echo "Can't execute with elevated priviliges: $*" >&2 + exit 1 + fi +} + +# Install missing packages +if [ -n "$missing" ] +then + case "$PACKAGE_MANAGER" in + apk) + : no need to install missing packages, because + : we will install OpenJDK using apk + ;; + pacman) + sudo_exec pacman -Syy --noconfirm "$missing" + ;; + apt-get) + sudo_exec apt-get update + # shellcheck disable=SC2086 + sudo_exec apt-get install -y --no-install-recommends $missing + ;; + dnf|emerge|yum|zypper) + sudo_exec "$PACKAGE_MANAGER" update + # shellcheck disable=SC2086 + sudo_exec "$PACKAGE_MANAGER" install -y $missing + ;; + *) + echo "The following packages are missing from your system: $missing" >&2 + echo "Please install these packages before proceeding" >&2 + exit 1; + ;; + esac +fi + +if [ "$PACKAGE_MANAGER" = apk ] +then + if sudo_exec apk add --no-cache ${alpine_openjdk_package} + then + echo "Installed Java to $alpine_openjdk_location" + echo "To start using 'javac', add $alpine_openjdk_location/bin to your PATH:" + echo "export PATH=$alpine_openjdk_location/bin:\$PATH" + fi + exit +fi + + +JDK_FILENAME=$(basename "$JDK_URL") +tmpdir=$(mktemp -d) +trap -- 'rm -rf "$tmpdir"' EXIT + +mkdir "$tmpdir/JAVA_HOME_DIR" +curl -L -o "$tmpdir/$JDK_FILENAME" "$JDK_URL" +tar -xf "$tmpdir/$JDK_FILENAME" -C "$tmpdir/JAVA_HOME_DIR" --strip-components=1 + +if [ -d "$tmpdir/JAVA_HOME_DIR/bin" ] +then + sudo_exec rm -rf "$JAVA_HOME_DIR" + sudo_exec mkdir -p "$(dirname "$JAVA_HOME_DIR")" + sudo_exec mv "$tmpdir/JAVA_HOME_DIR" "$JAVA_HOME_DIR" +else + echo "Error extracting archive contents" >&2 + exit 1 +fi + +echo "Java has been installed in $JAVA_HOME_DIR" + +if command -v update-alternatives >/dev/null +then + update-alternatives --install /usr/bin/java java "$JAVA_HOME_DIR/bin/java" 2000 + update-alternatives --install /usr/bin/javac javac "$JAVA_HOME_DIR/bin/javac" 2000 + update-alternatives --set java "$JAVA_HOME_DIR/bin/java" + update-alternatives --set javac "$JAVA_HOME_DIR/bin/javac" + + echo "and configured as the default JDK using 'update-alternatives'." + echo "If you need to change to another JDK later, you can do so like so:" + echo " update-alternatives --config java" + echo " update-alternatives --config javac" +else + echo "To start using it, please set/update your 'JAVA_HOME' and 'PATH' environment variables like so:" + echo + echo "export JAVA_HOME=\"$JAVA_HOME_DIR\"" + echo "export PATH=\"$JAVA_HOME_DIR/bin:\$PATH\"" + echo + echo "Consider adding the above lines to one of your personal initialization files" + echo " like ~/.bashrc, ~/.bash_profile, ~/.profile, or similar." +fi diff --git a/scripts/install_java_macos.sh b/scripts/install_java_macos.sh new file mode 100755 index 00000000000..d672e34d133 --- /dev/null +++ b/scripts/install_java_macos.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +# Install OpenJDK 11.0.2 on macOS + +set -eu + +# Download and install locations +JDK_URL=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_osx-x64_bin.tar.gz +JAVA_HOME_DIR=/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk + + +OS=$(uname) +if [[ $OS != Darwin ]] +then + echo This script supports macOS only >&2 + exit 1 +fi + +command -v curl >/dev/null || { echo "cURL is not available" >&2; exit 1; } +command -v tar >/dev/null || { echo "tar is not available" >&2; exit 1; } + +sudo_exec () { + if [[ $EUID -eq 0 ]] + then + "$@" + else + sudo "$@" + fi +} + +JDK_FILENAME=$(basename "$JDK_URL") + +tmpdir=$(mktemp -d) +trap -- 'rm -rf "$tmpdir"' EXIT + +mkdir "$tmpdir/JAVA_HOME_DIR" +curl -L -o "$tmpdir/$JDK_FILENAME" "$JDK_URL" +tar -xf "$tmpdir/$JDK_FILENAME" -C "$tmpdir/JAVA_HOME_DIR" --strip-components=2 + +if [[ -d "$tmpdir/JAVA_HOME_DIR/Contents" ]] +then + sudo_exec rm -rf "$JAVA_HOME_DIR" + sudo_exec mkdir -p "$(dirname "$JAVA_HOME_DIR")" + sudo_exec mv "$tmpdir/JAVA_HOME_DIR" "$JAVA_HOME_DIR" +else + echo "Error extracting archive contents" >&2 + exit 1 +fi + +echo "Java has been installed in $JAVA_HOME_DIR" +echo "To start using it, please set/update your 'JAVA_HOME' and 'PATH' environment variables like so:" +echo +echo " export JAVA_HOME=\"$JAVA_HOME_DIR/Contents/Home\"" +echo " export PATH=\"$JAVA_HOME_DIR/Contents/Home/bin:\$PATH\"" +echo +echo "Consider adding the above lines to one of your personal initialization files." +echo "(~/.bashrc, ~/.bash_profile, ~/.profile, or similar)." + +export JAVA_HOME="$JAVA_HOME_DIR/Contents/Home" +export PATH="$JAVA_HOME_DIR/Contents/Home/bin":$PATH