Search in sources :

Example 1 with Macro

use of org.eclipse.che.ide.api.macro.Macro in project che by eclipse.

the class ServerProtocolMacro method getMacros.

/** {@inheritDoc} */
@Override
public Set<Macro> getMacros(DevMachine devMachine) {
    final Set<Macro> providers = Sets.newHashSet();
    for (Map.Entry<String, ? extends Server> entry : devMachine.getDescriptor().getRuntime().getServers().entrySet()) {
        if (Strings.isNullOrEmpty(entry.getValue().getProtocol())) {
            continue;
        }
        Macro macro = new CustomMacro(KEY.replace("%", entry.getKey()), entry.getValue().getProtocol(), "Returns protocol of a server registered by name");
        providers.add(macro);
        // register port without "/tcp" suffix
        if (entry.getKey().endsWith("/tcp")) {
            final String port = entry.getKey().substring(0, entry.getKey().length() - 4);
            Macro shortMacro = new CustomMacro(KEY.replace("%", port), entry.getValue().getProtocol(), "Returns protocol of a server registered by name");
            providers.add(shortMacro);
        }
    }
    return providers;
}
Also used : Macro(org.eclipse.che.ide.api.macro.Macro) Map(java.util.Map)

Example 2 with Macro

use of org.eclipse.che.ide.api.macro.Macro in project che by eclipse.

the class ServerHostNameMacroTest method getMacros.

@Test
public void getMacros() throws Exception {
    final Set<Macro> providers = provider.getMacros(devMachine);
    assertEquals(providers.size(), 2);
    final Iterator<Macro> iterator = providers.iterator();
    final Macro provider1 = iterator.next();
    assertTrue(provider1 instanceof CustomMacro);
    assertEquals(provider1.getName(), ServerHostNameMacro.KEY.replace("%", WS_AGENT_PORT));
    provider1.expand().then(new Operation<String>() {

        @Override
        public void apply(String address) throws OperationException {
            assertEquals(address, PROTOCOL);
        }
    });
    final Macro provider2 = iterator.next();
    assertTrue(provider2 instanceof CustomMacro);
    assertEquals(provider2.getName(), ServerHostNameMacro.KEY.replace("%", WS_AGENT_PORT.substring(0, WS_AGENT_PORT.length() - 4)));
    provider2.expand().then(new Operation<String>() {

        @Override
        public void apply(String address) throws OperationException {
            assertEquals(address, PROTOCOL);
        }
    });
}
Also used : CustomMacro(org.eclipse.che.ide.macro.CustomMacro) ServerHostNameMacro(org.eclipse.che.ide.macro.ServerHostNameMacro) Macro(org.eclipse.che.ide.api.macro.Macro) CustomMacro(org.eclipse.che.ide.macro.CustomMacro) OperationException(org.eclipse.che.api.promises.client.OperationException) Test(org.junit.Test)

Example 3 with Macro

use of org.eclipse.che.ide.api.macro.Macro in project che by eclipse.

the class AbstractServerMacro method registerProviders.

/**
     * Register macro providers which returns the implementation.
     *
     * @see AbstractServerMacro#getMacros(DevMachine)
     * @since 4.7.0
     */
private void registerProviders() {
    final DevMachine devMachine = appContext.getDevMachine();
    if (devMachine == null) {
        return;
    }
    final Set<Macro> providers = getMacros(devMachine);
    checkNotNull(providers);
    if (providers.isEmpty()) {
        return;
    }
    providerRegistry.register(providers);
}
Also used : DevMachine(org.eclipse.che.ide.api.machine.DevMachine) Macro(org.eclipse.che.ide.api.macro.Macro)

Example 4 with Macro

use of org.eclipse.che.ide.api.macro.Macro in project che by eclipse.

the class MacroProcessorImpl method expandMacros.

private Promise<String> expandMacros(Promise<String> promise, StringContainer stringContainer, Iterator<Macro> iterator) {
    if (!iterator.hasNext()) {
        return promise;
    }
    Macro macro = iterator.next();
    Promise<String> derivedPromise = promise.thenPromise(expandMacro(stringContainer, macro));
    return expandMacros(derivedPromise, stringContainer, iterator);
}
Also used : Macro(org.eclipse.che.ide.api.macro.Macro)

Example 5 with Macro

use of org.eclipse.che.ide.api.macro.Macro in project che by eclipse.

the class ServerHostNameMacro method getMacros.

/** {@inheritDoc} */
@Override
public Set<Macro> getMacros(DevMachine devMachine) {
    final Set<Macro> providers = Sets.newHashSet();
    for (Map.Entry<String, ? extends Server> entry : devMachine.getDescriptor().getRuntime().getServers().entrySet()) {
        if (Strings.isNullOrEmpty(entry.getValue().getRef())) {
            continue;
        }
        Macro macro = new CustomMacro(KEY.replace("%", entry.getKey()), entry.getValue().getRef(), "Returns hostname of a server registered by name");
        providers.add(macro);
        // register port without "/tcp" suffix
        if (entry.getKey().endsWith("/tcp")) {
            final String port = entry.getKey().substring(0, entry.getKey().length() - 4);
            Macro shortMacro = new CustomMacro(KEY.replace("%", port), entry.getValue().getRef(), "Returns hostname of a server registered by name");
            providers.add(shortMacro);
        }
    }
    return providers;
}
Also used : Macro(org.eclipse.che.ide.api.macro.Macro) Map(java.util.Map)

Aggregations

Macro (org.eclipse.che.ide.api.macro.Macro)10 Map (java.util.Map)4 OperationException (org.eclipse.che.api.promises.client.OperationException)4 CustomMacro (org.eclipse.che.ide.macro.CustomMacro)4 Test (org.junit.Test)4 DevMachine (org.eclipse.che.ide.api.machine.DevMachine)1 ServerHostNameMacro (org.eclipse.che.ide.macro.ServerHostNameMacro)1 ServerMacro (org.eclipse.che.ide.macro.ServerMacro)1 ServerPortMacro (org.eclipse.che.ide.macro.ServerPortMacro)1 ServerProtocolMacro (org.eclipse.che.ide.macro.ServerProtocolMacro)1