BugFix for integration of the LESS stylesheet compiler into the theme publishing process

git-svn-id: https://svn.libreccm.org/ccm/trunk@5741 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2018-11-21 18:07:14 +00:00
parent 50ec8b6c4e
commit a567d09675
2 changed files with 89 additions and 54 deletions

View File

@ -15,7 +15,6 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package com.arsdigita.themedirector.ui.listeners; package com.arsdigita.themedirector.ui.listeners;
import com.arsdigita.bebop.event.ActionEvent; import com.arsdigita.bebop.event.ActionEvent;
@ -54,38 +53,53 @@ import org.apache.log4j.Logger;
public class ApproveThemeActionListener implements ThemeDirectorConstants, public class ApproveThemeActionListener implements ThemeDirectorConstants,
ActionListener { ActionListener {
/** Internal logger instance to faciliate debugging. Enable logging output /**
* by editing /WEB-INF/conf/log4j.properties int the runtime environment * Internal logger instance to faciliate debugging. Enable logging output by
* and set * editing /WEB-INF/conf/log4j.properties int the runtime environment and
* set
* com.arsdigita.themedirector.ui.listeners.ApproveThemeActionListener=DEBUG * com.arsdigita.themedirector.ui.listeners.ApproveThemeActionListener=DEBUG
* by uncommenting or adding the line. */ * by uncommenting or adding the line.
private static final Logger s_log = Logger.getLogger( */
private static final Logger LOGGER = Logger.getLogger(
ApproveThemeActionListener.class); ApproveThemeActionListener.class);
private final ThemeSelectionModel m_model; private final ThemeSelectionModel selectionModel;
/** /**
* Constructor, just stores the ThemeSelectionModel. * Constructor, just stores the ThemeSelectionModel.
* *
* @param model the ThemeSelectionModel * @param selectionModel the ThemeSelectionModel
*/ */
public ApproveThemeActionListener(ThemeSelectionModel model) { public ApproveThemeActionListener(
m_model = model; final ThemeSelectionModel selectionModel) {
this.selectionModel = selectionModel;
} }
/** /**
* *
* @param e * @param event
*/ */
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(final ActionEvent event) {
// First, we rename the current production directory so that if there // First, we rename the current production directory so that if there
// is an exception, we can try to move it back in to place // is an exception, we can try to move it back in to place
Theme theme = m_model.getSelectedTheme(e.getPageState()); final Theme theme = selectionModel
File currentRoot = new File(Web.getServletContext().getRealPath("/")); .getSelectedTheme(event.getPageState());
File oldProd = new File(currentRoot, PROD_THEMES_BASE_DIR +
theme.getURL()); final File currentRoot = new File(
File backupFile = new File(oldProd.getAbsolutePath() + ".bak"); Web.getServletContext().getRealPath("/"));
final File newProd = new File(currentRoot, PROD_THEMES_BASE_DIR);
final File devDir = new File(currentRoot,
DEV_THEMES_BASE_DIR + theme.getURL());
ThemeFileUtil.prepareThemeDirectory(devDir.getAbsolutePath());
final File oldProd = new File(currentRoot,
PROD_THEMES_BASE_DIR + theme.getURL());
final File backupFile = new File(oldProd.getAbsolutePath() + ".bak");
if (oldProd.exists()) { if (oldProd.exists()) {
oldProd.renameTo(backupFile); oldProd.renameTo(backupFile);
@ -93,50 +107,66 @@ public class ApproveThemeActionListener implements ThemeDirectorConstants,
oldProd.mkdirs(); oldProd.mkdirs();
// now, we copy the "dev" directory to the "prd" directory // now, we copy the "dev" directory to the "prd" directory
File newProd = new File(currentRoot, PROD_THEMES_BASE_DIR);
File devDir = new File(currentRoot, DEV_THEMES_BASE_DIR +
theme.getURL());
try { try {
// sort filepaths to be copied alphabetically, so that the // sort filepaths to be copied alphabetically, so that the
// directory is always created before the files contained therein // directory is always created before the files contained therein
Set filesToCopy = new TreeSet(Arrays.asList(Files.listFilesInTree(devDir, final Set<String> filesToCopy = new TreeSet<>(
Arrays.asList(Files
.listFilesInTree(devDir,
new WhiteListFilenameFilter()))); new WhiteListFilenameFilter())));
for (Iterator it=filesToCopy.iterator(); it.hasNext(); ) {
String path = (String) it.next(); for (String path : filesToCopy) {
File src = new File(devDir, path);
final File src = new File(devDir, path);
if (src.isDirectory()) { if (src.isDirectory()) {
s_log.debug("creating directory " + path); LOGGER.debug("creating directory " + path);
new File(newProd, theme.getURL() + File.separator + path).mkdirs(); new File(newProd, theme.getURL() + File.separator + path)
.mkdirs();
} else { } else {
s_log.debug("Copying file " + path); LOGGER.debug("Copying file " + path);
Files.copy(src, new File(newProd, theme.getURL() + File.separator + path)); Files.copy(src,
new File(newProd,
theme.getURL()
+ File.separator
+ path));
} }
} }
// assuming that went well, we need to move the devDir in to the // assuming that went well, we need to move the devDir in to the
// database as the latest "live" files but before we do that, we // database as the latest "live" files but before we do that, we
// copy is_deleted flag from development to published files // copy is_deleted flag from development to published files
DataOperation op = SessionManager.getSession().retrieveDataOperation( final DataOperation op = SessionManager
.getSession()
.retrieveDataOperation(
"com.arsdigita.themedirector.bulkFileUpdate"); "com.arsdigita.themedirector.bulkFileUpdate");
op.setParameter("themeID", theme.getID()); op.setParameter("themeID", theme.getID());
op.setParameter("timestamp", new Date()); op.setParameter("timestamp", new Date());
op.execute(); op.execute();
ThemeFileUtil.updateDatabaseFiles(devDir, theme, ThemeFileUtil.updateDatabaseFiles(devDir,
devDir.getAbsolutePath(), true, theme,
devDir.getAbsolutePath(),
true,
ThemeFile.LIVE); ThemeFile.LIVE);
// since we are publishing, we also want to share the DEV files // since we are publishing, we also want to share the DEV files
ThemeFileUtil.updateDatabaseFiles(devDir, theme, ThemeFileUtil.updateDatabaseFiles(devDir,
devDir.getAbsolutePath(), true, theme,
devDir.getAbsolutePath(),
true,
ThemeFile.DRAFT); ThemeFile.DRAFT);
// add the observer to make sure that it syncs with other // add the observer to make sure that it syncs with other
// servers in the cluster // servers in the cluster
theme.addObserver(new ThemeObserver()); theme.addObserver(new ThemeObserver());
} catch (IOException ex) { } catch (IOException ex) {
String errorMsg = "There was an error moving files from " + final String errorMsg = "There was an error moving files from "
devDir.getAbsolutePath() + " to " + + devDir.getAbsolutePath()
newProd.getAbsolutePath(); + " to "
s_log.error(errorMsg, ex); + newProd.getAbsolutePath();
LOGGER.error(errorMsg, ex);
// delete the directory and move the oldProd back // delete the directory and move the oldProd back
Files.delete(new File(newProd + theme.getURL())); Files.delete(new File(newProd + theme.getURL()));
if (oldProd.exists()) { if (oldProd.exists()) {
@ -157,5 +187,5 @@ public class ApproveThemeActionListener implements ThemeDirectorConstants,
// add it to the subsite drop down list // add it to the subsite drop down list
Subsite.getConfig().addTheme(theme.getURL(), theme.getTitle()); Subsite.getConfig().addTheme(theme.getURL(), theme.getTitle());
} }
}
}

View File

@ -40,7 +40,6 @@ import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
/** /**
* This is a utility class that is able to take a theme and, when necessary, * This is a utility class that is able to take a theme and, when necessary,
@ -79,10 +78,12 @@ public class ThemeFileUtil {
* ThemeFile.DRAFT are the two allowed values. * ThemeFile.DRAFT are the two allowed values.
* *
*/ */
public static void updateDatabaseFiles(File currentFile, Theme currentTheme, public static void updateDatabaseFiles(File currentFile,
Theme currentTheme,
String serverSpecificPath, String serverSpecificPath,
boolean overwriteNewerFiles, boolean overwriteNewerFiles,
String fileType) { String fileType) {
Assert.isTrue(ThemeFile.LIVE.equals(fileType) || ThemeFile.DRAFT.equals( Assert.isTrue(ThemeFile.LIVE.equals(fileType) || ThemeFile.DRAFT.equals(
fileType)); fileType));
@ -103,8 +104,12 @@ public class ThemeFileUtil {
} }
} }
updateDatabaseFiles(currentFile, currentTheme, serverSpecificPath, updateDatabaseFiles(currentFile,
themeFiles, overwriteNewerFiles, fileType); currentTheme,
serverSpecificPath,
themeFiles,
overwriteNewerFiles,
fileType);
} }
/** /**
@ -115,7 +120,7 @@ public class ThemeFileUtil {
* *
* @param themePath * @param themePath
*/ */
private static void prepareThemeDirectory(final String themePath) { public static void prepareThemeDirectory(final String themePath) {
final Path root = Paths.get(themePath); final Path root = Paths.get(themePath);