Search in sources :

Example 11 with IWebProject

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

the class PropertiesUtil method hasNonDefaultEncodingLanguagePropertiesFile.

public static boolean hasNonDefaultEncodingLanguagePropertiesFile(IProject project) {
    if (!CoreUtil.isLiferayProject(project)) {
        project = CoreUtil.getLiferayProject(project);
    }
    if (project == null) {
        return false;
    }
    try {
        IWebProject webProject = LiferayCore.create(IWebProject.class, project);
        if (webProject == null) {
            return false;
        }
        IFile[] resourceFiles = getLanguagePropertiesFromPortletXml(webProject.getDescriptorFile(ILiferayConstants.PORTLET_XML_FILE));
        for (IFile file : resourceFiles) {
            if (!ILiferayConstants.LANGUAGE_PROPERTIES_FILE_ENCODING_CHARSET.equals(file.getCharset())) {
                return true;
            }
        }
        IFile[] languageFiles = getLanguagePropertiesFromLiferayHookXml(webProject.getDescriptorFile(ILiferayConstants.LIFERAY_HOOK_XML_FILE));
        for (IFile file : languageFiles) {
            if (!ILiferayConstants.LANGUAGE_PROPERTIES_FILE_ENCODING_CHARSET.equals(file.getCharset())) {
                return true;
            }
        }
    } catch (CoreException ce) {
        LiferayCore.logError(ce);
    }
    return false;
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IWebProject(com.liferay.ide.core.IWebProject)

Example 12 with IWebProject

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

the class PortalSourceLookupParticipant method getSourceName.

public String getSourceName(Object object) throws CoreException {
    String retval = null;
    if (object instanceof FMStackFrame) {
        try {
            FMStackFrame frame = (FMStackFrame) object;
            String templateName = getTemplateName(frame);
            // if( templateName.matches( "^\\d+#\\d+#\\d+$" ) ) //$NON-NLS-1$
            // {
            // retval = templateName + ".ftl"; //$NON-NLS-1$
            // }
            // else
            // {
            // we need to figure out how to map this back to a valid project path.
            // first if it contains a path that points to an existing plugin project
            IPath templatePath = new Path(templateName);
            final String firstSegment = templatePath.segment(0);
            final String resourcePath = templatePath.removeFirstSegments(1).toPortableString();
            IProject project = ServerUtil.findProjectByContextName(firstSegment);
            final IWebProject webproject = LiferayCore.create(IWebProject.class, project);
            if (webproject != null) {
                // first lets see if we can find
                final String diffsPath = "_diffs/" + resourcePath;
                final IResource diffsResourceFile = webproject.findDocrootResource(new Path(diffsPath));
                if (diffsResourceFile.exists()) {
                    retval = diffsPath;
                } else {
                    final IResource resourceFile = webproject.findDocrootResource(new Path(resourcePath));
                    if (resourceFile.exists()) {
                        retval = resourcePath;
                    }
                }
            }
        } catch (Exception e) {
        }
    }
    return retval;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) FMStackFrame(com.liferay.ide.portal.core.debug.fm.FMStackFrame) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource) CoreException(org.eclipse.core.runtime.CoreException) DebugException(org.eclipse.debug.core.DebugException)

Example 13 with IWebProject

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

the class SDKProjectRemoteServerPublisher method publishModuleFull.

