Search in sources :

Example 1 with OsgiClient

use of org.apache.sling.ide.osgi.OsgiClient in project sling by apache.

the class SlingLaunchpadBehaviour method publishBundleModule.

private void publishBundleModule(IModule[] module, IProgressMonitor monitor) throws CoreException {
    final IProject project = module[0].getProject();
    boolean installLocally = getServer().getAttribute(ISlingLaunchpadServer.PROP_INSTALL_LOCALLY, true);
    monitor.beginTask("deploying via local install", 5);
    try {
        OsgiClient osgiClient = Activator.getDefault().getOsgiClientFactory().createOsgiClient(ServerUtil.getRepositoryInfo(getServer(), monitor));
        Version supportBundleVersion = osgiClient.getBundleVersion(EmbeddedArtifactLocator.SUPPORT_BUNDLE_SYMBOLIC_NAME);
        monitor.worked(1);
        if (supportBundleVersion == null) {
            throw new CoreException(new Status(Status.ERROR, Activator.PLUGIN_ID, "The support bundle was not found, please install it via the server properties page."));
        }
        IJavaProject javaProject = ProjectHelper.asJavaProject(project);
        IFolder outputFolder = (IFolder) project.getWorkspace().getRoot().findMember(javaProject.getOutputLocation());
        IPath outputLocation = outputFolder.getLocation();
        //ensure the MANIFEST.MF exists - if it doesn't then let the publish fail with a warn (instead of an error)
        IResource manifest = outputFolder.findMember("META-INF/MANIFEST.MF");
        if (manifest == null) {
            Activator.getDefault().getPluginLogger().warn("Project " + project + " does not have a META-INF/MANIFEST.MF (yet) - not publishing this time");
            Activator.getDefault().issueConsoleLog("InstallBundle", outputFolder.getLocation().toOSString(), "Project " + project + " does not have a META-INF/MANIFEST.MF (yet) - not publishing this time");
            monitor.done();
            setModulePublishState(module, IServer.PUBLISH_STATE_FULL);
            return;
        }
        monitor.worked(1);
        //osgiClient must have a timeout!!!
        if (installLocally) {
            osgiClient.installLocalBundle(outputLocation.toOSString());
            monitor.worked(3);
        } else {
            JarBuilder builder = new JarBuilder();
            InputStream bundle = builder.buildJar(outputFolder);
            monitor.worked(1);
            osgiClient.installLocalBundle(bundle, outputFolder.getLocation().toOSString());
            monitor.worked(2);
        }
        setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
    } catch (URISyntaxException e1) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e1.getMessage(), e1));
    } catch (OsgiClientException e1) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed installing bundle : " + e1.getMessage(), e1));
    } finally {
        monitor.done();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) InputStream(java.io.InputStream) URISyntaxException(java.net.URISyntaxException) IProject(org.eclipse.core.resources.IProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) Version(org.osgi.framework.Version) OsgiClient(org.apache.sling.ide.osgi.OsgiClient) OsgiClientException(org.apache.sling.ide.osgi.OsgiClientException) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with OsgiClient

use of org.apache.sling.ide.osgi.OsgiClient in project sling by apache.

the class SlingLaunchpadBehaviour method start.

