Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

Commit

Permalink
Add references property to the force-data-tree-import task
Browse files Browse the repository at this point in the history
  • Loading branch information
mcartoixa committed Jun 5, 2024
1 parent 2e6da34 commit c3e1d58
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 88 deletions.
95 changes: 95 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: build

on:
push:
paths-ignore:
- '.vscode/**'
- '.editorconfig'
- '**.md'

jobs:
build:
runs-on: ubuntu-latest
env:
PACKAGE_VERSION: 1.2.${{ github.run_number }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: 8
java-package: jdk
distribution: temurin
- name: Cache binary dependencies
uses: actions/cache@v3
with:
path: |
.tmp/*
.tmp/cloc.pl
!.tmp/*.gz
!.tmp/*.xz
!.tmp/*.zip
key: bin-${{ hashFiles('build/versions.env') }}
- name: Cache Ivy dependencies
uses: actions/cache@v3
with:
path: ivy
key: ivy-${{hashFiles('ivy.xml')}}
- name: Prepare build environment
shell: bash
run: |
source build/setenv.sh
# Only way to share environment variables between steps...
echo "ANT_HOME=$ANT_HOME" >> $GITHUB_ENV
echo "PMD_HOME=$PMD_HOME" >> $GITHUB_ENV
echo "$ANT_HOME/bin" >> $GITHUB_PATH
mkdir -p ivy
if [ ! -f ivy/ivy.jar ]; then wget -nv -O ivy/ivy.jar https://repo1.maven.org/maven2/org/apache/ivy/ivy/$_IVY_VERSION/ivy-$_IVY_VERSION.jar; fi
java -jar ivy/ivy.jar -retrieve "ivy/lib/[conf]/[artifact].[ext]" -confs build
- name: Build
shell: bash
run: |
ant -noclasspath -nouserlib -noinput -logger org.apache.tools.ant.listener.AnsiColorLogger -Dverbosity=debug -f build.xml release
- name: JUnit Tests Report
if: success() || failure()
uses: dorny/test-reporter@v1
with:
name: JUnit Tests
path: tmp/junit-results.xml
reporter: java-junit
fail-on-error: true
- name: Archive artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts
path: |
tmp/out/bin/**.*
- name: Archive logs
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: logs
path: |
build.log
retention-days: 2
- name: Archive results
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: results
path: |
tmp/junit-results
tmp/*-results.html
tmp/*-results.xml
retention-days: 8
- name: Create release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v2
with:
draft: true
files: |
tmp/out/bin/**.*
39 changes: 0 additions & 39 deletions .travis.yml

This file was deleted.

8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# ant-sfdx
[![Build status](https://travis-ci.org/mcartoixa/ant-sfdx.svg?branch=master)](https://travis-ci.org/mcartoixa/ant-sfdx)
[![Build Status](https://dev.azure.com/mcartoixa/ant-sfdx/_apis/build/status/ant-sfdx-CI)](https://dev.azure.com/mcartoixa/ant-sfdx/_build/latest?definitionId=1)
[![Build status](https://github.com/mcartoixa/ant-sfdx/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/mcartoixa/ant-sfdx/actions/workflows/build.yml)
[![Code coverage](https://codecov.io/gh/mcartoixa/ant-sfdx/branch/master/graph/badge.svg)](https://codecov.io/gh/mcartoixa/ant-sfdx)
[![BCH compliance](https://bettercodehub.com/edge/badge/mcartoixa/ant-sfdx?branch=master)](https://bettercodehub.com/)

Ant tasks that encapsulate the Salesforce DX CLI

Expand Down Expand Up @@ -35,8 +33,8 @@ But if you can handle it, this project allows you to:
* with native JSON support in Ant [scripts](http://ant.apache.org/manual/Tasks/script.html) if necessary.
* easily integrate third-party Java based tools like [PMD](https://pmd.github.io/) or [ApexDoc](https://github.com/SalesforceFoundation/ApexDoc).
* read your build more easily (if you can accept [the angle bracket tax](https://blog.codinghorror.com/xml-the-angle-bracket-tax/)). What's more readable:
* `sfdx force:org:create -v HubOrg -s -f config/project-scratch-def.json -a ciorg --wait 2` ?
* or `<sfdx:force-org-create targetdevhubusername="HubOrg" defaultusername="true" definitionfile="config/project-scratch-def.json" alias="ciorg" wait="2" />` ?
* `sfdx force:org:create -v HubOrg -s -f config/project-scratch-def.json -a ciorg --wait 2`?
* or `<sfdx:force-org-create targetdevhubusername="HubOrg" defaultusername="true" definitionfile="config/project-scratch-def.json" alias="ciorg" wait="2" />`?

## Usage

Expand Down
38 changes: 0 additions & 38 deletions azure-pipelines.yml

This file was deleted.

2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

source build/.bashrc
source build/setenv.sh



Expand Down
2 changes: 1 addition & 1 deletion build/.bashrc → build/setenv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ esac

#Ant
export ANT_HOME=$(pwd)/.tmp/apache-ant-$_ANT_VERSION
if [ ! -f $_ANT_HOME/bin/ant ]; then
if [ ! -f $ANT_HOME/bin/ant ]; then
wget -nv $_wget_interactive_options -O .tmp/apache-ant-$_ANT_VERSION-bin.tar.gz https://archive.apache.org/dist/ant/binaries/apache-ant-$_ANT_VERSION-bin.tar.gz
tar -xzvf .tmp/apache-ant-$_ANT_VERSION-bin.tar.gz -C .tmp
fi
Expand Down
5 changes: 5 additions & 0 deletions docs/force-data-tree-import.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ <h3>Parameters</h3>
<td>A username or alias for the target org.</td>
<td>No</td>
</tr>
<tr>
<td>referencesproperty</td>
<td>The name of a property in which the references of the imported data should be stored. Subproperties are named according to the (lowercased) references ids of the imported data.</td>
<td>No</td>
</tr>
</tbody>
</table>

Expand Down
16 changes: 16 additions & 0 deletions map_drive.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@ECHO OFF
::--------------------------------------------------------------------
:: Usage: "mad_drive <drive_name>"
::
:: <drive_name> - Optional. W: by default.
::--------------------------------------------------------------------

SETLOCAL
SET MAPPED_DRIVE_NAME=%~1
IF "x%MAPPED_DRIVE_NAME%x"=="xx" SET MAPPED_DRIVE_NAME=W:

NET USE %MAPPED_DRIVE_NAME% /DELETE
SUBST %MAPPED_DRIVE_NAME% /D >NUL
SUBST %MAPPED_DRIVE_NAME% "%~dp0."

ENDLOCAL
26 changes: 23 additions & 3 deletions src/main/com/mcartoixa/ant/sfdx/force/data/tree/ImportTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
Expand All @@ -41,6 +42,7 @@
*
* @author Mathieu Cartoixa
*/
@SuppressWarnings("PMD.LongVariable")
public class ImportTask extends SfdxTask {

/* default */ class JsonParser extends SfdxTask.JsonParser {
Expand All @@ -49,7 +51,7 @@ public class ImportTask extends SfdxTask {
super();
}

@SuppressWarnings("PMD.EmptyCatchBlock")
@SuppressWarnings({"PMD.EmptyCatchBlock", "PMD.LongVariable"})
@Override
protected void doParse(final JSONObject json) {
final JSONArray result = json.optJSONArray("result");
Expand All @@ -58,9 +60,17 @@ protected void doParse(final JSONObject json) {
final Object value = result.get(i);
if (value instanceof JSONObject) {
final JSONObject object = (JSONObject) value;
final String refId = object.getString("refId");
final String id = object.getString("id");
final String referencesProperty = ImportTask.this.getReferencesProperty();
if (referencesProperty != null && !referencesProperty.isEmpty()) {
ImportTask.this.getProject().setNewProperty(referencesProperty + "." + refId.toLowerCase(Locale.ROOT), id);
}

final String message = String.format(
"%s imported.",
object.getString("refId")
"%s imported (%s).",
refId,
id
);
this.log(message, Project.MSG_INFO);
}
Expand Down Expand Up @@ -151,6 +161,10 @@ public void setPlan(final File plan) {
}
}

public void setReferencesProperty(final String referencesProperty) {
this.referencesProperty = referencesProperty;
}

public void setTargetUserName(final String userName) {
if (userName != null && !userName.isEmpty()) {
getCommandline().createArgument().setValue("-u");
Expand Down Expand Up @@ -210,6 +224,12 @@ protected ISfdxJsonParser getParser() {
return new ImportTask.JsonParser();
}

@SuppressWarnings("PMD.DefaultPackage")
/* default */ String getReferencesProperty() {
return this.referencesProperty;
}

private transient final List<FileSet> fileSets = new ArrayList<>();
private transient String referencesProperty;
private transient Union resources = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ public void executeShouldSetStatusProperty() {
Assert.assertEquals("Status property should be set", "0", buildRule.getProject().getProperty("execute.status"));
}

@Test
public void executeShouldSetReferencesProperties() {
buildRule.executeTarget("execute");
Assert.assertEquals("References properties should be set", "a063N000004OhI8QAK", buildRule.getProject().getProperty("execute.references.object__cref2"));
}

@Test
public void executeShouldAddJsonArgument() {
buildRule.executeTarget("execute");
Expand Down
2 changes: 1 addition & 1 deletion src/test/com/mcartoixa/ant/sfdx/force/data/tree/import.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


<target name="execute" depends="init">
<sfdx:force-data-tree-import targetusername="testuser" statusproperty="execute.status" resultproperty="execute.result" executable="${sfdx-path}">
<sfdx:force-data-tree-import targetusername="testuser" statusproperty="execute.status" resultproperty="execute.result" referencesproperty="execute.references" executable="${sfdx-path}">
<filelist refid="datafiles" />
</sfdx:force-data-tree-import>
</target>
Expand Down

0 comments on commit c3e1d58

Please sign in to comment.