Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions extide/gradle/nbproject/project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
<code-name-base>org.netbeans.modules.libs.gradle</code-name-base>
<compile-dependency/>
<run-dependency>
<release-version>8</release-version>
<specification-version>8.7</specification-version>
<release-version>9</release-version>
<specification-version>9.3</specification-version>
</run-dependency>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ public String toString() {
return "GradleProject{" + "quality=" + quality + ", baseProject=" + baseProject + '}';
}

public boolean betterThan(GradleProject prj) {
return prj == null
|| quality.betterThan(prj.quality)
|| ((quality == prj.quality) && getProblems().size() > prj.getProblems().size());

}
/**
*
* @since 2.23
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Supplier;
import java.util.logging.Level;
import org.netbeans.api.project.Project;
import org.netbeans.spi.project.ProjectState;
Expand Down Expand Up @@ -217,10 +218,7 @@ public void fireProjectReload(boolean wait) {
void attachAllUpdater() {
synchronized (this) {
if (openedProjectUpdater == null) {
openedProjectUpdater = new Updater((new FileProvider() {

@Override
public Set<File> getFiles() {
openedProjectUpdater = new Updater(() -> {
GradleFiles gf = getGradleFiles();
Set<File> ret = new LinkedHashSet<>();
for (GradleFiles.Kind kind : GradleFiles.Kind.PROJECT_FILES) {
Expand All @@ -230,8 +228,7 @@ public Set<File> getFiles() {
}
}
return ret;
}
}));
});
}
}

Expand Down Expand Up @@ -308,33 +305,6 @@ public GradleProject projectWithQuality(String desc, Quality aim, boolean intera
}
}

/**
* Obtains a project attempting at least the defined quality, without setting
* that quality level for subsequent loads. Note that the returned project's quality
* must be checked. If the currently loaded project declares the desired quality,
* no load is performed.
* <p>
* This method should be used in preference to {@link #loadProject()} or {@link #loadOWnProject},
* unless it's desired to force refresh the project contents to the current disk state.
* <div class="nonnormative">
* Implementation note: project reload events are dispatched <b>synchronously</b>
* in the calling thread.
* </div>
* @param desc optional description for the loading process, can be {@code null}.
* @param aim aimed quality
* @param interactive true, if user messages/confirmations can be displayed
* @param force to force load even though the quality does not change.
* @return project instance
*/
@Deprecated
public CompletableFuture<GradleProject> projectWithQualityTask(String desc, Quality aim, boolean interactive, boolean force) {
return projectWithQualityTask(NbGradleProject.loadOptions(aim).
setDescription(desc).
setInteractive(interactive).
setForce(force)
);
}

