use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project liferay-ide by liferay.
the class ProjectUtil method createExistingProject.
public static IProject createExistingProject(ProjectRecord record, IPath sdkLocation, IProgressMonitor monitor) throws CoreException {
String projectName = record.getProjectName();
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IProject project = workspace.getRoot().getProject(projectName);
if (record.description == null) {
// error case
record.description = workspace.newProjectDescription(projectName);
IPath locationPath = new Path(record.projectSystemFile.getAbsolutePath());
if (Platform.getLocation().isPrefixOf(locationPath)) {
record.description.setLocation(null);
} else {
record.description.setLocation(locationPath);
}
} else {
record.description.setName(projectName);
}
project.create(record.description, CoreUtil.newSubMonitor(monitor, 30));
project.open(IResource.FORCE, CoreUtil.newSubMonitor(monitor, 70));
if (project.getName().endsWith(ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX)) {
_fixExtProjectClasspathEntries(project);
}
IFacetedProject fProject = ProjectFacetsManager.create(project, true, monitor);
FacetedProjectWorkingCopy fpwc = new FacetedProjectWorkingCopy(fProject);
String pluginType = guessPluginType(fpwc);
SDKPluginFacetUtil.configureProjectAsSDKProject(fpwc, pluginType, sdkLocation.toPortableString(), record);
fpwc.commitChanges(monitor);
IJavaProject javaProject = JavaCore.create(fProject.getProject());
CoreUtil.getWorkspace().run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
List<IClasspathEntry> rawClasspaths = new ArrayList<>();
IPath containerPath = null;
for (IClasspathEntry entry : javaProject.getRawClasspath()) {
String segment = entry.getPath().segment(0);
if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) && segment.equals(SDKClasspathContainer.ID)) {
containerPath = entry.getPath();
break;
}
if (!_isLiferayRuntimePluginClassPath(entry)) {
rawClasspaths.add(entry);
}
}
if (containerPath != null) {
ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(SDKClasspathContainer.ID);
initializer.initialize(containerPath, javaProject);
} else {
javaProject.setRawClasspath(rawClasspaths.toArray(new IClasspathEntry[rawClasspaths.size()]), new NullProgressMonitor());
javaProject.setRawClasspath(rawClasspaths.toArray(new IClasspathEntry[rawClasspaths.size()]), new NullProgressMonitor());
IAccessRule[] accessRules = {};
IClasspathAttribute[] attributes = { JavaCore.newClasspathAttribute(IClasspathDependencyConstants.CLASSPATH_COMPONENT_NON_DEPENDENCY, StringPool.EMPTY) };
IPath cpePath = new Path(SDKClasspathContainer.ID);
IClasspathEntry newEntry = JavaCore.newContainerEntry(cpePath, accessRules, attributes, false);
IClasspathEntry[] entries = javaProject.getRawClasspath();
for (IClasspathEntry entry : entries) {
if (entry.getPath().equals(cpePath)) {
return;
}
}
IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
System.arraycopy(entries, 0, newEntries, 0, entries.length);
newEntries[entries.length] = newEntry;
javaProject.setRawClasspath(newEntries, monitor);
}
monitor.done();
SDK sdk = SDKUtil.createSDKFromLocation(sdkLocation);
SDKUtil.openAsProject(sdk);
}
}, monitor);
return project;
}
use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project liferay-ide by liferay.
the class LiferayMavenProjectConfigurator method configure.
@Override
public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask(NLS.bind(Msgs.configuringLiferayProject, request.getProject()), 100);
Plugin liferayMavenPlugin = MavenUtil.getPlugin(request.getMavenProjectFacade(), ILiferayMavenConstants.LIFERAY_MAVEN_PLUGIN_KEY, monitor);
if (!_shouldConfigure(liferayMavenPlugin, request)) {
monitor.done();
return;
}
IProject project = request.getProject();
IFile pomFile = project.getFile(IMavenConstants.POM_FILE_NAME);
IFacetedProject facetedProject = ProjectFacetsManager.create(project, false, monitor);
_removeLiferayMavenMarkers(project);
monitor.worked(25);
MavenProject mavenProject = request.getMavenProject();
List<MavenProblemInfo> errors = _findLiferayMavenPluginProblems(request, monitor);
if (ListUtil.isNotEmpty(errors)) {
try {
markerManager.addErrorMarkers(pomFile, ILiferayMavenConstants.LIFERAY_MAVEN_MARKER_CONFIGURATION_WARNING_ID, errors);
} catch (CoreException ce) {
// no need to log this error its just best effort
}
}
monitor.worked(25);
MavenProblemInfo installProblem = null;
if (_shouldInstallNewLiferayFacet(facetedProject)) {
installProblem = _installNewLiferayFacet(facetedProject, request, monitor);
}
if (_shouldAddLiferayNature(mavenProject, facetedProject)) {
LiferayNature.addLiferayNature(project, monitor);
}
monitor.worked(25);
if (installProblem != null) {
this.markerManager.addMarker(pomFile, ILiferayMavenConstants.LIFERAY_MAVEN_MARKER_CONFIGURATION_WARNING_ID, installProblem.getMessage(), installProblem.getLocation().getLineNumber(), IMarker.SEVERITY_WARNING);
} else {
String pluginType = MavenUtil.getLiferayMavenPluginType(mavenProject);
// IDE-817 we need to mak sure that on deployment it will have the correct
// suffix for project name
IVirtualComponent projectComponent = ComponentCore.createComponent(project);
try {
if (projectComponent != null) {
String deployedName = projectComponent.getDeployedName();
Matcher m = _versionPattern.matcher(deployedName);
if (m.matches()) {
deployedName = m.group(1);
configureDeployedName(project, deployedName);
}
if (pluginType != null) {
String pluginTypeSuffix = "-" + pluginType;
String deployedFileName = project.getName() + pluginTypeSuffix;
if ((deployedName == null) || ((deployedName != null) && !deployedName.endsWith(pluginTypeSuffix))) {
configureDeployedName(project, deployedFileName);
}
String oldContextRoot = ComponentUtilities.getServerContextRoot(project);
if ((oldContextRoot == null) || ((oldContextRoot != null) && !oldContextRoot.endsWith(pluginTypeSuffix))) {
IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(LiferayMavenCore.PLUGIN_ID);
boolean setMavenPluginSuffix = prefs.getBoolean(LiferayMavenCore.PREF_ADD_MAVEN_PLUGIN_SUFFIX, false);
if (setMavenPluginSuffix) {
ComponentUtilities.setServerContextRoot(project, deployedFileName);
}
}
}
}
} catch (Exception e) {
LiferayMavenCore.logError("Unable to configure deployed name for project " + project.getName(), e);
}
if (ILiferayMavenConstants.THEME_PLUGIN_TYPE.equals(pluginType)) {
IVirtualComponent component = ComponentCore.createComponent(project, true);
if (component != null) {
// make sure to update the main deployment folder
WarPluginConfiguration config = new WarPluginConfiguration(mavenProject, project);
String warSourceDirectory = config.getWarSourceDirectory();
IFolder contentFolder = project.getFolder(warSourceDirectory);
IPath warPath = _rootPath.append(contentFolder.getProjectRelativePath());
IPath themeFolder = _rootPath.append(getThemeTargetFolder(mavenProject, project));
// add a link to our m2e-liferay/theme-resources folder into deployment assembly
WTPProjectsUtil.insertLinkBefore(project, themeFolder, warPath, _rootPath, monitor);
}
}
}
if ((project != null) && ProjectUtil.isHookProject(project)) {
HookDescriptorHelper hookDescriptor = new HookDescriptorHelper(project);
String customJSPFolder = hookDescriptor.getCustomJSPFolder(null);
if (customJSPFolder != null) {
IWebProject webproject = LiferayCore.create(IWebProject.class, project);
if ((webproject != null) && (webproject.getDefaultDocrootFolder() != null)) {
IFolder docFolder = webproject.getDefaultDocrootFolder();
IPath newPath = Path.fromOSString(customJSPFolder);
IPath pathValue = docFolder.getFullPath().append(newPath);
boolean disableCustomJspValidation = LiferayMavenCore.getPreferenceBoolean(LiferayMavenCore.PREF_DISABLE_CUSTOM_JSP_VALIDATION);
if (disableCustomJspValidation) {
HookUtil.configureJSPSyntaxValidationExclude(project, project.getFolder(pathValue.makeRelativeTo(project.getFullPath())), true);
}
}
}
}
monitor.worked(25);
monitor.done();
}
use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project jbosstools-hibernate by jbosstools.
the class JPAProjectConfigurator method configure.
@Override
public void configure(IProject project, Set<IPath> ignoredDirectories, IProgressMonitor monitor) {
try {
IFacetedProject facetedProject = ProjectFacetsManager.create(project, true, monitor);
// $NON-NLS-1$
IProjectFacet JPA_FACET = ProjectFacetsManager.getProjectFacet("jpt.jpa");
if (!facetedProject.hasProjectFacet(JPA_FACET)) {
Set<Action> actions = new LinkedHashSet<>(2, 1);
IProjectFacetVersion javaFv = JavaFacet.FACET.getVersion(JavaFacetUtil.getCompilerLevel(project));
if (!facetedProject.hasProjectFacet(JavaFacet.FACET)) {
actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, javaFv, null));
} else if (!facetedProject.hasProjectFacet(javaFv)) {
actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.VERSION_CHANGE, javaFv, null));
}
// $NON-NLS-1$
RecursiveFileFinder finder = new RecursiveFileFinder("persistence.xml", ignoredDirectories);
project.accept(finder);
PersistenceXmlResourceProvider provider = PersistenceXmlResourceProvider.getXmlResourceProvider(finder.getFile());
JptXmlResource jpaXmlResource = provider.getXmlResource();
IProjectFacetVersion version = null;
if (jpaXmlResource.getVersion() != null) {
version = JpaProject.FACET.getVersion(jpaXmlResource.getVersion());
}
if (version == null) {
version = JpaProject.FACET.getLatestVersion();
}
// use default
JpaPlatform platform = null;
// TODO improve platform detection
LibraryInstallDelegate libraryDelegate = new LibraryInstallDelegate(facetedProject, version);
// $NON-NLS-1$
ILibraryProvider libraryProvider = LibraryProviderFramework.getProvider("jpa-no-op-library-provider");
libraryDelegate.setLibraryProvider(libraryProvider);
IDataModel dm = DataModelFactory.createDataModel(new JpaFacetInstallDataModelProvider());
dm.setProperty(IFacetDataModelProperties.FACET_VERSION_STR, version.getVersionString());
dm.setProperty(JpaFacetDataModelProperties.PLATFORM, platform);
dm.setProperty(JpaFacetInstallDataModelProperties.DISCOVER_ANNOTATED_CLASSES, true);
dm.setProperty(JpaFacetInstallDataModelProperties.LIBRARY_PROVIDER_DELEGATE, libraryDelegate);
actions.add(new IFacetedProject.Action(IFacetedProject.Action.Type.INSTALL, version, dm));
facetedProject.modify(actions, monitor);
}
} catch (Exception ex) {
HibernateJptUIPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, HibernateJptUIPlugin.PLUGIN_ID, ex.getMessage(), ex));
}
}
use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project webtools.servertools by eclipse.
the class FacetUtil method verifyFacets.
/**
* Tests whether the facets on a project are supported by a given server. Returns
* an OK status if the server's runtime supports the project's facets, and an
* ERROR status (with message) if it doesn't.
*
* @param project a project
* @param server a server
* @return OK status if the server's runtime supports the project's facets, and an
* ERROR status (with message) if it doesn't
*/
public static final IStatus verifyFacets(IProject project, IServer server) {
if (server == null)
return new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, Messages.errorNoRuntime, null);
IRuntime runtime = server.getRuntime();
if (runtime == null)
return new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, Messages.errorNoRuntime, null);
org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime2 = getRuntime(runtime);
if (// bug 150194 - what do we do if the facet runtime doesn't exist yet
runtime2 == null)
return Status.OK_STATUS;
try {
IFacetedProject facetedProject = ProjectFacetsManager.create(project);
Iterator iterator = facetedProject.getProjectFacets().iterator();
while (iterator.hasNext()) {
IProjectFacetVersion facet = (IProjectFacetVersion) iterator.next();
if (!runtime2.supports(facet))
return new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorFacet, facet.getProjectFacet().getLabel(), facet.getVersionString()), null);
}
} catch (CoreException ce) {
return ce.getStatus();
}
return Status.OK_STATUS;
}
use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project webtools.servertools by eclipse.
the class FacetUtil method removeTargets.
/**
* Removes the given runtime from the target of all projects.
*
* @param runtime a runtime
* @param monitor a progress monitor, or <code>null</code> if progress
* reporting and cancellation are not desired
* @throws CoreException if failed for any reason
*/
public static void removeTargets(IRuntime runtime, IProgressMonitor monitor) throws CoreException {
try {
org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime2 = getRuntime(runtime);
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
if (projects != null) {
for (IProject project : projects) {
IFacetedProject facetedProject = ProjectFacetsManager.create(project);
if (facetedProject != null) {
Set<org.eclipse.wst.common.project.facet.core.runtime.IRuntime> set = facetedProject.getTargetedRuntimes();
if (set != null && set.contains(runtime2))
facetedProject.removeTargetedRuntime(runtime2, monitor);
}
}
}
} catch (CoreException ce) {
throw ce;
} catch (Throwable t) {
if (Trace.WARNING) {
Trace.trace(Trace.STRING_WARNING, "Could not remove runtime target", t);
}
}
}
Aggregations