This is an automated email from the ASF dual-hosted git repository.
lkishalmi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new de5920c [NETBEANS-2941] Allow the IDE to see the compiler options for
Gradle Project files.
de5920c is described below
commit de5920c1a2aa19c8309ad01403a42ab54aa58921
Author: Laszlo Kishalmi <[email protected]>
AuthorDate: Wed Sep 11 09:44:36 2019 -0700
[NETBEANS-2941] Allow the IDE to see the compiler options for Gradle
Project files.
---
groovy/gradle.java/apichanges.xml | 16 ++-
groovy/gradle.java/manifest.mf | 2 +-
groovy/gradle.java/nbproject/project.xml | 2 +-
.../gradle/java/api/GradleJavaProjectBuilder.java | 30 +++++-
.../gradle/java/api/GradleJavaSourceSet.java | 74 ++++++++++++-
.../java/queries/GradleCompilerOptionsQuery.java | 117 +++++++++++++++++++++
.../gradle/tooling/NbProjectInfoBuilder.groovy | 38 +++----
.../modules/gradle/GradleProjectCache.java | 2 +-
8 files changed, 245 insertions(+), 36 deletions(-)
diff --git a/groovy/gradle.java/apichanges.xml
b/groovy/gradle.java/apichanges.xml
index eb7f050..c322ab7 100644
--- a/groovy/gradle.java/apichanges.xml
+++ b/groovy/gradle.java/apichanges.xml
@@ -83,12 +83,26 @@ is the proper place.
<!-- ACTUAL CHANGES BEGIN HERE: -->
<changes>
+ <change>
+ <api name="gradle.java.api"/>
+ <summary>Compiler arguments are accessible for SourceSet-s and
minor enhancements</summary>
+ <version major="1" minor="4"/>
+ <date day="16" month="9" year="2019"/>
+ <author login="lkishalmi"/>
+ <compatibility addition="yes"/>
+ <description>
+ Sourcsets can return the used compiler arguments on it's
default
+ compiler tasks for Java, Groovy and Scala as well.
+ </description>
+ <class package="org.netbeans.modules.gradle.java.api"
name="GradleJavaSourceSet"/>
+ <issue number="NETBEANS-2941"/>
+ </change>
</changes>
<!-- Now the surrounding HTML text and document structure: -->
<htmlcontents>
-<!--
+ <!--
NO NO NO NO NO!
diff --git a/groovy/gradle.java/manifest.mf b/groovy/gradle.java/manifest.mf
index 3fd9c3c..f9dedb8 100644
--- a/groovy/gradle.java/manifest.mf
+++ b/groovy/gradle.java/manifest.mf
@@ -3,4 +3,4 @@ AutoUpdate-Show-In-Client: false
OpenIDE-Module: org.netbeans.modules.gradle.java
OpenIDE-Module-Layer: org/netbeans/modules/gradle/java/layer.xml
OpenIDE-Module-Localizing-Bundle:
org/netbeans/modules/gradle/java/Bundle.properties
-OpenIDE-Module-Specification-Version: 1.3
+OpenIDE-Module-Specification-Version: 1.4
diff --git a/groovy/gradle.java/nbproject/project.xml
b/groovy/gradle.java/nbproject/project.xml
index a6dcc6d..87521f5 100644
--- a/groovy/gradle.java/nbproject/project.xml
+++ b/groovy/gradle.java/nbproject/project.xml
@@ -30,7 +30,7 @@
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
- <specification-version>1.0</specification-version>
+ <specification-version>1.3</specification-version>
</run-dependency>
</dependency>
<dependency>
diff --git
a/groovy/gradle.java/src/org/netbeans/modules/gradle/java/api/GradleJavaProjectBuilder.java
b/groovy/gradle.java/src/org/netbeans/modules/gradle/java/api/GradleJavaProjectBuilder.java
index 024d060..0890e43 100644
---
a/groovy/gradle.java/src/org/netbeans/modules/gradle/java/api/GradleJavaProjectBuilder.java
+++
b/groovy/gradle.java/src/org/netbeans/modules/gradle/java/api/GradleJavaProjectBuilder.java
@@ -23,12 +23,17 @@ import org.netbeans.modules.gradle.api.GradleBaseProject;
import org.netbeans.modules.gradle.spi.GradleFiles;
import org.netbeans.modules.gradle.spi.ProjectInfoExtractor;
import java.io.File;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.EnumMap;
import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import org.openide.filesystems.FileUtil;
import org.openide.util.lookup.ServiceProvider;
+import static
org.netbeans.modules.gradle.java.api.GradleJavaSourceSet.SourceType;
+import static
org.netbeans.modules.gradle.java.api.GradleJavaSourceSet.SourceType.*;
/**
*
@@ -59,7 +64,7 @@ final class GradleJavaProjectBuilder implements
ProjectInfoExtractor.Result {
if (sourceSetNames != null) {
for (String name : sourceSetNames) {
GradleJavaSourceSet sourceSet = prj.createSourceSet(name);
- for (GradleJavaSourceSet.SourceType type :
GradleJavaSourceSet.SourceType.values()) {
+ for (SourceType type : SourceType.values()) {
Set<File> dirs = (Set<File>) info.get("sourceset_" + name
+ "_" + type.name());
if (dirs != null) {
Set<File> normalizedDirs = new LinkedHashSet<>();
@@ -75,8 +80,27 @@ final class GradleJavaProjectBuilder implements
ProjectInfoExtractor.Result {
sourceSet.runtimeConfigurationName = (String)
info.get("sourceset_" + name + "_configuration_runtime");
sourceSet.outputClassDirs = (Set<File>) info.get("sourceset_"
+ name + "_output_classes");
sourceSet.outputResources = (File) info.get("sourceset_" +
name + "_output_resources");
- sourceSet.sourcesCompatibility = (String)
info.get("sourceset_" + name + "_source_compatibility");
- sourceSet.targetCompatibility = (String) info.get("sourceset_"
+ name + "_target_compatibility");
+ Map<SourceType, String> sourceComp = new
EnumMap<>(SourceType.class);
+ Map<SourceType, String> targetComp = new
EnumMap<>(SourceType.class);
+ Map<SourceType, List<String>> compilerArgs = new
EnumMap<>(SourceType.class);
+ for (SourceType lang : Arrays.asList(JAVA, GROOVY, SCALA)) {
+ String sc = (String) info.get("sourceset_" + name + "_" +
lang.name() + "_source_compatibility");
+ String tc = (String) info.get("sourceset_" + name + "_" +
lang.name() + "_target_compatibility");
+ if (sc != null) {
+ sourceComp.put(lang, sc);
+ }
+ if (tc != null) {
+ targetComp.put(lang, tc);
+ }
+ List<String> compArgs = (List<String>)
info.get("sourceset_" + name + "_" + lang.name() + "_compiler_args");
+ if (compArgs != null) {
+ compilerArgs.put(lang,
Collections.unmodifiableList(compArgs));
+ }
+ }
+ sourceSet.sourcesCompatibility =
Collections.unmodifiableMap(sourceComp);
+ sourceSet.targetCompatibility =
Collections.unmodifiableMap(targetComp);
+ sourceSet.compilerArgs =
Collections.unmodifiableMap(compilerArgs);
+
for (File out : sourceSet.getOutputClassDirs()) {
if (prj.getTestClassesRoots().contains(out)) {
sourceSet.testSourceSet = true;
diff --git
a/groovy/gradle.java/src/org/netbeans/modules/gradle/java/api/GradleJavaSourceSet.java
b/groovy/gradle.java/src/org/netbeans/modules/gradle/java/api/GradleJavaSourceSet.java
index d04c968..c1bf0f8 100644
---
a/groovy/gradle.java/src/org/netbeans/modules/gradle/java/api/GradleJavaSourceSet.java
+++
b/groovy/gradle.java/src/org/netbeans/modules/gradle/java/api/GradleJavaSourceSet.java
@@ -66,13 +66,15 @@ public final class GradleJavaSourceSet implements
Serializable {
public static final String MAIN_SOURCESET_NAME = "main"; //NOI18N
public static final String TEST_SOURCESET_NAME = "test"; //NOI18N
+ private static final String DEFAULT_SOURCE_COMPATIBILITY = "1.5"; //NOI18N
Map<SourceType, Set<File>> sources = new EnumMap<>(SourceType.class);
String name;
String runtimeConfigurationName;
String compileConfigurationName;
- String sourcesCompatibility = "1.5"; //NOI18N
- String targetCompatibility = sourcesCompatibility;
+ Map<SourceType, String> sourcesCompatibility = Collections.emptyMap();
+ Map<SourceType, String> targetCompatibility = Collections.emptyMap();
+ Map<SourceType, List<String>> compilerArgs = Collections.emptyMap();
boolean testSourceSet;
Set<File> outputClassDirs;
File outputResources;
@@ -94,12 +96,60 @@ public final class GradleJavaSourceSet implements
Serializable {
return testSourceSet;
}
+ /**
+ * This method returns the Java source compatibility defined for this
source
+ * set.
+ *
+ * @deprecated Use {@link
#getSourcesCompatibility(org.netbeans.modules.gradle.java.api.GradleJavaSourceSet.SourceType)}
instead.
+ * @return
+ */
+ @Deprecated
public String getSourcesCompatibility() {
- return sourcesCompatibility;
+ return getSourcesCompatibility(SourceType.JAVA);
+ }
+
+ /**
+ * This method returns the source compatibility defined for this source
+ * set for the given language type.
+ *
+ * The value is actually extracted from the compiler task defined for
+ * this source set and language type. If that cannot be determined for some
+ * reason this method returns "1.5".
+ *
+ * @since 1.4
+ * @param type
+ * @return the defined source compatibility or "1.5"
+ */
+ public String getSourcesCompatibility(SourceType type) {
+ return sourcesCompatibility.getOrDefault(type,
DEFAULT_SOURCE_COMPATIBILITY);
}
+ /**
+ * This method returns the Java target compatibility defined for this
source
+ * set.
+ *
+ * @deprecated Use {@link
#getTargetCompatibility(org.netbeans.modules.gradle.java.api.GradleJavaSourceSet.SourceType)}
instead.
+ * @return
+ */
+ @Deprecated
public String getTargetCompatibility() {
- return targetCompatibility;
+ return getTargetCompatibility(SourceType.JAVA);
+ }
+
+ /**
+ * This method returns the target compatibility defined for this source
+ * set for the given language type.
+ *
+ * The value is actually extracted from the compiler task defined for
+ * this source set and language type. If that cannot be determined for some
+ * reason this method returns the defined source compatibility.
+ *
+ * @since 1.4
+ * @param type
+ * @return the defined target compatibility
+ */
+ public String getTargetCompatibility(SourceType type) {
+ return targetCompatibility.getOrDefault(type,
getSourcesCompatibility(type));
}
public String getRuntimeConfigurationName() {
@@ -413,6 +463,22 @@ public final class GradleJavaSourceSet implements
Serializable {
return null;
}
+ /**
+ * Returns the compiler arguments for this source set defined for the given
+ * language.
+ *
+ * The value is actually extracted from the compiler task defined for
+ * this source set and language type. If that cannot be determined for some
+ * reason this method returns an empty list.
+ * @since 1.4
+ * @param type
+ * @return
+ */
+ public List<String> getCompilerArgs(SourceType type) {
+ List<String> args = compilerArgs.get(type);
+ return args != null ? args : Collections.<String>emptyList();
+ }
+
public String getCompileTaskName(String language) {
return getTaskName("compile", language);
}
diff --git
a/groovy/gradle.java/src/org/netbeans/modules/gradle/java/queries/GradleCompilerOptionsQuery.java
b/groovy/gradle.java/src/org/netbeans/modules/gradle/java/queries/GradleCompilerOptionsQuery.java
new file mode 100644
index 0000000..0a9aeb0
--- /dev/null
+++
b/groovy/gradle.java/src/org/netbeans/modules/gradle/java/queries/GradleCompilerOptionsQuery.java
@@ -0,0 +1,117 @@
+/*
+ * 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.java.queries;
+
+import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.swing.event.ChangeListener;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.gradle.api.NbGradleProject;
+import org.netbeans.modules.gradle.java.api.GradleJavaProject;
+import org.netbeans.modules.gradle.java.api.GradleJavaSourceSet;
+import org.netbeans.spi.java.queries.CompilerOptionsQueryImplementation;
+import org.netbeans.spi.project.ProjectServiceProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.ChangeSupport;
+
+/**
+ *
+ * @author lkishalmi
+ */
+@ProjectServiceProvider(service = CompilerOptionsQueryImplementation.class,
projectType = NbGradleProject.GRADLE_PLUGIN_TYPE + "/java-base")
+public final class GradleCompilerOptionsQuery implements
CompilerOptionsQueryImplementation {
+
+ final Project project;
+ private final PropertyChangeListener listener;
+ final Map<String, ResultImpl> cache = new HashMap<>();
+
+ public GradleCompilerOptionsQuery(Project project) {
+ this.project = project;
+ final NbGradleProject watcher = NbGradleProject.get(project);
+ listener = (evt) -> {
+ if (watcher.isUnloadable()) return;
+ if
(NbGradleProject.PROP_PROJECT_INFO.equals(evt.getPropertyName())) {
+ //TODO: How shall we handle source set removal?
+ synchronized(GradleCompilerOptionsQuery.this) {
+ for (ResultImpl res : cache.values()) {
+ res.support.fireChange();
+ }
+ }
+ }
+ };
+ }
+
+ @Override
+ public Result getOptions(FileObject file) {
+ File f = FileUtil.toFile(file);
+ GradleJavaProject gjp = GradleJavaProject.get(project);
+ GradleJavaSourceSet sourceSet = gjp.containingSourceSet(f);
+ ResultImpl ret = null;
+ if (sourceSet != null) {
+ GradleJavaSourceSet.SourceType sourceType =
sourceSet.getSourceType(f);
+ if (sourceType != GradleJavaSourceSet.SourceType.RESOURCES) {
+ String key = sourceSet.getName() + "." + sourceType.name();
+ synchronized(this) {
+ ret = cache.get(key);
+ if (ret == null) {
+ ret = new ResultImpl(sourceSet.getName(), sourceType);
+ cache.put(key, ret);
+ }
+ }
+ }
+ }
+ return ret;
+ }
+
+ final class ResultImpl extends Result {
+
+ final String sourceSetName;
+ final GradleJavaSourceSet.SourceType type;
+ final ChangeSupport support;
+
+ public ResultImpl(String sourceSetName, GradleJavaSourceSet.SourceType
type) {
+ this.sourceSetName = sourceSetName;
+ this.type = type;
+ support = new ChangeSupport(this);
+ }
+
+
+ @Override
+ public List<? extends String> getArguments() {
+ GradleJavaProject gjp = GradleJavaProject.get(project);
+ GradleJavaSourceSet ss = gjp.getSourceSets().get(sourceSetName);
+ return ss.getCompilerArgs(type);
+ }
+
+ @Override
+ public void addChangeListener(ChangeListener listener) {
+ support.addChangeListener(listener);
+ }
+
+ @Override
+ public void removeChangeListener(ChangeListener listener) {
+ support.removeChangeListener(listener);
+ }
+
+ }
+}
diff --git
a/groovy/gradle/netbeans-gradle-tooling/src/main/groovy/org/netbeans/modules/gradle/tooling/NbProjectInfoBuilder.groovy
b/groovy/gradle/netbeans-gradle-tooling/src/main/groovy/org/netbeans/modules/gradle/tooling/NbProjectInfoBuilder.groovy
index 3ac906a..56ca885 100644
---
a/groovy/gradle/netbeans-gradle-tooling/src/main/groovy/org/netbeans/modules/gradle/tooling/NbProjectInfoBuilder.groovy
+++
b/groovy/gradle/netbeans-gradle-tooling/src/main/groovy/org/netbeans/modules/gradle/tooling/NbProjectInfoBuilder.groovy
@@ -194,7 +194,6 @@ class NbProjectInfoBuilder {
Map<String, File> outputs = new HashMap<>()
Map<String, Map<String, Set<File>>> classpaths = new HashMap<>()
- boolean hasAndroid = project.plugins.hasPlugin('com.android.library')
|| project.plugins.hasPlugin('com.android.application')
boolean hasJava = project.plugins.hasPlugin('java-base')
boolean hasGroovy = project.plugins.hasPlugin('groovy-base')
boolean hasScala = project.plugins.hasPlugin('scala-base')
@@ -203,10 +202,19 @@ class NbProjectInfoBuilder {
if (project.sourceSets != null) {
model.info.sourcesets = storeSet(project.sourceSets.names);
project.sourceSets.each() { sourceSet ->
- def compileTask =['java', 'groovy', 'scala'].collect {
sourceSet.getCompileTaskName(it) }.findResult { project.tasks.findByName(it) }
- if (compileTask != null) {
-
model.info["sourceset_${sourceSet.name}_source_compatibility"] =
compileTask.sourceCompatibility
-
model.info["sourceset_${sourceSet.name}_target_compatibility"] =
compileTask.targetCompatibility
+ ['JAVA', 'GROOVY', 'SCALA'].each() { lang ->
+ def compileTask =
project.tasks.findByName(sourceSet.getCompileTaskName(lang.toLowerCase()))
+ if (compileTask != null) {
+
model.info["sourceset_${sourceSet.name}_${lang}_source_compatibility"] =
compileTask.sourceCompatibility
+
model.info["sourceset_${sourceSet.name}_${lang}_target_compatibility"] =
compileTask.targetCompatibility
+ List<String> compilerArgs = []
+ try {
+ compilerArgs =
compileTask.options.allCompilerArgs
+ } catch (Throwable ex) {
+ compilerArgs = compileTask.options.compilerArgs
+ }
+
model.info["sourceset_${sourceSet.name}_${lang}_compiler_args"] = new
ArrayList<String>(compilerArgs)
+ }
}
model.info["sourceset_${sourceSet.name}_JAVA"] =
storeSet(sourceSet.java.srcDirs);
model.info["sourceset_${sourceSet.name}_RESOURCES"] =
storeSet(sourceSet.resources.srcDirs);
@@ -239,26 +247,6 @@ class NbProjectInfoBuilder {
model.noteProblem('No sourceSets found on this project. This
project mightbe a Model/Rule based one which is not supported at the moment.')
}
}
- if (hasAndroid) {
- model.info.sourcesets = storeSet(project.android.sourceSets.names);
- project.android.sourceSets.each() {
- model.info["sourceset_${it.name}_JAVA"] =
storeSet(it.java.srcDirs);
- model.info["sourceset_${it.name}_RESOURCES"] =
storeSet(it.resources.srcDirs);
- model.info["sourceset_${it.name}_RES"] =
storeSet(it.res.srcDirs);
- model.info["sourceset_${it.name}_ASSETS"] =
storeSet(it.assets.srcDirs);
- model.info["sourceset_${it.name}_MANIFEST"] =
it.manifest.srcFile;
- model.info["sourceset_${it.name}_AIDL"] =
storeSet(it.aidl.srcDirs);
- model.info["sourceset_${it.name}_RS"] =
storeSet(it.renderscript.srcDirs);
- model.info["sourceset_${it.name}_JNI"] =
storeSet(it.jni.srcDirs);
- try {
- model.info["sourceset_${it.name}_classpath_compile"] =
storeSet(project.configurations[it.compileConfigurationName].files);
- } catch(Exception e) {
- model.noteProblem(e)
- }
- model.info["sourceset_${it.name}_configuration_compile"] =
it.compileConfigurationName;
- model.info["sourceset_${it.name}_configuration_package"] =
it.packageConfigurationName;
- }
- }
model.ext.perf.sources = System.currentTimeMillis() - time
}
diff --git
a/groovy/gradle/src/org/netbeans/modules/gradle/GradleProjectCache.java
b/groovy/gradle/src/org/netbeans/modules/gradle/GradleProjectCache.java
index df5a962..a96ca88 100644
--- a/groovy/gradle/src/org/netbeans/modules/gradle/GradleProjectCache.java
+++ b/groovy/gradle/src/org/netbeans/modules/gradle/GradleProjectCache.java
@@ -97,7 +97,7 @@ public final class GradleProjectCache {
private static final Map<File, Set<File>> SUB_PROJECT_DIR_CACHE = new
ConcurrentHashMap<>();
// Increase this number if new info is gathered from the projects.
- private static final int COMPATIBLE_CACHE_VERSION = 11;
+ private static final int COMPATIBLE_CACHE_VERSION = 12;
/**
* Loads a physical GradleProject either from Gradle or Cache. As project
retrieval can be time consuming using
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists