diff --git a/maven.j2ee/src/org/netbeans/modules/maven/j2ee/MavenJavaEEConstants.java b/maven.j2ee/src/org/netbeans/modules/maven/j2ee/MavenJavaEEConstants.java --- a/maven.j2ee/src/org/netbeans/modules/maven/j2ee/MavenJavaEEConstants.java +++ b/maven.j2ee/src/org/netbeans/modules/maven/j2ee/MavenJavaEEConstants.java @@ -69,6 +69,15 @@ * @since NetBeans 7.0 */ public static final String HINT_DEPLOY_ON_SAVE = "netbeans.deploy.on.save"; //NOI18N + + /** + * Optional property, if static resources should be copy to the target directory on save. + * + */ + public static final String HINT_COPY_STATIC_RESOURCES_ON_SAVE = "netbeans.copy.static.resources.on.save"; //NOI18N /** * when present, will deploy the web/ejb/ear project to an app server diff --git a/maven.j2ee/src/org/netbeans/modules/maven/j2ee/ui/customizer/impl/Bundle.properties b/maven.j2ee/src/org/netbeans/modules/maven/j2ee/ui/customizer/impl/Bundle.properties --- a/maven.j2ee/src/org/netbeans/modules/maven/j2ee/ui/customizer/impl/Bundle.properties +++ b/maven.j2ee/src/org/netbeans/modules/maven/j2ee/ui/customizer/impl/Bundle.properties @@ -50,3 +50,4 @@ CustomizerRunWeb.dosDescription.text=If selected, files are compiled and deployed when you save them.
This option saves you time when you run or debug your application in the IDE. CustomizerRunWeb.dosDescriptionIfDisabled.text=If selected, files are compiled and deployed when you save them.
This option saves you time when you run or debug your application in the IDE.
NOTE: If you want to enable Deploy on Save feature you will need to change Compile on Save first (you can do that in Build/Compile project properties) CustomizerRunWeb.browserLabel.text=B&rowser: +CustomizerRunWeb.jCheckBoxCopyStaticResources.text=Compile Static Resources on Save diff --git a/maven.j2ee/src/org/netbeans/modules/maven/j2ee/ui/customizer/impl/CustomizerRunWeb.form b/maven.j2ee/src/org/netbeans/modules/maven/j2ee/ui/customizer/impl/CustomizerRunWeb.form --- a/maven.j2ee/src/org/netbeans/modules/maven/j2ee/ui/customizer/impl/CustomizerRunWeb.form +++ b/maven.j2ee/src/org/netbeans/modules/maven/j2ee/ui/customizer/impl/CustomizerRunWeb.form @@ -16,7 +16,7 @@ - + @@ -45,8 +45,11 @@ - - + + + + + @@ -86,6 +89,8 @@ + + @@ -225,5 +230,12 @@ + + + + + + + diff --git a/maven.j2ee/src/org/netbeans/modules/maven/j2ee/ui/customizer/impl/CustomizerRunWeb.java b/maven.j2ee/src/org/netbeans/modules/maven/j2ee/ui/customizer/impl/CustomizerRunWeb.java --- a/maven.j2ee/src/org/netbeans/modules/maven/j2ee/ui/customizer/impl/CustomizerRunWeb.java +++ b/maven.j2ee/src/org/netbeans/modules/maven/j2ee/ui/customizer/impl/CustomizerRunWeb.java @@ -58,8 +58,8 @@ import org.netbeans.modules.maven.j2ee.MavenJavaEEConstants; import org.netbeans.modules.maven.j2ee.utils.Server; import org.netbeans.modules.maven.j2ee.ui.customizer.BaseRunCustomizer; +import org.netbeans.modules.maven.j2ee.ui.util.CopyStaticResourcesOnSaveCheckBoxUpdater; import org.netbeans.modules.maven.j2ee.utils.LoggingUtils; -import org.netbeans.modules.maven.j2ee.utils.MavenProjectSupport; import org.netbeans.modules.maven.j2ee.web.WebModuleImpl; import org.netbeans.modules.maven.j2ee.web.WebModuleProviderImpl; import org.netbeans.modules.web.api.webmodule.WebModule; @@ -108,6 +108,8 @@ initServerModel(serverCBox, serverLabel, J2eeModule.Type.WAR); initVersionModel(javaeeVersionCBox, javaeeVersionLabel, J2eeModule.Type.WAR); initDeployOnSave(jCheckBoxDeployOnSave, dosDescription); + + CopyStaticResourcesOnSaveCheckBoxUpdater.create(project, jCheckBoxCopyStaticResources); } @Override @@ -133,7 +135,7 @@ public void applyChanges() { changeServer(serverCBox); changeContextPath(); - + JavaEEProjectSettings.setBrowserID(project, browserModel.getSelectedBrowserId()); } @@ -277,6 +279,7 @@ javaeeVersionCBox = new javax.swing.JComboBox(); browserLabel = new javax.swing.JLabel(); browserCBox = createBrowserComboBox(); + jCheckBoxCopyStaticResources = new javax.swing.JCheckBox(); serverLabel.setLabelFor(serverCBox); org.openide.awt.Mnemonics.setLocalizedText(serverLabel, org.openide.util.NbBundle.getMessage(CustomizerRunWeb.class, "LBL_Server")); // NOI18N @@ -312,6 +315,8 @@ org.openide.awt.Mnemonics.setLocalizedText(browserLabel, org.openide.util.NbBundle.getMessage(CustomizerRunWeb.class, "CustomizerRunWeb.browserLabel.text")); // NOI18N + org.openide.awt.Mnemonics.setLocalizedText(jCheckBoxCopyStaticResources, org.openide.util.NbBundle.getMessage(CustomizerRunWeb.class, "CustomizerRunWeb.jCheckBoxCopyStaticResources.text")); // NOI18N + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -341,7 +346,9 @@ .addComponent(jCheckBoxDeployOnSave) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() - .addComponent(showBrowserCheckBox) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) + .addComponent(showBrowserCheckBox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(jCheckBoxCopyStaticResources, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(0, 0, Short.MAX_VALUE)))) ); layout.setVerticalGroup( @@ -372,6 +379,8 @@ .addGap(18, 18, 18) .addComponent(showBrowserCheckBox) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(jCheckBoxCopyStaticResources) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jCheckBoxDeployOnSave) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(dosDescription, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) @@ -413,6 +422,7 @@ private javax.swing.JLabel contextPathLabel; private javax.swing.JTextField contextPathTField; private javax.swing.JLabel dosDescription; + private javax.swing.JCheckBox jCheckBoxCopyStaticResources; private javax.swing.JCheckBox jCheckBoxDeployOnSave; private javax.swing.JComboBox javaeeVersionCBox; private javax.swing.JLabel javaeeVersionLabel; diff --git a/maven.j2ee/src/org/netbeans/modules/maven/j2ee/ui/util/CopyStaticResourcesOnSaveCheckBoxUpdater.java b/maven.j2ee/src/org/netbeans/modules/maven/j2ee/ui/util/CopyStaticResourcesOnSaveCheckBoxUpdater.java new file mode 100644 --- /dev/null +++ b/maven.j2ee/src/org/netbeans/modules/maven/j2ee/ui/util/CopyStaticResourcesOnSaveCheckBoxUpdater.java @@ -0,0 +1,102 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2013 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2013 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.maven.j2ee.ui.util; + +import java.util.prefs.Preferences; +import javax.swing.JCheckBox; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectUtils; +import org.netbeans.modules.maven.api.customizer.support.CheckBoxUpdater; +import org.netbeans.modules.maven.j2ee.MavenJavaEEConstants; +import org.netbeans.modules.maven.j2ee.utils.MavenProjectSupport; + +/** + * + * @author Martin Janicek + */ +public class CopyStaticResourcesOnSaveCheckBoxUpdater extends CheckBoxUpdater { + + private final Project project; + private final boolean defaultValue; + + private CopyStaticResourcesOnSaveCheckBoxUpdater(Project project, JCheckBox compileStaticResourcesCheckBox) { + super(compileStaticResourcesCheckBox); + this.project = project; + this.defaultValue = MavenProjectSupport.isCopyStaticResourcesOnSave(project); + } + + + /** + * Factory method encapsulating CheckBoxUpdater creation. Typically client don't + * want to do anything with a new instance so this makes more sense than creating + * it using "new" keyword. + * + * @param project project for which we want to change DoS + * @param deployOnSaveCheckBox Deploy on Save check box for which we want to create updater + */ + public static void create(Project project, JCheckBox deployOnSaveCheckBox) { + new CopyStaticResourcesOnSaveCheckBoxUpdater(project, deployOnSaveCheckBox); + } + + @Override + public Boolean getValue() { + Preferences preferences = ProjectUtils.getPreferences(project, DeployOnSaveCheckBoxUpdater.class, true); + String value = preferences.get(MavenJavaEEConstants.HINT_COPY_STATIC_RESOURCES_ON_SAVE, null); + + if (value != null) { + return Boolean.parseBoolean(value); + } else { + return null; + } + } + + @Override + public void setValue(Boolean value) { + MavenProjectSupport.setCopyStaticResourcesOnSave(project, value); + } + + @Override + public boolean getDefaultValue() { + return defaultValue; + } +} diff --git a/maven.j2ee/src/org/netbeans/modules/maven/j2ee/utils/MavenProjectSupport.java b/maven.j2ee/src/org/netbeans/modules/maven/j2ee/utils/MavenProjectSupport.java --- a/maven.j2ee/src/org/netbeans/modules/maven/j2ee/utils/MavenProjectSupport.java +++ b/maven.j2ee/src/org/netbeans/modules/maven/j2ee/utils/MavenProjectSupport.java @@ -68,7 +68,6 @@ import org.netbeans.modules.maven.api.execute.RunUtils; import org.netbeans.modules.maven.api.problem.ProblemReport; import org.netbeans.modules.maven.api.problem.ProblemReporter; -import org.netbeans.modules.maven.j2ee.CopyOnSave; import org.netbeans.modules.maven.j2ee.MavenJavaEEConstants; import org.netbeans.modules.maven.j2ee.SessionContent; import org.netbeans.modules.maven.j2ee.ear.EarModuleProviderImpl; @@ -454,14 +453,17 @@ } else { getPreferences(project, true).putBoolean(MavenJavaEEConstants.HINT_DEPLOY_ON_SAVE, value); } - - CopyOnSave copyOnSave = project.getLookup().lookup(CopyOnSave.class); - if (copyOnSave != null) { - if (isDeployOnSave(project)) { - copyOnSave.initialize(); - } else { - copyOnSave.cleanup(); - } + } + + public static boolean isCopyStaticResourcesOnSave(Project project) { + return getPreferences(project, true).getBoolean(MavenJavaEEConstants.HINT_COPY_STATIC_RESOURCES_ON_SAVE, true); + } + + public static void setCopyStaticResourcesOnSave(Project project, Boolean value) { + if (value == null || value == true) { + getPreferences(project, true).remove(MavenJavaEEConstants.HINT_COPY_STATIC_RESOURCES_ON_SAVE); + } else { + getPreferences(project, true).putBoolean(MavenJavaEEConstants.HINT_COPY_STATIC_RESOURCES_ON_SAVE, value); } } diff --git a/maven.j2ee/src/org/netbeans/modules/maven/j2ee/web/WebCopyOnSave.java b/maven.j2ee/src/org/netbeans/modules/maven/j2ee/web/WebCopyOnSave.java --- a/maven.j2ee/src/org/netbeans/modules/maven/j2ee/web/WebCopyOnSave.java +++ b/maven.j2ee/src/org/netbeans/modules/maven/j2ee/web/WebCopyOnSave.java @@ -55,6 +55,8 @@ import org.netbeans.modules.javaee.project.api.ClientSideDevelopmentSupport; import org.netbeans.modules.maven.api.NbMavenProject; import org.netbeans.modules.maven.j2ee.CopyOnSave; +import org.netbeans.modules.maven.j2ee.MavenJavaEEConstants; +import org.netbeans.modules.maven.j2ee.utils.MavenProjectSupport; import org.netbeans.modules.web.api.webmodule.WebModule; import org.netbeans.modules.web.common.api.CssPreprocessors; import org.netbeans.spi.project.ProjectServiceProvider; @@ -257,13 +259,33 @@ checkPreprocessors(fe.getFile()); if (!isInPlace()) { - handleCopyFileToDestDir(fe.getFile()); + boolean deployOnSave = MavenProjectSupport.isDeployOnSave(project); + boolean copyStaticResourcesOnSave = MavenProjectSupport.isCopyStaticResourcesOnSave(project); + + // DoS is enabled and copy static resource too --> handle all files + if (deployOnSave && copyStaticResourcesOnSave) { + handleCopyFileToDestDir(fe.getFile()); + } + + if (!deployOnSave && copyStaticResourcesOnSave) { + // DoS is disabled --> handle only static resources + if (isStaticResource(fe.getFile().getExt())) { + handleCopyFileToDestDir(fe.getFile()); + } + } } } catch (IOException e) { ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); } } + private boolean isStaticResource(String fileExt) { + if ("html".equals(fileExt) || "jsp".equals(fileExt) || "xhtml".equals(fileExt)) { + return true; + } + return false; + } + @Override public void fileDataCreated(final FileEvent fe) { if (SwingUtilities.isEventDispatchThread()) {//#167740