public static boolean isLiferayProject(IProject project) { boolean retval = false; if (project == null) { return retval; } try { IFacetedProject facetedProject = ProjectFacetsManager.create(project); if (facetedProject != null) { for (IProjectFacetVersion facet : facetedProject.getProjectFacets()) { IProjectFacet projectFacet = facet.getProjectFacet(); if (projectFacet.getId().startsWith("liferay")) { retval = true; break; } } } } catch (Exception e) { } return retval; }
protected void createInfoGroup(Composite parent) { new Label(parent, SWT.LEFT).setText(Msgs.liferayPluginTypeLabel); final Text pluginTypeLabel = new Text(parent, SWT.READ_ONLY | SWT.BORDER); pluginTypeLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); final IProjectFacet liferayFacet = ProjectUtil.getLiferayFacet(getFacetedProject()); if (liferayFacet != null) { pluginTypeLabel.setText(liferayFacet.getLabel()); } new Label(parent, SWT.LEFT).setText(Msgs.liferayRuntimeLabel); this.runtimeCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY); this.runtimeCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1)); String currentRuntimeName = null; try { ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(getProject()); currentRuntimeName = liferayRuntime.getRuntime().getName(); } catch (Exception e) { ProjectUIPlugin.logError("Could not determine liferay runtime", e); // $NON-NLS-1$ } final List<String> runtimeNames = new ArrayList<String>(); int selectionIndex = -1; for (IRuntime runtime : ServerCore.getRuntimes()) { if (ServerUtil.isLiferayRuntime(runtime)) { runtimeNames.add(runtime.getName()); if (runtime.getName().equals(currentRuntimeName)) { selectionIndex = runtimeNames.size() - 1; } } } if (runtimeNames.size() == 0) { runtimeNames.add("No Liferay runtimes available."); // $NON-NLS-1$ } this.runtimeCombo.setItems(runtimeNames.toArray(new String[0])); if (selectionIndex > -1) { this.runtimeCombo.select(selectionIndex); } }
static class DeploymentTypeValidator implements IValidator { String propertyName; IDataModel model; static final IProjectFacet EJB_FACET = ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_EJB_MODULE); static final IProjectFacetVersion EJB_30 = EJB_FACET.getVersion("3.0"); // $NON-NLS-1$ static final IProjectFacet EAR_FACET = ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_EAR_MODULE); static final IProjectFacetVersion EAR_50 = EAR_FACET.getVersion("5.0"); // $NON-NLS-1$ /** */ public DeploymentTypeValidator(String propertyName, IDataModel model) { this.propertyName = propertyName; this.model = model; } /** @see IValidator#validate(Object, Object) */ public Map<String, IStatus> validate(Object value, Object context) { final String deploymentType = value.toString(); if (!ISeamFacetDataModelProperties.DEPLOY_AS_WAR.equals(deploymentType)) { Object runtimeName = model.getProperty(IFacetProjectCreationDataModelProperties.FACET_RUNTIME); if (runtimeName != null) { IRuntime rt = RuntimeManager.getRuntime(runtimeName.toString()); if (!rt.supports(EJB_30) || !rt.supports(EAR_50)) { return SeamValidatorFactory.createErrormessage( propertyName, new Status( IStatus.ERROR, SeamCorePlugin.PLUGIN_ID, NLS.bind( SeamCoreMessages.SEAM_INSTALL_WIZARD_PAGE_CANNOT_USE_SELECTED_DEPLOYMENT6, new String[] {deploymentType.toUpperCase(), runtimeName.toString()}))); } } } return SeamValidatorFactory.NO_ERRORS; } }
public class WebFacetUtils { public static final IProjectFacet WEB_FACET = ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.DYNAMIC_WEB); public static final IProjectFacet WEBFRAGMENT_FACET = ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.WEBFRAGMENT); public static final IProjectFacetVersion WEB_22 = WEB_FACET.getVersion("2.2"); // $NON-NLS-1$ public static final IProjectFacetVersion WEB_23 = WEB_FACET.getVersion("2.3"); // $NON-NLS-1$ public static final IProjectFacetVersion WEB_24 = WEB_FACET.getVersion("2.4"); // $NON-NLS-1$ public static final IProjectFacetVersion WEB_25 = WEB_FACET.getVersion("2.5"); // $NON-NLS-1$ public static final IProjectFacetVersion WEB_30 = WEB_FACET.getVersion("3.0"); // $NON-NLS-1$ public static final IProjectFacetVersion WEB_31 = WEB_FACET.getVersion("3.1"); // $NON-NLS-1$ public static final IProjectFacetVersion WEBFRAGMENT_30 = WEBFRAGMENT_FACET.getVersion("3.0"); // $NON-NLS-1$ public static final IProjectFacetVersion WEBFRAGMENT_31 = WEBFRAGMENT_FACET.getVersion("3.1"); // $NON-NLS-1$ public static final IProjectFacet WEB_XDOCLET_FACET = getWebDocletFacet(); public static IProjectFacet getProjectFacet(String id) { try { return ProjectFacetsManager.getProjectFacet(id); } catch (IllegalArgumentException e) { return null; } } private static IProjectFacet getWebDocletFacet() { try { return ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.DYNAMIC_WEB_XDOCLET); } catch (IllegalArgumentException e) { // the web doclet facet is not defined return null; } } }
@Override public IProjectFacetVersion findFacetVersion( IMavenProjectFacade mavenProjectFacade, Map<?, ?> context, IProgressMonitor monitor) throws CoreException { if (JSF_FACET == null) { return null; } if (mavenProjectFacade != null && mavenProjectFacade.getMavenProject() != null) { for (Artifact artifact : mavenProjectFacade.getMavenProject().getArtifacts()) { if (isKnownJsf2BasedArtifact(artifact)) { return JSF_FACET.getVersion("2.0"); } } } return null; }
public static boolean hasFacet(IProject project, IProjectFacet checkProjectFacet) { boolean retval = false; if (project == null || checkProjectFacet == null) { return retval; } try { IFacetedProject facetedProject = ProjectFacetsManager.create(project); if (facetedProject != null && checkProjectFacet != null) { for (IProjectFacetVersion facet : facetedProject.getProjectFacets()) { IProjectFacet projectFacet = facet.getProjectFacet(); if (checkProjectFacet.equals(projectFacet)) { retval = true; break; } } } } catch (CoreException e) { } return retval; }
public static boolean isLiferayFacet(IProjectFacet projectFacet) { return projectFacet != null && projectFacet.getId().startsWith("liferay"); }
@SuppressWarnings("restriction") public abstract class AbstractWTPTestCase extends AbstractMavenProjectTestCase { protected static final IProjectFacetVersion DEFAULT_WEB_VERSION = WebFacetUtils.WEB_FACET.getVersion("2.5"); protected static final IProjectFacet EJB_FACET = ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.EJB); protected static final IProjectFacet UTILITY_FACET = ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.UTILITY); protected static final IProjectFacetVersion UTILITY_10 = UTILITY_FACET.getVersion("1.0"); protected static final IProjectFacet EAR_FACET = ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.ENTERPRISE_APPLICATION); protected static final IProjectFacetVersion DEFAULT_EAR_FACET = IJ2EEFacetConstants.ENTERPRISE_APPLICATION_13; protected static final String MAVEN_CLASSPATH_CONTAINER = "org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"; protected static final String JRE_CONTAINER_J2SE_1_5 = "org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"; protected static IClasspathContainer getWebLibClasspathContainer(IJavaProject project) throws JavaModelException { IClasspathEntry[] entries = project.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && "org.eclipse.jst.j2ee.internal.web.container".equals(entry.getPath().segment(0))) { return JavaCore.getClasspathContainer(entry.getPath(), project); } } return null; } private static boolean hasExtraAttribute(IClasspathEntry entry, String expectedAttribute) { for (IClasspathAttribute cpa : entry.getExtraAttributes()) { if (expectedAttribute.equals(cpa.getName())) { return true; } } return false; } protected String toString(IVirtualReference[] references) { StringBuilder sb = new StringBuilder("["); String sep = ""; for (IVirtualReference reference : references) { IVirtualComponent component = reference.getReferencedComponent(); sb.append(sep).append(reference.getRuntimePath() + " - "); sb.append(component.getName()); sb.append(" " + component.getMetaProperties()); sep = ", "; } return sb.append(']').toString(); } protected String toString(IFile[] files) { StringBuilder sb = new StringBuilder("["); String sep = ""; for (IFile file : files) { sb.append(sep).append(file.getFullPath()); sep = ", "; } return sb.append(']').toString(); } protected void assertHasMarker(String expectedMessage, List<IMarker> markers) throws CoreException { Pattern p = Pattern.compile(expectedMessage); for (IMarker marker : markers) { String markerMsg = marker.getAttribute(IMarker.MESSAGE).toString(); if (p.matcher(markerMsg).find()) { return; } } fail("[" + expectedMessage + "] is not a marker. Existing markers are :" + toString(markers)); } protected void assertMissingMarker(String expectedMessage, List<IMarker> markers) throws CoreException { Pattern p = Pattern.compile(expectedMessage); for (IMarker marker : markers) { String markerMsg = marker.getAttribute(IMarker.MESSAGE).toString(); if (p.matcher(markerMsg).find()) { fail( "[" + expectedMessage + "] was found but should be missing. Existing markers are :" + toString(markers)); } } } protected void assertNotDeployable(IClasspathEntry entry) { assertDeployable(entry, false); } protected void assertDeployable(IClasspathEntry entry, boolean expectedDeploymentStatus) { // Useless : IClasspathDependencyConstants.CLASSPATH_COMPONENT_DEPENDENCY doesn't seem to be // used in WTP 3.2.0. Has it ever worked??? // assertEquals(entry.toString() + " " + // IClasspathDependencyConstants.CLASSPATH_COMPONENT_DEPENDENCY, expectedDeploymentStatus, // hasExtraAttribute(entry, IClasspathDependencyConstants.CLASSPATH_COMPONENT_DEPENDENCY)); assertEquals( entry.toString() + " " + IClasspathDependencyConstants.CLASSPATH_COMPONENT_NON_DEPENDENCY, !expectedDeploymentStatus, hasExtraAttribute(entry, IClasspathDependencyConstants.CLASSPATH_COMPONENT_NON_DEPENDENCY)); } protected static IClasspathEntry[] getClassPathEntries(IProject project) throws Exception { IJavaProject javaProject = JavaCore.create(project); IClasspathContainer container = BuildPathManager.getMaven2ClasspathContainer(javaProject); return container.getClasspathEntries(); } protected static IResource[] getUnderlyingResources(IProject project) { IVirtualComponent component = ComponentCore.createComponent(project); IVirtualFolder root = component.getRootFolder(); IResource[] underlyingResources = root.getUnderlyingResources(); return underlyingResources; } protected static String getAsString(IFile file) throws IOException, CoreException { assert file != null; assert file.isAccessible(); InputStream ins = null; String content = null; try { ins = file.getContents(); content = IOUtil.toString(ins, 1024); } finally { IOUtil.close(ins); } return content; } public AbstractWTPTestCase() { super(); } /** * Replace the project pom.xml with a new one, triggers new build * * @param project * @param newPomName * @throws Exception */ protected void updateProject(IProject project, String newPomName) throws Exception { updateProject(project, newPomName, -1); } /** * Replace the project pom.xml with a new one, triggers new build, wait for waitTime milliseconds. * * @param project * @param newPomName * @param waitTime * @throws Exception */ protected void updateProject(IProject project, String newPomName, int waitTime) throws Exception { if (newPomName != null) { copyContent(project, newPomName, "pom.xml"); } IProjectConfigurationManager configurationManager = MavenPlugin.getDefault().getProjectConfigurationManager(); ResolverConfiguration configuration = new ResolverConfiguration(); configurationManager.enableMavenNature(project, configuration, monitor); configurationManager.updateProjectConfiguration(project, monitor); waitForJobsToComplete(); project.build(IncrementalProjectBuilder.FULL_BUILD, monitor); if (waitTime > 0) { Thread.sleep(waitTime); } waitForJobsToComplete(); } protected void updateProject(IProject project) throws Exception { updateProject(project, null, -1); } protected void assertContains(String findMe, String holder) { assertTrue("'" + findMe + "' is missing from : \n" + holder, holder.contains(findMe)); } protected void assertNotContains(String findMe, String holder) { assertFalse("'" + findMe + "' was found in : \n" + holder, holder.contains(findMe)); } protected void useBuildDirforGeneratingFiles(IProject project, boolean b) { IMavenWtpPreferences preferences = MavenWtpPlugin.getDefault().getMavenWtpPreferencesManager().getPreferences(project); preferences.setApplicationXmGeneratedInBuildDirectory(b); preferences.setWebMavenArchiverUsesBuildDirectory(b); MavenWtpPlugin.getDefault().getMavenWtpPreferencesManager().savePreferences(preferences, null); } protected void useBuildDirforGeneratingFiles(boolean b) { useBuildDirforGeneratingFiles(null, b); } }