Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java Frontend Application wizard for Gradle #1154

Merged
merged 8 commits into from
Apr 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions groovy/gradle.htmlui/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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.

-->
<project basedir="." default="netbeans" name="groovy/gradle.htmlui">
<description>Builds, tests, and runs the project org.netbeans.modules.gradle.htmlui</description>
<import file="../../nbbuild/templates/projectized.xml"/>
</project>
8 changes: 8 additions & 0 deletions groovy/gradle.htmlui/manifest.mf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Manifest-Version: 1.0
AutoUpdate-Show-In-Client: true
OpenIDE-Module: org.netbeans.modules.gradle.htmlui
OpenIDE-Module-Layer: org/netbeans/modules/gradle/htmlui/resources/layer.xml
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/gradle/htmlui/Bundle.properties
OpenIDE-Module-Recommends: org.netbeans.modules.debugger.jpda.ui
OpenIDE-Module-Specification-Version: 1.0

19 changes: 19 additions & 0 deletions groovy/gradle.htmlui/nbproject/project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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.

javac.source=1.7
javac.compilerargs=-Xlint -Xlint:-serial
135 changes: 135 additions & 0 deletions groovy/gradle.htmlui/nbproject/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?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.

-->
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.apisupport.project</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/nb-module-project/3">
<code-name-base>org.netbeans.modules.gradle.htmlui</code-name-base>
<module-dependencies>
<dependency>
<code-name-base>org.netbeans.api.templates</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>1.6.1</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.libs.freemarker</code-name-base>
<run-dependency>
<release-version>1</release-version>
<specification-version>2.39</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.gradle</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>1.0</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.netbeans.modules.projectapi</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<release-version>1</release-version>
<specification-version>1.71</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.dialogs</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.46</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.filesystems</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>9.14</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.loaders</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.72</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.nodes</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>7.50</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>9.11</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util.lookup</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>8.37</specification-version>
</run-dependency>
</dependency>
<dependency>
<code-name-base>org.openide.util.ui</code-name-base>
<build-prerequisite/>
<compile-dependency/>
<run-dependency>
<specification-version>9.12</specification-version>
</run-dependency>
</dependency>
</module-dependencies>
<test-dependencies>
<test-type>
<name>unit</name>
<test-dependency>
<code-name-base>org.netbeans.modules.nbjunit</code-name-base>
<recursive/>
<compile-dependency/>
</test-dependency>
<test-dependency>
<code-name-base>org.netbeans.modules.projectapi.nb</code-name-base>
<recursive/>
<compile-dependency/>
</test-dependency>
</test-type>
</test-dependencies>
<public-packages/>
</data>
</configuration>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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.

OpenIDE-Module-Name=DukeScript Gradle Project Wizard
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* 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.gradle.htmlui;

import java.io.IOException;
import java.util.Enumeration;
import java.util.Map;
import org.netbeans.api.templates.FileBuilder;
import org.netbeans.api.templates.FileBuilder.Mode;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.MapFormat;

final class GradleArchetype {
private final FileObject templates;
private final FileObject projectFo;
private final Map<String, Object> params;

GradleArchetype(FileObject templates, FileObject projectFo, Map<String, Object> params) {
this.templates = templates;
this.projectFo = projectFo;
this.params = params;
}

final void copyTemplates() throws IOException {
MapFormat mf = new MapFormat(params);
mf.setLeftBrace("${"); // NOI18N
mf.setRightBrace("}"); // NOI18N
Enumeration<? extends FileObject> en = templates.getChildren(true);
while (en.hasMoreElements()) {
FileObject template = en.nextElement();
if (!template.isData()) {
continue;
}
String relativeParent = FileUtil.getRelativePath(templates, template.getParent());
Object packageAttr = template.getAttribute("package"); // NOI18N
if (packageAttr instanceof String) {
String packageName = mf.format(packageAttr).replace('.', '/');
relativeParent += "/" + packageName;
}
FileObject destinationFolder = FileUtil.createFolder(projectFo, relativeParent);

FileObject previous = destinationFolder.getFileObject(template.getNameExt());
if (previous != null) {
previous.delete();
}

FileBuilder fb = new FileBuilder(template, destinationFolder);
fb.withParameters(params);
fb.defaultMode(Mode.COPY);

FileObject copied = fb.build().iterator().next();

assert copied != null && copied.getNameExt().equals(template.getNameExt()) : "Created " + copied;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* 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.gradle.htmlui;

import org.netbeans.modules.gradle.spi.newproject.SimpleGradleWizardIterator;
import org.netbeans.modules.gradle.spi.newproject.TemplateOperation;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.netbeans.api.project.Project;
import org.netbeans.modules.gradle.api.NbGradleProject;
import org.openide.WizardDescriptor;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.loaders.TemplateWizard;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle.Messages;

@Messages("template.htmlUIProject=Java Frontend Application")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be quite confusing especially when this is in the main Gradle Project Wizard folder. At least if I'd like to do a Java Frontend Application, I would not think on bck2brwsr app on the first place (I'm sorry for that).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This template is not about bck2brwsr. The main focus is DukeScript - e.g. combination of the best Java VM and portable frontend rendering. What exactly is the problem? The "Run" action? If so, it can be changed to do the same thing as "Debug".

The naming is consistent with the Maven category. There is a Java Frontend Application archetype in the Maven category which leads to the same/similar application, using the same libraries. Our intention is to deliver the same Java Frontend Application experience to Gradle users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw. there is also a way to run the application as Android application and as iOS application. They aren't advertised in the UI yet as it requires additional configuration of SDK, simulator, etc. We'd welcome coordinated support in this direction of generic Java Frontend Applications, but we think it is out of the scope of this PR.

public class HtmlJavaApplicationProjectWizard extends SimpleGradleWizardIterator {
private static final String DEFAULT_LICENSE_TEMPLATE = "/Templates/Licenses/license-default.txt"; //NOI18N

@Messages("LBL_FrontendApplicationProject=Java Frontend Application with Gradle")
public HtmlJavaApplicationProjectWizard() {
super(Bundle.LBL_FrontendApplicationProject(), initParams());
}

private static Map<String, Object> initParams() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this method is a copy paste and does not really needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method is used on line 47, but the properties are likely useless: ee258eb

Map<String, Object> params = new HashMap<>();
return params;
}

@Override
protected List<? extends WizardDescriptor.Panel<WizardDescriptor>> createPanels() {
return Collections.singletonList(createProjectAttributesPanel(null));
}

@Override
protected void collectOperations(TemplateOperation ops, Map<String, Object> params) {
super.collectOperations(ops, params);
String packageBase = (String) params.get(PROP_PACKAGE_BASE);
String mainClassName = (String) params.get("mainClassName");

File projectDir = (File) params.get("projectDir");

File mainJava = (File) params.get(PROP_MAIN_JAVA_DIR);
File packageDir = new File(mainJava, packageBase.replace('.', '/'));
Map<String, Object> mainParams = new HashMap<>(params);
mainParams.put("project", new DummyProject());
mainParams.put("package", packageBase); //NOI18N
mainParams.put("name", mainClassName); //NOI18N

FileObject folder = ((TemplateWizard)this.getData()).getTemplate().getPrimaryFile();
ops.addConfigureProject(projectDir, new CopyTree(folder, projectDir, mainParams));
}

private static class CopyTree implements TemplateOperation.ProjectConfigurator {
private final FileObject templateFolder;
private final File projectDir;
private final Map<String, Object> params;

private CopyTree(FileObject templateFolder, File projectDir, Map<String, Object> params) {
this.projectDir = projectDir;
this.params = params;
this.templateFolder = templateFolder;
}

@Override
public void configure(Project project) {
FileObject projectFo = FileUtil.toFileObject(projectDir);

GradleArchetype ga = new GradleArchetype(templateFolder, projectFo, params);
try {
ga.copyTemplates();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
} finally {
NbGradleProject.fireGradleProjectReload(project);
}
}
}

public static class DummyProject {
public String getLicensePath() {
return DEFAULT_LICENSE_TEMPLATE;
}
}

}
Loading