Search in sources :

Example 31 with IWebProject

use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.

the class ExtPluginFacetInstall method fixTilesDefExtFile.

protected void fixTilesDefExtFile() {
    IWebProject webproject = LiferayCore.create(IWebProject.class, project);
    IFolder webappRoot = webproject.getDefaultDocrootFolder();
    IFile tilesDefExtFile = webappRoot.getFile("WEB-INF/ext-web/docroot/WEB-INF/tiles-defs-ext.xml");
    if (FileUtil.notExists(tilesDefExtFile)) {
        return;
    }
    try {
        IDOMModel domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(tilesDefExtFile);
        domModel.aboutToChangeModel();
        IDOMDocument document = domModel.getDocument();
        Element root = document.getDocumentElement();
        Element def = document.createElement("definition");
        def.setAttribute("name", StringPool.EMPTY);
        root.appendChild(def);
        root.appendChild(document.createTextNode("\n"));
        new FormatProcessorXML().formatNode(def);
        domModel.changedModel();
        domModel.save();
        domModel.releaseFromEdit();
        tilesDefExtFile.refreshLocal(IResource.DEPTH_INFINITE, null);
    } catch (Exception e) {
        ProjectCore.logError(e);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IWebProject(com.liferay.ide.core.IWebProject) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Element(org.w3c.dom.Element) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML) CoreException(org.eclipse.core.runtime.CoreException) IFolder(org.eclipse.core.resources.IFolder)

Example 32 with IWebProject

use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.

the class ExtPluginFacetInstall method _removeUnneededFolders.

private void _removeUnneededFolders(IProject project) throws CoreException {
    IWebProject webproject = LiferayCore.create(IWebProject.class, project);
    if ((webproject != null) && (webproject.getDefaultDocrootFolder() != null)) {
        IFolder webappRoot = webproject.getDefaultDocrootFolder();
        deleteFolder(webappRoot.getFolder("WEB-INF/lib"));
    }
}
Also used : IWebProject(com.liferay.ide.core.IWebProject) IFolder(org.eclipse.core.resources.IFolder)

Example 33 with IWebProject

use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.

the class ProjectUtil method getPortletXmlFile.

public static IFile getPortletXmlFile(IProject project) {
    if ((project == null) || !isLiferayFacetedProject(project)) {
        return null;
    }
    IWebProject webProject = LiferayCore.create(IWebProject.class, project);
    if (webProject == null) {
        return null;
    }
    IFolder defaultDocrootFolder = webProject.getDefaultDocrootFolder();
    if (defaultDocrootFolder == null) {
        return null;
    }
    IFile portletXml = defaultDocrootFolder.getFile(new Path("WEB-INF/portlet.xml"));
    if ((portletXml != null) && portletXml.exists()) {
        return portletXml;
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IWebProject(com.liferay.ide.core.IWebProject) IFolder(org.eclipse.core.resources.IFolder)

Example 34 with IWebProject

use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.

the class IvyUtil method configureIvyProject.

public static IStatus configureIvyProject(final IProject project, IProgressMonitor monitor) throws CoreException {
    SDK sdk = SDKUtil.getSDK(project);
    // check for 6.1.2 and greater but not 6.1.10 which is older EE release
    // and match 6.2.0 and greater
    final Version version = new Version(sdk.getVersion());
    if (((CoreUtil.compareVersions(version, ILiferayConstants.V611) >= 0) && (CoreUtil.compareVersions(version, ILiferayConstants.V6110) < 0)) || (CoreUtil.compareVersions(version, ILiferayConstants.V620) >= 0)) {
        IFile ivyXmlFile = project.getFile(ISDKConstants.IVY_XML_FILE);
        if (ivyXmlFile.exists()) {
            // IDE-1044
            addIvyNature(project, monitor);
            IvyClasspathContainer ivycp = addIvyLibrary(project, monitor);
            if (ivycp != null) {
                IStatus status = ivycp.launchResolve(false, monitor);
                if (status.isOK()) {
                    final IWebProject webproject = LiferayCore.create(IWebProject.class, project);
                    if (webproject != null) {
                        final IFolder webinfFolder = webproject.getDefaultDocrootFolder().getFolder("WEB-INF");
                        if (webinfFolder != null) {
                            ComponentUtil.validateFolder(webinfFolder, monitor);
                        }
                    }
                } else {
                    return status;
                }
            }
        }
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) Version(org.osgi.framework.Version) IWebProject(com.liferay.ide.core.IWebProject) SDK(com.liferay.ide.sdk.core.SDK) IvyClasspathContainer(org.apache.ivyde.eclipse.cp.IvyClasspathContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 35 with IWebProject

use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.

the class LiferayLanguageFileEncodingTests method testHookProjectEncoding.

@Ignore
@Test
public void testHookProjectEncoding() throws Exception {
    if (shouldSkipBundleTests())
        return;
    final IProject hookProject = importProject("hooks", "Hook-Encoding-Test-hook");
    assertEquals(true, ProjectUtil.isHookProject(hookProject));
    final IFolder defaultDocrootFolder = LiferayCore.create(IWebProject.class, hookProject).getDefaultDocrootFolder();
    assertNotNull(defaultDocrootFolder);
    assertEquals(true, defaultDocrootFolder.exists());
    final IFolder defaultSrcFolder = defaultDocrootFolder.getFolder(new Path("WEB-INF/src/content/"));
    assertNotNull(defaultSrcFolder);
    assertEquals(true, defaultSrcFolder.exists());
    final IFile fileNameWithoutUnderscore = defaultSrcFolder.getFile("FileNameWithoutUnderscore.properties");
    assertEquals(true, isLanguagePropertiesFile(fileNameWithoutUnderscore));
    final IFile fileNameWithoutUnderscore_CorrectEncoding = defaultSrcFolder.getFile("FileNameWithoutUnderscore_CorrectEncoding.properties");
    assertEquals(true, isLanguagePropertiesFile(fileNameWithoutUnderscore_CorrectEncoding));
    final IFile fileNameWithoutUnderscore_IncorrectEncoding = defaultSrcFolder.getFile("FileNameWithoutUnderscore_IncorrectEncoding.properties");
    assertEquals(true, isLanguagePropertiesFile(fileNameWithoutUnderscore_IncorrectEncoding));
    final IFile fileNameWithUnderscore_CorrectEncoding = defaultSrcFolder.getFile("FileNameWithUnderscore_CorrectEncoding.properties");
    assertEquals(true, isLanguagePropertiesFile(fileNameWithUnderscore_CorrectEncoding));
    final IFile fileNameWithUnderscore_IncorrectEncoding = defaultSrcFolder.getFile("FileNameWithUnderscore_IncorrectEncoding.properties");
    assertEquals(true, isLanguagePropertiesFile(fileNameWithUnderscore_IncorrectEncoding));
    final IFile fileNameWithStar = defaultSrcFolder.getFile("FileNameWithStar.properties");
    assertEquals(true, isLanguagePropertiesFile(fileNameWithStar));
    final IFile fileNameWithStarCorrectEncoding = defaultSrcFolder.getFile("FileNameWithStarCorrectEncoding.properties");
    assertEquals(true, isLanguagePropertiesFile(fileNameWithStarCorrectEncoding));
    final IFile fileNameWithStarIncorrectEncoding = defaultSrcFolder.getFile("FileNameWithStarIncorrectEncoding.properties");
    assertEquals(true, isLanguagePropertiesFile(fileNameWithStarIncorrectEncoding));
    final IFile removeThisLineTest = defaultSrcFolder.getFile("RemoveThisLineTest.properties");
    assertEquals(true, isLanguagePropertiesFile(removeThisLineTest));
    waitForBuildAndValidation(hookProject);
    // test the filename without underscore
    assertEquals(false, hasEncodingMarker(fileNameWithoutUnderscore));
    assertEquals(false, hasEncodingMarker(fileNameWithoutUnderscore_CorrectEncoding));
    assertEquals(true, hasEncodingMarker(fileNameWithoutUnderscore_IncorrectEncoding));
    // test the filename with underscore
    assertEquals(false, hasEncodingMarker(fileNameWithUnderscore_CorrectEncoding));
    assertEquals(true, hasEncodingMarker(fileNameWithUnderscore_IncorrectEncoding));
    // test the filename with a wildcard "*"
    assertEquals(false, hasEncodingMarker(fileNameWithStar));
    assertEquals(false, hasEncodingMarker(fileNameWithStarCorrectEncoding));
    assertEquals(true, hasEncodingMarker(fileNameWithStarIncorrectEncoding));
    // test an incorrect encoding file referenced by liferay-hook.xml
    // remove the reference line, the marker will disappear.
    assertEquals(true, hasEncodingMarker(removeThisLineTest));
    IWebProject webProject = LiferayCore.create(IWebProject.class, hookProject);
    final IFile liferayHookXml = webProject.getDescriptorFile(ILiferayConstants.LIFERAY_HOOK_XML_FILE);
    assertNotNull(liferayHookXml);
    removeSpecifiedNode(liferayHookXml, "language-properties", "content/RemoveThisLineTest.properties");
    waitForBuildAndValidation(hookProject);
    assertEquals(false, hasEncodingMarker(removeThisLineTest));
    /*
         * Both encoding action and quick fix of the encoding marker invoke method
         * PropertiesUtils.encodeLanguagePropertiesFilesToDefault(),
         * so here we only test this method and re-check the existence of markers.
         */
    // test encoding one properties file to default, take FileNameWithoutUnderscore_IncorrectEncoding for example.
    PropertiesUtil.encodeLanguagePropertiesFilesToDefault(fileNameWithoutUnderscore_IncorrectEncoding, new NullProgressMonitor());
    waitForBuildAndValidation(hookProject);
    assertEquals(false, hasEncodingMarker(fileNameWithoutUnderscore_IncorrectEncoding));
    // test encoding all properties files of this project to default.
    PropertiesUtil.encodeLanguagePropertiesFilesToDefault(hookProject, new NullProgressMonitor());
    waitForBuildAndValidation(hookProject);
    assertEquals(false, hasEncodingMarker(fileNameWithUnderscore_IncorrectEncoding));
    assertEquals(false, hasEncodingMarker(fileNameWithStarIncorrectEncoding));
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IWebProject(com.liferay.ide.core.IWebProject) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

IWebProject (com.liferay.ide.core.IWebProject)46 IFolder (org.eclipse.core.resources.IFolder)31 IFile (org.eclipse.core.resources.IFile)27 IProject (org.eclipse.core.resources.IProject)25 IPath (org.eclipse.core.runtime.IPath)24 Path (org.eclipse.core.runtime.Path)20 CoreException (org.eclipse.core.runtime.CoreException)15 IResource (org.eclipse.core.resources.IResource)10 IStatus (org.eclipse.core.runtime.IStatus)6 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)5 IOException (java.io.IOException)5 Test (org.junit.Test)5 SDK (com.liferay.ide.sdk.core.SDK)4 Path (org.eclipse.sapphire.modeling.Path)4 CustomJspDir (com.liferay.ide.hook.core.model.CustomJspDir)3 InputStream (java.io.InputStream)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 HookDescriptorHelper (com.liferay.ide.hook.core.dd.HookDescriptorHelper)2 Hook (com.liferay.ide.hook.core.model.Hook)2 File (java.io.File)2