Unverified Commit b8c421ef authored by Geertjan Wielenga's avatar Geertjan Wielenga Committed by GitHub
Browse files

Merge pull request #2908 from apache/delivery

Sync release124 with delivery branch
parents ed64962c a61bd21f
......@@ -47,6 +47,7 @@ import org.netbeans.modules.cpplite.editor.spi.CProjectConfigurationProvider;
import org.netbeans.modules.cpplite.editor.spi.CProjectConfigurationProvider.ProjectConfiguration;
import org.openide.filesystems.FileUtil;
import org.openide.modules.Places;
import org.openide.util.Pair;
/**
*
......@@ -66,7 +67,7 @@ public class LanguageServerImpl implements LanguageServerProvider {
private static final Logger LOG = Logger.getLogger(LanguageServerImpl.class.getName());
private static final Map<Project, LanguageServerDescription> prj2Server = new HashMap<>();
private static final Map<Project, Pair<Process, LanguageServerDescription>> prj2Server = new HashMap<>();
@Override
public LanguageServerDescription startServer(Lookup lookup) {
......@@ -88,7 +89,10 @@ public class LanguageServerImpl implements LanguageServerProvider {
String ccls = Utils.getCCLSPath();
String clangd = Utils.getCLANGDPath();
if (ccls != null || clangd != null) {
return prj2Server.computeIfAbsent(prj, (Project p) -> {
return prj2Server.compute(prj, (p, pair) -> {
if (pair != null && pair.first().isAlive()) {
return pair;
}
try {
List<String> command = new ArrayList<>();
......@@ -128,14 +132,14 @@ public class LanguageServerImpl implements LanguageServerProvider {
in = new CopyInput(in, System.err);
out = new CopyOutput(out, System.err);
}
return LanguageServerDescription.create(in, out, process);
return Pair.of(process, LanguageServerDescription.create(in, out, process));
}
return null;
} catch (IOException ex) {
LOG.log(Level.FINE, null, ex);
return null;
}
});
}).second();
}
return null;
}
......
......@@ -19,7 +19,6 @@
package org.netbeans.modules.tomcat5.deploy;
import com.sun.org.apache.xerces.internal.impl.dv.util.Base64;
import org.netbeans.modules.tomcat5.deploy.TomcatManager;
import java.net.HttpURLConnection;
import java.net.URL;
......@@ -48,6 +47,7 @@ import org.openide.util.RequestProcessor;
import org.openide.util.NbBundle;
import java.io.*;
import java.net.Proxy;
import java.util.Base64;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.modules.tomcat5.AuthorizationException;
......@@ -530,7 +530,7 @@ public class TomcatManagerImpl implements ProgressObject, Runnable {
// Set up an authorization header with our credentials
TomcatProperties tp = tm.getTomcatProperties();
String input = tp.getUsername () + ":" + tp.getPassword ();
String auth = new String(Base64.encode(input.getBytes()));
String auth = Base64.getEncoder().encodeToString(input.getBytes());
hconn.setRequestProperty("Authorization", // NOI18N
"Basic " + auth); // NOI18N
......
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="__NS_LOCATION__/jsf/facelets"
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="__NS_LOCATION__/jsf/facelets"
template="__TEMPLATE__">
__DEFINE_TAGS__
</ui:composition>
\ No newline at end of file
......@@ -83,6 +83,18 @@ is the proper place.
<!-- ACTUAL CHANGES BEGIN HERE: -->
<changes>
<change id="local-gradle-version-discovery">
<api name="general"/>
<summary>GradleDistributionManager can detect local Gradle Distributions</summary>
<version major="2" minor="10"/>
<date day="12" month="4" year="2021"/>
<author login="lkishalmi"/>
<compatibility semantic="compatible" addition="yes"/>
<description>
Added <code><a href="@TOP@/org/netbeans/modules/gradle/api/execute/GradleDistributionManager.html#availableLocalDistributions--">GradleDistributionManager.availableLocalDistributions()</a></code>
method to help detection the already available GradleDistribution-s installed in the system.
</description>
</change>
<change id="tooling-runJvmArgs">
<api name="general"/>
<summary>NetBeans Tooling plugin recognizes "runJvmArgs" property</summary>
......
......@@ -3,4 +3,4 @@ AutoUpdate-Show-In-Client: false
OpenIDE-Module: org.netbeans.modules.gradle/2
OpenIDE-Module-Layer: org/netbeans/modules/gradle/layer.xml
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/gradle/Bundle.properties
OpenIDE-Module-Specification-Version: 2.9
OpenIDE-Module-Specification-Version: 2.10
......@@ -29,8 +29,8 @@
<code-name-base>org.netbeans.modules.libs.gradle</code-name-base>
<compile-dependency/>
<run-dependency>
<release-version>6</release-version>
<specification-version>6.3</specification-version>
<release-version>7</release-version>
<specification-version>7.0</specification-version>
</run-dependency>
</dependency>
<dependency>
......
......@@ -258,8 +258,10 @@ class NbProjectInfoBuilder {
model.info["sourceset_${sourceSet.name}_classpath_annotation"] = storeSet(sourceSet.compileClasspath.files)
}
}
model.info["sourceset_${sourceSet.name}_configuration_compile"] = sourceSet.compileConfigurationName;
model.info["sourceset_${sourceSet.name}_configuration_runtime"] = sourceSet.runtimeConfigurationName;
beforeGradle('7.0') {
model.info["sourceset_${sourceSet.name}_configuration_compile"] = sourceSet.compileConfigurationName;
model.info["sourceset_${sourceSet.name}_configuration_runtime"] = sourceSet.runtimeConfigurationName;
}
}
} else {
model.info.sourcesets = Collections.emptySet();
......
......@@ -126,6 +126,8 @@ public class ActionProviderImpl implements ActionProvider {
}
// add a fixed 'prime build' action
actions.add(ActionProvider.COMMAND_PRIME);
actions.add(COMMAND_DL_SOURCES);
actions.add(COMMAND_DL_JAVADOC);
return actions.toArray(new String[actions.size()]);
}
......@@ -263,7 +265,13 @@ public class ActionProviderImpl implements ActionProvider {
return;
}
}
final String loadReason;
if (mapping.getDisplayName() != null && !mapping.getDisplayName().equals(mapping.getName())) {
loadReason = mapping.getDisplayName();
} else {
loadReason = null;
}
boolean reloadOnly = !showUI && (args.length == 0);
if (!reloadOnly) {
......@@ -293,7 +301,7 @@ public class ActionProviderImpl implements ActionProvider {
if (needReload && canReload) {
String[] reloadArgs = RunUtils.evaluateActionArgs(project, mapping.getName(), mapping.getReloadArgs(), ctx);
final ActionProgress g = ActionProgress.start(context);
RequestProcessor.Task reloadTask = prj.reloadProject(true, maxQualily, reloadArgs);
RequestProcessor.Task reloadTask = prj.reloadProject(loadReason, true, maxQualily, reloadArgs);
reloadTask.addTaskListener((t) -> {
g.finished(true);
});
......
......@@ -26,6 +26,5 @@ import org.netbeans.modules.gradle.api.NbGradleProject;
*/
public interface GradleProjectLoader {
GradleProject loadProject(NbGradleProject.Quality aim, boolean ignoreCache, boolean interactive, String... args);
GradleProject loadProject(NbGradleProject.Quality aim, String descriptionOpt, boolean ignoreCache, boolean interactive, String... args);
}
......@@ -251,18 +251,22 @@ public final class NbGradleProjectImpl implements Project {
}
private GradleProject loadProject() {
return loadProject(false, aimedQuality);
return loadProject(null, false, aimedQuality);
}
private GradleProject loadProject(boolean ignoreCache, Quality aim, String... args) {
private GradleProject loadProject(String desc, boolean ignoreCache, Quality aim, String... args) {
GradleProjectLoader loader = getLookup().lookup(GradleProjectLoader.class);
GradleProject prj = loader != null ? loader.loadProject(aim, ignoreCache, false, args) : null;
GradleProject prj = loader != null ? loader.loadProject(aim, desc, ignoreCache, false, args) : null;
return prj;
}
RequestProcessor.Task reloadProject(final boolean ignoreCache, final Quality aim, final String... args) {
return reloadProject(null, ignoreCache, aim, args);
}
RequestProcessor.Task reloadProject(String desc, final boolean ignoreCache, final Quality aim, final String... args) {
return RELOAD_RP.post(() -> {
project = loadProject(ignoreCache, aim, args);
project = loadProject(desc, ignoreCache, aim, args);
ACCESSOR.doFireReload(watcher);
});
}
......@@ -310,6 +314,10 @@ public final class NbGradleProjectImpl implements Project {
*
* @return future that produces the result.
*/
@NbBundle.Messages({
"# {0} - project name",
"ACT_PrimingProject=Preparing project {0}"
})
CompletableFuture<GradleProject> primeProject() {
CompletableFuture<GradleProject> ret;
synchronized (this) {
......@@ -328,7 +336,7 @@ public final class NbGradleProjectImpl implements Project {
// Build project, so trust the project.
ProjectTrust.getDefault().trustProject(this, true);
GradleProjectLoader loader = getLookup().lookup(GradleProjectLoader.class);
GradleProject gradleProject = loader.loadProject(FULL_ONLINE, true, true);
GradleProject gradleProject = loader.loadProject(FULL_ONLINE, Bundle.ACT_PrimingProject(project.getBaseProject().getName()), true, true);
LOG.log(Level.FINER, "Priming finished, reloading {0}: {1}", project);
fireProjectReload(false);
ret.complete(gradleProject);
......
......@@ -35,6 +35,7 @@ import org.openide.util.NbBundle;
import org.netbeans.modules.gradle.api.GradleProjects;
import static org.netbeans.modules.gradle.Bundle.*;
import org.netbeans.modules.gradle.api.GradleBaseProject;
import static org.netbeans.modules.gradle.api.NbGradleProject.Quality.FULL_ONLINE;
/**
......@@ -65,6 +66,9 @@ public class ReloadAction extends AbstractAction implements ContextAwareAction
}
}
@NbBundle.Messages({
"ACT_ReloadingProject=Reloading"
})
@Override public void actionPerformed(ActionEvent event) {
Set<Project> reload = new LinkedHashSet<>();
for (NbGradleProjectImpl prj : context.lookupAll(NbGradleProjectImpl.class)) {
......@@ -78,7 +82,8 @@ public class ReloadAction extends AbstractAction implements ContextAwareAction
// A bit low level calls, just to allow UI interaction to
// Trust the project.
GradleProjectLoader loader = impl.getLookup().lookup(GradleProjectLoader.class);
impl.project = loader.loadProject(FULL_ONLINE, true, true);
GradleBaseProject gbp = GradleBaseProject.get(project);
impl.project = loader.loadProject(FULL_ONLINE, ACT_ReloadingProject(), true, true);
NbGradleProjectImpl.ACCESSOR.doFireReload(NbGradleProject.get(impl));
});
}
......
......@@ -37,18 +37,18 @@
<args>clean</args>
<reload rule="NEVER"/>
</action>
<action name="download.javadoc">
<action displayName="Download Javadoc" name="download.javadoc">
<!--
We do not really execute any tasks here, rather just reload the project
allowing it to go online and fetch some dependencies. So in this case
the action is forcing a project reload with some argiments.
the action is forcing a project reload with some arguments.
-->
<reload rule="ALWAYS_ONLINE">
<args>-PdownloadJavadoc=${requestedComponent}</args>
</reload>
</action>
<action name="download.sources">
<action displayName="Download sources" name="download.sources">
<reload rule="ALWAYS_ONLINE">
<args>-PdownloadSources=${requestedComponent}</args>
</reload>
......
......@@ -51,6 +51,17 @@ public final class GradleProjects {
GradleModuleFileCache21.CachedArtifactVersion.Entry sources = av != null ? av.getSources() : null;
return sources != null ? sources.getPath().toFile() : GradleArtifactStore.getDefault().getSources(binary);
}
public static boolean isGradleCacheArtifact(File toCheck) {
try {
GradleModuleFileCache21 cache = GradleModuleFileCache21.getGradleFileCache();
GradleModuleFileCache21.CachedArtifactVersion av = cache.resolveCachedArtifactVersion(toCheck.toPath());
return av != null;
} catch (IllegalArgumentException ex) {
// expected: not an artifact
return false;
}
}
/**
* Get the JavaDoc artifact for the given binary if available.
......
......@@ -31,8 +31,15 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileVisitOption;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
......@@ -76,7 +83,7 @@ public final class GradleDistributionManager {
private static final RequestProcessor RP = new RequestProcessor("Gradle Installer", 1); //NOI18N
private static final String DOWNLOAD_URI = "https://services.gradle.org/distributions/gradle-%s-%s.zip"; //NOI18N
private static final Pattern DIST_VERSION_PATTERN = Pattern.compile(".*gradle-(\\d+\\.\\d+.*)-(bin|all)\\.zip"); //NOI18N
private static final Pattern DIST_VERSION_PATTERN = Pattern.compile(".*(gradle-(\\d+\\.\\d+.*))-(bin|all)\\.zip"); //NOI18N
private static final Set<String> VERSION_BLACKLIST = new HashSet<>(Arrays.asList("2.3", "2.13")); //NOI18N
private static final Map<File, GradleDistributionManager> CACHE = new WeakHashMap<>();
private static final GradleVersion MINIMUM_SUPPORTED_VERSION = GradleVersion.version("2.0"); //NOI18N
......@@ -88,6 +95,7 @@ public final class GradleDistributionManager {
GradleVersion.version("6.0"), // JDK-13
GradleVersion.version("6.3"), // JDK-14
GradleVersion.version("6.7"), // JDK-15
GradleVersion.version("7.0"), // JDK-16
};
private static final int JAVA_VERSION;
......@@ -206,7 +214,7 @@ public final class GradleDistributionManager {
URI uri = getWrapperDistributionURI(gradleProjectRoot);
Matcher m = DIST_VERSION_PATTERN.matcher(uri.getPath());
if (m.matches()) {
String version = m.group(1);
String version = m.group(2);
return new GradleDistribution(distributionBaseDir(uri, version), uri, version);
} else {
throw new URISyntaxException(uri.getPath(), "Cannot get the Gradle distribution version from the URI"); //NOI18N
......@@ -308,6 +316,46 @@ public final class GradleDistributionManager {
return ret;
}
/**
* Lists all the {@link GradleDistribution}s available on the Gradle Home
* of this distribution manager. It looks for the <code>$GRADLE_HOME/wrapper/dists</code>
* directory for already downloaded distributions.
* @return the list of available Gradle distributions from the Gradle Home.
* @since 2.10
*/
public List<GradleDistribution> availableLocalDistributions() {
List<GradleDistribution> ret = new ArrayList<>();
Path dists = gradleUserHome.toPath().resolve("wrapper").resolve("dists"); //NOI18N
if (Files.isDirectory(dists)) {
try {
Files.walkFileTree(dists, EnumSet.noneOf(FileVisitOption.class), 2, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path f, BasicFileAttributes attrs) throws IOException {
String fname = f.getFileName().toString();
Matcher m = DIST_VERSION_PATTERN.matcher(fname);
if (m.matches()) {
Path dist = f.resolveSibling(m.group(1));
if (Files.isDirectory(dist)) {
try {
GradleDistribution d = distributionFromDir(dist.toFile());
if (GradleVersion.version(d.getVersion()).compareTo(MINIMUM_SUPPORTED_VERSION) >= 0) {
ret.add(d);
}
} catch (IOException ex) {
// This might be a broken distribution
}
}
}
return FileVisitResult.CONTINUE;
}
});
} catch (IOException ex) {
//Do nothing if we fail to scan the files
}
}
return ret;
}
File distributionBaseDir(URI downloadLocation, String version) {
WrapperConfiguration conf = new WrapperConfiguration();
conf.setDistribution(downloadLocation);
......
......@@ -67,12 +67,14 @@ public abstract class AbstractProjectLoader {
final GradleProject previous;
final NbGradleProject.Quality aim;
final GradleCommandLine cmd;
final String description;
public ReloadContext(NbGradleProjectImpl project, NbGradleProject.Quality aim, GradleCommandLine cmd) {
public ReloadContext(NbGradleProjectImpl project, NbGradleProject.Quality aim, GradleCommandLine cmd, String description) {
this.project = project;
this.previous = project.isGradleProjectLoaded() ? project.getGradleProject() : FallbackProjectLoader.createFallbackProject(project.getGradleFiles());
this.aim = aim;
this.cmd = cmd;
this.description = description;
}
public GradleProject getPrevious() {
......
......@@ -37,6 +37,7 @@ import org.netbeans.modules.gradle.options.GradleExperimentalSettings;
public class GradleProjectLoaderImpl implements GradleProjectLoader {
final Project project;
private String actionDescription;
private static final Logger LOGGER = Logger.getLogger(GradleProjectLoaderImpl.class.getName());
public GradleProjectLoaderImpl(Project project) {
......@@ -44,10 +45,10 @@ public class GradleProjectLoaderImpl implements GradleProjectLoader {
}
@Override
public GradleProject loadProject(NbGradleProject.Quality aim, boolean ignoreCache, boolean interactive, String... args) {
public GradleProject loadProject(NbGradleProject.Quality aim, String descriptionOpt, boolean ignoreCache, boolean interactive, String... args) {
LOGGER.info("Load aiming " +aim + " for "+ project);
GradleCommandLine cmd = new GradleCommandLine(args);
AbstractProjectLoader.ReloadContext ctx = new AbstractProjectLoader.ReloadContext((NbGradleProjectImpl) project, aim, cmd);
AbstractProjectLoader.ReloadContext ctx = new AbstractProjectLoader.ReloadContext((NbGradleProjectImpl) project, aim, cmd, descriptionOpt);
List<AbstractProjectLoader> loaders = new LinkedList<>();
if (!ignoreCache) loaders.add(new DiskCacheProjectLoader(ctx));
......
......@@ -267,12 +267,21 @@ public class LegacyProjectLoader extends AbstractProjectLoader {
@NbBundle.Messages({
"# {0} - The project name",
"LBL_Loading=Loading {0}"
"LBL_Loading=Loading {0}",
"# {0} (re)load reason",
"# {1} project name",
"FMT_ProjectLoadReason={0} ({1})"
})
@Override
public GradleProject call() throws Exception {
tokenSource = GradleConnector.newCancellationTokenSource();
final ProgressHandle handle = ProgressHandle.createHandle(Bundle.LBL_Loading(ctx.previous.getBaseProject().getName()), this);
String msg;
if (ctx.description != null) {
msg = Bundle.FMT_ProjectLoadReason(ctx.description, ctx.previous.getBaseProject().getName());
} else {
msg = Bundle.LBL_Loading(ctx.previous.getBaseProject().getName());
}
final ProgressHandle handle = ProgressHandle.createHandle(msg, this);
ProgressListener pl = (ProgressEvent pe) -> {
handle.progress(pe.getDescription());
};
......
......@@ -28,6 +28,7 @@ import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutionException;
import javax.swing.ButtonModel;
......@@ -44,7 +45,6 @@ import org.netbeans.modules.gradle.api.execute.GradleDistributionManager;
import org.netbeans.modules.gradle.api.execute.GradleDistributionManager.GradleDistribution;
import org.openide.LifecycleManager;
import org.openide.awt.NotificationDisplayer;
import org.openide.util.Exceptions;
import org.openide.util.ImageUtilities;
import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages;
......@@ -744,19 +744,24 @@ public class SettingsPanel extends javax.swing.JPanel {
@Override
protected List<GradleDistribution> doInBackground() throws Exception {
return gdm.availableDistributions(true);
try {
return gdm.availableDistributions(true);
} catch (IOException ex) {
return gdm.availableLocalDistributions();
}
}
@Override
protected void done() {
GradleDistribution[] items = new GradleDistribution[0];
try {
GradleDistribution[] items = get().toArray(new GradleDistribution[0]);
ComboBoxModel<GradleDistribution> model = new DefaultComboBoxModel<>(items);
cbGradleVersion.setModel(model);
model.setSelectedItem(gdm.distributionFromVersion(settings.getGradleVersion()));
items = get().toArray(new GradleDistribution[0]);
} catch (InterruptedException | ExecutionException ex) {
Exceptions.printStackTrace(ex);
// Something happened, let's have the combo list box empty;
}
ComboBoxModel<GradleDistribution> model = new DefaultComboBoxModel<>(items);
cbGradleVersion.setModel(model);
model.setSelectedItem(gdm.distributionFromVersion(settings.getGradleVersion()));
}
}.execute();
......@@ -775,7 +780,10 @@ public class SettingsPanel extends javax.swing.JPanel {
} else {
settings.setGradleUserHome(new File(tfGradleUserHome.getText()));
}
settings.setGradleVersion(((GradleDistribution) cbGradleVersion.getSelectedItem()).getVersion());
GradleDistribution distVersion = (GradleDistribution) cbGradleVersion.getSelectedItem();
if (distVersion != null) {
settings.setGradleVersion(distVersion.getVersion());
}
settings.setDistributionHome(tfUseCustomGradle.getText());
settings.setWrapperPreferred(cbPreferWrapper.isSelected());
boolean useCustomGradle = bgUsedDistribution.getSelection() == rbUseCustomGradle.getModel();
......@@ -896,10 +904,6 @@ public class SettingsPanel extends javax.swing.JPanel {
}
private static String getRawGradleUserHome() {
return GradleSettings.getDefault().getPreferences().get(GradleSettings.PROP_GRADLE_USER_HOME, null);
}
private static String getDefaultGradleUserHome() {
String dir = System.getenv("GRADLE_USER_HOME"); //NOI18N
return dir != null ? dir : new File(System.getProperty("user.home"), ".gradle").getAbsolutePath(); //NOI18N
......
......@@ -265,7 +265,7 @@ public final class TemplateOperation implements Runnable {
//Just load the project into the cache.
GradleProjectLoader loader = nbProject.getLookup().lookup(GradleProjectLoader.class);
if (loader != null) {
loader.loadProject(Quality.FULL_ONLINE, true, false);
loader.loadProject(Quality.FULL_ONLINE, null, true, false);
}
}
return Collections.singleton(projectDir);
......
......@@ -85,7 +85,7 @@ public class AbstractGradleProjectTestCase extends NbTestCase {
// A bit low level calls, just to allow UI interaction to
// Trust the project.
GradleProjectLoader loader = impl.getLookup().lookup(GradleProjectLoader.class);
impl.project = loader.loadProject(FULL_ONLINE, true, true);
impl.project = loader.loadProject(FULL_ONLINE, null, true, true);
NbGradleProjectImpl.ACCESSOR.doFireReload(NbGradleProject.get(impl));
}).get();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment