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