Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2003-2014 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 groovy.grape;
import groovy.lang.Grab;
import groovy.lang.GrabConfig;
import groovy.lang.GrabExclude;
import groovy.lang.GrabResolver;
import groovy.lang.Grapes;
import groovy.transform.CompilationUnitAware;
import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.ast.AnnotatedNode;
import org.codehaus.groovy.ast.AnnotationNode;
import org.codehaus.groovy.ast.ClassCodeVisitorSupport;
import org.codehaus.groovy.ast.ClassHelper;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.ImportNode;
import org.codehaus.groovy.ast.ModuleNode;
import org.codehaus.groovy.ast.expr.ArgumentListExpression;
import org.codehaus.groovy.ast.expr.ConstantExpression;
import org.codehaus.groovy.ast.expr.Expression;
import org.codehaus.groovy.ast.expr.ListExpression;
import org.codehaus.groovy.ast.expr.MapExpression;
import org.codehaus.groovy.ast.expr.MethodCallExpression;
import org.codehaus.groovy.ast.expr.StaticMethodCallExpression;
import org.codehaus.groovy.ast.expr.VariableExpression;
import org.codehaus.groovy.ast.stmt.ExpressionStatement;
import org.codehaus.groovy.ast.stmt.Statement;
import org.codehaus.groovy.control.CompilationUnit;
import org.codehaus.groovy.control.CompilePhase;
import org.codehaus.groovy.control.SourceUnit;
import org.codehaus.groovy.control.io.StringReaderSource;
import org.codehaus.groovy.runtime.DefaultGroovyMethods;
import org.codehaus.groovy.tools.GrapeUtil;
import org.codehaus.groovy.transform.ASTTransformation;
import org.codehaus.groovy.transform.ASTTransformationVisitor;
import org.codehaus.groovy.transform.GroovyASTTransformation;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static org.codehaus.groovy.transform.AbstractASTTransformation.getMemberStringValue;
/**
* Transformation for declarative dependency management.
*/
@GroovyASTTransformation(phase=CompilePhase.CONVERSION)
public class GrabAnnotationTransformation extends ClassCodeVisitorSupport implements ASTTransformation, CompilationUnitAware {
private static final String GRAB_CLASS_NAME = Grab.class.getName();
private static final String GRAB_DOT_NAME = GRAB_CLASS_NAME.substring(GRAB_CLASS_NAME.lastIndexOf("."));
private static final String GRAB_SHORT_NAME = GRAB_DOT_NAME.substring(1);
private static final String GRABEXCLUDE_CLASS_NAME = GrabExclude.class.getName();
private static final String GRABEXCLUDE_DOT_NAME = dotName(GRABEXCLUDE_CLASS_NAME);
private static final String GRABEXCLUDE_SHORT_NAME = shortName(GRABEXCLUDE_DOT_NAME);
private static final String GRABCONFIG_CLASS_NAME = GrabConfig.class.getName();
private static final String GRABCONFIG_DOT_NAME = dotName(GRABCONFIG_CLASS_NAME);
private static final String GRABCONFIG_SHORT_NAME = shortName(GRABCONFIG_DOT_NAME);
private static final String GRAPES_CLASS_NAME = Grapes.class.getName();
private static final String GRAPES_DOT_NAME = dotName(GRAPES_CLASS_NAME);
private static final String GRAPES_SHORT_NAME = shortName(GRAPES_DOT_NAME);
private static final String GRABRESOLVER_CLASS_NAME = GrabResolver.class.getName();
private static final String GRABRESOLVER_DOT_NAME = dotName(GRABRESOLVER_CLASS_NAME);
private static final String GRABRESOLVER_SHORT_NAME = shortName(GRABRESOLVER_DOT_NAME);
private static final ClassNode THREAD_CLASSNODE = ClassHelper.make(Thread.class);
private static final List GRABEXCLUDE_REQUIRED = Arrays.asList("group", "module");
private static final List GRABRESOLVER_REQUIRED = Arrays.asList("name", "root");
private static final List GRAB_REQUIRED = Arrays.asList("group", "module", "version");
private static final List GRAB_OPTIONAL = Arrays.asList("classifier", "transitive", "conf", "ext", "type", "changing", "force", "initClass");
private static final List GRAB_BOOLEAN = Arrays.asList("transitive", "changing", "force", "initClass");
private static final Collection GRAB_ALL = DefaultGroovyMethods.plus(GRAB_REQUIRED, GRAB_OPTIONAL);
private static final Pattern IVY_PATTERN = Pattern.compile("([a-zA-Z0-9-/._+=]+)#([a-zA-Z0-9-/._+=]+)(;([a-zA-Z0-9-/.\\(\\)\\[\\]\\{\\}_+=,:@][a-zA-Z0-9-/.\\(\\)\\]\\{\\}_+=,:@]*))?(\\[([a-zA-Z0-9-/._+=,]*)\\])?");
private static final Pattern ATTRIBUTES_PATTERN = Pattern.compile("(.*;|^)([a-zA-Z0-9]+)=([a-zA-Z0-9.*\\[\\]\\-\\(\\),]*)$");
private static final String AUTO_DOWNLOAD_SETTING = Grape.AUTO_DOWNLOAD_SETTING;
private static final String DISABLE_CHECKSUMS_SETTING = Grape.DISABLE_CHECKSUMS_SETTING;
private static String dotName(String className) {
return className.substring(className.lastIndexOf("."));
}
private static String shortName(String className) {
return className.substring(1);
}
boolean allowShortGrab;
Set grabAliases;
List grabAnnotations;
boolean allowShortGrabExcludes;
Set grabExcludeAliases;
List grabExcludeAnnotations;
boolean allowShortGrabConfig;
Set grabConfigAliases;
List grabConfigAnnotations;
boolean allowShortGrapes;
Set grapesAliases;
List grapesAnnotations;
boolean allowShortGrabResolver;
Set grabResolverAliases;
List grabResolverAnnotations;
CompilationUnit compilationUnit;
SourceUnit sourceUnit;
ClassLoader loader;
boolean initContextClassLoader;
Boolean autoDownload;
Boolean disableChecksums;
public SourceUnit getSourceUnit() {
return sourceUnit;
}
public void setCompilationUnit(final CompilationUnit compilationUnit) {
this.compilationUnit = compilationUnit;
}
public void visit(ASTNode[] nodes, SourceUnit source) {
sourceUnit = source;
loader = null;
initContextClassLoader = false;
ModuleNode mn = (ModuleNode) nodes[0];
allowShortGrab = true;
allowShortGrabExcludes = true;
allowShortGrabConfig = true;
allowShortGrapes = true;
allowShortGrabResolver = true;
grabAliases = new HashSet();
grabExcludeAliases = new HashSet();
grabConfigAliases = new HashSet();
grapesAliases = new HashSet();
grabResolverAliases = new HashSet();
for (ImportNode im : mn.getImports()) {
String alias = im.getAlias();
String className = im.getClassName();
if ((className.endsWith(GRAB_DOT_NAME) && ((alias == null) || (alias.length() == 0)))
|| (GRAB_CLASS_NAME.equals(alias)))
{
allowShortGrab = false;
} else if (GRAB_CLASS_NAME.equals(className)) {
grabAliases.add(im.getAlias());
}
if ((className.endsWith(GRAPES_DOT_NAME) && ((alias == null) || (alias.length() == 0)))
|| (GRAPES_CLASS_NAME.equals(alias)))
{
allowShortGrapes = false;
} else if (GRAPES_CLASS_NAME.equals(className)) {
grapesAliases.add(im.getAlias());
}
if ((className.endsWith(GRABRESOLVER_DOT_NAME) && ((alias == null) || (alias.length() == 0)))
|| (GRABRESOLVER_CLASS_NAME.equals(alias)))
{
allowShortGrabResolver = false;
} else if (GRABRESOLVER_CLASS_NAME.equals(className)) {
grabResolverAliases.add(im.getAlias());
}
}
// GRECLIPSE - if this is a list and not a set then you can duplicates when multiple classes
// are visited in the same source file. The same grabs are accumulated. There is maybe a
// better fix but this is easy. If there are duplicates it will work but we are calling
// grab with unnecessary dup info.
Collection