sdedic commented on code in PR #4043: URL: https://github.com/apache/netbeans/pull/4043#discussion_r861725975
########## extide/gradle/src/org/netbeans/modules/gradle/problems/ChangeOrRemovePropertyResolver.java: ########## @@ -0,0 +1,181 @@ +/* + * 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.problems; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Future; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.netbeans.api.project.Project; +import org.netbeans.modules.gradle.NbGradleProjectImpl; +import org.netbeans.modules.gradle.api.NbGradleProject; +import org.netbeans.modules.gradle.spi.GradleFiles; +import org.netbeans.spi.project.ui.ProjectProblemResolver; +import org.netbeans.spi.project.ui.ProjectProblemsProvider; +import org.netbeans.spi.project.ui.ProjectProblemsProvider.Result; +import org.openide.util.EditableProperties; +import org.openide.util.NbBundle; +import org.openide.util.RequestProcessor; + +/** + * Adds, modifies or removes proxy properties from gradle's settings file. If found in some of the existing files, the + * Resolver modifies that property file. If the properties are nowehere to be found (and are necessary), the Resolver + * adds them to the user properties file ({@code ~/.gradle/gradle.properties}). + * + * @author sdedic + */ +public class ChangeOrRemovePropertyResolver implements ProjectProblemResolver { + private static final Logger LOG = Logger.getLogger(ChangeOrRemovePropertyResolver.class.getName()); + private static final RequestProcessor EDIT_RP = new RequestProcessor(ChangeOrRemovePropertyResolver.class); + + private final Project project; + private final String proxyHost; + private final PropertiesEditor editor; + private final int proxyPort; + private final CompletableFuture<ProjectProblemsProvider.Result> future = new CompletableFuture<>(); + + public ChangeOrRemovePropertyResolver(Project project, PropertiesEditor editor, String proxyHost, int proxyPort) { + this.project = project; + this.proxyHost = proxyHost; + this.proxyPort = proxyPort; + this.editor = editor; + } + + @Override + public Future<ProjectProblemsProvider.Result> resolve() { + EDIT_RP.post(() -> run()); + return future; + } + + @NbBundle.Messages({ + "# {0} - properties file name", + "# {1} - reported error message", + "Error_UpdatePropertiesError=Error updating properties file {0}: {1}", + "Error_ProxySettingNotFound=Proxy settings not found.", + "# {0} - properties file name", + "Error_LoadingUserProperties=Could not load user properties file ({0}).", + "ReasonProxyChanged=Gradle proxies have changed" + }) + public void run() { + boolean reload = doRun(); + if (reload) { + NbGradleProject gp = NbGradleProject.get(project); + gp.toQuality(Bundle.ReasonProxyChanged(), NbGradleProject.Quality.FULL, true); + } + } + + boolean doRun() { + GradleFiles gf = ((NbGradleProjectImpl) project).getGradleFiles(); Review Comment: Didn't place them into Lookup, but made available from `NbGradleProject`, see ee74e45 (also removes the unused var). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- 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
