Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
asbachb committed Jun 9, 2023
1 parent 5204c51 commit 9a19f16
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.netbeans.api.j2ee.core.DeploymentDescriptors;
import org.netbeans.api.j2ee.core.Profile;
import org.netbeans.api.project.Project;
import org.netbeans.modules.j2ee.api.ejbjar.Ear;
Expand All @@ -42,6 +46,12 @@ public class DDHelper {

private static final String RESOURCE_FOLDER = "/org/netbeans/modules/j2ee/common/dd/resources/"; //NOI18N

private static final List <Profile> WEBXML_REQUIREMENTS_INDEPENDANT_PROFILES = List.of(
Profile.JAVA_EE_5,
Profile.J2EE_14,
Profile.J2EE_13
);

private DDHelper() {
}

Expand All @@ -58,36 +68,23 @@ public static FileObject createWebXml(Profile j2eeProfile, FileObject dir) throw

/**
* Creates web.xml deployment descriptor.
* @param j2eeProfile Java EE/Jakarta EE profile to specify which version of web.xml should be created
* @param eeProfile Java EE/Jakarta EE profile to specify which version of web.xml should be created
* @param webXmlRequired true if web.xml should be created also for profiles where it is not required
* @param dir Directory where web.xml should be created
* @return web.xml file as FileObject
* @throws java.io.IOException
*/
public static FileObject createWebXml(Profile j2eeProfile, boolean webXmlRequired, FileObject dir) throws IOException {
String template = null;
if ((Profile.JAKARTA_EE_10_FULL == j2eeProfile || Profile.JAKARTA_EE_10_WEB == j2eeProfile) && webXmlRequired) {
template = "web-6.0.xml"; //NOI18N
} else if ((Profile.JAKARTA_EE_9_1_FULL == j2eeProfile || Profile.JAKARTA_EE_9_1_WEB == j2eeProfile ||
Profile.JAKARTA_EE_9_FULL == j2eeProfile || Profile.JAKARTA_EE_9_WEB == j2eeProfile) && webXmlRequired) {
template = "web-5.0.xml"; //NOI18N
} else if ((Profile.JAKARTA_EE_8_FULL == j2eeProfile || Profile.JAKARTA_EE_8_WEB == j2eeProfile ||
Profile.JAVA_EE_8_FULL == j2eeProfile || Profile.JAVA_EE_8_WEB == j2eeProfile) && webXmlRequired) {
template = "web-4.0.xml"; //NOI18N
} else if ((Profile.JAVA_EE_7_FULL == j2eeProfile || Profile.JAVA_EE_7_WEB == j2eeProfile) && webXmlRequired) {
template = "web-3.1.xml"; //NOI18N
} else if ((Profile.JAVA_EE_6_FULL == j2eeProfile || Profile.JAVA_EE_6_WEB == j2eeProfile) && webXmlRequired) {
template = "web-3.0.xml"; //NOI18N
} else if (Profile.JAVA_EE_5 == j2eeProfile) {
template = "web-2.5.xml"; //NOI18N
} else if (Profile.J2EE_14 == j2eeProfile) {
template = "web-2.4.xml"; //NOI18N
} else if (Profile.J2EE_13 == j2eeProfile) {
template = "web-2.3.xml"; //NOI18N
public static FileObject createWebXml(Profile eeProfile, boolean webXmlRequired, FileObject dir) throws IOException {
if (!webXmlRequired && !WEBXML_REQUIREMENTS_INDEPENDANT_PROFILES.contains(eeProfile)) {
return null;
}
if (template == null)

String webDDVersion = eeProfile.getDeploymentDescriptors().get(DeploymentDescriptors.Type.WEB);
if (webDDVersion == null) {
return null;
}

String template = String.format("web-%s.xml",webDDVersion);
MakeFileCopy action = new MakeFileCopy(RESOURCE_FOLDER + template, dir, "web.xml");
FileUtil.runAtomicAction(action);
if (action.getException() != null)
Expand All @@ -98,29 +95,18 @@ public static FileObject createWebXml(Profile j2eeProfile, boolean webXmlRequire

/**
* Creates web-fragment.xml deployment descriptor.
* @param j2eeProfile Java EE/Jakarta EE profile to specify which version of web-fragment.xml should be created
* @param eeProfile Java EE/Jakarta EE profile to specify which version of web-fragment.xml should be created
* @param dir Directory where web-fragment.xml should be created
* @return web-fragment.xml file as FileObject
* @throws java.io.IOException
*/
public static FileObject createWebFragmentXml(Profile j2eeProfile, FileObject dir) throws IOException {
String template = null;
if (Profile.JAKARTA_EE_10_FULL == j2eeProfile || Profile.JAKARTA_EE_10_WEB == j2eeProfile) {
template = "web-fragment-6.0.xml"; //NOI18N
} else if (Profile.JAKARTA_EE_9_1_FULL == j2eeProfile || Profile.JAKARTA_EE_9_1_WEB == j2eeProfile ||
Profile.JAKARTA_EE_9_FULL == j2eeProfile || Profile.JAKARTA_EE_9_WEB == j2eeProfile) {
template = "web-fragment-5.0.xml"; //NOI18N
} else if (Profile.JAKARTA_EE_8_FULL == j2eeProfile || Profile.JAKARTA_EE_8_WEB == j2eeProfile ||
Profile.JAVA_EE_8_FULL == j2eeProfile || Profile.JAVA_EE_8_WEB == j2eeProfile) {
template = "web-fragment-4.0.xml"; //NOI18N
} else if (Profile.JAVA_EE_7_FULL == j2eeProfile || Profile.JAVA_EE_7_WEB == j2eeProfile) {
template = "web-fragment-3.1.xml"; //NOI18N
} else if (Profile.JAVA_EE_6_FULL == j2eeProfile || Profile.JAVA_EE_6_WEB == j2eeProfile) {
template = "web-fragment-3.0.xml"; //NOI18N
}
if (template == null)
public static FileObject createWebFragmentXml(Profile eeProfile, FileObject dir) throws IOException {
String webFragmentDDVersion = eeProfile.getDeploymentDescriptors().get(DeploymentDescriptors.Type.WEB_FRAGMENT);
if (webFragmentDDVersion == null) {
return null;
}

String template = String.format("web-fragment-%s.xml", webFragmentDDVersion);
MakeFileCopy action = new MakeFileCopy(RESOURCE_FOLDER + template, dir, "web-fragment.xml");
FileUtil.runAtomicAction(action);
if (action.getException() != null)
Expand All @@ -143,32 +129,20 @@ public static FileObject createBeansXml(Profile j2eeProfile, FileObject dir) thr

/**
* Creates beans.xml deployment descriptor.
* @param j2eeProfile Java EE/Jakarta EE profile to specify which version of beans.xml should be created
* @param eeProfile Java EE/Jakarta EE profile to specify which version of beans.xml should be created
* @param dir Directory where beans.xml should be created
* @param name name of configuration file to create; should be always "beans" for now
* @return beans.xml file as FileObject
* @throws java.io.IOException
* @since 1.49
*/
public static FileObject createBeansXml(Profile j2eeProfile, FileObject dir, String name) throws IOException {
String template = null;
if (Profile.JAKARTA_EE_10_FULL == j2eeProfile || Profile.JAKARTA_EE_10_WEB == j2eeProfile) {
template = "beans-4.0.xml"; //NOI18N
} else if (Profile.JAKARTA_EE_9_1_FULL == j2eeProfile || Profile.JAKARTA_EE_9_1_WEB == j2eeProfile ||
Profile.JAKARTA_EE_9_FULL == j2eeProfile || Profile.JAKARTA_EE_9_WEB == j2eeProfile) {
template = "beans-3.0.xml"; //NOI18N
} else if (Profile.JAKARTA_EE_8_FULL == j2eeProfile || Profile.JAKARTA_EE_8_WEB == j2eeProfile ||
Profile.JAVA_EE_8_FULL == j2eeProfile || Profile.JAVA_EE_8_WEB == j2eeProfile) {
template = "beans-2.0.xml"; //NOI18N
} else if (Profile.JAVA_EE_7_FULL == j2eeProfile || Profile.JAVA_EE_7_WEB == j2eeProfile) {
template = "beans-1.1.xml"; //NOI18N
} else if (Profile.JAVA_EE_6_FULL == j2eeProfile || Profile.JAVA_EE_6_WEB == j2eeProfile) {
template = "beans-1.0.xml"; //NOI18N
}

if (template == null)
public static FileObject createBeansXml(Profile eeProfile, FileObject dir, String name) throws IOException {
String beansDDVersion = eeProfile.getDeploymentDescriptors().get(DeploymentDescriptors.Type.WEB_FRAGMENT);
if (beansDDVersion == null) {
return null;
}

String template = String.format("beans-%s.xml", beansDDVersion);
MakeFileCopy action = new MakeFileCopy(RESOURCE_FOLDER + template, dir, name+".xml");
FileUtil.runAtomicAction(action);
if (action.getException() != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.api.j2ee.core;

/**
* This class contains information about which schema version is used for a
* specific Java EE or Jakarta EE version.
*
* @author Benjamin Asbach
*/
public class DeploymentDescriptors {

public enum Type {
WEB,
WEB_FRAGMENT,
BEANS;
}
}
145 changes: 125 additions & 20 deletions enterprise/j2ee.core/src/org/netbeans/api/j2ee/core/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
package org.netbeans.api.j2ee.core;

import java.util.Comparator;
import java.util.Map;
import static java.util.Map.entry;
import org.netbeans.api.annotations.common.CheckForNull;
import org.netbeans.api.annotations.common.NonNull;
import org.netbeans.api.annotations.common.NullAllowed;
import static org.netbeans.api.j2ee.core.DeploymentDescriptors.Type.BEANS;
import static org.netbeans.api.j2ee.core.DeploymentDescriptors.Type.WEB;
import static org.netbeans.api.j2ee.core.DeploymentDescriptors.Type.WEB_FRAGMENT;
import org.openide.util.NbBundle;
import org.openide.util.NbBundle.Messages;

Expand All @@ -36,70 +41,168 @@ public enum Profile {
// !!! ATTENTION: BE AWARE OF THE ENUM ORDER! It controls compatibility and UI position.
// Do not ever change name of this constant - it is copied from j2eeserver
@Messages("J2EE_13.displayName=J2EE 1.3")
J2EE_13("1.3"),
J2EE_13("1.3",
Map.of(WEB, "2.3")
),

// Do not ever change name of this constant - it is copied from j2eeserver
@Messages("J2EE_14.displayName=J2EE 1.4")
J2EE_14("1.4"),
J2EE_14("1.4",
Map.of(WEB, "2.4")
),

// Do not ever change name of this constant - it is copied from j2eeserver
@Messages("JAVA_EE_5.displayName=Java EE 5")
JAVA_EE_5("1.5"),
JAVA_EE_5("1.5",
Map.of(WEB, "2.5")
),

@Messages("JAVA_EE_6_WEB.displayName=Java EE 6 Web")
JAVA_EE_6_WEB("1.6", "web"),
JAVA_EE_6_WEB("1.6", "web",
Map.ofEntries(
entry(WEB, "3.0"),
entry(WEB_FRAGMENT, "3.0"),
entry(BEANS, "1.0")
)
),

@Messages("JAVA_EE_6_FULL.displayName=Java EE 6")
JAVA_EE_6_FULL("1.6"),
JAVA_EE_6_FULL("1.6",
Map.ofEntries(
entry(WEB, "3.0"),
entry(WEB_FRAGMENT, "3.0"),
entry(BEANS, "1.0")
)
),

@Messages("JAVA_EE_7_WEB.displayName=Java EE 7 Web")
JAVA_EE_7_WEB("1.7", "web"),
JAVA_EE_7_WEB("1.7", "web",
Map.ofEntries(
entry(WEB, "3.1"),
entry(WEB_FRAGMENT, "3.1"),
entry(BEANS, "1.1")
)
),

@Messages("JAVA_EE_7_FULL.displayName=Java EE 7")
JAVA_EE_7_FULL("1.7"),
JAVA_EE_7_FULL("1.7",
Map.ofEntries(
entry(WEB, "3.1"),
entry(WEB_FRAGMENT, "3.1"),
entry(BEANS, "1.1")
)
),

@Messages("JAVA_EE_8_WEB.displayName=Java EE 8 Web")
JAVA_EE_8_WEB("1.8", "web"),
JAVA_EE_8_WEB("1.8", "web",
Map.ofEntries(
entry(WEB, "4.0"),
entry(WEB_FRAGMENT, "4.0"),
entry(BEANS, "2.0")
)
),

@Messages("JAVA_EE_8_FULL.displayName=Java EE 8")
JAVA_EE_8_FULL("1.8"),
JAVA_EE_8_FULL("1.8",
Map.ofEntries(
entry(WEB, "4.0"),
entry(WEB_FRAGMENT, "4.0"),
entry(BEANS, "2.0")
)
),

@Messages("JAKARTA_EE_8_WEB.displayName=Jakarta EE 8 Web")
JAKARTA_EE_8_WEB("8.0", "web"),
JAKARTA_EE_8_WEB("8.0", "web",
Map.ofEntries(
entry(WEB, "4.0"),
entry(WEB_FRAGMENT, "4.0"),
entry(BEANS, "2.0")
)
),

@Messages("JAKARTA_EE_8_FULL.displayName=Jakarta EE 8")
JAKARTA_EE_8_FULL("8.0"),
JAKARTA_EE_8_FULL("8.0",
Map.ofEntries(
entry(WEB, "4.0"),
entry(WEB_FRAGMENT, "4.0"),
entry(BEANS, "2.0")
)
),

@Messages("JAKARTA_EE_9_WEB.displayName=Jakarta EE 9 Web")
JAKARTA_EE_9_WEB("9.0", "web"),
JAKARTA_EE_9_WEB("9.0", "web",
Map.ofEntries(
entry(WEB, "5.0"),
entry(WEB_FRAGMENT, "5.0"),
entry(BEANS, "3.0")
)
),

@Messages("JAKARTA_EE_9_FULL.displayName=Jakarta EE 9")
JAKARTA_EE_9_FULL("9.0"),
JAKARTA_EE_9_FULL("9.0",
Map.ofEntries(
entry(WEB, "5.0"),
entry(WEB_FRAGMENT, "5.0"),
entry(BEANS, "3.0")
)
),

@Messages("JAKARTA_EE_9_1_WEB.displayName=Jakarta EE 9.1 Web")
JAKARTA_EE_9_1_WEB("9.1", "web"),
JAKARTA_EE_9_1_WEB("9.1", "web",
Map.ofEntries(
entry(WEB, "5.0"),
entry(WEB_FRAGMENT, "5.0"),
entry(BEANS, "3.0")
)
),

@Messages("JAKARTA_EE_9_1_FULL.displayName=Jakarta EE 9.1")
JAKARTA_EE_9_1_FULL("9.1"),
JAKARTA_EE_9_1_FULL("9.1",
Map.ofEntries(
entry(WEB, "5.0"),
entry(WEB_FRAGMENT, "5.0"),
entry(BEANS, "3.0")
)
),

@Messages("JAKARTA_EE_10_WEB.displayName=Jakarta EE 10 Web")
JAKARTA_EE_10_WEB("10", "web"),
JAKARTA_EE_10_WEB("10", "web",
Map.ofEntries(
entry(WEB, "6.0"),
entry(WEB_FRAGMENT, "6.0"),
entry(BEANS, "4.0")
)
),

@Messages("JAKARTA_EE_10_FULL.displayName=Jakarta EE 10")
JAKARTA_EE_10_FULL("10");
JAKARTA_EE_10_FULL("10",
Map.ofEntries(
entry(WEB, "6.0"),
entry(WEB_FRAGMENT, "6.0"),
entry(BEANS, "4.0")
)
);
// !!! ATTENTION: BE AWARE OF THE ENUM ORDER! It controls compatibility and UI position.

public static final Comparator<Profile> UI_COMPARATOR = (Profile o1, Profile o2) -> -(o1.ordinal() - o2.ordinal());

// cache
private final String propertiesString;

private Profile(String canonicalName) {
this.propertiesString = canonicalName;
private final Map<DeploymentDescriptors.Type, String> deploymentDescriptors;

private Profile(String version, Map<DeploymentDescriptors.Type, String> deploymentDescriptors) {
this.propertiesString = version;
this.deploymentDescriptors = deploymentDescriptors;
}

private Profile(String canonicalName, String profile) {
private Profile(String canonicalName, String profile, Map<DeploymentDescriptors.Type, String> deploymentDescriptors) {
this.propertiesString = canonicalName + "-" + profile;
this.deploymentDescriptors = deploymentDescriptors;
}

public Map<DeploymentDescriptors.Type, String> getDeploymentDescriptors() {
return deploymentDescriptors;
}

/**
Expand Down Expand Up @@ -140,6 +243,8 @@ public boolean isAtLeast(@NonNull Profile profile) {
return this.ordinal() >= profile.ordinal();
}



@Override
public String toString() {
return toPropertiesString();
Expand Down

0 comments on commit 9a19f16

Please sign in to comment.