Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2011 the original author or authors.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.codehaus.gmavenplus.mojo;
 
 
 import java.io.File;
 import java.util.List;


The base mojo class, which all other mojos extend.

Author(s):
Keegan Witt
 
 public abstract class AbstractGroovyMojo extends AbstractMojo {

    
The pattern defining Groovy files.
 
     protected static final String GROOVY_SOURCES_PATTERN = "**" + . + "*.groovy";

    
The pattern defining Java stub files.
 
     protected static final String JAVA_SOURCES_PATTERN = "**" + . + "*.java";

    
The Maven project this plugin is being used on.

Parameter:
property="project"
Required:
Readonly:
 
     protected MavenProject project;

    
The Maven Session this plugin is being used on.

Parameter:
property="session"
Required:
Readonly:
 
     protected MavenSession session;

    
The Maven Settings.

Parameter:
property="settings"
Required:
Readonly:
 
     protected Settings settings;

    
The plugin dependencies.

Parameter:
property="plugin.artifacts"
Required:
Readonly:
 
     protected List<ArtifactpluginArtifacts;

    
The local repository.

Parameter:
property="localRepository"
Required:
Readonly:
 
     protected ArtifactRepository localRepository;

    
The reactor projects.

Parameter:
property="reactorProjects"
Required:
Readonly:
    protected List<MavenProjectreactorProjects;

    
Logs the version of groovy used by this mojo.

Parameters:
goal The goal to mention in the log statement showing Groovy version
    protected void logGroovyVersion(final String goal) {
        if (getLog().isInfoEnabled()) {
            String logMessage = "Using Groovy " + getGroovyVersion();
            if (isGroovyIndy()) {
                logMessage += "-indy";
            }
            getLog().info(logMessage + " from project compile classpath to perform " + goal + ".");
        }
    }

    
Gets the version string of Groovy used from the dependency information.

Returns:
The version string of Groovy used by the project
    protected String getGroovyVersionString() {
        String groovyVersion = null;
        /*
         * You can call InvokerHelper.getVersion() for versions 1.0 - 1.8.x but
         * not for 1.9+.
         * You can call GroovySystem.getVersion() for versions 1.6.6+.
         * And for some reason InvokerHelper.getVersion() was returning an empty
         * String for 1.5.0, so I decided to just get it from the dependency itself.
         */
        Artifact groovyDependency = getGroovyDependency();
        if (groovyDependency == null) {
            getLog().warn("Unable to determine Groovy version.  Is Groovy declared as a dependency?");
        } else {
            groovyVersion = groovyDependency.getVersion();
        }
        return groovyVersion;
    }

    
Gets the version of Groovy used from the dependency information.

Returns:
The version of Groovy used by the project
    protected Version getGroovyVersion() {
        try {
            return Version.parseFromString(getGroovyVersionString());
        } catch (Exception e) {
            getLog().warn("Unable to determine Groovy version.  Is Groovy declared as a dependency?");
            return null;
        }
    }

    
Gets the version of Groovy used from the dependency information.

Returns:
true if the version of Groovy uses InvokeDynamic, false if not or Groovy dependency cannot be found.
    protected boolean isGroovyIndy() {
        boolean isGroovyIndy = false;
        Artifact groovyDependency = getGroovyDependency();
        if (groovyDependency == null) {
            getLog().warn("Unable to determine Groovy version.  Is Groovy declared as a dependency?");
        } else if ("indy".equals(groovyDependency.getClassifier())) {
            isGroovyIndy = true;
        }
        return isGroovyIndy;
    }

    
Gets the Groovy dependency used by the project.

Returns:
The Groovy dependency used by the project
    protected Artifact getGroovyDependency() {
        Artifact groovyDependency = null;
        if ( != null) {
            for (Object art : ) {
                Artifact artifact = (Artifactart;
                if (isGroovyGroupId(artifact) && isGroovyArtifactId(artifact) && artifact.getType().equals("jar")) {
                    groovyDependency = artifact;
                    break;
                }
            }
        }
        if (groovyDependency == null && .getCompileDependencies() != null) {
            for (Object dep : .getCompileDependencies()) {
                Dependency dependency = (Dependencydep;
                if (isGroovyGroupId(dependency) && isGroovyArtifactId(dependency) && dependency.getType().equals("jar")) {
                    groovyDependency = new DefaultArtifact(dependency.getGroupId(), dependency.getArtifactId(), VersionRange.createFromVersion(dependency.getVersion()), dependency.getScope(), dependency.getType(), dependency.getClassifier() != null ? dependency.getClassifier() : ""null);
                    break;
                }
            }
        }
        return groovyDependency;
    }

    
Whether the groupId of the dependency is Groovy's groupId.

Parameters:
dependency The dependency to inspect
Returns:
true if the dependency's groupId is a Groovy groupId, false otherwise
    protected boolean isGroovyGroupId(final Dependency dependency) {
        return dependency.getGroupId().equals("org.codehaus.groovy") || dependency.getGroupId().equals("groovy");
    }

    
Whether the artifactId of the dependency is Groovy's artifactId.

Parameters:
dependency The dependency to inspect
Returns:
true if the dependency's groupId is a Groovy groupId, false otherwise
    protected boolean isGroovyArtifactId(final Dependency dependency) {
        return dependency.getArtifactId().equals("groovy-all") || dependency.getArtifactId().equals("groovy-all-minimal")
                                    || dependency.getArtifactId().equals("groovy") || dependency.getArtifactId().equals("groovy-all-jdk14")
                                    || dependency.getArtifactId().equals("groovy-jdk14");
    }


    
Whether the groupId of the dependency is Groovy's groupId.

Parameters:
artifact The dependency to inspect
Returns:
true if the dependency's groupId is a Groovy groupId, false otherwise
    protected boolean isGroovyGroupId(final Artifact artifact) {
        return artifact.getGroupId().equals("org.codehaus.groovy") || artifact.getGroupId().equals("groovy");
    }

    
Whether the artifactId of the dependency is Groovy's artifactId.

Parameters:
artifact The dependency to inspect
Returns:
true if the dependency's groupId is a Groovy groupId, false otherwise
    protected boolean isGroovyArtifactId(final Artifact artifact) {
        return artifact.getArtifactId().equals("groovy-all") || artifact.getArtifactId().equals("groovy-all-minimal")
                || artifact.getArtifactId().equals("groovy") || artifact.getArtifactId().equals("groovy-all-jdk14")
                || artifact.getArtifactId().equals("groovy-jdk14");
    }

    
Determines whether the version of Java executing this mojo supports invokedynamic (is at least 1.7).

Returns:
true if the running Java supports invokedynamic, false otherwise
    protected boolean isJavaSupportIndy() {
        return getJavaVersion().compareTo(new Version(1, 7), false) >= 0;
    }

    
Gets the version of Java executing this mojo as a Version object.

Returns:
a Version object of the running Java version
    protected Version getJavaVersion() {
        return Version.parseFromString(getJavaVersionString());
    }

    
Gets the version of Java executing this mojo as a String.

Returns:
a String of the running Java version
    protected String getJavaVersionString() {
        return System.getProperty("java.version");
    }
New to GrepCode? Check out our FAQ X