Skip to content

Commit

Permalink
Merge branch 'groovy-1.7' into groovy-1.8
Browse files Browse the repository at this point in the history
Conflicts:
	settings.gradle
  • Loading branch information
pniederw committed Jan 27, 2012
2 parents 0a6039d + 85a775c commit 9c87b49
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://repo.gradle.org/gradle/distributions/gradle-1.0-milestone-6-bin.zip
distributionUrl=http\://repo.gradle.org/gradle/distributions/gradle-1.0-milestone-7-bin.zip

1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include 'spock-core'
include 'spock-guice'
include "spock-maven"
include 'spock-specs'
include 'spock-spring'
include 'spock-tapestry'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.spockframework.util.InternalIdentifiers;
import org.spockframework.util.Identifiers;
import org.spockframework.runtime.SpockRuntime;
import org.spockframework.util.Jvm;

/**
* A Spec visitor responsible for most of the rewriting of a Spec's AST.
Expand Down Expand Up @@ -354,9 +355,14 @@ private MethodNode copyMethod(MethodNode method, String newName) {
return newMethod;
}

// NOTE: alternatively, we could remove method with:
// spec.getAst().getMethods().remove(method)
private void deactivateMethod(MethodNode method) {
private void deactivateMethod(MethodNode method) {
if (Jvm.getCurrent().isIbmJvm()) {
// see http://issues.spockframework.org/detail?id=225
// solves the problem if spec is compiled with IBM JDK
spec.getAst().getMethods().remove(method);
return;
}

Statement stat = new ExpressionStatement(
new MethodCallExpression(
new ClassExpression(nodeCache.SpockRuntime),
Expand Down
31 changes: 31 additions & 0 deletions spock-core/src/main/java/org/spockframework/util/Jvm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2009 the original author or authors.
*
* Licensed 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 org.spockframework.util;

public class Jvm {
private static final Jvm INSTANCE = new Jvm();

private Jvm() {}

public static Jvm getCurrent() {
return INSTANCE;
}

public boolean isIbmJvm() {
return System.getProperty("java.vendor").toLowerCase().contains("ibm");
}
}
2 changes: 1 addition & 1 deletion spock-example/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://repo.gradle.org/gradle/distributions/gradle-1.0-milestone-6-bin.zip
distributionUrl=http\://repo.gradle.org/gradle/distributions/gradle-1.0-milestone-7-bin.zip
21 changes: 21 additions & 0 deletions spock-maven/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apply from: profile("publishMaven")

sourceSets {
main {
java {
// don't build the Mojo for now
exclude "org/spockframework/buildsupport/maven/FindSpecsMojo.java"
}
}
}

dependencies {
compile project(":spock-core")
compile("org.apache.maven.surefire:surefire-junit47:2.11") {
exclude group: "junit"
}
runtime libs.asm
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/*
* Copyright 2011 the original author or authors.
*
* Licensed 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 org.apache.maven.surefire.junitcore;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.maven.surefire.common.junit4.JUnit4RunListenerFactory;
import org.apache.maven.surefire.common.junit4.JUnit4TestChecker;
import org.apache.maven.surefire.common.junit48.FilterFactory;
import org.apache.maven.surefire.common.junit48.JUnit48Reflector;
import org.apache.maven.surefire.providerapi.AbstractProvider;
import org.apache.maven.surefire.providerapi.ProviderParameters;
import org.apache.maven.surefire.report.ConsoleLogger;
import org.apache.maven.surefire.report.ConsoleOutputCapture;
import org.apache.maven.surefire.report.ConsoleOutputReceiver;
import org.apache.maven.surefire.report.ReporterException;
import org.apache.maven.surefire.report.ReporterFactory;
import org.apache.maven.surefire.report.RunListener;
import org.apache.maven.surefire.suite.RunResult;
import org.apache.maven.surefire.testset.TestSetFailedException;
import org.apache.maven.surefire.util.DirectoryScanner;
import org.apache.maven.surefire.util.RunOrderCalculator;
import org.apache.maven.surefire.util.ScannerFilter;
import org.apache.maven.surefire.util.TestsToRun;
import org.apache.maven.surefire.util.internal.StringUtils;

import org.junit.runner.Description;
import org.junit.runner.manipulation.Filter;

/**
* Adaptation of {@link org.apache.maven.surefire.junitcore.JUnitCoreProvider}
* to Spock. Not meant to run JUnit tests.
*
* @author Kristian Rosenvold
*/
@SuppressWarnings( { "UnusedDeclaration" } )
public class SpockProvider
extends AbstractProvider
{
private final ClassLoader testClassLoader;

private final DirectoryScanner directoryScanner;

private final JUnitCoreParameters jUnitCoreParameters;

private final ScannerFilter scannerFilter;

private final List<org.junit.runner.notification.RunListener> customRunListeners;

private final ProviderParameters providerParameters;



private TestsToRun testsToRun;

private JUnit48Reflector jUnit48Reflector;

private RunOrderCalculator runOrderCalculator;

private String requestedTestMethod;

public SpockProvider( ProviderParameters providerParameters )
{
this.providerParameters = providerParameters;
this.testClassLoader = providerParameters.getTestClassLoader();
this.directoryScanner = providerParameters.getDirectoryScanner();
this.runOrderCalculator = providerParameters.getRunOrderCalculator();
this.jUnitCoreParameters = new JUnitCoreParameters( providerParameters.getProviderProperties() );
this.scannerFilter = new JUnit4TestChecker( testClassLoader );
this.requestedTestMethod = providerParameters.getTestRequest().getRequestedTestMethod();

customRunListeners = JUnit4RunListenerFactory.
createCustomListeners( providerParameters.getProviderProperties().getProperty( "listener" ) );
jUnit48Reflector = new JUnit48Reflector( testClassLoader );
}

public Boolean isRunnable()
{
return Boolean.TRUE;
}

public Iterator getSuites()
{
final Filter filter = jUnit48Reflector.isJUnit48Available() ? createJUnit48Filter() : null;
testsToRun = getSuitesAsList( filter );
return testsToRun.iterator();
}

public RunResult invoke( Object forkTestSet )
throws TestSetFailedException, ReporterException
{
final String message = "Concurrency config is " + jUnitCoreParameters.toString() + "\n";
final ReporterFactory reporterFactory = providerParameters.getReporterFactory();

final ConsoleLogger consoleLogger = providerParameters.getConsoleLogger();
consoleLogger.info( message );

Filter filter = jUnit48Reflector.isJUnit48Available() ? createJUnit48Filter() : null;

if ( testsToRun == null )
{
testsToRun = forkTestSet == null ? getSuitesAsList( filter ) : TestsToRun.fromClass( (Class) forkTestSet );
}

if (testsToRun.size() == 0)
{
filter = null;
}

final Map<String, TestSet> testSetMap = new ConcurrentHashMap<String, TestSet>();

RunListener listener = ConcurrentReporterManager.createInstance( testSetMap, reporterFactory,
jUnitCoreParameters.isParallelClasses(),
jUnitCoreParameters.isParallelBoth(),
consoleLogger );

ConsoleOutputCapture.startCapture( (ConsoleOutputReceiver) listener );

org.junit.runner.notification.RunListener jUnit4RunListener = new JUnitCoreRunListener( listener, testSetMap );
customRunListeners.add( 0, jUnit4RunListener );

JUnitCoreWrapper.execute( testsToRun, jUnitCoreParameters, customRunListeners, filter );
return reporterFactory.close();
}

@SuppressWarnings( "unchecked" )
private TestsToRun getSuitesAsList( Filter filter )
{
List<Class<?>> res = new ArrayList<Class<?>>( 500 );
TestsToRun max = scanClassPath();
if ( filter == null )
{
return max;
}

Iterator<Class<?>> it = max.iterator();
while ( it.hasNext() )
{
Class<?> clazz = it.next();
boolean isCategoryAnnotatedClass = jUnit48Reflector.isCategoryAnnotationPresent( clazz );
Description d = Description.createSuiteDescription( clazz );
if ( filter.shouldRun( d ) )
{
res.add( clazz );
}
else
{
for ( Method method : clazz.getMethods() )
{
final Description testDescription =
Description.createTestDescription( clazz, method.getName(), method.getAnnotations() );
if ( filter.shouldRun( testDescription ) )
{
res.add( clazz );
break;
}
}
}
}
return new TestsToRun( res );
}

private Filter createJUnit48Filter()
{
final FilterFactory filterFactory = new FilterFactory( testClassLoader );
return isMethodFilterSpecified() ?
filterFactory.createMethodFilter( requestedTestMethod ) :
filterFactory.createGroupFilter( providerParameters.getProviderProperties() );
}

private TestsToRun scanClassPath()
{
final TestsToRun scanned = directoryScanner.locateTestClasses( testClassLoader, scannerFilter );
return runOrderCalculator.orderTestClasses( scanned );
}

private boolean isMethodFilterSpecified()
{
return !StringUtils.isBlank( requestedTestMethod );
}
}

0 comments on commit 9c87b49

Please sign in to comment.