Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
[98028648] NPE when attempting to link a non-faceted project
Browse files Browse the repository at this point in the history
  • Loading branch information
elsony committed Jul 24, 2015
1 parent 5491b40 commit 5705a2b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 34 deletions.
Expand Up @@ -190,6 +190,34 @@ public void updateApplicationModule(CloudFoundryApplicationModule module) {
}
}

/** Convenience method to determine if a module is for a non-faceted project */
public static boolean isNonfacetedModule(IModule module) {
boolean isNonfacetedProjResult = false;

// Workaround - Remove the following and use the above commented
// out code
ClassLoader classLoader = module.getClass().getClassLoader();
if (classLoader != null) {
try {
Class iModule2 = classLoader.loadClass("org.eclipse.wst.server.core.IModule2"); //$NON-NLS-1$
if (iModule2 != null) {
Method getProperty = iModule2.getMethod("getProperty", String.class); //$NON-NLS-1$
Object o = getProperty.invoke(module, CloudFoundryConstants.PROPERTY_MODULE_NO_FACET);
if (o instanceof String && ((String) o).equals("true")) { //$NON-NLS-1$
isNonfacetedProjResult = true;
}
}
}
catch (Exception e) {
// If any issues, just go ahead and do the facet check
// below
}
}
// End of workaround

return isNonfacetedProjResult;
}

@Override
public IStatus canModifyModules(IModule[] add, IModule[] remove) {
if (add != null) {
Expand All @@ -205,39 +233,8 @@ public IStatus canModifyModules(IModule[] add, IModule[] remove) {
IStatus status;
// If the module, in a non-faceted project, has been determined
// to be deployable to CF (ie. a single zip application
// archive), then
// this facet check is unnecessary.
boolean ignoreFacetCheck = false;
// FIXNS: Enable with IModule2 workaround is in place, as its
// not available in Eclipse 4.3 and older.
// if (module instanceof IModule2) {
// String property =
// ((IModule2)module).getProperty(CloudFoundryConstants.PROPERTY_MODULE_NO_FACET);
// if (property != null && property.equals("true")) {
// ignoreFacetCheck = true;
// }
// }

// Workaround - Remove the following and use the above commented
// out code
ClassLoader classLoader = module.getClass().getClassLoader();
if (classLoader != null) {
try {
Class iModule2 = classLoader.loadClass("org.eclipse.wst.server.core.IModule2"); //$NON-NLS-1$
if (iModule2 != null) {
Method getProperty = iModule2.getMethod("getProperty", String.class); //$NON-NLS-1$
Object o = getProperty.invoke(module, CloudFoundryConstants.PROPERTY_MODULE_NO_FACET);
if (o instanceof String && ((String) o).equals("true")) { //$NON-NLS-1$
ignoreFacetCheck = true;
}
}
}
catch (Exception e) {
// If any issues, just go ahead and do the facet check
// below
}
}
// End of workaround
// archive), then this facet check is unnecessary.
boolean ignoreFacetCheck = isNonfacetedModule(module);

if (module.getProject() != null && !ignoreFacetCheck) {
status = FacetUtil.verifyFacets(module.getProject(), getServer());
Expand Down
Expand Up @@ -952,6 +952,7 @@ public class Messages extends NLS {
public static String MANAGE_SERVICES_TO_APPLICATIONS_FINISH_ERROR_DESCRIPTION;

public static String UPDATE_PROJECT_MAPPING;
public static String REMOVE_PROJECT_MAPPING;

public static String CloudFoundryServiceWizardPage_GETTING_AVAILABLE_SERVICES;

Expand Down
Expand Up @@ -471,6 +471,7 @@ MANAGE_SERVICES_TO_APPLICATIONS_GET_APPLICATION_NAMES=Loading application names
MANAGE_SERVICES_TO_APPLICATIONS_FINISH_ERROR_TITLE=Error Processing Applications for Service Binding
MANAGE_SERVICES_TO_APPLICATIONS_FINISH_ERROR_DESCRIPTION=An exception has occurred when processing the applications for service binding. Please enable logging to see the exception details.
UPDATE_PROJECT_MAPPING=Linking project with {0}
REMOVE_PROJECT_MAPPING=Unlinking project {0}

# Service Wizard
CloudFoundryServiceWizard_JOB_SUBTASK_VERIFYING_SERVICES=Verifying services
Expand Down
Expand Up @@ -48,6 +48,8 @@
import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.eclipse.ui.model.WorkbenchViewerComparator;
import org.eclipse.wst.common.project.facet.core.IFacetedProject;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.eclipse.wst.server.core.IModule;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.IServerWorkingCopy;
Expand Down Expand Up @@ -166,9 +168,30 @@ public boolean select(Viewer viewer, Object parent, Object element) {
if (element instanceof IProject) {
potentialProject = (IProject) element;
}

if (potentialProject == null || !potentialProject.isAccessible()) {
return false;
}

// If a module is set as nonfaceted, we do not need to check it.
if(!CloudFoundryServer.isNonfacetedModule(appModule)) {

// .. otherwise, all projects should be faceted.
IFacetedProject facetedProject;
try {
facetedProject = ProjectFacetsManager.create(potentialProject);

if(facetedProject == null) {
// Unfaceted projects are not supported, so return false.
return false;
}
} catch (CoreException e) {
// If an error occurs when attempting to convert an individual project, then
// it likely is not supported (for example, not faceted), so return false.
return false;
}
}

// Allow mapping a project with the same name as the app. This
// case needs to be handled first before checking for other
// potentially unrelated
Expand Down Expand Up @@ -291,4 +314,5 @@ public void run() {
return null;
}


}
Expand Up @@ -50,7 +50,7 @@ public void run() {
final CloudFoundryApplicationModule appModule = cloudServer.getExistingCloudModule(module);
if (appModule != null && editorPage.getSite() != null && editorPage.getSite().getShell() != null) {

Job job = new Job(NLS.bind(Messages.UPDATE_PROJECT_MAPPING, appModule.getDeployedApplicationName())) {
Job job = new Job(NLS.bind(Messages.REMOVE_PROJECT_MAPPING, appModule.getDeployedApplicationName())) {
protected IStatus run(IProgressMonitor monitor) {
try {
new UnmapProjectOperation(appModule, editorPage.getCloudServer()).run(monitor);
Expand Down
Expand Up @@ -43,6 +43,9 @@ protected IStatus run(IProgressMonitor monitor) {
}
catch (CoreException e) {
CloudFoundryPlugin.logError(e);
if(e.getStatus() != null) {
return e.getStatus();
}
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
Expand Down

0 comments on commit 5705a2b

Please sign in to comment.