Use groovy compiler where really necessary. Override the compiler per-project, only where there are groovy files to compile. Convert one of the groovy files to java.
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/4c1d54b9 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/4c1d54b9 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/4c1d54b9 Branch: refs/heads/master Commit: 4c1d54b9eac17cdad475c2b10dd0c668e854d180 Parents: c34812c Author: Svetoslav Neykov <[email protected]> Authored: Sun Jan 25 11:03:20 2015 +0200 Committer: Svetoslav Neykov <[email protected]> Committed: Sun Jan 25 11:03:20 2015 +0200 ---------------------------------------------------------------------- core/pom.xml | 16 ++ locations/jclouds/pom.xml | 16 ++ policy/pom.xml | 16 ++ pom.xml | 8 - sandbox/database/pom.xml | 16 ++ sandbox/nosql/pom.xml | 16 ++ .../lifecycle/StartStopSshDriverTest.groovy | 135 --------------- .../basic/lifecycle/StartStopSshDriverTest.java | 166 +++++++++++++++++++ software/database/pom.xml | 14 ++ software/webapp/pom.xml | 14 ++ usage/cli/pom.xml | 12 ++ 11 files changed, 286 insertions(+), 143 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4c1d54b9/core/pom.xml ---------------------------------------------------------------------- diff --git a/core/pom.xml b/core/pom.xml index 5145381..3a9925b 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -228,4 +228,20 @@ </dependency> </dependencies> + <build> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <inherited>true</inherited> + <executions> + <execution> + <id>default-testCompile</id> + <configuration> + <compilerId>groovy-eclipse-compiler</compilerId> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4c1d54b9/locations/jclouds/pom.xml ---------------------------------------------------------------------- diff --git a/locations/jclouds/pom.xml b/locations/jclouds/pom.xml index f86147b..b3f5625 100644 --- a/locations/jclouds/pom.xml +++ b/locations/jclouds/pom.xml @@ -200,4 +200,20 @@ </dependency> </dependencies> + <build> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <inherited>true</inherited> + <executions> + <execution> + <id>default-testCompile</id> + <configuration> + <compilerId>groovy-eclipse-compiler</compilerId> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4c1d54b9/policy/pom.xml ---------------------------------------------------------------------- diff --git a/policy/pom.xml b/policy/pom.xml index c90c370..5e6cf85 100644 --- a/policy/pom.xml +++ b/policy/pom.xml @@ -97,4 +97,20 @@ </dependency> </dependencies> + <build> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <inherited>true</inherited> + <executions> + <execution> + <id>default-testCompile</id> + <configuration> + <compilerId>groovy-eclipse-compiler</compilerId> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4c1d54b9/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 793d70f..3e64ccf 100644 --- a/pom.xml +++ b/pom.xml @@ -1114,14 +1114,6 @@ <fork>true</fork> <verbose>false</verbose> </configuration> - <executions> - <execution> - <id>default-testCompile</id> - <configuration> - <compilerId>groovy-eclipse-compiler</compilerId> - </configuration> - </execution> - </executions> <dependencies> <dependency> <groupId>org.codehaus.groovy</groupId> http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4c1d54b9/sandbox/database/pom.xml ---------------------------------------------------------------------- diff --git a/sandbox/database/pom.xml b/sandbox/database/pom.xml index 9c82d2d..d7f6054 100644 --- a/sandbox/database/pom.xml +++ b/sandbox/database/pom.xml @@ -64,4 +64,20 @@ </dependency> </dependencies> + <build> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <inherited>true</inherited> + <executions> + <execution> + <id>default-testCompile</id> + <configuration> + <compilerId>groovy-eclipse-compiler</compilerId> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4c1d54b9/sandbox/nosql/pom.xml ---------------------------------------------------------------------- diff --git a/sandbox/nosql/pom.xml b/sandbox/nosql/pom.xml index 679406f..646e295 100644 --- a/sandbox/nosql/pom.xml +++ b/sandbox/nosql/pom.xml @@ -77,4 +77,20 @@ </dependency> </dependencies> + <build> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <inherited>true</inherited> + <executions> + <execution> + <id>default-testCompile</id> + <configuration> + <compilerId>groovy-eclipse-compiler</compilerId> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> </project> http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4c1d54b9/software/base/src/test/java/brooklyn/entity/basic/lifecycle/StartStopSshDriverTest.groovy ---------------------------------------------------------------------- diff --git a/software/base/src/test/java/brooklyn/entity/basic/lifecycle/StartStopSshDriverTest.groovy b/software/base/src/test/java/brooklyn/entity/basic/lifecycle/StartStopSshDriverTest.groovy deleted file mode 100644 index 5190733..0000000 --- a/software/base/src/test/java/brooklyn/entity/basic/lifecycle/StartStopSshDriverTest.groovy +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package brooklyn.entity.basic.lifecycle - -import static brooklyn.test.TestUtils.* -import static org.testng.Assert.* -import groovy.transform.InheritConstructors - -import java.lang.management.ManagementFactory -import java.lang.management.ThreadInfo -import java.lang.management.ThreadMXBean - -import org.testng.annotations.BeforeMethod -import org.testng.annotations.Test - -import brooklyn.entity.basic.AbstractSoftwareProcessSshDriver -import brooklyn.entity.basic.BrooklynConfigKeys -import brooklyn.entity.basic.Entities -import brooklyn.location.basic.SshMachineLocation -import brooklyn.test.entity.TestApplication -import brooklyn.test.entity.TestApplicationImpl -import brooklyn.test.entity.TestEntity -import brooklyn.test.entity.TestEntityImpl -import brooklyn.util.internal.ssh.SshTool -import brooklyn.util.internal.ssh.cli.SshCliTool -import brooklyn.util.internal.ssh.sshj.SshjTool -import brooklyn.util.stream.StreamGobbler - -class StartStopSshDriverTest { - - TestApplication app - TestEntity entity - SshMachineLocationWithSshTool sshMachineLocation - AbstractSoftwareProcessSshDriver driver - - protected static class SshMachineLocationWithSshTool extends SshMachineLocation { - SshTool lastTool; - public SshMachineLocationWithSshTool(Map flags) { super(flags); } - public SshTool connectSsh(Map args) { - SshTool result = super.connectSsh(args); - lastTool = result; - return result; - } - } - - @BeforeMethod(alwaysRun = true) - public void setUp() { - app = new TestApplicationImpl() - entity = new TestEntityImpl(app) - Entities.startManagement(app); - sshMachineLocation = new SshMachineLocationWithSshTool(address:"localhost"); - driver = new BasicStartStopSshDriver(entity, sshMachineLocation) - } - - @Test(groups = [ "Integration" ]) - public void testExecuteDoesNotLeaveRunningStreamGobblerThread() { - ThreadInfo[] existingThreads = getThreadsCalling(StreamGobbler.class) - List<Long> existingThreadIds = existingThreads.collect { it.threadId } - - List<String> script = ["echo hello"] - driver.execute(script, "mytest") - - executeUntilSucceeds(timeout:10*1000) { - ThreadInfo[] currentThreads = getThreadsCalling(StreamGobbler.class) - List<Long> currentThreadIds = currentThreads.collect { it.threadId } - - currentThreadIds.removeAll(existingThreadIds) - assertEquals(currentThreadIds, []) - } - } - - @Test(groups = [ "Integration" ]) - public void testSshScriptHeaderUsedWhenSpecified() { - entity.setConfig(BrooklynConfigKeys.SSH_CONFIG_SCRIPT_HEADER, "#!/bin/bash -e\necho hello world"); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - driver.execute(out: out, Arrays.asList("echo goodbye"), "test"); - String s = out.toString(); - assertTrue(s.contains("goodbye"), "should have said goodbye: "+s); - assertTrue(s.contains("hello world"), "should have said hello: "+s); - assertTrue(sshMachineLocation.lastTool instanceof SshjTool, "expect sshj tool, got "+ - (sshMachineLocation.lastTool!=null ? ""+sshMachineLocation.lastTool.getClass()+":" : "") + sshMachineLocation.lastTool); - } - - @Test(groups = [ "Integration" ]) - public void testSshCliPickedUpWhenSpecified() { - entity.setConfig(BrooklynConfigKeys.SSH_TOOL_CLASS, SshCliTool.class.getName()); - driver.execute(Arrays.asList("echo hi"), "test"); - assertTrue(sshMachineLocation.lastTool instanceof SshCliTool, "expect CLI tool, got "+ - (sshMachineLocation.lastTool!=null ? ""+sshMachineLocation.lastTool.getClass()+":" : "") + sshMachineLocation.lastTool); - } - - private List<ThreadInfo> getThreadsCalling(Class<?> clazz) { - String clazzName = clazz.getCanonicalName() - List<ThreadInfo> result = [] - ThreadMXBean threadMxbean = ManagementFactory.getThreadMXBean() - ThreadInfo[] threads = threadMxbean.dumpAllThreads(false, false) - - for (ThreadInfo thread : threads) { - StackTraceElement[] stackTrace = thread.getStackTrace() - for (StackTraceElement stackTraceElement : stackTrace) { - if (clazzName == stackTraceElement.getClassName()) { - result << thread - break - } - } - } - return result - } -} - -@InheritConstructors -public class BasicStartStopSshDriver extends AbstractSoftwareProcessSshDriver { - public boolean isRunning() { true } - public void stop() {} - public void kill() {} - public void install() {} - public void customize() {} - public void launch() {} -} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4c1d54b9/software/base/src/test/java/brooklyn/entity/basic/lifecycle/StartStopSshDriverTest.java ---------------------------------------------------------------------- diff --git a/software/base/src/test/java/brooklyn/entity/basic/lifecycle/StartStopSshDriverTest.java b/software/base/src/test/java/brooklyn/entity/basic/lifecycle/StartStopSshDriverTest.java new file mode 100644 index 0000000..2c64d38 --- /dev/null +++ b/software/base/src/test/java/brooklyn/entity/basic/lifecycle/StartStopSshDriverTest.java @@ -0,0 +1,166 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package brooklyn.entity.basic.lifecycle; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.lang.management.ManagementFactory; +import java.lang.management.ThreadInfo; +import java.lang.management.ThreadMXBean; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import brooklyn.entity.basic.AbstractSoftwareProcessSshDriver; +import brooklyn.entity.basic.BrooklynConfigKeys; +import brooklyn.entity.basic.Entities; +import brooklyn.entity.basic.EntityLocal; +import brooklyn.location.basic.SshMachineLocation; +import brooklyn.test.Asserts; +import brooklyn.test.entity.TestApplication; +import brooklyn.test.entity.TestApplicationImpl; +import brooklyn.test.entity.TestEntity; +import brooklyn.test.entity.TestEntityImpl; +import brooklyn.util.collections.MutableList; +import brooklyn.util.internal.ssh.SshTool; +import brooklyn.util.internal.ssh.cli.SshCliTool; +import brooklyn.util.internal.ssh.sshj.SshjTool; +import brooklyn.util.stream.StreamGobbler; + +import com.google.common.base.Function; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +class StartStopSshDriverTest { + + public class BasicStartStopSshDriver extends AbstractSoftwareProcessSshDriver { + public BasicStartStopSshDriver(EntityLocal entity, SshMachineLocation machine) { + super(entity, machine); + } + public boolean isRunning() { return true; } + public void stop() {} + public void kill() {} + public void install() {} + public void customize() {} + public void launch() {} + } + + private static class ThreadIdTransformer implements Function<ThreadInfo, Long> { + @Override + public Long apply(ThreadInfo t) { + return t.getThreadId(); + } + } + + private TestApplication app; + private TestEntity entity; + private SshMachineLocationWithSshTool sshMachineLocation; + private AbstractSoftwareProcessSshDriver driver; + + @SuppressWarnings("rawtypes") + protected static class SshMachineLocationWithSshTool extends SshMachineLocation { + private static final long serialVersionUID = 1L; + + SshTool lastTool; + public SshMachineLocationWithSshTool(Map flags) { super(flags); } + public SshTool connectSsh(Map args) { + SshTool result = super.connectSsh(args); + lastTool = result; + return result; + } + } + + @BeforeMethod(alwaysRun = true) + public void setUp() { + app = new TestApplicationImpl(); + entity = new TestEntityImpl(app); + Entities.startManagement(app); + sshMachineLocation = new SshMachineLocationWithSshTool(ImmutableMap.of("address", "localhost")); + driver = new BasicStartStopSshDriver(entity, sshMachineLocation); + } + + @Test(groups="Integration") + public void testExecuteDoesNotLeaveRunningStreamGobblerThread() { + List<ThreadInfo> existingThreads = getThreadsCalling(StreamGobbler.class); + final List<Long> existingThreadIds = getThreadId(existingThreads); + + List<String> script = Arrays.asList("echo hello"); + driver.execute(script, "mytest"); + + Asserts.succeedsEventually(ImmutableMap.of("timeout", 10*1000), new Runnable() { + @Override + public void run() { + List<ThreadInfo> currentThreads = getThreadsCalling(StreamGobbler.class); + List<Long> currentThreadIds = getThreadId(currentThreads); + + currentThreadIds.removeAll(existingThreadIds); + assertEquals(currentThreadIds, ImmutableList.<Long>of()); + } + }); + } + + @Test(groups="Integration") + public void testSshScriptHeaderUsedWhenSpecified() { + entity.setConfig(BrooklynConfigKeys.SSH_CONFIG_SCRIPT_HEADER, "#!/bin/bash -e\necho hello world"); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + driver.execute(ImmutableMap.of("out", out), Arrays.asList("echo goodbye"), "test"); + String s = out.toString(); + assertTrue(s.contains("goodbye"), "should have said goodbye: "+s); + assertTrue(s.contains("hello world"), "should have said hello: "+s); + assertTrue(sshMachineLocation.lastTool instanceof SshjTool, "expect sshj tool, got "+ + (sshMachineLocation.lastTool!=null ? ""+sshMachineLocation.lastTool.getClass()+":" : "") + sshMachineLocation.lastTool); + } + + @Test(groups="Integration") + public void testSshCliPickedUpWhenSpecified() { + entity.setConfig(BrooklynConfigKeys.SSH_TOOL_CLASS, SshCliTool.class.getName()); + driver.execute(Arrays.asList("echo hi"), "test"); + assertTrue(sshMachineLocation.lastTool instanceof SshCliTool, "expect CLI tool, got "+ + (sshMachineLocation.lastTool!=null ? ""+sshMachineLocation.lastTool.getClass()+":" : "") + sshMachineLocation.lastTool); + } + + private List<ThreadInfo> getThreadsCalling(Class<?> clazz) { + String clazzName = clazz.getCanonicalName(); + List<ThreadInfo> result = MutableList.of(); + ThreadMXBean threadMxbean = ManagementFactory.getThreadMXBean(); + ThreadInfo[] threads = threadMxbean.dumpAllThreads(false, false); + + for (ThreadInfo thread : threads) { + StackTraceElement[] stackTrace = thread.getStackTrace(); + for (StackTraceElement stackTraceElement : stackTrace) { + if (clazzName == stackTraceElement.getClassName()) { + result.add(thread); + break; + } + } + } + return result; + } + + private ImmutableList<Long> getThreadId(List<ThreadInfo> existingThreads) { + return FluentIterable.from(existingThreads).transform(new ThreadIdTransformer()).toList(); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4c1d54b9/software/database/pom.xml ---------------------------------------------------------------------- diff --git a/software/database/pom.xml b/software/database/pom.xml index 89090a1..b835507 100644 --- a/software/database/pom.xml +++ b/software/database/pom.xml @@ -55,6 +55,20 @@ </plugin> </plugins> </pluginManagement> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <inherited>true</inherited> + <executions> + <execution> + <id>default-testCompile</id> + <configuration> + <compilerId>groovy-eclipse-compiler</compilerId> + </configuration> + </execution> + </executions> + </plugin> + </plugins> </build> <dependencies> http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4c1d54b9/software/webapp/pom.xml ---------------------------------------------------------------------- diff --git a/software/webapp/pom.xml b/software/webapp/pom.xml index aeef6ad..0859814 100644 --- a/software/webapp/pom.xml +++ b/software/webapp/pom.xml @@ -53,6 +53,20 @@ </plugin> </plugins> </pluginManagement> + <plugins> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <inherited>true</inherited> + <executions> + <execution> + <id>default-testCompile</id> + <configuration> + <compilerId>groovy-eclipse-compiler</compilerId> + </configuration> + </execution> + </executions> + </plugin> + </plugins> </build> <dependencies> http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4c1d54b9/usage/cli/pom.xml ---------------------------------------------------------------------- diff --git a/usage/cli/pom.xml b/usage/cli/pom.xml index a3a5262..a748a1d 100644 --- a/usage/cli/pom.xml +++ b/usage/cli/pom.xml @@ -121,6 +121,18 @@ </instructions> </configuration> </plugin> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <inherited>true</inherited> + <executions> + <execution> + <id>default-testCompile</id> + <configuration> + <compilerId>groovy-eclipse-compiler</compilerId> + </configuration> + </execution> + </executions> + </plugin> </plugins> <pluginManagement> <plugins>
