sdedic commented on code in PR #7655: URL: https://github.com/apache/netbeans/pull/7655#discussion_r1718962055
########## java/maven/src/org/netbeans/modules/maven/queries/MavenPrimingReloadImplementation.java: ########## @@ -0,0 +1,251 @@ +/* + * 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.maven.queries; + +import java.lang.ref.Reference; +import java.lang.ref.WeakReference; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.atomic.AtomicReference; +import java.util.function.Consumer; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.project.MavenProject; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectUtils; +import org.netbeans.modules.maven.api.NbMavenProject; +import org.netbeans.modules.maven.modelcache.MavenProjectCache; +import org.netbeans.modules.project.dependency.ProjectOperationException; +import org.netbeans.modules.project.dependency.ProjectReload; +import org.netbeans.modules.project.dependency.spi.ProjectReloadImplementation; +import org.netbeans.spi.project.ActionProgress; +import org.netbeans.spi.project.ActionProvider; +import org.netbeans.spi.project.LookupProvider; +import org.netbeans.spi.project.ProjectServiceProvider; +import org.openide.util.Cancellable; +import org.openide.util.Lookup; +import org.openide.util.NbBundle; +import org.openide.util.lookup.Lookups; + +/** + * This class steps in, if the requested quality is higher than LOAD and the + * MavenProject loaded by the base implementation contains fake artifacts. + If RESOLVED is requested, the implementation runs a priming build and then restarts the reload + * operation, so that base maven impl will re-read the project. + * To avoid reloading loops, the faked artifacts are stored between reloads. If the reported fake artifacts + * are all already known - that is,they were not resolved by the priming build, the implementation ends + * with an error, the project is not correctable. + * @author sdedic + */ +@ProjectServiceProvider(service = ProjectReloadImplementation.class, projectTypes = { + @LookupProvider.Registration.ProjectType(id = NbMavenProject.TYPE, position = 11000) + +}) +public class MavenPrimingReloadImplementation implements ProjectReloadImplementation { + /** + * Names of artifacts that were faked. It's not productive to run a priming build to fix this known set of artifacts, + * unless "force" is in effect - they are unlikely to be retrieved, since they already failed. + */ + // @GuardedBy(this) + private Set<String> fakeArtifactNames = new HashSet<>(); + + + private Reference<ProjectStateData> lastData = new WeakReference<>(null); + + static class LC { + boolean firstRun = true; + } + + // just pretend MavenProject is not there, do not make conflicts + static class H { + final MavenProject p; + + public H(MavenProject p) { + this.p = p; + } + } Review Comment: `H` as Holder ... but right I should not be so lazy with nonlocal names. -- 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
