This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 270140 - Add Java/HTML Maven Archetypes
Summary: Add Java/HTML Maven Archetypes
Status: RESOLVED FIXED
Alias: None
Product: projects
Classification: Unclassified
Component: Maven (show other bugs)
Version: Dev
Hardware: All All
: P2 normal (vote)
Assignee: Tomas Stupka
URL:
Keywords: API_REVIEW_FAST
Depends on:
Blocks:
 
Reported: 2017-03-20 17:27 UTC by maxnitribitt
Modified: 2017-04-11 01:51 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
The patch (38.74 KB, patch)
2017-03-20 17:27 UTC, maxnitribitt
Details | Diff
screenshots mentioned in text (717.06 KB, application/zip)
2017-03-20 17:28 UTC, maxnitribitt
Details
the real patch (46.12 KB, patch)
2017-03-23 08:33 UTC, maxnitribitt
Details | Diff
updated patch (38.35 KB, patch)
2017-03-23 10:09 UTC, maxnitribitt
Details | Diff
less dependencies (37.12 KB, patch)
2017-03-24 13:14 UTC, maxnitribitt
Details | Diff
proposed patch for TS02 and TS03 (43.74 KB, patch)
2017-03-30 20:24 UTC, maxnitribitt
Details | Diff
<no description> (6.43 KB, text/x-diff)
2017-03-31 17:16 UTC, Tomas Stupka
Details
Styling and getSettings (77.08 KB, patch)
2017-04-09 07:27 UTC, maxnitribitt
Details | Diff
updated diff (9.26 KB, application/octet-stream)
2017-04-09 18:25 UTC, maxnitribitt
Details
missing files (225.05 KB, application/octet-stream)
2017-04-09 18:40 UTC, maxnitribitt
Details
Slightly too dark background on Linux+Metal (31.25 KB, image/png)
2017-04-09 19:26 UTC, Jaroslav Tulach
Details

Note You need to log in before you can comment on or make changes to this bug.
Description maxnitribitt 2017-03-20 17:27:04 UTC
Created attachment 163896 [details]
The patch

