1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.scalabench.plugins.dacapo;
19
20 import java.util.Set;
21
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.plugin.AbstractMojo;
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.project.MavenProject;
26 import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
27 import org.apache.maven.shared.artifact.filter.collection.FilterArtifacts;
28 import org.apache.maven.shared.artifact.filter.collection.ScopeFilter;
29
30 public abstract class AbstractDacapoBenchmarkMojo extends AbstractMojo {
31
32
33
34
35
36
37
38
39 private MavenProject project;
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 private String benchmarkName;
57
58 public MavenProject getProject() {
59 return project;
60 }
61
62 public String getBenchmarkName() {
63 if (benchmarkName == null)
64 return getBenchmarkNameFromArtifactId(getProject().getArtifactId());
65 else
66 return benchmarkName;
67 }
68
69 public static String getBenchmarkNameFromArtifactId(String artifactId) {
70 final String DACAPO_BENCHMARK_SUFFIX = "-dacapo-benchmark";
71 final String DACAPO_PREFIX = "dacapo-";
72 final String BENCHMARK_SUFFIX = "-benchmark";
73
74 if (artifactId.endsWith(DACAPO_BENCHMARK_SUFFIX))
75 return artifactId.substring(0, artifactId.length() - DACAPO_BENCHMARK_SUFFIX.length());
76 else if (artifactId.startsWith(DACAPO_PREFIX) && artifactId.endsWith(BENCHMARK_SUFFIX))
77 return artifactId.substring(DACAPO_PREFIX.length(), artifactId.length() - BENCHMARK_SUFFIX.length());
78 else
79 return artifactId;
80 }
81
82
83
84
85
86
87
88 public Set<Artifact> getLibraries() throws MojoExecutionException {
89 final FilterArtifacts filter = new FilterArtifacts();
90 filter.addFilter(new ScopeFilter(Artifact.SCOPE_PROVIDED, ""));
91
92 try {
93 return filter.filter(getProject().getArtifacts());
94 } catch (ArtifactFilterException e) {
95 throw new MojoExecutionException(e.getMessage(), e);
96 }
97 }
98
99 public void logDebug(String format, Object... args) {
100 getLog().debug(String.format(format, args));
101 }
102
103 public void logInfo(String format, Object... args) {
104 getLog().info(String.format(format, args));
105 }
106
107 public void logWarn(String format, Object... args) {
108 getLog().warn(String.format(format, args));
109 }
110
111 public void logError(String format, Object... args) {
112 getLog().error(String.format(format, args));
113 }
114 }