static { IProjectFacet jsfFacet = null; if (ProjectFacetsManager.isProjectFacetDefined(JSF_FACET_ID)) { jsfFacet = ProjectFacetsManager.getProjectFacet(JSF_FACET_ID); } JSF_FACET = jsfFacet; }
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; }
public static IFacetedProject getFacetedProject(IProject project) { try { return ProjectFacetsManager.create(project); } catch (CoreException e) { return null; } }
public static IProjectFacet getProjectFacet(String id) { try { return ProjectFacetsManager.getProjectFacet(id); } catch (IllegalArgumentException e) { return null; } }
@Override protected IModule createModule(IProject project) { try { IFacetedProject facetedProject = ProjectFacetsManager.create(project); if (facetedProject != null && facetedProject.hasProjectFacet(facet)) { IProjectFacetVersion projectFacetVersion = facetedProject.getInstalledVersion(facet); String version = projectFacetVersion.getVersionString(); IModule module = createModule( project.getName(), project.getName(), SwordfishConstants.SWORDFISH_APPLICATION_TYPE, version, project); SwordfishApplicationDeployable deployable = new SwordfishApplicationDeployable(project); deployable.initialize(module); moduleDelegates.add(deployable); return module; } } catch (CoreException e) { e.printStackTrace(); } return null; }
protected void configureWtpUtil( IProject project, MavenProject mavenProject, IProgressMonitor monitor) throws CoreException { // Adding utility facet on JEE projects is not allowed if (WTPProjectsUtil.isJavaEEProject(project)) { return; } IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor); Set<Action> actions = new LinkedHashSet<Action>(); installJavaFacet(actions, project, facetedProject); if (!facetedProject.hasProjectFacet(WTPProjectsUtil.UTILITY_FACET)) { actions.add( new IFacetedProject.Action( IFacetedProject.Action.Type.INSTALL, WTPProjectsUtil.UTILITY_10, null)); } else if (!facetedProject.hasProjectFacet(WTPProjectsUtil.UTILITY_10)) { actions.add( new IFacetedProject.Action( IFacetedProject.Action.Type.VERSION_CHANGE, WTPProjectsUtil.UTILITY_10, null)); } if (!actions.isEmpty()) { facetedProject.modify(actions, monitor); } // MNGECLIPSE-904 remove tests folder links for utility jars // TODO handle modules in a parent pom (the following doesn't work) removeTestFolderLinks(project, mavenProject, monitor, "/"); // Remove "library unavailable at runtime" warning. setNonDependencyAttributeToContainer(project, monitor); }
private static IProjectFacet getWebDocletFacet() { try { return ProjectFacetsManager.getProjectFacet(IJ2EEFacetConstants.DYNAMIC_WEB_XDOCLET); } catch (IllegalArgumentException e) { // the web doclet facet is not defined return null; } }
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; } }
/** * Add a mapping for some facet type to some default extension * * @param facet * @param extension * @return */ public boolean addDefaultExtension(String facet, String extension) { if (!mapping.containsKey(facet)) { if (ProjectFacetsManager.isProjectFacetDefined(facet)) { mapping.put(facet, extension); return true; } } return false; }
public class SwordfishApplicationDeployableFactory extends ProjectModuleFactoryDelegate { private IProjectFacet facet = ProjectFacetsManager.getProjectFacet(SwordfishConstants.SWORDFISH_APPLICATION_TYPE); private List<ModuleDelegate> moduleDelegates = new ArrayList<ModuleDelegate>(); @Override public ModuleDelegate getModuleDelegate(IModule module) { for (ModuleDelegate moduleDelegate : moduleDelegates) { if (moduleDelegate.getModule() == module) { return moduleDelegate; } } return null; } @Override protected IModule createModule(IProject project) { try { IFacetedProject facetedProject = ProjectFacetsManager.create(project); if (facetedProject != null && facetedProject.hasProjectFacet(facet)) { IProjectFacetVersion projectFacetVersion = facetedProject.getInstalledVersion(facet); String version = projectFacetVersion.getVersionString(); IModule module = createModule( project.getName(), project.getName(), SwordfishConstants.SWORDFISH_APPLICATION_TYPE, version, project); SwordfishApplicationDeployable deployable = new SwordfishApplicationDeployable(project); deployable.initialize(module); moduleDelegates.add(deployable); return module; } } catch (CoreException e) { e.printStackTrace(); } return null; } @Override protected IPath[] getListenerPaths() { return new IPath[] { new Path(".project"), new Path("feature.xml"), new Path(".settings/org.eclipse.wst.common.project.facet.core.xml"), }; } }
private void initControls() { _switchYardProject = SwitchYardProjectManager.instance().getSwitchYardProject(getProject()).createWorkingCopy(); if (_switchYardProject.needsLoading()) { BusyIndicator.showWhile( getShell().getDisplay(), new Runnable() { @Override public void run() { _switchYardProject.load(new NullProgressMonitor()); } }); } try { _ifp = ProjectFacetsManager.create(_switchYardProject.getProject()); _ifpwc = SharedWorkingCopyManager.getWorkingCopy(_ifp); _configuredRuntimes = _ifpwc.getTargetedRuntimes(); } catch (CoreException e) { Activator.getDefault().getLog().log(e.getStatus()); } _settingsGroup.setProject(_ifpwc); initTargetRuntime(); initRuntimeVersion(); initComponentsTable(); _useSwitchYardDependencyBOMCheckbox.setSelection(pomUsesSwitchYardBOM()); String errmsg = null; if (!pomDefinesSwitchYardVersion()) { _settingsGroup.setRuntimeControlEnablement(false); } else if (pomUsesSwitchYardBOM()) { if (!isSelectedRuntimeVersion2OrHigher()) { // only valid versions with BOM dependency support are 2.0+ errmsg = Messages.ProjectConfigurationWizardPage_errorMessage_bomRequiresVersion2; } } else if (!isSelectedConfigurationVersionOkForRuntime()) { String configVersion = getMajorMinorFromVersion(getRuntimeVersion().toString()); errmsg = "The Configuration Version must be " + configVersion + " or lower to work with Library Version " + getRuntimeVersion().toString() + "."; } setErrorMessage(errmsg); getContainer().updateMessage(); }
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; } } }
public static IPath getPortalDir(IProject project) { try { IFacetedProject facetedProject = ProjectFacetsManager.create(project); org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime = facetedProject.getPrimaryRuntime(); if (runtime != null) { return ServerUtil.getPortalDir(runtime); } } catch (CoreException e) { LiferayServerCorePlugin.logError(e); } return null; }
@Override public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException { final MavenProject mavenProject = request.getMavenProject(); final Plugin liferayMavenPlugin = LiferayMavenUtil.getLiferayMavenPlugin(mavenProject); if (!shouldConfigure(liferayMavenPlugin)) { return; } final IProject project = request.getProject(); final IFile pomFile = project.getFile(IMavenConstants.POM_FILE_NAME); final IFacetedProject facetedProject = ProjectFacetsManager.create(project, false, monitor); removeLiferayMavenMarkers(project); final List<MavenProblemInfo> errors = findLiferayMavenPluginProblems(project, mavenProject); if (errors.size() > 0) { try { this.markerManager.addErrorMarkers( pomFile, ILiferayMavenConstants.LIFERAY_MAVEN_MARKER_CONFIGURATION_ERROR_ID, errors); } catch (CoreException e) { // no need to log this error its just best effort } return; } if (shouldInstallNewLiferayFacet(facetedProject)) { final MavenProblemInfo installProblem = installNewLiferayFacet(facetedProject, mavenProject, monitor); if (installProblem != null) { this.markerManager.addMarker( pomFile, ILiferayMavenConstants.LIFERAY_MAVEN_MARKER_CONFIGURATION_ERROR_ID, installProblem.getMessage(), installProblem.getLocation().getLineNumber(), IMarker.SEVERITY_WARNING); } } }
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; }
/** @return */ private Object getDeployAsDefaultValue() { String result = SeamProjectPreferences.getStringPreference( SeamProjectPreferences.JBOSS_AS_DEFAULT_DEPLOY_AS); if (!isSeamProjectWizard()) { ISelection sel = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); IProject project = SeamWizardUtils.getInitialProject(sel); if (project == null) { SeamCorePlugin.getPluginLog() .logError( "Can't get project name to initialize SeamInstallWizardPage for ModifyFacetedProjectWizard"); return result; } IFacetedProject facetedProject; try { facetedProject = ProjectFacetsManager.create(project); if (facetedProject == null) { SeamCorePlugin.getPluginLog() .logError( "Can't get faceted project to initialize SeamInstallWizardPage for ModifyFacetedProjectWizard"); return result; } } catch (CoreException e) { SeamCorePlugin.getPluginLog().logError(e); return result; } IProjectFacetVersion webVersion = facetedProject.getProjectFacetVersion(IJ2EEFacetConstants.DYNAMIC_WEB_FACET); if (webVersion != null) { return ISeamFacetDataModelProperties.DEPLOY_AS_WAR; } else { return ISeamFacetDataModelProperties.DEPLOY_AS_EAR; } } return result; }
/** * The activator class controls the plugin life cycle * * @auther Greg Amerson * @author Cindy Li */ public class PortletCore extends Plugin { public static final IProjectFacet JSF_FACET = ProjectFacetsManager.getProjectFacet(IJSFCoreConstants.JSF_CORE_FACET_ID); // The plugin ID public static final String PLUGIN_ID = "com.liferay.ide.portlet.core"; // $NON-NLS-1$ public static final String PREF_KEY_PORTLET_SUPERCLASSES_USED = "portlet-superclasses-used"; //$NON-NLS-1$ // The shared instance private static PortletCore plugin; public static BuildLanguageJob createBuildLanguageJob(IFile file) { BuildLanguageJob job = new BuildLanguageJob(file); return job; } public static IStatus createErrorStatus(Exception e) { return new Status(IStatus.ERROR, PLUGIN_ID, e.getMessage(), e); } public static IStatus createErrorStatus(String msg) { return new Status(IStatus.ERROR, PLUGIN_ID, msg); } public static IStatus createErrorStatus(String msg, Exception e) { return new Status(IStatus.ERROR, PLUGIN_ID, msg, e); } public static IStatus createWarningStatus(String msg) { return new Status(IStatus.WARNING, PLUGIN_ID, msg); } /** * Returns the shared instance * * @return the shared instance */ public static PortletCore getDefault() { return plugin; } public static Preferences getPreferences() { @SuppressWarnings("deprecation") final IScopeContext scope = new InstanceScope(); return scope.getNode(PLUGIN_ID); } public static void logError(Exception ex) { getDefault().getLog().log(createErrorStatus(ex)); } public static void logError(String msg, Exception e) { getDefault().getLog().log(createErrorStatus(msg, e)); } /** The constructor */ public PortletCore() {} /* * (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext ) */ public void start(BundleContext context) throws Exception { super.start(context); plugin = this; } /* * (non-Javadoc) * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext ) */ public void stop(BundleContext context) throws Exception { plugin = null; super.stop(context); } }
protected void configure(IProject project, MavenProject mavenProject, IProgressMonitor monitor) throws CoreException { IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor); IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry() .create(project.getFile(IMavenConstants.POM_FILE_NAME), true, monitor); // make sure to update the main deployment folder WarPluginConfiguration config = new WarPluginConfiguration(mavenProject, project); String warSourceDirectory = config.getWarSourceDirectory(); IFolder contentFolder = project.getFolder(warSourceDirectory); Set<Action> actions = new LinkedHashSet<Action>(); installJavaFacet(actions, project, facetedProject); IVirtualComponent component = ComponentCore.createComponent(project, true); // MNGECLIPSE-2279 get the context root from the final name of the project, or artifactId by // default. String contextRoot = getContextRoot(mavenProject, config.getWarName()); IProjectFacetVersion webFv = config.getWebFacetVersion(project); IDataModel webModelCfg = getWebModelConfig(warSourceDirectory, contextRoot); if (!facetedProject.hasProjectFacet(WebFacetUtils.WEB_FACET)) { removeConflictingFacets(facetedProject, webFv, actions); actions.add( new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, webFv, webModelCfg)); } else { IProjectFacetVersion projectFacetVersion = facetedProject.getProjectFacetVersion(WebFacetUtils.WEB_FACET); if (webFv.getVersionString() != null && !webFv.getVersionString().equals(projectFacetVersion.getVersionString())) { actions.add( new IFacetedProject.Action( IFacetedProject.Action.Type.VERSION_CHANGE, webFv, webModelCfg)); } } String customWebXml = config.getCustomWebXml(project); if (!actions.isEmpty()) { ResourceCleaner fileCleaner = new ResourceCleaner(project); try { addFilesToClean(fileCleaner, facade.getResourceLocations()); addFilesToClean(fileCleaner, facade.getCompileSourceLocations()); IFolder libDir = project.getFolder(warSourceDirectory).getFolder("WEB-INF/lib"); fileCleaner.addFiles( contentFolder.getFile("META-INF/MANIFEST.MF").getProjectRelativePath()); fileCleaner.addFolder(libDir, false); if (customWebXml != null) { IFile defaultWebXml = project.getFolder(warSourceDirectory).getFile("WEB-INF/web.xml"); fileCleaner.addFiles(defaultWebXml.getProjectRelativePath()); } facetedProject.modify(actions, monitor); } finally { // Remove any unwanted MANIFEST.MF the Facet installation has created fileCleaner.cleanUp(); } } // MECLIPSEWTP-41 Fix the missing moduleCoreNature fixMissingModuleCoreNature(project, monitor); // MNGECLIPSE-632 remove test sources/resources from WEB-INF/classes removeTestFolderLinks(project, mavenProject, monitor, "/WEB-INF/classes"); addContainerAttribute(project, DEPENDENCY_ATTRIBUTE, monitor); // MNGECLIPSE-2279 change the context root if needed if (!contextRoot.equals(J2EEProjectUtilities.getServerContextRoot(project))) { J2EEProjectUtilities.setServerContextRoot(project, contextRoot); } // If we have a custom web.xml but WTP created one against our will, we delete it if (customWebXml != null) { linkFileFirst(project, customWebXml, "/WEB-INF/web.xml", monitor); } component = ComponentCore.createComponent(project, true); if (component != null) { IPath warPath = new Path("/").append(contentFolder.getProjectRelativePath()); List<IPath> sourcePaths = new ArrayList<IPath>(); sourcePaths.add(warPath); if (!WTPProjectsUtil.hasLink(project, ROOT_PATH, warPath, monitor)) { component.getRootFolder().createLink(warPath, IVirtualResource.NONE, monitor); } // MECLIPSEWTP-22 support web filtered resources. Filtered resources directory must be // declared BEFORE // the regular web source directory. First resources discovered take precedence on deployment IPath filteredFolder = new Path("/") .append(WebResourceFilteringConfiguration.getTargetFolder(mavenProject, project)); boolean useBuildDir = MavenWtpPlugin.getDefault() .getMavenWtpPreferencesManager() .getPreferences(project) .isWebMavenArchiverUsesBuildDirectory(); boolean useWebresourcefiltering = config.getWebResources() != null && config.getWebResources().length > 0 || config.isFilteringDeploymentDescriptorsEnabled(); if (useBuildDir || useWebresourcefiltering) { if (!useBuildDir && useWebresourcefiltering) { mavenMarkerManager.addMarker( project, MavenWtpConstants.WTP_MARKER_CONFIGURATION_ERROR_ID, Messages.markers_mavenarchiver_output_settings_ignored_warning, -1, IMarker.SEVERITY_WARNING); } sourcePaths.add(filteredFolder); WTPProjectsUtil.insertLinkBefore(project, filteredFolder, warPath, new Path("/"), monitor); } else { component.getRootFolder().removeLink(filteredFolder, IVirtualResource.NONE, monitor); } WTPProjectsUtil.deleteLinks(project, ROOT_PATH, sourcePaths, monitor); WTPProjectsUtil.setDefaultDeploymentDescriptorFolder( component.getRootFolder(), warPath, monitor); addComponentExclusionPatterns(component, config); } WTPProjectsUtil.removeWTPClasspathContainer(project); // MECLIPSEWTP-214 : add (in|ex)clusion patterns as .component metadata }
/** * TODO: this is probably not the best way to do things. This one test validates most of the * functionality in tools.ui. However, starting and stopping a workbench takes a lot of time and * we need a project to run the service creation tests so... * * <p>Tests the creation of a SwitchYard project: project, pom.xml, switchyard.xml creation. * * <p>Test dependency update operation. * * <p>Tests the creation of a new SwitchYard service. * * @throws Exception if an error occurs or test fails. */ public void testCreateSwitchYardProjectOperation() throws Exception { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProject newProjectHandle = workspace.getRoot().getProject(CreateSwitchYardProjectTest.class.getSimpleName()); String packageName = "test.package_name"; String groupId = "test.project.group"; String version = "0.0.1-SNAPSHOT"; String runtimeVersion = "0.5.0.Final"; assertTrue("Project already exists.", !newProjectHandle.exists()); final NewSwitchYardProjectMetaData projectMetaData = new NewSwitchYardProjectMetaData(); projectMetaData.setNewProjectHandle(newProjectHandle); projectMetaData.setPackageName(packageName); projectMetaData.setGroupId(groupId); projectMetaData.setProjectVersion(version); projectMetaData.setRuntimeVersion(runtimeVersion); projectMetaData.setComponents( Collections.singleton( SwitchYardComponentExtensionManager.instance().getRuntimeComponentExtension())); IWorkspaceRunnable op = new CreateSwitchYardProjectOperation(projectMetaData, null); workspace.run(op, new NullProgressMonitor()); waitForJobs(); newProjectHandle.build(IncrementalProjectBuilder.FULL_BUILD, monitor); waitForJobs(); assertNoErrors(newProjectHandle); // TODO: change true to false once SWITCHYARD-469 is corrected assertTrue( "Project contains errors", newProjectHandle.findMaxProblemSeverity(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE) < IMarker.SEVERITY_ERROR); IFile switchyardFile = newProjectHandle.getFile("src/main/resources/META-INF/switchyard.xml"); assertTrue("Failed to create switchyard.xml", switchyardFile.exists()); assertTrue( "switchyard.xml file is out of sync after project creation", switchyardFile.isSynchronized(IFile.DEPTH_ZERO)); IFile pomFile = newProjectHandle.getFile("pom.xml"); assertTrue("Failed to create pom.xml", pomFile.exists()); assertTrue( "pom.xml file is out of sync after project creation", pomFile.isSynchronized(IFile.DEPTH_ZERO)); IFacetedProject fp = ProjectFacetsManager.create(newProjectHandle, false, new NullProgressMonitor()); assertNotNull("Project is not a faceted project.", fp); assertTrue( "switchyard.core facet not configured on project", fp.hasProjectFacet(ProjectFacetsManager.getProjectFacet("switchyard.core"))); assertTrue( "jst.utility facet not configured on project", fp.hasProjectFacet(ProjectFacetsManager.getProjectFacet("jst.utility"))); assertTrue( "java facet not configured on project", fp.hasProjectFacet(ProjectFacetsManager.getProjectFacet("java"))); // Test project update op = new AbstractSwitchYardProjectOperation( null, Collections.singleton( SwitchYardComponentExtensionManager.instance() .getComponentExtension("org.switchyard.components:switchyard-component-bpm")), true, "Testing SwitchYard project update", null) { @Override protected IProject getProject() { return newProjectHandle; } @Override protected void execute(IProgressMonitor monitor) throws CoreException { monitor.done(); } }; workspace.run(op, new NullProgressMonitor()); waitForJobs(); newProjectHandle.build(IncrementalProjectBuilder.FULL_BUILD, monitor); waitForJobs(); assertNoErrors(newProjectHandle); assertTrue("Failed to update pom.xml", pomFile.exists()); assertTrue( "pom.xml file is out of sync after project update", pomFile.isSynchronized(IFile.DEPTH_ZERO)); assertXMLFilesMatch( "pom dependency update failed", pomFile, "test-data/validation/add_dependency_pom.xml"); // test new bean service and test class IFile testServiceFile = newProjectHandle .getFolder("src/main/java") .getFolder(packageName.replace('.', '/')) .getFile("TestService.java"); testServiceFile.create( CreateSwitchYardProjectTest.class .getClassLoader() .getResourceAsStream("test-data/source/TestService.java"), true, new NullProgressMonitor()); // the project needs to be built or we can't create the service test class newProjectHandle.build(IncrementalProjectBuilder.FULL_BUILD, monitor); waitForJobs(); NewBeanServiceClassWizardPage newBeanPage = new NewBeanServiceClassWizardPage(); newBeanPage.init(new StructuredSelection(testServiceFile)); assertTrue( "NewBeanServiceClassWizardPage is not initialized correctly.", newBeanPage.isPageComplete()); NewServiceTestClassWizardPage newTestPage = new NewServiceTestClassWizardPage(); newTestPage.init(new StructuredSelection(testServiceFile)); newTestPage.setServiceContract(newBeanPage.getServiceContract(), false); assertTrue( "NewServiceTestClassWizardPage is not initialized correctly.", newTestPage.isPageComplete()); op = new CreateBeanServiceOperation(newBeanPage, newTestPage, null); workspace.run(op, new NullProgressMonitor()); waitForJobs(); newProjectHandle.build(IncrementalProjectBuilder.FULL_BUILD, monitor); waitForJobs(); assertNoErrors(newProjectHandle); assertTrue("switchyard.xml missing after bean service creation", switchyardFile.exists()); assertTrue( "switchyard.xml file is out of sync after bean service creation", switchyardFile.isSynchronized(IFile.DEPTH_ZERO)); assertXMLFilesMatch( "bean service creation failed", switchyardFile, "test-data/validation/create_service_switchyard.xml"); assertTrue("pom.xml missing after bean service creation", pomFile.exists()); assertTrue( "pom.xml file is out of sync after bean service creation", pomFile.isSynchronized(IFile.DEPTH_ZERO)); assertXMLFilesMatch( "bean service creation failed", pomFile, "test-data/validation/create_service_pom.xml"); IFile testServiceImplFile = newProjectHandle .getFolder("src/main/java") .getFolder(packageName.replace('.', '/')) .getFile("TestServiceBean.java"); IFile testServiceTestFile = newProjectHandle .getFolder("src/test/java") .getFolder(packageName.replace('.', '/')) .getFile("TestServiceTest.java"); assertTrue("TestServiceBean missing after bean service creation", testServiceImplFile.exists()); assertTrue( "TestServiceBean file is out of sync after bean service creation", testServiceImplFile.isSynchronized(IFile.DEPTH_ZERO)); assertTrue( "testServiceTestFile missing after bean service creation", testServiceTestFile.exists()); assertTrue( "testServiceTestFile file is out of sync after bean service creation", testServiceTestFile.isSynchronized(IFile.DEPTH_ZERO)); // TODO: validate contents of generated files }
public IProjectFacetVersion getProjectFacetVersion() { final IProjectFacet jaxrsFacet = ProjectFacetsManager.getProjectFacet(IJAXRSCoreConstants.JAXRS_FACET_ID); final IFacetedProject fproj = getFacetedProject(); return fproj.getInstalledVersion(jaxrsFacet); }
/* * Don't want to add jpa as required plugin, so use String constant instead of JptCorePlugin.FACET_ID */ private IProjectFacetVersion getJpaFacetVersion() { IFacetedProjectWorkingCopy facetedProject = ((ModifyFacetedProjectWizard) getWizard()).getFacetedProjectWorkingCopy(); return facetedProject.getProjectFacetVersion( ProjectFacetsManager.getProjectFacet("jpt.jpa")); // $NON-NLS-1$ }
public static boolean isExtProject(IProject project) { return hasFacet(project, ProjectFacetsManager.getProjectFacet("liferay.ext")); }
protected void configure(IProject project, MavenProject mavenProject, IProgressMonitor monitor) throws CoreException { IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor); // make sure to update the main deployment folder WarPluginConfiguration config = new WarPluginConfiguration(mavenProject, project); String warSourceDirectory = config.getWarSourceDirectory(); IFile defaultWebXml = project.getFolder(warSourceDirectory).getFile("WEB-INF/web.xml"); IFolder libDir = project.getFolder(warSourceDirectory).getFolder("WEB-INF/lib"); boolean alreadyHasWebXml = defaultWebXml.exists(); boolean alreadyHasLibDir = libDir.exists(); Set<Action> actions = new LinkedHashSet<Action>(); installJavaFacet(actions, project, facetedProject); IVirtualComponent component = ComponentCore.createComponent(project); if (component != null && warSourceDirectory != null) { IPath warPath = new Path(warSourceDirectory); // remove the old links (if there is one) before adding the new one. component.getRootFolder().removeLink(warPath, IVirtualResource.NONE, monitor); component.getRootFolder().createLink(warPath, IVirtualResource.NONE, monitor); } // MNGECLIPSE-2279 get the context root from the final name of the project, or artifactId by // default. String contextRoot = getContextRoot(mavenProject); IProjectFacetVersion webFv = config.getWebFacetVersion(project); if (!facetedProject.hasProjectFacet(WebFacetUtils.WEB_FACET)) { installWebFacet(mavenProject, warSourceDirectory, contextRoot, actions, webFv); } else { IProjectFacetVersion projectFacetVersion = facetedProject.getProjectFacetVersion(WebFacetUtils.WEB_FACET); if (webFv.getVersionString() != null && !webFv.getVersionString().equals(projectFacetVersion.getVersionString())) { try { Action uninstallAction = new IFacetedProject.Action( IFacetedProject.Action.Type.UNINSTALL, facetedProject.getInstalledVersion(WebFacetUtils.WEB_FACET), null); facetedProject.modify(Collections.singleton(uninstallAction), monitor); } catch (Exception ex) { MavenLogger.log("Error removing WEB facet", ex); } installWebFacet(mavenProject, warSourceDirectory, contextRoot, actions, webFv); } } if (!actions.isEmpty()) { facetedProject.modify(actions, monitor); } // MNGECLIPSE-632 remove test sources/resources from WEB-INF/classes removeTestFolderLinks(project, mavenProject, monitor, "/WEB-INF/classes"); addContainerAttribute(project, DEPENDENCY_ATTRIBUTE, monitor); // MNGECLIPSE-2279 change the context root if needed if (!contextRoot.equals(J2EEProjectUtilities.getServerContextRoot(project))) { J2EEProjectUtilities.setServerContextRoot(project, contextRoot); } // MNGECLIPSE-2357 support custom location of web.xml String customWebXml = config.getCustomWebXml(project); // If we have a custom web.xml but WTP created one against our will, we delete it if (customWebXml != null && !alreadyHasWebXml && defaultWebXml.exists()) { defaultWebXml.delete(true, monitor); } // Maven /m2eclipse doesn't need a new lib dir. if (!alreadyHasLibDir && libDir.exists()) { libDir.delete(true, monitor); } linkFile(project, customWebXml, "WEB-INF/web.xml", monitor); IPath filteredFolder = WebResourceFilteringConfiguration.getTargetFolder(mavenProject, project); if (component != null) { ProjectUtils.hideM2eclipseWtpFolder(mavenProject, project); component.getRootFolder().removeLink(filteredFolder, IVirtualResource.NONE, monitor); if (config.getWebResources() != null && config.getWebResources().length > 0) { component.getRootFolder().createLink(filteredFolder, IVirtualResource.NONE, monitor); } } }
public static IRuntime getRuntime(IProject project) throws CoreException { return (IRuntime) getRuntimeAdapter(ProjectFacetsManager.create(project).getPrimaryRuntime(), IRuntime.class); }
@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); } }