Skip to content

Commit b16652e

Browse files
authored
Merge pull request #12 from applandinc/feat/refine-appmap-agent-dependency
feat: Refine appmap agent dependency
2 parents a0a9424 + d4418ac commit b16652e

File tree

11 files changed

+176
-149
lines changed

11 files changed

+176
-149
lines changed

build.gradle

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,38 @@ plugins {
33
id 'java'
44
id 'java-gradle-plugin'
55
id 'idea'
6+
id 'maven-publish'
67
id 'io.github.gradle-nexus.publish-plugin' version '1.0.0'
78
id 'com.gradle.plugin-publish' version '0.14.0'
89
id 'signing'
910
}
1011

11-
def defGroupId = 'com.appland'
12-
def defArtifactId = 'appmap-gradle-plugin'
13-
def defName = 'AppMap Gradle Plugin'
14-
def defVersion = "1.0.2"
15-
def defDescription = 'Gradle plugin to record AppMaps'
16-
def defGitSlug = "applandinc/appmap-gradle-plugin"
17-
def defMavenRepo = 'https://s01.oss.sonatype.org'
18-
19-
def paramSignKey = findProperty('signingKey')
20-
def paramSignPassword = findProperty("signingPassword")
21-
def paramRepoUsername = findProperty('ossrhUsername')
22-
def paramRepoPassword = findProperty('ossrhPassword')
23-
def paramGradleKey = findProperty('gradlePublishKey')
24-
def paramGradleSecret = findProperty('gradlePublishSecret')
25-
def paramDescription = findProperty('artifactDescription') ?: defDescription
26-
def paramName = findProperty('artifactName') ?: defName
27-
def paramGroupId = findProperty('publicationGroupId') ?: defGroupId
28-
def paramArtifactId = findProperty('publicationArtifactId') ?: defArtifactId
29-
def paramGitSlug = System.getenv("TRAVIS_REPO_SLUG") ?: defGitSlug
30-
def paramMavenRepo = findProperty('mavenRepo') ?: defMavenRepo
31-
32-
def paramVersion = findProperty('paramVersion')
33-
def travisVersion = System.getenv("TRAVIS_BRANCH")
34-
def versionLikeRegexp = /^\d+\.\d+.*/
35-
def travisVersionOK = travisVersion && (travisVersion ==~ versionLikeRegexp)
36-
37-
paramVersion = paramVersion ?: ( travisVersionOK ? travisVersion : defVersion )
12+
def defGroupId = 'com.appland'
13+
def defArtifactId = 'appmap-gradle-plugin'
14+
def defName = 'AppMap Gradle Plugin'
15+
def defVersion = "1.0.2"
16+
def defDescription = 'Gradle plugin to record AppMaps'
17+
def defGitSlug = "applandinc/appmap-gradle-plugin"
18+
def defMavenRepo = 'https://s01.oss.sonatype.org'
19+
20+
def paramSignKey = findProperty('signingKey')
21+
def paramSignPassword = findProperty("signingPassword")
22+
def paramRepoUsername = findProperty('ossrhUsername')
23+
def paramRepoPassword = findProperty('ossrhPassword')
24+
def paramGradleKey = findProperty('gradlePublishKey')
25+
def paramGradleSecret = findProperty('gradlePublishSecret')
26+
def paramDescription = findProperty('artifactDescription') ?: defDescription
27+
def paramName = findProperty('artifactName') ?: defName
28+
def paramGroupId = findProperty('publicationGroupId') ?: defGroupId
29+
def paramGitSlug = System.getenv("TRAVIS_REPO_SLUG") ?: defGitSlug
30+
def paramMavenRepo = findProperty('mavenRepo') ?: defMavenRepo
31+
32+
def paramVersion = findProperty('paramVersion')
33+
def travisVersion = System.getenv("TRAVIS_BRANCH")
34+
def versionLikeRegexp = /^\d+\.\d+.*/
35+
def travisVersionOK = travisVersion && (travisVersion ==~ versionLikeRegexp)
36+
37+
paramVersion = paramVersion ?: (travisVersionOK ? travisVersion : defVersion)
3838
version = paramVersion
3939
group = paramGroupId
4040

@@ -51,8 +51,9 @@ dependencies {
5151
localGroovy()
5252
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
5353
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
54+
implementation 'com.appland:appmap-agent:[1.3, 2.0)'
5455
implementation 'commons-lang:commons-lang:2.6'
55-
implementation 'com.google.guava:guava:30.1.1-jre'
56+
implementation 'com.google.guava:guava:30.1.1-jre'
5657
implementation 'org.assertj:assertj-core:3.15.0'
5758
}
5859

@@ -84,7 +85,7 @@ gradlePlugin {
8485
id = 'com.appland.appmap'
8586
displayName = 'AppMap plugin'
8687
description = 'Interactive maps and architecture analysis to help you write better Java.'
87-
implementationClass = 'com.appland.appmap.AppmapPlugin'
88+
implementationClass = 'com.appland.appmap.gradle.AppMapPlugin'
8889
}
8990
}
9091
}
@@ -100,24 +101,23 @@ publishing {
100101
publications {
101102
withType(MavenPublication) {
102103
pom {
103-
name = paramName
104+
name = paramName
104105
description = paramDescription
105-
version = paramVersion
106-
url = "https://appland.com"
106+
version = paramVersion
107+
url = "https://appland.com"
107108

108109
licenses {
109110
license {
110111
name = "MIT"
111-
url = "https://raw.githubusercontent.com/$paramGitSlug/master/LICENSE"
112+
url = "https://raw.githubusercontent.com/$paramGitSlug/master/LICENSE"
112113
}
113114
}
114115
developers {
115116
developer {
116-
// id = "kgilpin"
117117
name = "Kevin Gilpin"
118118
119119
organization = "AppLand Inc."
120-
url="https://dev.to/kgilpin"
120+
url = "https://dev.to/kgilpin"
121121
}
122122
}
123123
scm {
@@ -133,10 +133,10 @@ publishing {
133133
nexusPublishing {
134134
repositories {
135135
sonatype {
136-
nexusUrl = uri(paramMavenRepo + "/service/local/")
137-
snapshotRepositoryUrl = uri(paramMavenRepo + "/content/repositories/snapshots" )
138-
username = paramRepoUsername
139-
password = paramRepoPassword
136+
nexusUrl = uri(paramMavenRepo + "/service/local/")
137+
snapshotRepositoryUrl = uri(paramMavenRepo + "/content/repositories/snapshots")
138+
username = paramRepoUsername
139+
password = paramRepoPassword
140140
}
141141
}
142142
}

src/main/java/com/appland/appmap/CleanOutputDirectoryAction.java

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/main/java/com/appland/appmap/AgentCommandLineLoader.java renamed to src/main/java/com/appland/appmap/gradle/AgentCommandLineLoader.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.appland.appmap;
1+
package com.appland.appmap.gradle;
22

33
import static java.lang.String.format;
44

@@ -16,16 +16,18 @@
1616
import org.gradle.util.RelativePathUtil;
1717

1818
/**
19-
* This class is the actual responsible of building the JVM args to run the Appmap Agent.
19+
* This class is the actual responsible of building the JVM args to run the AppMap Agent.
2020
*/
2121
public class AgentCommandLineLoader implements CommandLineArgumentProvider, Named {
2222

23+
static final String DEFAULT_CONFIG_FILE = "appmap.yml";
24+
2325
private static final Logger LOGGER = Logging.getLogger(CommandLineArgumentProvider.class);
24-
private static final List<String> DEBUG_FLAGS = Arrays.asList("hooks", "locals", "http");
26+
private static final List<String> DEBUG_FLAGS = Arrays.asList("debug", "hooks", "locals", "http");
2527

26-
private final AppmapPluginExtension appmap;
28+
private final AppMapPluginExtension appmap;
2729

28-
public AgentCommandLineLoader(AppmapPluginExtension appmap) {
30+
public AgentCommandLineLoader(AppMapPluginExtension appmap) {
2931
this.appmap = appmap;
3032
}
3133

@@ -55,7 +57,7 @@ public List<String> getAsJvmArg() {
5557
+ appmap.getConfigFile().get().getAsFile().getPath());
5658
}
5759
if (appmap.shouldSkip()) {
58-
LOGGER.warn("Appmap task was executed but but is disable, skip property set to " + appmap
60+
LOGGER.warn("AppMap task was executed but but is disabled, 'skip' property set to " + appmap
5961
.shouldSkip());
6062
return new ArrayList<>();
6163
} else {
@@ -66,8 +68,11 @@ public List<String> getAsJvmArg() {
6668

6769
List<String> argumentLn = new ArrayList<>();
6870
argumentLn.add(javaAgentArg);
69-
argumentLn.add("-Dappmap.config.file=" + appmap.getConfigFile().get().toString());
70-
argumentLn.add("-Dappmap.output.directory=" + appmap.getOutputDirectory().get().toString());
71+
72+
if ( appmap.getConfigFile().isPresent() ) {
73+
argumentLn.add("-Dappmap.config.file=" + appmap.getConfigFile().get());
74+
}
75+
argumentLn.add("-Dappmap.output.directory=" + appmap.getOutputDirectory().get());
7176
argumentLn.add("-Dappmap.event.valueSize=" + appmap.getEventValueSize());
7277
argumentLn.addAll(buildDebugParams());
7378
LOGGER.lifecycle("Arguments line set to " + Joiner.on(",").join(argumentLn));
@@ -80,14 +85,23 @@ private List<String> buildDebugParams() {
8085
if (appmap.getDebug() != null && !appmap.getDebug().isEmpty()) {
8186
final List<String> debugTokens = new ArrayList<>(
8287
Arrays.asList(appmap.getDebug().split("[,|\\s]")));
88+
89+
boolean hasDebug = false;
8390
for (String token : debugTokens) {
8491
if (DEBUG_FLAGS.contains(token)) {
85-
debugArgs.add("-Dappmap.debug." + token);
92+
hasDebug = true;
93+
if (token.equals("debug")) {
94+
debugArgs.add("-Dappmap.debug");
95+
} else {
96+
debugArgs.add("-Dappmap.debug." + token);
97+
}
8698
}
8799
}
88-
debugArgs.add(0, "-Dappmap.debug");
89-
debugArgs.add(0, "-Dappmap.debug.file=" + StringEscapeUtils
90-
.escapeJava(format("%s", appmap.getDebugFile())));
100+
101+
if (hasDebug) {
102+
debugArgs.add(0, "-Dappmap.debug.file=" + StringEscapeUtils
103+
.escapeJava(format("%s", appmap.getDebugFile())));
104+
}
91105
}
92106
return debugArgs;
93107
}

src/main/java/com/appland/appmap/AppmapPlugin.java renamed to src/main/java/com/appland/appmap/gradle/AppMapPlugin.java

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
package com.appland.appmap;
1+
package com.appland.appmap.gradle;
22

33
import org.gradle.api.Plugin;
44
import org.gradle.api.Project;
55
import org.gradle.api.artifacts.Configuration;
6-
import org.gradle.api.file.FileSystemOperations;
7-
import org.gradle.api.internal.project.ProjectInternal;
86
import org.gradle.api.plugins.JavaPlugin;
97
import org.gradle.api.plugins.ReportingBasePlugin;
108
import org.gradle.language.base.plugins.LifecycleBasePlugin;
119

1210
/**
1311
* The actual plugin definition for appmap plugin.
1412
*/
15-
public class AppmapPlugin implements Plugin<Project> {
16-
17-
public static final String DEFAULT_AGENT_VERSION = "latest.release";
13+
public class AppMapPlugin implements Plugin<Project> {
14+
public static final String DEFAULT_AGENT_VERSION = "[1.3, 2.0)";
1815
public static final String AGENT_CONFIGURATION_NAME = "appmapAgent";
1916
public static final String PLUGIN_EXTENSION_NAME = "appmap";
2017
private Project project;
@@ -27,29 +24,27 @@ public void apply(Project project) {
2724
final Configuration config = project.getConfigurations().getAt(AGENT_CONFIGURATION_NAME);
2825
config.setVisible(false);
2926
config.setTransitive(true);
30-
config.setDescription("Appmap agent to generate app map data.");
27+
config.setDescription("AppMap agent to generate app map data.");
3128
config.defaultDependencies(dependencies ->
3229
dependencies.add(
3330
project.getDependencies().create("com.appland:appmap-agent:" + DEFAULT_AGENT_VERSION)
3431
)
3532
);
36-
AppmapPluginExtension extension = project.getExtensions()
37-
.create(PLUGIN_EXTENSION_NAME, AppmapPluginExtension.class, project, config);
33+
AppMapPluginExtension extension = project.getExtensions()
34+
.create(PLUGIN_EXTENSION_NAME, AppMapPluginExtension.class, project, config);
3835
//extension.setAgentVersion(DEFAULT_AGENT_VERSION);*/
39-
addAppmapGradleTasks(extension);
36+
addAppMapGradleTasks(extension);
4037
}
4138

4239
private void registerAgentConfiguration() {
4340
Configuration agentConf = project.getConfigurations().create(AGENT_CONFIGURATION_NAME);
4441
agentConf.setVisible(false);
4542
agentConf.setTransitive(true);
46-
agentConf.setDescription("Appmap agent to generate app map data.");
43+
agentConf.setDescription("AppMap agent to generate app map data.");
4744
}
4845

49-
private void addAppmapGradleTasks(AppmapPluginExtension extension) {
50-
project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
51-
addAppmapTasks(extension);
52-
});
46+
private void addAppMapGradleTasks(AppMapPluginExtension extension) {
47+
project.getPlugins().withType(JavaPlugin.class, javaPlugin -> addAppMapTasks(extension));
5348
}
5449

5550
/**
@@ -58,37 +53,45 @@ private void addAppmapGradleTasks(AppmapPluginExtension extension) {
5853
*
5954
* @param extension holds the config parameters for the plugin.
6055
*/
61-
private void addAppmapTasks(AppmapPluginExtension extension) {
56+
private void addAppMapTasks(AppMapPluginExtension extension) {
6257
project.getTasks().register(
6358
"appmap",
64-
AppmapTask.class,
59+
AppMapTask.class,
6560
prepareAgentTask -> {
6661
prepareAgentTask.doFirst(
6762
new ValidateConfigAction(extension.getConfigFile().getAsFile())
6863
);
69-
prepareAgentTask.doLast(
70-
new CleanOutputDirectoryAction(
71-
((ProjectInternal) project).getServices().get(FileSystemOperations.class),
72-
extension.getOutputDirectory().getAsFile())
73-
);
74-
prepareAgentTask.doLast(new LoadAppmapAgentAction(project, extension));
64+
prepareAgentTask.doLast(new LoadAppMapAgentAction(project, extension));
7565
prepareAgentTask.setGroup(LifecycleBasePlugin.BUILD_GROUP);
7666
prepareAgentTask.setDescription(
77-
String.format("Attaches Appmap Agent to the Test task")
67+
String.format("Injects AppMap Agent JVM settings to the 'test' task")
7868
);
7969
});
8070

8171
project.getTasks().register(
82-
"validate-config",
72+
"appmap-validate-config",
8373
validateConfigTask -> {
8474
validateConfigTask.doFirst(
8575
new ValidateConfigAction(extension.getConfigFile().getAsFile())
8676
);
8777
validateConfigTask.setGroup(LifecycleBasePlugin.BUILD_GROUP);
8878
validateConfigTask.setDescription(
89-
String.format("Searches Appmap Agent config file and validates it")
79+
String.format("Validates the AppMap Agent configuration")
9080
);
9181
}
9282
);
83+
84+
project.getTasks().register(
85+
"appmap-print-jar-path",
86+
agentJarPathTask -> {
87+
agentJarPathTask.doFirst(
88+
new PrintJarPathAction(extension)
89+
);
90+
agentJarPathTask.setGroup(LifecycleBasePlugin.BUILD_GROUP);
91+
agentJarPathTask.setDescription(
92+
String.format("Prints the file path of the AppMap Agent JAR")
93+
);
94+
}
95+
);
9396
}
9497
}

0 commit comments

Comments
 (0)