public void start(IProgressMonitor monitor) throws CoreException {
    boolean success = false;
    Result<ResourceProxy> result = null;
    monitor = SubMonitor.convert(monitor, "Starting server", 10).setWorkRemaining(50);
    Repository repository;
    RepositoryInfo repositoryInfo;
    OsgiClient client;
    try {
        repository = ServerUtil.connectRepository(getServer(), monitor);
        repositoryInfo = ServerUtil.getRepositoryInfo(getServer(), monitor);
        client = Activator.getDefault().getOsgiClientFactory().createOsgiClient(repositoryInfo);
    } catch (CoreException e) {
        setServerState(IServer.STATE_STOPPED);
        throw e;
    } catch (URISyntaxException e) {
        setServerState(IServer.STATE_STOPPED);
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e));
    }
    // 10/50 done
    monitor.worked(10);
    try {
        EmbeddedArtifactLocator artifactLocator = Activator.getDefault().getArtifactLocator();
        // 15/50 done
        installBundle(monitor, client, artifactLocator.loadSourceSupportBundle(), SUPPORT_SOURCE_BUNDLE_SYMBOLIC_NAME);
        // 20/50 done
        installBundle(monitor, client, artifactLocator.loadToolingSupportBundle(), SUPPORT_BUNDLE_SYMBOLIC_NAME);
    } catch (IOException | OsgiClientException e) {
        Activator.getDefault().getPluginLogger().warn("Failed reading the installation support bundle", e);
    }
    try {
        if (getServer().getMode().equals(ILaunchManager.DEBUG_MODE)) {
            debuggerConnection = new JVMDebuggerConnection(client);
            success = debuggerConnection.connectInDebugMode(launch, getServer(), SubMonitor.convert(monitor, 30));
        // 50/50 done
        } else {
            Command<ResourceProxy> command = repository.newListChildrenNodeCommand("/");
            result = command.execute();
            success = result.isSuccess();
            // 50/50 done
            monitor.worked(30);
        }
        if (success) {
            setServerState(IServer.STATE_STARTED);
        } else {
            setServerState(IServer.STATE_STOPPED);
            String message = "Unable to connect to the Server. Please make sure a server instance is running ";
            if (result != null) {
                message += " (" + result.toString() + ")";
            }
            throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, message));
        }
    } catch (CoreException | RuntimeException e) {
        setServerState(IServer.STATE_STOPPED);
        throw e;
    } finally {
        monitor.done();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) RepositoryInfo(org.apache.sling.ide.transport.RepositoryInfo) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) Repository(org.apache.sling.ide.transport.Repository) CoreException(org.eclipse.core.runtime.CoreException) OsgiClient(org.apache.sling.ide.osgi.OsgiClient) EmbeddedArtifactLocator(org.apache.sling.ide.artifacts.EmbeddedArtifactLocator) OsgiClientException(org.apache.sling.ide.osgi.OsgiClientException)

Example 3 with OsgiClient

use of org.apache.sling.ide.osgi.OsgiClient in project sling by apache.

the class ToolingSupportBundle method before.

@Override
protected void before() throws Throwable {
    EmbeddedArtifactLocator locator = Activator.getDefault().getArtifactLocator();
    EmbeddedArtifact toolingBundle = locator.loadToolingSupportBundle();
    OsgiClientFactory clientFactory = Activator.getDefault().getOsgiClientFactory();
    OsgiClient osgiClient = clientFactory.createOsgiClient(new RepositoryInfo(config.getUsername(), config.getPassword(), config.getUrl()));
    osgiClient.installBundle(toolingBundle.openInputStream(), toolingBundle.getName());
}
Also used : OsgiClientFactory(org.apache.sling.ide.osgi.OsgiClientFactory) RepositoryInfo(org.apache.sling.ide.transport.RepositoryInfo) EmbeddedArtifactLocator(org.apache.sling.ide.artifacts.EmbeddedArtifactLocator) OsgiClient(org.apache.sling.ide.osgi.OsgiClient) EmbeddedArtifact(org.apache.sling.ide.artifacts.EmbeddedArtifact)

Aggregations

OsgiClient (org.apache.sling.ide.osgi.OsgiClient)3 URISyntaxException (java.net.URISyntaxException)2 EmbeddedArtifactLocator (org.apache.sling.ide.artifacts.EmbeddedArtifactLocator)2 OsgiClientException (org.apache.sling.ide.osgi.OsgiClientException)2 RepositoryInfo (org.apache.sling.ide.transport.RepositoryInfo)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 EmbeddedArtifact (org.apache.sling.ide.artifacts.EmbeddedArtifact)1 OsgiClientFactory (org.apache.sling.ide.osgi.OsgiClientFactory)1 Repository (org.apache.sling.ide.transport.Repository)1 ResourceProxy (org.apache.sling.ide.transport.ResourceProxy)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 Version (org.osgi.framework.Version)1