Skip to content

Commit

Permalink
Merge pull request #20 from atlassian-forks/issue/master/DCA11Y-1274-…
Browse files Browse the repository at this point in the history
…incremental-compilation

DCA11Y-1274 - Incremental compilation updates & minor fixes
  • Loading branch information
atl-mk authored Nov 29, 2024
2 parents 57fe735 + 727c3d2 commit 3c83087
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 40 deletions.
29 changes: 26 additions & 3 deletions FORK_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,29 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [1.15.1-atlassian-2]
## [1.15.1-atlassian-3] - 2024-11-29

### Fixed

- [DCA11Y-1274]: Null arguments for mojos would fail the build
- [DCA11Y-1274]: Fix incremental with Yarn berry by fixing runtime detection
- [DCA11Y-1274]: Corepack Mojo incremental works
- [DCA11Y-1274]: Fix updating of digest versions without clean install
- [DCA11Y-1274]: Download dev metrics now correctly report PAC
- [DCA11Y-1145]: Fixed the legacy "downloadRoot" argument for PNPM & NPM installation

### Added

- [DCA11Y-1274]: ".flattened-pom.xml" & ".git" & ".node" to the excluded filenames list after finding it in Jira
- [DCA11Y-1274]: Log message indicating how much time is saved

## [1.15.1-atlassian-2] - 2024-11-26

### Added

- [DCA11Y-1274]: Incremental builds for Yarn, Corepack and NPM goals

## [1.15.1-atlassian-1]
## [1.15.1-atlassian-1] - 2024-11-25

- [DCA11Y-1145]: Automatic version detection of the Node version from `.tool-versions`, `.node-version`, and `.nvmrc` files
- [DCA11Y-1145]: The configuration property `nodeVersionFile` to specify a file that can be read in `install-node-and-npm`, `install-node-and-pnpm`, and `install-node-and-yarn`
Expand All @@ -19,6 +35,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

- [DCA11Y-1145]: Now tolerant of `v` missing or present at the start of a Node version



