use of com.liferay.ide.server.core.ILiferayRuntime in project liferay-ide by liferay.
the class CreateDBConnectAction method run.
@SuppressWarnings("resource")
public void run(IAction action) {
if (selectedServer != null) {
final ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(selectedServer);
final Properties pluginPackageProperties = getDatabaseProperties(liferayRuntime.getLiferayHome());
final String driverName = // $NON-NLS-1$
pluginPackageProperties.getProperty(JDBC_DRIVER_CLASS_NAME, "org.hsqldb.jdbcDriver");
final String connectionName = liferayRuntime.getRuntime().getName();
// $NON-NLS-1$
final String userName = pluginPackageProperties.getProperty("jdbc.default.username");
// $NON-NLS-1$
final String connectionUrl = pluginPackageProperties.getProperty("jdbc.default.url");
// $NON-NLS-1$
final String password = pluginPackageProperties.getProperty("jdbc.default.password");
try {
final URL[] runtimeLibs = getLiferayRuntimeLibs(liferayRuntime);
new Job(Msgs.addDBConnnection) {
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
final Class<?> classRef = new URLClassLoader(runtimeLibs).loadClass(driverName);
if (classRef != null) {
final String libPath = classRef.getProtectionDomain().getCodeSource().getLocation().getPath();
// $NON-NLS-1$
final String jarPath = java.net.URLDecoder.decode(libPath, "UTF-8");
final String driverPath = new File(jarPath).getAbsolutePath();
final LiferayDatabaseConnection dbConnection = getLiferayDBConnection(driverName, userName, password, connectionUrl);
if (dbConnection != null) {
if (!dbConnection.addDatabaseConnectionProfile(connectionName, driverPath)) {
return LiferayServerUI.createErrorStatus("An error happened when create connection profile");
}
UIUtil.async(new Runnable() {
public void run() {
IViewPart dbView = // $NON-NLS-1$
UIUtil.showView("org.eclipse.datatools.connectivity.DataSourceExplorerNavigator");
dbView.setFocus();
}
});
}
}
} catch (Exception e) {
LiferayServerCore.logError(Msgs.addProfileError, e);
}
return Status.OK_STATUS;
}
}.schedule();
} catch (Exception e) {
LiferayServerCore.logError(Msgs.noDBConnectDriver, e);
}
}
}
use of com.liferay.ide.server.core.ILiferayRuntime in project liferay-ide by liferay.
the class LiferayPropertiesSourceViewerConfiguration method _getAppServerPortalDir.
private IPath _getAppServerPortalDir(IEditorInput input) {
IPath retval = null;
IFile ifile = input.getAdapter(IFile.class);
if (ifile != null) {
ILiferayProject project = LiferayCore.create(ifile.getProject());
if (project != null) {
ILiferayPortal portal = project.adapt(ILiferayPortal.class);
if (portal != null) {
retval = portal.getAppServerPortalDir();
}
}
} else {
File file = input.getAdapter(File.class);
if ((file == null) && input instanceof FileStoreEditorInput) {
FileStoreEditorInput fInput = (FileStoreEditorInput) input;
file = new File(fInput.getURI().getPath());
}
if ((file != null) && file.exists()) {
try {
IPath propsParentPath = new Path(file.getParentFile().getCanonicalPath());
for (IRuntime runtime : ServerCore.getRuntimes()) {
if (propsParentPath.equals(runtime.getLocation()) || propsParentPath.isPrefixOf(runtime.getLocation())) {
ILiferayRuntime lr = ServerUtil.getLiferayRuntime(runtime);
retval = lr.getAppServerPortalDir();
break;
}
}
} catch (Exception e) {
LiferayUIPlugin.logError("Unable to get portal language properties file", e);
}
}
}
return retval;
}
use of com.liferay.ide.server.core.ILiferayRuntime in project liferay-ide by liferay.
the class MavenUtil method createNewLiferayProfileNode.
public static Node createNewLiferayProfileNode(Document pomDocument, NewLiferayProfile newLiferayProfile) {
Node newNode = null;
String liferayVersion = newLiferayProfile.getLiferayVersion().content();
try {
String runtimeName = newLiferayProfile.getRuntimeName().content();
ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(ServerUtil.getRuntime(runtimeName));
Element root = pomDocument.getDocumentElement();
Element profiles = NodeUtil.findChildElement(root, "profiles");
if (profiles == null) {
newNode = profiles = NodeUtil.appendChildElement(root, "profiles");
}
Element newProfile = null;
if (profiles != null) {
NodeUtil.appendTextNode(profiles, "\n");
newProfile = NodeUtil.appendChildElement(profiles, "profile");
NodeUtil.appendTextNode(profiles, "\n");
if (newNode == null) {
newNode = newProfile;
}
}
if (newProfile != null) {
IPath serverDir = liferayRuntime.getAppServerDir();
IPath autoDeployDir = serverDir.removeLastSegments(1).append("deploy");
NodeUtil.appendTextNode(newProfile, "\n\t");
NodeUtil.appendChildElement(newProfile, "id", newLiferayProfile.getId().content());
NodeUtil.appendTextNode(newProfile, "\n\t");
Element propertiesElement = NodeUtil.appendChildElement(newProfile, "properties");
NodeUtil.appendTextNode(newProfile, "\n\t");
NodeUtil.appendTextNode(propertiesElement, "\n\t\t");
NodeUtil.appendChildElement(propertiesElement, "liferay.version", liferayVersion);
NodeUtil.appendTextNode(propertiesElement, "\n\t\t");
NodeUtil.appendChildElement(propertiesElement, "liferay.maven.plugin.version", liferayVersion);
NodeUtil.appendTextNode(propertiesElement, "\n\t\t");
NodeUtil.appendChildElement(propertiesElement, "liferay.auto.deploy.dir", autoDeployDir.toOSString());
NodeUtil.appendTextNode(propertiesElement, "\n\t\t");
NodeUtil.appendChildElement(propertiesElement, "liferay.app.server.deploy.dir", liferayRuntime.getAppServerDeployDir().toOSString());
NodeUtil.appendTextNode(propertiesElement, "\n\t\t");
NodeUtil.appendChildElement(propertiesElement, "liferay.app.server.lib.global.dir", liferayRuntime.getAppServerLibGlobalDir().toOSString());
NodeUtil.appendTextNode(propertiesElement, "\n\t\t");
NodeUtil.appendChildElement(propertiesElement, "liferay.app.server.portal.dir", liferayRuntime.getAppServerPortalDir().toOSString());
NodeUtil.appendTextNode(propertiesElement, "\n\t");
NodeFormatter formatter = new NodeFormatter();
formatter.format(newNode);
}
} catch (Exception e) {
LiferayMavenCore.logError("Unable to add new liferay profile.", e);
}
return newNode;
}
Aggregations