├── .gitignore ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .travis.yml ├── .travis └── settings.xml ├── CHANGES.md ├── LICENSE.txt ├── README.md ├── build ├── build.config ├── gmaven-adapter-api ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── codehaus │ │ └── gmaven │ │ └── adapter │ │ ├── ClassSource.java │ │ ├── ClosureTarget.java │ │ ├── ConsoleWindow.java │ │ ├── GroovyRuntime.java │ │ ├── MagicContext.java │ │ ├── ResourceLoader.java │ │ ├── ScriptExecutor.java │ │ ├── ShellRunner.java │ │ └── package-info.java │ └── site │ ├── markdown │ └── index.md │ └── site.xml ├── gmaven-adapter-impl ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── codehaus │ │ │ └── gmaven │ │ │ └── adapter │ │ │ └── impl │ │ │ ├── ConsoleWindowImpl.java │ │ │ ├── GroovyRuntimeImpl.java │ │ │ ├── ScriptExecutorImpl.java │ │ │ ├── ShellRunnerImpl.java │ │ │ └── package-info.java │ └── resources │ │ └── META-INF │ │ └── services │ │ └── org.codehaus.gmaven.adapter.GroovyRuntime │ └── site │ ├── markdown │ └── index.md.vm │ └── site.xml ├── gmaven-testsuite ├── pom.xml └── src │ ├── site │ ├── markdown │ │ └── index.md │ └── site.xml │ └── test │ ├── it-projects │ ├── execute-script │ │ ├── defaultContext.groovy │ │ ├── groovyVersion.groovy │ │ ├── pom.xml │ │ └── simple.groovy │ ├── property-resolution │ │ ├── pom.xml │ │ └── printResult.groovy │ ├── scriptpath │ │ ├── hello.groovy │ │ ├── pom.xml │ │ └── scripts │ │ │ ├── HelloWorld.groovy │ │ │ └── goodbye.groovy │ └── settings.xml │ └── java │ └── org │ └── codehaus │ └── gmaven │ └── testsuite │ ├── ITSupport.java │ ├── MavenVerifier.java │ ├── suite │ ├── Maven305_Groovy206_SuiteIT.java │ ├── Maven305_Groovy215_SuiteIT.java │ ├── Maven31x_Groovy206_SuiteIT.java │ ├── Maven31x_Groovy215_SuiteIT.java │ └── SuiteSupport.java │ └── tests │ ├── ExecuteBasics.java │ ├── PropertyResolution.java │ └── Scriptpath.java ├── groovy-maven-plugin ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── codehaus │ │ │ └── gmaven │ │ │ └── plugin │ │ │ ├── BasicResourceLoader.java │ │ │ ├── ClassSourceFactory.java │ │ │ ├── ClasspathScope.java │ │ │ ├── ConsoleMojo.java │ │ │ ├── ExecuteMojo.java │ │ │ ├── FailClosureTarget.java │ │ │ ├── GroovyRuntimeFactory.java │ │ │ ├── MojoResourceLoader.java │ │ │ ├── MojoSupport.java │ │ │ ├── RuntimeMojoSupport.java │ │ │ ├── ShellMojo.java │ │ │ ├── package-info.java │ │ │ └── util │ │ │ ├── ContainerHelper.java │ │ │ ├── GroovyVersionHelper.java │ │ │ ├── Maps2.java │ │ │ ├── MavenVersionHelper.java │ │ │ ├── PropertiesBuilder.java │ │ │ ├── VersionHelper.java │ │ │ └── package-info.java │ └── resources │ │ └── META-INF │ │ └── org.sonatype.gossip │ │ └── config.properties │ ├── site │ ├── markdown │ │ ├── classpath.md │ │ ├── console.md │ │ ├── execute.md │ │ ├── index.md │ │ ├── logging.md │ │ ├── scriptpath.md │ │ ├── shell.md │ │ └── variables.md.vm │ └── site.xml │ └── test │ └── java │ └── org │ └── codehaus │ └── gmaven │ └── plugin │ ├── ClassSourceFactoryTest.java │ ├── ClasspathScopeTest.java │ ├── FailClosureTargetTest.java │ ├── GroovyRuntimeFactoryTest.java │ ├── MojoSupportTest.java │ └── util │ ├── Maps2Test.java │ ├── PropertiesBuilderTest.java │ └── VersionHelperTest.java ├── header.txt ├── mvnw ├── mvnw.cmd ├── pom.xml └── src └── site ├── markdown └── index.md ├── publish.groovy ├── resources └── images │ ├── gmaven.png │ └── groovy.png └── site.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # Maven 2 | target/ 3 | pom.xml.tag 4 | pom.xml.releaseBackup 5 | pom.xml.versionsBackup 6 | pom.xml.next 7 | release.properties 8 | dependency-reduced-pom.xml 9 | 10 | # Eclipse 11 | .project 12 | .classpath 13 | .settings/ 14 | 15 | # IDEA 16 | .idea 17 | *.ipr 18 | *.iml 19 | *.iws 20 | 21 | # NetBeans 22 | nb-configuration.xml 23 | 24 | # OSX 25 | .DS_Store 26 | 27 | # VS Code 28 | .vscode/ 29 | -------------------------------------------------------------------------------- /.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, either express or implied. See the License for the 16 | specific language governing permissions and limitations 17 | under the License. 18 | */ 19 | 20 | import java.net.*; 21 | import java.io.*; 22 | import java.nio.channels.*; 23 | import java.util.Properties; 24 | 25 | public class MavenWrapperDownloader { 26 | 27 | /** 28 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 29 | */ 30 | private static final String DEFAULT_DOWNLOAD_URL = 31 | "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; 32 | 33 | /** 34 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 35 | * use instead of the default one. 36 | */ 37 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 38 | ".mvn/wrapper/maven-wrapper.properties"; 39 | 40 | /** 41 | * Path where the maven-wrapper.jar will be saved to. 42 | */ 43 | private static final String MAVEN_WRAPPER_JAR_PATH = 44 | ".mvn/wrapper/maven-wrapper.jar"; 45 | 46 | /** 47 | * Name of the property which should be used to override the default download url for the wrapper. 48 | */ 49 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 50 | 51 | public static void main(String args[]) { 52 | System.out.println("- Downloader started"); 53 | File baseDirectory = new File(args[0]); 54 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 55 | 56 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 57 | // wrapperUrl parameter. 58 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 59 | String url = DEFAULT_DOWNLOAD_URL; 60 | if(mavenWrapperPropertyFile.exists()) { 61 | FileInputStream mavenWrapperPropertyFileInputStream = null; 62 | try { 63 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 64 | Properties mavenWrapperProperties = new Properties(); 65 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 66 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 67 | } catch (IOException e) { 68 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 69 | } finally { 70 | try { 71 | if(mavenWrapperPropertyFileInputStream != null) { 72 | mavenWrapperPropertyFileInputStream.close(); 73 | } 74 | } catch (IOException e) { 75 | // Ignore ... 76 | } 77 | } 78 | } 79 | System.out.println("- Downloading from: : " + url); 80 | 81 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 82 | if(!outputFile.getParentFile().exists()) { 83 | if(!outputFile.getParentFile().mkdirs()) { 84 | System.out.println( 85 | "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 86 | } 87 | } 88 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 89 | try { 90 | downloadFileFromURL(url, outputFile); 91 | System.out.println("Done"); 92 | System.exit(0); 93 | } catch (Throwable e) { 94 | System.out.println("- Error downloading"); 95 | e.printStackTrace(); 96 | System.exit(1); 97 | } 98 | } 99 | 100 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 101 | URL website = new URL(urlString); 102 | ReadableByteChannel rbc; 103 | rbc = Channels.newChannel(website.openStream()); 104 | FileOutputStream fos = new FileOutputStream(destination); 105 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 106 | fos.close(); 107 | rbc.close(); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/groovy/gmaven/b5fa664ecea354548d039d39e04011a44e6f5f4c/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | sudo: false 4 | 5 | env: 6 | global: 7 | - secure: "GDFKIFESOdPDItXYqhk8Ci97oE9phVo79Nn3eFHdU1+ncLeAcNcZZ05T+iLBQXumuZ8Z4BJgNW5vqBcTXpr+IlavKbcI1zfpOdqaLMBZSoJpB+DcrT9pypp/FL1hiVdnoyk3CGHwVMj5KDgIGDG+Bf58Jh8K/d+Zof7zrFilut8=" 8 | - secure: "IkXdzwD5xUB57fzf2wE/q9UlGjAZhiVohoDuID0fbzM+VEdG0LyaUe1fpLnOQH6ZHwm8d2BDv3mK2nuMASpQu+K9xKiqPTFCh1UUo/8Zi0lTiXDWRAOzZ/QCu9rPw9xmQAZYWAZjj8+H9oYcAV7CIhe7JvYGKKQOv/dFytxVnnA=" 9 | - MAVEN_SETTINGS='.travis/settings.xml' 10 | - MAVEN_OPTIONS="-V -B -s $MAVEN_SETTINGS" 11 | 12 | branches: 13 | only: 14 | - gmaven-2.x 15 | 16 | jdk: 17 | - openjdk8 18 | 19 | install: ./build ci_prepare $MAVEN_OPTIONS 20 | 21 | script: ./build ci_build $MAVEN_OPTIONS 22 | -------------------------------------------------------------------------------- /.travis/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ossrh 6 | ${env.SONATYPE_USERNAME} 7 | ${env.SONATYPE_PASSWORD} 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | 18 | # ![GMaven](https://groovy.github.io/gmaven/images/gmaven.png) 19 | 20 | ## GMaven 2.1.1 21 | 22 | * Remove use of Guava Maps and Lists helpers 23 | * Resolve issue with property entry with null value 24 | 25 | ## GMaven 2.1 26 | 27 | * Adjustments for use with Maven multi-threading 28 | * Build configuration improvements 29 | 30 | ## GMaven 2.0 31 | 32 | * Initial release of 2.0 rewrite 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 18 | # GMaven 19 | 20 | ![license](https://img.shields.io/github/license/groovy/gmaven.svg) 21 | 22 | ![maven-central](https://img.shields.io/maven-central/v/org.codehaus.gmaven/gmaven/2.svg) 23 | 24 | [![DepShield Badge](https://depshield.sonatype.org/badges/groovy/gmaven/depshield.svg)](https://depshield.github.io) 25 | 26 | ![gmaven-logo](http://groovy.github.io/gmaven/images/gmaven.png) 27 | 28 | Groovy integration for Maven 29 | 30 | ## Building 31 | 32 | ### Requirements 33 | 34 | * Apache Maven 3.5+ 35 | * Java 8+ 36 | -------------------------------------------------------------------------------- /build: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | basename=`basename $0` 3 | dirname=`dirname $0` 4 | dirname=`cd "$dirname" && pwd` 5 | cd "$dirname" 6 | 7 | source build.config 8 | 9 | # load optional config 10 | if [ -f ./build.rc ]; then 11 | source ./build.rc 12 | fi 13 | 14 | # show message and exit 15 | function die { 16 | echo "$1" 17 | exit 1 18 | } 19 | 20 | # show usage and exit 21 | function usage { 22 | if [[ -z "$1" ]]; then 23 | echo "usage: $basename [options]" 24 | else 25 | echo "usage: $basename $1" 26 | fi 27 | exit 2 28 | } 29 | 30 | # run self 31 | function self { 32 | $0 "$@" 33 | } 34 | 35 | if [[ -z "$mvn_options" ]]; then 36 | mvn_options="" 37 | fi 38 | 39 | # run maven 40 | function mvn { 41 | ./mvnw ${mvn_options} "$@" 42 | } 43 | 44 | command="$1"; shift 45 | 46 | # complain if no command is given 47 | if [ -z "$command" ]; then 48 | usage 49 | fi 50 | 51 | case "$command" in 52 | # change the version of the project 53 | change-version) 54 | newVersion="$1" 55 | if [ -z "$newVersion" ]; then 56 | usage "$command " 57 | fi 58 | 59 | mvn org.eclipse.tycho:tycho-versions-plugin:1.2.0:set-version \ 60 | -Dartifacts=${project} \ 61 | -Dproperties=${project}.version \ 62 | -DnewVersion="$newVersion" 63 | ;; 64 | 65 | # check license headers 66 | license-check) 67 | mvn -f ./pom.xml -N -P -include-private com.mycila:license-maven-plugin:check 68 | if [ -f "private/pom.xml" ]; then 69 | mvn -f private/pom.xml -N com.mycila:license-maven-plugin:check "$@" 70 | fi 71 | ;; 72 | 73 | # format license headers 74 | license-format) 75 | mvn -f ./pom.xml -N -P -include-private com.mycila:license-maven-plugin:format 76 | if [ -f "private/pom.xml" ]; then 77 | mvn -f private/pom.xml -N com.mycila:license-maven-plugin:format "$@" 78 | fi 79 | ;; 80 | 81 | # release automation 82 | release) 83 | version="$1" 84 | nextVersion="$2" 85 | if [ -z "$version" -o -z "$nextVersion" ]; then 86 | usage "$command " 87 | fi 88 | releaseTag="release-$version" 89 | 90 | # update version and tag 91 | self change-version "$version" 92 | git commit -a -m "update version: $version" 93 | git tag $releaseTag 94 | 95 | # deploy release 96 | mvn -Pbuildsupport-release clean deploy -Dbuild.notes="t:release" 97 | 98 | # update to next version 99 | self change-version "$nextVersion" 100 | git commit -a -m "update version: $nextVersion" 101 | 102 | # TODO: push origin (branch + tag) 103 | ;; 104 | 105 | *) 106 | # attempt to lookup command function 107 | fn="command_$command" 108 | if [ "$(type -t $fn)" = 'function' ]; then 109 | $fn "$@" 110 | else 111 | # complain about missing command function 112 | echo "Unknown command: $command" 113 | usage 114 | fi 115 | ;; 116 | esac 117 | -------------------------------------------------------------------------------- /build.config: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | project=gmaven 4 | 5 | function command_rebuild { 6 | mvn clean install "$@" 7 | } 8 | 9 | function command_ci_prepare { 10 | self license-check $* 11 | } 12 | 13 | function command_ci_build { 14 | if [ "$TRAVIS_PULL_REQUEST" != 'false' ]; then 15 | goal=install 16 | else 17 | goal=deploy 18 | fi 19 | mvn clean ${goal} "$@" 20 | } 21 | 22 | function command_site_build { 23 | mvn -Psite-stage 24 | } 25 | 26 | function command_site_deploy { 27 | self site_build 28 | mvn -Psite-publish 29 | } -------------------------------------------------------------------------------- /gmaven-adapter-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.codehaus.gmaven 25 | gmaven 26 | 2.2-SNAPSHOT 27 | 28 | 29 | gmaven-adapter-api 30 | ${project.groupId}:${project.artifactId} 31 | 32 | 33 | 34 | org.slf4j 35 | slf4j-api 36 | 37 | 38 | 39 | com.google.guava 40 | guava 41 | 42 | 43 | 44 | com.google.code.findbugs 45 | jsr305 46 | true 47 | 48 | 49 | 50 | org.sonatype.sisu.litmus 51 | litmus-testsupport 52 | test 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /gmaven-adapter-api/src/main/java/org/codehaus/gmaven/adapter/ClassSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.adapter; 17 | 18 | import java.io.File; 19 | import java.io.Reader; 20 | import java.net.URL; 21 | 22 | /** 23 | * Configuration details for construction of a {@link groovy.lang.GroovyCodeSource} instance. 24 | * 25 | * @since 2.0 26 | */ 27 | @SuppressWarnings("JavadocReference") 28 | public interface ClassSource 29 | { 30 | URL getUrl(); 31 | 32 | File getFile(); 33 | 34 | interface Inline 35 | { 36 | String getName(); 37 | 38 | String getCodeBase(); 39 | 40 | Reader getInput(); 41 | } 42 | 43 | Inline getInline(); 44 | } 45 | -------------------------------------------------------------------------------- /gmaven-adapter-api/src/main/java/org/codehaus/gmaven/adapter/ClosureTarget.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.adapter; 17 | 18 | import javax.annotation.Nullable; 19 | 20 | /** 21 | * Target implementation for a {@link groovy.lang.Closure}. 22 | * 23 | * @since 2.0 24 | */ 25 | @SuppressWarnings("JavadocReference") 26 | public interface ClosureTarget 27 | { 28 | @Nullable 29 | Object call(Object[] args) throws Exception; 30 | } 31 | -------------------------------------------------------------------------------- /gmaven-adapter-api/src/main/java/org/codehaus/gmaven/adapter/ConsoleWindow.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.adapter; 17 | 18 | import java.util.Map; 19 | 20 | import javax.annotation.Nullable; 21 | 22 | /** 23 | * Provides the ability to open a {@link groovy.ui.Console} window. 24 | * 25 | * @since 2.0 26 | */ 27 | @SuppressWarnings("JavadocReference") 28 | public interface ConsoleWindow 29 | { 30 | interface WindowHandle 31 | { 32 | void close(); 33 | 34 | void await() throws InterruptedException; 35 | } 36 | 37 | WindowHandle open(ClassLoader classLoader, 38 | ResourceLoader resourceLoader, 39 | Map context, 40 | @Nullable Map options) 41 | throws Exception; 42 | } -------------------------------------------------------------------------------- /gmaven-adapter-api/src/main/java/org/codehaus/gmaven/adapter/GroovyRuntime.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.adapter; 17 | 18 | /** 19 | * Provides access to Groovy runtime components. 20 | * 21 | * @since 2.0 22 | */ 23 | public interface GroovyRuntime 24 | { 25 | ScriptExecutor createScriptExecutor(); 26 | 27 | ConsoleWindow createConsoleWindow(); 28 | 29 | ShellRunner createShellRunner(); 30 | 31 | void cleanup(); 32 | } 33 | -------------------------------------------------------------------------------- /gmaven-adapter-api/src/main/java/org/codehaus/gmaven/adapter/MagicContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.adapter; 17 | 18 | /** 19 | * Magic context constants. 20 | * 21 | * @since 2.0 22 | */ 23 | public enum MagicContext 24 | { 25 | /** 26 | * Context value will be replaced by a {@link groovy.util.AntBuilder} instance. 27 | */ 28 | @SuppressWarnings("JavadocReference") 29 | ANT_BUILDER 30 | } 31 | -------------------------------------------------------------------------------- /gmaven-adapter-api/src/main/java/org/codehaus/gmaven/adapter/ResourceLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.adapter; 17 | 18 | import java.net.MalformedURLException; 19 | import java.net.URL; 20 | 21 | import javax.annotation.Nullable; 22 | 23 | /** 24 | * Provides named access to resources. 25 | * 26 | * @since 2.0 27 | * 28 | * @see groovy.lang.GroovyResourceLoader 29 | */ 30 | @SuppressWarnings("JavadocReference") 31 | public interface ResourceLoader 32 | { 33 | @Nullable 34 | URL loadResource(String name) throws MalformedURLException; 35 | } 36 | -------------------------------------------------------------------------------- /gmaven-adapter-api/src/main/java/org/codehaus/gmaven/adapter/ScriptExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.adapter; 17 | 18 | import java.util.Map; 19 | 20 | import javax.annotation.Nullable; 21 | 22 | /** 23 | * Provides the ability to execute a Groovy script. 24 | * 25 | * @since 2.0 26 | * 27 | * @see groovy.lang.GroovyShell 28 | */ 29 | @SuppressWarnings("JavadocReference") 30 | public interface ScriptExecutor 31 | { 32 | @Nullable 33 | Object execute(ClassSource classSource, 34 | ClassLoader classLoader, 35 | ResourceLoader resourceLoader, 36 | Map context, 37 | @Nullable Map options) 38 | throws Exception; 39 | } -------------------------------------------------------------------------------- /gmaven-adapter-api/src/main/java/org/codehaus/gmaven/adapter/ShellRunner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.adapter; 17 | 18 | import java.util.Map; 19 | 20 | import javax.annotation.Nullable; 21 | 22 | /** 23 | * Provides the ability to run a {@code groovysh} shell. 24 | * 25 | * @since 2.0 26 | * 27 | * @see org.codehaus.groovy.tools.shell.Groovysh 28 | */ 29 | @SuppressWarnings("JavadocReference") 30 | public interface ShellRunner 31 | { 32 | void run(ClassLoader classLoader, 33 | ResourceLoader resourceLoader, 34 | Map context, 35 | @Nullable Map options) 36 | throws Exception; 37 | } -------------------------------------------------------------------------------- /gmaven-adapter-api/src/main/java/org/codehaus/gmaven/adapter/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * GMaven adapter API. 18 | * 19 | * @since 2.0 20 | */ 21 | package org.codehaus.gmaven.adapter; 22 | -------------------------------------------------------------------------------- /gmaven-adapter-api/src/site/markdown/index.md: -------------------------------------------------------------------------------- 1 | 18 | # GMaven Adapter API 19 | 20 | Provides an abstraction used by [groovy-maven-plugin](../groovy-maven-plugin/index.html) to 21 | interact with the Groovy runtime. 22 | 23 | ## Components 24 | 25 | ### GroovyRuntime 26 | 27 | Factory, discovered via `java.util.ServiceLoader`, which provides access to feature components. 28 | 29 | ### ScriptExecutor 30 | 31 | Provides script execution functionality. 32 | 33 | ### ConsoleWindow 34 | 35 | Provides the ability to open the GUI Groovy console window. 36 | 37 | ### ShellRunner 38 | 39 | Provides the ability to run the command-line Groovy shell (aka `groovysh`). 40 | 41 | -------------------------------------------------------------------------------- /gmaven-adapter-api/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /gmaven-adapter-impl/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.codehaus.gmaven 25 | gmaven 26 | 2.2-SNAPSHOT 27 | 28 | 29 | gmaven-adapter-impl 30 | ${project.groupId}:${project.artifactId} 31 | 32 | 33 | 2.4.9 34 | 1.9.4 35 | 36 | 39 | ${groovy.version} 40 | 41 | 42 | 43 | 44 | org.codehaus.gmaven 45 | gmaven-adapter-api 46 | provided 47 | 48 | 49 | 50 | com.google.code.findbugs 51 | jsr305 52 | true 53 | 54 | 55 | 56 | org.codehaus.groovy 57 | groovy-all 58 | ${groovy.version} 59 | 60 | 61 | 62 | org.apache.ant 63 | ant 64 | ${apache-ant.version} 65 | 66 | 67 | 68 | org.apache.ant 69 | ant-launcher 70 | ${apache-ant.version} 71 | 72 | 73 | 74 | jline 75 | jline 76 | 2.12 77 | 78 | 79 | 80 | org.sonatype.sisu.litmus 81 | litmus-testsupport 82 | test 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /gmaven-adapter-impl/src/main/java/org/codehaus/gmaven/adapter/impl/ConsoleWindowImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.adapter.impl; 17 | 18 | import java.util.EventObject; 19 | import java.util.Map; 20 | 21 | import javax.annotation.Nullable; 22 | 23 | import groovy.lang.Binding; 24 | import groovy.lang.GroovyClassLoader; 25 | import groovy.ui.Console; 26 | import org.codehaus.gmaven.adapter.ConsoleWindow; 27 | import org.codehaus.gmaven.adapter.ResourceLoader; 28 | import org.slf4j.Logger; 29 | import org.slf4j.LoggerFactory; 30 | 31 | import static com.google.common.base.Preconditions.checkNotNull; 32 | 33 | /** 34 | * Default {@link ConsoleWindow} implementation. 35 | * 36 | * @since 2.0 37 | */ 38 | public class ConsoleWindowImpl 39 | implements ConsoleWindow 40 | { 41 | private final Logger log = LoggerFactory.getLogger(getClass()); 42 | 43 | private final GroovyRuntimeImpl runtime; 44 | 45 | private final Object lock = new Object(); 46 | 47 | ConsoleWindowImpl(final GroovyRuntimeImpl runtime) { 48 | this.runtime = checkNotNull(runtime); 49 | } 50 | 51 | @Override 52 | public WindowHandle open(final ClassLoader classLoader, 53 | final ResourceLoader resourceLoader, 54 | final Map context, 55 | final @Nullable Map options) 56 | throws Exception 57 | { 58 | checkNotNull(classLoader); 59 | checkNotNull(resourceLoader); 60 | checkNotNull(context); 61 | 62 | log.trace("Opening; class-loader: {}, resource-loader: {}, context: {}", 63 | classLoader, resourceLoader, context); 64 | 65 | final GroovyClassLoader gcl = runtime.createGroovyClassLoader(classLoader, resourceLoader); 66 | Binding binding = runtime.createBinding(context); 67 | 68 | // FIXME: Sort out how we can avoid IDEA from thinking a sub-class of this needs to have additional overrides 69 | // FIXME: Its complaining about the synthetic methods which are dynamically added to GroovyObject instances 70 | // FIXME: Perhaps we can install exit lock notification via an event listener instead? 71 | 72 | final Console console = new Console(gcl, binding) 73 | { 74 | public void exit(final EventObject event) { 75 | try { 76 | super.exit(event); 77 | } 78 | finally { 79 | synchronized (lock) { 80 | lock.notifyAll(); 81 | } 82 | } 83 | } 84 | }; 85 | 86 | if (options != null) { 87 | configureOptions(console, options); 88 | } 89 | 90 | log.trace("Opening"); 91 | console.run(); 92 | 93 | return new WindowHandle() 94 | { 95 | @Override 96 | public void close() { 97 | log.trace("Closing"); 98 | console.exit(); 99 | cleanup(); 100 | } 101 | 102 | @Override 103 | public void await() throws InterruptedException { 104 | log.trace("Waiting"); 105 | synchronized (lock) { 106 | lock.wait(); 107 | } 108 | cleanup(); 109 | } 110 | 111 | private void cleanup() { 112 | gcl.clearCache(); 113 | } 114 | }; 115 | } 116 | 117 | private void configureOptions(final Console console, final Map options) { 118 | // TODO 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /gmaven-adapter-impl/src/main/java/org/codehaus/gmaven/adapter/impl/GroovyRuntimeImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.adapter.impl; 17 | 18 | import java.io.IOException; 19 | import java.net.MalformedURLException; 20 | import java.net.URL; 21 | import java.security.AccessController; 22 | import java.security.PrivilegedAction; 23 | import java.util.Map; 24 | import java.util.Map.Entry; 25 | 26 | import com.google.common.base.Throwables; 27 | import groovy.lang.Binding; 28 | import groovy.lang.Closure; 29 | import groovy.lang.GroovyClassLoader; 30 | import groovy.lang.GroovyCodeSource; 31 | import groovy.lang.GroovyResourceLoader; 32 | import groovy.util.AntBuilder; 33 | import org.apache.tools.ant.BuildLogger; 34 | import org.codehaus.gmaven.adapter.ClassSource; 35 | import org.codehaus.gmaven.adapter.ClassSource.Inline; 36 | import org.codehaus.gmaven.adapter.ClosureTarget; 37 | import org.codehaus.gmaven.adapter.ConsoleWindow; 38 | import org.codehaus.gmaven.adapter.GroovyRuntime; 39 | import org.codehaus.gmaven.adapter.MagicContext; 40 | import org.codehaus.gmaven.adapter.ResourceLoader; 41 | import org.codehaus.gmaven.adapter.ScriptExecutor; 42 | import org.codehaus.gmaven.adapter.ShellRunner; 43 | import org.slf4j.Logger; 44 | import org.slf4j.LoggerFactory; 45 | 46 | import static com.google.common.base.Preconditions.checkNotNull; 47 | 48 | /** 49 | * Default {@link GroovyRuntime} implementation. 50 | * 51 | * @since 2.0 52 | */ 53 | public class GroovyRuntimeImpl 54 | implements GroovyRuntime 55 | { 56 | private final Logger log = LoggerFactory.getLogger(getClass()); 57 | 58 | @Override 59 | public ScriptExecutor createScriptExecutor() { 60 | return new ScriptExecutorImpl(this); 61 | } 62 | 63 | @Override 64 | public ConsoleWindow createConsoleWindow() { 65 | return new ConsoleWindowImpl(this); 66 | } 67 | 68 | @Override 69 | public ShellRunner createShellRunner() { 70 | return new ShellRunnerImpl(this); 71 | } 72 | 73 | @Override 74 | public void cleanup() { 75 | // nothing atm 76 | } 77 | 78 | // 79 | // Internal 80 | // 81 | 82 | /** 83 | * Create a {@link GroovyClassLoader} from given {@link ClassLoader} and {@link ResourceLoader}. 84 | */ 85 | public GroovyClassLoader createGroovyClassLoader(final ClassLoader classLoader, final ResourceLoader resourceLoader) { 86 | return AccessController.doPrivileged(new PrivilegedAction() 87 | { 88 | @Override 89 | public GroovyClassLoader run() { 90 | GroovyClassLoader gcl = new GroovyClassLoader(classLoader); 91 | gcl.setResourceLoader(createGroovyResourceLoader(resourceLoader)); 92 | return gcl; 93 | } 94 | }); 95 | } 96 | 97 | /** 98 | * Creates a {@link GroovyResourceLoader} from a {@link ResourceLoader}. 99 | */ 100 | public GroovyResourceLoader createGroovyResourceLoader(final ResourceLoader resourceLoader) { 101 | checkNotNull(resourceLoader); 102 | 103 | return new GroovyResourceLoader() 104 | { 105 | @Override 106 | public URL loadGroovySource(final String name) throws MalformedURLException { 107 | return resourceLoader.loadResource(name); 108 | } 109 | }; 110 | } 111 | 112 | /** 113 | * Creates a {@link GroovyCodeSource} from a {@link ClassSource}. 114 | */ 115 | public GroovyCodeSource createGroovyCodeSource(final ClassSource source) throws IOException { 116 | checkNotNull(source); 117 | 118 | if (source.getUrl() != null) { 119 | return new GroovyCodeSource(source.getUrl()); 120 | } 121 | if (source.getFile() != null) { 122 | return new GroovyCodeSource(source.getFile()); 123 | } 124 | if (source.getInline() != null) { 125 | Inline inline = source.getInline(); 126 | return new GroovyCodeSource(inline.getInput(), inline.getName(), inline.getCodeBase()); 127 | } 128 | 129 | throw new Error("Unable to create GroovyCodeSource from: " + source); 130 | } 131 | 132 | /** 133 | * Creates a {@link Closure} from a {@link ClosureTarget}. 134 | */ 135 | public Closure createClosure(final Object owner, final ClosureTarget target) { 136 | checkNotNull(owner); 137 | checkNotNull(target); 138 | 139 | return new Closure(owner) 140 | { 141 | @Override 142 | public Object call(final Object[] args) { 143 | try { 144 | return target.call(args); 145 | } 146 | catch (Exception e) { 147 | throw Throwables.propagate(e); 148 | } 149 | } 150 | 151 | @Override 152 | public String toString() { 153 | return Closure.class.getSimpleName() + "{owner=" + owner + ", target=" + target + "}"; 154 | } 155 | }; 156 | } 157 | 158 | /** 159 | * Create an object for a {@link MagicContext} entry. 160 | */ 161 | public Object createMagicContextValue(final MagicContext magic) { 162 | checkNotNull(magic); 163 | 164 | switch (magic) { 165 | // Create the AntBuilder instance, normalizing its output to match mavens 166 | case ANT_BUILDER: { 167 | AntBuilder ant = new AntBuilder(); 168 | // TODO: Do we need to root the ant-project or otherwise augment the configuration? 169 | 170 | Object obj = ant.getAntProject().getBuildListeners().elementAt(0); 171 | if (obj instanceof BuildLogger) { 172 | BuildLogger logger = (BuildLogger) obj; 173 | logger.setEmacsMode(true); 174 | } 175 | return ant; 176 | } 177 | } 178 | 179 | throw new Error("Unsupported magic context: " + magic); 180 | } 181 | 182 | /** 183 | * Create script binding, handling conversion of {@link ClosureTarget} and {@link MagicContext} entries. 184 | */ 185 | public Binding createBinding(final Map context) { 186 | Binding binding = new Binding(); 187 | 188 | log.debug("Binding:"); 189 | for (Entry entry : context.entrySet()) { 190 | String key = entry.getKey(); 191 | Object value = entry.getValue(); 192 | 193 | if (value instanceof ClosureTarget) { 194 | value = createClosure(this, (ClosureTarget) value); 195 | } 196 | else if (value instanceof MagicContext) { 197 | value = createMagicContextValue((MagicContext) value); 198 | } 199 | 200 | log.debug(" {}={}", key, value); 201 | binding.setVariable(entry.getKey(), value); 202 | } 203 | 204 | return binding; 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /gmaven-adapter-impl/src/main/java/org/codehaus/gmaven/adapter/impl/ScriptExecutorImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.adapter.impl; 17 | 18 | import java.util.Map; 19 | 20 | import javax.annotation.Nullable; 21 | 22 | import groovy.lang.Binding; 23 | import groovy.lang.GroovyClassLoader; 24 | import groovy.lang.GroovyCodeSource; 25 | import groovy.lang.GroovyShell; 26 | import org.codehaus.gmaven.adapter.ClassSource; 27 | import org.codehaus.gmaven.adapter.ResourceLoader; 28 | import org.codehaus.gmaven.adapter.ScriptExecutor; 29 | import org.codehaus.groovy.control.CompilerConfiguration; 30 | import org.slf4j.Logger; 31 | import org.slf4j.LoggerFactory; 32 | 33 | import static com.google.common.base.Preconditions.checkNotNull; 34 | 35 | /** 36 | * Default {@link ScriptExecutor} implementation. 37 | * 38 | * @since 2.0 39 | */ 40 | public class ScriptExecutorImpl 41 | implements ScriptExecutor 42 | { 43 | private final Logger log = LoggerFactory.getLogger(getClass()); 44 | 45 | private final GroovyRuntimeImpl runtime; 46 | 47 | ScriptExecutorImpl(final GroovyRuntimeImpl runtime) { 48 | this.runtime = checkNotNull(runtime); 49 | } 50 | 51 | @Override 52 | @Nullable 53 | public Object execute(final ClassSource classSource, 54 | final ClassLoader classLoader, 55 | final ResourceLoader resourceLoader, 56 | final Map context, 57 | final @Nullable Map options) 58 | throws Exception 59 | { 60 | checkNotNull(classSource); 61 | checkNotNull(classLoader); 62 | checkNotNull(resourceLoader); 63 | checkNotNull(context); 64 | 65 | log.trace("Execute; class-source: {}, class-loader: {}, resource-loader: {}, context: {}", 66 | classSource, classLoader, resourceLoader, context); 67 | 68 | GroovyClassLoader gcl = runtime.createGroovyClassLoader(classLoader, resourceLoader); 69 | 70 | CompilerConfiguration cc = new CompilerConfiguration(); 71 | 72 | // TODO: How, if at all, do we want to expose compiler configuration customizations? 73 | 74 | Binding binding = runtime.createBinding(context); 75 | GroovyShell shell = new GroovyShell(gcl, binding, cc); 76 | 77 | if (options != null) { 78 | configureOptions(shell, options); 79 | } 80 | 81 | GroovyCodeSource codeSource = runtime.createGroovyCodeSource(classSource); 82 | try { 83 | return shell.evaluate(codeSource); 84 | } 85 | finally { 86 | gcl.clearCache(); 87 | } 88 | } 89 | 90 | private void configureOptions(final GroovyShell shell, final Map options) { 91 | // TODO 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /gmaven-adapter-impl/src/main/java/org/codehaus/gmaven/adapter/impl/ShellRunnerImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.adapter.impl; 17 | 18 | import java.util.Map; 19 | 20 | import javax.annotation.Nullable; 21 | 22 | import groovy.lang.Binding; 23 | import groovy.lang.GroovyClassLoader; 24 | import org.codehaus.gmaven.adapter.ResourceLoader; 25 | import org.codehaus.gmaven.adapter.ShellRunner; 26 | import org.codehaus.groovy.tools.shell.Groovysh; 27 | import org.codehaus.groovy.tools.shell.IO; 28 | import org.slf4j.Logger; 29 | import org.slf4j.LoggerFactory; 30 | 31 | import static com.google.common.base.Preconditions.checkNotNull; 32 | 33 | /** 34 | * Default {@link ShellRunner} implementation. 35 | * 36 | * @since 2.0 37 | */ 38 | public class ShellRunnerImpl 39 | implements ShellRunner 40 | { 41 | private final Logger log = LoggerFactory.getLogger(getClass()); 42 | 43 | private final GroovyRuntimeImpl runtime; 44 | 45 | ShellRunnerImpl(final GroovyRuntimeImpl runtime) { 46 | this.runtime = checkNotNull(runtime); 47 | } 48 | 49 | @Override 50 | public void run(final ClassLoader classLoader, 51 | final ResourceLoader resourceLoader, 52 | final Map context, 53 | final @Nullable Map options) 54 | throws Exception 55 | { 56 | checkNotNull(classLoader); 57 | checkNotNull(resourceLoader); 58 | checkNotNull(context); 59 | 60 | log.trace("Running; class-loader: {}, resource-loader: {}, context: {}", 61 | classLoader, resourceLoader, context); 62 | 63 | GroovyClassLoader gcl = runtime.createGroovyClassLoader(classLoader, resourceLoader); 64 | Binding binding = runtime.createBinding(context); 65 | 66 | Groovysh shell = new Groovysh(gcl, binding, new IO()); 67 | 68 | if (options != null) { 69 | configureOptions(shell, options); 70 | } 71 | 72 | try { 73 | shell.run(null); 74 | } 75 | finally { 76 | gcl.clearCache(); 77 | } 78 | } 79 | 80 | private void configureOptions(final Groovysh shell, final Map options) { 81 | // TODO: 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /gmaven-adapter-impl/src/main/java/org/codehaus/gmaven/adapter/impl/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * GMaven adapter implementation. 18 | * 19 | * @since 2.0 20 | */ 21 | package org.codehaus.gmaven.adapter.impl; 22 | -------------------------------------------------------------------------------- /gmaven-adapter-impl/src/main/resources/META-INF/services/org.codehaus.gmaven.adapter.GroovyRuntime: -------------------------------------------------------------------------------- 1 | org.codehaus.gmaven.adapter.impl.GroovyRuntimeImpl -------------------------------------------------------------------------------- /gmaven-adapter-impl/src/site/markdown/index.md.vm: -------------------------------------------------------------------------------- 1 |

