Skip to content

Commit

Permalink
[NETBEANS-5846] Minimal support of java-platfom Gradle projects.
Browse files Browse the repository at this point in the history
  • Loading branch information
lkishalmi committed Nov 20, 2021
1 parent eabd814 commit 224dfc0
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.ResolvedDependency
import org.gradle.api.artifacts.ResolveException
import org.gradle.api.artifacts.FileCollectionDependency
import org.gradle.api.artifacts.ExternalModuleDependency
import org.gradle.api.artifacts.ModuleDependency
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.component.ModuleComponentSelector
import org.gradle.api.artifacts.component.ProjectComponentSelector
import org.gradle.api.artifacts.result.ArtifactResult
Expand All @@ -51,10 +52,53 @@ import org.gradle.util.VersionNumber
*/
class NbProjectInfoBuilder {
def NB_PREFIX = 'netbeans.'
def CONFIG_EXCLUDES = ['archives', 'checkstyle', 'pmd', 'jacocoAgent', \
'jacocoAnt', 'findbugs', 'findbugsPlugins', 'jdepend', 'codenarc', \
'classycle']

def CONFIG_EXCLUDES = [\
'archives',
'checkstyle',
'classycle',
'codenarc',
'findbugs',
'findbugsPlugins',
'jacocoAgent',
'jacocoAnt',
'jdepend',
'pmd',
]

def RECOGNISED_PLUGINS = [
'antlr',
'application',
'base',
'checkstyle',
'com.android.application',
'com.android.library',
'com.github.lkishalmi.gatling',
'distribution',
'ear',
'findbugs',
'groovy',
'groovy-base',
'io.micronaut.application',
'ivy-publish',
'jacoco',
'java',
'java-base',
'java-library-distribution',
'java-platform',
'maven',
'maven-publish',
'org.jetbrains.kotlin.js',
'org.jetbrains.kotlin.jvm',
'org.jetbrains.kotlin.android',
'org.springframework.boot',
'osgi',
'play',
'pmd',
'scala',
'scala-base',
'war',
]

final Project project;
final VersionNumber gradleVersion;

Expand Down Expand Up @@ -147,18 +191,7 @@ class NbProjectInfoBuilder {
private void detectPlugins(NbProjectInfoModel model) {
long time = System.currentTimeMillis()
Set<String> plugins = new HashSet<>();
for (String plugin: ['base', 'java-base', 'java', 'war', \
'scala-base', 'scala', 'groovy-base', 'groovy',\
'distribution', 'application', 'maven', 'osgi', \
'jacoco', 'checkstyle', 'pmd', 'findbugs', 'ear', \
'play', 'java-library-distribution', 'maven-publish',
'ivy-publish', 'antlr', \
'org.springframework.boot', \
'com.github.lkishalmi.gatling', \
'com.android.library', 'com.android.application',
'org.jetbrains.kotlin.android', 'org.jetbrains.kotlin.js',
'org.jetbrains.kotlin.jvm',
'io.micronaut.application']) {
for (String plugin: RECOGNISED_PLUGINS) {
if (project.plugins.hasPlugin(plugin)) {
plugins.add(plugin);
}
Expand Down Expand Up @@ -341,10 +374,18 @@ class NbProjectInfoBuilder {
}
//visibleConfigurations = visibleConfigurations.findAll() { resolvable(it) }
visibleConfigurations.each() {
def componentIds = []
def componentIds = new HashSet()
def unresolvedIds = []
def projectNames = []
long time_inspect_conf = System.currentTimeMillis()

it.dependencies.withType(ModuleDependency) {
def group = it.group != null ? it.group : '';
def name = it.name
def version = it.version != null ? ':' + it.version : ''
def id = group + ':' + name + version;
componentIds.add(id)
}
if (resolvable(it)) {
try {
it.incoming.resolutionResult.allDependencies.each {
Expand All @@ -355,14 +396,21 @@ class NbProjectInfoBuilder {
}
if (it instanceof UnresolvedDependencyResult) {
def id = it.requested.displayName
unresolvedIds.add(id)
unresolvedProblems.put(id, it.failure.message)
if (componentIds.contains(id)) {
unresolvedIds.add(id)
}
if (!project.plugins.hasPlugin('java-platform')) {
unresolvedProblems.put(id, it.failure.message)
}
}
}
} catch (ResolveException ex) {
model.noteProblem(ex)
}
ids.addAll(componentIds)
} else {
unresolvedIds.addAll(componentIds)
componentIds.clear()
}
long time_project_deps = System.currentTimeMillis()
model.ext.perf["dependency_inspect_${it.name}_module"] = time_project_deps - time_inspect_conf
Expand Down Expand Up @@ -482,10 +530,12 @@ class NbProjectInfoBuilder {
}

private void collectModuleDependencies(final NbProjectInfoModel model, String confiurationName, boolean includeRoot, final Set deps) {
if (includeRoot && !model.info["configuration_${confiurationName}_non_resolving"]) {
if (includeRoot) {
deps.addAll(model.info["configuration_${confiurationName}_components"])
deps.addAll(model.info["configuration_${confiurationName}_unresolved"])
deps.addAll(model.info["configuration_${confiurationName}_files"])
if (!model.info["configuration_${confiurationName}_non_resolving"]) {
deps.addAll(model.info["configuration_${confiurationName}_unresolved"])
}
}
model.info["configuration_${confiurationName}_extendsFrom"].each {
collectModuleDependencies(model, it, true, deps)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static String bulletedList(Collection<? extends Object> elements) {
sb.append("<ul>"); //NOI18N
for (Object element : elements) {
sb.append("<li>"); //NOI18N
String[] lines = element.toString().split("\n"); //NOI18N
String[] lines = String.valueOf(element).split("\n"); //NOI18N
for (int i = 0; i < lines.length; i++) {
String line = lines[i];
sb.append(lineWrap(line, 78));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.modules.gradle.GradleModuleFileCache21;
import org.netbeans.modules.gradle.spi.GradleSettings;
import org.openide.util.lookup.ServiceProvider;
Expand All @@ -49,6 +51,7 @@
class GradleBaseProjectBuilder implements ProjectInfoExtractor.Result {

final static Map<String, List<String>> DEPENDENCY_TO_PLUGIN = new LinkedHashMap<>();
final static Logger LOG = Logger.getLogger(GradleBaseProjectBuilder.class.getName());

static {
addDependencyPlugin("javax:javaee-api:.*", "ejb", "jpa");
Expand All @@ -73,6 +76,11 @@ private static void addDependencyPlugin(String dependency, String... plugins) {
}

void build() {
if (LOG.isLoggable(Level.FINE)) {
for (Map.Entry<String, Object> entry : info.entrySet()) {
LOG.log(Level.FINE, entry.getKey() + " = " + String.valueOf(entry.getValue()));
}
}
processBasicInfo();
processTasks();
processDependencies();
Expand Down Expand Up @@ -217,7 +225,11 @@ void processDependencies() {
Set<String> unresolvedComp = (Set<String>) info.get("configuration_" + name + "_unresolved");
if (unresolvedComp != null) {
for (String u : unresolvedComp) {
conf.unresolved.add(unresolved.get(u));
UnresolvedDependency dep = unresolved.get(u);
if (dep == null) {
dep = new UnresolvedDependency(u);
}
conf.unresolved.add(dep);
}
}
Set<File> files = (Set<File>) info.get("configuration_" + name + "_files");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ public boolean isCanBeResolved() {
}

public boolean isEmpty() {
return !canBeResolved || ((files == null || files.files.isEmpty()) && modules.isEmpty() && unresolved.isEmpty() && projects.isEmpty());
return ((files == null || files.files.isEmpty())
&& modules.isEmpty()
&& unresolved.isEmpty()
&& projects.isEmpty());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.PreferenceChangeListener;
Expand All @@ -48,6 +47,7 @@
import org.netbeans.api.annotations.common.StaticResource;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectManager;
import org.netbeans.modules.gradle.api.GradleBaseProject;
import org.netbeans.modules.gradle.api.NbGradleProject.Quality;
import org.netbeans.spi.project.ui.LogicalViewProvider;
import org.openide.awt.HtmlBrowser;
Expand Down Expand Up @@ -94,7 +94,7 @@ public class ConfigurationsNode extends AbstractNode {
})
@SuppressWarnings("OverridableMethodCallInConstructor")
public ConfigurationsNode(NbGradleProjectImpl project) {
super(Children.create(new ConfigurationsChildren(project), true), Lookups.singleton(project));
super(Children.create(new ConfigurationsChildren(project), false), Lookups.singleton(project));
this.project = project;
setName("configurations"); //NOI18N
setDisplayName(Bundle.LBL_ConfigurationsNode());
Expand All @@ -108,7 +108,7 @@ public ConfigurationsNode(NbGradleProjectImpl project) {
public Image getIcon(int type) {
GradleProject gp = project.getGradleProject();
Image ret = ImageUtilities.loadImage(LIBRARIES_ICON);
if (gp.getQuality().worseThan(Quality.FULL) || !gp.getBaseProject().isResolved()) {
if (gp.getQuality().worseThan(Quality.FULL) || needsResolve()) {
Image warn = ImageUtilities.loadImage(WARNING_BADGE);
ret = ImageUtilities.mergeImages(ret, warn, 8, 0);
}
Expand All @@ -134,8 +134,12 @@ public Action[] getActions(boolean context) {
})
@Override
public String getShortDescription() {
GradleProject gp = project.getGradleProject();
return gp.getBaseProject().isResolved() ? Bundle.HINT_ConfigurationsNode() : Bundle.HINT_ConfigurationsNodeUnresolved();
return !needsResolve() ? Bundle.HINT_ConfigurationsNode() : Bundle.HINT_ConfigurationsNodeUnresolved();
}

private boolean needsResolve() {
GradleBaseProject gbp = GradleBaseProject.get(project);
return !gbp.isResolved() && !gbp.hasPlugins("java-platform"); //NOI18N
}

private static class ConfigurationsChildren extends ChildFactory.Detachable<GradleConfiguration> implements PreferenceChangeListener, PropertyChangeListener {
Expand All @@ -148,7 +152,7 @@ public ConfigurationsChildren(NbGradleProjectImpl project) {

@Override
protected Node createNodeForKey(GradleConfiguration conf) {
Children ch = conf.isEmpty() ? Children.LEAF : Children.create(new ConfigurationChildren(project, conf.getName()), true);
Children ch = conf.isEmpty() ? Children.LEAF : Children.create(new ConfigurationChildren(project, conf.getName()), false);
AbstractNode ret = new AbstractNode(ch);
ret.setName(conf.getName());
ret.setShortDescription(conf.getDescription());
Expand Down Expand Up @@ -220,6 +224,7 @@ public ConfigurationChildren(NbGradleProjectImpl project, String configuration)

@NbBundle.Messages({
"LBL_LocalDependenciesNode=Local Files",
"HINT_NotResolvableConfiguration=This dependency is not resolved here as its configuration can't be resolved.",
})
@Override
protected Node[] createNodesForKey(GradleDependency key) {
Expand Down Expand Up @@ -272,11 +277,15 @@ protected Node[] createNodesForKey(GradleDependency key) {
break;
}
case UNRESOLVED: {
GradleConfiguration conf = GradleBaseProject.get(project).getConfigurations().get(configuration);
GradleDependency.UnresolvedDependency dep = (GradleDependency.UnresolvedDependency) key;

AbstractNode node = new AbstractNode(Children.LEAF);
node.setName(dep.getId());
node.setIconBaseWithExtension(UNRESOLVED_ICON);
if (!conf.isCanBeResolved()) {
node.setShortDescription(Bundle.HINT_NotResolvableConfiguration());
}
ret.add(node);
break;
}
Expand All @@ -287,9 +296,8 @@ protected Node[] createNodesForKey(GradleDependency key) {

@Override
protected boolean createKeys(List<GradleDependency> list) {
GradleProject gp = project.getGradleProject();
ArrayList<GradleDependency> ret = new ArrayList<>();
GradleConfiguration conf = gp.getBaseProject().getConfigurations().get(configuration);
GradleConfiguration conf = GradleBaseProject.get(project).getConfigurations().get(configuration);
// We can get null here in some extreme cases, e.g. when the project is being deleted
if (conf != null) {
ret.addAll(conf.getUnresolved());
Expand All @@ -313,7 +321,6 @@ protected void removeNotify() {
@Override
protected void addNotify() {
NbGradleProject.addPropertyChangeListener(project, this);

}

@Override
Expand Down Expand Up @@ -419,12 +426,7 @@ protected boolean createKeys(List<FileObject> keys) {
ret.add(fo);
}
}
ret.sort(new Comparator<FileObject>() {
@Override
public int compare(FileObject o1, FileObject o2) {
return o1.getNameExt().compareTo(o2.getNameExt());
}
});
ret.sort((FileObject o1, FileObject o2) -> o1.getNameExt().compareTo(o2.getNameExt()));
keys.addAll(ret);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public class JavaSEProjectIconProvider implements ProjectIconProvider {
@StaticResource
private static final String APPLICATION_BADGE = "org/netbeans/modules/gradle/java/resources/application-badge.png"; //NOI18

@StaticResource
private static final String LIBRARIES_BADGE = "org/netbeans/modules/gradle/java/resources/libraries-badge.png"; //NOI18

final Project project;

public JavaSEProjectIconProvider(Project project) {
Expand All @@ -61,6 +64,11 @@ public Image getIcon() {
ret = ImageUtilities.mergeImages(ret, badge, 8, 8);
}
}
if (plugins.contains("java-platform")) { //NOI18N
ret = ImageUtilities.loadImage(GRADLE_JAVASE_ICON);
Image badge = ImageUtilities.loadImage(LIBRARIES_BADGE);
ret = ImageUtilities.mergeImages(ret, badge, 8, 8);
}
return ret;
}

Expand Down

0 comments on commit 224dfc0

Please sign in to comment.