Search in sources :

Example 6 with PortalBundle

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

the class PluginsSDKProjectProvider method provide.

@Override
public ILiferayProject provide(Object type) {
    if (type instanceof IProject) {
        IProject project = (IProject) type;
        if (!SDKUtil.isSDKProject(project)) {
            return null;
        }
        try {
            IJavaProject javaProject = JavaCore.create(project);
            boolean hasNewSdk = ClasspathUtil.hasNewLiferaySDKContainer(javaProject.getRawClasspath());
            if (hasNewSdk) {
                PortalBundle portalBundle = ServerUtil.getPortalBundle(project);
                if (portalBundle != null) {
                    return new PluginsSDKBundleProject(project, portalBundle);
                }
            } else {
                ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(project);
                if (liferayRuntime != null) {
                    return new PluginsSDKRuntimeProject(project, liferayRuntime);
                }
            }
        } catch (CoreException ce) {
        }
    } else if (type instanceof IRuntime) {
        try {
            IRuntime runtime = (IRuntime) type;
            ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(runtime);
            if (liferayRuntime != null) {
                return new PluginsSDKRuntimeProject(null, liferayRuntime);
            }
        } catch (Exception e) {
        }
    }
    return null;
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) PortalBundle(com.liferay.ide.server.core.portal.PortalBundle) CoreException(org.eclipse.core.runtime.CoreException) ILiferayRuntime(com.liferay.ide.server.core.ILiferayRuntime) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) IRuntime(org.eclipse.wst.server.core.IRuntime)

Example 7 with PortalBundle

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

the class SDKClasspathContainerInitializer method requestClasspathContainerUpdate.

