Search in sources :

Example 16 with ILiferayRuntime

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);
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IViewPart(org.eclipse.ui.IViewPart) Properties(java.util.Properties) URL(java.net.URL) ConnectionProfileException(org.eclipse.datatools.connectivity.ConnectionProfileException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ILiferayRuntime(com.liferay.ide.server.core.ILiferayRuntime) URLClassLoader(java.net.URLClassLoader) Job(org.eclipse.core.runtime.jobs.Job) File(java.io.File)

Example 17 with ILiferayRuntime

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ILiferayProject(com.liferay.ide.core.ILiferayProject) ILiferayRuntime(com.liferay.ide.server.core.ILiferayRuntime) ILiferayPortal(com.liferay.ide.core.ILiferayPortal) JarFile(java.util.jar.JarFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput) IOException(java.io.IOException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) IRuntime(org.eclipse.wst.server.core.IRuntime)

Example 18 with ILiferayRuntime

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) NodeFormatter(org.eclipse.wst.xml.core.internal.provisional.format.NodeFormatter) Node(org.w3c.dom.Node) ILiferayRuntime(com.liferay.ide.server.core.ILiferayRuntime) Element(org.w3c.dom.Element) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

ILiferayRuntime (com.liferay.ide.server.core.ILiferayRuntime)18 CoreException (org.eclipse.core.runtime.CoreException)10 File (java.io.File)9 IPath (org.eclipse.core.runtime.IPath)7 Version (org.osgi.framework.Version)6 IRuntime (org.eclipse.wst.server.core.IRuntime)5 URL (java.net.URL)4 ArrayList (java.util.ArrayList)3 JarFile (java.util.jar.JarFile)3 IStatus (org.eclipse.core.runtime.IStatus)3 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 IServer (org.eclipse.wst.server.core.IServer)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 IFile (org.eclipse.core.resources.IFile)2 IProject (org.eclipse.core.resources.IProject)2 Path (org.eclipse.core.runtime.Path)2 IClasspathContainer (org.eclipse.jdt.core.IClasspathContainer)2 ILiferayPortal (com.liferay.ide.core.ILiferayPortal)1 ILiferayProject (com.liferay.ide.core.ILiferayProject)1