Skip to content

Commit

Permalink
PAYARA-1922-Wrong-file-structure-when-packaging-a-custom-glassfish-ac…
Browse files Browse the repository at this point in the history
…c.xml-file-with-the-package-appclient-utility-script (payara#1877)
  • Loading branch information
mulderbaba authored and michaelranaldo committed Sep 12, 2017
1 parent f1a32bd commit a6bb9f0
Showing 1 changed file with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* only if the new code is made subject to such option by the copyright
* holder.
*/
// Portions Copyright [2017] [Payara Foundation and/or its affiliates]

package org.glassfish.appclient.client.packageappclient;

Expand Down Expand Up @@ -150,6 +151,9 @@ public class PackageAppClient {
private final static String ASENV_CONF = GLASSFISH_CONFIG + "/asenv.conf";
private final static String ASENV_BAT = GLASSFISH_CONFIG + "/asenv.bat";

private static final char UNIX_SEPARATOR = '/';
private static final char WINDOWS_SEPARATOR = '\\';

private final static String[] SINGLE_FILES_TO_COPY = {
IMQJMSRA_APP,
IMQ_JAR,
Expand Down Expand Up @@ -241,8 +245,14 @@ private void run(final String[] args) throws URISyntaxException, IOException {
/*
* The glassfish-acc.xml file and sun-acc.xml files.
*/
boolean customConfigFileProvided = argValue("-xml", args) != null;
for (File configFile : configFiles) {
addFile(os, installDir.toURI(), configFile.toURI(), tempFile, "");
if (!customConfigFileProvided) {
addFile(os, installDir.toURI(), configFile.toURI(), tempFile, "");
} else {
addFile(os, configFile.toURI(), tempFile, "",
DOMAIN_1_CONFIG + File.separator + getFileName(configFile.toURI().toString()));
}
}

os.close();
Expand Down Expand Up @@ -310,6 +320,16 @@ private void addFile(
final File outputFile,
final String indent
) throws IOException {
addFile(os, absoluteURIToAdd, outputFile, indent, installDirURI.relativize(absoluteURIToAdd).toString());
}

private void addFile(
final JarOutputStream os,
final URI absoluteURIToAdd,
final File outputFile,
final String indent,
final String relativizedURL
) throws IOException {
try {
if (isVerbose) {
System.err.println(indent + strings.get("addingFile", absoluteURIToAdd));
Expand All @@ -319,7 +339,8 @@ private void addFile(
return;
}

JarEntry entry = new JarEntry(OUTPUT_PREFIX + installDirURI.relativize(absoluteURIToAdd).toString());
JarEntry entry = new JarEntry(OUTPUT_PREFIX + relativizedURL);

try {
/*
* Some modules in the GlassFish build are marked as optional
Expand Down Expand Up @@ -356,6 +377,23 @@ private void addFile(
}
}

private String getFileName(String filename) {
if (filename == null) {
return null;
}
int index = indexOfLastSeparator(filename);
return filename.substring(index + 1);
}

private int indexOfLastSeparator(String filename) {
if (filename == null) {
return -1;
}
int lastUnixPos = filename.lastIndexOf(UNIX_SEPARATOR);
int lastWindowsPos = filename.lastIndexOf(WINDOWS_SEPARATOR);
return Math.max(lastUnixPos, lastWindowsPos);
}

/**
* Add all the files from the specified directory, recursing to lower-level
* subdirectories.
Expand Down Expand Up @@ -426,7 +464,7 @@ private void addDir(
*/
private void copyFileToStream(
final OutputStream os,
final URI uriToCopy) throws FileNotFoundException, IOException {
final URI uriToCopy) throws IOException {
File fileToCopy = new File(uriToCopy);
InputStream is = new BufferedInputStream(new FileInputStream(fileToCopy));
try {
Expand Down Expand Up @@ -501,13 +539,10 @@ private File[] chooseConfigFiles(final File installDir, final String[] args) {
final File userSpecifiedFile = new File(xmlArg);
files = new File[] {userSpecifiedFile};
if ( ! userSpecifiedFile.exists()) {
System.err.println(strings.get("xmlNotFound", userSpecifiedFile.getAbsolutePath()));
}


System.err.println(strings.get("xmlNotFound", userSpecifiedFile.getAbsolutePath()));
}
}
return files;

}

private File findInstallDir(final File currentJarFile) throws URISyntaxException {
Expand Down

0 comments on commit a6bb9f0

Please sign in to comment.