mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-02-13 05:10:44 +08:00
add maven plugin, refactor modules
This commit is contained in:
parent
26712108d6
commit
33a16f34af
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.testable</groupId>
|
<groupId>com.alibaba.testable</groupId>
|
||||||
<artifactId>core</artifactId>
|
<artifactId>testable-core</artifactId>
|
||||||
<version>${testable.version}</version>
|
<version>${testable.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
@ -56,12 +56,17 @@
|
|||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>com.alibaba.testable</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>testable-maven-plugin</artifactId>
|
||||||
<configuration>
|
<version>${testable.version}</version>
|
||||||
<!-- <argLine>@{argLine} -javaagent:${project.build.directory}/test-classes/testable-agent.jar</argLine>-->
|
<executions>
|
||||||
<argLine>@{argLine} -javaagent:${settings.localRepository}/com/alibaba/testable/agent/${testable.version}/agent-${testable.version}.jar</argLine>
|
<execution>
|
||||||
</configuration>
|
<id>prepare</id>
|
||||||
|
<goals>
|
||||||
|
<goal>prepare</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.jacoco</groupId>
|
<groupId>org.jacoco</groupId>
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.testable</groupId>
|
<groupId>com.alibaba.testable</groupId>
|
||||||
<artifactId>core</artifactId>
|
<artifactId>testable-core</artifactId>
|
||||||
<version>${testable.version}</version>
|
<version>${testable.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
@ -67,11 +67,17 @@
|
|||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>com.alibaba.testable</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>testable-maven-plugin</artifactId>
|
||||||
<configuration>
|
<version>${testable.version}</version>
|
||||||
<argLine>@{argLine} -javaagent:${settings.localRepository}/com/alibaba/testable/agent/${testable.version}/agent-${testable.version}.jar</argLine>
|
<executions>
|
||||||
</configuration>
|
<execution>
|
||||||
|
<id>prepare</id>
|
||||||
|
<goals>
|
||||||
|
<goal>prepare</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
|
5
pom.xml
5
pom.xml
@ -9,8 +9,9 @@
|
|||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>agent</module>
|
<module>testable-agent</module>
|
||||||
<module>core</module>
|
<module>testable-core</module>
|
||||||
|
<module>testable-maven-plugin</module>
|
||||||
<module>demo</module>
|
<module>demo</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.alibaba.testable</groupId>
|
<groupId>com.alibaba.testable</groupId>
|
||||||
<artifactId>agent</artifactId>
|
<artifactId>testable-agent</artifactId>
|
||||||
<version>0.1.1-SNAPSHOT</version>
|
<version>0.1.1-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>testable-agent</name>
|
<name>testable-agent</name>
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<description>Unit test enhancement toolkit</description>
|
<description>Unit test enhancement toolkit</description>
|
||||||
<groupId>com.alibaba.testable</groupId>
|
<groupId>com.alibaba.testable</groupId>
|
||||||
<artifactId>core</artifactId>
|
<artifactId>testable-core</artifactId>
|
||||||
<version>0.1.1-SNAPSHOT</version>
|
<version>0.1.1-SNAPSHOT</version>
|
||||||
<name>testable-core</name>
|
<name>testable-core</name>
|
||||||
|
|
||||||
@ -65,7 +65,7 @@
|
|||||||
<outputDirectory>${basedir}/target/classes</outputDirectory>
|
<outputDirectory>${basedir}/target/classes</outputDirectory>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>${basedir}/../agent/target</directory>
|
<directory>${basedir}/../testable-agent/target</directory>
|
||||||
<includes>
|
<includes>
|
||||||
<include>testable-agent.jar</include>
|
<include>testable-agent.jar</include>
|
||||||
</includes>
|
</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