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

thumbnail
Gordon Augat, geändert vor 7 Jahren. Regular Member Beiträge: 107 Beitrittsdatum: 16.08.06 Neueste Beiträge
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, geändert vor 6 Jahren. Regular Member Beiträge: 107 Beitrittsdatum: 16.08.06 Neueste Beiträge
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, geändert vor 6 Jahren. Liferay Legend Beiträge: 2416 Beitrittsdatum: 22.12.10 Neueste Beiträge
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, geändert vor 6 Jahren. Junior Member Beiträge: 89 Beitrittsdatum: 08.10.11 Neueste Beiträge
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.