@Override
public IPath publishModuleFull(IProgressMonitor monitor) throws CoreException {
    IPath deployPath = LiferayServerCore.getTempLocation("direct-deploy", StringPool.EMPTY);
    File warFile = deployPath.append(getProject().getName() + ".war").toFile();
    warFile.getParentFile().mkdirs();
    Map<String, String> properties = new HashMap<>();
    properties.put(ISDKConstants.PROPERTY_AUTO_DEPLOY_UNPACK_WAR, "false");
    ILiferayRuntime runtime = ServerUtil.getLiferayRuntime(getProject());
    String appServerDeployDirProp = ServerUtil.getAppServerPropertyKey(ISDKConstants.PROPERTY_APP_SERVER_DEPLOY_DIR, runtime);
    properties.put(appServerDeployDirProp, deployPath.toOSString());
    // IDE-1073 LPS-37923
    properties.put(ISDKConstants.PROPERTY_PLUGIN_FILE_DEFAULT, warFile.getAbsolutePath());
    properties.put(ISDKConstants.PROPERTY_PLUGIN_FILE, warFile.getAbsolutePath());
    String fileTimeStamp = System.currentTimeMillis() + "";
    // IDE-1491
    properties.put(ISDKConstants.PROPERTY_LP_VERSION, fileTimeStamp);
    properties.put(ISDKConstants.PROPERTY_LP_VERSION_SUFFIX, ".0");
    IStatus status = _sdk.validate();
    if (!status.isOK()) {
        throw new CoreException(status);
    }
    IStatus directDeployStatus = _sdk.war(getProject(), properties, true, new String[] { "-Duser.timezone=GMT" }, monitor);
    if (!directDeployStatus.isOK() || !warFile.exists()) {
        String pluginVersion = "1";
        IPath pluginPropertiesPath = new Path("WEB-INF/liferay-plugin-package.properties");
        IWebProject webproject = LiferayCore.create(IWebProject.class, getProject());
        if (webproject != null) {
            IResource propsRes = webproject.findDocrootResource(pluginPropertiesPath);
            if (propsRes instanceof IFile && propsRes.exists()) {
                try {
                    PropertiesConfiguration pluginPackageProperties = new PropertiesConfiguration();
                    InputStream is = ((IFile) propsRes).getContents();
                    pluginPackageProperties.load(is);
                    pluginVersion = pluginPackageProperties.getString("module-incremental-version");
                    is.close();
                } catch (Exception e) {
                    LiferayCore.logError("error reading module-incremtnal-version. ", e);
                }
            }
            IPath distPath = _sdk.getLocation().append("dist");
            String fullName = getProject().getName() + "-" + fileTimeStamp + "." + pluginVersion + ".0.war";
            warFile = distPath.append(fullName).toFile();
            if (!warFile.exists()) {
                throw new CoreException(directDeployStatus);
            }
        }
    }
    return new Path(warFile.getAbsolutePath());
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) IWebProject(com.liferay.ide.core.IWebProject) InputStream(java.io.InputStream) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) CoreException(org.eclipse.core.runtime.CoreException) CoreException(org.eclipse.core.runtime.CoreException) ILiferayRuntime(com.liferay.ide.server.core.ILiferayRuntime) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IResource(org.eclipse.core.resources.IResource)

Example 14 with IWebProject

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

the class PortletPluginFacetInstall method execute.

/**
 * IDE-815 Now with contributed portlet_2_0 uri we no longer need to copy TLD to
 * user's project
 */