@Override
public void requestClasspathContainerUpdate(IPath containerPath, IJavaProject project, IClasspathContainer containerSuggestion) throws CoreException {
    String key = SDKClasspathContainer.getDecorationManagerKey(project.getProject(), containerPath.toString());
    IClasspathEntry[] entries = containerSuggestion.getClasspathEntries();
    cpDecorations.clearAllDecorations(key);
    for (int i = 0; i < entries.length; i++) {
        IClasspathEntry entry = entries[i];
        IPath srcpath = entry.getSourceAttachmentPath();
        IPath srcrootpath = entry.getSourceAttachmentRootPath();
        IClasspathAttribute[] attrs = entry.getExtraAttributes();
        if ((srcpath != null) || ListUtil.isNotEmpty(attrs)) {
            String eid = entry.getPath().toString();
            ClasspathDecorations dec = new ClasspathDecorations();
            dec.setSourceAttachmentPath(srcpath);
            dec.setSourceAttachmentRootPath(srcrootpath);
            dec.setExtraAttributes(attrs);
            cpDecorations.setDecorations(key, eid, dec);
        }
    }
    cpDecorations.save();
    IPath portalDir = null;
    IPath portalGlobalDir = null;
    String javadocURL = null;
    IPath sourceLocation = null;
    IPath bundleDir = null;
    IPath[] bundleDependencyJarPaths = null;
    PortalBundle bundle = ServerUtil.getPortalBundle(project.getProject());
    boolean containerChanged = true;
    if (containerSuggestion instanceof SDKClasspathContainer) {
        portalDir = ((SDKClasspathContainer) containerSuggestion).getPortalDir();
        bundleDir = ((SDKClasspathContainer) containerSuggestion).getBundleDir();
        portalGlobalDir = ((SDKClasspathContainer) containerSuggestion).getPortalGlobalDir();
        javadocURL = ((SDKClasspathContainer) containerSuggestion).getJavadocURL();
        sourceLocation = ((SDKClasspathContainer) containerSuggestion).getSourceLocation();
        bundleDependencyJarPaths = ((SDKClasspathContainer) containerSuggestion).getBundleLibDependencyPath();
        if ((bundle != null) && bundle.getAppServerPortalDir().equals(portalDir)) {
            containerChanged = false;
        }
    }
    if (containerChanged == true) {
        if (bundle == null) {
            return;
        }
        portalDir = bundle.getAppServerPortalDir();
        portalGlobalDir = bundle.getAppServerLibGlobalDir();
        bundleDependencyJarPaths = bundle.getBundleDependencyJars();
    }
    IPath[] sdkDependencyPaths = _getSDKDependencies(project);
    if ((portalDir != null) && (portalGlobalDir != null)) {
        IClasspathContainer newContainer = new SDKClasspathContainer(containerPath, project, portalDir, javadocURL, sourceLocation, portalGlobalDir, bundleDir, bundleDependencyJarPaths, sdkDependencyPaths);
        IJavaProject[] projects = { project };
        IClasspathContainer[] containers = { newContainer };
        JavaCore.setClasspathContainer(containerPath, projects, containers, null);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IJavaProject(org.eclipse.jdt.core.IJavaProject) PortalBundle(com.liferay.ide.server.core.portal.PortalBundle) ClasspathDecorations(org.eclipse.jst.common.jdt.internal.classpath.ClasspathDecorations) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer)

Example 8 with PortalBundle

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

the class LiferayWorkspaceUtil method addPortalRuntime.

public static void addPortalRuntime() {
    IProject project = getWorkspaceProject();
    IPath bundlesLocation = getHomeLocation(project);
    try {
        if (FileUtil.exists(bundlesLocation)) {
            PortalBundle bundle = LiferayServerCore.newPortalBundle(bundlesLocation);
            if (bundle == null) {
                ProjectCore.logError("Can not create bundle from location :" + bundlesLocation);
                return;
            }
            String serverName = bundle.getServerReleaseInfo();
            ServerUtil.addPortalRuntimeAndServer(serverName, bundlesLocation, new NullProgressMonitor());
            IProject pluginsSDK = CoreUtil.getProject(LiferayWorkspaceUtil.getPluginsSDKDir(project.getLocation().toPortableString()));
            if (FileUtil.exists(pluginsSDK)) {
                SDK sdk = SDKUtil.createSDKFromLocation(pluginsSDK.getLocation());
                sdk.addOrUpdateServerProperties(ServerUtil.getLiferayRuntime(ServerUtil.getServer(serverName)).getLiferayHome());
                pluginsSDK.refreshLocal(IResource.DEPTH_INFINITE, null);
            }
        }
    } catch (Exception e) {
        ProjectCore.logError("Add Liferay server failed", e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) PortalBundle(com.liferay.ide.server.core.portal.PortalBundle) SDK(com.liferay.ide.sdk.core.SDK) IProject(org.eclipse.core.resources.IProject) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException)

Example 9 with PortalBundle

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

the class PortalBundleTests method testPortalBundleReleaseName.

@Test
public void testPortalBundleReleaseName() throws Exception {
    if (shouldSkipBundleTests())
        return;
    PortalBundle bundle = LiferayServerCore.newPortalBundle(getLiferayRuntimeDir());
    assertNotNull(bundle);
    assertEquals("Liferay Community Edition Portal 7.0.4 GA5", bundle.getServerReleaseInfo());
}
Also used : PortalBundle(com.liferay.ide.server.core.portal.PortalBundle) Test(org.junit.Test)

Example 10 with PortalBundle

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

the class ServerUtil method getModuleFileFrom70Server.

public static File getModuleFileFrom70Server(IRuntime runtime, String hostOsgiBundle, IPath temp) {
    final File f = new File(temp.toFile(), hostOsgiBundle);
    if (f.exists()) {
        return f;
    }
    PortalBundle portalBundle = LiferayServerCore.newPortalBundle(runtime.getLocation());
    String[] dirs = new String[] { "core", "modules", "portal", "static" };
    for (String dir : dirs) {
        File portalModuleDir = portalBundle.getOSGiBundlesDir().append(dir).toFile();
        File moduleOsgiBundle = new File(portalModuleDir, hostOsgiBundle);
        if (moduleOsgiBundle.exists()) {
            return copyModuleBundleJar(moduleOsgiBundle, temp);
        } else {
            int index = hostOsgiBundle.indexOf("-");
            if (index > 0) {
                String hostOsgiBundleWithoutVersion = hostOsgiBundle.substring(0, index) + ".jar";
                File moduleOsgiBundleWithoutVersion = new File(portalModuleDir, hostOsgiBundleWithoutVersion);
                if (moduleOsgiBundleWithoutVersion.exists()) {
                    return copyModuleBundleJar(moduleOsgiBundleWithoutVersion, temp);
                }
            }
        }
    }
    File[] files = getMarketplaceLpkgFiles(portalBundle);
    InputStream in = null;
    try {
        boolean found = false;
        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.contains(hostOsgiBundle)) {
                        in = jar.getInputStream(entry);
                        found = true;
                        FileUtil.writeFile(f, in);
                        break;
                    }
                }
                if (found) {
                    break;
                }
            }
        }
    } catch (Exception e) {
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
            }
        }
    }
    return f;
}
Also used : JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) 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) PortalBundle(com.liferay.ide.server.core.portal.PortalBundle) JarFile(java.util.jar.JarFile) File(java.io.File)

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