Skip to content

Commit

Permalink
Added Template based Project Wizard (gwt-plugins#499)
Browse files Browse the repository at this point in the history
* Added Template based Project Wizard

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

* Updated eclipse base to 2023-09

* Fixed things from review

- 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

* Unified the File renaming

- all renaming of files is done  by using the same method.
- allow filenames to contain the placeholder _PROJECTNAME_
keinhaar authored Dec 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent b145af7 commit 55fdf22
Showing 29 changed files with 1,861 additions and 162 deletions.
Original file line number Diff line number Diff line change
@@ -25,10 +25,10 @@

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.List;

/**
* Creates web app projects populated with files relevant to the selected natures.
@@ -56,10 +56,6 @@ public interface Participant {

void addContainerPath(IPath containerPath);

void addFile(IPath path, InputStream inputStream);

void addFile(IPath path, String content) throws UnsupportedEncodingException;

void addNature(String natureId);

/**
@@ -86,10 +82,6 @@ void create(IProgressMonitor monitor) throws CoreException, MalformedURLExceptio

void setProjectName(String projectName);

void setTemplates(String... templates);

void setTemplateSources(String... sources);

/**
* Build an Ant project.
*
@@ -105,25 +97,24 @@ void create(IProgressMonitor monitor) throws CoreException, MalformedURLExceptio
void setBuildMaven(boolean buildMaven);

/**
* Returns the created Java project. This is available half way through the creation process.
*
* @return the java projeect.
* Returns the created Java projects. This is available half way through the creation process.
* @return the java project.
*/
IJavaProject getCreatedJavaProject();
List<IJavaProject> getCreatedJavaProjects();

/**
* Returns build a Maven Project.
*
* @return Maven selected
*/
boolean getBuildMaven();
boolean isBuildMaven();

/**
* Returns build an ant project.
*
* @return Ant selected
*/
boolean getBuiltAnt();
boolean isBuiltAnt();

/**
* Returns the Creation progress monitor.
Original file line number Diff line number Diff line change
@@ -26,19 +26,19 @@
import org.eclipse.jface.text.Document;
import org.eclipse.text.edits.TextEdit;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.List;
import java.util.Vector;

/**
* Generates source for files needed by web application projects.
*
*
* TODO: Convert these use to use templates.
*/
@SuppressWarnings("restriction")
@@ -128,13 +128,13 @@ public static List<File> findFilesInDir(File directory, FilenameFilter filter) {
/**
* Given a java.io.File containing Java source, call the Eclipse auto-format
* code on that source and write it back to disk.
*
*
* @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());
String reformattedSource = reformatJavaSourceAsString(generatedSource);
if (!reformattedSource.equals(generatedSource)) {
writeStringToFile(reformattedSource, file);
@@ -166,32 +166,6 @@ public static String reformatJavaSourceAsString(String source) {
return source;
}

/*
* TODO: These next two methods might be useful somewhere else in the
* future, but right now, this is the only place where we need to do I/O on
* java.io.Files instead of Eclipse resources.
*/
private static String textFromFile(File file) throws IOException {
char bytes[] = new char[1024];
int nread;
StringBuilder builder = new StringBuilder();

BufferedReader reader = null;
try {
reader = new BufferedReader(new FileReader(file));
while ((nread = reader.read(bytes, 0, 1024)) != -1) {
char toAppend[] = new char[nread];
System.arraycopy(bytes, 0, toAppend, 0, nread);
builder.append(toAppend);
}
} finally {
if (reader != null) {
reader.close();
}
}
return builder.toString();
}

private static void writeStringToFile(String string, File file)
throws IOException {
BufferedWriter bw = null;
Original file line number Diff line number Diff line change
@@ -17,19 +17,21 @@
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.project.IProjectConfigurationManager;

import java.util.List;

public class MavenEnablingWebAppCreatorParicipant implements IWebAppProjectCreator.Participant {

private IJavaProject javaProject;
private List<IJavaProject> javaProjects;

@Override
public void updateWebAppProjectCreator(IWebAppProjectCreator webAppProjectCreator) {
boolean buildMaven = webAppProjectCreator.getBuildMaven();
boolean buildMaven = webAppProjectCreator.isBuildMaven();
if (!buildMaven) {
return;
}

javaProject = webAppProjectCreator.getCreatedJavaProject();
if (javaProject == null) {
javaProjects = webAppProjectCreator.getCreatedJavaProjects();
if (javaProjects == null) {
return;
}

@@ -42,7 +44,10 @@ private void runJob() {
protected IStatus run(IProgressMonitor monitor) {
// Turn on the Maven nature
try {
NatureUtils.addNature(javaProject.getProject(), MavenUtils.MAVEN2_NATURE_ID);
for(int i=0;i<javaProjects.size();i++)
{
NatureUtils.addNature(javaProjects.get(i).getProject(), MavenUtils.MAVEN2_NATURE_ID);
}
} catch (CoreException e1) {
e1.printStackTrace();
return Status.CANCEL_STATUS;
@@ -53,7 +58,10 @@ protected IStatus run(IProgressMonitor monitor) {
// Maven update project will add the Maven dependencies to the classpath
IProjectConfigurationManager projectConfig = MavenPlugin.getProjectConfigurationManager();
try {
projectConfig.updateProjectConfiguration(javaProject.getProject(), monitor);
for(int i=0;i<javaProjects.size();i++)
{
projectConfig.updateProjectConfiguration(javaProjects.get(i).getProject(), monitor);
}
} catch (CoreException e) {
// TODO(${user}): Auto-generated catch block
e.printStackTrace();
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
eclipse.preferences.version=1
encoding//project_templates/client_server_shared/client/.settings/org.eclipse.jdt.core.prefs=UTF-8
encoding//project_templates/client_server_shared/server/.settings/org.eclipse.jdt.core.prefs=UTF-8
encoding//project_templates/client_server_shared/shared/.settings/org.eclipse.jdt.core.prefs=UTF-8
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -40,5 +40,7 @@ Require-Bundle:
com.gwtplugins.gdt.eclipse.platform,
org.eclipse.equinox.common,
system.bundle,
org.eclipse.core.runtime
org.eclipse.core.runtime,
org.jdom2,
org.apache.commons.commons-io
Import-Package: org.eclipse.core.runtime.preferences
3 changes: 2 additions & 1 deletion plugins/com.gwtplugins.gdt.eclipse.suite/build.properties
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ bin.includes = META-INF/,\
plugin.xml,\
icons/,\
about.ini,\
plugin.properties
plugin.properties,\
project_templates/
javacSource=11
javacTarget=11
21 changes: 21 additions & 0 deletions plugins/com.gwtplugins.gdt.eclipse.suite/plugin.xml
Original file line number Diff line number Diff line change
@@ -200,6 +200,15 @@
id="com.gwtplugins.gdt.eclipse.suite.newWizards"
name="%gwt.label.new">
</category>
<wizard
category="com.gwtplugins.gdt.eclipse.suite.newWizards"
class="com.google.gdt.eclipse.suite.wizards.NewWebAppTemplateProjectWizard"
icon="icons/gdt-new-project_16x16.png"
id="com.gwtplugins.gdt.eclipse.suite.wizards.newMultiProjectWizard"
name="GWT Template based Project"
preferredPerspectives="org.eclipse.jdt.ui.JavaPerspective"
project="true">
</wizard>
<wizard
category="com.gwtplugins.gdt.eclipse.suite.newWizards"
class="com.google.gdt.eclipse.suite.wizards.NewWebAppProjectWizard"
@@ -223,24 +232,36 @@
point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension
targetID="org.eclipse.jdt.ui.JavaPerspective">
<newWizardShortcut
id="com.gwtplugins.gdt.eclipse.suite.wizards.newMultiProjectWizard">
</newWizardShortcut>
<newWizardShortcut
id="com.gwtplugins.gdt.eclipse.suite.wizards.newProjectWizard">
</newWizardShortcut>
</perspectiveExtension>
<perspectiveExtension
targetID="org.eclipse.jdt.ui.JavaBrowsingPerspective">
<newWizardShortcut
id="com.gwtplugins.gdt.eclipse.suite.wizards.newMultiProjectWizard">
</newWizardShortcut>
<newWizardShortcut
id="com.gwtplugins.gdt.eclipse.suite.wizards.newProjectWizard">
</newWizardShortcut>
</perspectiveExtension>
<perspectiveExtension
targetID="org.eclipse.jdt.ui.JavaHierarchyPerspective">
<newWizardShortcut
id="com.gwtplugins.gdt.eclipse.suite.wizards.newMultiProjectWizard">
</newWizardShortcut>
<newWizardShortcut
id="com.gwtplugins.gdt.eclipse.suite.wizards.newProjectWizard">
</newWizardShortcut>
</perspectiveExtension>
<perspectiveExtension
targetID="org.eclipse.jst.j2ee.J2EEPerspective">
<newWizardShortcut
id="com.gwtplugins.gdt.eclipse.suite.wizards.newMultiProjectWizard">
</newWizardShortcut>
<newWizardShortcut
id="com.gwtplugins.gdt.eclipse.suite.wizards.newProjectWizard">
</newWizardShortcut>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
When updating your version of GWT, you should also update this DTD reference,
so that your app can take advantage of the latest GWT module capabilities.
-->
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.10.0//EN"
"http://gwtproject.org/doctype/2.10.0/gwt-module.dtd">
<module rename-to='example'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>

<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->

<!-- Other module inherits -->
<inherits name='${PACKAGENAME}.shared'/>

<!-- Specify the app entry point class. -->
<entry-point class='${PACKAGENAME}.ui.Main'/>

<!-- Specify the paths for translatable code -->
<source path='ui'/>
</module>
Loading

0 comments on commit 55fdf22

Please sign in to comment.