sdedic commented on a change in pull request #2731: URL: https://github.com/apache/netbeans/pull/2731#discussion_r572716710
########## File path: ide/extexecution.base/src/org/netbeans/api/extexecution/base/ExplicitProcessParameters.java ########## @@ -0,0 +1,444 @@ +/* + * 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.api.extexecution.base; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.api.annotations.common.NullAllowed; +import org.openide.util.Lookup; + +/** + * Allows to augment or replace process parameters for a single execution action. + * The class is intended to be used by launchers which build parameters based on some + * persistent configuration (project, workspace) to allow additions, or replacements + * for a single execution only. + * <p> + * It is <b>strongly recommended</b> for any feature that performs execution of a process to support {@link ExplicitProcessParameters}, + * from a contextual {@link Lookup}, or at worst from {@link Lookup#getDefault()}. It will allow for future customizations and + * automation of the feature, enhancing the process launch for various environments, technologies etc. + * <p> + * <i>Note:</i> please refer also to {@code StartupExtender} API in the {@code extexecution} module, which contributes globally + * to priority arguments. + * <p> + * Two groups of parameters are recognized: {@link #getPriorityArguments()}, which should be passed + * first to the process (i.e. launcher parameters) and {@link #getArguments()} that represent the ordinary + * process arguments. + * <p> + * If the object is marked as {@link #isArgReplacement()}, the launcher implementor SHOULD replace all + * default or configured parameters with contents of this instruction. Both arguments and priorityArguments can have value {@code null}, which means "undefined": + * in that case, the relevant group of configured parameters should not be affected. + * <p> + * Since these parameters are passed <b>externally<b>, there's an utility method, {@link #buildExplicitParameters(org.openide.util.Lookup)} + * that builds the explicit parameter instruction based on {@link Lookup} contents. The parameters are + * merged in the order of the {@link Builder#withRank configured rank} and appearance (in the sort priority order). + * The default rank is {@code 0}, which allows both append or prepend parameters. If an item's + * {@link ExplicitProcessParameters#isArgReplacement()} is true, all arguments collected so far are discarded. + * <p> + * If the combining algorithm is acceptable for the caller's purpose, the following pattern may be used to build the final + * command line: + * <code><pre> + * ExplicitProcessParameters contextParams = ExplicitProcessParameters.buildExplicitParameters(runContext); + * ExplicitProcessParameters combined = ExplicitProcessParameters.builder(). + * priorityArgs(extraArgs). + * args(args). + * combine(contextParams).build(); + * </pre></code> + * This example will combine some args and extra args from project, or configuration with arguments passed from the + * {@code runContext} Lookup. + * @author sdedic + * @since 1.16 + */ +public final class ExplicitProcessParameters { + final int rank; + private final List<String> priorityArguments; + private final List<String> arguments; + private final boolean appendArgs; + private final boolean appendPriorityArgs; + + private ExplicitProcessParameters(int rank, List<String> priorityArguments, + List<String> arguments, boolean appendArgs, boolean appendPriorityArgs) { + this.rank = rank; + this.priorityArguments = priorityArguments == null ? null : Collections.unmodifiableList(priorityArguments); + this.arguments = arguments == null ? null : Collections.unmodifiableList(arguments); + this.appendArgs = appendArgs; + this.appendPriorityArgs = appendPriorityArgs; + } + + private static final ExplicitProcessParameters EMPTY = new ExplicitProcessParameters(0, null, null, true, true); + + /** + * Returns an empty instance of parameters that has no effect. DO NOT check for emptiness by + * equality or reference using the instance; use {@link #isEmpty()}. + * @return empty instance. + */ + public static ExplicitProcessParameters makeEmpty() { Review comment: Addressed in 600178d5af ---------------------------------------------------------------- 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. 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
