1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  package org.apache.maven.plugin.testing;
20  
21  import java.io.File;
22  
23  import org.apache.maven.artifact.repository.MavenArtifactRepository;
24  import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
25  import org.codehaus.plexus.PlexusTestCase;
26  import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
27  import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
28  
29  
30  
31  
32  
33  
34  
35  @Deprecated
36  public class ResolverExpressionEvaluatorStub implements ExpressionEvaluator {
37      
38      @Override
39      public Object evaluate(String expr) throws ExpressionEvaluationException {
40  
41          Object value = null;
42  
43          if (expr == null) {
44              return null;
45          }
46  
47          String expression = stripTokens(expr);
48  
49          if (expression.equals(expr)) {
50              int index = expr.indexOf("${");
51              if (index >= 0) {
52                  int lastIndex = expr.indexOf("}", index);
53                  if (lastIndex >= 0) {
54                      String retVal = expr.substring(0, index);
55  
56                      if (index > 0 && expr.charAt(index - 1) == '$') {
57                          retVal += expr.substring(index + 1, lastIndex + 1);
58                      } else {
59                          retVal += evaluate(expr.substring(index, lastIndex + 1));
60                      }
61  
62                      retVal += evaluate(expr.substring(lastIndex + 1));
63                      return retVal;
64                  }
65              }
66  
67              
68              if (expression.indexOf("$$") > -1) {
69                  return expression.replaceAll("\\$\\$", "\\$");
70              }
71          }
72  
73          if ("basedir".equals(expression) || "project.basedir".equals(expression)) {
74              return PlexusTestCase.getBasedir();
75          } else if (expression.startsWith("basedir") || expression.startsWith("project.basedir")) {
76              int pathSeparator = expression.indexOf("/");
77  
78              if (pathSeparator > 0) {
79                  value = PlexusTestCase.getBasedir() + expression.substring(pathSeparator);
80              } else {
81                  System.out.println("Got expression '" + expression + "' that was not recognised");
82              }
83              return value;
84          } else if ("localRepository".equals(expression)) {
85              File localRepo = new File(PlexusTestCase.getBasedir(), "target/local-repo");
86              return new MavenArtifactRepository(
87                      "localRepository",
88                      "file://" + localRepo.getAbsolutePath(),
89                      new DefaultRepositoryLayout(),
90                      null,
91                      null);
92          } else {
93              return expr;
94          }
95      }
96  
97      private String stripTokens(String expr) {
98          if (expr.startsWith("${") && expr.indexOf("}") == expr.length() - 1) {
99              expr = expr.substring(2, expr.length() - 1);
100         }
101 
102         return expr;
103     }
104 
105     
106     @Override
107     public File alignToBaseDirectory(File file) {
108         if (file.getAbsolutePath().startsWith(PlexusTestCase.getBasedir())) {
109             return file;
110         } else if (file.isAbsolute()) {
111             return file;
112         } else {
113             return new File(PlexusTestCase.getBasedir(), file.getPath());
114         }
115     }
116 }