@Override
public void execute(IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor) throws CoreException {
    super.execute(project, fv, config, monitor);
    IDataModel model = (IDataModel) config;
    IDataModel masterModel = (IDataModel) model.getProperty(FacetInstallDataModelProvider.MASTER_PROJECT_DM);
    if ((masterModel != null) && masterModel.getBooleanProperty(CREATE_PROJECT_OPERATION)) {
        // IDE-1122 SDK creating project has been moved to Class NewPluginProjectWizard
        String portletName = this.masterModel.getStringProperty(PORTLET_NAME);
        IPath projectTempPath = (IPath) masterModel.getProperty(PROJECT_TEMP_PATH);
        processNewFiles(projectTempPath.append(portletName + ISDKConstants.PORTLET_PLUGIN_PROJECT_SUFFIX));
        FileUtil.deleteDir(projectTempPath.toFile(), true);
        try {
            this.project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
        } catch (Exception e) {
            ProjectCore.logError(e);
        }
        if (masterModel.getBooleanProperty(PLUGIN_FRAGMENT_ENABLED)) {
            IDataModel fragmentModel = masterModel.getNestedModel(PLUGIN_FRAGMENT_DM);
            if (fragmentModel != null) {
                try {
                    if (fragmentModel.getBooleanProperty(IPluginWizardFragmentProperties.REMOVE_EXISTING_ARTIFACTS)) {
                        // IDE-110 IDE-648
                        IWebProject lrproject = LiferayCore.create(IWebProject.class, project);
                        IFolder webappRoot = lrproject.getDefaultDocrootFolder();
                        if (FileUtil.exists(webappRoot)) {
                            IFile viewJsp = webappRoot.getFile(new Path("view.jsp"));
                            if (FileUtil.exists(viewJsp)) {
                                viewJsp.delete(true, monitor);
                            }
                        }
                    }
                } catch (Exception ex) {
                    ProjectCore.logError("Error deleting view.jsp", ex);
                }
            }
        }
    } else if (shouldSetupDefaultOutputLocation()) {
        setupDefaultOutputLocation();
    }
    /*
		 * IDE-815 Now with contributed portlet_2_0 uri we no longer need to copy TLD to
		 * user's project
		 */
    try {
        this.project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
    } catch (Exception e1) {
        ProjectCore.logError(e1);
    }
    try {
        Bundle bundle = JSPCorePlugin.getDefault().getBundle();
        IEclipsePreferences node = new ProjectScope(this.project).getNode(bundle.getSymbolicName());
        node.putBoolean(JSPCorePreferenceNames.VALIDATE_FRAGMENTS, false);
        node.putBoolean(JSPCorePreferenceNames.VALIDATION_USE_PROJECT_SETTINGS, true);
        node.flush();
    } catch (Exception e) {
        ProjectCore.logError("Could not store jsp fragment validation preference", e);
    }
    if (shouldConfigureDeploymentAssembly()) {
        // IDE-565
        configureDeploymentAssembly(IPluginFacetConstants.PORTLET_PLUGIN_SDK_SOURCE_FOLDER, DEFAULT_DEPLOY_PATH);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ProjectScope(org.eclipse.core.resources.ProjectScope) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IWebProject(com.liferay.ide.core.IWebProject) Bundle(org.osgi.framework.Bundle) IDataModel(org.eclipse.wst.common.frameworks.datamodel.IDataModel) CoreException(org.eclipse.core.runtime.CoreException) IFolder(org.eclipse.core.resources.IFolder)

Example 15 with IWebProject

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

the class NewLiferayPluginProjectOpMethods method _removeSampleCodeAndFiles.

private static IStatus _removeSampleCodeAndFiles(NewLiferayPluginProjectOp op) {
    IStatus status = org.eclipse.core.runtime.Status.OK_STATUS;
    boolean includeSampleCode = op.getIncludeSampleCode().content();
    if (includeSampleCode) {
        return status;
    }
    IProject project = CoreUtil.getLiferayProject(op.getFinalProjectName().content());
    if (FileUtil.exists(project)) {
        ProjectCore.operate(project, RemoveSampleElementsOperation.class);
        try {
            IWebProject webproject = LiferayCore.create(IWebProject.class, project);
            if (webproject == null) {
                return status;
            }
            IFolder docroot = webproject.getDefaultDocrootFolder();
            IFile[] sampleFiles = { docroot.getFile("view.jsp"), docroot.getFile("css/main.css"), docroot.getFile("js/main.js") };
            for (IFile file : sampleFiles) {
                if (FileUtil.exists(file)) {
                    file.delete(true, new NullProgressMonitor());
                    if (file.getParent().members().length == 0) {
                        CoreUtil.deleteResource(file.getParent());
                    }
                }
            }
        } catch (CoreException ce) {
            ProjectCore.logError("Error deleting sample files.", ce);
        }
    }
    return status;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IWebProject(com.liferay.ide.core.IWebProject) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

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