Skip to content

Commit ceac8ff

Browse files
authored
Merge pull request #4730 from sdedic/gradle/java-micronaut-artifacts
Support for jar & native image artifact for gradle projects [3/3]
2 parents 58dd590 + 233721c commit ceac8ff

File tree

62 files changed

+2701
-129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2701
-129
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,9 @@ jobs:
16511651
- name: Extract
16521652
run: tar --zstd -xf build.tar.zst
16531653

1654+
- name: micronaut
1655+
run: ant $OPTS -f enterprise/micronaut test
1656+
16541657
- name: spring.webmvc
16551658
run: ant $OPTS -f enterprise/spring.webmvc test
16561659

enterprise/micronaut/nbproject/project.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ release.external/spring-boot-configuration-metadata-2.4.4.jar=modules/ext/spring
2121
release.external/android-json-0.0.20131108.vaadin1.jar=modules/ext/android-json-0.0.20131108.vaadin1.jar
2222
spec.version.base=1.7.0
2323
requires.nb.javac=true
24-
test-unit-sys-prop.test.netbeans.dest.dir=${netbeans.dest.dir}
24+
test-unit-sys-prop.test.netbeans.dest.dir=${netbeans.dest.dir}
25+
test.unit.cp.extra=${tools.jar}

enterprise/micronaut/nbproject/project.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@
214214
<specification-version>1.76</specification-version>
215215
</run-dependency>
216216
</dependency>
217+
<dependency>
218+
<code-name-base>org.netbeans.modules.gradle</code-name-base>
219+
<build-prerequisite/>
220+
<compile-dependency/>
221+
<run-dependency>
222+
<release-version>2</release-version>
223+
<specification-version>2.29</specification-version>
224+
</run-dependency>
225+
</dependency>
217226
<dependency>
218227
<code-name-base>org.netbeans.modules.j2ee.core.utilities</code-name-base>
219228
<build-prerequisite/>
@@ -439,6 +448,10 @@
439448
<recursive/>
440449
<compile-dependency/>
441450
</test-dependency>
451+
<test-dependency>
452+
<code-name-base>org.netbeans.modules.gradle.java</code-name-base>
453+
<recursive/>
454+
</test-dependency>
442455
</test-type>
443456
</test-dependencies>
444457
<public-packages/>
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.netbeans.modules.micronaut;
20+
21+
import java.beans.PropertyChangeEvent;
22+
import java.beans.PropertyChangeListener;
23+
import java.util.ArrayList;
24+
import java.util.Collection;
25+
import java.util.Collections;
26+
import java.util.List;
27+
import javax.swing.event.ChangeEvent;
28+
import javax.swing.event.ChangeListener;
29+
import org.netbeans.api.project.Project;
30+
import org.netbeans.modules.project.dependency.ArtifactSpec;
31+
import org.netbeans.modules.project.dependency.ProjectArtifactsQuery;
32+
import org.openide.util.RequestProcessor;
33+
import org.openide.util.WeakListeners;
34+
35+
/**
36+
*
37+
* @author sdedic
38+
*/
39+
public abstract class AbstractMicronautArtifacts implements PropertyChangeListener {
40+
private static final List<ArtifactSpec> UNKNOWN = new ArrayList<>();
41+
private static final RequestProcessor ARTIFACTS_RP = new RequestProcessor(AbstractMicronautArtifacts.class);
42+
43+
private final Project project;
44+
protected final ProjectArtifactsQuery.Filter query;
45+
46+
// @GuardedBy(this)
47+
private final List<ChangeListener> listeners = new ArrayList<>();
48+
// @GuardedBy(this)
49+
private List<ArtifactSpec> artifacts;
50+
51+
private PropertyChangeListener projectL;
52+
53+
private RequestProcessor.Task refreshTask;
54+
55+
private int eventNo;
56+
57+
public AbstractMicronautArtifacts(Project project, ProjectArtifactsQuery.Filter query) {
58+
this.project = project;
59+
this.query = query;
60+
}
61+
62+
public final Project getProject() {
63+
return project;
64+
}
65+
66+
protected abstract List<ArtifactSpec> compute();
67+
68+
protected abstract void attach(PropertyChangeListener l);
69+
70+
protected abstract void detach(PropertyChangeListener l);
71+
72+
protected abstract boolean accept(PropertyChangeEvent e);
73+
74+
public void addChangeListener(ChangeListener l) {
75+
synchronized (this) {
76+
if (projectL == null) {
77+
projectL = WeakListeners.propertyChange(this, project);
78+
attach(projectL);
79+
}
80+
listeners.add(l);
81+
}
82+
}
83+
84+
public void removeChangeListener(ChangeListener l) {
85+
synchronized (this) {
86+
listeners.remove(l);
87+
}
88+
}
89+
90+
public List<ArtifactSpec> getArtifacts() {
91+
synchronized (this) {
92+
if (artifacts != null) {
93+
return artifacts;
94+
}
95+
}
96+
return refresh(null);
97+
}
98+
99+
private List<ArtifactSpec> refresh(List<ArtifactSpec> old) {
100+
int mySerial;
101+
synchronized (this) {
102+
mySerial = eventNo;
103+
}
104+
List<ArtifactSpec> as = Collections.unmodifiableList(compute());
105+
synchronized (this) {
106+
if (mySerial != eventNo) {
107+
return as;
108+
}
109+
if (artifacts != null) {
110+
return artifacts;
111+
}
112+
if (as.equals(old)) {
113+
this.artifacts = old;
114+
return old;
115+
}
116+
this.artifacts = as;
117+
if (listeners == null || listeners.isEmpty()) {
118+
return as;
119+
}
120+
}
121+
fireChanged();
122+
return as;
123+
}
124+
125+
@Override
126+
public void propertyChange(PropertyChangeEvent evt) {
127+
if (!accept(evt)) {
128+
return;
129+
}
130+
List<ArtifactSpec> old;
131+
132+
boolean fire = false;
133+
synchronized (this) {
134+
++eventNo;
135+
old = artifacts;
136+
artifacts = null;
137+
if (old != null) {
138+
if (refreshTask != null) {
139+
refreshTask.cancel();
140+
}
141+
refreshTask = ARTIFACTS_RP.post(() -> refresh(old), 50);
142+
return;
143+
}
144+
if (listeners != null && !listeners.isEmpty()) {
145+
fire = true;
146+
}
147+
}
148+
if (fire) {
149+
fireChanged();
150+
}
151+
}
152+
153+
protected void fireChanged() {
154+
ChangeListener[] ll;
155+
156+
synchronized (this) {
157+
if (listeners == null || listeners.isEmpty()) {
158+
return;
159+
}
160+
ll = listeners.toArray(new ChangeListener[listeners.size()]);
161+
}
162+
ChangeEvent e = new ChangeEvent(this);
163+
for (ChangeListener l : ll) {
164+
l.stateChanged(e);
165+
}
166+
}
167+
168+
public Collection<ArtifactSpec> getExcludedArtifacts() {
169+
return null;
170+
}
171+
}

0 commit comments

Comments
 (0)