Skip to content

Commit 0be8be2

Browse files
authored
Merge pull request #7956 from apache/delivery
Sync delivery to release240 for 24-rc3
2 parents 4aeb2be + ae5d1d6 commit 0be8be2

File tree

11 files changed

+203
-24
lines changed

11 files changed

+203
-24
lines changed

enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/ConfigMapUploader.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.netbeans.api.project.ProjectInformation;
2424
import org.netbeans.api.project.ProjectUtils;
2525
import static org.netbeans.modules.cloud.oracle.NotificationUtils.showMessage;
26+
import org.netbeans.modules.cloud.oracle.assets.CloudAssets;
2627
import org.netbeans.modules.cloud.oracle.assets.ConfigMapProvider;
2728
import org.netbeans.modules.cloud.oracle.assets.Steps;
2829
import org.netbeans.modules.cloud.oracle.compute.ClusterItem;
@@ -40,22 +41,25 @@
4041
* @author Dusan Petrovic
4142
*/
4243
@NbBundle.Messages({
43-
"SuggestRerun=The changes will take place only after restarting the application"
44+
"SuggestRerun=The changes will take place only after restarting the application",
45+
"ClusterNotPresent=Please add the OKE Cluster first"
4446
})
4547
public class ConfigMapUploader {
4648

4749

4850
public static void uploadConfigMap(CompletableFuture<Object> future) {
51+
ClusterItem cluster = CloudAssets.getDefault().getItem(ClusterItem.class);
52+
if (cluster == null) {
53+
showMessage(Bundle.ClusterNotPresent());
54+
return;
55+
}
4956
Steps.NextStepProvider nsProvider = Steps.NextStepProvider.builder()
5057
.stepForClass(ProjectStep.class, (s) -> new TenancyStep())
51-
.stepForClass(TenancyStep.class, (s) -> new CompartmentStep())
52-
.stepForClass(CompartmentStep.class, (s) -> new SuggestedStep("Cluster"))
5358
.build();
5459
Lookup lookup = Lookups.fixed(nsProvider);
5560
Steps.getDefault().executeMultistep(new ProjectStep(), lookup)
5661
.thenAccept(values -> {
5762
Project project = values.getValueForStep(ProjectStep.class);
58-
ClusterItem cluster = (ClusterItem) values.getValueForStep(SuggestedStep.class);
5963
ProjectInformation projectInfo = ProjectUtils.getInformation(project);
6064
ConfigMapProvider configMapProvider = new ConfigMapProvider(projectInfo.getDisplayName(), cluster);
6165
configMapProvider.createConfigMap();

enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/CloudAssets.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,28 @@ public static synchronized CloudAssets getDefault() {
139139
return instance;
140140
}
141141

142-
public synchronized void addItem(OCIItem newItem) {
142+
public synchronized boolean addItem(OCIItem newItem) {
143143
Parameters.notNull("newItem cannot be null", newItem);
144144
long presentCount = items.stream()
145145
.filter(i -> i.getKey().getPath().equals(newItem.getKey().getPath()))
146146
.count();
147147
if (newItem.maxInProject() > presentCount && isTenancyCompatible(newItem, true)) {
148+
if (newItem instanceof Validator) {
149+
Validator.Result result = ((Validator) newItem).validate();
150+
if (result.status == Validator.ValidationStatus.WARNING) {
151+
showWarningMessage(result.message);
152+
}
153+
if (result.status == Validator.ValidationStatus.ERROR) {
154+
showWarningMessage(result.message);
155+
return false;
156+
}
157+
}
148158
items.add(newItem);
149159
newItem.addChangeListener(itemsListener);
150160
update();
151161
storeAssets();
152162
}
163+
return true;
153164
}
154165

155166
synchronized void removeItem(OCIItem item) {
@@ -184,7 +195,7 @@ public synchronized boolean isTenancyCompatible(OCIItem toCheck) {
184195
}
185196

186197
public synchronized boolean isTenancyCompatible(OCIItem toCheck, boolean showWarning) {
187-
List<OCIItem> itemsMissingInfo = new ArrayList();
198+
List<OCIItem> itemsMissingInfo = new ArrayList<> ();
188199
for(OCIItem item: items) {
189200
if (item != null && item.getTenancyId() == null) {
190201
itemsMissingInfo.add(item);

enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/CreateConfigCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class CreateConfigCommand implements CommandProvider {
4040
private static final String COMMAND_UPLOAD_TO_CONFIGMAP_WITHIN_DEVOPS = "nbls.cloud.assets.configmap.devops.upload"; //NOI18N
4141
private static final String COMMAND_UPLOAD_TO_CONFIGMAP = "nbls.cloud.assets.configmap.upload"; //NOI18N
4242

43-
private static final Set COMMANDS = new HashSet<>(Arrays.asList(
43+
private static final Set<String> COMMANDS = new HashSet<>(Arrays.asList(
4444
COMMAND_CREATE_CONFIG,
4545
COMMAND_UPLOAD_TO_CONFIGMAP_WITHIN_DEVOPS,
4646
COMMAND_UPLOAD_TO_CONFIGMAP
@@ -53,7 +53,7 @@ public Set<String> getCommands() {
5353

5454
@Override
5555
public CompletableFuture<Object> runCommand(String command, List<Object> arguments) {
56-
CompletableFuture future = new CompletableFuture();
56+
CompletableFuture<Object> future = new CompletableFuture<>();
5757
if (COMMAND_CREATE_CONFIG.equals(command)) {
5858
PropertiesGenerator propGen = new PropertiesGenerator(false);
5959
ApplicationPropertiesGenerator appPropGen = new ApplicationPropertiesGenerator(propGen);

enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/PropertiesGenerator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public PropertiesGenerator(boolean local) {
139139
}
140140
if (vault != null) {
141141
bootstrap.put("oci.vault.config.enabled", "true"); // NOI18N
142+
bootstrap.put("micronaut.config-client.enabled", "true"); // NOI18N
142143
bootstrap.put("oci.vault.vaults[0].ocid", vault.getKey().getValue()); //NOI18N
143144
bootstrap.put("oci.vault.vaults[0].compartment-ocid", vault.getCompartmentId()); //NOI18N
144145
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.netbeans.modules.cloud.oracle.assets;
20+
21+
/**
22+
* Validates if the implementing class is suitable for adding to {@link CloudAssets}.
23+
* The validation result is represented by {@link Result}, which includes a {@link ValidationStatus}
24+
* indicating the outcome of the validation.
25+
*
26+
* <p>The possible validation states are:
27+
* <ul>
28+
* <li>{@link ValidationStatus#OK} - Indicates that the item is suitable for adding to {@link CloudAssets}
29+
* without any warnings or restrictions.</li>
30+
* <li>{@link ValidationStatus#WARNING} - Indicates that the item may be added to {@link CloudAssets},
31+
* but with a warning message to notify the user of potential issues.</li>
32+
* <li>{@link ValidationStatus#ERROR} - Indicates that the item cannot be added to {@link CloudAssets}.
33+
* A warning message will be shown, and the addition process will be blocked.</li>
34+
* </ul>
35+
*
36+
* @author Jan Horvath
37+
*/
38+
public interface Validator {
39+
40+
enum ValidationStatus {
41+
OK, WARNING, ERROR
42+
};
43+
44+
public class Result {
45+
46+
public final ValidationStatus status;
47+
public final String message;
48+
49+
public Result(ValidationStatus status, String message) {
50+
this.status = status;
51+
this.message = message;
52+
}
53+
54+
}
55+
56+
public Result validate();
57+
58+
}

enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/compute/ComputeInstanceItem.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,19 @@
2626
import org.netbeans.modules.cloud.oracle.items.OCID;
2727
import org.netbeans.modules.cloud.oracle.items.OCIItem;
2828
import org.openide.util.Exceptions;
29+
import org.openide.util.NbBundle;
30+
import org.netbeans.modules.cloud.oracle.assets.Validator;
2931

3032
/**
3133
*
3234
* @author Jan Horvath
3335
*/
34-
public final class ComputeInstanceItem extends OCIItem implements URLProvider {
36+
@NbBundle.Messages({
37+
"SuggestAmpere=The Compute Instance has a different architecture than the local machine. Container images built on the local machine may not be compatible with this Compute Instance. Please consider creating a Compute Instance with an Ampere® shape.",
38+
"SuggestIntel=The Compute Instance has a different architecture than the local machine. Container images built on the local machine may not be compatible with this Compute Instance. Please consider creating a Compute Instance with an AMD or Intel® shape."
39+
})
40+
public final class ComputeInstanceItem extends OCIItem implements URLProvider, Validator {
41+
private final String AARCH = "aarch64";
3542
private String publicIp = null;
3643
private String processorDescription;
3744
private String username;
@@ -88,4 +95,19 @@ public URL getURL() {
8895
}
8996
return null;
9097
}
98+
99+
@Override
100+
public Result validate() {
101+
String osArch = System.getProperty("os.arch"); //NOI18N
102+
String shapeDesc = getProcessorDescription();
103+
boolean os_arm = AARCH.equals(osArch);
104+
boolean shape_arm = shapeDesc != null && shapeDesc.contains("Ampere"); //NOI18N
105+
if (os_arm == shape_arm) {
106+
return new Result(ValidationStatus.OK, null);
107+
} else if (os_arm && !shape_arm) {
108+
return new Result(ValidationStatus.WARNING, Bundle.SuggestAmpere());
109+
}
110+
return new Result(ValidationStatus.WARNING, Bundle.SuggestIntel());
111+
}
112+
91113
}

enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/developer/ContainerRepositoryItem.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@
1818
*/
1919
package org.netbeans.modules.cloud.oracle.developer;
2020

21+
import java.net.MalformedURLException;
22+
import java.net.URI;
23+
import java.net.URISyntaxException;
24+
import java.net.URL;
25+
import org.netbeans.modules.cloud.oracle.adm.URLProvider;
2126
import org.netbeans.modules.cloud.oracle.items.OCID;
2227
import org.netbeans.modules.cloud.oracle.items.OCIItem;
28+
import org.openide.util.Exceptions;
2329

2430
/**
2531
*
2632
* @author Jan Horvath
2733
*/
28-
public final class ContainerRepositoryItem extends OCIItem {
34+
public final class ContainerRepositoryItem extends OCIItem implements URLProvider {
2935

3036
private Boolean isPublic;
3137
private Integer imageCount;
@@ -65,5 +71,18 @@ public String getUrl() {
6571
public String getRegistry() {
6672
return String.format("%s.ocir.io", getRegionCode());
6773
}
74+
75+
@Override
76+
public URL getURL() {
77+
if (getKey().getValue() != null && getRegion() != null) {
78+
try {
79+
URI uri = new URI(String.format("https://cloud.oracle.com/compute/registry/containers?region=%s", getRegion()));
80+
return uri.toURL();
81+
} catch (MalformedURLException | URISyntaxException ex) {
82+
Exceptions.printStackTrace(ex);
83+
}
84+
}
85+
return null;
86+
}
6887

6988
}

enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/developer/ContainerTagItem.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@
1818
*/
1919
package org.netbeans.modules.cloud.oracle.developer;
2020

21+
import java.net.MalformedURLException;
22+
import java.net.URI;
23+
import java.net.URISyntaxException;
24+
import java.net.URL;
25+
import org.netbeans.modules.cloud.oracle.adm.URLProvider;
2126
import org.netbeans.modules.cloud.oracle.items.OCID;
2227
import org.netbeans.modules.cloud.oracle.items.OCIItem;
28+
import org.openide.util.Exceptions;
2329

2430
/**
2531
*
2632
* @author Jan Horvath
2733
*/
28-
public final class ContainerTagItem extends OCIItem {
34+
public final class ContainerTagItem extends OCIItem implements URLProvider {
2935

3036
private String digest;
3137
private String version;
@@ -61,5 +67,18 @@ public String getVersion() {
6167
}
6268
return version;
6369
}
70+
71+
@Override
72+
public URL getURL() {
73+
if (getKey().getValue() != null && getRegion() != null) {
74+
try {
75+
URI uri = new URI(String.format("https://cloud.oracle.com/compute/registry/containers?region=%s", getRegion()));
76+
return uri.toURL();
77+
} catch (MalformedURLException | URISyntaxException ex) {
78+
Exceptions.printStackTrace(ex);
79+
}
80+
}
81+
return null;
82+
}
6483

6584
}

java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/TokenList.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,23 @@ public int index() {
365365
}
366366

367367
public void resetToIndex(int index) {
368-
if (ts == null) {
369-
return ;
370-
}
368+
doc.render(() -> {
369+
if (cancel.get()) {
370+
return ;
371+
}
372+
373+
if (ts == null) {
374+
return ;
375+
}
376+
377+
if (!ts.isValid()) {
378+
cancel.set(true);
379+
return ;
380+
}
371381

372-
ts.moveIndex(index);
373-
ts.moveNext();
382+
ts.moveIndex(index);
383+
ts.moveNext();
384+
});
374385
}
375386

376387
private static List<TokenSequence<?>> embeddedTokenSequences(TokenHierarchy<Document> th, int offset) {

java/java.lsp.server/vscode/src/extension.ts

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,12 +1035,22 @@ function activateWithJDK(specifiedJDK: string | null, context: ExtensionContext,
10351035
function runCommandInTerminal(command: string, name: string) {
10361036
const isWindows = process.platform === 'win32';
10371037

1038+
const shell = process.env.SHELL || '/bin/bash';
1039+
const shellName = shell.split('/').pop();
1040+
const isZsh = shellName === 'zsh';
1041+
10381042
const defaultShell = isWindows
10391043
? process.env.ComSpec || 'cmd.exe'
1040-
: process.env.SHELL || '/bin/bash';
1044+
: shell;
1045+
1046+
const pauseCommand = isWindows
1047+
? 'pause'
1048+
: 'echo "Press any key to close..."; ' + (isZsh
1049+
? 'read -rs -k1'
1050+
: 'read -rsn1');
1051+
1052+
const commandWithPause = `${command} && ${pauseCommand}`;
10411053

1042-
const pauseCommand = 'echo "Press any key to close..."; node -e "process.stdin.setRawMode(true); process.stdin.resume(); process.stdin.on(\'data\', process.exit.bind(process, 0));"';
1043-
const commandWithPause = `${command} 2>&1; ${pauseCommand}`;
10441054
const terminal = vscode.window.createTerminal({
10451055
name: name,
10461056
shellPath: defaultShell,
@@ -1098,13 +1108,37 @@ async function runDockerSSH(username: string, host: string, dockerImage: string,
10981108
micronautConfigFilesEnv += `${bootstrapProperties ? "," : ""}${applicationPropertiesContainerPath}`;
10991109
}
11001110

1101-
let dockerPullCommand = "";
1111+
let script = `#!/bin/sh\n`;
1112+
script += `set -e\n`;
1113+
script += `CONTAINER_ID_FILE="/home/${username}/.vscode.container.id"\n`;
1114+
script += `if [ -f "$CONTAINER_ID_FILE" ]; then\n`;
1115+
script += ` CONTAINER_ID=$(cat "$CONTAINER_ID_FILE")\n`;
1116+
script += ` if [ ! -z "$CONTAINER_ID" ] && docker ps -q --filter "id=$CONTAINER_ID" | grep -q .; then\n`;
1117+
script += ` echo "Stopping existing container with ID $CONTAINER_ID..."\n`;
1118+
script += ` docker stop "$CONTAINER_ID"\n`;
1119+
script += ` fi\n`;
1120+
script += ` rm -f "$CONTAINER_ID_FILE"\n`;
1121+
script += `fi\n`;
1122+
11021123
if (isRepositoryPrivate) {
1103-
dockerPullCommand = `cat ${bearerTokenRemotePath} | docker login --username=BEARER_TOKEN --password-stdin ${ocirServer} && `;
1124+
script += `cat ${bearerTokenRemotePath} | docker login --username=BEARER_TOKEN --password-stdin ${ocirServer} \n`;
11041125
}
1105-
dockerPullCommand += `docker pull ${dockerImage} && `;
1126+
script += `docker pull ${dockerImage} \n`;
11061127

1107-
sshCommand += `ssh ${username}@${host} "${dockerPullCommand} docker run -p 8080:8080 ${mountVolume} -e MICRONAUT_CONFIG_FILES=${micronautConfigFilesEnv} -it ${dockerImage}"`;
1128+
script += `NEW_CONTAINER_ID=$(docker run -p 8080:8080 ${mountVolume} -e MICRONAUT_CONFIG_FILES=${micronautConfigFilesEnv} -d ${dockerImage})\n`;
1129+
1130+
script += `if [ -n "$NEW_CONTAINER_ID" ]; then\n`
1131+
script += ` echo $NEW_CONTAINER_ID > $CONTAINER_ID_FILE\n`
1132+
script += `fi\n`
1133+
script += `docker logs -f "$NEW_CONTAINER_ID"\n`
1134+
1135+
const tempDir = process.env.TEMP || process.env.TMP || '/tmp';
1136+
const runContainerScript = path.join(tempDir, `run-container-${Date.now()}.sh`);
1137+
fs.writeFileSync(runContainerScript, script);
1138+
1139+
sshCommand += `scp "${runContainerScript}" ${username}@${host}:run-container.sh && `
1140+
1141+
sshCommand += `ssh ${username}@${host} "chmod +x run-container.sh && ./run-container.sh" `
11081142

11091143
runCommandInTerminal(sshCommand, `Container: ${username}@${host}`)
11101144
}

0 commit comments

Comments
 (0)