RE: Liferay IDE 3.5 - External properties file gets overridden (wiped out)

thumbnail
Gordon Augat, modified 6 Years ago. Regular Member Posts: 107 Join Date: 8/16/06 Recent Posts
When you specify an external properties file to use, the file gets completly overridden and you lose your custom settings.  The new external properties file just has the following...

# Last modified by Liferay IDE Wed Feb 20 09:38:31 MST 2019

include-and-override=[some location]\portal-ide.properties

I believe the problem is in the LiferayTomcatUtil.java class with the _setupExternalPropertiesFile method. The current code wipes out my settings.

Current code...

private static File _setupExternalPropertiesFile(File portalIdePropFile, String externalPropertiesPath) {
        File retval = null;

        File externalPropertiesFile = new File(externalPropertiesPath);

        if (FileUtil.exists(externalPropertiesFile)) {
            ExternalPropertiesConfiguration props = new ExternalPropertiesConfiguration();

            try (InputStream newInputStream = Files.newInputStream(externalPropertiesFile.toPath());
                OutputStream outputStream = Files.newOutputStream(externalPropertiesFile.toPath())) {

                props.load(newInputStream);
                props.setProperty("include-and-override", portalIdePropFile.getAbsolutePath());
                props.setHeader("# Last modified by Liferay IDE " + new Date());
                props.save(outputStream);

                retval = externalPropertiesFile;
            }
            catch (Exception e) {
                retval = null;
            }
        }
        else {
            retval = null;
        }

        return retval;
    }

When I revert the code back to the following, it works.

private static File _setupExternalPropertiesFile(File portalIdePropFile, String externalPropertiesPath) {
        File retval = null;

        File externalPropertiesFile = new File(externalPropertiesPath);

        if (FileUtil.exists(externalPropertiesFile)) {
            ExternalPropertiesConfiguration props = new ExternalPropertiesConfiguration();

            try (InputStream newInputStream = Files.newInputStream(externalPropertiesFile.toPath())) {
                props.load(newInputStream);
                props.setProperty("include-and-override", portalIdePropFile.getAbsolutePath());
                props.setHeader("# Last modified by Liferay IDE " + new Date());
                props.save(Files.newOutputStream(externalPropertiesFile.toPath()));

                retval = externalPropertiesFile;
            }
            catch (Exception e) {
                retval = null;
            }
        }
        else {
            retval = null;
        }

        return retval;
    }

Notice how the output stream is not created in the try statement as in the current code.  When it is created in the try statement, it does not work.
thumbnail
Gordon Augat, modified 6 Years ago. Regular Member Posts: 107 Join Date: 8/16/06 Recent Posts
Cleaner code in the try catch block...

                try  {
                    props.load(externalPropertiesFile.getAbsolutePath());
                    props.setProperty("include-and-override", portalIdePropFile.getAbsolutePath());
                    props.setHeader("# Last modified by Liferay IDE (3.6.2-ga3) " + new Date());
                    props.save(externalPropertiesFile.getAbsolutePath());
    
                    retval = externalPropertiesFile;
                }
                catch (Exception e) {
                    retval = null;
                }
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hey Gordon,

If you have the time, would you mind opening a ticket at issues.liferay.com and then updating this thread with a link to it? That way if someone else comes alogn later, they can follow the trail and see the status of the issue (and any dialogue from the Liferay team). 
thumbnail
Yanan Yuan, modified 6 Years ago. Junior Member Posts: 89 Join Date: 10/8/11 Recent Posts
Hello Gordon,

Thanks for catching this problem. And thanks Andrew for prompt creating a ticket on issues.liferay.com.

I've created a ticket which will be fixed in next release.