Skip to content
Snippets Groups Projects
Commit b8ea69e8 authored by Jérôme Charaoui's avatar Jérôme Charaoui
Browse files

New upstream version 2.0.0

parent 4b9bb6ed
No related branches found
No related tags found
No related merge requests found
name: mend_scan
on:
workflow_dispatch:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: connect_twingate
uses: twingate/github-action@v1
with:
service-key: ${{ secrets.TWINGATE_PUBLIC_REPO_KEY }}
- name: checkout repo content
uses: actions/checkout@v2 # checkout the repository content to github runner.
with:
fetch-depth: 1
# install java which is required for mend and clojure
- name: setup java
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
# install clojure tools
- name: Install Clojure tools
uses: DeLaGuardo/setup-clojure@10.1
with:
# Install just one or all simultaneously
# The value must indicate a particular version of the tool, or use 'latest'
# to always provision the latest version
cli: latest # Clojure CLI based on tools.deps
lein: latest # Leiningen
boot: latest # Boot.clj
bb: latest # Babashka
clj-kondo: latest # Clj-kondo
cljstyle: latest # cljstyle
zprint: latest # zprint
# run lein gen
- name: create pom.xml
run: lein pom
# download mend
- name: download_mend
run: curl -o wss-unified-agent.jar https://unified-agent.s3.amazonaws.com/wss-unified-agent.jar
- name: run mend
run: env WS_INCLUDES=pom.xml java -jar wss-unified-agent.jar
env:
WS_APIKEY: ${{ secrets.MEND_API_KEY }}
WS_WSS_URL: https://saas-eu.whitesourcesoftware.com/agent
WS_USERKEY: ${{ secrets.MEND_TOKEN }}
WS_PRODUCTNAME: Puppet Enterprise
WS_PROJECTNAME: ${{ github.event.repository.name }}
.lein*
pom.xml
/target/
\ No newline at end of file
/target/
/resources/locales.clj
/dev-resources/i18n/bin
## 2.0.0
* update to clj parent 7.3.15
* add in the i18n plugin, and Makefiles
## 1.0.2
* Built with the same code as 1.0.0, but with java8 instead of java11
## 1.0.0
* Initial release
* @puppetlabs/dumpling
include dev-resources/Makefile.i18n
# -*- Makefile -*-
# This file was generated by the i18n leiningen plugin
# Do not edit this file; it will be overwritten the next time you run
# lein i18n init
#
# The name of the package into which the translations bundle will be placed
BUNDLE=puppetlabs.clj_shell_utils
# The name of the POT file into which the gettext code strings (msgid) will be placed
POT_NAME=clj-shell-utils.pot
# The list of names of packages covered by the translation bundle;
# by default it contains a single package - the same where the translations
# bundle itself is placed - but this can be overridden - preferably in
# the top level Makefile
PACKAGES?=$(BUNDLE)
LOCALES=$(basename $(notdir $(wildcard locales/*.po)))
BUNDLE_DIR=$(subst .,/,$(BUNDLE))
BUNDLE_FILES=$(patsubst %,resources/$(BUNDLE_DIR)/Messages_%.class,$(LOCALES))
FIND_SOURCES=find src -name \*.clj
# xgettext before 0.19 does not understand --add-location=file. Even CentOS
# 7 ships with an older gettext. We will therefore generate full location
# info on those systems, and only file names where xgettext supports it
LOC_OPT=$(shell xgettext --add-location=file -f - </dev/null >/dev/null 2>&1 && echo --add-location=file || echo --add-location)
LOCALES_CLJ=resources/locales.clj
define LOCALES_CLJ_CONTENTS
{
:locales #{$(patsubst %,"%",$(LOCALES))}
:packages [$(patsubst %,"%",$(PACKAGES))]
:bundle $(patsubst %,"%",$(BUNDLE).Messages)
}
endef
export LOCALES_CLJ_CONTENTS
i18n: msgfmt
# Update locales/<project-name>.pot
update-pot: locales/$(POT_NAME)
locales/$(POT_NAME): $(shell $(FIND_SOURCES)) | locales
@tmp=$$(mktemp $@.tmp.XXXX); \
$(FIND_SOURCES) \
| xgettext --from-code=UTF-8 --language=lisp \
--copyright-holder='Puppet <docs@puppet.com>' \
--package-name="$(BUNDLE)" \
--package-version="$(BUNDLE_VERSION)" \
--msgid-bugs-address="docs@puppet.com" \
-k \
-kmark:1 -ki18n/mark:1 \
-ktrs:1 -ki18n/trs:1 \
-ktru:1 -ki18n/tru:1 \
-ktrun:1,2 -ki18n/trun:1,2 \
-ktrsn:1,2 -ki18n/trsn:1,2 \
$(LOC_OPT) \
--add-comments --sort-by-file \
-o $$tmp -f -; \
sed -i.bak -e 's/charset=CHARSET/charset=UTF-8/' $$tmp; \
sed -i.bak -e 's/POT-Creation-Date: [^\\]*/POT-Creation-Date: /' $$tmp; \
rm -f $$tmp.bak; \
if ! diff -q -I POT-Creation-Date $$tmp $@ >/dev/null 2>&1; then \
mv $$tmp $@; \
else \
rm $$tmp; touch $@; \
fi
# Run msgfmt over all .po files to generate Java resource bundles
# and create the locales.clj file
msgfmt: $(BUNDLE_FILES) $(LOCALES_CLJ) clean-orphaned-bundles
# Force rebuild of locales.clj if its contents is not the the desired one. The
# shell echo is used to add a trailing newline to match the one from `cat`
ifneq ($(shell cat $(LOCALES_CLJ) 2> /dev/null),$(shell echo '$(LOCALES_CLJ_CONTENTS)'))
.PHONY: $(LOCALES_CLJ)
endif
$(LOCALES_CLJ): | resources
@echo "Writing $@"
@echo "$$LOCALES_CLJ_CONTENTS" > $@
# Remove every resource bundle that wasn't generated from a PO file.
# We do this because we used to generate the english bundle directly from the POT.
.PHONY: clean-orphaned-bundles
clean-orphaned-bundles:
@for bundle in resources/$(BUNDLE_DIR)/Messages_*.class; do \
locale=$$(basename "$$bundle" | sed -E -e 's/\$$?1?\.class$$/_class/' | cut -d '_' -f 2;); \
if [ ! -f "locales/$$locale.po" -a -f "$$bundle" ]; then \
rm "$$bundle"; \
fi \
done
resources/$(BUNDLE_DIR)/Messages_%.class: locales/%.po | resources
msgfmt --java2 -d resources -r $(BUNDLE).Messages -l $(*F) $<
# Use this to initialize translations. Updating the PO files is done
# automatically through a CI job that utilizes the scripts in the project's
# `bin` file, which themselves come from the `clj-i18n` project.
locales/%.po: | locales
@if [ ! -f $@ ]; then \
touch $@ && msginit --no-translator -l $(*F) -o $@ -i locales/$(POT_NAME); \
fi
resources locales:
@mkdir $@
help:
$(info $(HELP))
@echo
.PHONY: help
define HELP
This Makefile assists in handling i18n related tasks during development. Files
that need to be checked into source control are put into the locales/ directory.
They are
locales/$(POT_NAME) - the POT file generated by 'make update-pot'
locales/$$LANG.po - the translations for $$LANG
Only the $$LANG.po files should be edited manually; this is usually done by
translators.
You can use the following targets:
i18n: refresh all the files in locales/ and recompile resources
update-pot: extract strings and update locales/$(POT_NAME)
locales/LANG.po: create translations for LANG
msgfmt: compile the translations into Java classes; this step is
needed to make translations available to the Clojure code
and produces Java class files in resources/
endef
# @todo lutter 2015-04-20: for projects that use libraries with their own
# translation, we need to combine all their translations into one big po
# file and then run msgfmt over that so that we only have to deal with one
# resource bundle
#!/usr/bin/env sh
echo $PWD
(defproject puppetlabs/clj-shell-utils "1.0.2"
(defproject puppetlabs/clj-shell-utils "2.0.0"
:description "Clojure shell execution utilities"
:min-lein-version "2.9.0"
:parent-project {:coords [puppetlabs/clj-parent "3.0.0"]
:parent-project {:coords [puppetlabs/clj-parent "7.3.15"]
:inherit [:managed-dependencies]}
:pedantic? :abort
......@@ -11,7 +11,8 @@
:test-paths ["test/unit"]
:plugins [[lein-project-version "0.1.0"]
[lein-parent "0.3.6"]]
[lein-parent "0.3.6"]
[puppetlabs/i18n "0.9.0"]]
:source-paths ["src/clj"]
:java-source-paths ["src/java"]
......@@ -34,7 +35,7 @@
:username :env/clojars_jenkins_username
:password :env/clojars_jenkins_password
:sign-releases false}]
["snapshots" "http://nexus.delivery.puppetlabs.net/content/repositories/snapshots/"]]
)
["snapshots" "http://nexus.delivery.puppetlabs.net/content/repositories/snapshots/"]])
......@@ -27,7 +27,8 @@
(def ExecutionOptions
{(schema/optional-key :args) [schema/Str]
(schema/optional-key :env) (schema/maybe {schema/Str schema/Str})
(schema/optional-key :in) (schema/maybe InputStream)})
(schema/optional-key :in) (schema/maybe InputStream)
(schema/optional-key :cwd) (schema/maybe schema/Str)})
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Internal
......@@ -35,14 +36,17 @@
(def default-execution-options
{:args []
:env nil
:in nil})
:in nil
:cwd nil})
(schema/defn ^:always-validate java-exe-options :- ShellUtils$ExecutionOptions
[{:keys [env in]} :- ExecutionOptions]
[{:keys [env in cwd]} :- ExecutionOptions]
(let [exe-options (ShellUtils$ExecutionOptions.)]
(.setStdin exe-options in)
(when env
(.setEnv exe-options (ks/mapkeys name env)))
(when cwd
(.setWorkingDirectory exe-options cwd))
exe-options))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
......
......@@ -11,6 +11,7 @@ import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.File;
import java.util.Map;
public class ShellUtils {
......@@ -19,6 +20,7 @@ public class ShellUtils {
private boolean combineStdoutStderr = false;
private Map<String, String> env = null;
private InputStream stdin = null;
private String cwd = null;
public boolean getCombineStdoutStderr() {
return combineStdoutStderr;
......@@ -43,6 +45,14 @@ public class ShellUtils {
public void setEnv(Map<String, String> env) {
this.env = env;
}
public String getWorkingDirectory() {
return cwd;
}
public void setWorkingDirectory(String cwd) {
this.cwd = cwd;
}
}
private static final Logger log = LoggerFactory.getLogger(ShellUtils.class);
......@@ -92,6 +102,12 @@ public class ShellUtils {
// Set up the handlers
executor.setStreamHandler(streamHandler);
// Set up cwd
String cwd = options.getWorkingDirectory();
if (cwd != null) {
executor.setWorkingDirectory(new File(cwd));
}
Integer exitCode = executor.execute(commandLine, options.getEnv());
ByteArrayInputStream stdoutInputStream = new ByteArrayInputStream(stdoutOutputStream.toByteArray());
......
......@@ -104,6 +104,13 @@
{:in (ByteArrayInputStream.
(.getBytes "foo" "UTF-8"))}))))))
(deftest sets-cwd-correctly
(testing "sets current working directory correctly"
(let [tmpdir (System/getProperty "java.io.tmpdir")]
(is (= (str tmpdir "\n") (:stdout (sh-utils/execute-command
(script-path "echo_cwd")
{:cwd tmpdir})))))))
(deftest throws-exception-for-non-absolute-path
(testing "Commands must be given using absolute paths"
(is (thrown? IllegalArgumentException
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment