Skip to content

Commit cc863fd

Browse files
authored
Merge pull request #7629 from apache/delivery
Sync delivery to release230 for 23-rc2
2 parents b2b45ae + 3134074 commit cc863fd

File tree

29 files changed

+161
-97
lines changed

29 files changed

+161
-97
lines changed

apisupport/maven.apisupport/src/org/netbeans/modules/maven/apisupport/NBMNativeMWI.java

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import java.io.FileOutputStream;
2525
import java.io.IOException;
2626
import java.io.OutputStream;
27-
import java.nio.file.Files;
28-
import java.nio.file.Path;
2927
import java.util.Collections;
3028
import java.util.List;
3129
import java.util.Properties;
@@ -49,6 +47,7 @@
4947
import org.netbeans.modules.maven.model.pom.Project;
5048
import org.netbeans.modules.maven.model.pom.Repository;
5149
import org.netbeans.modules.maven.model.pom.RepositoryPolicy;
50+
import org.netbeans.modules.maven.options.MavenVersionSettings;
5251
import org.netbeans.modules.maven.spi.newproject.CreateProjectBuilder;
5352
import org.openide.util.Exceptions;
5453

@@ -58,12 +57,12 @@
5857
*/
5958
final class NBMNativeMWI {
6059

61-
static void instantiate(ProjectInfo vi, File projFile, String version, boolean useOsgi, MavenProject mp) {
60+
static void instantiate(ProjectInfo vi, File projFile, String nbVersion, boolean useOsgi, MavenProject mp) {
6261
CreateProjectBuilder builder = new CreateProjectBuilder(projFile, vi.groupId, vi.artifactId, vi.version)
6362
.setPackageName(vi.packageName)
6463
.setPackaging("nbm")
6564
.setAdditionalNonPomWork(new AdditionalFiles())
66-
.setAdditionalOperations(new AdditionalOperations(version, useOsgi));
65+
.setAdditionalOperations(new AdditionalOperations(nbVersion, useOsgi));
6766
if (mp != null) {
6867
builder = builder.setParentProject(mp);
6968
}
@@ -237,7 +236,6 @@ public void performOperation(POMModel model) {
237236
//nbm-maven-plugin
238237
boolean addPlugin = true;
239238
String managedPVersion = null;
240-
String pVersion = MavenNbModuleImpl.getLatestNbmPluginVersion();
241239
// boolean useOsgiDepsSet = false;
242240
if (parent != null) {
243241
//TODO do we want to support the case when the plugin is defined in parent pom with inherited=true?
@@ -259,12 +257,13 @@ public void performOperation(POMModel model) {
259257
}
260258
}
261259
}
260+
MavenVersionSettings settings = MavenVersionSettings.getDefault();
262261
if (addPlugin) {
263262
Plugin p = model.getFactory().createPlugin();
264263
p.setGroupId(MavenNbModuleImpl.GROUPID_APACHE);
265264
p.setArtifactId(MavenNbModuleImpl.NBM_PLUGIN);
266265
if (managedPVersion == null) {
267-
p.setVersion(pVersion);
266+
p.setVersion(MavenNbModuleImpl.getLatestNbmPluginVersion());
268267
}
269268
p.setExtensions(true);
270269
if (useOsgi) {
@@ -278,52 +277,44 @@ public void performOperation(POMModel model) {
278277
//now comes the compiler plugin
279278
addPlugin = true;
280279
managedPVersion = null;
281-
String source = null;
282-
String target = null;
283-
pVersion = "3.11.0";
284280
if (parent != null) {
285281
//TODO do we want to support the case when the plugin is defined in parent pom with inherited=true?
286282
PluginManagement pm = parent.getPluginManagement();
287283
if (pm != null) {
288-
for (org.apache.maven.model.Plugin p : pm.getPlugins()) {
289-
if (Constants.GROUP_APACHE_PLUGINS.equals(p.getGroupId()) && Constants.PLUGIN_COMPILER.equals(p.getArtifactId())) {
290-
managedPVersion = p.getVersion();
291-
Xpp3Dom conf = (Xpp3Dom) p.getConfiguration();
292-
if (conf != null) {
293-
Xpp3Dom sourceEl = conf.getChild("source");
294-
if (sourceEl != null) {
295-
source = sourceEl.getValue();
296-
}
297-
Xpp3Dom targetEl = conf.getChild("target");
298-
if (targetEl != null) {
299-
target = targetEl.getValue();
284+
if (parent.getProperties().getProperty("maven.compiler.release") != null) {
285+
addPlugin = false;
286+
} else {
287+
for (org.apache.maven.model.Plugin p : pm.getPlugins()) {
288+
if (Constants.GROUP_APACHE_PLUGINS.equals(p.getGroupId()) && Constants.PLUGIN_COMPILER.equals(p.getArtifactId())) {
289+
managedPVersion = p.getVersion();
290+
Xpp3Dom conf = (Xpp3Dom) p.getConfiguration();
291+
if (conf != null) {
292+
if ( conf.getChild("release") != null
293+
|| conf.getChild("source") != null
294+
|| conf.getChild("target") != null) {
295+
addPlugin = false;
296+
}
300297
}
298+
break;
301299
}
302-
break;
303300
}
304301
}
305302
}
306303
}
307-
addPlugin = target == null || source == null;
308304
if (addPlugin) {
309305
Plugin p = model.getFactory().createPlugin();
310306
p.setGroupId(Constants.GROUP_APACHE_PLUGINS);
311307
p.setArtifactId(Constants.PLUGIN_COMPILER);
312308
if (managedPVersion == null) {
313-
p.setVersion(pVersion);
309+
p.setVersion(settings.getVersion(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_COMPILER));
314310
}
315-
Configuration c = model.getFactory().createConfiguration();
316-
c.setSimpleParameter("source", "1.8");
317-
c.setSimpleParameter("target", "1.8");
318-
p.setConfiguration(c);
319311
getOrCreateBuild(model).addPlugin(p);
312+
model.getProject().getProperties().setProperty("maven.compiler.release", "17");
320313
}
321314

322315
//now the jar plugin
323-
addPlugin = true;
324316
managedPVersion = null;
325317
String useManifest = null;
326-
pVersion = "3.3.0";
327318
if (parent != null) {
328319
//TODO do we want to support the case when the plugin is defined in parent pom with inherited=true?
329320
PluginManagement pm = parent.getPluginManagement();
@@ -359,6 +350,7 @@ public void performOperation(POMModel model) {
359350
p.setGroupId(Constants.GROUP_APACHE_PLUGINS);
360351
p.setArtifactId(Constants.PLUGIN_JAR);
361352
if (managedPVersion == null) {
353+
String pVersion = settings.getVersion(Constants.GROUP_APACHE_PLUGINS, Constants.PLUGIN_JAR);
362354
p.setVersion(pVersion);
363355
managedPVersion = pVersion;
364356
}

apisupport/maven.apisupport/test/unit/src/org/netbeans/modules/maven/apisupport/NBMNativeMWITest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
public class NBMNativeMWITest extends NbTestCase {
4040

41+
private static final String EXPECTED_JAVAC_PLUGIN_VERSION = "3.13.0";
42+
4143
private FileObject wd;
4244

4345
public NBMNativeMWITest(String testName) {
@@ -64,7 +66,7 @@ public void testPathNoParent() throws IOException, XmlPullParserException {
6466
assertEquals("nbm-maven-plugin", model.getBuild().getPlugins().get(0).getArtifactId());
6567
assertEquals(MavenNbModuleImpl.getLatestNbmPluginVersion(), model.getBuild().getPlugins().get(0).getVersion());
6668
assertEquals("maven-compiler-plugin", model.getBuild().getPlugins().get(1).getArtifactId());
67-
assertEquals("3.11.0", model.getBuild().getPlugins().get(1).getVersion());
69+
assertEquals(EXPECTED_JAVAC_PLUGIN_VERSION, model.getBuild().getPlugins().get(1).getVersion());
6870
assertEquals(0, model.getRepositories().size());
6971
}
7072

@@ -82,7 +84,7 @@ public void testPathNoParentSnapshot() throws IOException, XmlPullParserExceptio
8284
assertEquals("nbm-maven-plugin", model.getBuild().getPlugins().get(0).getArtifactId());
8385
assertEquals(MavenNbModuleImpl.getLatestNbmPluginVersion(), model.getBuild().getPlugins().get(0).getVersion());
8486
assertEquals("maven-compiler-plugin", model.getBuild().getPlugins().get(1).getArtifactId());
85-
assertEquals("3.11.0", model.getBuild().getPlugins().get(1).getVersion());
87+
assertEquals(EXPECTED_JAVAC_PLUGIN_VERSION, model.getBuild().getPlugins().get(1).getVersion());
8688
assertEquals(1, model.getRepositories().size());
8789
}
8890

@@ -109,7 +111,7 @@ public void testPathParent() throws IOException, XmlPullParserException {
109111
assertEquals("nbm-maven-plugin", model.getBuild().getPlugins().get(0).getArtifactId());
110112
assertEquals(MavenNbModuleImpl.getLatestNbmPluginVersion(), model.getBuild().getPlugins().get(0).getVersion());
111113
assertEquals("maven-compiler-plugin", model.getBuild().getPlugins().get(1).getArtifactId());
112-
assertEquals("3.11.0", model.getBuild().getPlugins().get(1).getVersion());
114+
assertEquals(EXPECTED_JAVAC_PLUGIN_VERSION, model.getBuild().getPlugins().get(1).getVersion());
113115
assertEquals(0, model.getRepositories().size());
114116
}
115117

@@ -135,7 +137,7 @@ public void testPathParentSnapshot() throws IOException, XmlPullParserException
135137
assertEquals("nbm-maven-plugin", model.getBuild().getPlugins().get(0).getArtifactId());
136138
assertEquals(MavenNbModuleImpl.getLatestNbmPluginVersion(), model.getBuild().getPlugins().get(0).getVersion());
137139
assertEquals("maven-compiler-plugin", model.getBuild().getPlugins().get(1).getArtifactId());
138-
assertEquals("3.11.0", model.getBuild().getPlugins().get(1).getVersion());
140+
assertEquals(EXPECTED_JAVAC_PLUGIN_VERSION, model.getBuild().getPlugins().get(1).getVersion());
139141
assertEquals(1, model.getRepositories().size());
140142
}
141143

@@ -190,7 +192,7 @@ public void testPathParentJar() throws IOException, XmlPullParserException {
190192
assertEquals("nbm-maven-plugin", modeloutput.getBuild().getPlugins().get(0).getArtifactId());
191193
assertEquals(MavenNbModuleImpl.getLatestNbmPluginVersion(), modeloutput.getBuild().getPlugins().get(0).getVersion());
192194
assertEquals("maven-compiler-plugin", modeloutput.getBuild().getPlugins().get(1).getArtifactId());
193-
assertEquals("3.11.0", modeloutput.getBuild().getPlugins().get(1).getVersion());
195+
assertEquals(EXPECTED_JAVAC_PLUGIN_VERSION, modeloutput.getBuild().getPlugins().get(1).getVersion());
194196
assertEquals(0, model.getRepositories().size());
195197
}
196198

java/debugger.jpda.truffle/nbproject/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# under the License.
1717

1818
javac.compilerargs=-Xlint:unchecked
19-
javac.source=1.8
19+
javac.release=11
2020
javadoc.arch=${basedir}/arch.xml
2121
nbm.module.author=Martin Entlicher
2222
requires.nb.javac=true

java/debugger.jpda.truffle/src/org/netbeans/modules/debugger/jpda/truffle/RemoteServices.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,7 @@ private static ObjectReference getContextClassLoader(ThreadReference tawt, Virtu
180180

181181
private static int getTargetMajorVersion(VirtualMachine vm) throws InternalExceptionWrapper, VMDisconnectedExceptionWrapper {
182182
String version = VirtualMachineWrapper.version(vm);
183-
int dot = version.indexOf(".");
184-
if (dot < 0) {
185-
dot = version.length();
186-
}
187-
return Integer.parseInt(version.substring(0, dot));
183+
return Runtime.Version.parse(version).feature();
188184
}
189185

190186
public static ClassObjectReference uploadBasicClasses(JPDAThreadImpl t, String basicClassName) throws InvalidTypeException, ClassNotLoadedException, IncompatibleThreadStateException, InvocationException, IOException, PropertyVetoException, InternalExceptionWrapper, VMDisconnectedExceptionWrapper, ObjectCollectedExceptionWrapper, UnsupportedOperationExceptionWrapper, ClassNotPreparedExceptionWrapper {

java/debugger.jpda/src/org/netbeans/modules/debugger/jpda/models/VariableMirrorTranslator.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
import java.io.InvalidObjectException;
5050
import java.lang.reflect.Array;
5151
import java.lang.reflect.Constructor;
52-
import java.lang.reflect.InvocationTargetException;
52+
import java.lang.reflect.InaccessibleObjectException;
5353
import java.util.ArrayList;
5454
import java.util.Arrays;
5555
import java.util.Collections;
@@ -250,7 +250,12 @@ private static Object setFieldsValues(Object newInstance, Class clazz, Map<Field
250250
logger.log(Level.CONFIG, "No Such Field({0}) of class {1}", new Object[]{name, clazz});
251251
return null;
252252
}
253-
field.setAccessible(true);
253+
try {
254+
field.setAccessible(true);
255+
} catch(InaccessibleObjectException ex) {
256+
logger.log(Level.CONFIG, "InaccessibleObjectException({0}) of field {1}", new Object[]{ex.getLocalizedMessage(), field});
257+
return null;
258+
}
254259
Value v = fieldValues.get(f);
255260
try {
256261
if (v == null) {

java/java.editor/src/org/netbeans/modules/editor/java/JavaCompletionItem.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ public CharSequence getAssignToVarText() {
15221522
public String toString() {
15231523
return (typeName != null ? typeName + " " : "") + varName; //NOI18N
15241524
}
1525-
}
1525+
}
15261526

15271527
static class FieldItem extends WhiteListJavaCompletionItem<VariableElement> {
15281528

@@ -1545,6 +1545,7 @@ static class FieldItem extends WhiteListJavaCompletionItem<VariableElement> {
15451545
private String typeName;
15461546
private String leftText;
15471547
private String rightText;
1548+
private CharSequence sortText;
15481549
private boolean autoImportEnclosingType;
15491550
private CharSequence enclSortText;
15501551
private int castEndOffset;
@@ -1597,7 +1598,10 @@ public int getSortPriority() {
15971598

15981599
@Override
15991600
public CharSequence getSortText() {
1600-
return simpleName + "#" + enclSortText; //NOI18N
1601+
if (sortText == null) {
1602+
sortText = LazySortText.link(simpleName, enclSortText);
1603+
}
1604+
return sortText;
16011605
}
16021606

16031607
@Override
@@ -1827,7 +1831,7 @@ static class MethodItem extends WhiteListJavaCompletionItem<ExecutableElement> {
18271831
protected List<ParamDesc> params;
18281832
private String typeName;
18291833
private boolean addSemicolon;
1830-
private String sortText;
1834+
private CharSequence sortText;
18311835
private String leftText;
18321836
private String rightText;
18331837
private boolean autoImportEnclosingType;
@@ -1910,7 +1914,7 @@ public CharSequence getSortText() {
19101914
cnt++;
19111915
}
19121916
sortParams.append(')');
1913-
sortText = simpleName + "#" + enclSortText + "#" + ((cnt < 10 ? "0" : "") + cnt) + "#" + sortParams.toString(); //NOI18N
1917+
sortText = LazySortText.link(simpleName, enclSortText, ((cnt < 10 ? "0" : "") + cnt) + "#" + sortParams.toString()); //NOI18N
19141918
}
19151919
return sortText;
19161920
}

java/java.editor/src/org/netbeans/modules/editor/java/LazySortText.java

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,18 @@
2424
import org.netbeans.api.java.source.support.ReferencesCount;
2525

2626
/**
27+
* Characters are lazily computed in charAt(), avoid toString().
28+
*
29+
* Use link() to combine lazy sequences.
2730
*
2831
* @author Dusan Balek
2932
*/
30-
class LazySortText implements CharSequence {
33+
final class LazySortText implements CharSequence {
3134

32-
private String simpleName;
33-
private String enclName;
34-
private ElementHandle<TypeElement> handle;
35-
private ReferencesCount referencesCount;
35+
private final String simpleName;
36+
private final String enclName;
37+
private final ElementHandle<TypeElement> handle;
38+
private final ReferencesCount referencesCount;
3639
private String importanceLevel = null;
3740

3841
LazySortText(String simpleName, String enclName, ElementHandle<TypeElement> handle, ReferencesCount referencesCount) {
@@ -48,6 +51,7 @@ public int length() {
4851
}
4952

5053
@Override
54+
@SuppressWarnings("AssignmentToMethodParameter")
5155
public char charAt(int index) {
5256
if ((index < 0) || (index >= length())) {
5357
throw new StringIndexOutOfBoundsException(index);
@@ -74,10 +78,61 @@ public CharSequence subSequence(int start, int end) {
7478
throw new UnsupportedOperationException("Not supported yet."); //NOI18N
7579
}
7680

81+
@Override
82+
public String toString() {
83+
return new StringBuilder(this).toString();
84+
}
85+
7786
private String getImportanceLevel() {
7887
if (importanceLevel == null) {
7988
importanceLevel = String.format("%8d", Utilities.getImportanceLevel(referencesCount, handle)); //NOI18N
8089
}
8190
return importanceLevel;
8291
}
92+
93+
public static CharSequence link(CharSequence first, CharSequence second) {
94+
return new LinkedLazyCharSequence(first, second);
95+
}
96+
97+
public static CharSequence link(CharSequence first, CharSequence second, CharSequence third) {
98+
return new LinkedLazyCharSequence(first, new LinkedLazyCharSequence(second, third));
99+
}
100+
101+
private static final class LinkedLazyCharSequence implements CharSequence {
102+
103+
private final CharSequence first;
104+
private final CharSequence second;
105+
private final int length;
106+
107+
private LinkedLazyCharSequence(CharSequence first, CharSequence second) {
108+
this.first = first;
109+
this.second = second;
110+
this.length = first.length() + second.length() + 1;
111+
}
112+
113+
@Override
114+
@SuppressWarnings("AssignmentToMethodParameter")
115+
public char charAt(int index) {
116+
if (index < first.length()) {
117+
return first.charAt(index);
118+
}
119+
index -= first.length();
120+
if (index-- == 0) {
121+
return '#';
122+
}
123+
return second.charAt(index);
124+
}
125+
126+
@Override
127+
public int length() {
128+
return length;
129+
}
130+
131+
@Override
132+
public CharSequence subSequence(int start, int end) {
133+
throw new UnsupportedOperationException("Not supported yet."); //NOI18N
134+
}
135+
136+
}
137+
83138
}

java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ConstructorGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public List<CodeAction> getCodeActions(NbCodeLanguageClient client, ResultIterat
188188
data.put(OFFSET, startOffset);
189189
data.put(CONSTRUCTORS, constructors);
190190
data.put(FIELDS, fields);
191-
return Collections.singletonList(createCodeAction(client, Bundle.DN_GenerateConstructor(), isSource ? CODE_GENERATOR_KIND : CodeActionKind.QuickFix, null, "nbls.generate.code", GENERATE_CONSTRUCTOR, data));
191+
return Collections.singletonList(createCodeAction(client, Bundle.DN_GenerateConstructor(), isSource ? CODE_GENERATOR_KIND : CodeActionKind.QuickFix, null, "nbls.generate.code", Utils.encodeCommand(GENERATE_CONSTRUCTOR, client.getNbCodeCapabilities()), data));
192192
}
193193

194194
@Override

java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/DelegateMethodGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public List<CodeAction> getCodeActions(NbCodeLanguageClient client, ResultIterat
137137
data.put(OFFSET, offset);
138138
data.put(TYPE, typeItem);
139139
data.put(FIELDS, fields);
140-
return Collections.singletonList(createCodeAction(client, Bundle.DN_GenerateDelegateMethod(), CODE_GENERATOR_KIND, null, "nbls.generate.code", GENERATE_DELEGATE_METHOD, data));
140+
return Collections.singletonList(createCodeAction(client, Bundle.DN_GenerateDelegateMethod(), CODE_GENERATOR_KIND, null, "nbls.generate.code", Utils.encodeCommand(GENERATE_DELEGATE_METHOD, client.getNbCodeCapabilities()), data));
141141
}
142142

143143
@Override

0 commit comments

Comments
 (0)