You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2021/10/22 11:18:05 UTC
[GitHub] [netbeans] sdedic opened a new pull request #3262: [NETBEANS-5847] Maven project template uses template for project structure.
sdedic opened a new pull request #3262:
URL: https://github.com/apache/netbeans/pull/3262
The PR improves how the 'native project templates' for maven are handled.
The native templates, created by NB code (instead of `archetype:create` run) were generated entirely. The Layer template was just a stub whose only function was to invoke the wizard. The `api.templates` API lacks the ability to construct a subtree populated with files; this PR fixes that - the default processing will copy out folder-based template. Naturally if a specific `CreateFromTemplateHandler` chooses a different implementation, it will take precedence. As part of the changes, I've introduced possibility to interpolate template parameters in filenames - see the provided test resources.
There are a few helper methods for CreateFromTemplateHandler implementors, which do stuff whose details are IMHO better not to export from the `api.templates` module or have the CFTH implementors replicate.
There's also [NETBEANS-5847](https://issues.apache.org/jira/browse/NETBEANS-5847) that notes that the maven application Wizard cannot be run from a headless mode (provided all necessary parameters are in). This PR moves much of WizardIterator's logic into `CreateFromTemplateHandler` implementation, and the Wizard just populates the `FileBuilder` parameter map.
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] sdedic commented on a change in pull request #3262: [NETBEANS-5847] Maven project template uses template for project structure.
Posted by GitBox <gi...@apache.org>.
sdedic commented on a change in pull request #3262:
URL: https://github.com/apache/netbeans/pull/3262#discussion_r742746705
##########
File path: platform/openide.filesystems/src/org/openide/filesystems/FileUtil.java
##########
@@ -937,6 +938,23 @@ public static FileObject toFileObject(File file) {
*/
public static void copyAttributes(FileObject source, FileObject dest)
throws IOException {
+ copyAttributes(source, dest, null);
+ }
+
+ /** Copies attributes from one file to another.
+ * Note: several special attributes will not be copied, as they should
+ * semantically be transient. These include attributes used by the
Review comment:
Good to mention it now. It requires a semantic change in javadoc which would be hard to do after introduction; thanks.
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] sdedic commented on a change in pull request #3262: [NETBEANS-5847] Maven project template uses template for project structure.
Posted by GitBox <gi...@apache.org>.
sdedic commented on a change in pull request #3262:
URL: https://github.com/apache/netbeans/pull/3262#discussion_r740405203
##########
File path: java/maven/src/org/netbeans/modules/maven/layer.xml
##########
@@ -33,6 +33,22 @@
<folder name="Maven2">
<attr name="displayName" bundlevalue="org.netbeans.modules.maven.newproject.Bundle#Templates/Project/Maven2"/>
<attr name="position" intvalue="100"/>
+
+ <!-- Simple Java project structure -->
+ <folder name="JavaApplication2">
+ <folder name="src">
+ <folder name="main">
+ <folder name="java">
+ <folder name="${packagePath}">
+ <file name="${mainClassName}.java" url="nbresloc:/org/netbeans/modules/maven/resources/App.java.template">
Review comment:
well, respecting the ScriptEngine could be helpful in some more complicated cases, asi the expression can reference context objects for example; but in simple ones like this ...
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] sdedic commented on a change in pull request #3262: [NETBEANS-5847] Maven project template uses template for project structure.
Posted by GitBox <gi...@apache.org>.
sdedic commented on a change in pull request #3262:
URL: https://github.com/apache/netbeans/pull/3262#discussion_r740140643
##########
File path: java/java.lsp.server/nbcode/integration/src/org/netbeans/modules/nbcode/integration/layer.xml
##########
@@ -39,7 +39,7 @@
</folder>
<file name="Import_hidden"/>
<folder name="Maven2">
- <file name="JavaApplication_hidden"/>
+ <file name="maven.archetype_hidden"/>
Review comment:
Hm. I thought that `maven.archetype` was a way how to allow LSP to create a project. This is now replaced by the `JavaApplication2` template.
Re. rename: that's a question how to handle such situation: the original template is a **file**. I need to provide a folder structure, so:
* the template can be no longer a **file**, but must turn to a folder. Existing installations or extensions that may have contributed to that file in the ConfigFS would break (impossible to layer-merge file + folder).
* a new template will be introduced, which I did (JavaApplication2).
* a "contents here" attribute will be introduced. So the project itself can continue as **file** template, but its contents will be elsewhere. I even made code support for it, but at the end decided not to use it in the template.
Please share your thoughts.
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] sdedic merged pull request #3262: [NETBEANS-5847] Maven project template uses template for project structure.
Posted by GitBox <gi...@apache.org>.
sdedic merged pull request #3262:
URL: https://github.com/apache/netbeans/pull/3262
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] sdedic commented on a change in pull request #3262: [NETBEANS-5847] Maven project template uses template for project structure.
Posted by GitBox <gi...@apache.org>.
sdedic commented on a change in pull request #3262:
URL: https://github.com/apache/netbeans/pull/3262#discussion_r742776913
##########
File path: platform/openide.filesystems/src/org/openide/filesystems/FileUtil.java
##########
@@ -937,6 +938,23 @@ public static FileObject toFileObject(File file) {
*/
public static void copyAttributes(FileObject source, FileObject dest)
throws IOException {
+ copyAttributes(source, dest, null);
+ }
+
+ /** Copies attributes from one file to another.
+ * Note: several special attributes will not be copied, as they should
+ * semantically be transient. These include attributes used by the
Review comment:
Addressed in ffc97b6
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] sdedic commented on a change in pull request #3262: [NETBEANS-5847] Maven project template uses template for project structure.
Posted by GitBox <gi...@apache.org>.
sdedic commented on a change in pull request #3262:
URL: https://github.com/apache/netbeans/pull/3262#discussion_r740405203
##########
File path: java/maven/src/org/netbeans/modules/maven/layer.xml
##########
@@ -33,6 +33,22 @@
<folder name="Maven2">
<attr name="displayName" bundlevalue="org.netbeans.modules.maven.newproject.Bundle#Templates/Project/Maven2"/>
<attr name="position" intvalue="100"/>
+
+ <!-- Simple Java project structure -->
+ <folder name="JavaApplication2">
+ <folder name="src">
+ <folder name="main">
+ <folder name="java">
+ <folder name="${packagePath}">
+ <file name="${mainClassName}.java" url="nbresloc:/org/netbeans/modules/maven/resources/App.java.template">
Review comment:
well, respecting the ScriptEngine could be helpful in some more complicated cases, asi the expression can reference context objects for example; but in simple ones like this ...
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] JaroslavTulach commented on a change in pull request #3262: [NETBEANS-5847] Maven project template uses template for project structure.
Posted by GitBox <gi...@apache.org>.
JaroslavTulach commented on a change in pull request #3262:
URL: https://github.com/apache/netbeans/pull/3262#discussion_r740177182
##########
File path: platform/api.templates/src/org/netbeans/api/templates/CreateFromTemplateHandler.java
##########
@@ -59,4 +64,171 @@
CreateDescriptor desc
) throws IOException;
+ /**
+ * Replaces ${param} tokens in a String. The parameter reference has syntax "${" paramName [":" defaultValue ] "}".
+ * Parameters are replaced recursively. "${" can be escaped by \, so "\${" will not act as parameter reference start.
+ * @param expression string template
+ * @param parameters parameter values
+ * @return evaluated string.
+ * @since 1.23
+ */
+ public static String mapParameters(String expression, Map<String, ?> parameters) {
Review comment:
I still like the [use of the templating engine itself](https://github.com/apache/netbeans/pull/3262#discussion_r740114513) more than our own substitution mechanism...
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] JaroslavTulach commented on a change in pull request #3262: [NETBEANS-5847] Maven project template uses template for project structure.
Posted by GitBox <gi...@apache.org>.
JaroslavTulach commented on a change in pull request #3262:
URL: https://github.com/apache/netbeans/pull/3262#discussion_r741050076
##########
File path: java/maven/src/org/netbeans/modules/maven/layer.xml
##########
@@ -33,6 +33,22 @@
<folder name="Maven2">
<attr name="displayName" bundlevalue="org.netbeans.modules.maven.newproject.Bundle#Templates/Project/Maven2"/>
<attr name="position" intvalue="100"/>
+
+ <!-- Simple Java project structure -->
+ <folder name="JavaApplication2">
+ <folder name="src">
+ <folder name="main">
+ <folder name="java">
+ <folder name="${packagePath}">
+ <file name="${mainClassName}.java" url="nbresloc:/org/netbeans/modules/maven/resources/App.java.template">
Review comment:
Yes, it is an overkill.
On the other hand, the templating engine must be around and it provides familiar syntax. E.g. one would be using the same syntax for the file name as well as for the file content.
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] JaroslavTulach commented on a change in pull request #3262: [NETBEANS-5847] Maven project template uses template for project structure.
Posted by GitBox <gi...@apache.org>.
JaroslavTulach commented on a change in pull request #3262:
URL: https://github.com/apache/netbeans/pull/3262#discussion_r740175427
##########
File path: java/java.lsp.server/nbcode/integration/src/org/netbeans/modules/nbcode/integration/layer.xml
##########
@@ -39,7 +39,7 @@
</folder>
<file name="Import_hidden"/>
<folder name="Maven2">
- <file name="JavaApplication_hidden"/>
+ <file name="maven.archetype_hidden"/>
Review comment:
Isn't the `maven.archetype` registered only in `java/java.lsp.server/nbcode` suite? If so, it doesn't have to be hidden.
Changing `file` to `folder` has some drawback, your solution is fine. Consider calling the folder `JavaApp` to avoid the `2`.
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] sdedic commented on a change in pull request #3262: [NETBEANS-5847] Maven project template uses template for project structure.
Posted by GitBox <gi...@apache.org>.
sdedic commented on a change in pull request #3262:
URL: https://github.com/apache/netbeans/pull/3262#discussion_r740147564
##########
File path: platform/api.templates/src/org/netbeans/api/templates/CreateFromTemplateHandler.java
##########
@@ -59,4 +64,171 @@
CreateDescriptor desc
) throws IOException;
+ /**
+ * Replaces ${param} tokens in a String. The parameter reference has syntax "${" paramName [":" defaultValue ] "}".
+ * Parameters are replaced recursively. "${" can be escaped by \, so "\${" will not act as parameter reference start.
+ * @param expression string template
+ * @param parameters parameter values
+ * @return evaluated string.
+ * @since 1.23
+ */
+ public static String mapParameters(String expression, Map<String, ?> parameters) {
Review comment:
Reuse: I don't think its's possible 'as is' as I'd like to keep the default - which gives some troubles if the default itself contains delimiters (see this impl). Also the replacement in MapFormat is not recursive - that could be also solved by the caller by calling MapFormat repeatedly, but could be added.
If you think it's worth moving to MapFormat, I'll try; but I'd like to retain the `${...}` syntax, which is consistent with Ant, Freemarker or other interpolation engines.
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] sdedic commented on a change in pull request #3262: [NETBEANS-5847] Maven project template uses template for project structure.
Posted by GitBox <gi...@apache.org>.
sdedic commented on a change in pull request #3262:
URL: https://github.com/apache/netbeans/pull/3262#discussion_r740143241
##########
File path: platform/api.templates/src/org/netbeans/api/templates/CreateFromTemplateHandler.java
##########
@@ -59,4 +64,171 @@
CreateDescriptor desc
) throws IOException;
+ /**
+ * Replaces ${param} tokens in a String. The parameter reference has syntax "${" paramName [":" defaultValue ] "}".
+ * Parameters are replaced recursively. "${" can be escaped by \, so "\${" will not act as parameter reference start.
+ * @param expression string template
+ * @param parameters parameter values
+ * @return evaluated string.
+ * @since 1.23
+ */
+ public static String mapParameters(String expression, Map<String, ?> parameters) {
+ int start = 0;
+ int pos = 0;
+ StringBuilder sb = null;
+
+ while ((pos = expression.indexOf("${", pos)) != -1) { // NOI18N
+ if (pos > 0 && expression.charAt(pos - 1) == '\\') { // NOI18N
+ pos += 2;
+ continue;
+ }
+ int endPos = pos + 2;
+ int state = 0;
+ int nested = 0;
+ A: while (endPos < expression.length()) {
+ char c = expression.charAt(endPos);
+ if (state == 1) {
+ state = 0;
+ endPos++;
+ continue;
+ }
+ switch (c) {
+ case '\\': // NOI18N
+ state = 1;
+ break;
+ case '$': // NOI18N
+ state = 2;
+ break;
+ case '{': // NOI18N
+ if (state == 2) {
+ state = 0;
+ nested++;
+ }
+ break;
+ case '}': // NOI18N
+ if (state == 0) {
+ if (nested-- == 0) {
+ break A;
+ }
+ }
+ break;
+ }
+ endPos++;
+ }
+ if (endPos >= expression.length()) {
+ pos += 2;
+ continue;
+ }
+ String token = expression.substring(pos + 2, endPos);
+ String defValue = null;
+
+ int colon = token.indexOf(':'); // NOI18N
+ if (colon != -1) {
+ defValue = token.substring(colon + 1);
+ token = token.substring(0, colon);
+ }
+
+ if (sb == null) {
+ sb = new StringBuilder();
+ }
+ Object v = parameters.get(token);
+ if (v == null) {
+ v = defValue;
+ }
+ if (v == null) {
+ pos += 2;
+ continue;
+ }
+ sb.append(expression.substring(start, pos)).append(v.toString());
+ start = endPos + 1;
+ pos = start;
+ }
+ if (sb == null) {
+ return expression;
+ }
+ if (start < expression.length()) {
+ sb.append(expression.substring(start));
+ }
+
+ return mapParameters(sb.toString(), parameters);
+ }
+
+ private static final String PROP_TEMPLATE = "template"; // NOI18N
+
+ /**
+ * Prefix for template-controlling attributes. Such attributes will not be copied
+ * during template instantiation.
+ */
+ private static final String ATTR_TEMPLATE_PREFIX = "template.";
+
+ /**
+ * Copies template attributes over to the created file. Copies over from the source (template) to the target (usually
+ * the produced file), except attributes that parametrize template creation. By default, attributes that are prefixed
+ * with {@code "template."} are not copied. As the operation is not atomic, the method should be called in a
+ * {@link org.openide.filesystems.FileSystem#runAtomicAction(org.openide.filesystems.FileSystem.AtomicAction)}.
+ * The {@code "template"} attribute is never copied.
+ *
+ * @param h the Handler responsible for file creation, usually the calling handler.
+ * @param from the original file
+ * @param to the target file
+ * @throws IOException if an I/O error occurs.
+ */
+ public static void copyAttributesFromTemplate(CreateFromTemplateHandler h, FileObject from, FileObject to) throws IOException {
+ // copy attributes; some attributes are filtered by FileSystems API already
+ FileUtil.copyAttributes(from, to);
+ // need to filter additional template-related attributes:
+ for (String a : Collections.list(to.getAttributes())) {
+ if ("javax.script.ScriptEngine".equals(a) // NOI18N
+ || a.startsWith(ATTR_TEMPLATE_PREFIX)) {
+ to.setAttribute(a, null);
+ }
+ }
+ // hack to overcome package-private modifier in setTemplate(fo, boolean)
+ to.setAttribute(PROP_TEMPLATE, null);
+ }
+
+
+ /**
+ * Copies the files or folders contained in the specified folder to the target. The original descriptor can be passed in,
+ * since it has Lookup, parameters etc set up. They will be passed on to individual created files. The `contentsParent` may
+ * be {@code null}, in which case the {@link CreateDescriptor#getTemplate()} folder will be used.
+ * @param origDescriptor original descriptor to get parameters / lookup from
+ * @param contentsParent template folder whose contents should be copied
+ * @param target target folder
+ * @return created files
+ * @throws IOException
+ * @since 1.23
+ */
+ protected static List<FileObject> defaultCopyContents(CreateDescriptor origDescriptor, FileObject contentsParent, FileObject target) throws IOException {
Review comment:
Yes, you can always do a trampoline from some subclass and made it public to whatever code you like. It was meant as a helper primarily for CreateFromTemplateHandler imlementations (with limited use elsewhere), but can be `public` as well.
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] JaroslavTulach commented on a change in pull request #3262: [NETBEANS-5847] Maven project template uses template for project structure.
Posted by GitBox <gi...@apache.org>.
JaroslavTulach commented on a change in pull request #3262:
URL: https://github.com/apache/netbeans/pull/3262#discussion_r742583135
##########
File path: ide/projectui/test/unit/src/org/netbeans/modules/project/ui/test-layer.xml
##########
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
+<filesystem>
+ <folder name="Templates">
+ <folder name="Test">
+ <folder name="FolderTemplate">
+ <folder name="${packagePath!"foo-bar"}">
+ <attr name="javax.script.ScriptEngine" stringvalue="freemarker"/>
+ <file name='${mainClassName!"App"}.java' url="nbres:/org/netbeans/modules/project/ui/AppTemplate.java.template">
Review comment:
It is not that bad!
##########
File path: platform/openide.filesystems/src/org/openide/filesystems/FileUtil.java
##########
@@ -937,6 +938,23 @@ public static FileObject toFileObject(File file) {
*/
public static void copyAttributes(FileObject source, FileObject dest)
throws IOException {
+ copyAttributes(source, dest, null);
+ }
+
+ /** Copies attributes from one file to another.
+ * Note: several special attributes will not be copied, as they should
+ * semantically be transient. These include attributes used by the
Review comment:
I suggest to define field or function to let people access:
```java
public static final BiFunction<String, Object, Object> DEFAULT_ATTR_TRANSFORMER;
```
then they can either:
* use it as the 3rd parameter to get behavior of the two args method
* delegate to it from own transformer as a last resort
* skip it by not delegating from own transformer
I never really liked the hard-coded list of attributes, but they are useful. Exposing them as `BiFunction` keeps the concept of important attributes on, but puts the full control into the hands of `attrTransformer` writer.
##########
File path: platform/api.templates/src/org/netbeans/api/templates/CreateFromTemplateHandler.java
##########
@@ -59,4 +63,169 @@
CreateDescriptor desc
) throws IOException;
+ /**
+ * Replaces ${param} tokens in a String. The parameter reference has syntax "${" paramName [":" defaultValue ] "}".
+ * Parameters are replaced recursively. "${" can be escaped by \, so "\${" will not act as parameter reference start.
+ * @param expression string template
+ * @param parameters parameter values
+ * @return evaluated string.
+ */
+ static String mapParameters(String expression, Map<String, ?> parameters) {
Review comment:
I was hoping this _in-house mapping_ can now be removed when we can use the Freemarker based one (with `'...'`) easily. But I can live with both variants. Up to you.
##########
File path: ide/projectui/test/unit/src/org/netbeans/modules/project/ui/test-layer.xml
##########
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<!DOCTYPE filesystem PUBLIC "-//NetBeans//DTD Filesystem 1.2//EN" "http://www.netbeans.org/dtds/filesystem-1_2.dtd">
+<filesystem>
+ <folder name="Templates">
+ <folder name="Test">
+ <folder name="FolderTemplate">
+ <folder name="${packagePath!"foo-bar"}">
Review comment:
Ugly. The variant with `'.."..."..'` is nicer.
##########
File path: java/maven/src/org/netbeans/modules/maven/layer.xml
##########
@@ -35,7 +35,7 @@
<attr name="position" intvalue="100"/>
<!-- Simple Java project structure -->
- <folder name="JavaApplication2">
+ <folder name="JavaApp">
Review comment:
OK.
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] JaroslavTulach commented on a change in pull request #3262: [NETBEANS-5847] Maven project template uses template for project structure.
Posted by GitBox <gi...@apache.org>.
JaroslavTulach commented on a change in pull request #3262:
URL: https://github.com/apache/netbeans/pull/3262#discussion_r741050076
##########
File path: java/maven/src/org/netbeans/modules/maven/layer.xml
##########
@@ -33,6 +33,22 @@
<folder name="Maven2">
<attr name="displayName" bundlevalue="org.netbeans.modules.maven.newproject.Bundle#Templates/Project/Maven2"/>
<attr name="position" intvalue="100"/>
+
+ <!-- Simple Java project structure -->
+ <folder name="JavaApplication2">
+ <folder name="src">
+ <folder name="main">
+ <folder name="java">
+ <folder name="${packagePath}">
+ <file name="${mainClassName}.java" url="nbresloc:/org/netbeans/modules/maven/resources/App.java.template">
Review comment:
Yes, it is an overkill.
On the other hand, the templating engine must be around and it provides familiar syntax. E.g. one would be using the same syntax for the file name as well as for the file content.
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] JaroslavTulach commented on a change in pull request #3262: [NETBEANS-5847] Maven project template uses template for project structure.
Posted by GitBox <gi...@apache.org>.
JaroslavTulach commented on a change in pull request #3262:
URL: https://github.com/apache/netbeans/pull/3262#discussion_r740111437
##########
File path: java/java.lsp.server/nbcode/integration/src/org/netbeans/modules/nbcode/integration/layer.xml
##########
@@ -39,7 +39,7 @@
</folder>
<file name="Import_hidden"/>
<folder name="Maven2">
- <file name="JavaApplication_hidden"/>
+ <file name="maven.archetype_hidden"/>
Review comment:
Why was existing `JavaApplication` file renamed? Or where the `maven.archetype` file/folder comes from.
##########
File path: java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LspTemplateUI.java
##########
@@ -138,6 +138,7 @@ private LspTemplateUI() {
final DataFolder target = targetAndName.first();
final String name = targetAndName.second();
Map<String,String> prjParams = new HashMap<>();
+ // PENDING: this is a mavenism;
prjParams.put("version", "1.0-SNAPSHOT"); // NOI18N
Review comment:
Please modify existing templates (as exposed by VSNetBeans) to use `1.0-SNAPSHOT` as default and remove this attribute.
##########
File path: java/java.lsp.server/nbcode/integration/src/org/netbeans/modules/nbcode/integration/package-info.java
##########
@@ -21,14 +21,6 @@
@TemplateRegistration(folder = "Classes/Code", position = 100, content = "resources/GeneratedMethodBody.template", scriptEngine = "freemarker", displayName = "#GeneratedMethodBody", category = "java-code-snippet"),
@TemplateRegistration(folder = "Classes/Code", position = 200, content = "resources/OverriddenMethodBody.template", scriptEngine = "freemarker", displayName = "#OverriddenMethodBody", category = "java-code-snippet"),
@TemplateRegistration(folder = "Classes/Code", position = 300, content = "resources/LambdaBody.template", scriptEngine = "freemarker", displayName = "#LambdaBody", category = "java-code-snippet"),
- @TemplateRegistration(
Review comment:
Less differences between VSNetBeans and NetBeans is good.
##########
File path: java/maven/src/org/netbeans/modules/maven/newproject/TemplateUtils.java
##########
@@ -0,0 +1,268 @@
+/*
+ * 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.newproject;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.regex.Pattern;
+import org.netbeans.api.progress.ProgressHandle;
+import org.netbeans.api.project.Project;
+import org.netbeans.api.project.ProjectInformation;
+import org.netbeans.api.project.ProjectManager;
+import org.netbeans.api.templates.CreateDescriptor;
+import org.netbeans.modules.maven.api.archetype.ProjectInfo;
+import org.netbeans.spi.project.ActionProgress;
+import org.netbeans.spi.project.ActionProvider;
+import org.netbeans.spi.project.ui.support.CommonProjectActions;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.Lookup;
+import org.openide.util.NbBundle;
+import org.openide.util.lookup.Lookups;
+import org.openide.util.lookup.ProxyLookup;
+
+public final class TemplateUtils {
Review comment:
Can this class be package private?
##########
File path: platform/api.templates/src/org/netbeans/api/templates/FileBuilder.java
##########
@@ -109,6 +135,20 @@
public FileBuilder(@NonNull FileObject template, @NonNull FileObject target) {
descriptor = new CreateDescriptor(template, target);
}
+
+ /**
+ * Use specific Lookup for creation. This allows to pass in additional
+ * parameters or services. A GUI-aware caller may, for example, add
+ * a ProgressHandle or a project ActionProgress interface to the lookup,
Review comment:
OK.
##########
File path: platform/api.templates/src/org/netbeans/api/templates/CreateFromTemplateHandler.java
##########
@@ -59,4 +64,171 @@
CreateDescriptor desc
) throws IOException;
+ /**
+ * Replaces ${param} tokens in a String. The parameter reference has syntax "${" paramName [":" defaultValue ] "}".
+ * Parameters are replaced recursively. "${" can be escaped by \, so "\${" will not act as parameter reference start.
+ * @param expression string template
+ * @param parameters parameter values
+ * @return evaluated string.
+ * @since 1.23
+ */
+ public static String mapParameters(String expression, Map<String, ?> parameters) {
Review comment:
There is `org.openide.util.MapFormat` - if the suggestion to use `freemarker` isn't going to fly - wouldn't it be better to reuse the existing `MapFormat` or expand it?
##########
File path: platform/api.templates/src/org/netbeans/api/templates/CreateFromTemplateHandler.java
##########
@@ -59,4 +64,171 @@
CreateDescriptor desc
) throws IOException;
+ /**
+ * Replaces ${param} tokens in a String. The parameter reference has syntax "${" paramName [":" defaultValue ] "}".
+ * Parameters are replaced recursively. "${" can be escaped by \, so "\${" will not act as parameter reference start.
+ * @param expression string template
+ * @param parameters parameter values
+ * @return evaluated string.
+ * @since 1.23
+ */
+ public static String mapParameters(String expression, Map<String, ?> parameters) {
+ int start = 0;
+ int pos = 0;
+ StringBuilder sb = null;
+
+ while ((pos = expression.indexOf("${", pos)) != -1) { // NOI18N
+ if (pos > 0 && expression.charAt(pos - 1) == '\\') { // NOI18N
+ pos += 2;
+ continue;
+ }
+ int endPos = pos + 2;
+ int state = 0;
+ int nested = 0;
+ A: while (endPos < expression.length()) {
+ char c = expression.charAt(endPos);
+ if (state == 1) {
+ state = 0;
+ endPos++;
+ continue;
+ }
+ switch (c) {
+ case '\\': // NOI18N
+ state = 1;
+ break;
+ case '$': // NOI18N
+ state = 2;
+ break;
+ case '{': // NOI18N
+ if (state == 2) {
+ state = 0;
+ nested++;
+ }
+ break;
+ case '}': // NOI18N
+ if (state == 0) {
+ if (nested-- == 0) {
+ break A;
+ }
+ }
+ break;
+ }
+ endPos++;
+ }
+ if (endPos >= expression.length()) {
+ pos += 2;
+ continue;
+ }
+ String token = expression.substring(pos + 2, endPos);
+ String defValue = null;
+
+ int colon = token.indexOf(':'); // NOI18N
+ if (colon != -1) {
+ defValue = token.substring(colon + 1);
+ token = token.substring(0, colon);
+ }
+
+ if (sb == null) {
+ sb = new StringBuilder();
+ }
+ Object v = parameters.get(token);
+ if (v == null) {
+ v = defValue;
+ }
+ if (v == null) {
+ pos += 2;
+ continue;
+ }
+ sb.append(expression.substring(start, pos)).append(v.toString());
+ start = endPos + 1;
+ pos = start;
+ }
+ if (sb == null) {
+ return expression;
+ }
+ if (start < expression.length()) {
+ sb.append(expression.substring(start));
+ }
+
+ return mapParameters(sb.toString(), parameters);
+ }
+
+ private static final String PROP_TEMPLATE = "template"; // NOI18N
+
+ /**
+ * Prefix for template-controlling attributes. Such attributes will not be copied
+ * during template instantiation.
+ */
+ private static final String ATTR_TEMPLATE_PREFIX = "template.";
+
+ /**
+ * Copies template attributes over to the created file. Copies over from the source (template) to the target (usually
+ * the produced file), except attributes that parametrize template creation. By default, attributes that are prefixed
+ * with {@code "template."} are not copied. As the operation is not atomic, the method should be called in a
+ * {@link org.openide.filesystems.FileSystem#runAtomicAction(org.openide.filesystems.FileSystem.AtomicAction)}.
+ * The {@code "template"} attribute is never copied.
+ *
+ * @param h the Handler responsible for file creation, usually the calling handler.
+ * @param from the original file
+ * @param to the target file
+ * @throws IOException if an I/O error occurs.
+ */
+ public static void copyAttributesFromTemplate(CreateFromTemplateHandler h, FileObject from, FileObject to) throws IOException {
+ // copy attributes; some attributes are filtered by FileSystems API already
+ FileUtil.copyAttributes(from, to);
Review comment:
Consider expanding the `copyAttributes` method with a `Predicate<String> attributeName` rather than copying everything and then cleaning it up.
##########
File path: java/maven/test/unit/src/org/netbeans/modules/maven/newproject/simplewizard/SimpleWizardTemplateHandlerTest.java
##########
@@ -0,0 +1,174 @@
+/*
+ * 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.newproject.simplewizard;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Optional;
+import org.apache.maven.project.MavenProject;
+import org.netbeans.api.project.Project;
+import org.netbeans.api.project.ProjectManager;
+import org.netbeans.api.templates.FileBuilder;
+import org.netbeans.junit.NbTestCase;
+import org.netbeans.modules.maven.api.NbMavenProject;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+
+/**
+ *
+ * @author sdedic
+ */
+public class SimpleWizardTemplateHandlerTest extends NbTestCase {
+
+ public SimpleWizardTemplateHandlerTest(String name) {
+ super(name);
+ }
+
+ FileObject whereTo;
+
+ private FileBuilder createProject() throws IOException {
+ clearWorkDir();
+ whereTo = FileUtil.createFolder(FileUtil.toFileObject(getWorkDir()), "whereTo");
+
+ FileObject template = FileUtil.getConfigFile("Templates/Project/Maven2/JavaApplication2");
+ FileBuilder bld = new FileBuilder(template, whereTo);
+ bld.name("TestProject");
+ bld.defaultMode(FileBuilder.Mode.COPY);
+
+ bld.param("artifactId", "netbeans-test-project");
+ bld.param("groupId", "org.netbeans.modules.maven");
+ // leave out version
Review comment:
Looks like the version can be left out.
##########
File path: java/maven/src/org/netbeans/modules/maven/layer.xml
##########
@@ -33,6 +33,22 @@
<folder name="Maven2">
<attr name="displayName" bundlevalue="org.netbeans.modules.maven.newproject.Bundle#Templates/Project/Maven2"/>
<attr name="position" intvalue="100"/>
+
+ <!-- Simple Java project structure -->
+ <folder name="JavaApplication2">
+ <folder name="src">
+ <folder name="main">
+ <folder name="java">
+ <folder name="${packagePath}">
+ <file name="${mainClassName}.java" url="nbresloc:/org/netbeans/modules/maven/resources/App.java.template">
Review comment:
Using new substitution mechanism for names is OK, but the syntax! Let's make the syntax pluggable! Sváťo, what do you think about:
If there is an `<attr name="javax.script.ScriptEngine" stringvalue="freemarker"/>` attribute on a file or folder, apply the specified engine (e.g. `freemarker`) to the name of the file/folder as well.
##########
File path: platform/api.templates/src/org/netbeans/api/templates/CreateDescriptor.java
##########
@@ -181,4 +187,17 @@ public boolean hasFreeExtension() {
public boolean isPreformatted() {
return preformatted;
}
+
+ void setLookup(Lookup contextLookup) {
+ this.contextLookup = contextLookup;
+ }
+
+ /**
+ * Lookup that may contain additional services or instructions for
+ * the template creation.
+ * @since 1.23
+ */
+ public Lookup getLookup() {
Review comment:
The class could now `implements Lookup.Provider`.
##########
File path: platform/api.templates/src/org/netbeans/api/templates/TemplateRegistration.java
##########
@@ -156,4 +156,10 @@
* @since 1.4
*/
String[] techIds() default {};
+
+ /**
+ * Specifies the default handler to instantiate the template.
+ * @since 1.23
+ */
+ Class<? extends CreateFromTemplateHandler> createHandlerClass() default CreateFromTemplateHandler.class;
Review comment:
Nice.
##########
File path: java/maven/src/org/netbeans/modules/maven/newproject/idenative/SimpleJavaNativeMWI.java
##########
@@ -19,103 +19,29 @@
package org.netbeans.modules.maven.newproject.idenative;
-import org.netbeans.modules.maven.spi.newproject.CreateProjectBuilder;
-import java.io.File;
-import java.util.Collections;
-import java.util.List;
-import org.apache.maven.project.MavenProject;
-import org.netbeans.api.java.platform.JavaPlatform;
-import org.netbeans.api.java.platform.JavaPlatformManager;
-import org.netbeans.api.progress.ProgressHandle;
import org.netbeans.api.templates.TemplateRegistration;
-import org.netbeans.modules.maven.api.Constants;
-import org.netbeans.modules.maven.api.PluginPropertyUtils;
import org.netbeans.modules.maven.api.archetype.ArchetypeWizards;
-import org.netbeans.modules.maven.api.archetype.ProjectInfo;
-import org.netbeans.modules.maven.classpath.AbstractBootPathImpl;
-import org.netbeans.modules.maven.model.ModelOperation;
-import org.netbeans.modules.maven.model.pom.POMModel;
-import org.netbeans.modules.maven.model.pom.Project;
-import org.netbeans.modules.maven.model.pom.Properties;
import static org.netbeans.modules.maven.newproject.idenative.Bundle.LBL_Maven_Quickstart_Archetype;
-import org.netbeans.modules.maven.options.MavenSettings;
import org.openide.util.NbBundle.Messages;
/**
*
* @author mkleint
*/
@TemplateRegistration(
- id = "JavaApplication",
+ id = "JavaApplication2/",
Review comment:
Why is this template being renamed?
##########
File path: java/maven/src/org/netbeans/modules/maven/newproject/idenative/IDENativeTemplateHandler.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.maven.newproject.idenative;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import org.netbeans.api.progress.ProgressHandle;
+import org.netbeans.api.project.ProjectManager;
+import org.netbeans.api.templates.CreateDescriptor;
+import org.netbeans.api.templates.CreateFromTemplateHandler;
+import org.netbeans.api.templates.FileBuilder;
+import org.netbeans.modules.maven.api.archetype.ProjectInfo;
+import org.netbeans.modules.maven.newproject.TemplateUtils;
+import org.netbeans.modules.maven.spi.newproject.CreateProjectBuilder;
+import org.netbeans.spi.project.ui.support.CommonProjectActions;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.BaseUtilities;
+import org.openide.util.NbBundle;
+
+/**
+ * Allows to create the 'ide native' projects in the headless mode. Is not registered as an interceptor, but rather
+ * listed explicitly for a template it handles.
+ * @author sdedic
+ */
+public class IDENativeTemplateHandler extends CreateFromTemplateHandler {
Review comment:
Can we use some other name than IDE native? There is no native code and I find the name confusing.
##########
File path: platform/api.templates/src/org/netbeans/api/templates/CreateFromTemplateHandler.java
##########
@@ -59,4 +64,171 @@
CreateDescriptor desc
) throws IOException;
+ /**
+ * Replaces ${param} tokens in a String. The parameter reference has syntax "${" paramName [":" defaultValue ] "}".
+ * Parameters are replaced recursively. "${" can be escaped by \, so "\${" will not act as parameter reference start.
+ * @param expression string template
+ * @param parameters parameter values
+ * @return evaluated string.
+ * @since 1.23
+ */
+ public static String mapParameters(String expression, Map<String, ?> parameters) {
+ int start = 0;
+ int pos = 0;
+ StringBuilder sb = null;
+
+ while ((pos = expression.indexOf("${", pos)) != -1) { // NOI18N
+ if (pos > 0 && expression.charAt(pos - 1) == '\\') { // NOI18N
+ pos += 2;
+ continue;
+ }
+ int endPos = pos + 2;
+ int state = 0;
+ int nested = 0;
+ A: while (endPos < expression.length()) {
+ char c = expression.charAt(endPos);
+ if (state == 1) {
+ state = 0;
+ endPos++;
+ continue;
+ }
+ switch (c) {
+ case '\\': // NOI18N
+ state = 1;
+ break;
+ case '$': // NOI18N
+ state = 2;
+ break;
+ case '{': // NOI18N
+ if (state == 2) {
+ state = 0;
+ nested++;
+ }
+ break;
+ case '}': // NOI18N
+ if (state == 0) {
+ if (nested-- == 0) {
+ break A;
+ }
+ }
+ break;
+ }
+ endPos++;
+ }
+ if (endPos >= expression.length()) {
+ pos += 2;
+ continue;
+ }
+ String token = expression.substring(pos + 2, endPos);
+ String defValue = null;
+
+ int colon = token.indexOf(':'); // NOI18N
+ if (colon != -1) {
+ defValue = token.substring(colon + 1);
+ token = token.substring(0, colon);
+ }
+
+ if (sb == null) {
+ sb = new StringBuilder();
+ }
+ Object v = parameters.get(token);
+ if (v == null) {
+ v = defValue;
+ }
+ if (v == null) {
+ pos += 2;
+ continue;
+ }
+ sb.append(expression.substring(start, pos)).append(v.toString());
+ start = endPos + 1;
+ pos = start;
+ }
+ if (sb == null) {
+ return expression;
+ }
+ if (start < expression.length()) {
+ sb.append(expression.substring(start));
+ }
+
+ return mapParameters(sb.toString(), parameters);
+ }
+
+ private static final String PROP_TEMPLATE = "template"; // NOI18N
+
+ /**
+ * Prefix for template-controlling attributes. Such attributes will not be copied
+ * during template instantiation.
+ */
+ private static final String ATTR_TEMPLATE_PREFIX = "template.";
+
+ /**
+ * Copies template attributes over to the created file. Copies over from the source (template) to the target (usually
+ * the produced file), except attributes that parametrize template creation. By default, attributes that are prefixed
+ * with {@code "template."} are not copied. As the operation is not atomic, the method should be called in a
+ * {@link org.openide.filesystems.FileSystem#runAtomicAction(org.openide.filesystems.FileSystem.AtomicAction)}.
+ * The {@code "template"} attribute is never copied.
+ *
+ * @param h the Handler responsible for file creation, usually the calling handler.
+ * @param from the original file
+ * @param to the target file
+ * @throws IOException if an I/O error occurs.
+ */
+ public static void copyAttributesFromTemplate(CreateFromTemplateHandler h, FileObject from, FileObject to) throws IOException {
+ // copy attributes; some attributes are filtered by FileSystems API already
+ FileUtil.copyAttributes(from, to);
+ // need to filter additional template-related attributes:
+ for (String a : Collections.list(to.getAttributes())) {
+ if ("javax.script.ScriptEngine".equals(a) // NOI18N
+ || a.startsWith(ATTR_TEMPLATE_PREFIX)) {
+ to.setAttribute(a, null);
+ }
+ }
+ // hack to overcome package-private modifier in setTemplate(fo, boolean)
+ to.setAttribute(PROP_TEMPLATE, null);
+ }
+
+
+ /**
+ * Copies the files or folders contained in the specified folder to the target. The original descriptor can be passed in,
+ * since it has Lookup, parameters etc set up. They will be passed on to individual created files. The `contentsParent` may
+ * be {@code null}, in which case the {@link CreateDescriptor#getTemplate()} folder will be used.
+ * @param origDescriptor original descriptor to get parameters / lookup from
+ * @param contentsParent template folder whose contents should be copied
+ * @param target target folder
+ * @return created files
+ * @throws IOException
+ * @since 1.23
+ */
+ protected static List<FileObject> defaultCopyContents(CreateDescriptor origDescriptor, FileObject contentsParent, FileObject target) throws IOException {
Review comment:
Strange method. `protected static` is a strange combination of modifiers - if the class is subclassable, there is nothing "protected" in this method. If the class isn't subclassable, making a method `protected` makes no sense.
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] JaroslavTulach commented on a change in pull request #3262: [NETBEANS-5847] Maven project template uses template for project structure.
Posted by GitBox <gi...@apache.org>.
JaroslavTulach commented on a change in pull request #3262:
URL: https://github.com/apache/netbeans/pull/3262#discussion_r741050076
##########
File path: java/maven/src/org/netbeans/modules/maven/layer.xml
##########
@@ -33,6 +33,22 @@
<folder name="Maven2">
<attr name="displayName" bundlevalue="org.netbeans.modules.maven.newproject.Bundle#Templates/Project/Maven2"/>
<attr name="position" intvalue="100"/>
+
+ <!-- Simple Java project structure -->
+ <folder name="JavaApplication2">
+ <folder name="src">
+ <folder name="main">
+ <folder name="java">
+ <folder name="${packagePath}">
+ <file name="${mainClassName}.java" url="nbresloc:/org/netbeans/modules/maven/resources/App.java.template">
Review comment:
Yes, it is an overkill.
On the other hand, the templating engine must be around and it provides familiar syntax. E.g. one would be using the same syntax for the file name as well as for the file content.
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
[GitHub] [netbeans] sdedic commented on pull request #3262: [NETBEANS-5847] Maven project template uses template for project structure.
Posted by GitBox <gi...@apache.org>.
sdedic commented on pull request #3262:
URL: https://github.com/apache/netbeans/pull/3262#issuecomment-971462464
Finally all checks passed. We **NEED** to stabilize the testusites.
--
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: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists