Skip to content

Commit

Permalink
Issue 8 - getInterpretedSpecVersion inconsistent with javadoc (#9)
Browse files Browse the repository at this point in the history
* Bump version for org.eclipse.jst.j2ee

* Clean up whitespace in J2EEArtifactImportDataModelProvider

* Apply generics in J2EEArtifactImportDataModelProvider where easily possible

* Correct getInterpretedSpecVersion(..) in J2EEArtifactImportDataModelProvider to use the highest version when nothing else is known (#8)

Assuming the highest version is the expected behaviour according to the JavaDoc. It is also the the behaviour that was present in 487b0b3 before the changes for Jakarta EE 10 in 9788800 . The changes to support Jakarta EE 10 clamped the version at EE 8.
  • Loading branch information
erik-brangs committed Apr 8, 2024
1 parent cd06b77 commit 006fd3b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion plugins/org.eclipse.jst.j2ee/META-INF/MANIFEST.MF
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name.0
Bundle-SymbolicName: org.eclipse.jst.j2ee; singleton:=true
Bundle-Version: 1.2.1000.qualifier
Bundle-Version: 1.2.1100.qualifier
Bundle-Activator: org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin
Bundle-Vendor: %Bundle-Vendor.0
Bundle-Localization: plugin
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2023 IBM Corporation and others.
* Copyright (c) 2003, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -62,15 +62,15 @@
public abstract class J2EEArtifactImportDataModelProvider extends AbstractDataModelProvider implements IJ2EEComponentImportDataModelProperties, IDataModelListener {

private static final String USE_DEFAULT_PROJECT_NAME = "J2EEArtifactImportDataModelProvider.USE_DEFAULT_PROJECT_NAME"; //$NON-NLS-1$
public static final String FACET_RUNTIME = "IJ2EEArtifactImportDataModelProperties.FACET_RUNTIME"; //$NON-NLS-1$

public static final String FACET_RUNTIME = "IJ2EEArtifactImportDataModelProperties.FACET_RUNTIME"; //$NON-NLS-1$

private IDataModel componentCreationDM;
private Throwable archiveOpenFailure = null;

@Override
public Set getPropertyNames() {
Set propertyNames = super.getPropertyNames();
public Set<String> getPropertyNames() {
Set<String> propertyNames = super.getPropertyNames();
propertyNames.add(FILE_NAME);
propertyNames.add(CLOSE_ARCHIVE_ON_DISPOSE);
propertyNames.add(USE_DEFAULT_PROJECT_NAME);
Expand Down Expand Up @@ -99,7 +99,7 @@ public Object getDefaultProperty(String propertyName) {
}else if( propertyName.equals(COMPONENT)){
String projectName = getStringProperty(PROJECT_NAME);
IProject project = ProjectUtilities.getProject(projectName);
return ComponentCore.createComponent(project);
return ComponentCore.createComponent(project);
}
return super.getDefaultProperty(propertyName);
}
Expand Down Expand Up @@ -205,19 +205,19 @@ protected ArchiveOptions getArchiveOptions(IPath archivePath) throws ArchiveOpen
archiveOptions.setOption(JavaEEArchiveUtilities.DISCRIMINATE_EJB_ANNOTATIONS, Boolean.TRUE);
return archiveOptions;
}

protected ArchiveWrapper openArchiveWrapper(String uri) throws ArchiveOpenFailureException{
IArchive archive = null;
IPath path = new Path(uri);
ArchiveOptions archiveOptions = getArchiveOptions(path);
archive = JavaEEArchiveUtilities.INSTANCE.openArchive(archiveOptions);
archive.setPath(path);
JavaEEQuickPeek jqp = JavaEEArchiveUtilities.INSTANCE.getJavaEEQuickPeek(archive);

if(jqp.getJavaEEVersion() == J2EEConstants.UNKNOWN && jqp.getType() == J2EEConstants.UNKNOWN){
handleUnknownType(jqp);
}

return new ArchiveWrapper(archive);
}
/**
Expand Down Expand Up @@ -287,7 +287,7 @@ public void dispose() {
protected final ArchiveWrapper getArchiveWrapper(){
return (ArchiveWrapper)getProperty(ARCHIVE_WRAPPER);
}

@Override
public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) {
return super.getValidPropertyDescriptors(propertyName);
Expand All @@ -305,13 +305,13 @@ public void propertyChanged(DataModelEvent event) {
}
}
}

protected void refreshInterpretedSpecVersion(){

}

/**
* Updates the Java Facet Version so it is compliant with the Java EE Module version
* Updates the Java Facet Version so it is compliant with the Java EE Module version
*/
protected void updateJavaFacetVersion() {
IProjectFacetVersion javaFacetVersion = null;
Expand Down Expand Up @@ -376,14 +376,14 @@ else if (runtime.supports(JavaFacet.VERSION_11)){
updateWorkingCopyFacetVersion(moduleDM, javaFacetDataModel);
}
}

protected void updateWorkingCopyFacetVersion(IDataModel moduleDM, IDataModel facetDM) {
IProjectFacetVersion facetVersion = (IProjectFacetVersion)facetDM.getProperty(IFacetDataModelProperties.FACET_VERSION);
//[Bug 314162] IFacetedProjectWorkingCopy facet version is not automatically updated so it has to be done manually
IFacetedProjectWorkingCopy fpwc = (IFacetedProjectWorkingCopy)moduleDM.getProperty(IFacetProjectCreationDataModelProperties.FACETED_PROJECT_WORKING_COPY);
fpwc.changeProjectFacetVersion(facetVersion);
}

/**
* Calling this method will fixup the JST facet version if it is incompatible with the selected runtime
* It should be called when the Server Runtime or the Archive properties are set.
Expand All @@ -394,7 +394,7 @@ protected IStatus validateVersionSupportedByServer(){
IDataModel projectModel = model.getNestedModel(NESTED_MODEL_J2EE_COMPONENT_CREATION);
FacetDataModelMap map = (FacetDataModelMap) projectModel.getProperty(IFacetProjectCreationDataModelProperties.FACET_DM_MAP);
Collection projectFacets = (Collection)getProperty(FacetProjectCreationDataModelProvider.REQUIRED_FACETS_COLLECTION);

IRuntime runtime = (IRuntime) getProperty(IFacetProjectCreationDataModelProperties.FACET_RUNTIME);
if(runtime != null){
for(Iterator iterator = projectFacets.iterator(); iterator.hasNext();){
Expand All @@ -403,16 +403,16 @@ protected IStatus validateVersionSupportedByServer(){
if(facetVersion.getProjectFacet().equals(JavaFacet.FACET)){
Set set = Collections.singleton(facetVersion.getProjectFacet());
try {
Set correctSet = runtime.getDefaultFacets(set);
Set<IProjectFacetVersion> correctSet = runtime.getDefaultFacets(set);
IProjectFacetVersion correctVersion = null;
Iterator correctVersions = correctSet.iterator();
Iterator<IProjectFacetVersion> correctVersions = correctSet.iterator();
while(correctVersions.hasNext() && correctVersion == null){
IProjectFacetVersion version = (IProjectFacetVersion)correctVersions.next();
IProjectFacetVersion version = correctVersions.next();
if(version.getProjectFacet().equals(JavaFacet.FACET)){
correctVersion = version;
}
}

if(correctVersion != null){
if(!facetVersion.equals(correctVersion)){
facetDataModel.setProperty(IFacetDataModelProperties.FACET_VERSION, correctVersion);
Expand All @@ -423,7 +423,7 @@ protected IStatus validateVersionSupportedByServer(){
J2EEPlugin.logError(e);
}
}

if(!runtime.supports(facetVersion)){
return WTPCommonPlugin.createErrorStatus( J2EECreationResourceHandler.VERSION_NOT_SUPPORTED );
}
Expand All @@ -432,9 +432,9 @@ protected IStatus validateVersionSupportedByServer(){
}
return OK_STATUS;
}

/**
* If the archive does not have a deployment descriptor, then the
* If the archive does not have a deployment descriptor, then the
* version will be interpreted as the highest version supported
* by the server.
* @return
Expand All @@ -453,6 +453,7 @@ protected JavaEEQuickPeek getInterpretedSpecVersion(ArchiveWrapper wrapper){
final int EE8 = 3;
final int EE9 = 4;
final int EE10 = 5;
final int HIGHEST_EE_VERSION = EE10;
int [] highestJQPVersion = new int[] {
EE5,
EE6,
Expand Down Expand Up @@ -545,10 +546,10 @@ protected JavaEEQuickPeek getInterpretedSpecVersion(ArchiveWrapper wrapper){
if(archive.containsArchiveResource(ddPath)){
return jqp;
}

IRuntime runtime = (IRuntime)getProperty(IFacetProjectCreationDataModelProperties.FACET_RUNTIME);
if(archiveType == JavaEEQuickPeek.CONNECTOR_TYPE || runtime == null || runtime.supports(highestProjectFacetVersion[EE8]) ){
return new JavaEEQuickPeek(jqp.getType(), highestJQPVersion[EE8]);
if(archiveType == JavaEEQuickPeek.CONNECTOR_TYPE || runtime == null || runtime.supports(highestProjectFacetVersion[HIGHEST_EE_VERSION]) ){
return new JavaEEQuickPeek(jqp.getType(), highestJQPVersion[HIGHEST_EE_VERSION]);
} else if(runtime.supports(highestProjectFacetVersion[EE10]) ){
return new JavaEEQuickPeek(jqp.getType(), highestJQPVersion[EE10]);
} else if(runtime.supports(highestProjectFacetVersion[EE9]) ){
Expand Down
2 changes: 1 addition & 1 deletion plugins/org.eclipse.jst.j2ee/pom.xml
Expand Up @@ -21,6 +21,6 @@

<groupId>org.eclipse.webtools.javaee</groupId>
<artifactId>org.eclipse.jst.j2ee</artifactId>
<version>1.2.1000-SNAPSHOT</version>
<version>1.2.1100-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>

0 comments on commit 006fd3b

Please sign in to comment.