diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..c4224f8 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,88 @@ +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: Ruby 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 diff --git a/build.sh b/build.sh index 9920e9e..ebf3de7 100755 --- a/build.sh +++ b/build.sh @@ -1,6 +1,6 @@ #!/bin/bash -source build/.bashrc +source build/setenv.sh diff --git a/build/.bashrc b/build/setenv.sh similarity index 98% rename from build/.bashrc rename to build/setenv.sh index 30b48d0..5f69c0d 100755 --- a/build/.bashrc +++ b/build/setenv.sh @@ -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 diff --git a/docs/force-data-tree-import.html b/docs/force-data-tree-import.html index 9f332de..d8d2fca 100644 --- a/docs/force-data-tree-import.html +++ b/docs/force-data-tree-import.html @@ -52,6 +52,11 @@

Parameters

A username or alias for the target org. No + + referencesproperty + 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. + No + diff --git a/map_drive.cmd b/map_drive.cmd new file mode 100644 index 0000000..5bfc5a0 --- /dev/null +++ b/map_drive.cmd @@ -0,0 +1,16 @@ +@ECHO OFF +::-------------------------------------------------------------------- +:: Usage: "mad_drive " +:: +:: - 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 diff --git a/src/main/com/mcartoixa/ant/sfdx/force/data/tree/ImportTask.java b/src/main/com/mcartoixa/ant/sfdx/force/data/tree/ImportTask.java index f2cb1b3..e9fde03 100644 --- a/src/main/com/mcartoixa/ant/sfdx/force/data/tree/ImportTask.java +++ b/src/main/com/mcartoixa/ant/sfdx/force/data/tree/ImportTask.java @@ -58,9 +58,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(), id); + } + final String message = String.format( - "%s imported.", - object.getString("refId") + "%s imported (%s).", + refId, + id ); this.log(message, Project.MSG_INFO); } @@ -151,6 +159,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"); @@ -210,6 +222,12 @@ protected ISfdxJsonParser getParser() { return new ImportTask.JsonParser(); } + @SuppressWarnings("PMD.DefaultPackage") + /* default */ String getReferencesProperty() { + return this.referencesProperty; + } + private transient final List fileSets = new ArrayList<>(); + private transient String referencesProperty; private transient Union resources = null; } diff --git a/src/test/com/mcartoixa/ant/sfdx/force/data/tree/ImportTaskTest.java b/src/test/com/mcartoixa/ant/sfdx/force/data/tree/ImportTaskTest.java index 3223a89..abeafaf 100644 --- a/src/test/com/mcartoixa/ant/sfdx/force/data/tree/ImportTaskTest.java +++ b/src/test/com/mcartoixa/ant/sfdx/force/data/tree/ImportTaskTest.java @@ -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"); diff --git a/src/test/com/mcartoixa/ant/sfdx/force/data/tree/import.xml b/src/test/com/mcartoixa/ant/sfdx/force/data/tree/import.xml index dfe6b04..a7de0a6 100644 --- a/src/test/com/mcartoixa/ant/sfdx/force/data/tree/import.xml +++ b/src/test/com/mcartoixa/ant/sfdx/force/data/tree/import.xml @@ -13,7 +13,7 @@ - +