mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-02-09 03:10:17 +08:00
add maven plugin, refactor modules
This commit is contained in:
parent
26712108d6
commit
33a16f34af
@ -27,7 +27,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.testable</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<artifactId>testable-core</artifactId>
|
||||
<version>${testable.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
@ -56,12 +56,17 @@
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- <argLine>@{argLine} -javaagent:${project.build.directory}/test-classes/testable-agent.jar</argLine>-->
|
||||
<argLine>@{argLine} -javaagent:${settings.localRepository}/com/alibaba/testable/agent/${testable.version}/agent-${testable.version}.jar</argLine>
|
||||
</configuration>
|
||||
<groupId>com.alibaba.testable</groupId>
|
||||
<artifactId>testable-maven-plugin</artifactId>
|
||||
<version>${testable.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>prepare</id>
|
||||
<goals>
|
||||
<goal>prepare</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
|
@ -40,7 +40,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.testable</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<artifactId>testable-core</artifactId>
|
||||
<version>${testable.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
@ -67,11 +67,17 @@
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<argLine>@{argLine} -javaagent:${settings.localRepository}/com/alibaba/testable/agent/${testable.version}/agent-${testable.version}.jar</argLine>
|
||||
</configuration>
|
||||
<groupId>com.alibaba.testable</groupId>
|
||||
<artifactId>testable-maven-plugin</artifactId>
|
||||
<version>${testable.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>prepare</id>
|
||||
<goals>
|
||||
<goal>prepare</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
|
5
pom.xml
5
pom.xml
@ -9,8 +9,9 @@
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>agent</module>
|
||||
<module>core</module>
|
||||
<module>testable-agent</module>
|
||||
<module>testable-core</module>
|
||||
<module>testable-maven-plugin</module>
|
||||
<module>demo</module>
|
||||
</modules>
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.alibaba.testable</groupId>
|
||||
<artifactId>agent</artifactId>
|
||||
<artifactId>testable-agent</artifactId>
|
||||
<version>0.1.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>testable-agent</name>
|
@ -6,7 +6,7 @@
|
||||
|
||||
<description>Unit test enhancement toolkit</description>
|
||||
<groupId>com.alibaba.testable</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<artifactId>testable-core</artifactId>
|
||||
<version>0.1.1-SNAPSHOT</version>
|
||||
<name>testable-core</name>
|
||||
|
||||
@ -65,7 +65,7 @@
|
||||
<outputDirectory>${basedir}/target/classes</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${basedir}/../agent/target</directory>
|
||||
<directory>${basedir}/../testable-agent/target</directory>
|
||||
<includes>
|
||||
<include>testable-agent.jar</include>
|
||||
</includes>
|
44
testable-maven-plugin/pom.xml
Normal file
44
testable-maven-plugin/pom.xml
Normal file
@ -0,0 +1,44 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.alibaba.testable</groupId>
|
||||
<artifactId>testable-maven-plugin</artifactId>
|
||||
<packaging>maven-plugin</packaging>
|
||||
<version>0.1.1-SNAPSHOT</version>
|
||||
<name>testable-maven-plugin</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-core</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.plugin-tools</groupId>
|
||||
<artifactId>maven-plugin-annotations</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.testable</groupId>
|
||||
<artifactId>testable-agent</artifactId>
|
||||
<version>0.1.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-plugin-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -0,0 +1,69 @@
|
||||
package com.alibaba.testable;
|
||||
|
||||
import org.apache.maven.artifact.Artifact;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Goal which prepare testable agent.
|
||||
*
|
||||
* @author flin
|
||||
*/
|
||||
@Mojo(name = "prepare", defaultPhase = LifecyclePhase.INITIALIZE,
|
||||
requiresDependencyResolution = ResolutionScope.RUNTIME, threadSafe = true)
|
||||
public class TestableMojo extends AbstractMojo
|
||||
{
|
||||
/**
|
||||
* Maven project.
|
||||
*/
|
||||
@Parameter(property = "project", readonly = true)
|
||||
private MavenProject project;
|
||||
/**
|
||||
* Map of plugin artifacts.
|
||||
*/
|
||||
@Parameter(property = "plugin.artifactMap", required = true, readonly = true)
|
||||
private Map<String, Artifact> pluginArtifactMap;
|
||||
/**
|
||||
* Name of the Testable Agent artifact.
|
||||
*/
|
||||
private static final String AGENT_ARTIFACT_NAME = "com.alibaba.testable:testable-agent";
|
||||
/**
|
||||
* Name of the property used in maven-osgi-test-plugin.
|
||||
*/
|
||||
private static final String TYCHO_ARG_LINE = "tycho.testArgLine";
|
||||
/**
|
||||
* Name of the property used in maven-surefire-plugin.
|
||||
*/
|
||||
private static final String SUREFIRE_ARG_LINE = "argLine";
|
||||
/**
|
||||
* Name of eclipse test plugin
|
||||
*/
|
||||
private static final String ECLIPSE_TEST_PLUGIN = "eclipse-test-plugin";
|
||||
|
||||
public void execute() throws MojoExecutionException
|
||||
{
|
||||
final String testArgsPropertyKey = getEffectivePropertyKey();
|
||||
final Properties projectProperties = project.getProperties();
|
||||
final String oldArgs = projectProperties.getProperty(testArgsPropertyKey);
|
||||
final String newArgs = (oldArgs == null) ? getAgentJarArgs().trim() : oldArgs + getAgentJarArgs();
|
||||
getLog().info(testArgsPropertyKey + " set to " + newArgs);
|
||||
projectProperties.setProperty(testArgsPropertyKey, newArgs);
|
||||
}
|
||||
|
||||
private String getAgentJarArgs() {
|
||||
final Artifact testableAgentArtifact = pluginArtifactMap.get(AGENT_ARTIFACT_NAME);
|
||||
return " -javaagent:" + testableAgentArtifact.getFile().getAbsolutePath();
|
||||
}
|
||||
|
||||
private String getEffectivePropertyKey() {
|
||||
return ECLIPSE_TEST_PLUGIN.equals(project.getPackaging()) ? TYCHO_ARG_LINE : SUREFIRE_ARG_LINE;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user