Search in sources :

Example 1 with PortalBundle

use of com.liferay.ide.server.core.portal.PortalBundle in project liferay-ide by liferay.

the class PluginsSDKProjectProvider method createNewProject.

@Override
public IStatus createNewProject(NewLiferayPluginProjectOp op, IProgressMonitor monitor) throws CoreException {
    ElementList<ProjectName> projectNames = op.getProjectNames();
    PluginType pluginType = op.getPluginType().content(true);
    String originalProjectName = op.getProjectName().content();
    String pluginTypeSuffix = NewLiferayPluginProjectOpMethods.getPluginTypeSuffix(pluginType);
    String fixedProjectName = originalProjectName;
    if (originalProjectName.endsWith(pluginTypeSuffix)) {
        fixedProjectName = originalProjectName.substring(0, originalProjectName.length() - pluginTypeSuffix.length());
    }
    String projectName = fixedProjectName;
    String displayName = op.getDisplayName().content(true);
    boolean separateJRE = true;
    SDK sdk = _getSDK(op);
    if (sdk == null) {
        return ProjectCore.createErrorStatus("Can not get correct SDK for " + fixedProjectName + ", Please check SDK configuration setting.");
    }
    // workingDir should always be the directory of the type of plugin /sdk/portlets/ for a portlet, etc
    String workingDir = null;
    ArrayList<String> arguments = new ArrayList<>();
    arguments.add(projectName);
    arguments.add(displayName);
    boolean hasGradleTools = SDKUtil.hasGradleTools(sdk.getLocation());
    IPath newSDKProjectPath = null;
    IPath path = null;
    switch(pluginType) {
        case servicebuilder:
            op.setPortletFramework("mvc");
        case portlet:
            path = sdk.getLocation().append(ISDKConstants.PORTLET_PLUGIN_PROJECT_FOLDER);
            String frameworkName = NewLiferayPluginProjectOpMethods.getFrameworkName(op);
            workingDir = path.toOSString();
            if (hasGradleTools) {
                arguments.add(frameworkName);
                sdk.createNewProject(projectName, arguments, "portlet", workingDir, monitor);
            } else {
                newSDKProjectPath = sdk.createNewPortletProject(projectName, displayName, frameworkName, separateJRE, workingDir, null, monitor);
            }
            break;
        case hook:
            path = sdk.getLocation().append(ISDKConstants.HOOK_PLUGIN_PROJECT_FOLDER);
            workingDir = path.toOSString();
            if (hasGradleTools) {
                sdk.createNewProject(projectName, arguments, "hook", workingDir, monitor);
            } else {
                newSDKProjectPath = sdk.createNewHookProject(projectName, displayName, separateJRE, workingDir, null, monitor);
            }
            break;
        case ext:
            path = sdk.getLocation().append(ISDKConstants.EXT_PLUGIN_PROJECT_FOLDER);
            workingDir = path.toOSString();
            if (hasGradleTools) {
                sdk.createNewProject(projectName, arguments, "ext", workingDir, monitor);
            } else {
                newSDKProjectPath = sdk.createNewExtProject(projectName, displayName, separateJRE, workingDir, null, monitor);
            }
            break;
        case layouttpl:
            path = sdk.getLocation().append(ISDKConstants.LAYOUTTPL_PLUGIN_PROJECT_FOLDER);
            workingDir = path.toOSString();
            if (hasGradleTools) {
                sdk.createNewProject(projectName, arguments, "layouttpl", workingDir, monitor);
            } else {
                newSDKProjectPath = sdk.createNewLayoutTplProject(projectName, displayName, separateJRE, workingDir, null, monitor);
            }
            IProject layoutProject = ProjectUtil.getProject(projectName);
            if (!LiferayDescriptorHelper.getDescriptorVersion(layoutProject).equals("6.2.0")) {
                IPath projectPath = newSDKProjectPath.append(projectName + pluginTypeSuffix);
                IPath fileWap = projectPath.append("docroot").append("blank_columns.wap.tpl");
                if (FileUtil.exists(fileWap)) {
                    fileWap.toFile().delete();
                }
            }
            break;
        case theme:
            path = sdk.getLocation().append(ISDKConstants.THEME_PLUGIN_PROJECT_FOLDER);
            workingDir = path.toOSString();
            if (hasGradleTools) {
                sdk.createNewProject(projectName, arguments, "theme", workingDir, monitor);
            } else {
                newSDKProjectPath = sdk.createNewThemeProject(projectName, displayName, separateJRE, workingDir, null, monitor);
            }
            break;
        case web:
            path = sdk.getLocation().append(ISDKConstants.WEB_PLUGIN_PROJECT_FOLDER);
            workingDir = path.toOSString();
            if (hasGradleTools) {
                sdk.createNewProject(projectName, arguments, "web", workingDir, monitor);
            } else {
                newSDKProjectPath = sdk.createNewWebProject(projectName, displayName, separateJRE, workingDir, null, monitor);
            }
            break;
    }
    NewLiferayPluginProjectOpMethods.updateLocation(op);
    Path projectLocation = op.getLocation().content();
    if (!hasGradleTools) {
        File projectDir = projectLocation.toFile();
        File projectParent = projectDir.getParentFile();
        projectParent.mkdirs();
        if (FileUtil.notExists(newSDKProjectPath)) {
            return ProjectCore.createErrorStatus("Error create project due to '" + newSDKProjectPath + "' does not exist.");
        }
        File newSDKProjectDir = newSDKProjectPath.toFile();
        try {
            FileUtils.copyDirectory(newSDKProjectDir, projectParent);
            FileUtils.deleteDirectory(newSDKProjectDir);
        } catch (IOException ioe) {
            throw new CoreException(ProjectCore.createErrorStatus(ioe));
        }
    }
    ProjectRecord projectRecord = ProjectUtil.getProjectRecordForDir(projectLocation.toOSString());
    IProject newProject = ProjectImportUtil.importProject(projectRecord.getProjectLocation(), monitor, op);
    newProject.open(monitor);
    // need to update project name incase the suffix was not correct
    op.setFinalProjectName(newProject.getName());
    projectNames.insert().setName(op.getFinalProjectName().content());
    _projectCreated(newProject);
    switch(op.getPluginType().content()) {
        case portlet:
            _portletProjectCreated(op, newProject, monitor);
            break;
        case servicebuilder:
            PortalBundle bundle = ServerUtil.getPortalBundle(newProject);
            _serviceBuilderProjectCreated(bundle.getVersion(), newProject, monitor);
            break;
        case theme:
            _themeProjectCreated(newProject);
            break;
        default:
            break;
    }
    return Status.OK_STATUS;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) IPath(org.eclipse.core.runtime.IPath) ProjectName(com.liferay.ide.project.core.model.ProjectName) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PluginType(com.liferay.ide.project.core.model.PluginType) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) PortalBundle(com.liferay.ide.server.core.portal.PortalBundle) SDK(com.liferay.ide.sdk.core.SDK) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 2 with PortalBundle

use of com.liferay.ide.server.core.portal.PortalBundle in project liferay-ide by liferay.

the class SDKClasspathContainerInitializer method initialize.

@Override
public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
    IClasspathContainer classpathContainer = null;
    String root = containerPath.segment(0);
    if (!SDKClasspathContainer.ID.equals(root)) {
        String msg = "Invalid plugin classpath container, expecting container root ";
        throw new CoreException(ProjectCore.createErrorStatus(msg + SDKClasspathContainer.ID));
    }
    PortalBundle bundle = ServerUtil.getPortalBundle(project.getProject());
    if (bundle == null) {
        String msg = "Invalid sdk properties setting.";
        throw new CoreException(ProjectCore.createErrorStatus(msg));
    }
    IPath globalDir = bundle.getAppServerLibGlobalDir();
    IPath portalDir = bundle.getAppServerPortalDir();
    IPath bundleDir = bundle.getAppServerDir();
    IPath[] bundleDependencyJars = bundle.getBundleDependencyJars();
    IPath[] sdkDependencyJarPaths = _getSDKDependencies(project);
    if (portalDir == null) {
        return;
    }
    classpathContainer = new SDKClasspathContainer(containerPath, project, portalDir, null, null, globalDir, bundleDir, bundleDependencyJars, sdkDependencyJarPaths);
    IJavaProject[] projects = { project };
    IClasspathContainer[] containers = { classpathContainer };
    JavaCore.setClasspathContainer(containerPath, projects, containers, null);
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) PortalBundle(com.liferay.ide.server.core.portal.PortalBundle) IPath(org.eclipse.core.runtime.IPath) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer)

Example 3 with PortalBundle

use of com.liferay.ide.server.core.portal.PortalBundle in project liferay-ide by liferay.

