-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
250 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/target | ||
/.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
= Restore Project File Names | ||
:source-highlighter: prettify | ||
ifdef::env-github[] | ||
:outfilesuffix: .adoc | ||
:!toc-title: | ||
:caution-caption: :fire: | ||
:important-caption: :exclamation: | ||
:note-caption: :paperclip: | ||
:tip-caption: :bulb: | ||
:warning-caption: :warning: | ||
endif::[] | ||
|
||
== Abstract | ||
|
||
Restores the original names of entity store files after running `projupgrade` tool. | ||
|
||
== Background | ||
|
||
When a new release of an Axway API Gateway is used, all policy projects have to be upgraded to the new version. | ||
Local projects can be upgraded with the `projupgrade` tool provided by the client development tools. | ||
|
||
Unfortunately after using this tool all the file names of the XML entity store are changed. | ||
This has impacts if the entity store is managed by an SCM (e.g. Git). | ||
From the perspective of the SCM the files are deleted and new files are created. | ||
Or the SCM is able to automatically detect the renaming. | ||
In both cases it is confusing. | ||
|
||
This tool restores the original file names for the XML entity store. | ||
It only affect the names of the files, no content is changed. | ||
|
||
== Usage | ||
|
||
To restore the file names of a policy project in the folder `src/policies`, just invoke the tool with the parameter `--projdir` pointing to the project folder. | ||
|
||
.Example: invoke with local Python interpreter | ||
[source,shell] | ||
---- | ||
$ python restorefilenames.py --projdir=src/policies | ||
---- | ||
|
||
|
||
.Example: invoke with Axway Jython interpreter (Unix) | ||
[source,shell] | ||
---- | ||
$ restorefilenames.sh --projdir=src/policies | ||
---- | ||
|
||
.Example: invoke with Axway Jython interpreter (Windows) | ||
[source,cmd] | ||
---- | ||
> restorefilenames.cmd --projdir=src/policies | ||
---- | ||
|
||
IMPORTANT: For usage of the Jython interpreter the `AXWAY_HOME` environment variable has to be defined. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,53 @@ | ||
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.1.0 http://maven.apache.org/xsd/assembly-2.1.0.xsd"> | ||
<id>dist</id> | ||
<formats> | ||
<format>zip</format> | ||
</formats> | ||
<fileSets> | ||
<!-- KPS export/import tool --> | ||
<fileSet> | ||
<directory>${basedir}/src/main/resources/kpsexport</directory> | ||
<outputDirectory>kpsexport</outputDirectory> | ||
<excludes> | ||
<exclude>_*</exclude> | ||
</excludes> | ||
<fileMode>0500</fileMode> | ||
<lineEnding>unix</lineEnding> | ||
</fileSet> | ||
<fileSet> | ||
<directory>${basedir}/src/main/resources/kpsexport</directory> | ||
<outputDirectory>kpsexport</outputDirectory> | ||
<includes> | ||
<include>_*</include> | ||
</includes> | ||
<fileMode>0400</fileMode> | ||
<lineEnding>unix</lineEnding> | ||
</fileSet> | ||
</fileSets> | ||
<id>dist</id> | ||
<formats> | ||
<format>zip</format> | ||
</formats> | ||
<fileSets> | ||
<!-- Unix shell scripts --> | ||
<fileSet> | ||
<directory>${basedir}/src/main/resources</directory> | ||
<outputDirectory>.</outputDirectory> | ||
<includes> | ||
<include>**/*.sh</include> | ||
</includes> | ||
<excludes> | ||
<exclude>**/_*.sh</exclude> | ||
</excludes> | ||
<fileMode>0500</fileMode> | ||
<lineEnding>unix</lineEnding> | ||
</fileSet> | ||
<fileSet> | ||
<directory>${basedir}/src/main/resources</directory> | ||
<outputDirectory>.</outputDirectory> | ||
<includes> | ||
<include>**/_*.sh</include> | ||
</includes> | ||
<fileMode>0400</fileMode> | ||
<lineEnding>unix</lineEnding> | ||
</fileSet> | ||
|
||
<!-- Windows command scripts --> | ||
<fileSet> | ||
<directory>${basedir}/src/main/resources</directory> | ||
<outputDirectory>.</outputDirectory> | ||
<includes> | ||
<include>**/*.cmd</include> | ||
</includes> | ||
<fileMode>0400</fileMode> | ||
<lineEnding>windows</lineEnding> | ||
</fileSet> | ||
|
||
<!-- All other files --> | ||
<fileSet> | ||
<directory>${basedir}/src/main/resources</directory> | ||
<outputDirectory>.</outputDirectory> | ||
<excludes> | ||
<exclude>**/*.cmd</exclude> | ||
<exclude>**/*.sh</exclude> | ||
</excludes> | ||
<fileMode>0400</fileMode> | ||
</fileSet> | ||
</fileSets> | ||
</assembly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
@ECHO off | ||
SETLOCAL | ||
IF "%AXWAY_HOME%" == "" GOTO no_axway_home | ||
|
||
SET JYTHON=%AXWAY_HOME%\apigateway\Win32\bin\jython.bat | ||
IF NOT EXIST %JYTHON% GOTO no_jython | ||
|
||
SET CMD_HOME=%~dp0 | ||
CALL %JYTHON% "%CMD_HOME%/restorefilenames.py" %* | ||
|
||
GOTO exit | ||
|
||
:no_axway_home | ||
ECHO ERROR: environment variable AXWAY_HOME not set | ||
GOTO exit | ||
|
||
:no_jython | ||
ECHO ERROR: Jython interpreter not found: %JYTHON% | ||
|
||
:exit | ||
ENDLOCAL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import sys | ||
import os | ||
import logging | ||
|
||
from optparse import OptionParser | ||
import xml.etree.ElementTree as ET | ||
|
||
class ProjectFiles: | ||
def __init__(self, projdir): | ||
self.__projdir = projdir | ||
self.__config_file = os.path.join(self.__projdir, "configs.xml") | ||
|
||
# Check for valid project directory | ||
logging.info("Restore file names for project '%s'" % (self.__projdir)) | ||
if not os.path.isfile(self.__config_file): | ||
raise ValueError("Directory is not a valid project directory (missing 'configs.xml'): %s" % (self.__config_file)) | ||
|
||
# Read configuration | ||
logging.info("Reading configuration file: %s" % (self.__config_file)) | ||
self.__config_tree = ET.parse(self.__config_file) | ||
|
||
def __rename_file(self, current_name, new_name): | ||
logging.info("Rename: %s --> %s" % (current_name, new_name)) | ||
current_path = os.path.join(self.__projdir, current_name) | ||
new_path = os.path.join(self.__projdir, new_name) | ||
os.rename(current_path, new_path) | ||
|
||
def __rename_store_files(self, current_base_name, new_base_name): | ||
current_xml = current_base_name + ".xml" | ||
current_md5 = current_base_name + ".md5" | ||
new_xml = new_base_name + ".xml" | ||
new_md5 = new_base_name + ".md5" | ||
|
||
if current_base_name != new_base_name: | ||
self.__rename_file(current_xml, new_xml) | ||
self.__rename_file(current_md5, new_md5) | ||
else: | ||
logging.info("%s already restored" % (new_base_name)) | ||
return new_xml | ||
|
||
def __restore_store_file(self, id): | ||
store = self.__config_tree.getroot().findall("./store[@id='%s']" % (id))[0] | ||
store_type = store.get('type') | ||
logging.debug("Restore file of store '%s' of type '%s'" % (id, store_type)) | ||
|
||
url = store.findall("./connectionCredentials/credential[@name='url']")[0] | ||
url.text = self.__rename_store_files(url.text[:-len('.xml')], store_type) | ||
|
||
def restore_names(self): | ||
root = self.__config_tree.getroot() | ||
assembly_name = root.get('activeAssembly') | ||
logging.debug("Using assembly '%s'" % (assembly_name)) | ||
for component in root.findall("assembly[@id='%s']/component" % (assembly_name)): | ||
self.__restore_store_file(component.get('id')) | ||
|
||
self.__config_tree.write(self.__config_file) | ||
logging.info("configs.xml updated") | ||
|
||
def main(): | ||
prog = sys.argv[0] | ||
version = "%prog 1.0.0" | ||
usage = "%prog OPTIONS" | ||
epilog = "Restores the original names of entity store files after running `projupgrade` tool." | ||
|
||
parser = OptionParser(usage=usage, version=version, epilog=epilog) | ||
parser.add_option("-v", "--verbose", dest="verbose", help="Enable verbose messages [optional]", action="store_true") | ||
parser.add_option("--projdir", dest="projdir", help="Project directory (contains 'configs.xml' file)", metavar="PROJDIR") | ||
|
||
(options, args) = parser.parse_args() | ||
|
||
if not options.projdir: | ||
parser.error("Project directory is missing!") | ||
|
||
try: | ||
# Configure logging | ||
logging.basicConfig(format='%(levelname)s: %(message)s') | ||
if options.verbose: | ||
logging.getLogger().setLevel(logging.DEBUG) | ||
else: | ||
logging.getLogger().setLevel(logging.INFO) | ||
|
||
# Restore file names | ||
proj = ProjectFiles(options.projdir) | ||
proj.restore_names() | ||
|
||
except Exception as e: | ||
if options.verbose: | ||
logging.error("Error occurred, check details:", exc_info=True) | ||
else: | ||
logging.error("%r" % (e)) | ||
sys.exit(1) | ||
|
||
sys.exit(0) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
if [ "${AXWAY_HOME}" != "" ] | ||
then | ||
JYTHON=${AXWAY_HOME}/apigateway/posix/bin/jython | ||
if [ $(uname -o) == "Msys" ] | ||
then | ||
JYTHON=${AXWAY_HOME}/apigateway/Win32/bin/jython.bat | ||
fi | ||
|
||
if [ -f "${JYTHON}" ] | ||
then | ||
CMD_HOME=`dirname $0` | ||
"${JYTHON}" "${CMD_HOME}/restorefilenames.py" $* | ||
else | ||
echo "ERROR: Jython interpreter not found: ${JYTHON}" | ||
fi | ||
else | ||
echo "ERROR: environment variable AXWAY_HOME not set" | ||
fi |