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;
}
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);
}
}
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);
}
}
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());
}
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;
}
Aggregations