Author: ruschein
Date: 2011-03-08 16:24:38 -0800 (Tue, 08 Mar 2011)
New Revision: 24346
Modified:
core3/profiler-mojo/trunk/src/main/java/org/cytoscape/mavenplugins/ProfilerMojo.java
Log:
Work in progress.
Modified:
core3/profiler-mojo/trunk/src/main/java/org/cytoscape/mavenplugins/ProfilerMojo.java
===================================================================
---
core3/profiler-mojo/trunk/src/main/java/org/cytoscape/mavenplugins/ProfilerMojo.java
2011-03-08 23:45:51 UTC (rev 24345)
+++
core3/profiler-mojo/trunk/src/main/java/org/cytoscape/mavenplugins/ProfilerMojo.java
2011-03-09 00:24:38 UTC (rev 24346)
@@ -30,23 +30,53 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.surefire.AbstractSurefireMojo;
+import org.apache.maven.plugin.surefire.ProviderInfo;
+import org.apache.maven.plugin.surefire.SurefireExecutionParameters;
+import org.apache.maven.plugin.surefire.SurefireHelper;
+import org.apache.maven.plugin.surefire.SurefireReportParameters;
+import org.apache.maven.plugin.surefire.booterclient.ChecksumCalculator;
+import org.apache.maven.plugin.surefire.booterclient.ForkConfiguration;
+import org.apache.maven.plugin.surefire.booterclient.ForkStarter;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.surefire.booter.ClassLoaderConfiguration;
+import org.apache.maven.surefire.booter.Classpath;
+import org.apache.maven.surefire.booter.SurefireBooterForkException;
+import org.apache.maven.surefire.booter.SurefireExecutionException;
+import org.apache.maven.toolchain.ToolchainManager;
import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileWriter;
+import java.io.InputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import javax.xml.stream.*;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.*;
+import javax.xml.stream.XMLInputFactory;
+
/**
* Goal which runs profiling regression tests.
*
@@ -54,41 +84,659 @@
*
* @phase test
*/
-public final class ProfilerMojo extends AbstractMojo {
+public final class ProfilerMojo extends AbstractSurefireMojo implements
SurefireExecutionParameters, SurefireReportParameters {
/**
- * @parameter expression="${localRepository}"
+ * Set this to "true" to skip running tests, but still compile them.
Its use is NOT RECOMMENDED, but quite
+ * convenient on occasion.
+ *
+ * @parameter default-value="false" expression="${skipTests}"
+ * @since 2.4
+ */
+ private boolean skipTests;
+
+ /**
+ * This old parameter is just like <code>skipTests</code>, but bound to
the old property "maven.test.skip.exec".
+ *
+ * @parameter expression="${maven.test.skip.exec}"
+ * @since 2.3
+ * @deprecated Use skipTests instead.
+ */
+ private boolean skipExec;
+
+ /**
+ * Set this to "true" to bypass unit tests entirely. Its use is NOT
RECOMMENDED, especially if you
+ * enable it using the "maven.test.skip" property, because
maven.test.skip disables both running the
+ * tests and compiling the tests. Consider using the
<code>skipTests</code> parameter instead.
+ *
+ * @parameter default-value="false" expression="${maven.test.skip}"
+ */
+ private boolean skip;
+
+ /**
+ * Set this to "true" to ignore a failure during testing. Its use is
NOT RECOMMENDED, but quite convenient on
+ * occasion.
+ *
+ * @parameter default-value="false"
expression="${maven.test.failure.ignore}"
+ */
+ private boolean testFailureIgnore;
+
+ /**
+ * The base directory of the project being tested. This can be obtained
in your unit test via
+ * System.getProperty("basedir").
+ *
+ * @parameter default-value="${basedir}"
+ */
+ private File basedir;
+
+ /**
+ * The directory containing generated test classes of the project being
tested.
+ * This will be included at the beginning of the test classpath.
*
+ *
+ * @parameter default-value="${project.build.testOutputDirectory}"
+ */
+ private File testClassesDirectory;
+
+ /**
+ * The directory containing generated classes of the project being
tested.
+ * This will be included after the test classes in the test classpath.
+ *
+ * @parameter default-value="${project.build.outputDirectory}"
+ */
+ private File classesDirectory;
+
+ /**
+ * The Maven Project Object.
+ *
+ * @parameter default-value="${project}"
* @readonly
+ */
+ private MavenProject project;
+
+ /**
+ * List of dependencies to exclude from the test classpath.
+ * Each dependency string must follow the format
<i>groupId:artifactId</i>.
+ * For example: <i>org.acme:project-a</i>
+ *
+ * @parameter
+ * @since 2.6
+ */
+ private List classpathDependencyExcludes;
+
+ /**
+ * A dependency scope to exclude from the test classpath.
+ * The scope can be one of the following scopes:
+ * <p/>
+ * <ul><li><i>compile</i> - system, provided, compile
+ * <li><i>runtime</i> - compile, runtime
+ * <li><i>test</i> - system, provided, compile, runtime, test</ul>
+ *
+ * @parameter default-value=""
+ * @since 2.6
+ */
+ private String classpathDependencyScopeExclude;
+
+ /**
+ * Additional elements to be appended to the classpath.
+ *
+ * @parameter
+ * @since 2.4
+ */
+ private List additionalClasspathElements;
+
+ /**
+ * Base directory where all reports are written to.
+ *
+ * @parameter
default-value="${project.build.directory}/surefire-reports"
+ */
+ private File reportsDirectory;
+
+ /**
+ * The test source directory containing test class sources.
+ *
+ * @parameter default-value="${project.build.testSourceDirectory}"
* @required
+ * @since 2.2
*/
+ private File testSourceDirectory;
+
+ /**
+ * Specify this parameter to run individual tests by file name,
overriding the <code>includes/excludes</code>
+ * parameters. Each pattern you specify here will be used to create an
+ * include pattern formatted like <code>**/${test}.java</code>, so
you can just type "-Dtest=MyTest"
+ * to run a single test called "foo/MyTest.java".<br/>
+ * This parameter overrides the <code>includes/excludes</code>
parameters, and the TestNG
+ * <code>suiteXmlFiles</code> parameter.
+ *
+ * @parameter expression="${test}"
+ */
+ private String test;
+
+ /**
+ * A list of <include> elements specifying the tests (by pattern)
that should be included in testing. When not
+ * specified and when the <code>test</code> parameter is not specified,
the default includes will be
+ * <code><br/>
+ * <includes><br/>
+ * <include>**/Test*.java</include><br/>
+ * <include>**/*Test.java</include><br/>
+ * <include>**/*TestCase.java</include><br/>
+ * </includes><br/>
+ * </code>
+ * This parameter is ignored if the TestNG <code>suiteXmlFiles</code>
parameter is specified.
+ *
+ * @parameter
+ */
+ private List includes;
+
+ /**
+ * A list of <exclude> elements specifying the tests (by pattern)
that should be excluded in testing. When not
+ * specified and when the <code>test</code> parameter is not specified,
the default excludes will be
+ * <code><br/>
+ * <excludes><br/>
+ * <exclude>**/*$*</exclude><br/>
+ * </excludes><br/>
+ * </code>
+ * (which excludes all inner classes).<br>
+ * This parameter is ignored if the TestNG <code>suiteXmlFiles</code>
parameter is specified.
+ *
+ * @parameter
+ */
+ private List excludes;
+
+ /**
+ * ArtifactRepository of the localRepository. To obtain the directory
of localRepository in unit tests use
+ * System.getProperty("localRepository").
+ *
+ * @parameter expression="${localRepository}"
+ * @required
+ * @readonly
+ */
private ArtifactRepository localRepository;
/**
- * @parameter expression="${project.remoteArtifactRepositories}"
+ * List of System properties to pass to the JUnit tests.
+ *
+ * @parameter
+ * @deprecated Use systemPropertyVariables instead.
+ */
+ private Properties systemProperties;
+
+ /**
+ * List of System properties to pass to the JUnit tests.
+ *
+ * @parameter
+ * @since 2.5
+ */
+ private Map systemPropertyVariables;
+
+ /**
+ * List of properties for configuring all TestNG related
configurations. This is the new
+ * preferred method of configuring TestNG.
+ *
+ * @parameter
+ * @since 2.4
+ */
+ private Properties properties;
+
+ /**
+ * Map of plugin artifacts.
+ *
+ * @parameter expression="${plugin.artifactMap}"
+ * @required
* @readonly
+ */
+ private Map pluginArtifactMap;
+
+ /**
+ * Map of project artifacts.
+ *
+ * @parameter expression="${project.artifactMap}"
* @required
+ * @readonly
*/
- private List<ArtifactRepository> remoteRepositories;
-
+ private Map projectArtifactMap;
+
/**
- * @parameter baselineVersion
+ * Option to print summary of test suites or just print the test cases
that have errors.
+ *
+ * @parameter expression="${surefire.printSummary}" default-value="true"
+ */
+ private boolean printSummary;
+
+ /**
+ * Selects the formatting for the test report to be generated. Can be
set as "brief" or "plain".
+ *
+ * @parameter expression="${surefire.reportFormat}"
default-value="brief"
+ */
+ private String reportFormat;
+
+ /**
+ * Option to generate a file test report or just output the test report
to the console.
+ *
+ * @parameter expression="${surefire.useFile}" default-value="true"
+ */
+ private boolean useFile;
+
+ /**
+ * When forking, set this to "true" to redirect the unit test standard
output to a file (found in
+ * reportsDirectory/testName-output.txt).
+ *
+ * @parameter expression="${maven.test.redirectTestOutputToFile}"
default-value="false"
+ * @since 2.3
+ */
+ private boolean redirectTestOutputToFile;
+
+ /**
+ * Set this to "true" to cause a failure if there are no tests to run.
Defaults to "false".
+ *
+ * @parameter expression="${failIfNoTests}"
+ * @since 2.4
+ */
+ private Boolean failIfNoTests;
+
+ /**
+ * Option to specify the forking mode. Can be "never", "once" or
"always". "none" and "pertest" are also accepted
+ * for backwards compatibility. "always" forks for each test-class.
+ *
+ * @parameter expression="${forkMode}" default-value="none"
+ * @since 2.1
+ */
+ private String forkMode;
+
+ /**
+ * Option to specify the jvm (or path to the java executable) to use
with the forking options. For the default, the
+ * jvm will be a new instance of the same VM as the one used to run
Maven. JVM settings are not inherited from
+ * MAVEN_OPTS.
+ *
+ * @parameter expression="${jvm}"
+ * @since 2.1
+ */
+ private String jvm;
+
+ /**
+ * Arbitrary JVM options to set on the command line.
+ *
+ * @parameter expression="${argLine}"
+ * @since 2.1
+ */
+ private String argLine;
+
+ /**
+ * Attach a debugger to the forked JVM. If set to "true", the process
will suspend and
+ * wait for a debugger to attach on port 5005. If set to some other
string, that
+ * string will be appended to the argLine, allowing you to configure
arbitrary
+ * debuggability options (without overwriting the other options
specified through the <code>argLine</code>
+ * parameter).
+ *
+ * @parameter expression="${maven.surefire.debug}"
+ * @since 2.4
+ */
+ private String debugForkedProcess;
+
+ /**
+ * Kill the forked test process after a certain number of seconds. If
set to 0,
+ * wait forever for the process, never timing out.
+ *
+ * @parameter expression="${surefire.timeout}"
+ * @since 2.4
+ */
+ private int forkedProcessTimeoutInSeconds;
+
+ /**
+ * Additional environment variables to set on the command line.
+ *
+ * @parameter
+ * @since 2.1.3
+ */
+ private Map environmentVariables = new HashMap();
+
+ /**
+ * Command line working directory.
+ *
+ * @parameter expression="${basedir}"
+ * @since 2.1.3
+ */
+ private File workingDirectory;
+
+ /**
+ * When false it makes tests run using the standard classloader
delegation instead of the default Maven isolated
+ * classloader. Only used when forking (forkMode is not "none").<br/>
Setting it to false helps with some problems
+ * caused by conflicts between xml parsers in the classpath and the
Java 5 provider parser.
+ *
+ * @parameter expression="${childDelegation}" default-value="false"
+ * @since 2.1
+ */
+ private boolean childDelegation;
+
+ /**
+ * (TestNG only) Groups for this test. Only classes/methods/etc
decorated with one of the groups specified here will be included
+ * in test run, if specified.<br/>
+ * This parameter is ignored if the <code>suiteXmlFiles</code>
parameter is specified.
+ *
+ * @parameter expression="${groups}"
+ * @since 2.2
+ */
+ private String groups;
+
+ /**
+ * (TestNG only) Excluded groups. Any methods/classes/etc with one of
the groups specified in this list will specifically not be
+ * run.<br/>
+ * This parameter is ignored if the <code>suiteXmlFiles</code>
parameter is specified.
+ *
+ * @parameter expression="${excludedGroups}"
+ * @since 2.2
+ */
+ private String excludedGroups;
+
+ /**
+ * (TestNG only) List of <suiteXmlFile> elements specifying TestNG
suite xml file locations. Note that <code>suiteXmlFiles</code> is incompatible
+ * with several other parameters of this plugin, like
<code>includes/excludes</code>.<br/>
+ * This parameter is ignored if the <code>test</code> parameter is
specified (allowing you to run a single
+ * test instead of an entire suite).
+ *
+ * @parameter
+ * @since 2.2
+ */
+ private File[] suiteXmlFiles;
+
+ /**
+ * Allows you to specify the name of the JUnit artifact. If not set,
<code>junit:junit</code> will be used.
+ *
+ * @parameter expression="${junitArtifactName}"
default-value="junit:junit"
+ * @since 2.3.1
+ */
+ private String junitArtifactName;
+
+ /**
+ * Allows you to specify the name of the TestNG artifact. If not set,
<code>org.testng:testng</code> will be used.
+ *
+ * @parameter expression="${testNGArtifactName}"
default-value="org.testng:testng"
+ * @since 2.3.1
+ */
+ private String testNGArtifactName;
+
+ /**
+ * (TestNG/JUnit 4.7 provider only) The attribute thread-count allows
you to specify how many threads should be allocated for this execution. Only
+ * makes sense to use in conjunction with the <code>parallel</code>
parameter.
+ *
+ * @parameter expression="${threadCount}"
+ * @since 2.2
+ */
+ private int threadCount;
+
+ /**
+ * (JUnit 4.7 provider) Indicates that threadCount is per cpu core.
+ *
+ * @parameter expression="${perCoreThreadCount}" default-value="true"
+ * @since 2.5
+ */
+ private boolean perCoreThreadCount;
+
+ /**
+ * (JUnit 4.7 provider) Indicates that the thread pool will be
unlimited. The <code>parallel</code> parameter and the actual number of
classes/methods
+ * will decide. Setting this to "true" effectively disables
<code>perCoreThreadCount</code> and <code>threadCount</code>. Defaults to
"false".
+ *
+ * @parameter expression="${useUnlimitedThreads}" default-value="false"
+ * @since 2.5
+ */
+ private boolean useUnlimitedThreads;
+
+ /**
+ * (TestNG only) When you use the <code>parallel</code> attribute,
TestNG will try to run all your test methods in separate threads, except for
+ * methods that depend on each other, which will be run in the same
thread in order to respect their order of
+ * execution.
+ * <p/>
+ * (JUnit 4.7 provider) Supports values "classes"/"methods"/"both" to
run in separate threads, as controlled by <code>threadCount</code>.
+ *
+ * @parameter expression="${parallel}"
+ * @since 2.2
+ */
+ private String parallel;
+
+ /**
+ * Whether to trim the stack trace in the reports to just the lines
within the test, or show the full trace.
+ *
+ * @parameter expression="${trimStackTrace}" default-value="true"
+ * @since 2.2
+ */
+ private boolean trimStackTrace;
+
+ /**
+ * Resolves the artifacts needed.
+ *
+ * @component
+ */
+ private ArtifactResolver artifactResolver;
+
+ /**
+ * Creates the artifact.
+ *
+ * @component
+ */
+ private ArtifactFactory artifactFactory;
+
+ /**
+ * The remote plugin repositories declared in the POM.
+ *
+ * @parameter expression="${project.pluginArtifactRepositories}"
+ * @since 2.2
+ */
+ private List remoteRepositories;
+
+ /**
+ * For retrieval of artifact's metadata.
+ *
+ * @component
+ */
+ private ArtifactMetadataSource metadataSource;
+
+ private Properties originalSystemProperties;
+
+ /**
+ * systemPropertyVariables + systemProperties
+ */
+ private Properties internalSystemProperties = new Properties();
+
+ /**
+ * Flag to disable the generation of report files in xml format.
+ *
+ * @parameter expression="${disableXmlReport}" default-value="false"
+ * @since 2.2
+ */
+ private boolean disableXmlReport;
+
+ /**
+ * Option to pass dependencies to the system's classloader instead of
using an isolated class loader when forking.
+ * Prevents problems with JDKs which implement the service provider
lookup mechanism by using the system's
+ * classloader.
+ *
+ * @parameter expression="${surefire.useSystemClassLoader}"
default-value="true"
+ * @since 2.3
+ */
+ private boolean useSystemClassLoader;
+
+ /**
+ * By default, Surefire forks your tests using a manifest-only JAR; set
this parameter
+ * to "false" to force it to launch your tests with a plain old Java
classpath.
+ * (See
http://maven.apache.org/plugins/maven-surefire-plugin/examples/class-loading.html
+ * for a more detailed explanation of manifest-only JARs and their
benefits.)
+ * <p/>
+ * Beware, setting this to "false" may cause your tests to
+ * fail on Windows if your classpath is too long.
+ *
+ * @parameter expression="${surefire.useManifestOnlyJar}"
default-value="true"
+ * @since 2.4.3
+ */
+ private boolean useManifestOnlyJar;
+
+ /**
+ * By default, Surefire enables JVM assertions for the execution of
your test cases. To disable the assertions, set
+ * this flag to "false".
+ *
+ * @parameter expression="${enableAssertions}" default-value="true"
+ * @since 2.3.1
+ */
+ private boolean enableAssertions;
+
+ /**
+ * The current build session instance.
+ *
+ * @parameter expression="${session}"
* @required
+ * @readonly
*/
- private String baselineVersion;
+ private MavenSession session;
/**
- * The Maven Project Object.
+ * (TestNG only) Define the factory class used to create all test
instances.
*
- * @parameter default-value="${project}"
+ * @parameter expression="${objectFactory}"
+ * @since 2.5
+ */
+ private String objectFactory;
+
+
+ /**
+ * @parameter default-value="${session.parallel}"
* @readonly
+ * @noinspection UnusedDeclaration
*/
- private MavenProject project;
+ private Boolean parallelMavenExecution;
+ /**
+ * Defines the order the tests will be run in. Supported values are
"alphabetical", "reversealphabetical",
+ * "random", "hourly" (alphabetical on even hours, reverse alphabetical
on odd hours) and "filesystem".<p/>
+ * <p/>
+ * Odd/Even for hourly is determined at the time the of scanning the
classpath, meaning it could change during
+ * a multi-module build.
+ *
+ * @parameter default-value="filesystem"
+ * @since 2.7
+ */
+ private String runOrder;
+
+ /**
+ * @component
+ */
+ private ToolchainManager toolchainManager;
+
+ /**
+ * @parameter baselineVersion
+ * @required
+ */
+ private String baselineVersion;
+
/** @component */
private ArtifactResolver resolver;
- /** @component */
- private ArtifactFactory artifactFactory;
-
+ public void execute() throws MojoExecutionException,
MojoFailureException {
+System.err.println("+++++++++++++++++++++++++++ Entering execute()");
+ if (verifyParameters()) {
+System.err.println("+++++++++++++++++++++++++++ parameters are Ok");
+ if (hasExecutedBefore())
+ return;
+
+ logReportsDirectory();
+
+System.err.println("+++++++++++++++++++++++++++ about to call run()");
+ run();
+ final Set<ClassAndMethodNameAndExecutionTime>
currentNamesAndTimes = getTestTimes();
+System.err.println("+++++++++++++++++++++++++++ after first run: " +
currentNamesAndTimes);
+ run();
+ final Set<ClassAndMethodNameAndExecutionTime>
baselineNamesAndTimes = getTestTimes();
+System.err.println("+++++++++++++++++++++++++++ after baseline run: " +
baselineNamesAndTimes);
+ }
+ }
+
+ private void run() throws MojoExecutionException, MojoFailureException {
+ final List providers = initialize();
+ Exception exception = null;
+ ForkConfiguration forkConfiguration = null;
+ int result = 0;
+ for (Iterator iter = providers.iterator(); iter.hasNext(); /*
Empty! */) {
+ ProviderInfo provider = (ProviderInfo) iter.next();
+ forkConfiguration = getForkConfiguration();
+ final Classpath bootClasspath =
forkConfiguration.getBootClasspath();
+System.err.println("+++++++++++++++++++++++++++ class path is " +
bootClasspath.getClassPath());
+ ClassLoaderConfiguration classLoaderConfiguration =
+ getClassLoaderConfiguration(forkConfiguration);
+ ForkStarter forkStarter =
+ createForkStarter(provider, forkConfiguration,
classLoaderConfiguration);
+
+ try {
+ result = forkStarter.run();
+ } catch (SurefireBooterForkException e) {
+ exception = e;
+ } catch (SurefireExecutionException e) {
+ exception = e;
+ }
+ }
+
+ if (exception != null)
+ throw new
MojoExecutionException(exception.getMessage(), exception);
+
+ if (getOriginalSystemProperties() != null && forkConfiguration
!= null && !forkConfiguration.isForking()) {
+ // restore system properties, only makes sense when not
forking..
+ System.setProperties( getOriginalSystemProperties() );
+ }
+
+ SurefireHelper.reportExecution(this, result, getLog());
+ }
+
+ private Set<ClassAndMethodNameAndExecutionTime> getTestTimes() throws
MojoExecutionException {
+ final XMLInputFactory inputFactory =
XMLInputFactory.newInstance();
+
+ final String targetDir = "target/surefire-reports";
+ final File direcory = new File(targetDir);
+ final String fileNames[] = direcory.list();
+
+ final Set<ClassAndMethodNameAndExecutionTime> result = new
HashSet<ClassAndMethodNameAndExecutionTime>();
+ for (final String fileName : fileNames) {
+ if (!fileName.startsWith("TEST-") || !
fileName.endsWith(".xml"))
+ continue;
+
+ final InputStream input;
+ try {
+ input = new FileInputStream(new File(targetDir
+ "/" + fileName));
+ } catch (final FileNotFoundException e) {
+ throw new
MojoExecutionException(e.getMessage(), e);
+ }
+
+ final XMLStreamReader xmlStreamReader;
+ try {
+ xmlStreamReader =
inputFactory.createXMLStreamReader(input);
+ while (xmlStreamReader.hasNext()) {
+ final int event =
xmlStreamReader.next();
+ if (event !=
XMLStreamConstants.START_ELEMENT)
+ continue;
+ final String entityName =
xmlStreamReader.getLocalName();
+ if (!entityName.equals("testcase"))
+ continue;
+
+ double time = -1.0;
+ String classAndMethodName = null;
+ for (int i = 0; i <
xmlStreamReader.getAttributeCount(); ++i) {
+ final String attrName =
xmlStreamReader.getAttributeLocalName(i);
+ if (attrName.equals("time")) {
+ try {
+ time =
Double.parseDouble(xmlStreamReader.getAttributeValue(i));
+ } catch (final
Exception e) {
+ throw new
MojoExecutionException("failed to parse execution time in \""
+
+ fileName + "\"!");
+ }
+ } else if
(attrName.equals("name"))
+ classAndMethodName =
xmlStreamReader.getAttributeValue(i);
+ }
+ result.add(new
ClassAndMethodNameAndExecutionTime(classAndMethodName, time));
+ }
+ } catch (final XMLStreamException e) {
+ throw new
MojoExecutionException(e.getMessage(), e);
+ }
+ }
+
+ return result;
+ }
+
+ /*
public void execute() throws MojoExecutionException {
getLog().info("+++ ProfilerMojo: base line version is " +
baselineVersion + ", group ID: "
+ project.getGroupId() + ", artifact ID: " +
project.getArtifactId());
@@ -106,7 +754,9 @@
collectStats(baselineArtifact);
compareStats();
}
+ */
+ /*
private List<String> generateTestClasspath() {
final List<String> testClasspath = new ArrayList<String>();
for (final Object a : project.getArtifacts()) {
@@ -120,6 +770,7 @@
return testClasspath;
}
+ */
private void collectStats(final Artifact artifact) {
System.gc();
@@ -138,4 +789,692 @@
}
getLog().info("+++ ProfilerMojo: resolved " + artifact);
}
+
+ protected boolean verifyParameters() throws MojoFailureException {
+ if (isSkip() || isSkipTests() || isSkipExec()) {
+ getLog().info("Tests are skipped.");
+ return false;
+ }
+
+ if (!getTestClassesDirectory().exists()) {
+ if (getFailIfNoTests() != null &&
getFailIfNoTests().booleanValue())
+ throw new MojoFailureException("No tests to
run!");
+
+ getLog().info("No tests to run.");
+ return true;
+ }
+
+ ensureWorkingDirectoryExists();
+
+ ensureParallelRunningCompatibility();
+
+ warnIfUselessUseSystemClassLoaderParameter();
+
+ if (!baselineVersionIsValid()) {
+ getLog().warn("Baseline version is missing or
invalid!");
+ return false;
+ }
+
+ return true;
+ }
+
+ private boolean baselineVersionIsValid() {
+ if (baselineVersion == null && baselineVersion.isEmpty())
+ return false;
+ return true;
+ }
+
+ protected String getPluginName() {
+ return "cytoscape-profiler";
+ }
+
+ protected String[] getDefaultIncludes()
+ {
+ return new String[]{ "**/Test*.java", "**/*Test.java",
"**/*TestCase.java" };
+ }
+
+ // now for the implementation of the field accessors
+
+ public boolean isSkipTests()
+ {
+ return skipTests;
+ }
+
+
+ public void setSkipTests( boolean skipTests )
+ {
+ this.skipTests = skipTests;
+ }
+
+ /**
+ * @noinspection deprecation
+ */
+ public boolean isSkipExec()
+ {
+ return skipExec;
+ }
+
+ /**
+ * @noinspection deprecation
+ */
+ public void setSkipExec( boolean skipExec )
+ {
+ this.skipExec = skipExec;
+ }
+
+ public boolean isSkip()
+ {
+ return skip;
+ }
+
+ public void setSkip( boolean skip )
+ {
+ this.skip = skip;
+ }
+
+ public boolean isTestFailureIgnore()
+ {
+ return testFailureIgnore;
+ }
+
+ public void setTestFailureIgnore( boolean testFailureIgnore )
+ {
+ this.testFailureIgnore = testFailureIgnore;
+ }
+
+ public File getBasedir()
+ {
+ return basedir;
+ }
+
+ public void setBasedir( File basedir )
+ {
+ this.basedir = basedir;
+ }
+
+ public File getTestClassesDirectory()
+ {
+ return testClassesDirectory;
+ }
+
+ public void setTestClassesDirectory( File testClassesDirectory )
+ {
+ this.testClassesDirectory = testClassesDirectory;
+ }
+
+ public File getClassesDirectory()
+ {
+ return classesDirectory;
+ }
+
+ public void setClassesDirectory( File classesDirectory )
+ {
+ this.classesDirectory = classesDirectory;
+ }
+
+ public MavenProject getProject()
+ {
+ return project;
+ }
+
+ public void setProject( MavenProject project )
+ {
+ this.project = project;
+ }
+
+ public List getClasspathDependencyExcludes()
+ {
+ return classpathDependencyExcludes;
+ }
+
+ public void setClasspathDependencyExcludes( List
classpathDependencyExcludes )
+ {
+ this.classpathDependencyExcludes = classpathDependencyExcludes;
+ }
+
+ public String getClasspathDependencyScopeExclude()
+ {
+ return classpathDependencyScopeExclude;
+ }
+
+ public void setClasspathDependencyScopeExclude( String
classpathDependencyScopeExclude )
+ {
+ this.classpathDependencyScopeExclude =
classpathDependencyScopeExclude;
+ }
+
+ public List getAdditionalClasspathElements()
+ {
+ return additionalClasspathElements;
+ }
+
+ public void setAdditionalClasspathElements( List
additionalClasspathElements )
+ {
+ this.additionalClasspathElements = additionalClasspathElements;
+ }
+
+ public File getReportsDirectory()
+ {
+ return reportsDirectory;
+ }
+
+ public void setReportsDirectory( File reportsDirectory )
+ {
+ this.reportsDirectory = reportsDirectory;
+ }
+
+ public File getTestSourceDirectory()
+ {
+ return testSourceDirectory;
+ }
+
+ public void setTestSourceDirectory( File testSourceDirectory )
+ {
+ this.testSourceDirectory = testSourceDirectory;
+ }
+
+ public String getTest()
+ {
+ return test;
+ }
+
+ public void setTest( String test )
+ {
+ this.test = test;
+ }
+
+ public List getIncludes()
+ {
+ return includes;
+ }
+
+ public void setIncludes( List includes )
+ {
+ this.includes = includes;
+ }
+
+ public List getExcludes()
+ {
+ return excludes;
+ }
+
+ public void setExcludes( List excludes )
+ {
+ this.excludes = excludes;
+ }
+
+ public ArtifactRepository getLocalRepository()
+ {
+ return localRepository;
+ }
+
+ public void setLocalRepository( ArtifactRepository localRepository )
+ {
+ this.localRepository = localRepository;
+ }
+
+ /**
+ * @noinspection deprecation
+ */
+ public Properties getSystemProperties()
+ {
+ return systemProperties;
+ }
+
+ /**
+ * @noinspection deprecation
+ */
+ public void setSystemProperties( Properties systemProperties )
+ {
+ this.systemProperties = systemProperties;
+ }
+
+ public Map getSystemPropertyVariables()
+ {
+ return systemPropertyVariables;
+ }
+
+ public void setSystemPropertyVariables( Map systemPropertyVariables )
+ {
+ this.systemPropertyVariables = systemPropertyVariables;
+ }
+
+ public Properties getProperties()
+ {
+ return properties;
+ }
+
+ public void setProperties( Properties properties )
+ {
+ this.properties = properties;
+ }
+
+ public Map getPluginArtifactMap()
+ {
+ return pluginArtifactMap;
+ }
+
+ public void setPluginArtifactMap( Map pluginArtifactMap )
+ {
+ this.pluginArtifactMap = pluginArtifactMap;
+ }
+
+ public Map getProjectArtifactMap()
+ {
+ return projectArtifactMap;
+ }
+
+ public void setProjectArtifactMap( Map projectArtifactMap )
+ {
+ this.projectArtifactMap = projectArtifactMap;
+ }
+
+ public boolean isPrintSummary()
+ {
+ return printSummary;
+ }
+
+ public void setPrintSummary( boolean printSummary )
+ {
+ this.printSummary = printSummary;
+ }
+
+ public String getReportFormat()
+ {
+ return reportFormat;
+ }
+
+ public void setReportFormat( String reportFormat )
+ {
+ this.reportFormat = reportFormat;
+ }
+
+ public boolean isUseFile()
+ {
+ return useFile;
+ }
+
+ public void setUseFile( boolean useFile )
+ {
+ this.useFile = useFile;
+ }
+
+ public boolean isRedirectTestOutputToFile()
+ {
+ return redirectTestOutputToFile;
+ }
+
+ public void setRedirectTestOutputToFile( boolean
redirectTestOutputToFile )
+ {
+ this.redirectTestOutputToFile = redirectTestOutputToFile;
+ }
+
+ public Boolean getFailIfNoTests()
+ {
+ return failIfNoTests;
+ }
+
+ public void setFailIfNoTests( Boolean failIfNoTests )
+ {
+ this.failIfNoTests = failIfNoTests;
+ }
+
+ public String getForkMode()
+ {
+ return forkMode;
+ }
+
+ public void setForkMode( String forkMode )
+ {
+ this.forkMode = forkMode;
+ }
+
+ public String getJvm()
+ {
+ return jvm;
+ }
+
+ public void setJvm( String jvm )
+ {
+ this.jvm = jvm;
+ }
+
+ public String getArgLine()
+ {
+ return argLine;
+ }
+
+ public void setArgLine( String argLine )
+ {
+ this.argLine = argLine;
+ }
+
+ public String getDebugForkedProcess()
+ {
+ return debugForkedProcess;
+ }
+
+ public void setDebugForkedProcess( String debugForkedProcess )
+ {
+ this.debugForkedProcess = debugForkedProcess;
+ }
+
+ public int getForkedProcessTimeoutInSeconds()
+ {
+ return forkedProcessTimeoutInSeconds;
+ }
+
+ public void setForkedProcessTimeoutInSeconds( int
forkedProcessTimeoutInSeconds )
+ {
+ this.forkedProcessTimeoutInSeconds =
forkedProcessTimeoutInSeconds;
+ }
+
+ public Map getEnvironmentVariables()
+ {
+ return environmentVariables;
+ }
+
+ public void setEnvironmentVariables( Map environmentVariables )
+ {
+ this.environmentVariables = environmentVariables;
+ }
+
+ public File getWorkingDirectory()
+ {
+ return workingDirectory;
+ }
+
+ public void setWorkingDirectory( File workingDirectory )
+ {
+ this.workingDirectory = workingDirectory;
+ }
+
+ public boolean isChildDelegation()
+ {
+ return childDelegation;
+ }
+
+ public void setChildDelegation( boolean childDelegation )
+ {
+ this.childDelegation = childDelegation;
+ }
+
+ public String getGroups()
+ {
+ return groups;
+ }
+
+ public void setGroups( String groups )
+ {
+ this.groups = groups;
+ }
+
+ public String getExcludedGroups()
+ {
+ return excludedGroups;
+ }
+
+ public void setExcludedGroups( String excludedGroups )
+ {
+ this.excludedGroups = excludedGroups;
+ }
+
+ public File[] getSuiteXmlFiles()
+ {
+ return suiteXmlFiles;
+ }
+
+ public void setSuiteXmlFiles( File[] suiteXmlFiles )
+ {
+ this.suiteXmlFiles = suiteXmlFiles;
+ }
+
+ public String getJunitArtifactName()
+ {
+ return junitArtifactName;
+ }
+
+ public void setJunitArtifactName( String junitArtifactName )
+ {
+ this.junitArtifactName = junitArtifactName;
+ }
+
+ public String getTestNGArtifactName()
+ {
+ return testNGArtifactName;
+ }
+
+ public void setTestNGArtifactName( String testNGArtifactName )
+ {
+ this.testNGArtifactName = testNGArtifactName;
+ }
+
+ public int getThreadCount()
+ {
+ return threadCount;
+ }
+
+ public void setThreadCount( int threadCount )
+ {
+ this.threadCount = threadCount;
+ }
+
+ public boolean getPerCoreThreadCount()
+ {
+ return perCoreThreadCount;
+ }
+
+ public void setPerCoreThreadCount( boolean perCoreThreadCount )
+ {
+ this.perCoreThreadCount = perCoreThreadCount;
+ }
+
+ public boolean getUseUnlimitedThreads()
+ {
+ return useUnlimitedThreads;
+ }
+
+ public void setUseUnlimitedThreads( boolean useUnlimitedThreads )
+ {
+ this.useUnlimitedThreads = useUnlimitedThreads;
+ }
+
+ public String getParallel()
+ {
+ return parallel;
+ }
+
+ public void setParallel( String parallel )
+ {
+ this.parallel = parallel;
+ }
+
+ public boolean isTrimStackTrace()
+ {
+ return trimStackTrace;
+ }
+
+ public void setTrimStackTrace( boolean trimStackTrace )
+ {
+ this.trimStackTrace = trimStackTrace;
+ }
+
+ public ArtifactResolver getArtifactResolver()
+ {
+ return artifactResolver;
+ }
+
+ public void setArtifactResolver( ArtifactResolver artifactResolver )
+ {
+ this.artifactResolver = artifactResolver;
+ }
+
+ public ArtifactFactory getArtifactFactory()
+ {
+ return artifactFactory;
+ }
+
+ public void setArtifactFactory( ArtifactFactory artifactFactory )
+ {
+ this.artifactFactory = artifactFactory;
+ }
+
+ public List getRemoteRepositories()
+ {
+ return remoteRepositories;
+ }
+
+ public void setRemoteRepositories( List remoteRepositories )
+ {
+ this.remoteRepositories = remoteRepositories;
+ }
+
+ public ArtifactMetadataSource getMetadataSource()
+ {
+ return metadataSource;
+ }
+
+ public void setMetadataSource( ArtifactMetadataSource metadataSource )
+ {
+ this.metadataSource = metadataSource;
+ }
+
+ public Properties getOriginalSystemProperties()
+ {
+ return originalSystemProperties;
+ }
+
+ public void setOriginalSystemProperties( Properties
originalSystemProperties )
+ {
+ this.originalSystemProperties = originalSystemProperties;
+ }
+
+ public Properties getInternalSystemProperties()
+ {
+ return internalSystemProperties;
+ }
+
+ public void setInternalSystemProperties( Properties
internalSystemProperties )
+ {
+ this.internalSystemProperties = internalSystemProperties;
+ }
+
+ public boolean isDisableXmlReport()
+ {
+ return disableXmlReport;
+ }
+
+ public void setDisableXmlReport( boolean disableXmlReport )
+ {
+ this.disableXmlReport = disableXmlReport;
+ }
+
+ public boolean isUseSystemClassLoader()
+ {
+ return useSystemClassLoader;
+ }
+
+ public void setUseSystemClassLoader( boolean useSystemClassLoader )
+ {
+ this.useSystemClassLoader = useSystemClassLoader;
+ }
+
+ public boolean isUseManifestOnlyJar()
+ {
+ return useManifestOnlyJar;
+ }
+
+ public void setUseManifestOnlyJar( boolean useManifestOnlyJar )
+ {
+ this.useManifestOnlyJar = useManifestOnlyJar;
+ }
+
+ public boolean isEnableAssertions()
+ {
+ return enableAssertions;
+ }
+
+ public void setEnableAssertions( boolean enableAssertions )
+ {
+ this.enableAssertions = enableAssertions;
+ }
+
+ public MavenSession getSession()
+ {
+ return session;
+ }
+
+ public void setSession( MavenSession session )
+ {
+ this.session = session;
+ }
+
+ public String getObjectFactory()
+ {
+ return objectFactory;
+ }
+
+ public void setObjectFactory( String objectFactory )
+ {
+ this.objectFactory = objectFactory;
+ }
+
+ public ToolchainManager getToolchainManager()
+ {
+ return toolchainManager;
+ }
+
+ public void setToolchainManager( ToolchainManager toolchainManager )
+ {
+ this.toolchainManager = toolchainManager;
+ }
+
+ public boolean isMavenParallel()
+ {
+ return parallelMavenExecution != null &&
parallelMavenExecution.booleanValue();
+ }
+
+ public String getRunOrder()
+ {
+ return runOrder;
+ }
+
+ public void setRunOrder( String runOrder )
+ {
+ this.runOrder = runOrder;
+ }
+
+ protected void addPluginSpecificChecksumItems( ChecksumCalculator
checksum )
+ {
+ }
+
+
+ static final class ClassAndMethodNameAndExecutionTime {
+ private final String classAndMethodName;
+ private final double executionTime;
+
+ ClassAndMethodNameAndExecutionTime(final String
classAndMethodName, final double executionTime) {
+ this.classAndMethodName = classAndMethodName;
+ this.executionTime = executionTime; // in seconds
+ }
+
+ String getClassAndMethodName() { return classAndMethodName; }
+ double getExecutionTime() { return executionTime; }
+
+ @Override
+ public int hashCode() { return classAndMethodName.hashCode(); }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (!(o instanceof ClassAndMethodNameAndExecutionTime))
+ return false;
+
+ final ClassAndMethodNameAndExecutionTime other =
(ClassAndMethodNameAndExecutionTime)o;
+ return
other.getClassAndMethodName().equals(classAndMethodName);
+ }
+
+ @Override
+ public String toString() {
+ return "Class/method name: " + classAndMethodName + ",
execution time: " + executionTime + "s";
+ }
+ }
}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.