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-94f89814c4dfmaster
parent
50ec8b6c4e
commit
a567d09675
|
|
@ -15,7 +15,6 @@
|
|||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.arsdigita.themedirector.ui.listeners;
|
||||
|
||||
import com.arsdigita.bebop.event.ActionEvent;
|
||||
|
|
@ -49,43 +48,58 @@ import org.apache.log4j.Logger;
|
|||
* This is done by copying the files from the devel directory into the published
|
||||
* directory.
|
||||
*
|
||||
* @author Randy Graebner <randyg@redhat.com>
|
||||
* @author Randy Graebner <randyg@redhat.com>
|
||||
*/
|
||||
public class ApproveThemeActionListener implements ThemeDirectorConstants,
|
||||
ActionListener {
|
||||
|
||||
/** Internal logger instance to faciliate debugging. Enable logging output
|
||||
* by editing /WEB-INF/conf/log4j.properties int the runtime environment
|
||||
* and set
|
||||
* com.arsdigita.themedirector.ui.listeners.ApproveThemeActionListener=DEBUG
|
||||
* by uncommenting or adding the line. */
|
||||
private static final Logger s_log = Logger.getLogger(
|
||||
ApproveThemeActionListener.class);
|
||||
/**
|
||||
* Internal logger instance to faciliate debugging. Enable logging output by
|
||||
* editing /WEB-INF/conf/log4j.properties int the runtime environment and
|
||||
* set
|
||||
* com.arsdigita.themedirector.ui.listeners.ApproveThemeActionListener=DEBUG
|
||||
* by uncommenting or adding the line.
|
||||
*/
|
||||
private static final Logger LOGGER = Logger.getLogger(
|
||||
ApproveThemeActionListener.class);
|
||||
|
||||
private final ThemeSelectionModel m_model;
|
||||
private final ThemeSelectionModel selectionModel;
|
||||
|
||||
/**
|
||||
* Constructor, just stores the ThemeSelectionModel.
|
||||
*
|
||||
* @param model the ThemeSelectionModel
|
||||
* @param selectionModel the ThemeSelectionModel
|
||||
*/
|
||||
public ApproveThemeActionListener(ThemeSelectionModel model) {
|
||||
m_model = model;
|
||||
public ApproveThemeActionListener(
|
||||
final ThemeSelectionModel selectionModel) {
|
||||
|
||||
this.selectionModel = selectionModel;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param e
|
||||
* @param event
|
||||
*/
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
public void actionPerformed(final ActionEvent event) {
|
||||
|
||||
// First, we rename the current production directory so that if there
|
||||
// is an exception, we can try to move it back in to place
|
||||
Theme theme = m_model.getSelectedTheme(e.getPageState());
|
||||
File currentRoot = new File(Web.getServletContext().getRealPath("/"));
|
||||
File oldProd = new File(currentRoot, PROD_THEMES_BASE_DIR +
|
||||
theme.getURL());
|
||||
File backupFile = new File(oldProd.getAbsolutePath() + ".bak");
|
||||
final Theme theme = selectionModel
|
||||
.getSelectedTheme(event.getPageState());
|
||||
|
||||
final File currentRoot = new File(
|
||||
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()) {
|
||||
oldProd.renameTo(backupFile);
|
||||
|
|
@ -93,56 +107,72 @@ public class ApproveThemeActionListener implements ThemeDirectorConstants,
|
|||
|
||||
oldProd.mkdirs();
|
||||
// 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 {
|
||||
// sort filepaths to be copied alphabetically, so that the
|
||||
// directory is always created before the files contained therein
|
||||
Set filesToCopy = new TreeSet(Arrays.asList(Files.listFilesInTree(devDir,
|
||||
new WhiteListFilenameFilter())));
|
||||
for (Iterator it=filesToCopy.iterator(); it.hasNext(); ) {
|
||||
String path = (String) it.next();
|
||||
File src = new File(devDir, path);
|
||||
final Set<String> filesToCopy = new TreeSet<>(
|
||||
Arrays.asList(Files
|
||||
.listFilesInTree(devDir,
|
||||
new WhiteListFilenameFilter())));
|
||||
|
||||
for (String path : filesToCopy) {
|
||||
|
||||
final File src = new File(devDir, path);
|
||||
|
||||
if (src.isDirectory()) {
|
||||
s_log.debug("creating directory " + path);
|
||||
new File(newProd, theme.getURL() + File.separator + path).mkdirs();
|
||||
LOGGER.debug("creating directory " + path);
|
||||
new File(newProd, theme.getURL() + File.separator + path)
|
||||
.mkdirs();
|
||||
} else {
|
||||
s_log.debug("Copying file " + path);
|
||||
Files.copy(src, new File(newProd, theme.getURL() + File.separator + path));
|
||||
LOGGER.debug("Copying file " + 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
|
||||
// database as the latest "live" files but before we do that, we
|
||||
// copy is_deleted flag from development to published files
|
||||
DataOperation op = SessionManager.getSession().retrieveDataOperation(
|
||||
"com.arsdigita.themedirector.bulkFileUpdate");
|
||||
final DataOperation op = SessionManager
|
||||
.getSession()
|
||||
.retrieveDataOperation(
|
||||
"com.arsdigita.themedirector.bulkFileUpdate");
|
||||
op.setParameter("themeID", theme.getID());
|
||||
op.setParameter("timestamp", new Date());
|
||||
op.execute();
|
||||
ThemeFileUtil.updateDatabaseFiles(devDir, theme,
|
||||
devDir.getAbsolutePath(), true,
|
||||
ThemeFileUtil.updateDatabaseFiles(devDir,
|
||||
theme,
|
||||
devDir.getAbsolutePath(),
|
||||
true,
|
||||
ThemeFile.LIVE);
|
||||
|
||||
// since we are publishing, we also want to share the DEV files
|
||||
ThemeFileUtil.updateDatabaseFiles(devDir, theme,
|
||||
devDir.getAbsolutePath(), true,
|
||||
ThemeFileUtil.updateDatabaseFiles(devDir,
|
||||
theme,
|
||||
devDir.getAbsolutePath(),
|
||||
true,
|
||||
ThemeFile.DRAFT);
|
||||
|
||||
// add the observer to make sure that it syncs with other
|
||||
// servers in the cluster
|
||||
theme.addObserver(new ThemeObserver());
|
||||
|
||||
} catch (IOException ex) {
|
||||
String errorMsg = "There was an error moving files from " +
|
||||
devDir.getAbsolutePath() + " to " +
|
||||
newProd.getAbsolutePath();
|
||||
s_log.error(errorMsg, ex);
|
||||
final String errorMsg = "There was an error moving files from "
|
||||
+ devDir.getAbsolutePath()
|
||||
+ " to "
|
||||
+ newProd.getAbsolutePath();
|
||||
LOGGER.error(errorMsg, ex);
|
||||
// delete the directory and move the oldProd back
|
||||
Files.delete(new File(newProd + theme.getURL()));
|
||||
if (oldProd.exists()) {
|
||||
oldProd.renameTo(new File(currentRoot,
|
||||
PROD_THEMES_BASE_DIR + theme.getURL()
|
||||
));
|
||||
));
|
||||
}
|
||||
throw new UncheckedWrapperException(errorMsg, ex);
|
||||
}
|
||||
|
|
@ -157,5 +187,5 @@ public class ApproveThemeActionListener implements ThemeDirectorConstants,
|
|||
// add it to the subsite drop down list
|
||||
Subsite.getConfig().addTheme(theme.getURL(), theme.getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ import java.nio.file.Paths;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
public static void updateDatabaseFiles(File currentFile, Theme currentTheme,
|
||||
public static void updateDatabaseFiles(File currentFile,
|
||||
Theme currentTheme,
|
||||
String serverSpecificPath,
|
||||
boolean overwriteNewerFiles,
|
||||
String fileType) {
|
||||
|
||||
Assert.isTrue(ThemeFile.LIVE.equals(fileType) || ThemeFile.DRAFT.equals(
|
||||
fileType));
|
||||
|
||||
|
|
@ -103,8 +104,12 @@ public class ThemeFileUtil {
|
|||
}
|
||||
}
|
||||
|
||||
updateDatabaseFiles(currentFile, currentTheme, serverSpecificPath,
|
||||
themeFiles, overwriteNewerFiles, fileType);
|
||||
updateDatabaseFiles(currentFile,
|
||||
currentTheme,
|
||||
serverSpecificPath,
|
||||
themeFiles,
|
||||
overwriteNewerFiles,
|
||||
fileType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -115,7 +120,7 @@ public class ThemeFileUtil {
|
|||
*
|
||||
* @param themePath
|
||||
*/
|
||||
private static void prepareThemeDirectory(final String themePath) {
|
||||
public static void prepareThemeDirectory(final String themePath) {
|
||||
|
||||
final Path root = Paths.get(themePath);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue