Skip to content

Commit

Permalink
Merge pull request #12 from applandinc/feat/refine-appmap-agent-depen…
Browse files Browse the repository at this point in the history
…dency

feat: Refine appmap agent dependency
  • Loading branch information
kgilpin authored Aug 9, 2021
2 parents a0a9424 + d4418ac commit b16652e
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 149 deletions.
78 changes: 39 additions & 39 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,38 @@ plugins {
id 'java'
id 'java-gradle-plugin'
id 'idea'
id 'maven-publish'
id 'io.github.gradle-nexus.publish-plugin' version '1.0.0'
id 'com.gradle.plugin-publish' version '0.14.0'
id 'signing'
}

def defGroupId = 'com.appland'
def defArtifactId = 'appmap-gradle-plugin'
def defName = 'AppMap Gradle Plugin'
def defVersion = "1.0.2"
def defDescription = 'Gradle plugin to record AppMaps'
def defGitSlug = "applandinc/appmap-gradle-plugin"
def defMavenRepo = 'https://s01.oss.sonatype.org'

def paramSignKey = findProperty('signingKey')
def paramSignPassword = findProperty("signingPassword")
def paramRepoUsername = findProperty('ossrhUsername')
def paramRepoPassword = findProperty('ossrhPassword')
def paramGradleKey = findProperty('gradlePublishKey')
def paramGradleSecret = findProperty('gradlePublishSecret')
def paramDescription = findProperty('artifactDescription') ?: defDescription
def paramName = findProperty('artifactName') ?: defName
def paramGroupId = findProperty('publicationGroupId') ?: defGroupId
def paramArtifactId = findProperty('publicationArtifactId') ?: defArtifactId
def paramGitSlug = System.getenv("TRAVIS_REPO_SLUG") ?: defGitSlug
def paramMavenRepo = findProperty('mavenRepo') ?: defMavenRepo

def paramVersion = findProperty('paramVersion')
def travisVersion = System.getenv("TRAVIS_BRANCH")
def versionLikeRegexp = /^\d+\.\d+.*/
def travisVersionOK = travisVersion && (travisVersion ==~ versionLikeRegexp)

paramVersion = paramVersion ?: ( travisVersionOK ? travisVersion : defVersion )
def defGroupId = 'com.appland'
def defArtifactId = 'appmap-gradle-plugin'
def defName = 'AppMap Gradle Plugin'
def defVersion = "1.0.2"
def defDescription = 'Gradle plugin to record AppMaps'
def defGitSlug = "applandinc/appmap-gradle-plugin"
def defMavenRepo = 'https://s01.oss.sonatype.org'

def paramSignKey = findProperty('signingKey')
def paramSignPassword = findProperty("signingPassword")
def paramRepoUsername = findProperty('ossrhUsername')
def paramRepoPassword = findProperty('ossrhPassword')
def paramGradleKey = findProperty('gradlePublishKey')
def paramGradleSecret = findProperty('gradlePublishSecret')
def paramDescription = findProperty('artifactDescription') ?: defDescription
def paramName = findProperty('artifactName') ?: defName
def paramGroupId = findProperty('publicationGroupId') ?: defGroupId
def paramGitSlug = System.getenv("TRAVIS_REPO_SLUG") ?: defGitSlug
def paramMavenRepo = findProperty('mavenRepo') ?: defMavenRepo

def paramVersion = findProperty('paramVersion')
def travisVersion = System.getenv("TRAVIS_BRANCH")
def versionLikeRegexp = /^\d+\.\d+.*/
def travisVersionOK = travisVersion && (travisVersion ==~ versionLikeRegexp)

paramVersion = paramVersion ?: (travisVersionOK ? travisVersion : defVersion)
version = paramVersion
group = paramGroupId

Expand All @@ -51,8 +51,9 @@ dependencies {
localGroovy()
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
implementation 'com.appland:appmap-agent:[1.3, 2.0)'
implementation 'commons-lang:commons-lang:2.6'
implementation 'com.google.guava:guava:30.1.1-jre'
implementation 'com.google.guava:guava:30.1.1-jre'
implementation 'org.assertj:assertj-core:3.15.0'
}

