Skip to content

Commit

Permalink
Merge pull request #6607 from apache/delivery
Browse files Browse the repository at this point in the history
Sync delivery to release200 for 20-rc2
  • Loading branch information
neilcsmith-net authored Oct 25, 2023
2 parents f999eff + 5ec2467 commit d30b8ef
Show file tree
Hide file tree
Showing 101 changed files with 2,523 additions and 626 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ jobs:
timeout-minutes: 60
strategy:
matrix:
java: [ '11' ]
java: [ '11', '17' ]
steps:

- name: Set up JDK ${{ matrix.java }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
import org.gradle.api.Task;
import org.gradle.api.tasks.JavaExec;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.process.CommandLineArgumentProvider;
import org.gradle.tooling.BuildException;
import org.gradle.util.GradleVersion;
/**
*
Expand All @@ -47,6 +47,8 @@ class NetBeansRunSinglePlugin implements Plugin<Project> {
private static final String RUN_SINGLE_JVM_ARGS = "runJvmArgs";
private static final String RUN_SINGLE_CWD = "runWorkingDir";

private static final String DEPRECATE_RUN_SINGLE =
"runSingle task is deprecated. Inspect your configuration and use just 'run' task instead of 'runSingle'";
@Override
public void apply(Project project) {
project.afterEvaluate(p -> {
Expand All @@ -55,61 +57,58 @@ public void apply(Project project) {
&& project.hasProperty(RUN_SINGLE_MAIN)) {
Set<Task> runTasks = p.getTasksByName("run", false);
Task r = runTasks.isEmpty() ? null : runTasks.iterator().next();
String mainClass = project.property(RUN_SINGLE_MAIN).toString();
p.getTasks().withType(JavaExec.class).configureEach(je -> {
if (GRADLE_VERSION.compareTo(GradleVersion.version("6.4")) < 0) {
// Using setMain to keep the backward compatibility before Gradle 6.4
je.setMain(mainClass);
} else {
je.getMainClass().set(mainClass);
}
if (project.hasProperty(RUN_SINGLE_ARGS)) {
je.setArgs(asList(project.property(RUN_SINGLE_ARGS).toString().split(" ")));
}
if (p.hasProperty(RUN_SINGLE_JVM_ARGS)) {
// Property jvmArgumentProviders should not be implemented as a lambda to allow execution optimizations.
// See https://docs.gradle.org/current/userguide/validation_problems.html#implementation_unknown
je.getJvmArgumentProviders().add(new CommandLineArgumentProvider() {
// Do not convert to lambda.
@Override
public Iterable<String> asArguments() {
return asList(p.property(RUN_SINGLE_JVM_ARGS).toString().split(" "));
}
});
}
try {
je.setStandardInput(System.in);
} catch (RuntimeException ex) {
if(LOG.isEnabled(LogLevel.DEBUG)) {
LOG.debug("Failed to set STDIN for Plugin: " + je.toString(), ex);
} else {
LOG.info("Failed to set STDIN for Plugin: " + je.toString());
}
}
if (project.hasProperty(RUN_SINGLE_CWD)) {
je.setWorkingDir(project.property(RUN_SINGLE_CWD).toString());
}
});
p.getTasks().withType(JavaExec.class).configureEach(je -> configureJavaExec(project, je));
addTask(project, r);
}
});
}

public static class JE extends JavaExec {
@Override
public void exec() {
private void configureJavaExec(Project project, JavaExec je) {
String mainClass = project.property(RUN_SINGLE_MAIN).toString();
if (GRADLE_VERSION.compareTo(GradleVersion.version("6.4")) < 0) {
// Using setMain to keep the backward compatibility before Gradle 6.4
je.setMain(mainClass);
} else {
je.getMainClass().set(mainClass);
}
}

private void addTask(Project project, Task runTask) {
project.getTasks().register(RUN_SINGLE_TASK, JE.class, (je) -> {
if (runTask == null) {
throw new BuildException("Could not find \"run\" task to execute. Please upgrade your configuration to use standard run-style tasks instead of deprecated runSingle", null);
if (project.hasProperty(RUN_SINGLE_ARGS)) {
je.setArgs(asList(project.property(RUN_SINGLE_ARGS).toString().split(" ")));
}
if (project.hasProperty(RUN_SINGLE_JVM_ARGS)) {
// Property jvmArgumentProviders should not be implemented as a lambda to allow execution optimizations.
// See https://docs.gradle.org/current/userguide/validation_problems.html#implementation_unknown
je.getJvmArgumentProviders().add(new CommandLineArgumentProvider() {
// Do not convert to lambda.
@Override
public Iterable<String> asArguments() {
return asList(project.property(RUN_SINGLE_JVM_ARGS).toString().split(" "));
}
});
}
try {
je.setStandardInput(System.in);
} catch (RuntimeException ex) {
if(LOG.isEnabled(LogLevel.DEBUG)) {
LOG.debug("Failed to set STDIN for Plugin: " + je.toString(), ex);
} else {
LOG.warn("runSingle task is deprecated. Inspect your configuration and use just 'run' task instead of 'runSingle'");
je.finalizedBy(runTask);
LOG.info("Failed to set STDIN for Plugin: " + je.toString());
}
});
}
if (project.hasProperty(RUN_SINGLE_CWD)) {
je.setWorkingDir(project.property(RUN_SINGLE_CWD).toString());
}
}

private void addTask(Project project, Task runTask) {
TaskProvider<? extends DefaultTask> runSingle = runTask == null
? project.getTasks().register(RUN_SINGLE_TASK, JavaExec.class, (je) -> {
SourceSetContainer sourceSets = project.getExtensions().findByType(SourceSetContainer.class);
je.setClasspath(sourceSets.findByName("main").getRuntimeClasspath());
configureJavaExec(project, je);
})
: project.getTasks().register(RUN_SINGLE_TASK, DefaultTask.class, (task) -> task.finalizedBy(runTask));

runSingle.configure((task) -> task.doFirst((action) -> project.getLogger().warn(DEPRECATE_RUN_SINGLE)));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.modules.gradle;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.logging.Logger;
import org.gradle.tooling.GradleConnector;
import org.netbeans.api.project.Project;
import org.openide.modules.OnStop;

/**
*
* @author lkishalmi
*/
public final class GradleConnectorManager {

private final Map<Project, GradleConnector> projectConnector = new WeakHashMap<>();
private final List<GradleConnector> connectors = new ArrayList<>();

private static final GradleConnectorManager INSTANCE = new GradleConnectorManager();
private static final Logger LOG = Logger.getLogger(GradleConnectorManager.class.getName());

private GradleConnectorManager() {}

public static GradleConnectorManager getDefault() {
return INSTANCE;
}

public GradleConnector getConnector(Project prj) {
synchronized (connectors) {
GradleConnector ret = projectConnector.computeIfAbsent(prj, p -> {
GradleConnector conn = GradleConnector.newConnector();
connectors.add(conn);
return conn;
});
return ret;
}
}


public void disconnectAll() {
LOG.info("Disconnecting from Gradle Daemons."); //NOI18N
synchronized (connectors) {
projectConnector.clear();

connectors.forEach(GradleConnector::disconnect);
connectors.clear();
}
LOG.info("Disconnecting from Gradle Daemons. Done."); //NOI18N
}

@OnStop
public static class DisconnectGradle implements Runnable {

@Override
public void run() {
GradleConnectorManager.getDefault().disconnectAll();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import org.gradle.tooling.ResultHandler;
import org.gradle.tooling.TestLauncher;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.api.project.ProjectUtils;
import org.netbeans.modules.gradle.api.NbGradleProject;
import org.netbeans.modules.gradle.api.execute.GradleDistributionManager;
import org.netbeans.modules.gradle.api.execute.GradleDistributionManager.GradleDistribution;
Expand Down Expand Up @@ -151,8 +153,8 @@ private <T extends ConfigurableLauncher<?>> T setJavaHome(T launcher) {
return launcher;
}

private static ProjectConnection createConnection(GradleDistribution dist, File projectDir) {
GradleConnector gconn = GradleConnector.newConnector();
private ProjectConnection createConnection(GradleDistribution dist, File projectDir) {
GradleConnector gconn = GradleConnectorManager.getDefault().getConnector(project);
gconn = gconn.useGradleUserHomeDir(dist.getGradleUserHome());
if (dist.isAvailable()) {
gconn = gconn.useInstallation(dist.getDistributionDir());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public class GradleDistributionProviderImpl implements GradleDistributionProvide
final NbGradleProjectImpl project;
private GradleDistribution dist;
private final PropertyChangeListener pcl;
private URI distributionURI;

public GradleDistributionProviderImpl(Project project) {
this.project = (NbGradleProjectImpl) project;
Expand All @@ -83,8 +82,7 @@ public GradleDistributionProviderImpl(Project project) {
URI uri = (URI) evt.getNewValue();
if ((uri != null) && (uri.getPath() != null) && uri.getPath().endsWith(GradleFiles.WRAPPER_PROPERTIES)) {
URI newDistURI = getWrapperDistributionURI();
if (GradleSettings.getDefault().isWrapperPreferred() && (distributionURI != null) && !Objects.equal(distributionURI, newDistURI)) {
distributionURI = newDistURI;
if (GradleSettings.getDefault().isWrapperPreferred() && (dist != null) && !Objects.equal(dist.getDistributionURI(), newDistURI)) {
distributionChanged();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.netbeans.modules.gradle.loaders;

import org.netbeans.modules.gradle.api.NbGradleProject;
import org.netbeans.modules.gradle.api.execute.GradleCommandLine;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -31,12 +30,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.gradle.tooling.BuildAction;
import org.gradle.tooling.BuildActionExecuter;
import org.gradle.tooling.BuildController;
import org.gradle.tooling.GradleConnectionException;
import org.gradle.tooling.GradleConnector;
import org.gradle.tooling.ProjectConnection;
import org.openide.modules.InstalledFileLocator;
import org.openide.modules.Places;
import org.openide.util.RequestProcessor;
Expand All @@ -55,11 +48,6 @@ public final class GradleDaemon {
private static final String PROP_TOOLING_JAR = "NETBEANS_TOOLING_JAR";
private static final String TOOLING_JAR = InstalledFileLocator.getDefault().locate(TOOLING_JAR_NAME, NbGradleProject.CODENAME_BASE, false).getAbsolutePath().replace("\\", "\\\\");

private static final String DAEMON_LOADED = "Daemon Loaded."; //NOI18N
private static final String LOADER_PROJECT_NAME = "modules/gradle/daemon-loader"; //NOI18N
private static final File LOADER_PROJECT_DIR = InstalledFileLocator.getDefault().locate(LOADER_PROJECT_NAME, NbGradleProject.CODENAME_BASE, false);
private static final DummyBuildAction DUMMY_ACTION = new DummyBuildAction();

private static final Logger LOG = Logger.getLogger(GradleDaemon.class.getName());

private GradleDaemon() {}
Expand All @@ -82,32 +70,4 @@ public static String initScript() {
}
return initScript.getAbsolutePath();
}

private static void doLoadDaemon() {
GradleConnector gconn = GradleConnector.newConnector();
ProjectConnection pconn = gconn.forProjectDirectory(LOADER_PROJECT_DIR).connect();
BuildActionExecuter<String> action = pconn.action(DUMMY_ACTION);
GradleCommandLine cmd = new GradleCommandLine();
cmd.setFlag(GradleCommandLine.Flag.OFFLINE, true);
cmd.addParameter(GradleCommandLine.Parameter.INIT_SCRIPT, initScript());
cmd.configure(action);
try {
action.run();
} catch (GradleConnectionException | IllegalStateException ex) {
// Well for some reason we were not able to load Gradle.
// Ignoring that for now
} finally {
pconn.close();
}
}

private static class DummyBuildAction implements BuildAction<String> {

@Override
public String execute(BuildController bc) {
return DAEMON_LOADED;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ public Set<FileObject> execute() {
// Well for some reason we were not able to load Gradle.
// Ignoring that for now
}
gconn.disconnect();
return Collections.singleton(FileUtil.toFileObject(target));
}
}
Expand Down Expand Up @@ -492,6 +493,7 @@ public Set<FileObject> execute() {
// Well for some reason we were not able to load Gradle.
// Ignoring that for now
}
gconn.disconnect();
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ private Project makeProjectWithWrapper(String subdir, String gradleVersion) thro
OpenProjects.getDefault().openProjects().get();

NbGradleProject.get(p).toQuality("Load data", NbGradleProject.Quality.FULL, false).toCompletableFuture().get();
gconn.disconnect();
return p;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ private void markBranchFlags (Map<String, GitBranch> allBranches, RevWalk walk,
}
} else {
usedFlags.add(flagId);
if (i < 25) {
i = i + 1;
if (i <= 23) { // leave one spare flag for the run method, see RevWalk.newFlag()
i++;
RevFlag flag = walk.newFlag(flagId);
List<GitBranch> branches = new ArrayList<>(allBranches.size());
branches.add(e.getValue());
Expand Down Expand Up @@ -253,7 +253,7 @@ protected String getCommandDescription () {
}

public GitRevisionInfo[] getRevisions () {
return revisions.toArray(new GitRevisionInfo[revisions.size()]);
return revisions.toArray(new GitRevisionInfo[0]);
}

private void addRevision (GitRevisionInfo info) {
Expand Down
Loading

0 comments on commit d30b8ef

Please sign in to comment.