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