Expand Down Expand Up @@ -84,7 +85,7 @@ gradlePlugin {
id = 'com.appland.appmap'
displayName = 'AppMap plugin'
description = 'Interactive maps and architecture analysis to help you write better Java.'
implementationClass = 'com.appland.appmap.AppmapPlugin'
implementationClass = 'com.appland.appmap.gradle.AppMapPlugin'
}
}
}
Expand All @@ -100,24 +101,23 @@ publishing {
publications {
withType(MavenPublication) {
pom {
name = paramName
name = paramName
description = paramDescription
version = paramVersion
url = "https://appland.com"
version = paramVersion
url = "https://appland.com"

licenses {
license {
name = "MIT"
url = "https://github.com/raw/$paramGitSlug/master/LICENSE"
url = "https://github.com/raw/$paramGitSlug/master/LICENSE"
}
}
developers {
developer {
// id = "kgilpin"
name = "Kevin Gilpin"
email = "kevin@appland.com"
organization = "AppLand Inc."
url="https://dev.to/kgilpin"
url = "https://dev.to/kgilpin"
}
}
scm {
Expand All @@ -133,10 +133,10 @@ publishing {
nexusPublishing {
repositories {
sonatype {
nexusUrl = uri(paramMavenRepo + "/service/local/")
snapshotRepositoryUrl = uri(paramMavenRepo + "/content/repositories/snapshots" )
username = paramRepoUsername
password = paramRepoPassword
nexusUrl = uri(paramMavenRepo + "/service/local/")
snapshotRepositoryUrl = uri(paramMavenRepo + "/content/repositories/snapshots")
username = paramRepoUsername
password = paramRepoPassword
}
}
}
Expand Down
35 changes: 0 additions & 35 deletions src/main/java/com/appland/appmap/CleanOutputDirectoryAction.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.appland.appmap;
package com.appland.appmap.gradle;

import static java.lang.String.format;

Expand All @@ -16,16 +16,18 @@
import org.gradle.util.RelativePathUtil;

/**
* This class is the actual responsible of building the JVM args to run the Appmap Agent.
* This class is the actual responsible of building the JVM args to run the AppMap Agent.
*/
public class AgentCommandLineLoader implements CommandLineArgumentProvider, Named {

static final String DEFAULT_CONFIG_FILE = "appmap.yml";

private static final Logger LOGGER = Logging.getLogger(CommandLineArgumentProvider.class);
private static final List<String> DEBUG_FLAGS = Arrays.asList("hooks", "locals", "http");
private static final List<String> DEBUG_FLAGS = Arrays.asList("debug", "hooks", "locals", "http");

private final AppmapPluginExtension appmap;
private final AppMapPluginExtension appmap;

public AgentCommandLineLoader(AppmapPluginExtension appmap) {
public AgentCommandLineLoader(AppMapPluginExtension appmap) {
this.appmap = appmap;
}

Expand Down Expand Up @@ -55,7 +57,7 @@ public List<String> getAsJvmArg() {
+ appmap.getConfigFile().get().getAsFile().getPath());
}
if (appmap.shouldSkip()) {
LOGGER.warn("Appmap task was executed but but is disable, skip property set to " + appmap
LOGGER.warn("AppMap task was executed but but is disabled, 'skip' property set to " + appmap
.shouldSkip());
return new ArrayList<>();
} else {
Expand All @@ -66,8 +68,11 @@ public List<String> getAsJvmArg() {

List<String> argumentLn = new ArrayList<>();
argumentLn.add(javaAgentArg);
argumentLn.add("-Dappmap.config.file=" + appmap.getConfigFile().get().toString());
argumentLn.add("-Dappmap.output.directory=" + appmap.getOutputDirectory().get().toString());

if ( appmap.getConfigFile().isPresent() ) {
argumentLn.add("-Dappmap.config.file=" + appmap.getConfigFile().get());
}
argumentLn.add("-Dappmap.output.directory=" + appmap.getOutputDirectory().get());
argumentLn.add("-Dappmap.event.valueSize=" + appmap.getEventValueSize());
argumentLn.addAll(buildDebugParams());
LOGGER.lifecycle("Arguments line set to " + Joiner.on(",").join(argumentLn));
Expand All @@ -80,14 +85,23 @@ private List<String> buildDebugParams() {
if (appmap.getDebug() != null && !appmap.getDebug().isEmpty()) {
final List<String> debugTokens = new ArrayList<>(
Arrays.asList(appmap.getDebug().split("[,|\\s]")));

boolean hasDebug = false;
for (String token : debugTokens) {
if (DEBUG_FLAGS.contains(token)) {
debugArgs.add("-Dappmap.debug." + token);
hasDebug = true;
if (token.equals("debug")) {
debugArgs.add("-Dappmap.debug");
} else {
debugArgs.add("-Dappmap.debug." + token);
}
}
}
debugArgs.add(0, "-Dappmap.debug");
debugArgs.add(0, "-Dappmap.debug.file=" + StringEscapeUtils
.escapeJava(format("%s", appmap.getDebugFile())));

if (hasDebug) {
debugArgs.add(0, "-Dappmap.debug.file=" + StringEscapeUtils
.escapeJava(format("%s", appmap.getDebugFile())));
}
}
return debugArgs;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package com.appland.appmap;
package com.appland.appmap.gradle;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.file.FileSystemOperations;
import org.gradle.api.internal.project.ProjectInternal;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.ReportingBasePlugin;
import org.gradle.language.base.plugins.LifecycleBasePlugin;

/**
* The actual plugin definition for appmap plugin.
*/
public class AppmapPlugin implements Plugin<Project> {

public static final String DEFAULT_AGENT_VERSION = "latest.release";
public class AppMapPlugin implements Plugin<Project> {
public static final String DEFAULT_AGENT_VERSION = "[1.3, 2.0)";
public static final String AGENT_CONFIGURATION_NAME = "appmapAgent";
public static final String PLUGIN_EXTENSION_NAME = "appmap";
private Project project;
Expand All @@ -27,29 +24,27 @@ public void apply(Project project) {
final Configuration config = project.getConfigurations().getAt(AGENT_CONFIGURATION_NAME);
config.setVisible(false);
config.setTransitive(true);
config.setDescription("Appmap agent to generate app map data.");
config.setDescription("AppMap agent to generate app map data.");
config.defaultDependencies(dependencies ->
dependencies.add(
project.getDependencies().create("com.appland:appmap-agent:" + DEFAULT_AGENT_VERSION)
)
);
AppmapPluginExtension extension = project.getExtensions()
.create(PLUGIN_EXTENSION_NAME, AppmapPluginExtension.class, project, config);
AppMapPluginExtension extension = project.getExtensions()
.create(PLUGIN_EXTENSION_NAME, AppMapPluginExtension.class, project, config);
//extension.setAgentVersion(DEFAULT_AGENT_VERSION);*/
addAppmapGradleTasks(extension);
addAppMapGradleTasks(extension);
}

private void registerAgentConfiguration() {
Configuration agentConf = project.getConfigurations().create(AGENT_CONFIGURATION_NAME);
agentConf.setVisible(false);
agentConf.setTransitive(true);
agentConf.setDescription("Appmap agent to generate app map data.");
agentConf.setDescription("AppMap agent to generate app map data.");
}

private void addAppmapGradleTasks(AppmapPluginExtension extension) {
project.getPlugins().withType(JavaPlugin.class, javaPlugin -> {
addAppmapTasks(extension);
});
private void addAppMapGradleTasks(AppMapPluginExtension extension) {
project.getPlugins().withType(JavaPlugin.class, javaPlugin -> addAppMapTasks(extension));
}

/**
Expand All @@ -58,37 +53,45 @@ private void addAppmapGradleTasks(AppmapPluginExtension extension) {
*
* @param extension holds the config parameters for the plugin.
*/
private void addAppmapTasks(AppmapPluginExtension extension) {
private void addAppMapTasks(AppMapPluginExtension extension) {
project.getTasks().register(
"appmap",
AppmapTask.class,
AppMapTask.class,
prepareAgentTask -> {
prepareAgentTask.doFirst(
new ValidateConfigAction(extension.getConfigFile().getAsFile())
);
prepareAgentTask.doLast(
new CleanOutputDirectoryAction(
((ProjectInternal) project).getServices().get(FileSystemOperations.class),
extension.getOutputDirectory().getAsFile())
);
prepareAgentTask.doLast(new LoadAppmapAgentAction(project, extension));
prepareAgentTask.doLast(new LoadAppMapAgentAction(project, extension));
prepareAgentTask.setGroup(LifecycleBasePlugin.BUILD_GROUP);
prepareAgentTask.setDescription(
String.format("Attaches Appmap Agent to the Test task")
String.format("Injects AppMap Agent JVM settings to the 'test' task")
);
});

project.getTasks().register(
"validate-config",
"appmap-validate-config",
validateConfigTask -> {
validateConfigTask.doFirst(
new ValidateConfigAction(extension.getConfigFile().getAsFile())
);
validateConfigTask.setGroup(LifecycleBasePlugin.BUILD_GROUP);
validateConfigTask.setDescription(
String.format("Searches Appmap Agent config file and validates it")
String.format("Validates the AppMap Agent configuration")
);
}
);

project.getTasks().register(
"appmap-print-jar-path",
agentJarPathTask -> {
agentJarPathTask.doFirst(
new PrintJarPathAction(extension)
);
agentJarPathTask.setGroup(LifecycleBasePlugin.BUILD_GROUP);
agentJarPathTask.setDescription(
String.format("Prints the file path of the AppMap Agent JAR")
);
}
);
}
}
Loading

0 comments on commit b16652e

Please sign in to comment.