GMaven Adapter Implementation

2 | 3 | Provides the default [gmaven-runtime-api](../gmaven-runtime-api/index.html) implementation 4 | supporting Groovy 2.0+ and 2.1+ runtimes. 5 | 6 | Default version: Groovy ${site_groovyVersion} 7 | 8 | New versions of Groovy could break compatiblity, so becareful if customizing the Groovy version. 9 | If an incompatiblity is found, please [report the problem](https://jira.codehaus.org/browse/GMAVEN). 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /gmaven-adapter-impl/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /gmaven-testsuite/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.codehaus.gmaven 25 | gmaven 26 | 2.2-SNAPSHOT 27 | 28 | 29 | gmaven-testsuite 30 | ${project.groupId}:${project.artifactId} 31 | 32 | 33 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | org.sonatype.sisu.litmus 50 | litmus-testsupport 51 | test 52 | 53 | 54 | 55 | commons-lang 56 | commons-lang 57 | test 58 | 59 | 60 | 61 | commons-io 62 | commons-io 63 | test 64 | 65 | 66 | 67 | org.codehaus.plexus 68 | plexus-interpolation 69 | 70 | 71 | 72 | org.apache.maven.shared 73 | maven-verifier 74 | test 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | org.apache.maven.plugins 83 | maven-failsafe-plugin 84 | 85 | 86 | ${settings.localRepository} 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | org.codehaus.mojo 96 | animal-sniffer-maven-plugin 97 | 98 | 99 | none 100 | 101 | 102 | 103 | 104 | 105 | org.apache.maven.plugins 106 | maven-dependency-plugin 107 | 108 | 111 | 112 | generate-test-resources 113 | 114 | unpack 115 | 116 | 117 | ${project.build.directory}/filesets 118 | 119 | 120 | org.apache.maven 121 | apache-maven 122 | bin 123 | zip 124 | 3.0.5 125 | 126 | 127 | 128 | org.apache.maven 129 | apache-maven 130 | bin 131 | zip 132 | 3.1.0-alpha-1 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/site/markdown/index.md: -------------------------------------------------------------------------------- 1 | 18 | # GMaven Testsuite 19 | 20 | GMaven integration tests. 21 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/it-projects/execute-script/defaultContext.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2013, the original author or authors. 3 | * 4 | * This program is licensed to you under the Apache License Version 2.0, 5 | * and you may not use this file except in compliance with the Apache License Version 2.0. 6 | * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | 14 | //noinspection GroovyAssignabilityCheck 15 | def assertVariable = { value, Class expectedType -> 16 | // spit out value and class for reference 17 | println value 18 | println value?.getClass() 19 | 20 | // require non-null and expected type 21 | assert value != null 22 | assert expectedType.isAssignableFrom(value.getClass()) 23 | 24 | // we are good 25 | println 'OK' 26 | } 27 | 28 | // basic 29 | assertVariable(project, org.apache.maven.project.MavenProject) 30 | assertVariable(basedir, java.io.File) 31 | assertVariable(properties, java.util.Properties) 32 | assertVariable(ant, groovy.util.AntBuilder) 33 | assertVariable(fail, groovy.lang.Closure) 34 | assertVariable(log, org.slf4j.Logger) 35 | 36 | // advanced 37 | assertVariable(container, org.codehaus.gmaven.plugin.util.ContainerHelper) 38 | assertVariable(plugin, org.apache.maven.plugin.descriptor.PluginDescriptor) 39 | assertVariable(pluginContext, java.util.Map) 40 | assertVariable(mojo, org.apache.maven.plugin.MojoExecution) 41 | assertVariable(session, org.apache.maven.execution.MavenSession) 42 | assertVariable(settings, org.apache.maven.settings.Settings) 43 | 44 | // all validation passed 45 | println 'ALL OK' 46 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/it-projects/execute-script/groovyVersion.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2013, the original author or authors. 3 | * 4 | * This program is licensed to you under the Apache License Version 2.0, 5 | * and you may not use this file except in compliance with the Apache License Version 2.0. 6 | * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | 14 | // Print version of groovy we have access 15 | println "Version: ${GroovySystem.version}" 16 | println 'ALL OK' -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/it-projects/execute-script/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 18 | 19 | 4.0.0 20 | 21 | org.codehaus.gmaven.testsuite.it-projects 22 | execute-script 23 | 1 24 | 25 | 26 | 27 | 28 | org.codehaus.gmaven 29 | groovy-maven-plugin 30 | ${underTest.version} 31 | 32 | 33 | org.codehaus.groovy 34 | groovy-all 35 | ${groovy.version} 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/it-projects/execute-script/simple.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2013, the original author or authors. 3 | * 4 | * This program is licensed to you under the Apache License Version 2.0, 5 | * and you may not use this file except in compliance with the Apache License Version 2.0. 6 | * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | 14 | // Nothing fancy, just print something 15 | println 'ALL OK' 16 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/it-projects/property-resolution/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 18 | 19 | 4.0.0 20 | 21 | org.codehaus.gmaven.testsuite.it-projects 22 | property-defaults 23 | 1 24 | 25 | 26 | 27 | 28 | 29 | org.codehaus.gmaven 30 | groovy-maven-plugin 31 | ${underTest.version} 32 | 33 | 34 | org.codehaus.groovy 35 | groovy-all 36 | ${groovy.version} 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | projectDefined 47 | 48 | OK 49 | 50 | 51 | 52 | 53 | defaultDefined 54 | 55 | 56 | 57 | org.codehaus.gmaven 58 | groovy-maven-plugin 59 | 60 | 61 | OK 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | defaultReferencesProjectProperty 71 | 72 | ${foo} 73 | 74 | 75 | 76 | 77 | org.codehaus.gmaven 78 | groovy-maven-plugin 79 | 80 | 81 | OK 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | defaultReferencesSystemProperty 91 | 92 | 93 | 94 | org.codehaus.gmaven 95 | groovy-maven-plugin 96 | 97 | 98 | ${foo} 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | overrideDefined 108 | 109 | 110 | 111 | org.codehaus.gmaven 112 | groovy-maven-plugin 113 | 114 | 115 | OK 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | overrideReferencesSystemProperty 125 | 126 | 127 | 128 | org.codehaus.gmaven 129 | groovy-maven-plugin 130 | 131 | 132 | ${foo} 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 143 | 144 | overrideReferencesDefault 145 | 146 | 147 | 148 | org.codehaus.gmaven 149 | groovy-maven-plugin 150 | 151 | 152 | OK 153 | 154 | 155 | ${foo} 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/it-projects/property-resolution/printResult.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2013, the original author or authors. 3 | * 4 | * This program is licensed to you under the Apache License Version 2.0, 5 | * and you may not use this file except in compliance with the Apache License Version 2.0. 6 | * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | 14 | println 'Properties:' 15 | properties.sort().each { 16 | println " $it" 17 | } 18 | 19 | println "RESULT: ${properties['result']}" 20 | 21 | println 'ALL OK' 22 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/it-projects/scriptpath/hello.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2013, the original author or authors. 3 | * 4 | * This program is licensed to you under the Apache License Version 2.0, 5 | * and you may not use this file except in compliance with the Apache License Version 2.0. 6 | * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | 14 | new HelloWorld().run() 15 | 16 | println 'ALL OK' 17 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/it-projects/scriptpath/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 18 | 19 | 4.0.0 20 | 21 | org.codehaus.gmaven.testsuite.it-projects 22 | scriptpath 23 | 1 24 | 25 | 26 | 27 | 28 | 29 | org.codehaus.gmaven 30 | groovy-maven-plugin 31 | ${underTest.version} 32 | 33 | 34 | org.codehaus.groovy 35 | groovy-all 36 | ${groovy.version} 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | scriptpathResolvesClass 47 | 48 | 49 | 50 | org.codehaus.gmaven 51 | groovy-maven-plugin 52 | 53 | 54 | ${project.basedir}/scripts 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | peerResolvesClass 64 | 65 | 66 | 67 | org.codehaus.gmaven 68 | groovy-maven-plugin 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/it-projects/scriptpath/scripts/HelloWorld.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2013, the original author or authors. 3 | * 4 | * This program is licensed to you under the Apache License Version 2.0, 5 | * and you may not use this file except in compliance with the Apache License Version 2.0. 6 | * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | 14 | class HelloWorld 15 | { 16 | String message = 'Hello World' 17 | 18 | def run() { 19 | println message 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/it-projects/scriptpath/scripts/goodbye.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007-2013, the original author or authors. 3 | * 4 | * This program is licensed to you under the Apache License Version 2.0, 5 | * and you may not use this file except in compliance with the Apache License Version 2.0. 6 | * You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. 7 | * 8 | * Unless required by applicable law or agreed to in writing, 9 | * software distributed under the Apache License Version 2.0 is distributed on an 10 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. 12 | */ 13 | 14 | new HelloWorld(message: 'Goodbye World').run() 15 | 16 | println 'ALL OK' 17 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/it-projects/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/java/org/codehaus/gmaven/testsuite/MavenVerifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.testsuite; 17 | 18 | import java.io.File; 19 | 20 | import org.apache.maven.it.Verifier; 21 | 22 | /** 23 | * Wrapper around {@link org.apache.maven.it.Verifier} to provide saner API. 24 | */ 25 | public class MavenVerifier 26 | { 27 | private final Verifier delegate; 28 | 29 | public MavenVerifier(final File projectDir, final File settingsFile) throws Exception { 30 | this.delegate = new Verifier(projectDir.getAbsolutePath(), settingsFile.getAbsolutePath()); 31 | } 32 | 33 | public MavenVerifier setProperty(final String name, final Object value) { 34 | delegate.getSystemProperties().setProperty(name, String.valueOf(value)); 35 | return this; 36 | } 37 | 38 | public MavenVerifier addArg(final String arg) { 39 | delegate.addCliOption(arg); 40 | return this; 41 | } 42 | 43 | public MavenVerifier addProfile(final String profileId) { 44 | delegate.addCliOption("-P" + profileId); 45 | return this; 46 | } 47 | 48 | public MavenVerifier errorFree() throws Exception { 49 | delegate.verifyErrorFreeLog(); 50 | return this; 51 | } 52 | 53 | public MavenVerifier logContains(final String... values) throws Exception { 54 | for (String value : values) { 55 | delegate.verifyTextInLog(value); 56 | } 57 | return this; 58 | } 59 | 60 | public MavenVerifier executeGoal(final String goal) throws Exception { 61 | delegate.executeGoal(goal); 62 | return this; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/java/org/codehaus/gmaven/testsuite/suite/Maven305_Groovy206_SuiteIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.testsuite.suite; 17 | 18 | import org.junit.BeforeClass; 19 | import org.junit.runner.RunWith; 20 | import org.junit.runners.Suite; 21 | 22 | /** 23 | * Maven 3.0.5 and Groovy 2.0.6 combination test-suite. 24 | */ 25 | @RunWith(Suite.class) 26 | public class Maven305_Groovy206_SuiteIT 27 | extends SuiteSupport 28 | { 29 | @BeforeClass 30 | public static void configureCombination() { 31 | setMavenVersion("3.0.5"); 32 | setGroovyVersion("2.0.6"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/java/org/codehaus/gmaven/testsuite/suite/Maven305_Groovy215_SuiteIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.testsuite.suite; 17 | 18 | import org.junit.BeforeClass; 19 | import org.junit.runner.RunWith; 20 | import org.junit.runners.Suite; 21 | 22 | /** 23 | * Maven 3.0.5 and Groovy 2.1.5 combination test-suite. 24 | */ 25 | @RunWith(Suite.class) 26 | public class Maven305_Groovy215_SuiteIT 27 | extends SuiteSupport 28 | { 29 | @BeforeClass 30 | public static void configureCombination() { 31 | setMavenVersion("3.0.5"); 32 | setGroovyVersion("2.1.5"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/java/org/codehaus/gmaven/testsuite/suite/Maven31x_Groovy206_SuiteIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.testsuite.suite; 17 | 18 | import org.junit.BeforeClass; 19 | import org.junit.runner.RunWith; 20 | import org.junit.runners.Suite; 21 | 22 | /** 23 | * Maven 3.1.x and Groovy 2.0.6 combination test-suite. 24 | */ 25 | @RunWith(Suite.class) 26 | public class Maven31x_Groovy206_SuiteIT 27 | extends SuiteSupport 28 | { 29 | @BeforeClass 30 | public static void configureCombination() { 31 | setMavenVersion("3.1.0-alpha-1"); 32 | setGroovyVersion("2.0.6"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/java/org/codehaus/gmaven/testsuite/suite/Maven31x_Groovy215_SuiteIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.testsuite.suite; 17 | 18 | import org.junit.BeforeClass; 19 | import org.junit.runner.RunWith; 20 | import org.junit.runners.Suite; 21 | 22 | /** 23 | * Maven 3.1.x and Groovy 2.1.5 combination test-suite. 24 | */ 25 | @RunWith(Suite.class) 26 | public class Maven31x_Groovy215_SuiteIT 27 | extends SuiteSupport 28 | { 29 | @BeforeClass 30 | public static void configureCombination() { 31 | setMavenVersion("3.1.0-alpha-1"); 32 | setGroovyVersion("2.1.5"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/java/org/codehaus/gmaven/testsuite/suite/SuiteSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.testsuite.suite; 17 | 18 | import org.codehaus.gmaven.testsuite.tests.ExecuteBasics; 19 | import org.codehaus.gmaven.testsuite.tests.PropertyResolution; 20 | import org.junit.runners.Suite.SuiteClasses; 21 | 22 | /** 23 | * Support for suites. 24 | */ 25 | @SuiteClasses({ 26 | ExecuteBasics.class, 27 | PropertyResolution.class 28 | }) 29 | public abstract class SuiteSupport 30 | { 31 | protected static void setMavenVersion(final String version) { 32 | System.setProperty("maven.version", version); 33 | } 34 | 35 | protected static void setGroovyVersion(final String version) { 36 | System.setProperty("groovy.version", version); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/java/org/codehaus/gmaven/testsuite/tests/ExecuteBasics.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.testsuite.tests; 17 | 18 | import java.io.File; 19 | import java.net.URL; 20 | 21 | import org.codehaus.gmaven.testsuite.ITSupport; 22 | import org.codehaus.gmaven.testsuite.MavenVerifier; 23 | import org.junit.Test; 24 | 25 | /** 26 | * Verify 'execute' basics. 27 | */ 28 | public class ExecuteBasics 29 | extends ITSupport 30 | { 31 | private MavenVerifier executeScript(final String source) throws Exception { 32 | return verifier("execute-script") 33 | .setProperty("source", source) 34 | .executeGoal(goal("execute")); 35 | } 36 | 37 | private MavenVerifier executeScriptFileName(final String fileName) throws Exception { 38 | return executeScript(new File(testIndex.getDirectory(), fileName).getAbsolutePath()); 39 | } 40 | 41 | /** 42 | * Verifies all default context variables. 43 | */ 44 | @Test 45 | public void defaultContext() throws Exception { 46 | executeScriptFileName("defaultContext.groovy") 47 | .errorFree() 48 | .logContains("ALL OK"); 49 | } 50 | 51 | /** 52 | * Verify configured groovy runtime version matches what is detected. 53 | */ 54 | @Test 55 | public void groovyVersion() throws Exception { 56 | executeScriptFileName("groovyVersion.groovy") 57 | .errorFree() 58 | .logContains( 59 | "Version: " + getGroovyVersion(), 60 | "ALL OK" 61 | ); 62 | } 63 | 64 | /** 65 | * Verify execution of a simple inline-source script. 66 | */ 67 | @Test 68 | public void simpleInlineSource() throws Exception { 69 | executeScript("println(12345+1)") 70 | .errorFree() 71 | .logContains("12346"); 72 | } 73 | 74 | /** 75 | * Verify execution of a simple file-source script. 76 | */ 77 | @Test 78 | public void simpleFileSource() throws Exception { 79 | File file = new File(testIndex.getDirectory(), "simple.groovy"); 80 | executeScript(file.getAbsolutePath()) 81 | .errorFree() 82 | .logContains("ALL OK"); 83 | } 84 | 85 | /** 86 | * Verify execution of a simple url-source script. 87 | */ 88 | @Test 89 | public void simpleUrlSource() throws Exception { 90 | URL url = new File(testIndex.getDirectory(), "simple.groovy").toURI().toURL(); 91 | executeScript(url.toExternalForm()) 92 | .errorFree() 93 | .logContains("ALL OK"); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/java/org/codehaus/gmaven/testsuite/tests/PropertyResolution.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.testsuite.tests; 17 | 18 | import org.codehaus.gmaven.testsuite.ITSupport; 19 | import org.codehaus.gmaven.testsuite.MavenVerifier; 20 | import org.junit.Ignore; 21 | import org.junit.Test; 22 | 23 | /** 24 | * Verify property resolution. 25 | */ 26 | public class PropertyResolution 27 | extends ITSupport 28 | { 29 | private MavenVerifier verifier() throws Exception { 30 | return verifier("property-resolution") 31 | .setProperty("source", "printResult.groovy") 32 | .addProfile(testName.getMethodName()); 33 | } 34 | 35 | private void verify(final MavenVerifier verifier) throws Exception { 36 | verifier 37 | .errorFree() 38 | .logContains( 39 | "RESULT: OK", 40 | "ALL OK" 41 | ); 42 | } 43 | 44 | private void verifyDefault() throws Exception { 45 | verify( 46 | verifier() 47 | .executeGoal(goal("execute")) 48 | ); 49 | } 50 | 51 | @Test 52 | public void projectDefined() throws Exception { 53 | verifyDefault(); 54 | } 55 | 56 | @Test 57 | public void defaultDefined() throws Exception { 58 | verifyDefault(); 59 | } 60 | 61 | @Test 62 | public void defaultReferencesProjectProperty() throws Exception { 63 | verifyDefault(); 64 | } 65 | 66 | @Test 67 | public void defaultReferencesSystemProperty() throws Exception { 68 | verify( 69 | verifier() 70 | .setProperty("foo", "OK") 71 | .executeGoal(goal("execute")) 72 | ); 73 | } 74 | 75 | @Test 76 | public void overrideDefined() throws Exception { 77 | verifyDefault(); 78 | } 79 | 80 | @Test 81 | public void overrideReferencesSystemProperty() throws Exception { 82 | verify( 83 | verifier() 84 | .setProperty("foo", "OK") 85 | .executeGoal(goal("execute")) 86 | ); 87 | } 88 | 89 | @Test 90 | @Ignore("FIXME: This test has issues due to Maven interpolation before execution") 91 | public void overrideReferencesDefault() throws Exception { 92 | verifyDefault(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /gmaven-testsuite/src/test/java/org/codehaus/gmaven/testsuite/tests/Scriptpath.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.testsuite.tests; 17 | 18 | import java.io.File; 19 | 20 | import org.codehaus.gmaven.testsuite.ITSupport; 21 | import org.codehaus.gmaven.testsuite.MavenVerifier; 22 | import org.junit.Test; 23 | 24 | /** 25 | * Verify scriptpath resolution. 26 | */ 27 | public class Scriptpath 28 | extends ITSupport 29 | { 30 | private MavenVerifier verifier() throws Exception { 31 | return verifier("scriptpath") 32 | .addProfile(testName.getMethodName()); 33 | } 34 | 35 | @Test 36 | public void scriptpathResolvesClass() throws Exception { 37 | verifier() 38 | .setProperty("source", "hello.groovy") 39 | .executeGoal(goal("execute")) 40 | .errorFree() 41 | .logContains("Hello World"); 42 | } 43 | 44 | @Test 45 | public void scriptpathPropertyResolvesClass() throws Exception { 46 | verifier() 47 | .setProperty("scriptpath", new File(testdir(), "scripts")) 48 | .setProperty("source", "hello.groovy") 49 | .executeGoal(goal("execute")) 50 | .errorFree() 51 | .logContains("Hello World"); 52 | } 53 | 54 | @Test 55 | public void peerResolvesClass() throws Exception { 56 | verifier() 57 | .setProperty("source", "scripts/goodbye.groovy") 58 | .executeGoal(goal("execute")) 59 | .errorFree() 60 | .logContains("Goodbye World"); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /groovy-maven-plugin/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 4.0.0 22 | 23 | 24 | org.codehaus.gmaven 25 | gmaven 26 | 2.2-SNAPSHOT 27 | 28 | 29 | groovy-maven-plugin 30 | ${project.groupId}:${project.artifactId} 31 | maven-plugin 32 | 33 | 34 | 35 | org.slf4j 36 | slf4j-api 37 | 38 | 39 | 42 | 43 | 44 | org.sonatype.gossip 45 | gossip-slf4j 46 | runtime 47 | 48 | 49 | 50 | com.google.guava 51 | guava 52 | 53 | 54 | 55 | com.google.code.findbugs 56 | jsr305 57 | true 58 | 59 | 60 | 61 | org.apache.maven.plugin-tools 62 | maven-plugin-annotations 63 | provided 64 | 65 | 66 | 67 | org.apache.maven 68 | maven-plugin-api 69 | provided 70 | 71 | 72 | 73 | org.apache.maven 74 | maven-core 75 | provided 76 | 77 | 78 | 79 | org.apache.maven 80 | maven-settings 81 | provided 82 | 83 | 84 | 85 | org.codehaus.plexus 86 | plexus-classworlds 87 | 88 | 89 | 90 | org.codehaus.plexus 91 | plexus-interpolation 92 | 93 | 94 | 95 | org.eclipse.aether 96 | aether-util 97 | 98 | 99 | 100 | org.codehaus.gmaven 101 | gmaven-adapter-api 102 | 103 | 104 | 105 | org.codehaus.gmaven 106 | gmaven-adapter-impl 107 | 108 | 109 | 110 | org.sonatype.sisu.litmus 111 | litmus-testsupport 112 | test 113 | 114 | 117 | 118 | ch.qos.logback 119 | logback-classic 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | org.codehaus.plexus 129 | plexus-component-metadata 130 | 131 | 132 | 133 | org.apache.maven.plugins 134 | maven-plugin-plugin 135 | 136 | 137 | 3.0 138 | 1.6 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | org.apache.maven.plugins 149 | maven-plugin-plugin 150 | 3.2 151 | 152 | 153 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/BasicResourceLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin; 17 | 18 | import java.net.MalformedURLException; 19 | import java.net.URL; 20 | 21 | import javax.annotation.Nullable; 22 | 23 | import org.codehaus.gmaven.adapter.ResourceLoader; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | import static com.google.common.base.Preconditions.checkNotNull; 28 | 29 | /** 30 | * Basic {@link ResourceLoader} implementation. 31 | * 32 | * @since 2.0 33 | */ 34 | public class BasicResourceLoader 35 | implements ResourceLoader 36 | { 37 | protected static final String DOT_GROOVY = ".groovy"; 38 | 39 | protected final Logger log = LoggerFactory.getLogger(getClass()); 40 | 41 | protected final ClassLoader classLoader; 42 | 43 | public BasicResourceLoader(final ClassLoader classLoader) { 44 | this.classLoader = checkNotNull(classLoader); 45 | } 46 | 47 | @Nullable 48 | public URL loadResource(final String name) throws MalformedURLException { 49 | return resolve(name, classLoader); 50 | } 51 | 52 | @Nullable 53 | protected URL resolve(final String className, final ClassLoader classLoader) throws MalformedURLException { 54 | log.trace("Resolve; class-name: {}, class-loader: {}", className, classLoader); 55 | 56 | String name = resourceName(className); 57 | 58 | log.trace("Resolve; resource: {}", name); 59 | 60 | boolean tcl = false; 61 | URL resource = classLoader.getResource(name); 62 | 63 | // try from tcl if given CL does not resolve 64 | if (resource == null) { 65 | resource = Thread.currentThread().getContextClassLoader().getResource(name); 66 | tcl = true; 67 | } 68 | 69 | log.trace("Resource: {}, tcl: {}", resource, tcl); 70 | 71 | return resource; 72 | } 73 | 74 | /** 75 | * Translate class-name into resource-name. 76 | */ 77 | protected String resourceName(final String className) { 78 | String name = className; 79 | 80 | if (!name.startsWith("/")) { 81 | name = "/" + name; 82 | } 83 | 84 | if (!name.endsWith(DOT_GROOVY)) { 85 | name = name.replace('.', '/'); 86 | name += DOT_GROOVY; 87 | } 88 | 89 | return name; 90 | } 91 | } -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/ClassSourceFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin; 17 | 18 | import java.io.File; 19 | import java.io.IOException; 20 | import java.io.Reader; 21 | import java.io.StringReader; 22 | import java.net.MalformedURLException; 23 | import java.net.URL; 24 | import java.util.concurrent.atomic.AtomicInteger; 25 | 26 | import javax.annotation.Nullable; 27 | 28 | import com.google.common.annotations.VisibleForTesting; 29 | import org.codehaus.gmaven.adapter.ClassSource; 30 | import org.codehaus.gmaven.adapter.ClassSource.Inline; 31 | import org.codehaus.plexus.component.annotations.Component; 32 | import org.slf4j.Logger; 33 | import org.slf4j.LoggerFactory; 34 | 35 | import static com.google.common.base.Preconditions.checkNotNull; 36 | 37 | /** 38 | * Creates {@link ClassSource} instances 39 | * 40 | * @since 2.0 41 | */ 42 | @Component(role = ClassSourceFactory.class) 43 | public class ClassSourceFactory 44 | { 45 | private final Logger log = LoggerFactory.getLogger(getClass()); 46 | 47 | private static final class ClassSourceImpl 48 | implements ClassSource 49 | { 50 | private final URL url; 51 | 52 | private final File file; 53 | 54 | private final Inline inline; 55 | 56 | private ClassSourceImpl(final @Nullable URL url, 57 | final @Nullable File file, 58 | final @Nullable Inline inline) 59 | { 60 | this.url = url; 61 | this.file = file; 62 | this.inline = inline; 63 | } 64 | 65 | public URL getUrl() { 66 | return url; 67 | } 68 | 69 | public File getFile() { 70 | return file; 71 | } 72 | 73 | public Inline getInline() { 74 | return inline; 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return getClass().getSimpleName() + "{" + 80 | "url=" + url + 81 | ", file=" + file + 82 | ", inline=" + inline + 83 | '}'; 84 | } 85 | } 86 | 87 | @VisibleForTesting 88 | static final AtomicInteger scriptCounter = new AtomicInteger(0); 89 | 90 | private static final class InlineImpl 91 | implements Inline 92 | { 93 | private final String name; 94 | 95 | private final String codeBase; 96 | 97 | private final Reader input; 98 | 99 | private InlineImpl(final String source) { 100 | this.name = "script" + scriptCounter.incrementAndGet() + ".groovy"; 101 | this.codeBase = "/groovy/script"; 102 | this.input = new StringReader(source); 103 | } 104 | 105 | public String getName() { 106 | return name; 107 | } 108 | 109 | public String getCodeBase() { 110 | return codeBase; 111 | } 112 | 113 | public Reader getInput() { 114 | return input; 115 | } 116 | 117 | @Override 118 | public String toString() { 119 | return getClass().getSimpleName() + "{" + 120 | "name='" + name + '\'' + 121 | ", codeBase='" + codeBase + '\'' + 122 | ", input=" + input + 123 | '}'; 124 | } 125 | } 126 | 127 | /** 128 | * Create a class-source from the given source. 129 | */ 130 | public ClassSource create(final String source) { 131 | checkNotNull(source); 132 | 133 | String trimmed = source.trim(); 134 | log.trace("Creating class-source from: {}", trimmed); 135 | 136 | // First try and parse the source as a URL 137 | try { 138 | return new ClassSourceImpl(new URL(trimmed), null, null); 139 | } 140 | catch (MalformedURLException e) { 141 | log.trace("Not a URL", e); 142 | } 143 | 144 | // FIXME: This is _slightly_ problematic as if you have a valid file ref 145 | // FIXME: but the file is missing then it will be treated as inline instead of as a file 146 | 147 | // Then as a File 148 | try { 149 | File file = new File(trimmed).getCanonicalFile(); 150 | if (file.exists()) { 151 | return new ClassSourceImpl(null, file, null); 152 | } 153 | } 154 | catch (IOException e) { 155 | log.trace("Not a File", e); 156 | } 157 | 158 | // Else it is an inline 159 | return new ClassSourceImpl(null, null, new InlineImpl(source)); 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/ClasspathScope.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin; 17 | 18 | /** 19 | * Classpath scope. 20 | * 21 | * @since 2.0 22 | */ 23 | @SuppressWarnings("UnusedDeclaration") 24 | public enum ClasspathScope 25 | { 26 | none(null), 27 | provided(null), 28 | compile(provided), 29 | runtime(compile), 30 | test(runtime); 31 | 32 | private final ClasspathScope include; 33 | 34 | private ClasspathScope(final ClasspathScope include) { 35 | this.include = include; 36 | } 37 | 38 | public boolean matches(final String scope) { 39 | if (name().equals(scope)) { 40 | return true; 41 | } 42 | else if (include != null) { 43 | return include.matches(scope); 44 | } 45 | return false; 46 | } 47 | 48 | public boolean matches(final ClasspathScope scope) { 49 | return matches(scope.name()); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/ConsoleMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin; 17 | 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | 21 | import org.apache.maven.plugins.annotations.Mojo; 22 | import org.codehaus.gmaven.adapter.ConsoleWindow; 23 | import org.codehaus.gmaven.adapter.ConsoleWindow.WindowHandle; 24 | import org.codehaus.gmaven.adapter.ResourceLoader; 25 | 26 | import static org.apache.maven.plugins.annotations.ResolutionScope.TEST; 27 | 28 | /** 29 | * Open a Groovy console window. 30 | * 31 | *
32 | * See usage for more details. 33 | * 34 | * @since 2.0 35 | */ 36 | @Mojo(name = "console", requiresProject = false, requiresDependencyResolution = TEST, aggregator = true) 37 | public class ConsoleMojo 38 | extends RuntimeMojoSupport 39 | { 40 | // TODO: Expose console options 41 | 42 | @Override 43 | protected void run() throws Exception { 44 | final ResourceLoader resourceLoader = new MojoResourceLoader(getRuntimeRealm(), getScriptpath()); 45 | final Map context = createContext(); 46 | final Map options = new HashMap(); 47 | final ConsoleWindow console = getRuntime().createConsoleWindow(); 48 | 49 | WindowHandle handle = console.open(getRuntimeRealm(), resourceLoader, context, options); 50 | handle.await(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/ExecuteMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin; 17 | 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | 21 | import org.apache.maven.plugins.annotations.Component; 22 | import org.apache.maven.plugins.annotations.Mojo; 23 | import org.apache.maven.plugins.annotations.Parameter; 24 | import org.codehaus.gmaven.adapter.ClassSource; 25 | import org.codehaus.gmaven.adapter.ResourceLoader; 26 | import org.codehaus.gmaven.adapter.ScriptExecutor; 27 | import org.codehaus.gmaven.plugin.util.PropertiesBuilder; 28 | 29 | import static org.apache.maven.plugins.annotations.ResolutionScope.TEST; 30 | 31 | /** 32 | * Execute a Groovy script. 33 | * 34 | *
35 | * See usage for more details. 36 | * 37 | * @since 2.0 38 | */ 39 | @Mojo(name = "execute", requiresProject = false, threadSafe = true, requiresDependencyResolution = TEST) 40 | public class ExecuteMojo 41 | extends RuntimeMojoSupport 42 | { 43 | @Component 44 | private ClassSourceFactory classSourceFactory; 45 | 46 | /** 47 | * Source of the script to execute. 48 | * 49 | *
50 | * Allowed content flavors: 51 | *
    52 | *
  • File
  • 53 | *
  • URL
  • 54 | *
  • Inline script
  • 55 | *
56 | * 57 | *
58 | * When using inline scripts, be aware that Maven will interpolate this value early when configuring execution. 59 | * This may cause problems if the script is expecting {@code groovy.lang.GString} evaluation instead. 60 | * 61 | *
62 | * Scripts which make use of GString expressions should seriously consider using a File or URL source instead. 63 | */ 64 | @Parameter(property = "source", required = true) 65 | private String source; 66 | 67 | /** 68 | * Execution property overrides. 69 | * 70 | *
71 | * Any property defined here will take precedence over any other definition. 72 | */ 73 | @Parameter 74 | private Map properties; 75 | 76 | /** 77 | * Execution property defaults. 78 | * 79 | *
80 | * Any property defined _elsewhere_ (project, user, system, etc) will take precedence over default values. 81 | */ 82 | @Parameter 83 | private Map defaults; 84 | 85 | 86 | /** 87 | * Skip the execution of this mojo. 88 | * 89 | * @since 2.2.0 90 | */ 91 | @Parameter(property = "gmaven.execute.skip", defaultValue = "false") 92 | private boolean skip; 93 | 94 | @Override 95 | protected void run() throws Exception { 96 | final ClassSource classSource = classSourceFactory.create(source); 97 | log.debug("Class source: {}", classSource); 98 | 99 | final ResourceLoader resourceLoader = new MojoResourceLoader(getRuntimeRealm(), classSource, getScriptpath()); 100 | final Map context = createContext(); 101 | final Map options = new HashMap(); 102 | final ScriptExecutor executor = getRuntime().createScriptExecutor(); 103 | 104 | Object result = executor.execute(classSource, getRuntimeRealm(), resourceLoader, context, options); 105 | log.debug("Result: {}", result); 106 | } 107 | 108 | @Override 109 | protected void customizeProperties(final PropertiesBuilder builder) { 110 | builder.setProperties(properties) 111 | .setDefaults(defaults); 112 | } 113 | 114 | @Override 115 | protected boolean isSkipped() { 116 | return skip; 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/FailClosureTarget.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin; 17 | 18 | import javax.annotation.Nullable; 19 | 20 | import com.google.common.annotations.VisibleForTesting; 21 | import org.apache.maven.plugin.MojoExecutionException; 22 | import org.codehaus.gmaven.adapter.ClosureTarget; 23 | 24 | /** 25 | * Target implementation of {@code fail} closure. 26 | * 27 | *
28 | * Usage: 29 | *
    30 | *
  • {@code fail()}
  • 31 | *
  • {@code fail(Object)}
  • 32 | *
  • {@code fail(Throwable)}
  • 33 | *
  • {@code fail(Object, Throwable)}
  • 34 | *
35 | * 36 | *
37 | * Failing with a simple string: 38 | *
 39 |  * fail('I done goofed')
 40 |  * 
41 | * 42 | *
43 | * Failing with an exception detail: 44 | *
 45 |  * try {
 46 |  *   ....
 47 |  * }
 48 |  * catch (e) {
 49 |  *   fail(e)
 50 |  * }
 51 |  * 
52 | * 53 | *
54 | * Failing with an exception detail and a message: 55 | *
 56 |  * try {
 57 |  *   ....
 58 |  * }
 59 |  * catch (e) {
 60 |  *   fail('Houston we have a problem', e)
 61 |  * }
 62 |  * 
63 | * 64 | * @since 2.0 65 | */ 66 | public class FailClosureTarget 67 | implements ClosureTarget 68 | { 69 | @VisibleForTesting 70 | static final String FAILED = "Failed"; 71 | 72 | /** 73 | * Throws {@link MojoExecutionException}. 74 | */ 75 | public Object call(final @Nullable Object[] args) throws Exception { 76 | if (args == null || args.length == 0) { 77 | throw new MojoExecutionException(FAILED); 78 | } 79 | else if (args.length == 1) { 80 | if (args[0] instanceof Throwable) { 81 | Throwable cause = (Throwable) args[0]; 82 | throw new MojoExecutionException(cause.getMessage(), cause); 83 | } 84 | else { 85 | throw new MojoExecutionException(String.valueOf(args[0])); 86 | } 87 | } 88 | else if (args.length == 2) { 89 | if (args[1] instanceof Throwable) { 90 | throw new MojoExecutionException(String.valueOf(args[0]), (Throwable) args[1]); 91 | } 92 | else { 93 | throw new Error("Invalid arguments to fail(Object, Throwable), second argument must be a Throwable"); 94 | } 95 | } 96 | else { 97 | throw new Error("Too many arguments; expected one of: fail(), fail(Object) or fail(Object, Throwable)"); 98 | } 99 | } 100 | } -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/GroovyRuntimeFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin; 17 | 18 | import java.util.Iterator; 19 | import java.util.ServiceLoader; 20 | 21 | import com.google.common.annotations.VisibleForTesting; 22 | import org.codehaus.gmaven.adapter.GroovyRuntime; 23 | import org.codehaus.plexus.component.annotations.Component; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | import static com.google.common.base.Preconditions.checkNotNull; 28 | import static com.google.common.base.Preconditions.checkState; 29 | 30 | /** 31 | * Creates {@link GroovyRuntime} instances. 32 | * 33 | * @since 2.0 34 | */ 35 | @Component(role=GroovyRuntimeFactory.class) 36 | public class GroovyRuntimeFactory 37 | { 38 | private final Logger log = LoggerFactory.getLogger(getClass()); 39 | 40 | public GroovyRuntime create(final ClassLoader classLoader) { 41 | checkNotNull(classLoader); 42 | 43 | Iterator services = findServices(classLoader); 44 | 45 | checkState(services.hasNext(), "No GroovyRuntime service found"); 46 | 47 | GroovyRuntime runtime = services.next(); 48 | 49 | checkState(!services.hasNext(), "Multiple GroovyRuntime services found"); 50 | 51 | log.debug("Runtime: {}", runtime); 52 | return runtime; 53 | } 54 | 55 | @VisibleForTesting 56 | protected Iterator findServices(final ClassLoader classLoader) { 57 | ServiceLoader serviceLoader = ServiceLoader.load(GroovyRuntime.class, classLoader); 58 | log.debug("Loader: {}", serviceLoader); 59 | return serviceLoader.iterator(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/MojoResourceLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin; 17 | 18 | import java.io.File; 19 | import java.net.MalformedURLException; 20 | import java.net.URL; 21 | import java.util.List; 22 | 23 | import javax.annotation.Nullable; 24 | 25 | import org.codehaus.gmaven.adapter.ClassSource; 26 | import org.codehaus.gmaven.adapter.ResourceLoader; 27 | 28 | /** 29 | * Mojo {@link ResourceLoader}. 30 | * 31 | * @since 2.0 32 | */ 33 | public class MojoResourceLoader 34 | extends BasicResourceLoader 35 | { 36 | private final ClassSource classSource; 37 | 38 | private final List scriptpath; 39 | 40 | public MojoResourceLoader(final ClassLoader classLoader, 41 | final @Nullable ClassSource classSource, 42 | final @Nullable List scriptpath) 43 | { 44 | super(classLoader); 45 | this.classSource = classSource; 46 | this.scriptpath = scriptpath; 47 | } 48 | 49 | public MojoResourceLoader(final ClassLoader classLoader, 50 | final @Nullable List scriptpath) 51 | { 52 | this(classLoader, null, scriptpath); 53 | } 54 | 55 | @Nullable 56 | protected URL resolve(final String className, final ClassLoader classLoader) throws MalformedURLException { 57 | String name = resourceName(className); 58 | 59 | // First check the scriptpath 60 | if (scriptpath != null) { 61 | for (File path : scriptpath) { 62 | File file = new File(path, name); 63 | if (file.exists()) { 64 | return file.toURI().toURL(); 65 | } 66 | } 67 | } 68 | 69 | // Then look for a resource in the classpath 70 | URL url = classLoader.getResource(name); 71 | 72 | // FIXME: Sort out if this is required to function or if it should be removed 73 | // Try w/o leading '/'... ??? Seems that when loading resources the '/' prefix messes things up? 74 | if (url == null) { 75 | if (name.startsWith("/")) { 76 | String tmp = name.substring(1, name.length()); 77 | url = classLoader.getResource(tmp); 78 | } 79 | } 80 | 81 | if (url != null) { 82 | return url; 83 | } 84 | 85 | // Check for a class defined in a file next to the main script file 86 | if (classSource != null) { 87 | File script = classSource.getFile(); 88 | if (script != null) { 89 | File file = new File(script.getParentFile(), name); 90 | 91 | if (file.exists()) { 92 | return file.toURI().toURL(); 93 | } 94 | } 95 | } 96 | 97 | // else fallback to super impl 98 | return super.resolve(className, classLoader); 99 | } 100 | } -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/MojoSupport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin; 17 | 18 | import com.google.common.base.Throwables; 19 | import org.apache.maven.plugin.AbstractMojo; 20 | import org.apache.maven.plugin.Mojo; 21 | import org.apache.maven.plugin.MojoExecutionException; 22 | import org.apache.maven.plugin.MojoFailureException; 23 | import org.slf4j.Logger; 24 | import org.slf4j.LoggerFactory; 25 | 26 | /** 27 | * Support for {@link Mojo} implementations. 28 | * 29 | * @since 2.0 30 | */ 31 | public abstract class MojoSupport 32 | extends AbstractMojo 33 | { 34 | protected final Logger log = LoggerFactory.getLogger(getClass()); 35 | 36 | protected MojoSupport() { 37 | log.trace("Construct"); 38 | } 39 | 40 | public void execute() throws MojoExecutionException, MojoFailureException { 41 | if (isSkipped()) { 42 | getLog().info("Skipping as requested by the user"); 43 | return; 44 | } 45 | try { 46 | try { 47 | log.trace("Prepare"); 48 | prepare(); 49 | 50 | log.trace("Run"); 51 | run(); 52 | } 53 | finally { 54 | log.trace("Cleanup"); 55 | cleanup(); 56 | } 57 | } 58 | catch (Exception e) { 59 | log.trace("Failure", e); 60 | Throwables.propagateIfPossible(e, MojoExecutionException.class, MojoFailureException.class); 61 | throw Throwables.propagate(e); 62 | } 63 | } 64 | 65 | protected void prepare() throws Exception { 66 | // empty 67 | } 68 | 69 | protected abstract void run() throws Exception; 70 | 71 | protected void cleanup() throws Exception { 72 | // empty 73 | } 74 | 75 | protected boolean isSkipped() { 76 | return false; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/ShellMojo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin; 17 | 18 | import java.util.HashMap; 19 | import java.util.Map; 20 | 21 | import org.apache.maven.plugins.annotations.Mojo; 22 | import org.codehaus.gmaven.adapter.ResourceLoader; 23 | import org.codehaus.gmaven.adapter.ShellRunner; 24 | 25 | import static org.apache.maven.plugins.annotations.ResolutionScope.TEST; 26 | 27 | /** 28 | * Run {@code groovysh} shell. 29 | * 30 | *
31 | * See usage for more details. 32 | * 33 | * @since 2.0 34 | */ 35 | @Mojo(name = "shell", requiresProject = false, requiresDependencyResolution = TEST, aggregator = true) 36 | public class ShellMojo 37 | extends RuntimeMojoSupport 38 | { 39 | // TODO: Expose groovysh options 40 | 41 | @Override 42 | protected void run() throws Exception { 43 | final ResourceLoader resourceLoader = new MojoResourceLoader(getRuntimeRealm(), getScriptpath()); 44 | final Map context = createContext(); 45 | final Map options = new HashMap(); 46 | final ShellRunner shell = getRuntime().createShellRunner(); 47 | 48 | shell.run(getRuntimeRealm(), resourceLoader, context, options); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * GMaven plugin. 18 | * 19 | * @since 2.0 20 | */ 21 | package org.codehaus.gmaven.plugin; 22 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/util/ContainerHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin.util; 17 | 18 | import com.google.common.annotations.VisibleForTesting; 19 | import org.codehaus.plexus.PlexusContainer; 20 | import org.codehaus.plexus.component.annotations.Component; 21 | import org.codehaus.plexus.component.annotations.Requirement; 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | 25 | import static com.google.common.base.Preconditions.checkNotNull; 26 | 27 | /** 28 | * IoC container helper. 29 | * 30 | * @since 2.0 31 | */ 32 | @SuppressWarnings("unchecked") 33 | @Component(role = ContainerHelper.class) 34 | public class ContainerHelper 35 | { 36 | private final Logger log = LoggerFactory.getLogger(getClass()); 37 | 38 | @Requirement 39 | private PlexusContainer container; 40 | 41 | public ContainerHelper() {} 42 | 43 | @VisibleForTesting 44 | public ContainerHelper(final PlexusContainer container) { 45 | this.container = checkNotNull(container); 46 | } 47 | 48 | public Object lookup(final Class type) throws Exception { 49 | checkNotNull(type); 50 | 51 | log.trace("Lookup; class: {}", type); 52 | Object component = container.lookup(type); 53 | log.trace("Component: {}", component); 54 | 55 | return component; 56 | } 57 | 58 | public Object lookup(final String typeName) throws Exception { 59 | checkNotNull(typeName); 60 | 61 | log.trace("Lookup; class-name: {}", typeName); 62 | Object component = container.lookup(typeName); 63 | log.trace("Component: {}", component); 64 | 65 | return component; 66 | } 67 | 68 | public Object lookup(final Class type, final String name) throws Exception { 69 | checkNotNull(type); 70 | checkNotNull(name); 71 | 72 | log.trace("Lookup; class: {}, name: {}", type, name); 73 | Object component = container.lookup(type, name); 74 | log.trace("Component: {}", component); 75 | 76 | return component; 77 | } 78 | 79 | public Object lookup(final String typeName, final String name) throws Exception { 80 | checkNotNull(typeName); 81 | checkNotNull(name); 82 | 83 | log.trace("Lookup; class-name: {}, name: {}", typeName, name); 84 | Object component = container.lookup(typeName, name); 85 | log.trace("Component: {}", component); 86 | 87 | return component; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/util/GroovyVersionHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin.util; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | import javax.annotation.Nullable; 21 | 22 | import com.google.common.annotations.VisibleForTesting; 23 | import org.codehaus.plexus.component.annotations.Component; 24 | import org.codehaus.plexus.component.annotations.Requirement; 25 | import org.eclipse.aether.version.Version; 26 | import org.slf4j.Logger; 27 | import org.slf4j.LoggerFactory; 28 | 29 | import static com.google.common.base.Preconditions.checkNotNull; 30 | 31 | /** 32 | * Groovy version helper. 33 | * 34 | * @since 2.0 35 | */ 36 | @Component(role=GroovyVersionHelper.class) 37 | public class GroovyVersionHelper 38 | { 39 | private final Logger log = LoggerFactory.getLogger(getClass()); 40 | 41 | @Requirement 42 | private VersionHelper versionHelper; 43 | 44 | public GroovyVersionHelper() {} 45 | 46 | @VisibleForTesting 47 | public GroovyVersionHelper(final VersionHelper versionHelper) { 48 | this.versionHelper = checkNotNull(versionHelper); 49 | } 50 | 51 | @Nullable 52 | public Version detectVersion(final ClassLoader classLoader) { 53 | checkNotNull(classLoader); 54 | 55 | log.trace("Detecting Groovy version; class-loader: {}", classLoader); 56 | 57 | // Modern versions of Groovy expose the version via GroovySystem.getVersion() 58 | String raw = getVersion(classLoader, "groovy.lang.GroovySystem", "getVersion"); 59 | if (raw == null) { 60 | // Older versions of Groovy expose the version via InvokerHelper.getVersion() 61 | raw = getVersion(classLoader, "org.codehaus.groovy.runtime.InvokerHelper", "getVersion"); 62 | } 63 | 64 | log.trace("Raw version: {}", raw); 65 | if (raw == null) { 66 | return null; 67 | } 68 | 69 | Version version = versionHelper.parseVersion(raw); 70 | log.trace("Version: {}", version); 71 | return version; 72 | } 73 | 74 | /** 75 | * Get version from Groovy version helper utilities via reflection. 76 | */ 77 | private String getVersion(final ClassLoader classLoader, final String className, final String methodName) { 78 | log.trace("Getting version; class-loader: {}, class-name: {}, method-name: {}", 79 | classLoader, className, methodName); 80 | 81 | try { 82 | Class type = classLoader.loadClass(className); 83 | Method method = type.getMethod(methodName); 84 | Object result = method.invoke(null); 85 | if (result != null) { 86 | return result.toString(); 87 | } 88 | } 89 | catch (Throwable e) { 90 | log.trace("Unable determine version from: {}", className); 91 | } 92 | 93 | return null; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/util/Maps2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin.util; 17 | 18 | import java.util.Enumeration; 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | import java.util.Properties; 22 | 23 | import static com.google.common.base.Preconditions.checkNotNull; 24 | 25 | /** 26 | * Map helper. 27 | * 28 | * @since 2.1.1 29 | */ 30 | public class Maps2 31 | { 32 | private Maps2() { 33 | // empty 34 | } 35 | 36 | public static Map fromProperties(final Properties properties) { 37 | checkNotNull(properties); 38 | Map result = new HashMap(properties.size()); 39 | Enumeration names = properties.propertyNames(); 40 | while (names.hasMoreElements()) { 41 | String name = (String)names.nextElement(); 42 | result.put(name, properties.getProperty(name)); 43 | } 44 | return result; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/util/MavenVersionHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin.util; 17 | 18 | import java.io.IOException; 19 | import java.io.InputStream; 20 | import java.net.URL; 21 | import java.util.Properties; 22 | 23 | import javax.annotation.Nullable; 24 | 25 | import com.google.common.annotations.VisibleForTesting; 26 | import org.codehaus.plexus.component.annotations.Component; 27 | import org.codehaus.plexus.component.annotations.Requirement; 28 | import org.eclipse.aether.version.Version; 29 | import org.slf4j.Logger; 30 | import org.slf4j.LoggerFactory; 31 | 32 | import static com.google.common.base.Preconditions.checkNotNull; 33 | 34 | /** 35 | * Maven version helper. 36 | * 37 | * @since 2.0 38 | */ 39 | @Component(role = MavenVersionHelper.class) 40 | public class MavenVersionHelper 41 | { 42 | private final Logger log = LoggerFactory.getLogger(getClass()); 43 | 44 | @Requirement 45 | private VersionHelper versionHelper; 46 | 47 | public MavenVersionHelper() {} 48 | 49 | @VisibleForTesting 50 | public MavenVersionHelper(final VersionHelper versionHelper) { 51 | this.versionHelper = checkNotNull(versionHelper); 52 | } 53 | 54 | @Nullable 55 | public Version detectVersion(final ClassLoader classLoader) { 56 | checkNotNull(classLoader); 57 | 58 | log.trace("Detecting Maven version; class-loader: {}", classLoader); 59 | 60 | // TODO: Sort out how compatible this logic is for newer/older versions of maven 61 | 62 | Properties props = readProperties( 63 | classLoader, "org.apache.maven.cli.MavenCli", "/org/apache/maven/messages/build.properties"); 64 | String raw = props.getProperty("version"); 65 | 66 | log.trace("Raw version: {}", raw); 67 | if (raw == null) { 68 | return null; 69 | } 70 | 71 | Version version = versionHelper.parseVersion(raw); 72 | log.trace("Version: {}", version); 73 | return version; 74 | } 75 | 76 | private Properties readProperties(final ClassLoader classLoader, final String className, final String resourceName) { 77 | log.trace("Reading properties; class-loader: {}, class-name: {}, resource-name: {}", 78 | classLoader, className, resourceName); 79 | 80 | Properties props = new Properties(); 81 | try { 82 | Class type = classLoader.loadClass(className); 83 | log.trace("Type: {}", type); 84 | 85 | URL resource = type.getResource(resourceName); 86 | log.trace("Resource: {}", resource); 87 | 88 | if (resource != null) { 89 | InputStream stream = resource.openStream(); 90 | try { 91 | props.load(stream); 92 | } 93 | finally { 94 | stream.close(); 95 | } 96 | } 97 | } 98 | catch (ClassNotFoundException e) { 99 | log.trace("Failed to resolve class", e); 100 | } 101 | catch (IOException e) { 102 | log.trace("Failed to read properties", e); 103 | } 104 | 105 | return props; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/util/PropertiesBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin.util; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Collections; 20 | import java.util.HashMap; 21 | import java.util.List; 22 | import java.util.Map; 23 | import java.util.Map.Entry; 24 | 25 | import javax.annotation.Nullable; 26 | 27 | import org.apache.maven.execution.MavenSession; 28 | import org.apache.maven.project.MavenProject; 29 | import org.codehaus.plexus.component.annotations.Component; 30 | import org.codehaus.plexus.interpolation.InterpolationException; 31 | import org.codehaus.plexus.interpolation.Interpolator; 32 | import org.codehaus.plexus.interpolation.MapBasedValueSource; 33 | import org.codehaus.plexus.interpolation.StringSearchInterpolator; 34 | import org.slf4j.Logger; 35 | import org.slf4j.LoggerFactory; 36 | 37 | /** 38 | * Helper to build merged Maven execution properties. 39 | * 40 | * @since 2.0 41 | */ 42 | @Component(role = PropertiesBuilder.class, instantiationStrategy="per-lookup") 43 | public class PropertiesBuilder 44 | { 45 | private final Logger log = LoggerFactory.getLogger(getClass()); 46 | 47 | private MavenProject project; 48 | 49 | private MavenSession session; 50 | 51 | private Map properties; 52 | 53 | private Map defaults; 54 | 55 | public PropertiesBuilder setProject(final @Nullable MavenProject project) { 56 | this.project = project; 57 | return this; 58 | } 59 | 60 | public PropertiesBuilder setSession(final @Nullable MavenSession session) { 61 | this.session = session; 62 | return this; 63 | } 64 | 65 | public PropertiesBuilder setProperties(final @Nullable Map properties) { 66 | this.properties = properties; 67 | return this; 68 | } 69 | 70 | public PropertiesBuilder setDefaults(final @Nullable Map defaults) { 71 | this.defaults = defaults; 72 | return this; 73 | } 74 | 75 | public Map build() { 76 | Map props = new HashMap(); 77 | if (defaults != null) { 78 | props.putAll(defaults); 79 | } 80 | if (project != null) { 81 | props.putAll(Maps2.fromProperties(project.getProperties())); 82 | } 83 | if (session != null) { 84 | props.putAll(Maps2.fromProperties(session.getSystemProperties())); 85 | props.putAll(Maps2.fromProperties(session.getUserProperties())); 86 | } 87 | if (properties != null) { 88 | props.putAll(properties); 89 | } 90 | 91 | // resolve any dangling references which could exist due to custom properties/defaults 92 | props = resolve(props); 93 | 94 | if (log.isTraceEnabled()) { 95 | log.trace("Properties:"); 96 | List keys = new ArrayList(props.keySet()); 97 | Collections.sort(keys); 98 | for (String key : keys) { 99 | log.trace(" {}={}", key, props.get(key)); 100 | } 101 | } 102 | 103 | return props; 104 | } 105 | 106 | private Map resolve(final Map source) { 107 | Map result = new HashMap(source.size()); 108 | Interpolator interpolator = new StringSearchInterpolator(); 109 | interpolator.addValueSource(new MapBasedValueSource(source)); 110 | 111 | for (Entry entry : source.entrySet()) { 112 | String key = entry.getKey(); 113 | String value = entry.getValue(); 114 | 115 | if (value == null) { 116 | log.warn("Ignoring null property: {}", key); 117 | continue; 118 | } 119 | 120 | // skip unless value contains an expression 121 | if (value.contains(StringSearchInterpolator.DEFAULT_START_EXPR)) { 122 | try { 123 | value = interpolator.interpolate(value); 124 | log.trace("Resolved: {} -> '{}'", key, value); 125 | } 126 | catch (InterpolationException e) { 127 | log.warn("Failed to interpolate: {}, using original value: {}", key, value); 128 | } 129 | } 130 | result.put(key, value); 131 | } 132 | 133 | return result; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/util/VersionHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin.util; 17 | 18 | import com.google.common.annotations.VisibleForTesting; 19 | import com.google.common.base.Throwables; 20 | import org.codehaus.plexus.component.annotations.Component; 21 | import org.eclipse.aether.util.version.GenericVersionScheme; 22 | import org.eclipse.aether.version.InvalidVersionSpecificationException; 23 | import org.eclipse.aether.version.Version; 24 | import org.eclipse.aether.version.VersionRange; 25 | import org.eclipse.aether.version.VersionScheme; 26 | import org.slf4j.Logger; 27 | import org.slf4j.LoggerFactory; 28 | 29 | import static com.google.common.base.Preconditions.checkArgument; 30 | import static com.google.common.base.Preconditions.checkNotNull; 31 | 32 | /** 33 | * Aether version/range/scheme helpers. 34 | * 35 | * @since 2.0 36 | */ 37 | @Component(role = VersionHelper.class) 38 | public class VersionHelper 39 | { 40 | private final Logger log = LoggerFactory.getLogger(getClass()); 41 | 42 | /** 43 | * Earliest suffix to help Aether detect ranges _better_ when SNAPSHOT versions are used. 44 | */ 45 | public static final String EARLIEST_SUFFIX = "alpha-SNAPSHOT"; 46 | 47 | private final VersionScheme versionScheme; 48 | 49 | public VersionHelper() { 50 | this(new GenericVersionScheme()); 51 | } 52 | 53 | @VisibleForTesting 54 | public VersionHelper(final VersionScheme versionScheme) { 55 | this.versionScheme = checkNotNull(versionScheme); 56 | } 57 | 58 | public VersionScheme getScheme() { 59 | return versionScheme; 60 | } 61 | 62 | /** 63 | * Parses a {@link Version} and propagates exceptions. 64 | */ 65 | public Version parseVersion(final String version) { 66 | checkNotNull(version); 67 | try { 68 | return versionScheme.parseVersion(version); 69 | } 70 | catch (InvalidVersionSpecificationException e) { 71 | throw Throwables.propagate(e); 72 | } 73 | } 74 | 75 | /** 76 | * Parses a {@link VersionRange} and propagates exceptions. 77 | */ 78 | public VersionRange parseRange(final String pattern) { 79 | checkNotNull(pattern); 80 | try { 81 | return versionScheme.parseVersionRange(pattern); 82 | } 83 | catch (InvalidVersionSpecificationException e) { 84 | throw Throwables.propagate(e); 85 | } 86 | } 87 | 88 | /** 89 | * Builds a range between version parts and parts[n] + 1. 90 | * 91 | * ie. range(1,2,3) produces a range between versions 1.2.3 and 1.2.4. 92 | */ 93 | public VersionRange range(final int... parts) { 94 | checkNotNull(parts); 95 | checkArgument(parts.length != 0); 96 | 97 | StringBuilder buff = new StringBuilder() 98 | .append("["); 99 | 100 | for (int i = 0; i < parts.length; i++) { 101 | buff.append(parts[i]); 102 | if (i + 1 < parts.length) { 103 | buff.append("."); 104 | } 105 | } 106 | 107 | buff.append(","); 108 | 109 | for (int i = 0; i < parts.length; i++) { 110 | if (i + 1 == parts.length) { 111 | buff.append(parts[i] + 1); 112 | } 113 | else { 114 | buff.append(parts[i]) 115 | .append("."); 116 | } 117 | } 118 | 119 | buff.append(")"); 120 | 121 | log.trace("Range pattern: {}", buff); 122 | 123 | return parseRange(buff.toString()); 124 | } 125 | 126 | /** 127 | * Builds a range before version parts. 128 | */ 129 | public VersionRange before(final int... parts) { 130 | checkNotNull(parts); 131 | checkArgument(parts.length != 0); 132 | 133 | StringBuilder buff = new StringBuilder() 134 | .append("(,"); 135 | 136 | for (int i = 0; i < parts.length; i++) { 137 | buff.append(parts[i]); 138 | if (i + 1 < parts.length) { 139 | buff.append("."); 140 | } 141 | } 142 | 143 | buff.append("-") 144 | .append(EARLIEST_SUFFIX) 145 | .append(")"); 146 | 147 | log.trace("Range pattern: {}", buff); 148 | 149 | return parseRange(buff.toString()); 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/java/org/codehaus/gmaven/plugin/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * GMaven plugin utilities. 18 | * 19 | * @since 2.0 20 | */ 21 | package org.codehaus.gmaven.plugin.util; 22 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/main/resources/META-INF/org.sonatype.gossip/config.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2006-present the original author or authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | version=1.0.0 18 | 19 | profiles=default, gmaven-common, gmaven-logging-debug, gmaven-logging-trace 20 | 21 | ## 22 | ## default 23 | ## 24 | 25 | profile.default.includes=gmaven-common 26 | profile.default.listeners=console 27 | profile.default.listener.console=org.sonatype.gossip.listener.ConsoleListener 28 | profile.default.listener.console.renderer=org.sonatype.gossip.render.PatternRenderer 29 | profile.default.listener.console.renderer.pattern=[%l] %m%n%x 30 | profile.default.logger.*=INFO 31 | 32 | ## 33 | ## Common 34 | ## 35 | 36 | profile.gmaven-common.listeners=console 37 | profile.gmaven-common.listener.console=org.sonatype.gossip.listener.ConsoleListener 38 | profile.gmaven-common.listener.console.renderer=org.sonatype.gossip.render.PatternRenderer 39 | profile.gmaven-common.listener.console.renderer.pattern=[%l] %c - %m%n%x 40 | 41 | ## 42 | ## gmaven.logging=DEBUG 43 | ## 44 | 45 | profile.gmaven-logging-debug.includes=gmaven-common 46 | profile.gmaven-logging-debug.triggers=default 47 | profile.gmaven-logging-debug.trigger.default=org.sonatype.gossip.trigger.SystemPropertyTrigger 48 | profile.gmaven-logging-debug.trigger.default.name=gmaven.logging 49 | profile.gmaven-logging-debug.trigger.default.value=DEBUG 50 | profile.gmaven-logging-debug.trigger.default.ignoreCase=true 51 | profile.gmaven-logging-debug.logger.*=DEBUG 52 | 53 | ## 54 | ## gmaven.logging=TRACE 55 | ## 56 | 57 | profile.gmaven-logging-trace.includes=gmaven-common 58 | profile.gmaven-logging-trace.triggers=default 59 | profile.gmaven-logging-trace.trigger.default=org.sonatype.gossip.trigger.SystemPropertyTrigger 60 | profile.gmaven-logging-trace.trigger.default.name=gmaven.logging 61 | profile.gmaven-logging-trace.trigger.default.value=TRACE 62 | profile.gmaven-logging-trace.trigger.default.ignoreCase=true 63 | profile.gmaven-logging-trace.logger.*=TRACE -------------------------------------------------------------------------------- /groovy-maven-plugin/src/site/markdown/classpath.md: -------------------------------------------------------------------------------- 1 | 18 | # Classpath 19 | 20 | When executing a goal with a Maven project, GMaven can provide access to the classpath of the project for a 21 | particular scope. This is controlled by the `classpathScope` parameter. 22 | 23 | For example, to execute a script and include the `runtime` scope dependencencies on the classpath: 24 | 25 | 26 | org.codehaus.gmaven 27 | groovy-maven-plugin 28 | 29 | 30 | process-classes 31 | 32 | execute 33 | 34 | 35 | runtime 36 | 37 | // this script has access to the compiled classes and all depencencies of scope=runtime. 38 | 39 | 40 | 41 | 42 | 43 | 44 | By default `classpathScope` is set to `none` which means that no additional classpath elements will be available. 45 | 46 | When executing a goal directly without a project, the scope may be configured by setting the `scope` property: 47 | 48 | mvn groovy:shell -Dscope=test 49 | 50 | For all supported values and additional documentation see 51 | [ClasspathScope](apidocs/org/codehaus/gmaven/plugin/ClasspathScope.html). 52 | 53 | Any additional classpath which may be needed can also be configured on the plugin definition: 54 | 55 | 56 | org.codehaus.gmaven 57 | groovy-maven-plugin 58 | 59 | 60 | commons-lang 61 | commons-lang 62 | 2.6 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/site/markdown/console.md: -------------------------------------------------------------------------------- 1 | 18 | # Console 19 | 20 | GMaven supports opening up the GUI [Groovy Console](http://groovy.codehaus.org/Groovy+Console) 21 | with the [console](console-mojo.html) goal: 22 | 23 | mvn groovy:console 24 | 25 | This goal works with and without a project. When a project is available additional [classpath](classpath.html) 26 | configuration options are avaiable. 27 | 28 | All context [variables](variables.html) are availble for use in the console. 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/site/markdown/execute.md: -------------------------------------------------------------------------------- 1 | 18 | # Execute 19 | 20 | Groovy script execution is the main purpose of GMaven and is available with the [execute](execute-mojo.html) goal. 21 | A script can be executed as part of a build (attached to a lifecycle phase) or directly via the command-line. 22 | 23 | This goal is not bound to a [lifecycle phase](http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference) 24 | by default, so the phase must always be configured, and the phase will depend highly on what the purpose is that you are 25 | executing a script for. 26 | 27 | This goal works with and without a project. When a project is available additional [classpath](classpath.html) 28 | configuration options are avaiable. 29 | 30 | All context [variables](variables.html) are availble for use in executed scripts. 31 | 32 | ## Source 33 | 34 | The configuration of the _source_ of the script to execute can be configured to be one of: 35 | 36 | * File 37 | * URL 38 | * Inline 39 | 40 | This value can be specified by the `source` configuration parameter or by the `source` property. 41 | 42 | ### File 43 | 44 | Files can be used, and for most complex usage recommend, as the source of the script to execute: 45 | 46 | 47 | org.codehaus.gmaven 48 | groovy-maven-plugin 49 | 50 | 51 | generate-resources 52 | 53 | execute 54 | 55 | 56 | ${project.basedir}/src/main/script/myscript.groovy 57 | 58 | 59 | 60 | 61 | 62 | or: 63 | 64 | mvn groovy:execute -Dsource=src/main/script/myscript.groovy 65 | 66 | This form only works when the file actually _exists_ and if the file is missing it could cause 67 | GMaven to treat the source as _inline_ instead. 68 | 69 | ### URL 70 | 71 | URL sources allow the script to be resolved by a URL, which can be any URL which the JVM can resolve. 72 | 73 | 74 | org.codehaus.gmaven 75 | groovy-maven-plugin 76 | 77 | 78 | generate-resources 79 | 80 | execute 81 | 82 | 83 | http://mydomain.com/myscript.groovy 84 | 85 | 86 | 87 | 88 | 89 | or: 90 | 91 | mvn groovy:execute -Dsource=http://mydomain.com/myscript.groovy 92 | 93 | ### Inline 94 | 95 | Inline allows scripts to be defined inside of project files. 96 | 97 | 98 | org.codehaus.gmaven 99 | groovy-maven-plugin 100 | 101 | 102 | generate-resources 103 | 104 | execute 105 | 106 | 107 | 108 | println 'Hello' 109 | 110 | 111 | 112 | 113 | 114 | 115 | or: 116 | 117 | mvn groovy:execute -Dsource="println 'Hello'" 118 | 119 | #### Maven interpolation and GStrings 120 | 121 | While this form may be the simplest to use for many cases, there are some pitfalls to be aware of. Specifically 122 | use of [GStrings](http://groovy.codehaus.org/Strings+and+GString) (special String-like constructs available to Groovy), 123 | can cause some unexpected behavior due to Maven interpolation syntax `${}` overloading the GString syntax. 124 | 125 | When Maven loads a project, it very early on, interpolates the content of the POM to replace properties and simple 126 | expressions with string values. This is very common and very handy, but it does provide some complication when 127 | Maven attempts to resolve an expression which was expected to be resolved by a GString. 128 | 129 | Scripts which make heavy use of GStrings should seriously consider using a File-based source configuration to 130 | avoid this potential complication. 131 | 132 | ## Properties and Defaults 133 | 134 | Additional customization of the execution variable `properties` are available for scripts run with `execute`. 135 | 136 | Script executions can have _overriding_ properties by setting the `properties` configuration parameter. 137 | Values set here will take precendence over any other property definition (user, system, project, defaults, etc). 138 | 139 | 140 | org.codehaus.gmaven 141 | groovy-maven-plugin 142 | 143 | 144 | generate-resources 145 | 146 | execute 147 | 148 | 149 | 150 | Xenu 151 | 152 | 153 | println 'Hello ' + properties['name'] 154 | 155 | 156 | 157 | 158 | 159 | 160 | This example will always print `Hello Xenu` even if `mvn -Dname=Steve` or if the project 161 | defined a property of the same name. 162 | 163 | Script executions can also have _default_ properties by setting the `defaults` configuration parameter. 164 | Values set here will only be used if no other property for the same nme definition exists. 165 | 166 | 167 | org.codehaus.gmaven 168 | groovy-maven-plugin 169 | 170 | 171 | generate-resources 172 | 173 | execute 174 | 175 | 176 | 177 | Xenu 178 | 179 | 180 | println 'Hello ' + properties['name'] 181 | 182 | 183 | 184 | 185 | 186 | 187 | Here, with out any other definition of `name`, will print `Hello Xenu`, but if instead was invoked with 188 | `mvn -Dname=Jason` would print `Hello Jason` instead. 189 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/site/markdown/index.md: -------------------------------------------------------------------------------- 1 | 18 | # Groovy Maven Plugin 19 | 20 | See _USAGE_ content for more details. 21 | 22 | ### Hard Requirements 23 | 24 | The Maven and Groovy version requirements are ***hard*** requirements. 25 | 26 | When goals are executing the versions of Maven and Groovy are detected. 27 | If they are not compatible the goals will fail with an error. 28 | 29 | ### Customizing Groovy Version 30 | 31 | To customize the version of Groovy the plugin will use, override the `org.codehaus.groovy:groovy-all` dependency 32 | on the plugin definition in the project. 33 | 34 | For example to use Groovy 2.0.6 instead of the default: 35 | 36 | 37 | org.codehaus.gmaven 38 | groovy-maven-plugin 39 | 40 | 41 | org.codehaus.groovy 42 | groovy-all 43 | 2.0.6 44 | 45 | 46 | 47 | 48 | There is currently no way to change the Groovy version without a project. 49 | Direct execution of goals will always use the default Groovy version if no project is available. When a project 50 | is available, then `pluginManagement` can be used to configure direct goal execution. 51 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/site/markdown/logging.md: -------------------------------------------------------------------------------- 1 | 18 | # Logging 19 | 20 | ## Apache Maven 3.0+ 21 | 22 | GMaven uses SLF4J and uses the [Gossip](https://github.com/jdillon/gossip) provider to allow for simple and 23 | flexible configuration of logging output. 24 | 25 | When running in Apache Maven 3.0.x without any SLF4J customizations, additional GMaven logging can be enabled 26 | by setting the `gmaven.logging` property on the `mvn` command-line. 27 | 28 | To enable `DEBUG` logging: 29 | 30 | mvn -Dgmaven.logging=DEBUG 31 | 32 | To enable `TRACE` logging: 33 | 34 | mvn -Dgmaven.logging=TRACE 35 | 36 | ## Apache Maven 3.1+ 37 | 38 | Apache Maven 3.1.x provides SLF4J bindings [slf4j-simple](http://www.slf4j.org/apidocs/org/slf4j/impl/SimpleLogger.html) 39 | by default and that binding implementation must be configured to enable more verbose logging details. 40 | 41 | To enable logging configuration as described for Apache Maven 3.0+ the 3.1+ distribution needs to be 42 | augmented to replace the default SLF4J binding with Gossip. 43 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/site/markdown/scriptpath.md: -------------------------------------------------------------------------------- 1 | 18 | # Scriptpath 19 | 20 | The `scriptpath` is a path where GMaven will search for additional Groovy sources to resolve when executing a Groovy script. 21 | 22 | This configuration applies to all goals. This means that you can access your external script via the `console` 23 | and `shell` goals as well as `execute`. 24 | 25 | ### Explicit 26 | 27 | For example if you have a class named `Helper` defined in a file named `${project.basedir}/src/main/script/Helper.groovy` 28 | your scripts can use that class if you configure the script path to include `${project.basedir}/src/main/script`: 29 | 30 | 31 | org.codehaus.gmaven 32 | groovy-maven-plugin 33 | 34 | 35 | generate-resources 36 | 37 | execute 38 | 39 | 40 | 41 | ${project.basedir}/src/main/script 42 | 43 | 44 | import Helper 45 | def h = new Helper() 46 | 47 | 48 | 49 | 50 | 51 | 52 | ### Peer 53 | 54 | Additionally if using a file-based source configuration, GMaven will automatically look for 55 | matching classes _nexus to_ the source file. 56 | 57 | So if you had a `${project.basedir}/src/main/script/Main.groovy` with something like: 58 | 59 | import Helper 60 | def h = new Helper() 61 | 62 | ... then this configuration would be sufficent to allow the source file script to access to 63 | `${project.basedir}/src/main/script/Helper.groovy` script: 64 | 65 | 66 | org.codehaus.gmaven 67 | groovy-maven-plugin 68 | 69 | 70 | generate-resources 71 | 72 | execute 73 | 74 | 75 | ${project.basedir}/src/main/script/Main.groovy 76 | 77 | 78 | 79 | 80 | 81 | ### Command-line 82 | 83 | Configure the `scriptpath` property on the mvn command-line with a _comma seperated_ list of entries: 84 | 85 | mvn -Dscriptpath=dir1,dir2,dir3 86 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/site/markdown/shell.md: -------------------------------------------------------------------------------- 1 | 18 | # Shell 19 | 20 | GMaven supports running the command-line [Groovy Shell](http://groovy.codehaus.org/Groovy+Shell) 21 | (aka `groovysh`) with the [shell](shell-mojo.html) goal: 22 | 23 | mvn groovy:shell 24 | 25 | This goal works with and without a project. When a project is available additional [classpath](classpath.html) 26 | configuration options are avaiable. 27 | 28 | All context [variables](variables.html) are availble for use in the shell. 29 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/site/markdown/variables.md.vm: -------------------------------------------------------------------------------- 1 |

Variables

2 | 3 | All goals which invoke the Groovy runtime, expose a set of predefined context (aka binding) variables. 4 | 5 |

Basic

6 | 7 | Basic context variables. 8 | 9 | | Name | Description 10 | | ---------- | ----------- 11 | | project | The currently executing [MavenProject][MavenProject] or if no project, this will be a reference to the generic stub project. 12 | | basedir | [File][File] reference to detected base directory for Maven execution. 13 | | properties | [Properties][Properties] containing merged execution properties. 14 | | ant | Preconfigured [AntBuilder][AntBuilder]. 15 | | fail | Closure to help fail execution. See [FailClosureTarget][FailClosureTarget] for supported syntax and usage. 16 | | log | SLF4J [Logger][Logger]. 17 | 18 |

Advanced

19 | 20 | Advanced context variables. 21 | 22 | | Name | Description 23 | | ------------- | ----------- 24 | | container | [ContainerHelper][ContainerHelper] to simplify looking up Maven components. 25 | | plugin | `groovy-maven-plugin` [PluginDescriptor][PluginDescriptor]. 26 | | pluginContext | Plugin context [Map][Map] to allow communication between plugin goals. See [ContextEnabled][ContextEnabled] for more details. 27 | | mojo | The current [MojoExecution][MojoExecution]. 28 | | session | The current [MavenSession][MavenSession]. 29 | | settings | The current [Settings][Settings]. 30 | 31 | [File]: ${site_javaApidocsUrl}/java/io/File.html 32 | [Properties]: ${site_javaApidocsUrl}/java/util/Properties.html 33 | [Map]: ${site_javaApidocsUrl}/java/util/Map.html 34 | [FailClosureTarget]: apidocs/org/codehaus/gmaven/plugin/FailClosureTarget.html 35 | [ContainerHelper]: apidocs/org/codehaus/gmaven/plugin/util/ContainerHelper.html 36 | [MavenProject]: ${site_mavenApidocsUrl}/org/apache/maven/project/MavenProject.html 37 | [AntBuilder]: ${site_groovyApidocsUrl}/groovy/util/AntBuilder.html 38 | [PluginDescriptor]: ${site_mavenApidocsUrl}/org/apache/maven/plugin/descriptor/PluginDescriptor.html 39 | [ContextEnabled]: ${site_mavenApidocsUrl}/org/apache/maven/plugin/ContextEnabled.html 40 | [MojoExecution]: ${site_mavenApidocsUrl}/org/apache/maven/plugin/MojoExecution.html 41 | [MavenSession]: ${site_mavenApidocsUrl}/org/apache/maven/execution/MavenSession.html 42 | [Settings]: ${site_mavenApidocsUrl}/org/apache/maven/settings/Settings.html 43 | [Logger]: http://www.slf4j.org/apidocs/org/slf4j/Logger.html -------------------------------------------------------------------------------- /groovy-maven-plugin/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/test/java/org/codehaus/gmaven/plugin/ClassSourceFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin; 17 | 18 | import java.io.File; 19 | import java.net.URL; 20 | 21 | import org.sonatype.sisu.litmus.testsupport.TestSupport; 22 | 23 | import org.codehaus.gmaven.adapter.ClassSource; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | 27 | import static org.hamcrest.Matchers.is; 28 | import static org.hamcrest.Matchers.notNullValue; 29 | import static org.hamcrest.Matchers.nullValue; 30 | import static org.junit.Assert.assertThat; 31 | 32 | /** 33 | * Tests for {@link ClassSourceFactory}. 34 | */ 35 | public class ClassSourceFactoryTest 36 | extends TestSupport 37 | { 38 | private ClassSourceFactory underTest; 39 | 40 | @Before 41 | public void setUp() throws Exception { 42 | underTest = new ClassSourceFactory(); 43 | } 44 | 45 | private String whitespace(final String text) { 46 | return "\n\t " + text + "\n\t "; 47 | } 48 | 49 | private void assertUrl(final String url) throws Exception { 50 | ClassSource source = underTest.create(url); 51 | log(source); 52 | 53 | assertThat(source, notNullValue()); 54 | assertThat(source.getUrl(), notNullValue()); 55 | assertThat(source.getFile(), nullValue()); 56 | assertThat(source.getInline(), nullValue()); 57 | 58 | assertThat(source.getUrl(), is(new URL(url))); 59 | } 60 | 61 | @Test 62 | public void create_url() throws Exception { 63 | assertUrl("http://google.com"); 64 | } 65 | 66 | @Test 67 | public void create_url_withWhitespace() throws Exception { 68 | assertUrl(whitespace("http://google.com")); 69 | } 70 | 71 | private void assertFile(final String path) throws Exception { 72 | ClassSource source = underTest.create(path); 73 | log(source); 74 | 75 | assertThat(source, notNullValue()); 76 | assertThat(source.getUrl(), nullValue()); 77 | assertThat(source.getFile(), notNullValue()); 78 | assertThat(source.getInline(), nullValue()); 79 | 80 | assertThat(source.getFile(), is(new File(path.trim()))); 81 | } 82 | 83 | @Test 84 | public void create_file() throws Exception { 85 | assertFile(util.createTempFile().getPath()); 86 | } 87 | 88 | @Test 89 | public void create_file_withWhitespace() throws Exception { 90 | assertFile(whitespace(util.createTempFile().getPath())); 91 | } 92 | 93 | // FIXME: This test will not pass as current logic treats non-existing files as inline-sources 94 | 95 | //@Test 96 | //public void create_file_nonExisting() throws Exception { 97 | // File file = util.createTempFile(); 98 | // file.delete(); 99 | // assertFile(file.getPath()); 100 | //} 101 | 102 | private void assertInline(final String script) throws Exception { 103 | ClassSource source = underTest.create(script); 104 | log(source); 105 | 106 | assertThat(source, notNullValue()); 107 | assertThat(source.getUrl(), nullValue()); 108 | assertThat(source.getFile(), nullValue()); 109 | assertThat(source.getInline(), notNullValue()); 110 | 111 | // keep IDEA happy 112 | assert source.getInline() != null; 113 | 114 | assertThat(source.getInline().getName(), notNullValue()); 115 | assertThat(source.getInline().getCodeBase(), notNullValue()); 116 | assertThat(source.getInline().getInput(), notNullValue()); 117 | } 118 | 119 | @Test 120 | public void create_inline() throws Exception { 121 | assertInline("println 1234"); 122 | } 123 | 124 | @Test 125 | public void create_inline_withWhitespace() throws Exception { 126 | assertInline(whitespace("println 1234")); 127 | } 128 | 129 | @Test 130 | public void create_inlineIncrementsCounter() { 131 | ClassSourceFactory.scriptCounter.set(0); 132 | 133 | underTest.create("println 1234"); 134 | assertThat(ClassSourceFactory.scriptCounter.get(), is(1)); 135 | 136 | underTest.create("println 5678"); 137 | assertThat(ClassSourceFactory.scriptCounter.get(), is(2)); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/test/java/org/codehaus/gmaven/plugin/ClasspathScopeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin; 17 | 18 | import org.sonatype.sisu.litmus.testsupport.TestSupport; 19 | 20 | import org.junit.Test; 21 | 22 | import static org.codehaus.gmaven.plugin.ClasspathScope.compile; 23 | import static org.codehaus.gmaven.plugin.ClasspathScope.none; 24 | import static org.codehaus.gmaven.plugin.ClasspathScope.provided; 25 | import static org.codehaus.gmaven.plugin.ClasspathScope.runtime; 26 | import static org.codehaus.gmaven.plugin.ClasspathScope.test; 27 | import static org.hamcrest.Matchers.is; 28 | import static org.junit.Assert.assertThat; 29 | 30 | /** 31 | * Tests for {@link ClasspathScope}. 32 | */ 33 | public class ClasspathScopeTest 34 | extends TestSupport 35 | { 36 | @Test 37 | public void matches_none() { 38 | ClasspathScope value = none; 39 | assertThat(value.matches(none), is(true)); 40 | assertThat(value.matches(provided), is(false)); 41 | assertThat(value.matches(compile), is(false)); 42 | assertThat(value.matches(runtime), is(false)); 43 | assertThat(value.matches(test), is(false)); 44 | } 45 | 46 | @Test 47 | public void matches_provided() { 48 | ClasspathScope value = provided; 49 | assertThat(value.matches(none), is(false)); 50 | assertThat(value.matches(provided), is(true)); 51 | assertThat(value.matches(compile), is(false)); 52 | assertThat(value.matches(runtime), is(false)); 53 | assertThat(value.matches(test), is(false)); 54 | } 55 | 56 | @Test 57 | public void matches_compile() { 58 | ClasspathScope value = compile; 59 | assertThat(value.matches(none), is(false)); 60 | assertThat(value.matches(provided), is(true)); 61 | assertThat(value.matches(compile), is(true)); 62 | assertThat(value.matches(runtime), is(false)); 63 | assertThat(value.matches(test), is(false)); 64 | } 65 | 66 | @Test 67 | public void matches_runtime() { 68 | ClasspathScope value = runtime; 69 | assertThat(value.matches(none), is(false)); 70 | assertThat(value.matches(provided), is(true)); 71 | assertThat(value.matches(compile), is(true)); 72 | assertThat(value.matches(runtime), is(true)); 73 | assertThat(value.matches(test), is(false)); 74 | } 75 | 76 | @Test 77 | public void matches_test() { 78 | ClasspathScope value = test; 79 | assertThat(value.matches(none), is(false)); 80 | assertThat(value.matches(provided), is(true)); 81 | assertThat(value.matches(compile), is(true)); 82 | assertThat(value.matches(runtime), is(true)); 83 | assertThat(value.matches(test), is(true)); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/test/java/org/codehaus/gmaven/plugin/FailClosureTargetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin; 17 | 18 | import org.sonatype.sisu.litmus.testsupport.TestSupport; 19 | 20 | import org.apache.maven.plugin.MojoExecutionException; 21 | import org.junit.Before; 22 | import org.junit.Test; 23 | 24 | import static org.hamcrest.Matchers.is; 25 | import static org.hamcrest.Matchers.nullValue; 26 | import static org.junit.Assert.assertThat; 27 | 28 | /** 29 | * Tests for {@link FailClosureTarget}. 30 | */ 31 | public class FailClosureTargetTest 32 | extends TestSupport 33 | { 34 | private FailClosureTarget underTest; 35 | 36 | @Before 37 | public void setUp() throws Exception { 38 | underTest = new FailClosureTarget(); 39 | } 40 | 41 | @Test 42 | public void fail_null() throws Exception { 43 | try { 44 | underTest.call(null); 45 | } 46 | catch (MojoExecutionException e) { 47 | assertThat(e.getMessage(), is(FailClosureTarget.FAILED)); 48 | } 49 | } 50 | 51 | @Test 52 | public void fail_noArgs() throws Exception { 53 | try { 54 | underTest.call(new Object[0]); 55 | } 56 | catch (MojoExecutionException e) { 57 | assertThat(e.getMessage(), is(FailClosureTarget.FAILED)); 58 | } 59 | } 60 | 61 | @Test 62 | public void fail_object() throws Exception { 63 | try { 64 | underTest.call(new Object[]{"foo"}); 65 | } 66 | catch (MojoExecutionException e) { 67 | assertThat(e.getMessage(), is("foo")); 68 | assertThat(e.getCause(), nullValue()); 69 | } 70 | } 71 | 72 | @Test 73 | public void fail_throwable() throws Exception { 74 | @SuppressWarnings("ThrowableInstanceNeverThrown") 75 | Throwable cause = new Throwable("foo"); 76 | try { 77 | underTest.call(new Object[]{cause}); 78 | } 79 | catch (MojoExecutionException e) { 80 | assertThat(e.getMessage(), is("foo")); 81 | assertThat(e.getCause(), is(cause)); 82 | } 83 | } 84 | 85 | @Test 86 | public void fail_objectAndThrowable() throws Exception { 87 | @SuppressWarnings("ThrowableInstanceNeverThrown") 88 | Throwable cause = new Throwable("bar"); 89 | try { 90 | underTest.call(new Object[]{"foo", cause}); 91 | } 92 | catch (MojoExecutionException e) { 93 | assertThat(e.getMessage(), is("foo")); 94 | assertThat(e.getCause(), is(cause)); 95 | } 96 | } 97 | 98 | /** 99 | * 2-arg form, 2nd arg must be a Throwable. 100 | */ 101 | @Test(expected = Error.class) 102 | public void fail_invalidArgs() throws Exception { 103 | underTest.call(new Object[]{1, 2}); 104 | } 105 | 106 | /** 107 | * more than 2 args is not supported. 108 | */ 109 | @Test(expected = Error.class) 110 | public void fail_tooManyArgs() throws Exception { 111 | underTest.call(new Object[]{1, 2, 3}); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/test/java/org/codehaus/gmaven/plugin/GroovyRuntimeFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin; 17 | 18 | import java.util.ArrayList; 19 | import java.util.Iterator; 20 | import java.util.List; 21 | 22 | import org.sonatype.sisu.litmus.testsupport.TestSupport; 23 | 24 | import org.codehaus.gmaven.adapter.GroovyRuntime; 25 | import org.junit.Before; 26 | import org.junit.Test; 27 | import org.mockito.Mock; 28 | 29 | import static org.hamcrest.Matchers.notNullValue; 30 | import static org.junit.Assert.assertThat; 31 | import static org.junit.Assert.fail; 32 | import static org.mockito.Mockito.mock; 33 | 34 | /** 35 | * Tests for {@link GroovyRuntimeFactory}. 36 | * 37 | * These tests assume that the underlying {@link java.util.ServiceLoader} functions, 38 | * so we by-pass it and only validate the handling around the loader. 39 | */ 40 | public class GroovyRuntimeFactoryTest 41 | extends TestSupport 42 | { 43 | private GroovyRuntimeFactory underTest; 44 | 45 | @Mock 46 | private ClassLoader classLoader; 47 | 48 | private List services; 49 | 50 | @Before 51 | public void setUp() throws Exception { 52 | services = new ArrayList(); 53 | 54 | underTest = new GroovyRuntimeFactory() 55 | { 56 | @Override 57 | protected Iterator findServices(final ClassLoader classLoader) { 58 | return services.iterator(); 59 | } 60 | }; 61 | } 62 | 63 | /** 64 | * If no service is found, ISE should be thrown. 65 | */ 66 | @Test(expected = IllegalStateException.class) 67 | public void create_noServices() { 68 | underTest.create(classLoader); 69 | fail(); 70 | } 71 | 72 | /** 73 | * If more than one service is found, ISE should be thrown. 74 | */ 75 | @Test(expected = IllegalStateException.class) 76 | public void create_multipuleServices() { 77 | services.add(mock(GroovyRuntime.class)); 78 | services.add(mock(GroovyRuntime.class)); 79 | underTest.create(classLoader); 80 | fail(); 81 | } 82 | 83 | /** 84 | * Single service should return non-null value. 85 | */ 86 | @Test 87 | public void create_singleService() { 88 | services.add(mock(GroovyRuntime.class)); 89 | GroovyRuntime runtime = underTest.create(classLoader); 90 | assertThat(runtime, notNullValue()); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/test/java/org/codehaus/gmaven/plugin/MojoSupportTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin; 17 | 18 | import java.util.concurrent.atomic.AtomicInteger; 19 | 20 | import org.sonatype.sisu.litmus.testsupport.TestSupport; 21 | 22 | import org.apache.maven.plugin.MojoExecutionException; 23 | import org.apache.maven.plugin.MojoFailureException; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | 27 | import static org.hamcrest.Matchers.instanceOf; 28 | import static org.hamcrest.Matchers.is; 29 | import static org.junit.Assert.assertThat; 30 | import static org.junit.Assert.fail; 31 | 32 | /** 33 | * Tests for {@link MojoSupport}. 34 | */ 35 | public class MojoSupportTest 36 | extends TestSupport 37 | { 38 | private AtomicInteger prepareCount = new AtomicInteger(0); 39 | 40 | private AtomicInteger runCount = new AtomicInteger(0); 41 | 42 | private AtomicInteger cleanupCount = new AtomicInteger(0); 43 | 44 | private class MojoSupportTester 45 | extends MojoSupport 46 | { 47 | @Override 48 | protected void prepare() throws Exception { 49 | prepareCount.incrementAndGet(); 50 | } 51 | 52 | @Override 53 | protected void run() throws Exception { 54 | runCount.incrementAndGet(); 55 | } 56 | 57 | @Override 58 | protected void cleanup() throws Exception { 59 | cleanupCount.incrementAndGet(); 60 | } 61 | } 62 | 63 | @Before 64 | public void setUp() throws Exception { 65 | prepareCount.set(0); 66 | runCount.set(0); 67 | cleanupCount.set(0); 68 | } 69 | 70 | @Test 71 | public void execute_prepare_run_cleanup() throws Exception { 72 | MojoSupport underTest = new MojoSupportTester(); 73 | 74 | underTest.execute(); 75 | 76 | assertThat(prepareCount.get(), is(1)); 77 | assertThat(runCount.get(), is(1)); 78 | assertThat(cleanupCount.get(), is(1)); 79 | } 80 | 81 | @Test 82 | public void execute_prepareExceptionCallsCleanup() throws Exception { 83 | MojoSupport underTest = new MojoSupportTester() 84 | { 85 | @Override 86 | protected void prepare() throws Exception { 87 | throw new Exception("fail"); 88 | } 89 | }; 90 | 91 | try { 92 | underTest.execute(); 93 | fail(); 94 | } 95 | catch (Exception e) { 96 | // expected 97 | } 98 | 99 | assertThat(runCount.get(), is(0)); 100 | assertThat(cleanupCount.get(), is(1)); 101 | } 102 | 103 | @Test 104 | public void execute_runExceptionCallsCleanup() throws Exception { 105 | MojoSupport underTest = new MojoSupportTester() 106 | { 107 | @Override 108 | protected void run() throws Exception { 109 | throw new Exception("fail"); 110 | } 111 | }; 112 | 113 | try { 114 | underTest.execute(); 115 | fail(); 116 | } 117 | catch (Exception e) { 118 | // expected 119 | } 120 | 121 | assertThat(prepareCount.get(), is(1)); 122 | assertThat(cleanupCount.get(), is(1)); 123 | } 124 | 125 | @Test 126 | public void execute_MojoExecutionException_propagates() throws Exception { 127 | MojoSupport underTest = new MojoSupportTester() 128 | { 129 | @Override 130 | protected void run() throws Exception { 131 | throw new MojoExecutionException("fail"); 132 | } 133 | }; 134 | 135 | try { 136 | underTest.execute(); 137 | fail(); 138 | } 139 | catch (Exception e) { 140 | assertThat(e, instanceOf(MojoExecutionException.class)); 141 | } 142 | } 143 | 144 | @Test 145 | public void execute_MojoFailureException_propagates() throws Exception { 146 | MojoSupport underTest = new MojoSupportTester() 147 | { 148 | @Override 149 | protected void run() throws Exception { 150 | throw new MojoFailureException("fail"); 151 | } 152 | }; 153 | 154 | try { 155 | underTest.execute(); 156 | fail(); 157 | } 158 | catch (Exception e) { 159 | assertThat(e, instanceOf(MojoFailureException.class)); 160 | } 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/test/java/org/codehaus/gmaven/plugin/util/Maps2Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin.util; 17 | 18 | import java.util.Enumeration; 19 | import java.util.Map; 20 | import java.util.Properties; 21 | 22 | import org.sonatype.sisu.litmus.testsupport.TestSupport; 23 | 24 | import com.google.common.collect.ImmutableList; 25 | import com.google.common.collect.Iterators; 26 | import org.junit.Test; 27 | 28 | import static org.hamcrest.Matchers.hasEntry; 29 | import static org.junit.Assert.assertThat; 30 | 31 | /** 32 | * {@link Maps2} tests. 33 | */ 34 | public class Maps2Test 35 | extends TestSupport 36 | { 37 | @Test 38 | public void fromProperties_entryWithNullValue() throws Exception { 39 | Properties props1 = new Properties() { 40 | @Override 41 | public Enumeration propertyNames() { 42 | return Iterators.asEnumeration(ImmutableList.of("foo").iterator()); 43 | } 44 | 45 | @Override 46 | public String getProperty(final String key) { 47 | if ("foo".equals(key)) { 48 | return null; 49 | } 50 | return super.getProperty(key); 51 | } 52 | }; 53 | Map props2 = Maps2.fromProperties(props1); 54 | assertThat(props2, hasEntry("foo", null)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/test/java/org/codehaus/gmaven/plugin/util/PropertiesBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin.util; 17 | 18 | import java.util.Map; 19 | 20 | import org.sonatype.sisu.litmus.testsupport.TestSupport; 21 | 22 | import com.google.common.collect.ImmutableMap; 23 | import org.junit.Before; 24 | import org.junit.Test; 25 | 26 | import static org.hamcrest.Matchers.hasEntry; 27 | import static org.junit.Assert.assertThat; 28 | 29 | /** 30 | * Tests for {@link PropertiesBuilder}. 31 | */ 32 | public class PropertiesBuilderTest 33 | extends TestSupport 34 | { 35 | private PropertiesBuilder underTest; 36 | 37 | @Before 38 | public void setUp() throws Exception { 39 | underTest = new PropertiesBuilder(); 40 | } 41 | 42 | @Test 43 | public void defaults_used() throws Exception { 44 | underTest.setDefaults(ImmutableMap.of("foo", "bar")); 45 | underTest.setProperties(ImmutableMap.of("baz", "ick")); 46 | Map props = underTest.build(); 47 | 48 | assertThat(props, hasEntry("foo", "bar")); 49 | } 50 | 51 | @Test 52 | public void properties_overrideDefaults() throws Exception { 53 | underTest.setDefaults(ImmutableMap.of("foo", "bar")); 54 | underTest.setProperties(ImmutableMap.of("foo", "baz")); 55 | Map props = underTest.build(); 56 | 57 | assertThat(props, hasEntry("foo", "baz")); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /groovy-maven-plugin/src/test/java/org/codehaus/gmaven/plugin/util/VersionHelperTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-present the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.codehaus.gmaven.plugin.util; 17 | 18 | import org.sonatype.sisu.litmus.testsupport.TestSupport; 19 | 20 | import org.eclipse.aether.version.VersionRange; 21 | import org.junit.Before; 22 | import org.junit.Test; 23 | 24 | import static org.hamcrest.Matchers.is; 25 | import static org.junit.Assert.assertThat; 26 | 27 | /** 28 | * Tests for {@link VersionHelper}. 29 | */ 30 | public class VersionHelperTest 31 | extends TestSupport 32 | { 33 | private VersionHelper underTest; 34 | 35 | @Before 36 | public void setUp() throws Exception { 37 | underTest = new VersionHelper(); 38 | } 39 | 40 | @Test 41 | public void range() { 42 | VersionRange range = underTest.range(1, 2, 3); 43 | log(range); 44 | assertThat(range.toString(), is("[1.2.3,1.2.4)")); 45 | } 46 | 47 | @Test 48 | public void before() { 49 | VersionRange range = underTest.before(1, 2, 3); 50 | log(range); 51 | assertThat(range.toString(), is("(,1.2.3-" + VersionHelper.EARLIEST_SUFFIX + ")")); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /header.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) ${project.inceptionYear}-present the original author or authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" 124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( 125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | echo Found %WRAPPER_JAR% 132 | ) else ( 133 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 134 | echo Downloading from: %DOWNLOAD_URL% 135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" 136 | echo Finished downloading %WRAPPER_JAR% 137 | ) 138 | @REM End of extension 139 | 140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 141 | if ERRORLEVEL 1 goto error 142 | goto end 143 | 144 | :error 145 | set ERROR_CODE=1 146 | 147 | :end 148 | @endlocal & set ERROR_CODE=%ERROR_CODE% 149 | 150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 154 | :skipRcPost 155 | 156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 158 | 159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 160 | 161 | exit /B %ERROR_CODE% 162 | -------------------------------------------------------------------------------- /src/site/markdown/index.md: -------------------------------------------------------------------------------- 1 | 18 | # GMaven 19 | 20 | 21 | 22 | [Groovy](http://groovy.codehaus.org) integration for [Apache Maven](http://maven.apache.org). 23 | 24 | ## Supported Environments 25 | 26 | * Java 1.6+ 27 | * Groovy 2.0+ 28 | * Groovy 2.1+ 29 | * Apache Maven 3.0+ 30 | * Apache Maven 3.1+ 31 | 32 | ## Features 33 | 34 | * Script execution 35 | * GUI console access 36 | * Command-line shell access 37 | 38 | For more details please see the [groovy-maven-plugin](groovy-maven-plugin/index.html) documentation. 39 | 40 | ## No Compilation Support 41 | 42 | GMaven 2.x no longer supports any integration for compilation of Groovy sources. There were too many problems with 43 | stub-generation and hooking up compliation to the proper Maven lifecycle phases to effectivly support. 44 | 45 | For compliation integration with Maven please see the 46 | [Groovy Eclipse Compiler](https://github.com/groovy/groovy-eclipse/wiki/Groovy-Eclipse-Maven-plugin), 47 | which is the recommended and prefered option. If any problems are discovered with the compiler please 48 | [report an issue](https://github.com/groovy/groovy-eclipse/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc). 49 | 50 | As a fallback the [Groovy ant tasks](http://groovy.codehaus.org/Compiling+With+Maven2) can also be used 51 | if for some reason the prefered option is not viable for the target environment. 52 | -------------------------------------------------------------------------------- /src/site/publish.groovy: -------------------------------------------------------------------------------- 1 | // 2 | // Helper to checkout, update, commit and push Maven-generated site content for GH-Pages. 3 | // 4 | 5 | // FIXME: ATM only supports github SSH repository urls 6 | // TODO: allow configuration to be passed in from pom 7 | 8 | boolean dryRun = Boolean.parseBoolean(properties.getProperty('dryRun', 'false')) 9 | log.info "Dry run: $dryRun" 10 | 11 | def siteUrl = project?.distributionManagement?.site?.url 12 | log.info "Site URL: $siteUrl" 13 | assert siteUrl 14 | 15 | def gitRepository = siteUrl - 'scm:git:ssh://git@github.com/' 16 | log.info "GIT repository: $gitRepository" 17 | 18 | def gitUrl = "git@github.com:$gitRepository" 19 | log.info "GIT URL: $gitUrl" 20 | 21 | def gitBranch = properties.getProperty('gitBranch', 'gh-pages') 22 | log.info "GIT Branch: $gitBranch" 23 | 24 | def targetDir = new File(project.build.directory as String) 25 | log.info "Target directory: $targetDir" 26 | 27 | def stagingDir = new File(targetDir, 'staging') 28 | log.info "Staging directory: $stagingDir" 29 | assert stagingDir.exists() 30 | 31 | def checkoutDir = new File(targetDir, 'publish-checkout') 32 | log.info "Checkout directory: $checkoutDir" 33 | if (checkoutDir.exists()) { 34 | ant.delete(dir: checkoutDir) 35 | } 36 | ant.mkdir(dir: checkoutDir) 37 | 38 | // helper to run a task surrounded by snippet markers 39 | def snippet = { Closure task -> 40 | println '----8<----' 41 | task.run() 42 | println '---->8----' 43 | } 44 | 45 | log.info "Cloning $gitUrl ($gitBranch branch) to: $checkoutDir" 46 | snippet { 47 | ant.exec(executable: 'git', dir: checkoutDir) { 48 | arg(value: 'clone') 49 | arg(value: '--branch') 50 | arg(value: gitBranch) 51 | arg(value: gitUrl) 52 | arg(value: '.') 53 | } 54 | } 55 | 56 | log.info "Removing existing content from $checkoutDir" 57 | ant.exec(executable: 'git', dir: checkoutDir, failonerror: true) { 58 | arg(value: 'rm') 59 | arg(value: '-r') 60 | arg(value: '--quiet') 61 | arg(value: '.') 62 | } 63 | 64 | log.info "Copying generated content to: $checkoutDir" 65 | ant.copy(todir: checkoutDir) { 66 | fileset(dir: stagingDir) { 67 | include(name: '**') 68 | } 69 | } 70 | 71 | log.info 'Adding changed files' 72 | ant.exec(executable: 'git', dir: checkoutDir, failonerror: true) { 73 | arg(value: 'add') 74 | arg(value: '.') 75 | } 76 | 77 | log.info 'Checking status' 78 | ant.exec(executable: 'git', dir: checkoutDir, failonerror: true, outputproperty: 'git-status') { 79 | arg(value: 'status') 80 | arg(value: '--short') 81 | } 82 | def status = ant.project.properties.'git-status'.trim() 83 | 84 | if (status) { 85 | snippet { println status } 86 | 87 | log.info 'Committing changes' 88 | snippet { 89 | ant.exec(executable: 'git', dir: checkoutDir, failonerror: true) { 90 | arg(value: 'commit') 91 | arg(value: '-m') 92 | arg(value: 'Maven-generated site content refresh') 93 | } 94 | } 95 | 96 | if (!dryRun) { 97 | log.info 'Pushing changes' 98 | snippet { 99 | ant.exec(executable: 'git', dir: checkoutDir, failonerror: true) { 100 | arg(value: 'push') 101 | arg(value: 'origin') 102 | arg(value: gitBranch) 103 | } 104 | } 105 | } 106 | } 107 | else { 108 | log.info 'No changes detected' 109 | } 110 | 111 | log.info 'Done' 112 | -------------------------------------------------------------------------------- /src/site/resources/images/gmaven.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/groovy/gmaven/b5fa664ecea354548d039d39e04011a44e6f5f4c/src/site/resources/images/gmaven.png -------------------------------------------------------------------------------- /src/site/resources/images/groovy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/groovy/gmaven/b5fa664ecea354548d039d39e04011a44e6f5f4c/src/site/resources/images/groovy.png -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 22 | 23 | gmaven 24 | GMaven 25 | http://groovy.github.io/gmaven/images/gmaven.png 26 | http://groovy.github.io/gmaven 27 | 28 | 29 | 30 | org.apache.maven.skins 31 | maven-fluido-skin 32 | 1.7 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | false 41 | true 42 | 43 | groovy/gmaven 44 | right 45 | green 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | --------------------------------------------------------------------------------