[DCA11Y-1274]: https://hello.jira.atlassian.cloud/browse/DCA11Y-1274
[DCA11Y-1145]: https://hello.jira.atlassian.cloud/browse/DCA11Y-1145
[unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.15.1-atlassian-2...HEAD

[unreleased]: https://github.com/atlassian-forks/frontend-maven-plugin/compare/frontend-plugins-1.15.1-atlassian-3...HEAD
[1.15.1-atlassian-3]: https://github.com/atlassian-forks/frontend-maven-plugin/compare/frontend-plugins-1.15.1-atlassian-2...frontend-plugins-1.15.1-atlassian-3
[1.15.1-atlassian-2]: https://github.com/atlassian-forks/frontend-maven-plugin/compare/frontend-plugins-1.15.1-atlassian-1...frontend-plugins-1.15.1-atlassian-2
[1.15.1-atlassian-1]: https://github.com/atlassian-forks/frontend-maven-plugin/compare/frontend-plugins-1.15.1-atlassian-1-16519678...frontend-plugins-1.15.1-atlassian-1
[1.15.1-atlassian-1-16519678]: https://github.com/atlassian-forks/frontend-maven-plugin/compare/frontend-plugins-1.15.1...frontend-plugins-1.15.1-atlassian-1-16519678
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.github.eirslett.maven.plugins.frontend.lib.CorepackRunner;
import com.github.eirslett.maven.plugins.frontend.lib.FrontendPluginFactory;
import com.github.eirslett.maven.plugins.frontend.lib.IncrementalMojoHelper;
import com.github.eirslett.maven.plugins.frontend.lib.IncrementalBuildExecutionDigest.ExecutionCoordinates;
import com.github.eirslett.maven.plugins.frontend.lib.IncrementalMojoHelper;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
Expand All @@ -17,6 +17,7 @@

import static com.github.eirslett.maven.plugins.frontend.lib.AtlassianDevMetricsReporter.Goal.COREPACK;
import static com.github.eirslett.maven.plugins.frontend.lib.AtlassianDevMetricsReporter.incrementExecutionCount;
import static com.github.eirslett.maven.plugins.frontend.lib.IncrementalMojoHelper.DEFAULT_EXCLUDED_FILENAMES;

@Mojo(name="corepack", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true)
public final class CorepackMojo extends AbstractFrontendMojo {
Expand Down Expand Up @@ -51,7 +52,7 @@ public final class CorepackMojo extends AbstractFrontendMojo {
* to the defaults in {@link IncrementalMojoHelper}. Whole directories will be
* excluded.
*/
@Parameter(property = "excludedFilenames", required = false, defaultValue = "node_modules,lcov-report,coverage,screenshots,build,dist,target,.idea,.history,tmp,.settings,.vscode,dependency-reduced-pom.xml")
@Parameter(property = "excludedFilenames", required = false, defaultValue = DEFAULT_EXCLUDED_FILENAMES)
private Set<String> excludedFilenames;

@Component(role = SettingsDecrypter.class)
Expand All @@ -72,17 +73,19 @@ protected boolean skipExecution() {
public synchronized void execute(FrontendPluginFactory factory) throws Exception {
CorepackRunner runner = factory.getCorepackRunner();

IncrementalMojoHelper incrementalHelper = new IncrementalMojoHelper(frontendIncremental, getTargetDir(), workingDirectory, triggerFiles, excludedFilenames);
ExecutionCoordinates coordinates = new ExecutionCoordinates(execution.getGoal(), execution.getExecutionId(), execution.getLifecyclePhase());
IncrementalMojoHelper incrementalHelper = new IncrementalMojoHelper(frontendIncremental, coordinates, getTargetDir(), workingDirectory, triggerFiles, excludedFilenames);

boolean incrementalEnabled = incrementalHelper.incrementalEnabled();
boolean isIncremental = incrementalEnabled && incrementalHelper.canBeSkipped(arguments, coordinates, runner.getRuntime(), environmentVariables, project.getArtifactId(), getFrontendMavenPluginVersion());
boolean isIncremental = incrementalEnabled && incrementalHelper.canBeSkipped(arguments, runner.getRuntime(), environmentVariables, project.getArtifactId(), getFrontendMavenPluginVersion());

incrementExecutionCount(project.getArtifactId(), arguments, COREPACK, getFrontendMavenPluginVersion(), incrementalEnabled, isIncremental, () -> {
if (isIncremental) {
getLog().info("Skipping corepack execution as no modified files in " + workingDirectory);
} else {
runner.execute(arguments, environmentVariables);

incrementalHelper.acceptIncrementalBuildDigest();
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ public void execute(FrontendPluginFactory factory) throws Exception {

String validNodeVersion = getDownloadableVersion(nodeVersion);

final String nodeDownloadRoot = getNodeDownloadRoot();
final String npmDownloadRoot = getNpmDownloadRoot();
String nodeDownloadRoot = getNodeDownloadRoot();
String npmDownloadRoot = getNpmDownloadRoot();

try {
if (isAtlassianProject(project) &&
Expand All @@ -135,10 +135,10 @@ public void execute(FrontendPluginFactory factory) throws Exception {
getLog().info("Atlassian project detected, going to use the internal mirrors (requires VPN)");

serverId = "maven-atlassian-com";
nodeDownloadRoot = isBlank(nodeDownloadRoot) ? ATLASSIAN_NODE_DOWNLOAD_ROOT : nodeDownloadRoot;
npmDownloadRoot = isBlank(npmDownloadRoot) ? ATLASSIAN_NPM_DOWNLOAD_ROOT : npmDownloadRoot;
try {
install(factory, validNodeVersion,
isBlank(nodeDownloadRoot) ? ATLASSIAN_NODE_DOWNLOAD_ROOT : nodeDownloadRoot,
isBlank(npmDownloadRoot) ? ATLASSIAN_NPM_DOWNLOAD_ROOT : npmDownloadRoot);
install(factory, validNodeVersion, nodeDownloadRoot, npmDownloadRoot);
return;
} catch (InstallationException exception) {
// Ignore as many filesystem exceptions unrelated to the mirror easily
Expand All @@ -149,7 +149,9 @@ public void execute(FrontendPluginFactory factory) throws Exception {
pacAttemptFailed = true;
getLog().warn("Oh no couldn't use the internal mirrors! Falling back to upstream mirrors");
getLog().debug("Using internal mirrors failed because: ", exception);
} finally {

nodeDownloadRoot = getNodeDownloadRoot();
npmDownloadRoot = getNpmDownloadRoot();
serverId = null;
}
}
Expand All @@ -163,6 +165,8 @@ public void execute(FrontendPluginFactory factory) throws Exception {
boolean finalFailed = failed;
boolean finalPacAttemptFailed = pacAttemptFailed;
boolean finalTriedToUsePac = triedToUsePac;
String finalNodeDownloadRoot = nodeDownloadRoot;
String finalNpmDownloadRoot = npmDownloadRoot;
timer.stop(
"runtime.download",
project.getArtifactId(),
Expand All @@ -172,8 +176,8 @@ public void execute(FrontendPluginFactory factory) throws Exception {
put("installation", "npm");
put("installation-work-runtime", runtimeWork.toString());
put("installation-work-package-manager", packageManagerWork.toString());
put("runtime-host", getHostForMetric(nodeDownloadRoot, NODEJS_ORG, finalTriedToUsePac, finalPacAttemptFailed));
put("package-manager-host", getHostForMetric(npmDownloadRoot, DEFAULT_NPM_DOWNLOAD_ROOT, finalTriedToUsePac, finalPacAttemptFailed));
put("runtime-host", getHostForMetric(finalNodeDownloadRoot, NODEJS_ORG, finalTriedToUsePac, finalPacAttemptFailed));
put("package-manager-host", getHostForMetric(finalNpmDownloadRoot, DEFAULT_NPM_DOWNLOAD_ROOT, finalTriedToUsePac, finalPacAttemptFailed));
put("failed", Boolean.toString(finalFailed));
put("pac-attempted-failed", Boolean.toString(finalPacAttemptFailed));
put("tried-to-use-pac", Boolean.toString(finalTriedToUsePac));
Expand Down Expand Up @@ -229,7 +233,7 @@ private String getNodeDownloadRoot() {
}

private String getNpmDownloadRoot() {
if (downloadRoot != null && !"".equals(downloadRoot) && NPMInstaller.DEFAULT_NPM_DOWNLOAD_ROOT.equals(npmDownloadRoot)) {
if (downloadRoot != null && !"".equals(downloadRoot) && isBlank(npmDownloadRoot)) {
return downloadRoot;
}
return npmDownloadRoot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ public void execute(FrontendPluginFactory factory) throws Exception {
getLog().info("Atlassian project detected, going to use the internal mirrors (requires VPN)");

serverId = "maven-atlassian-com";
resolvedNodeDownloadRoot = isBlank(resolvedNodeDownloadRoot) ? ATLASSIAN_NODE_DOWNLOAD_ROOT : resolvedNodeDownloadRoot;
resolvedPnpmDownloadRoot = isBlank(resolvedPnpmDownloadRoot) ? ATLASSIAN_NPM_DOWNLOAD_ROOT : resolvedPnpmDownloadRoot;
try {
install(factory, validNodeVersion,
isBlank(resolvedNodeDownloadRoot) ? ATLASSIAN_NODE_DOWNLOAD_ROOT : resolvedNodeDownloadRoot,
isBlank(resolvedPnpmDownloadRoot) ? ATLASSIAN_NPM_DOWNLOAD_ROOT : resolvedPnpmDownloadRoot);
install(factory, validNodeVersion, resolvedNodeDownloadRoot, resolvedPnpmDownloadRoot);
return;
} catch (InstallationException exception) {
// Ignore as many filesystem exceptions unrelated to the mirror easily
Expand All @@ -154,7 +154,9 @@ public void execute(FrontendPluginFactory factory) throws Exception {
pacAttemptFailed = true;
getLog().warn("Oh no couldn't use the internal mirrors! Falling back to upstream mirrors");
getLog().debug("Using internal mirrors failed because: ", exception);
} finally {

resolvedNodeDownloadRoot = getNodeDownloadRoot();
resolvedPnpmDownloadRoot = getPnpmDownloadRoot();
serverId = null;
}
}
Expand All @@ -168,6 +170,8 @@ public void execute(FrontendPluginFactory factory) throws Exception {
boolean finalFailed = failed;
boolean finalPacAttemptFailed = pacAttemptFailed;
boolean finalTriedToUsePac = triedToUsePac;
String finalResolvedPnpmDownloadRoot = resolvedPnpmDownloadRoot;
String finalResolvedNodeDownloadRoot = resolvedNodeDownloadRoot;
timer.stop(
"runtime.download",
project.getArtifactId(),
Expand All @@ -177,8 +181,8 @@ public void execute(FrontendPluginFactory factory) throws Exception {
put("installation", "pnpm");
put("installation-work-runtime", runtimeWork.toString());
put("installation-work-package-manager", packageManagerWork.toString());
put("runtime-host", getHostForMetric(resolvedPnpmDownloadRoot, NODEJS_ORG, finalTriedToUsePac, finalPacAttemptFailed));
put("package-manager-host", getHostForMetric(resolvedPnpmDownloadRoot, DEFAULT_PNPM_DOWNLOAD_ROOT, finalTriedToUsePac, finalPacAttemptFailed));
put("runtime-host", getHostForMetric(finalResolvedNodeDownloadRoot, NODEJS_ORG, finalTriedToUsePac, finalPacAttemptFailed));
put("package-manager-host", getHostForMetric(finalResolvedPnpmDownloadRoot, DEFAULT_PNPM_DOWNLOAD_ROOT, finalTriedToUsePac, finalPacAttemptFailed));
put("failed", Boolean.toString(finalFailed));
put("pac-attempted-failed", Boolean.toString(finalPacAttemptFailed));
put("tried-to-use-pac", Boolean.toString(finalTriedToUsePac));
Expand Down Expand Up @@ -230,7 +234,7 @@ private String getNodeDownloadRoot() {
}

private String getPnpmDownloadRoot() {
if (downloadRoot != null && !"".equals(downloadRoot) && PnpmInstaller.DEFAULT_PNPM_DOWNLOAD_ROOT.equals(pnpmDownloadRoot)) {
if (downloadRoot != null && !"".equals(downloadRoot) && isBlank(pnpmDownloadRoot)) {
return downloadRoot;
}
return pnpmDownloadRoot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void execute(FrontendPluginFactory factory) throws Exception {
pacAttemptFailed = true;
getLog().warn("Oh no couldn't use the internal mirrors! Falling back to upstream mirrors");
getLog().debug("Using internal mirrors failed because: ", exception);
} finally {

nodeDownloadRoot = userSetNodeDownloadRoot;
yarnDownloadRoot = userSetYarnDownloadRoot;
serverId = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static com.github.eirslett.maven.plugins.frontend.lib.AtlassianDevMetricsReporter.Goal.NPM;
import static com.github.eirslett.maven.plugins.frontend.lib.AtlassianDevMetricsReporter.incrementExecutionCount;
import static com.github.eirslett.maven.plugins.frontend.lib.IncrementalMojoHelper.DEFAULT_EXCLUDED_FILENAMES;

@Mojo(name="npm", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true)
public final class NpmMojo extends AbstractFrontendMojo {
Expand Down Expand Up @@ -61,7 +62,7 @@ public final class NpmMojo extends AbstractFrontendMojo {
* to the defaults in {@link IncrementalMojoHelper}. Whole directories will be
* excluded.
*/
@Parameter(property = "excludedFilenames", defaultValue = "node_modules,lcov-report,coverage,screenshots,build,dist,target,.idea,.history,tmp,.settings,.vscode,dependency-reduced-pom.xml", required = false)
@Parameter(property = "excludedFilenames", defaultValue = DEFAULT_EXCLUDED_FILENAMES, required = false)
private Set<String> excludedFilenames;

@Component
Expand All @@ -85,11 +86,11 @@ protected boolean skipExecution() {
public synchronized void execute(FrontendPluginFactory factory) throws Exception {
NpmRunner runner = factory.getNpmRunner(getProxyConfig(), getRegistryUrl());

IncrementalMojoHelper incrementalHelper = new IncrementalMojoHelper(frontendIncremental, getTargetDir(), workingDirectory, triggerFiles, excludedFilenames);
ExecutionCoordinates coordinates = new ExecutionCoordinates(execution.getGoal(), execution.getExecutionId(), execution.getLifecyclePhase());
IncrementalMojoHelper incrementalHelper = new IncrementalMojoHelper(frontendIncremental, coordinates, getTargetDir(), workingDirectory, triggerFiles, excludedFilenames);

boolean incrementalEnabled = incrementalHelper.incrementalEnabled();
boolean isIncremental = incrementalEnabled && incrementalHelper.canBeSkipped(arguments, coordinates, runner.getRuntime(), environmentVariables, project.getArtifactId(), getFrontendMavenPluginVersion());
boolean isIncremental = incrementalEnabled && incrementalHelper.canBeSkipped(arguments, runner.getRuntime(), environmentVariables, project.getArtifactId(), getFrontendMavenPluginVersion());

incrementExecutionCount(project.getArtifactId(), arguments, NPM, getFrontendMavenPluginVersion(), incrementalEnabled, isIncremental, () -> {
if (isIncremental) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static com.github.eirslett.maven.plugins.frontend.lib.AtlassianDevMetricsReporter.Goal.YARN;
import static com.github.eirslett.maven.plugins.frontend.lib.AtlassianDevMetricsReporter.incrementExecutionCount;
import static com.github.eirslett.maven.plugins.frontend.lib.IncrementalMojoHelper.DEFAULT_EXCLUDED_FILENAMES;
import static com.github.eirslett.maven.plugins.frontend.mojo.YarnUtils.isYarnrcYamlFilePresent;

@Mojo(name = "yarn", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true)
Expand Down Expand Up @@ -63,7 +64,7 @@ public final class YarnMojo extends AbstractFrontendMojo {
* to the defaults in {@link IncrementalMojoHelper}. Whole directories will be
* excluded.
*/
@Parameter(property = "excludedFilenames", required = false, defaultValue = "node_modules,lcov-report,coverage,screenshots,build,dist,target,.idea,.history,tmp,.settings,.vscode,dependency-reduced-pom.xml")
@Parameter(property = "excludedFilenames", required = false, defaultValue = DEFAULT_EXCLUDED_FILENAMES)
private Set<String> excludedFilenames;

@Component
Expand All @@ -88,11 +89,11 @@ public synchronized void execute(FrontendPluginFactory factory) throws Exception
boolean isYarnBerry = isYarnrcYamlFilePresent(this.session, this.workingDirectory);
YarnRunner runner = factory.getYarnRunner(getProxyConfig(), getRegistryUrl(), isYarnBerry);

IncrementalMojoHelper incrementalHelper = new IncrementalMojoHelper(frontendIncremental, getTargetDir(), workingDirectory, triggerFiles, excludedFilenames);
ExecutionCoordinates coordinates = new ExecutionCoordinates(execution.getGoal(), execution.getExecutionId(), execution.getLifecyclePhase());
IncrementalMojoHelper incrementalHelper = new IncrementalMojoHelper(frontendIncremental, coordinates, getTargetDir(), workingDirectory, triggerFiles, excludedFilenames);

boolean incrementalEnabled = incrementalHelper.incrementalEnabled();
boolean isIncremental = incrementalEnabled && incrementalHelper.canBeSkipped(arguments, coordinates, runner.getRuntime(), environmentVariables, project.getArtifactId(), getFrontendMavenPluginVersion());
boolean isIncremental = incrementalEnabled && incrementalHelper.canBeSkipped(arguments, runner.getRuntime(), environmentVariables, project.getArtifactId(), getFrontendMavenPluginVersion());

incrementExecutionCount(project.getArtifactId(), arguments, YARN, getFrontendMavenPluginVersion(), incrementalEnabled, isIncremental, () -> {
if (isIncremental) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static java.lang.System.getProperty;
import static java.lang.System.getenv;
import static java.time.Instant.now;
import static java.util.Objects.isNull;
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.http.entity.ContentType.APPLICATION_JSON;
Expand Down Expand Up @@ -262,6 +263,10 @@ public static String getHostForMetric(String hostSetting, String defaultHost, bo
* perfect
*/
static String getScriptFromArguments(String arguments) {
if (isNull(arguments)) {
arguments = "";
}

if (arguments.contains("test") || arguments.contains("check") || arguments.contains("visreg") || arguments.contains("jest") || arguments.contains("storybook")) {
return "test";
}
Expand Down
Loading

0 comments on commit 3c83087

Please sign in to comment.