Skip to content

Commit

Permalink
skipTest dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dcserrot committed Jan 2, 2025
1 parent 830903d commit 76acc38
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src/main/java/org/jfrog/buildinfo/ArtifactoryMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public class ArtifactoryMojo extends AbstractMojo {
@Parameter
Config.Proxy proxy = new Config.Proxy();

@Parameter(property = "skipTests", defaultValue = "false")
boolean skipTests;

@Override
public void execute() {
if (session.getRequest().getData().putIfAbsent("configured", Boolean.TRUE) == null) {
Expand Down Expand Up @@ -125,7 +128,7 @@ private void enforceDeployment() {
skipDefaultDeploy();
completeConfig();
addDeployProperties();
BuildInfoRecorder executionListener = new BuildInfoRecorder(session, getLog(), artifactory.delegate);
BuildInfoRecorder executionListener = new BuildInfoRecorder(session, getLog(), artifactory.delegate, skipTests);
repositoryListener.setBuildInfoRecorder(executionListener);
session.getRequest().setExecutionListener(executionListener);
}
Expand Down
29 changes: 14 additions & 15 deletions src/main/java/org/jfrog/buildinfo/deployment/BuildInfoRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -51,8 +50,6 @@
*/
public class BuildInfoRecorder implements BuildInfoExtractor<ExecutionEvent>, ExecutionListener {

private static final String[] TEST_GOALS = {"test", "testCompile"};

private final Map<String, DeployDetails> deployableArtifacts = Maps.newConcurrentMap();
private final Set<Artifact> buildTimeDependencies = Collections.synchronizedSet(new HashSet<>());
private final ModuleArtifacts currentModuleDependencies = new ModuleArtifacts();
Expand All @@ -63,13 +60,15 @@ public class BuildInfoRecorder implements BuildInfoExtractor<ExecutionEvent>, Ex
private final ExecutionListener wrappedListener;
private final BuildDeployer buildDeployer;
private final Log logger;
private final boolean skipTests;

public BuildInfoRecorder(MavenSession session, Log logger, ArtifactoryClientConfiguration conf) {
public BuildInfoRecorder(MavenSession session, Log logger, ArtifactoryClientConfiguration conf, boolean skipTests) {
this.wrappedListener = ObjectUtils.defaultIfNull(session.getRequest().getExecutionListener(), new AbstractExecutionListener());
this.buildInfoBuilder = new BuildInfoModelPropertyResolver(logger, session, conf);
this.buildDeployer = new BuildDeployer(logger);
this.logger = logger;
this.conf = conf;
this.skipTests = skipTests;
}

/**
Expand Down Expand Up @@ -97,7 +96,7 @@ public void projectSucceeded(ExecutionEvent event) {
}

// Fill currentModuleDependencies
addDependencies(project);
addDependencies(project, skipTests);

// Build module
addDependenciesToCurrentModule(moduleBuilder);
Expand All @@ -119,13 +118,9 @@ public void projectSucceeded(ExecutionEvent event) {
*/
@Override
public void mojoSucceeded(ExecutionEvent event) {
Object skipProperty = event.getSession().getUserProperties().get("maven.test.skip");
boolean skipTest = skipProperty != null && Boolean.parseBoolean(skipProperty.toString());
boolean test = ArrayUtils.contains(TEST_GOALS, event.getMojoExecution().getGoal());

if (!test || !skipTest) {
addDependencies(event.getProject());
}
addDependencies(event.getProject(), skipTests);


wrappedListener.mojoSucceeded(event);
}
Expand All @@ -137,7 +132,7 @@ public void mojoSucceeded(ExecutionEvent event) {
*/
@Override
public void mojoFailed(ExecutionEvent event) {
addDependencies(event.getProject());
addDependencies(event.getProject(), skipTests);

wrappedListener.mojoFailed(event);
}
Expand Down Expand Up @@ -212,14 +207,18 @@ private void addArtifacts(MavenProject project) {
* In case an artifact is included in both MavenProject dependencies and currentModuleDependencies,
* we'd like to keep the one that was taken from the MavenProject, because of the scope it has.
*
* @param project - The Maven project
* @param project - The Maven project
* @param skipTests
*/
private void addDependencies(MavenProject project) {
private void addDependencies(MavenProject project, boolean skipTests) {
// Create a set with new project dependencies. These dependencies are 1st priority in the set.
Set<Artifact> dependencies = Sets.newHashSet();
for (Artifact artifact : project.getArtifacts()) {
String classifier = StringUtils.defaultString(artifact.getClassifier());
String scope = StringUtils.defaultIfBlank(artifact.getScope(), Artifact.SCOPE_COMPILE);
if (skipTests && Artifact.SCOPE_TEST.equals(scope)) {
continue;
}
String classifier = StringUtils.defaultString(artifact.getClassifier());
Artifact art = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(),
artifact.getVersion(), scope, artifact.getType(), classifier, artifact.getArtifactHandler());
art.setFile(artifact.getFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class BuildInfoRecorderTest extends ArtifactoryMojoTestBase {
public void setUp() throws Exception {
super.setUp();
executionEvent = new TestExecutionEvent(mojo.session, mojo.project);
buildInfoRecorder = new BuildInfoRecorder(mojo.session, mojo.getLog(), mojo.artifactory.delegate);
buildInfoRecorder = new BuildInfoRecorder(mojo.session, mojo.getLog(), mojo.artifactory.delegate, true);
mojo.project.setArtifacts(Sets.newHashSet(TEST_ARTIFACT));
}

Expand Down

0 comments on commit 76acc38

Please sign in to comment.