NetBeans should have support for creating projects with the NetBeans HTML/Java API (http://bits.netbeans.org/html+java/1.3/index.html). There already is some support for creating Wizards, and TopComponents in Plugin projects, but this is limited to plugin development. 

The NetBeans/HTML (aka DukeScript) is also a great general purpose Java client technology and a great alternative to Swing and JavaFX. So far users need to install an external plugin to create applications with it, or to use maven on the command line. I think it's a shame that this great part of our beloved IDE is not given a little more attention.

That's why I propose to add a project type for Java/HTML-based client project. I've created a patch and added a new TemplateRegistration to the „maven“ module. I chose this module, because it already has other project templates based on maven archetypes (e.g. JavaFX). So I followed this example. 

The patch doesn’t make any changes in existing Java code, except that it fixes a bug in templatesui AbstractWizard which I found during testing (threading issue). 

I’m a long time member of the NetBeans community (maxnitribitt==Toni Epple), and I’m willing to maintain this integration as an external contributor also for future releases. The Maven archetypes (https://github.com/dukescript/maven-archetypes/releases) are also maintained by my company (Dukehoff GmbH) and have been in active use and development for more than 2 years. My company and I are committed to this project and will dedicate as much time as needed for maintaining this project.

The patch ads a new Project type to the JavaFX category (see screenshot1). From there the wizard collects user input to parametrize the archetype (see screenshots2-5). 

I’m not sure if that category is a good match, and would ask for advice where to best put it. Ideally there would be a separate category, or maybe it should go to the main Java category like Swing Projects (?). Also „JavaFX WebView Application“ is probably not a good description. Some feedback here would also be appreciated.

It would be great to finally have adequate support for this great part of NetBeans, so I ask for your support and feedback for this small, but important, enhancement.
Comment 1 maxnitribitt 2017-03-20 17:28:38 UTC
Created attachment 163897 [details]
screenshots mentioned in text
Comment 2 Jaroslav Tulach 2017-03-23 08:24:01 UTC
Toni, I don't think the patch is correct. It seems to contain some API changes done by Tomáš Zezula.
Comment 3 maxnitribitt 2017-03-23 08:33:29 UTC
Created attachment 163923 [details]
the real patch
Comment 4 Jaroslav Tulach 2017-03-23 08:47:53 UTC
Thanks for the fix in templatesui/src/org/netbeans/modules/templatesui/AbstractWizard.java, but:

Y01 Why is the diff changing so many lines? Did you reformat the source? Can you patch the file gently and just use the EventQueue.invokeLater and leave the other parts of the source unchanged?

Y02 The wizard hard-codes references to 0.13 version of the archetypes. Unless I am mistaken, there are newer versions: http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22com.dukescript.archetype%22 - don't you want to reference the most recent ones?
Comment 5 maxnitribitt 2017-03-23 10:09:45 UTC
Created attachment 163924 [details]
updated patch
Comment 6 Tomas Stupka 2017-03-23 18:53:46 UTC
TS01 the new wizard page has a different look than the typical NetBeansUI (fonts etc.). Any chance to do something about it? 

TS02 a lot of new dependencies. Are all them really necessary?

TS03 MavenUtilities.getDefault() etc. - there should be a better way how to access the settings file. See MavenEmbedder.getSettings() and how o.a.maven.Settings is used, maybe it can be of some help. 

thanks
Comment 7 maxnitribitt 2017-03-24 10:18:59 UTC
(In reply to Tomas Stupka from comment #6)
> TS01 the new wizard page has a different look than the typical NetBeansUI
> (fonts etc.). Any chance to do something about it? 

Yes, I can style it differently. Is there a list of fonts, sizes and colours for the different platforms that I can use?
Comment 8 maxnitribitt 2017-03-24 13:13:39 UTC
(In reply to Tomas Stupka from comment #6)
> TS02 a lot of new dependencies. Are all them really necessary?
> 
new patch has less dependencies.
Comment 9 maxnitribitt 2017-03-24 13:14:11 UTC
Created attachment 163933 [details]
less dependencies
Comment 10 maxnitribitt 2017-03-24 14:15:04 UTC
(In reply to Tomas Stupka from comment #6)

> TS03 MavenUtilities.getDefault() etc. - there should be a better way how to
> access the settings file. See MavenEmbedder.getSettings() and how
> o.a.maven.Settings is used, maybe it can be of some help. 

I tried using Maven DefaultSettingsWriter, but this way all comments and formatting are lost.
Comment 11 Tomas Stupka 2017-03-27 17:33:39 UTC
> (In reply to Tomas Stupka from comment #6)
> > TS01 the new wizard page has a different look than the typical NetBeansUI
> (In reply to Tomas Stupka from comment #6)
thinking it over one more time - currently all the wizards in maven project are swing/nb based and i see no good reason why the DukeScriptWizard should be now implemented by a different technology and by introducing new dependencies on top of it. 
Being consistent with how other wizards are made in maven, this problem would be off the table and we would save 4 new dependencies. 

> > TS03 MavenUtilities.getDefault() etc. - there should be a better way how to
> I tried using Maven DefaultSettingsWriter, but this way all comments and formatting are lost.
hm, would guess that the settings api is able to deal with it ... the problem with MavenUtils is that is be quite easy to break.
Comment 12 Jaroslav Tulach 2017-03-28 05:45:27 UTC
Re. TS02 - thanks for pointing this out. Yes, the new dependencies are an issue. The problem isn't that there is many of them (all of the modules are already in the NetBeans Platform), but that some of them need JavaFX. There are some JDKs that don't provide JavaFX by default (IcedTea or OpenJDK come to my mind) and with the new dependency on HTML UI API the whole Maven module would get disabled on such platforms. That's certainly an undesirable behaviour.

I see two solutions:
1) rewrite the UI to Swing
2) move the wizard definition to separate module

Tomáš already explained why #1 would be good and keep things simple. As somebody who believes Swing days are over and that HTML is a way to go I want to advocate #2: it wouldn't affect existing behaviour and it would be a great chance to explore the HTML approach and pave path to future followers. Btw. Toni is a great UI expert and I am sure he can polish the UI to look great.

The overall situation reminds me of the Equinox case[1] (1st in the Platform unused, then used by the IDE to run Mylyn, then powering JDeveloper as the fastest OSGi container on the Planet). I'd like the follow the same pattern in this case - as such I prefer #2.

[1] http://wiki.apidesign.org/wiki/Netbinox
Comment 13 maxnitribitt 2017-03-28 05:59:14 UTC
(In reply to Jaroslav Tulach from comment #12)
Re. TS02 - I would also be in favour of #2, since the idea of the wizard is to offer an alternative to Swing, it would be strange to write it in Swing. I'm at a conference now, but should be able to prepare a patch tomorrow after the talks.

Re. TS01 It's no problem styling it to make it look less alien, as soon as we've fixed the other problems. If there's a design document for fonts and colours, that would simplify things.
Comment 14 Jaroslav Tulach 2017-03-28 08:53:03 UTC
Btw. I have just integrated the deadlock fix: http://hg.netbeans.org/core-main/rev/1886b9d908cb
Comment 15 Tomas Stupka 2017-03-28 11:40:27 UTC
The dependency issue pointed out by jarda makes #2 the right way to go. 
As a side remark - a showcase should not be realised on the cost of mixing up different approaches at literally the same place, for the same kind of thing.

re design document for fonts and colours - i'm not aware about any. Most of it is given somewhere behind the curtains of NetBeans UI/L&F. Just note that every time some default for a font, color etc changes, you probably will have to straigthen it up in your implementation as well.

re o.a.mave.Settings - maybe the problem isn't in DefaultSettingsWritter, but how the settings file is read in the first place - skipping comments etc. and therefore they are later not written. Found a isStrict flag in DefaultSettingsReader, perhaps worth to have a look on it.
Comment 16 Tomas Stupka 2017-03-30 09:26:31 UTC
lets create a new module and call it something like - maven.javafx, or maven.htmljava, or maven.htmlui. 
Once the name is set, we can add the module as a friend to maven.embedder so that the settigns api can be accessed.
Comment 17 maxnitribitt 2017-03-30 15:24:30 UTC
(In reply to Tomas Stupka from comment #15)

> re o.a.mave.Settings - maybe the problem isn't in DefaultSettingsWritter,
> but how the settings file is read in the first place - skipping comments
> etc. and therefore they are later not written. Found a isStrict flag in
> DefaultSettingsReader, perhaps worth to have a look on it.

I've seen the flag, you can set it using the options Map. I tried with true/false. It makes no difference, comments are skipped.
Comment 18 maxnitribitt 2017-03-30 15:37:16 UTC
(In reply to maxnitribitt from comment #17)
> (In reply to Tomas Stupka from comment #15)
> 
> > re o.a.mave.Settings - maybe the problem isn't in DefaultSettingsWritter,
> > but how the settings file is read in the first place - skipping comments
> > etc. and therefore they are later not written. Found a isStrict flag in
> > DefaultSettingsReader, perhaps worth to have a look on it.
> 
> I've seen the flag, you can set it using the options Map. I tried with
> true/false. It makes no difference, comments are skipped.

Settings cannot keep comments (http://grepcode.com/file_/repo1.maven.org/maven2/org.apache.maven/maven-settings/2.0.8/org/apache/maven/settings/Settings.java/?v=source). Should I use XML Parser instead to make sure that valid XML is produced?
Comment 19 maxnitribitt 2017-03-30 16:14:17 UTC
How about sthg. like this. Makes sure it's valid xml and keeps comments:

        try {
            String path = "thePath";
            File settingsFile = settingsFile = new File(new File(new File(System.getProperty("user.home")), ".m2"), "settings.xml");
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder;
            dBuilder = dbFactory.newDocumentBuilder();
            Document settings = dBuilder.parse(settingsFile);
            settings.getDocumentElement().normalize();
            NodeList profiles = settings.getElementsByTagName("profiles");
            Node parent = profiles.item(0);
            Document doc = parent.getOwnerDocument();
            String fragment = "<profile>\n"
                    + "      <id>android.sdk.path</id>\n"
                    + "      <activation>\n"
                    + "        <property>\n"
                    + "          <name>!android.sdk.path</name>\n"
                    + "        </property>\n"
                    + "      </activation>\n"
                    + "      <properties>\n"
                    + "        <android.sdk.path>" + path + "</android.sdk.path>\n"
                    + "      </properties>\n"
                    + "    </profile>\n";

            Node fragmentNode = DocumentBuilderFactory
                    .newInstance()
                    .newDocumentBuilder().parse(
                            new InputSource(new StringReader(fragment)))
                    .getDocumentElement();
            fragmentNode = doc.importNode(fragmentNode, true);
            parent.appendChild(fragmentNode);
             doc.getDocumentElement().normalize();
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            Transformer transformer = transformerFactory.newTransformer();
            DOMSource source = new DOMSource(settings);
            StreamResult result = new StreamResult(settingsFile);
            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
            transformer.transform(source, result);
        } catch (ParserConfigurationException ex) {
            Logger.getLogger(MAin.class.getName()).log(Level.SEVERE, null, ex);
        }
Comment 20 maxnitribitt 2017-03-30 20:24:02 UTC
Created attachment 163984 [details]
proposed patch for TS02 and TS03
Comment 21 Tomas Stupka 2017-03-31 17:15:59 UTC
hm, bad luck with o.a.m.Settings
see attached patch - added maven/FileUtilities.getSettings() which gets (and eventually creates settings.xml) so that you are consistent with how it is done on other places in nb/maven

otherwise ok for me
Comment 22 Tomas Stupka 2017-03-31 17:16:30 UTC
Created attachment 163992 [details]
<no description>
Comment 23 maxnitribitt 2017-04-09 07:27:56 UTC
Created attachment 164052 [details]
Styling and getSettings
Comment 24 maxnitribitt 2017-04-09 07:30:15 UTC
I updated the patch to use getSettings and platform specific styling to look similar to the rest of the wizards.
Comment 25 maxnitribitt 2017-04-09 18:25:17 UTC
Created attachment 164058 [details]
updated diff

It seems the patch is corrupted. Strange, I created a fresh clone of main-silver, then applied Thomas patch and after that added my module. Then I used NetBeans "Export uncommitted Changes" to create and directly upload to the issue. This is the diff created with hg diff
Comment 26 maxnitribitt 2017-04-09 18:40:00 UTC
Created attachment 164059 [details]
missing files
Comment 27 Jaroslav Tulach 2017-04-09 19:22:17 UTC
https://hg.netbeans.org/ergonomics/rev/06d94994f818
Comment 28 Jaroslav Tulach 2017-04-09 19:26:03 UTC
Created attachment 164060 [details]
Slightly too dark background on Linux+Metal

Looks fine, integrated. Few improvements may be done later.
Comment 29 maxnitribitt 2017-04-10 06:43:58 UTC
(In reply to Jaroslav Tulach from comment #28)
> Created attachment 164060 [details]
> Slightly too dark background on Linux+Metal
> 
> Looks fine, integrated. Few improvements may be done later.

Thanks for the help. Yes, it seems I accidentally used the Nimbus background, metal should be rgb(238,238,238);.
Comment 30 Quality Engineering 2017-04-11 01:51:58 UTC
Integrated into 'main-silver', will be available in build *201704110002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/06d94994f818
User: Toni Epple <maxnitribitt@netbeans.org>
Log: #270140: Add Java/HTML Maven Archetypes