Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/apache/netbeans into apac…
Browse files Browse the repository at this point in the history
…he#4447-fix-missing-java-codeblocks-folding
  • Loading branch information
Chris committed Nov 9, 2022
2 parents ca44a81 + 47632f8 commit 0ec6d03
Show file tree
Hide file tree
Showing 113 changed files with 2,341 additions and 3,012 deletions.
24 changes: 16 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ jobs:
with:
java-version: ${{ matrix.java }}
distribution: 'zulu'

- name: Checkout ${{ github.ref }} ( ${{ github.sha }} )
uses: actions/checkout@v3
with:
persist-credentials: false
submodules: false

- name: Caching dependencies
uses: actions/cache@v3
with:
path: ~/.hgexternalcache
key: ${{ runner.os }}-${{ hashFiles('*/external/binaries-list', '*/*/external/binaries-list') }}
restore-keys: ${{ runner.os }}-

- name: Checkout ${{ github.ref }} ( ${{ github.sha }} )
uses: actions/checkout@v3
with:
persist-credentials: false
submodules: false

- name: Build NetBeans
run: ant -quiet -Dcluster.config=release build-nozip
Expand Down Expand Up @@ -1113,6 +1113,10 @@ jobs:
if: env.test_java == 'true' && success()
run: ant $OPTS -f java/java.completion test

- name: java.editor
if: env.test_java == 'true' && success()
run: ant $OPTS -f java/java.editor test-unit

- name: java.freeform
run: ant $OPTS -f java/java.freeform test

Expand Down Expand Up @@ -1244,6 +1248,10 @@ jobs:
if: env.test_java == 'true' && success()
run: ant $OPTS $OPTS_11 -f java/java.completion test

- name: java.editor
if: env.test_java == 'true' && success()
run: ant $OPTs $OPTS_11 -f java/java.editor test-unit

- name: java/java.source
run: ant $OPTS $OPTS_11 -f java/java.source test-unit

Expand Down Expand Up @@ -1651,8 +1659,8 @@ jobs:
- name: Extract
run: tar --zstd -xf build.tar.zst

- name: micronaut
run: ant $OPTS -f enterprise/micronaut test
- name: enterprise/micronaut
run: .github/retry.sh ant $OPTS -f enterprise/micronaut test

- name: spring.webmvc
run: ant $OPTS -f enterprise/spring.webmvc test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.cloud.oracle.adm;

/**
*
* @author sdedic
*/
public class AuditOptions {
private boolean forceAuditExecution;
private boolean runIfNotExists;
private String auditName;

public static AuditOptions makeNewAudit() {
return new AuditOptions().setForceAuditExecution(true).setRunIfNotExists(true);
}

public boolean isForceAuditExecution() {
return forceAuditExecution;
}

public AuditOptions setForceAuditExecution(boolean forceAuditExecution) {
this.forceAuditExecution = forceAuditExecution;
return this;
}

public boolean isRunIfNotExists() {
return runIfNotExists;
}

public AuditOptions setRunIfNotExists(boolean runIfNotExists) {
this.runIfNotExists = runIfNotExists;
return this;
}

public String getAuditName() {
return auditName;
}

public AuditOptions setAuditName(String auditName) {
this.auditName = auditName;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@ public KnowledgeBaseItem getProjectKnowledgeBase() {
"# {0} - project name",
"MSG_CreatingAuditFailed=Creating Vulnerablity audit for project {0} failed.",
})
public CompletableFuture<String> runProjectAudit(KnowledgeBaseItem item, boolean force, boolean runIfNoReport) {
public CompletableFuture<String> runProjectAudit(KnowledgeBaseItem item, AuditOptions options) {
if (item != null) {
setProjectKnowledgeBase(item);
}
CompletableFuture<String> result = new CompletableFuture<>();
AUDIT_PROCESSOR.post(() -> {
try {
result.complete(VulnerabilityWorker.getInstance().findVulnerability(project, force, runIfNoReport));
result.complete(VulnerabilityWorker.getInstance().findVulnerability(project, options));
} catch (ThreadDeath x) {
throw x;
} catch (AuditException ex) {
Expand All @@ -91,7 +91,7 @@ public CompletableFuture<String> runProjectAudit(KnowledgeBaseItem item, boolean
return result;
}

public CompletableFuture<KnowledgeBaseItem> findKnowledgeBase(String compartmentId, String knowledgeBaseId) {
public CompletableFuture<KnowledgeBaseItem> findKnowledgeBase(String knowledgeBaseId) {
CompletableFuture<KnowledgeBaseItem> result = new CompletableFuture<>();
CALL_PROCESSOR.post(() -> {
try ( ApplicationDependencyManagementClient client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void actionPerformed(ActionEvent e) {
final String projectDisplayName = ProjectUtils.getInformation(project).getDisplayName();
if (kbItem != null) {
try {
VulnerabilityWorker.getInstance().findVulnerability(project, true, true);
VulnerabilityWorker.getInstance().findVulnerability(project, AuditOptions.makeNewAudit());
} catch (AuditException exc) {
ErrorUtils.processError(exc, Bundle.MSG_CreatingAuditFailed(projectDisplayName));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,11 @@ public static VulnerabilityWorker getInstance() {
* @param forceAudit
* @return Returns the audit ID, or {@code null} if no audit is present.
*/
public String findVulnerability(Project project, boolean forceAudit, boolean runIfNoReport) throws AuditException {
LOG.log(Level.FINER, "Trying to obtain audit for project {0}, force:{1}", new Object[] { project, forceAudit });
public String findVulnerability(Project project, AuditOptions auditOptions) throws AuditException {
if (auditOptions == null) {
auditOptions = new AuditOptions();
}
LOG.log(Level.FINER, "Trying to obtain audit for project {0}, force:{1}", new Object[] { project, auditOptions.isForceAuditExecution() });
final String projectDisplayName = ProjectUtils.getInformation(project).getDisplayName();
KnowledgeBaseItem kbItem = getKnowledgeBaseForProject(project);
if (kbItem == null) {
Expand All @@ -382,9 +385,12 @@ public String findVulnerability(Project project, boolean forceAudit, boolean run
// remove from the cache old values
ProgressHandle progressHandle = ProgressHandle.createHandle(Bundle.MSG_AuditIsRunning(projectDisplayName));
AtomicBoolean remoteCall = new AtomicBoolean(false);
if (auditOptions.getAuditName() == null) {
auditOptions.setAuditName(projectDisplayName);
}
try {
return doFindVulnerability(project, kbItem.compartmentId, kbItem.getKey().getValue(),
projectDisplayName, progressHandle, forceAudit, runIfNoReport, remoteCall);
projectDisplayName, auditOptions, progressHandle, remoteCall);
} finally {
if (remoteCall.get()) {
progressHandle.close();
Expand All @@ -393,55 +399,56 @@ public String findVulnerability(Project project, boolean forceAudit, boolean run
}
}

private String doFindVulnerability(Project project, String compartmentId, String knowledgeBaseId, String projectDisplayName,
ProgressHandle progressHandle, boolean forceAudit, boolean runIfNoReport, AtomicBoolean remoteCall) throws AuditException {
DependencyResult dr = null;
private String doFindVulnerability(Project project, String compartmentId, String knowledgeBaseId, String projectDisplayName, AuditOptions auditOptions,
ProgressHandle progressHandle, AtomicBoolean remoteCall) throws AuditException {
List<ApplicationDependency> result = new ArrayList();

CacheItem cacheItem = null;
VulnerabilityReport savedAudit = null;

if (!forceAudit) {
boolean auditDone = false;

DependencyResult dr = null;

if (!auditOptions.isForceAuditExecution()) {
try {
savedAudit = AuditCache.getInstance().loadAudit(knowledgeBaseId);
} catch (IOException ex) {
LOG.log(Level.WARNING, "Could not load cached audit data", ex);
}
}

boolean auditDone = false;

if (!forceAudit && savedAudit == null) {
// attempt to find an active most recent audit:
remoteCall.set(true);
progressHandle.start();
progressHandle.progress(Bundle.MSG_SearchingAuditReport());
try (ApplicationDependencyManagementClient admClient
= new ApplicationDependencyManagementClient(OCIManager.getDefault().getConfigProvider())) {
ListVulnerabilityAuditsRequest request = ListVulnerabilityAuditsRequest
.builder()
.compartmentId(compartmentId)
.knowledgeBaseId(knowledgeBaseId)
.lifecycleState(LifecycleState.Active)
.sortBy(ListVulnerabilityAuditsRequest.SortBy.TimeCreated)
.sortOrder(SortOrder.Desc).build();
ListVulnerabilityAuditsResponse response = admClient.listVulnerabilityAudits(request);
if (!response.getVulnerabilityAuditCollection().getItems().isEmpty()) {
VulnerabilityAuditSummary summary = response.getVulnerabilityAuditCollection().getItems().get(0);
progressHandle.progress(Bundle.MSG_AuditCollectDependencies());
dr = ProjectDependencies.findDependencies(project, ProjectDependencies.newQuery(Scopes.RUNTIME));
convert(dr.getRoot(), new HashMap<>(), result);
cacheItem = fetchVulnerabilityItems(project, admClient, dr, summary, projectDisplayName);
savedAudit = new VulnerabilityReport(cacheItem.getAudit(), cacheItem.getVulnerabilities());
LOG.log(Level.WARNING, "Could not load cached audit data", ex);
}

if (savedAudit == null) {
// attempt to find an active most recent audit:
remoteCall.set(true);
progressHandle.start();
progressHandle.progress(Bundle.MSG_SearchingAuditReport());
try (ApplicationDependencyManagementClient admClient
= new ApplicationDependencyManagementClient(OCIManager.getDefault().getConfigProvider())) {
ListVulnerabilityAuditsRequest request = ListVulnerabilityAuditsRequest
.builder()
.compartmentId(compartmentId)
.knowledgeBaseId(knowledgeBaseId)
.lifecycleState(LifecycleState.Active)
.sortBy(ListVulnerabilityAuditsRequest.SortBy.TimeCreated)
.sortOrder(SortOrder.Desc).build();
ListVulnerabilityAuditsResponse response = admClient.listVulnerabilityAudits(request);
if (!response.getVulnerabilityAuditCollection().getItems().isEmpty()) {
VulnerabilityAuditSummary summary = response.getVulnerabilityAuditCollection().getItems().get(0);
progressHandle.progress(Bundle.MSG_AuditCollectDependencies());
dr = ProjectDependencies.findDependencies(project, ProjectDependencies.newQuery(Scopes.RUNTIME));
convert(dr.getRoot(), new HashMap<>(), result);
cacheItem = fetchVulnerabilityItems(project, admClient, dr, summary, projectDisplayName);
savedAudit = new VulnerabilityReport(cacheItem.getAudit(), cacheItem.getVulnerabilities());
}
} catch (BmcException ex) {
LOG.log(Level.FINE, "Unable to list newest audit for knowledgebase {0}, compartment {1}", new Object[] {
knowledgeBaseId, compartmentId
});
}
} catch (BmcException ex) {
LOG.log(Level.FINE, "Unable to list newest audit for knowledgebase {0}, compartment {1}", new Object[] {
knowledgeBaseId, compartmentId
});
}
}

if (savedAudit == null && (runIfNoReport || forceAudit)) {
if (savedAudit == null && (auditOptions.isRunIfNotExists() || auditOptions.isForceAuditExecution())) {
if (remoteCall.compareAndSet(false, true)) {
progressHandle.start();
}
Expand All @@ -462,7 +469,7 @@ private String doFindVulnerability(Project project, String compartmentId, String
.builder()
.compartmentId(compartmentId)
.knowledgeBaseId(knowledgeBaseId)
.displayName(projectDisplayName.replaceAll("[^A-Za-z0-9-_]", "_")) // remove offending characters
.displayName(auditOptions.getAuditName().replaceAll("[^A-Za-z0-9-_]", "_")) // remove offending characters
.buildType(VulnerabilityAudit.BuildType.Maven)
.configuration(auditConfiguration)
.applicationDependencies(result)
Expand All @@ -483,7 +490,12 @@ private String doFindVulnerability(Project project, String compartmentId, String
} finally {
progressHandle.finish();
}
} else if (savedAudit != null) {
} else if (savedAudit != null && cacheItem == null) {
if (dr == null) {
progressHandle.progress(Bundle.MSG_AuditCollectDependencies());
dr = ProjectDependencies.findDependencies(project, ProjectDependencies.newQuery(Scopes.RUNTIME));
convert(dr.getRoot(), new HashMap<>(), result);
}
cacheItem = new CacheItem(project, dr, savedAudit);
}

Expand All @@ -506,7 +518,7 @@ private String doFindVulnerability(Project project, String compartmentId, String
}
if (auditDone) {
DialogDisplayer.getDefault().notifyLater(
new NotifyDescriptor.Message(message));
new NotifyDescriptor.Message(message, cacheItem.getAudit().getIsSuccess() ? NotifyDescriptor.INFORMATION_MESSAGE : NotifyDescriptor.ERROR_MESSAGE));
}
Diagnostic.ReporterControl reporter = Diagnostic.findReporterControl(Lookup.getDefault(), project.getProjectDirectory());
reporter.diagnosticChanged(problematicFiles, null);
Expand Down
1 change: 0 additions & 1 deletion extide/gradle.dists/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# specific language governing permissions and limitations
# under the License.

is.eager=true
javac.source=1.8
javac.compilerargs=-Xlint -Xlint:-serial

Expand Down
1 change: 0 additions & 1 deletion extide/gradle.editor/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# specific language governing permissions and limitations
# under the License.

is.eager=true
javac.source=1.8
javac.compilerargs=-Xlint -Xlint:-serial

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,18 @@ public NbProjectInfo buildAll() {
runAndRegisterPerf(model, "dependencies", this::detectDependencies);
runAndRegisterPerf(model, "artifacts", this::detectArtifacts);
detectDistributions(model);
runAndRegisterPerf(model, "detectExtensions", this::detectExtensions);
runAndRegisterPerf(model, "detectPlugins2", this::detectAdditionalPlugins);
runAndRegisterPerf(model, "taskDependencies", this::detectTaskDependencies);

// introspection is only allowed for gradle 7.4 and above.
// TODO: investigate if some of the instrospection could be done for earlier Gradles.
sinceGradle("7.0", () -> {
runAndRegisterPerf(model, "detectExtensions", this::detectExtensions);
});
sinceGradle("7.0", () -> {
runAndRegisterPerf(model, "detectPlugins2", this::detectAdditionalPlugins);
});
sinceGradle("7.0", () -> {
runAndRegisterPerf(model, "taskDependencies", this::detectTaskDependencies);
});
runAndRegisterPerf(model, "taskProperties", this::detectTaskProperties);
runAndRegisterPerf(model, "artifacts", this::detectConfigurationArtifacts);
storeGlobalTypes(model);
Expand Down Expand Up @@ -351,6 +360,10 @@ private void detectConfigurationArtifacts(NbProjectInfoModel model) {
model.getInfo().put("configurationArtifacts", data); // NOI18N
}

/**
* Relies on PluginManagerInternal.findPluginIdForClass (gradle 7.1) and PluginRegistry.findPluginForClass (gradle 7.0)
* @param model
*/
private void detectAdditionalPlugins(NbProjectInfoModel model) {
final PluginManagerInternal pmi;
PluginRegistry reg;
Expand Down Expand Up @@ -854,6 +867,7 @@ private void detectProjectMetadata(NbProjectInfoModel model) {
model.getInfo().put("project_rootDir", project.getRootDir());
model.getInfo().put("gradle_user_home", project.getGradle().getGradleUserHomeDir());
model.getInfo().put("gradle_home", project.getGradle().getGradleHomeDir());
model.getInfo().put("gradle_version", project.getGradle().getGradleVersion());

Set<Configuration> visibleConfigurations = configurationsToSave();
model.getInfo().put("configurations", visibleConfigurations.stream().map(conf->conf.getName()).collect(Collectors.toCollection(HashSet::new )));
Expand Down
Loading

0 comments on commit 0ec6d03

Please sign in to comment.