mbien commented on code in PR #9736:
URL: https://github.com/apache/netbeans/pull/9736#discussion_r4727211284


##########
ide/generic.project/src/org/netbeans/modules/generic/project/GpAuxiliaryProperties.java:
##########
@@ -0,0 +1,346 @@
+/*
+ * 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.generic.project;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.netbeans.api.project.ProjectManager;
+import org.netbeans.api.project.ProjectUtils;
+import org.netbeans.spi.project.AuxiliaryConfiguration;
+import org.netbeans.spi.project.AuxiliaryProperties;
+import org.openide.filesystems.FileObject;
+import org.openide.util.EditableProperties;
+import org.openide.util.Mutex;
+import org.openide.util.NbBundle.Messages;
+import org.openide.xml.XMLUtil;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * The {@link AuxiliaryProperties} of a generic project.
+ *
+ * <p>Shared and private settings are stored according to the project's
+ * nature:
+ *
+ * <ul>
+ * <li>the <em>shared</em> settings of a project with the marker file
+ *     live in the marker file ({@link GenericProject#MARKER_FILE}),
+ *     which <em>is</em> the data file, so the data is versioned along
+ *     with the project;</li>
+ * <li>everything else — the <em>shared</em> settings of a local
+ *     (marker-less) project and, always, the <em>private</em>
+ *     settings — lives in the project's <em>private</em> auxiliary
+ *     configuration (a {@code FileObject} attribute on the project
+ *     directory, see
+ *     {@link AuxiliaryConfiguration#putConfigurationFragment}): the
+ *     same mechanism and storage (the user's {@code var/attributes.xml}
+ *     in the running IDE) as the per-project data of the other
+ *     project types, and nothing is ever written into the working
+ *     tree of a local project.</li>
+ * </ul>
+ *
+ * <p>The storage location of the shared data is re-evaluated on every
+ * access: if the marker file is created or deleted while the project
+ * is open, the shared data is moved to the new location on the next
+ * access; if it is deleted while no instance of the project is open,
+ * the shared data is lost with it. Private data is not affected by
+ * the marker state.
+ */
+final class GpAuxiliaryProperties implements AuxiliaryProperties {
+
+    private static final Logger LOG = 
Logger.getLogger(GpAuxiliaryProperties.class.getName());
+
+    /**
+     * Namespace of the auxiliary configuration fragment holding the
+     * auxiliary data of a local project (the shared settings) and,
+     * for every project, the private settings.
+     */
+    static final String NAMESPACE = 
"http://www.netbeans.org/ns/generic-project/1";; // NOI18N
+
+    /**
+     * Name of the root element of the auxiliary configuration
+     * fragment, one {@code <property name=... value=.../>} child per
+     * stored setting.
+     */
+    static final String ROOT = "properties"; // NOI18N
+
+    private static final String EL_PROPERTY = "property"; // NOI18N
+    private static final String ATTR_NAME = "name"; // NOI18N
+    private static final String ATTR_VALUE = "value"; // NOI18N
+
+    private static final String SHARED_PREFIX = "shared."; // NOI18N
+    private static final String PRIVATE_PREFIX = "private."; // NOI18N
+
+    private final GenericProject prj;
+    private final AuxiliaryConfiguration auxConfig;
+
+    // marker projects: EditableProperties keeps files stable, new properties 
are appended
+    private final EditableProperties markerData = new 
EditableProperties(false);
+
+    // The data stored in the auxiliary configuration fragment:
+    // always the private settings, plus - for a local (marker-less)
+    // project the shared settings as well, so each setting lives in exactly 
one
+    // of the two storage locations (here, or in the marker file) at any time.
+    // Kept sorted for stable output
+    private final TreeMap<String, String> fragmentData = new TreeMap<>();
+
+    private boolean loaded;
+    private boolean hasMarkerAtLoad;
+
+    GpAuxiliaryProperties(GenericProject prj) {
+        this.prj = prj;
+        this.auxConfig = ProjectUtils.getAuxiliaryConfiguration(prj);
+    }
+
+    /**
+     * The name of the shared auxiliary data file, brandable via the
+     * module bundle, defaults to {@code .nbgp.properties} (the
+     * {@code .properties} suffix, so that tools recognize the file
+     * type): identical to the name of the marker file
+     * ({@link GenericProject#MARKER_FILE}).
+     */
+    @Messages({
+        "LBL_aux_data_file_name=.nbgp.properties",
+    })
+    static String dataFileName() {
+        return Bundle.LBL_aux_data_file_name();
+    }

Review Comment:
   ok, will do on next pass



-- 
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

Reply via email to