diff --git a/build.gradle b/build.gradle index 28dfbe73bb..db8a3eebce 100644 --- a/build.gradle +++ b/build.gradle @@ -261,6 +261,12 @@ subprojects { subproject -> archives javadocJar } + jar { + manifest { + attributes('Implementation-Version': version) + } + } + build.dependsOn jacocoTestReport } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/graph/Graph.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/graph/Graph.java index 89da5c132d..1045ecc389 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/graph/Graph.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/management/graph/Graph.java @@ -17,6 +17,7 @@ package org.springframework.integration.support.management.graph; import java.util.Collection; +import java.util.Map; /** * This object can be exposed, for example, as a JSON object over @@ -29,15 +30,22 @@ import java.util.Collection; */ public class Graph { + private final Map contentDescriptor; + private final Collection nodes; private final Collection links; - public Graph(Collection nodes, Collection links) { + public Graph(Map descriptor, Collection nodes, Collection links) { + this.contentDescriptor = descriptor; this.nodes = nodes; this.links = links; } + public Map getContentDescriptor() { + return this.contentDescriptor; + } + public Collection getNodes() { return this.nodes; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/graph/IntegrationGraphServer.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/graph/IntegrationGraphServer.java index 8122b07e82..b224dffa23 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/graph/IntegrationGraphServer.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/management/graph/IntegrationGraphServer.java @@ -43,17 +43,31 @@ import org.springframework.messaging.MessageChannel; */ public class IntegrationGraphServer implements ApplicationContextAware, ApplicationListener { + private static final float GRAPH_VERSION = 1.0f; + private final NodeFactory nodeFactory = new NodeFactory(); private ApplicationContext applicationContext; private Graph graph; + private String applicationName; + @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } + /** + * Set the application name that will appear in the 'contentDescriptor' under + * the 'name' key. If not provided, the property 'spring.application.name' from + * the application context environment will be used (if present). + * @param applicationName the application name. + */ + public void setApplicationName(String applicationName) { + this.applicationName = applicationName; + } + /** * Return the cached graph. Although the graph is cached, the data therein (stats * etc.) are dynamic. @@ -79,6 +93,21 @@ public class IntegrationGraphServer implements ApplicationContextAware, Applicat } private synchronized Graph buildGraph() { + String implementationVersion = IntegrationGraphServer.class.getPackage().getImplementationVersion(); + if (implementationVersion == null) { + implementationVersion = "unknown - is Spring Integration running from the distribution jar?"; + } + Map descriptor = new HashMap(); + descriptor.put("provider", "spring-integration"); + descriptor.put("providerVersion", implementationVersion); + descriptor.put("providerFormatVersion", GRAPH_VERSION); + String name = this.applicationName; + if (name == null) { + name = this.applicationContext.getEnvironment().getProperty("spring.application.name"); + } + if (name != null) { + descriptor.put("name", name); + } this.nodeFactory.reset(); Collection nodes = new ArrayList(); Collection links = new ArrayList(); @@ -87,7 +116,7 @@ public class IntegrationGraphServer implements ApplicationContextAware, Applicat gateways(nodes, links, channelNodes); producers(nodes, links, channelNodes); consumers(nodes, links, channelNodes); - this.graph = new Graph(nodes, links); + this.graph = new Graph(descriptor, nodes, links); return this.graph; } diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/management/graph/IntegrationNode.java b/spring-integration-core/src/main/java/org/springframework/integration/support/management/graph/IntegrationNode.java index fe18bcea46..fead2b5d70 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/management/graph/IntegrationNode.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/management/graph/IntegrationNode.java @@ -35,15 +35,11 @@ public abstract class IntegrationNode { private final String componentType; - private final String componentName; - protected IntegrationNode(int nodeId, String name, Object nodeObject, Stats stats) { this.nodeId = nodeId; this.name = name; this.componentType = nodeObject instanceof NamedComponent ? ((NamedComponent) nodeObject).getComponentType() : nodeObject.getClass().getSimpleName(); - this.componentName = nodeObject instanceof NamedComponent ? ((NamedComponent) nodeObject).getComponentName() - : nodeObject.toString(); this.stats = stats; } @@ -59,10 +55,6 @@ public abstract class IntegrationNode { return this.componentType; } - public String getComponentName() { - return this.componentName; - } - public Stats getStats() { return this.stats.isAvailable() ? this.stats : null; } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/support/management/graph/IntegrationGraphServerTests.java b/spring-integration-core/src/test/java/org/springframework/integration/support/management/graph/IntegrationGraphServerTests.java index 0ac4d6b669..58bd486083 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/support/management/graph/IntegrationGraphServerTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/support/management/graph/IntegrationGraphServerTests.java @@ -70,7 +70,7 @@ public class IntegrationGraphServerTests { objectMapper.writeValue(baos, graph); // System . out . println(new String(baos.toByteArray())); Map map = objectMapper.readValue(baos.toByteArray(), Map.class); - assertThat(map.size(), is(equalTo(2))); + assertThat(map.size(), is(equalTo(3))); @SuppressWarnings("unchecked") List> nodes = (List>) map.get("nodes"); assertThat(nodes, is(notNullValue())); @@ -87,8 +87,10 @@ public class IntegrationGraphServerTests { public static class Config { @Bean - public IntegrationGraphServer builder() { - return new IntegrationGraphServer(); + public IntegrationGraphServer server() { + IntegrationGraphServer server = new IntegrationGraphServer(); + server.setApplicationName("myAppName:1.0"); + return server; } @Bean diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/management/IntegrationGraphControllerTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/management/IntegrationGraphControllerTests.java index 22d3350be3..55ef914316 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/management/IntegrationGraphControllerTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/management/IntegrationGraphControllerTests.java @@ -44,6 +44,7 @@ import org.springframework.integration.http.config.EnableIntegrationGraphControl import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; @@ -63,6 +64,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration @WebAppConfiguration +@TestPropertySource(properties = "spring.application.name:testApplication") public class IntegrationGraphControllerTests { @Autowired @@ -86,6 +88,8 @@ public class IntegrationGraphControllerTests { .andExpect(jsonPath("$.nodes..name") .value(Matchers.containsInAnyOrder("nullChannel", "errorChannel", "_org.springframework.integration.errorLogger"))) +// .andDo(print()) + .andExpect(jsonPath("$.contentDescriptor.name").value("testApplication")) .andExpect(jsonPath("$.links").exists()); }