/**
* Obtains a project attempting at least the defined quality, without setting
* that quality level for subsequent loads. Note that the returned project's quality
Expand Down Expand Up @@ -556,18 +526,8 @@ CompletableFuture<GradleProject> loadOwnProject0(LoadOptions options, boolean sy
loadedProjectSerial = s;
this.attemptedQuality = options.getAim();

boolean replace = project == null || options.isForce();
if (project != null) {
if (prj.getQuality().betterThan(project.getQuality())) {
replace = true;
} else if (
project.getQuality().equals(prj.getQuality()) &&
!project.getProblems().equals(prj.getProblems()) &&
!prj.getProblems().isEmpty()) {
// exception: if the new project is the same quality fallback, but contains (different) problem info, use it
replace = true;
}
}
boolean replace = prj.betterThan(project) || options.isForce();

if (!replace) {
// avoid replacing a project when nothing has changed.
LOG.log(Level.FINER, "Current project {1} sufficient for attempted quality {0}", new Object[] { this.project, options.getAim() });
Expand Down Expand Up @@ -613,8 +573,6 @@ private CompletableFuture<GradleProject> callAccessorReload(LoadingCF f, GradleP
f.ownThreadCompletion.remove();
f.complete(prj);
}
} catch (ThreadDeath t) {
throw t;
} catch (RuntimeException | Error ex) {
f.completeExceptionally(ex);
throw ex;
Expand Down Expand Up @@ -645,8 +603,8 @@ public int hashCode() {

@Override
public boolean equals(Object obj) {
if (obj instanceof Project) {
NbGradleProjectImpl impl = ((Project) obj).getLookup().lookup(NbGradleProjectImpl.class);
if (obj instanceof Project prj) {
NbGradleProjectImpl impl = prj.getLookup().lookup(NbGradleProjectImpl.class);
if (impl != null) {
return getGradleFiles().equals(impl.getGradleFiles());
}
Expand Down Expand Up @@ -725,9 +683,6 @@ CompletableFuture<GradleProject> primeProject() {
} catch (Throwable t) {
LOG.log(Level.FINER, t, () -> String.format("Priming errored for %s", project));
ret.completeExceptionally(t);
if (t instanceof ThreadDeath) {
throw t;
}
}
});
return ret;
Expand All @@ -753,20 +708,21 @@ private class ProjectOpenedHookImpl extends ProjectOpenedHook {

@Override
protected void projectOpened() {
Runnable open = () -> {
setAimedQuality(FULL);
attachAllUpdater();
if (ProjectProblems.isBroken(NbGradleProjectImpl.this)) {
ProjectProblems.showAlert(NbGradleProjectImpl.this);
}
};
if (GradleExperimentalSettings.getDefault().isOpenLazy()) {
RELOAD_RP.post(open, 100);
RELOAD_RP.post(this::open, 100);
} else {
open.run();
open();
}
}

private void open() {
setAimedQuality(FULL);
attachAllUpdater();
if (ProjectProblems.isBroken(NbGradleProjectImpl.this)) {
ProjectProblems.showAlert(NbGradleProjectImpl.this);
}
}

@Override
protected void projectClosed() {
setAimedQuality(Quality.FALLBACK);
Expand All @@ -777,11 +733,6 @@ protected void projectClosed() {
}
}

interface FileProvider {

Set<File> getFiles();
}

private class CacheDirProvider implements CacheDirectoryProvider {

@Override
Expand Down Expand Up @@ -902,11 +853,11 @@ public void propertyChange(PropertyChangeEvent evt) {

private class Updater implements FileChangeListener {

final FileProvider fileProvider;
final Supplier<Set<File>> fileProvider;
Set<File> filesToWatch;
long lastEventTime = 0;

Updater(FileProvider fp) {
Updater(Supplier<Set<File>> fp) {
fileProvider = fp;
}

Expand Down Expand Up @@ -945,7 +896,7 @@ public void fileAttributeChanged(FileAttributeEvent fe) {
}

synchronized void attachAll() {
filesToWatch = fileProvider.getFiles();
filesToWatch = fileProvider.get();
if (filesToWatch != null) {
for (File f : filesToWatch) {
if (f != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,7 @@ public enum PropertyKind {
/**
* Describes a property and its value.
*/
public static final class Property {
private final Object id;
private final String scope;
private final PropertyKind kind;
private final String type;
private final String value;
private final String name;

public Property(Object id, String scope, String propertyName, PropertyKind kind, String type, String value) {
this.id = id;
this.scope = scope;
this.kind = kind;
this.type = type;
this.value = value;
this.name = propertyName;
}
public static final record Property(Object id, String scope, String name, PropertyKind kind, String type, String value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: records are implicitly final and static

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. I left that change unintentionally there. I just needed a quick and good toString() method for debugging.

Well, if it made there let's keep that, I'll just remove the static final in the upcoming commit.


/**
* Returns the property id. The ID is a token that could be used to identify
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.util.List;
import javax.swing.event.ChangeListener;
import org.gradle.internal.impldep.javax.annotation.Nullable;
import org.netbeans.modules.gradle.api.execute.ActionMapping;
import org.netbeans.modules.gradle.api.execute.GradleExecConfiguration;
import org.netbeans.modules.gradle.spi.actions.ProjectActionMappingProvider;
Expand Down Expand Up @@ -60,13 +59,13 @@ public interface ConfigurableActionProvider {
* @param action the action name
* @return the action mapping for the action or {@code null} if none found
*/
ProjectActionMappingProvider findActionProvider(@Nullable String configurationId);
ProjectActionMappingProvider findActionProvider(String configurationId);

/**
* Returns a default mapping for the configuration
* @param configurationId
* @param action
* @return
*/
ActionMapping findDefaultMapping(@Nullable String configurationId, String action);
ActionMapping findDefaultMapping(String configurationId, String action);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.netbeans.modules.gradle.api.BuildPropertiesSupport;
Expand Down Expand Up @@ -98,10 +99,10 @@ private static class PropertyEvaluator implements BuildPropertiesImplementation

public PropertyEvaluator(Map<String, String> propertyMap, Map<String, String> propertyTypes,
Map<String, String> taskPropertyMap, Map<String, String> taskPropertyTypes) {
this.propertyMap = propertyMap;
this.propertyTypes = propertyTypes;
this.taskPropertyMap = taskPropertyMap;
this.taskPropertyTypes = taskPropertyTypes;
this.propertyMap = new TreeMap<>(propertyMap);
this.propertyTypes = new TreeMap<>(propertyTypes);
this.taskPropertyMap = new TreeMap<>(taskPropertyMap);
this.taskPropertyTypes = new TreeMap<>(taskPropertyTypes);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public GradleProject loadProject(LoadOptions options, String... args) {
LOGGER.log(Level.FINER, "Loaded with loader {0} -> {1}", new Object[] { loader, ret });
}
if (ret != null) {
if (best == null || best.getQuality().notBetterThan(ret.getQuality())) {
if (ret.betterThan(best)) {
best = ret;
}
if (ret.getQuality().atLeast(options.getAim())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.util.ArrayList;
Expand All @@ -51,9 +50,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.swing.SwingUtilities;
import org.gradle.tooling.BuildAction;
import org.gradle.tooling.BuildActionExecuter;
import org.gradle.tooling.BuildController;
import org.gradle.tooling.CancellationToken;
import org.gradle.tooling.CancellationTokenSource;
import org.gradle.tooling.GradleConnectionException;
Expand Down Expand Up @@ -187,8 +184,7 @@ private static GradleProject loadGradleProject(ReloadContext ctx, CancellationTo
for (String s : keys) {
Object o = info.getInfo().get(s);
// format just the 1st level:
if (o instanceof Collection) {
Collection c = (Collection)o;
if (o instanceof Collection c) {
if (!c.isEmpty()) {
LOG.finer(String.format(" %-20s: [", s));
for (Object x: c) {
Expand All @@ -200,8 +196,7 @@ private static GradleProject loadGradleProject(ReloadContext ctx, CancellationTo
LOG.finer(" ]");
continue;
}
} else if (o instanceof Map) {
Map m = (Map)o;
} else if (o instanceof Map m) {
if (!m.isEmpty()) {
LOG.finer(String.format(" %-20s: {", s));
List<String> mkeys = new ArrayList<>(m.keySet());
Expand Down Expand Up @@ -273,15 +268,13 @@ private static GradleProject loadGradleProject(ReloadContext ctx, CancellationTo
for (Report r : info.getReports()) {
reps.add(copyReport(r));
}
Object o = new ArrayList<String>(reps.stream().
var o = reps.stream().
map((r) -> r.formatReportForHintOrProblem(
true,
FileUtil.toFileObject(
ctx.project.getGradleFiles().getBuildScript()
)
)).
collect(Collectors.toList())
);
)).toList();
LOG.log(Level.FINE, "Project {0} loaded with exception, and with problems: {1}",
new Object[] {
ctx.project,
Expand All @@ -293,22 +286,20 @@ private static GradleProject loadGradleProject(ReloadContext ctx, CancellationTo
for (String s : info.getProblems()) {
reps.add(GradleProject.createGradleReport(f == null ? null : f.toPath(), s));
}
return ctx.previous.invalidate(reps.toArray(new GradleReport[0]));
return ctx.previous.invalidate(reps.toArray(GradleReport[]::new));
}
}
} catch (GradleConnectionException | IllegalStateException ex) {
LOG.log(FINE, "Failed to retrieve project information for: " + base.getProjectDir(), ex);
List<GradleReport> problems = exceptionsToProblems(ctx.project.getGradleFiles().getBuildScript(), ex);
errors.openNotification(TIT_LOAD_FAILED(base.getProjectDir()), ex.getMessage(), GradleProjectErrorNotifications.bulletedList(problems));
return ctx.previous.invalidate(problems.toArray(new GradleReport[0]));
} catch (ThreadDeath td) {
throw td;
return ctx.previous.invalidate(problems.toArray(GradleReport[]::new));
} catch (Throwable t) {
// catch any possible other errors, report project loading failure - but complete the loading operation.
LOG.log(Level.SEVERE, "Internal error during loading: " + base.getProjectDir(), t);
List<GradleReport> problems = exceptionsToProblems(ctx.project.getGradleFiles().getBuildScript(), t);
errors.openNotification(TIT_LOAD_FAILED(base.getProjectDir()), t.getMessage(), GradleProjectErrorNotifications.bulletedList(problems));
return ctx.previous.invalidate(problems.toArray(new GradleReport[0]));
return ctx.previous.invalidate(problems.toArray(GradleReport[]::new));
} finally {
loadedProjects.incrementAndGet();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/

plugins {
id("com.github.johnrengelman.shadow") version "7.1.2"
// id("com.github.johnrengelman.shadow") version "7.1.2"
// ExtensionPropertiesExtractorTest#testTaskListProperty fails with next point release
id("io.micronaut.application") version "3.6.5"
id("io.micronaut.application") version "4.6.1"
}

version = "0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# specific language governing permissions and limitations
# under the License.

micronautVersion=3.6.0
micronautVersion=4.10.0
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading