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

Added Template based Project Wizard #499

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

keinhaar
Copy link
Contributor

  • Create projects based on templates.
  • removed some unused code
  • added a multi project template without example code
  • added a multi project GWT project template with the example code from the existing GWT sample project, but splitted into 3 projects.

- Create projects based on templates.
- removed some unused code
- added a multi project template without example code
- added a multi project GWT project template with the example code from
the existing GWT sample project, but splitted into 3 projects.
@protoism
Copy link
Contributor

@keinhaar this PR looks great, and the implementation looks simply reasonable.
Before reviewing / merging, I'd like to know @niloc132 opinion about it.
Multi-module templates is definitely the right way to use GWT, classpath issues bite very often, but:

  1. Is there any overlap with what the SDK does already?
  2. The build is Eclipse only (no maven, no gradle), does this make sense? (I think so, honestly) - @keinhaar I don't find any pom.xml file, but I see something about maven nature. Am I rigth or not, that maven is not involved?

BTW the solution is expandable either by adding to the template dir, or defining an env variable. Not bad!

@keinhaar
Copy link
Contributor Author

keinhaar commented Sep 30, 2024

1. Is there any overlap with what the SDK does already?

It just uses modified versions of the files that are created by the sdk.

2. The build is Eclipse only (no maven, no gradle), does this make sense? (I think so, honestly) - @keinhaar I don't find any pom.xml file, but I see something about maven nature. Am I rigth or not, that maven is not involved?

maven based example could be added easily by just providing a template with pom files. I did not create more templates, because i did not know if this would be accepted.

BTW the solution is expandable either by adding to the template dir, or defining an env variable. Not bad!

The env variable makes it possible to create and use your own custom templates. Thats what i personally would like to use, because my applications often have 5 or even 6 projects which depend on each other.

@FrankHossfeld
Copy link

FrankHossfeld commented Sep 30, 2024

@keinhaar Thanks for contributing.
I would suggest to provide only the multi module templates. GWT is moving to a more serverless approach. AFAIK the webappcreator inside GWT is deprecated for that reason (only one single module). And, as @protoism already mention, a Maven module artifact using the gwt-maven-plugin would be nice.

And, having a template project using Spring Boot on the server side would be fine. ;-)

@FrankHossfeld
Copy link

FrankHossfeld commented Sep 30, 2024

It just uses modified versions of the files that are created by the sdk

Just use the archetype creators for generating the template files:

These are the suggested way creating a new project: https://www.gwtproject.org/gettingstarted-v2.html

@keinhaar
Copy link
Contributor Author

@niloc132 Could you please have a look on this pull request, as @protoism requested?

Copy link
Member

@niloc132 niloc132 left a comment

Choose a reason for hiding this comment

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

A lot of this is pretty eclipse-specific, I'm not sure how helpful I can be. Here's a quick review, but I think it would make more sense for someone who knows the project more deeply to dig in than me.

@@ -0,0 +1,130 @@
/*******************************************************************************
* Copyright 2011 Google Inc. All Rights Reserved.
Copy link
Member

Choose a reason for hiding this comment

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

new files, should have updated copyright date, and owner

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed this

@@ -0,0 +1,171 @@
/**
*
Copy link
Member

Choose a reason for hiding this comment

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

should be populated, or removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed this

Comment on lines +28 to +29
javaProjects = webAppProjectCreator.getCreatedJavaProjects();
if (javaProjects == null) {
Copy link
Member

Choose a reason for hiding this comment

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

it doesnt appear that this should never return null - would it make more sense to test if empty? also, what do you think about List<IJavaProject>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed this to list

pom.xml Outdated
@@ -11,7 +11,7 @@
<properties>
<tycho.version>3.0.1</tycho.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<eclipse.target>2022-09</eclipse.target> <!-- TODO change to neon -->
<eclipse.target>2023-09</eclipse.target> <!-- TODO change to neon -->
Copy link
Member

Choose a reason for hiding this comment

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

probably can remove that TODO as long as you're updating the line...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed todo

Comment on lines 29 to 30
<!-- allow Super Dev Mode -->
<add-linker name="xsiframe"/>
Copy link
Member

Choose a reason for hiding this comment

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

No longer needed since GWT 2.7, almost 10 years gwtproject/gwt@22865ad

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the xsiframe

throw new IOException("File to large");
}
byte[] data = Files.readAllBytes(path);
String str = new String(data, cset);
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure we want the default charset here, rather than just assuming utf8 everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to UTF-8

Comment on lines 260 to 262
BufferedWriter writer = Files.newBufferedWriter(path, cset);
writer.write(newStr);
writer.close();
Copy link
Member

Choose a reason for hiding this comment

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

try-with-resources, otherwise if the write fails this might not get closed (and then you've got a broken project, and windows won't let it be deleted or the like)

(goes away if you use Files.write())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to Files.writeString()

* @param file
* @throws CoreException
*/
public static void reformatJavaSource(File file) throws CoreException {
try {
String generatedSource = textFromFile(file);
String generatedSource = Files.readString(file.toPath(), Charset.defaultCharset());
Copy link
Member

Choose a reason for hiding this comment

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

consider if we really want the default charset here, or just assume utf8?

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 has been default charset in the previous implementation. Didn't want to change that. Just simplified the Code by using an existing JRE method.

String str = new String(data, cset);
String newStr = str.replaceAll(pattern, replacement);
BufferedWriter writer = Files.newBufferedWriter(path, cset);
writer.write(newStr);
Copy link
Member

Choose a reason for hiding this comment

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

if we've got the full string in memory... why buffer? why not just use Files.write(...)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see comment above

String name = file.getName();
name = name.replace("_PACKAGENAME_", packageBaseName.replace('.', File.separatorChar));
File newFile = new File(file.getParentFile(), name);
newFile.getParentFile().mkdirs();
Copy link
Member

Choose a reason for hiding this comment

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

consider using java.nio.Files.createDirectories(..) here - the Files class will throw instead of silently fail (or letting you ignore the return value, as you're doing here).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed to createDirectories

- javaProjects as List instead of Array
- Copyright information updated / inserted
- Fixed multithreading bug
- removed xsiframe from gwt.xml file
- replaced mkdirs() with Files.createDirectories()
- Use UTF-8 instead of defaultCharset
-Use Files.writeString() instead of BufferedWriter
- all renaming of files is done  by using the same method.
- allow filenames to contain the placeholder _PROJECTNAME_
@keinhaar
Copy link
Contributor Author

It just uses modified versions of the files that are created by the sdk

Just use the archetype creators for generating the template files:

* https://github.com/tbroyer/gwt-maven-archetypes (Tomcat)

* https://github.com/NaluKit/gwt-maven-springboot-archetype (Spring Boot)

These are the suggested way creating a new project: https://www.gwtproject.org/gettingstarted-v2.html

I've created a maven based template using the instructions on the gettingstarted-v2 page. It runs just fine if used with maven, but there are some problems running it from eclipse:

  1. It uses the jakarta enabled version of gwt-servlet, which is currently not supported by the plugin (maybe if you rename it manually?)
  2. The module.gwt.xml specifies an empty source path, which will not be accepted when running from eclipse
  3. The Eclipse Plugin can't create a valid launch command. I was able to create it manually and it works, but then maven will no longer work because of the changed source path.

To make it work from eclipse the following steps are required:

  • change <source path=""/> to <source path="MAINPACKAGE"/>
  • create a launcher manually with these arguments:
    -remoteUI "${gwt_remote_ui_server_port}:${unique_id}" -startupUrl index.html -logLevel INFO -codeServerPort 9997 -port 8888 -war /YOURPATH/PROJECTNAME/PROJECTNAME-server/src/main/webapp module module

I'm in doubt if i should add it in this state.
Because i don't use maven, some maven user may decide this. @protoism, @FrankHossfeld? What do you think?

@keinhaar
Copy link
Contributor Author

@protoism
I've fixed all the things that collin suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants