Skip to content

Commit

Permalink
Merge pull request #4147 from vieiro/hotfix/3809
Browse files Browse the repository at this point in the history
JavaWithMaven / POM Project
  • Loading branch information
ebarboni authored May 30, 2022
2 parents f446338 + fcbe2f8 commit cc14a92
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,27 +255,29 @@ private static void setMainClass(Map<Object, Object> properties, FileObject fo)
POMModel model = POMModelFactory.getDefault().getModel(modelSource);
org.netbeans.modules.maven.model.pom.Project root = model.getProject();
if (root != null) {
if (model.startTransaction()) {
try {
org.netbeans.modules.maven.model.pom.Properties props = root.getProperties();
if (props == null) {
props = model.getFactory().createProperties();
root.setProperties(props);
}
String packageName = (String) properties.get(TemplateUtils.PARAM_PACKAGE);
String mainClass = (String) properties.get(TemplateUtils.PARAM_MAIN_CLASS_NAME);
if (mainClass == null || mainClass.isEmpty()) {
mainClass = "App"; // NOI18N
}
if (packageName != null && !packageName.isEmpty()) {
mainClass = packageName + '.' + mainClass;
}
props.setProperty("exec.mainClass", mainClass); // NOI18N
} finally {
model.endTransaction();
if (model.getProject().getPackaging() == null || "jar".equals(model.getProject().getPackaging())) {
if (model.startTransaction()) {
try {
Utilities.saveChanges(model);
} catch (IOException ex) {}
org.netbeans.modules.maven.model.pom.Properties props = root.getProperties();
if (props == null) {
props = model.getFactory().createProperties();
root.setProperties(props);
}
String packageName = (String) properties.get(TemplateUtils.PARAM_PACKAGE);
String mainClass = (String) properties.get(TemplateUtils.PARAM_MAIN_CLASS_NAME);
if (mainClass == null || mainClass.isEmpty()) {
mainClass = "App"; // NOI18N
}
if (packageName != null && !packageName.isEmpty()) {
mainClass = packageName + '.' + mainClass;
}
props.setProperty("exec.mainClass", mainClass); // NOI18N
} finally {
model.endTransaction();
try {
Utilities.saveChanges(model);
} catch (IOException ex) {}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ protected FileBuilder builder(ProgressHandle h) throws IOException {

return new FileBuilder(w.getTemplate().getPrimaryFile(), w.getTargetFolder().getPrimaryFile().getParent()).
param(TemplateUtils.PARAM_PACKAGE, (String) wiz.getProperty("package")).
param(TemplateUtils.PARAM_PACKAGING, (String) this.packaging).
defaultMode(FileBuilder.Mode.COPY).
name(w.getTargetName()).
useLookup(Lookups.fixed(h));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,18 @@ protected List<FileObject> createProjectContents(FileObject target, CreateDescri
params.put("projecName", cd.getName());
params.put("packagePath", pi.packageName == null ? "" : pi.packageName.replace('.', '/')); // NOI18N

String mainName;
if (!params.containsKey("mainClassName")) { // NOI18N
String derived = deriveClassName(pi.artifactId);
if (BaseUtilities.isJavaIdentifier(derived)) {
mainName = derived;
} else {
mainName = "App"; // NOI18N
String packaging = cd.getValue(TemplateUtils.PARAM_PACKAGING);
if (packaging == null || "jar".equals(packaging)) { // NOI18N
String mainName;
if (!params.containsKey("mainClassName")) { // NOI18N
String derived = deriveClassName(pi.artifactId);
if (BaseUtilities.isJavaIdentifier(derived)) {
mainName = derived;
} else {
mainName = "App"; // NOI18N
}
params.put("mainClassName", mainName); // NOI18N
}
params.put("mainClassName", mainName); // NOI18N
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@
*
* @author mkleint
*/
@TemplateRegistration(folder=ArchetypeWizards.TEMPLATE_FOLDER, position=980, displayName="#LBL_Maven_POM_Archetype", iconBase="org/netbeans/modules/maven/resources/Maven2Icon.gif", description="pom-root.html")
@TemplateRegistration(
displayName="#LBL_Maven_POM_Archetype",
iconBase="org/netbeans/modules/maven/resources/Maven2Icon.gif",
description="pom-root.html",
folder=ArchetypeWizards.TEMPLATE_FOLDER,
position=980,
createHandlerClass = IDENativeTemplateHandler.class
)
@NbBundle.Messages("LBL_Maven_POM_Archetype=POM Project")
public class PomJavaNativeMWI extends IDENativeMavenWizardIterator {

Expand Down

0 comments on commit cc14a92

Please sign in to comment.