Search in sources :

Example 1 with WarPluginConfiguration

use of org.eclipse.m2e.wtp.WarPluginConfiguration in project liferay-ide by liferay.

the class MavenUtil method getWarSourceDirectory.

public static String getWarSourceDirectory(IMavenProjectFacade facade) {
    String retval = null;
    try {
        MavenProject mavenProject = facade.getMavenProject(new NullProgressMonitor());
        IProject project = facade.getProject();
        retval = new WarPluginConfiguration(mavenProject, project).getWarSourceDirectory();
    } catch (CoreException ce) {
        LiferayMavenCore.logError("Unable to get war source directory", ce);
    }
    return retval;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) MavenProject(org.apache.maven.project.MavenProject) CoreException(org.eclipse.core.runtime.CoreException) WarPluginConfiguration(org.eclipse.m2e.wtp.WarPluginConfiguration) IProject(org.eclipse.core.resources.IProject)

Example 2 with WarPluginConfiguration

use of org.eclipse.m2e.wtp.WarPluginConfiguration 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();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) Matcher(java.util.regex.Matcher) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IWebProject(com.liferay.ide.core.IWebProject) WarPluginConfiguration(org.eclipse.m2e.wtp.WarPluginConfiguration) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) MavenProblemInfo(org.eclipse.m2e.core.internal.markers.MavenProblemInfo) MavenProject(org.apache.maven.project.MavenProject) CoreException(org.eclipse.core.runtime.CoreException) HookDescriptorHelper(com.liferay.ide.hook.core.dd.HookDescriptorHelper) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent) Plugin(org.apache.maven.model.Plugin) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

MavenProject (org.apache.maven.project.MavenProject)2 IProject (org.eclipse.core.resources.IProject)2 CoreException (org.eclipse.core.runtime.CoreException)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 WarPluginConfiguration (org.eclipse.m2e.wtp.WarPluginConfiguration)2 IWebProject (com.liferay.ide.core.IWebProject)1 HookDescriptorHelper (com.liferay.ide.hook.core.dd.HookDescriptorHelper)1 Matcher (java.util.regex.Matcher)1 Plugin (org.apache.maven.model.Plugin)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 IPath (org.eclipse.core.runtime.IPath)1 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 MavenProblemInfo (org.eclipse.m2e.core.internal.markers.MavenProblemInfo)1 IVirtualComponent (org.eclipse.wst.common.componentcore.resources.IVirtualComponent)1 IFacetedProject (org.eclipse.wst.common.project.facet.core.IFacetedProject)1