the class ServerUtil method getModuleFileListFrom70Server.

public static List<String> getModuleFileListFrom70Server(IRuntime runtime) {
    List<String> bundles = new ArrayList<>();
    PortalBundle portalBundle = LiferayServerCore.newPortalBundle(runtime.getLocation());
    String[] dirs = new String[] { "core", "modules", "portal", "static" };
    if (portalBundle != null) {
        try {
            for (String dir : dirs) {
                File dirFile = portalBundle.getOSGiBundlesDir().append(dir).toFile();
                if (dirFile.exists()) {
                    File[] files = dirFile.listFiles(new FilenameFilter() {

                        @Override
                        public boolean accept(File dir, String name) {
                            return name.matches(".*\\.jar");
                        }
                    });
                    if (ListUtil.isNotEmpty(files)) {
                        for (File file : files) {
                            bundles.add(file.getName());
                        }
                    }
                }
            }
        } catch (Exception e) {
            LiferayServerCore.logError("Could not determine possible files.", e);
        }
        File[] files = ServerUtil.getMarketplaceLpkgFiles(portalBundle);
        for (File file : files) {
            try (JarFile jar = new JarFile(file)) {
                Enumeration<JarEntry> enu = jar.entries();
                while (enu.hasMoreElements()) {
                    JarEntry entry = enu.nextElement();
                    String name = entry.getName();
                    if (name.endsWith(".jar")) {
                        bundles.add(name);
                    }
                }
            } catch (IOException e) {
            }
        }
    }
    return bundles;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) CoreException(org.eclipse.core.runtime.CoreException) DebugException(org.eclipse.debug.core.DebugException) IOException(java.io.IOException) FilenameFilter(java.io.FilenameFilter) PortalBundle(com.liferay.ide.server.core.portal.PortalBundle) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 4 with PortalBundle

use of com.liferay.ide.server.core.portal.PortalBundle in project liferay-ide by liferay.

the class ImportLiferayWorkspaceServerNameService method compute.

@Override
protected String compute() {
    Value<Path> workspaceLocation = _op().getWorkspaceLocation();
    Path path = workspaceLocation.content();
    if (path == null) {
        return StringPool.EMPTY;
    }
    String serverName = path.lastSegment() + " server";
    PortalBundle bundle = LiferayServerCore.newPortalBundle(PathBridge.create(path).append("bundles"));
    if (bundle != null) {
        serverName = bundle.getServerReleaseInfo();
    }
    return serverName;
}
Also used : Path(org.eclipse.sapphire.modeling.Path) PortalBundle(com.liferay.ide.server.core.portal.PortalBundle)

Example 5 with PortalBundle

use of com.liferay.ide.server.core.portal.PortalBundle in project liferay-ide by liferay.

the class PortalRuntimeComposite method updateFields.

private void updateFields() {
    final PortalRuntime portalRuntime = getPortalRuntime();
    if (portalRuntime != null) {
        final PortalBundle portalBundle = portalRuntime.getPortalBundle();
        setFieldValue(this.typeField, portalBundle != null ? portalBundle.getDisplayName() : StringPool.BLANK);
    }
}
Also used : PortalRuntime(com.liferay.ide.server.core.portal.PortalRuntime) PortalBundle(com.liferay.ide.server.core.portal.PortalBundle)

Aggregations

PortalBundle (com.liferay.ide.server.core.portal.PortalBundle)12 IOException (java.io.IOException)6 CoreException (org.eclipse.core.runtime.CoreException)6 IPath (org.eclipse.core.runtime.IPath)6 SDK (com.liferay.ide.sdk.core.SDK)3 File (java.io.File)3 JarFile (java.util.jar.JarFile)3 IProject (org.eclipse.core.resources.IProject)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 JarEntry (java.util.jar.JarEntry)2 DebugException (org.eclipse.debug.core.DebugException)2 IClasspathContainer (org.eclipse.jdt.core.IClasspathContainer)2 Path (org.eclipse.sapphire.modeling.Path)2 IRuntime (org.eclipse.wst.server.core.IRuntime)2 ILiferayPortal (com.liferay.ide.core.ILiferayPortal)1 PluginType (com.liferay.ide.project.core.model.PluginType)1 ProjectName (com.liferay.ide.project.core.model.ProjectName)1 ILiferayRuntime (com.liferay.ide.server.core.ILiferayRuntime)1