Author: rmannibucau
Date: Wed Mar 6 09:55:25 2013
New Revision: 1453246
URL: http://svn.apache.org/r1453246
Log:
TOMEE-715 better config for advanced synchro on tomee mvn plugin
Added:
tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractSynchronizable.java
tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/Synch.java
Modified:
tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/Synchronization.java
tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/UpdatableTomEEMojo.java
Added:
tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractSynchronizable.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractSynchronizable.java?rev=1453246&view=auto
==============================================================================
---
tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractSynchronizable.java
(added)
+++
tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractSynchronizable.java
Wed Mar 6 09:55:25 2013
@@ -0,0 +1,54 @@
+package org.apache.openejb.maven.plugin;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public abstract class AbstractSynchronizable {
+ protected int updateInterval;
+ protected List<String> extensions;
+ protected List<String> updateOnlyExtensions;
+ protected String regex;
+ protected Map<File, File> updates;
+
+ public abstract Map<File, File> updates();
+
+ public int getUpdateInterval() {
+ return updateInterval;
+ }
+
+ public void setUpdateInterval(int updateInterval) {
+ this.updateInterval = updateInterval;
+ }
+
+ public List<String> getExtensions() {
+ if (extensions == null) {
+ extensions = new ArrayList<String>();
+ }
+ return extensions;
+ }
+
+ public void setExtensions(List<String> extensions) {
+ this.extensions = extensions;
+ }
+
+ public String getRegex() {
+ return regex;
+ }
+
+ public void setRegex(String regex) {
+ this.regex = regex;
+ }
+
+ public List<String> getUpdateOnlyExtenions() {
+ if (updateOnlyExtensions == null) {
+ updateOnlyExtensions = new ArrayList<String>();
+ }
+ return updateOnlyExtensions;
+ }
+
+ public void setUpdateOnlyExtensions(List<String> updateOnlyExtensions) {
+ this.updateOnlyExtensions = updateOnlyExtensions;
+ }
+}
Added:
tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/Synch.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/Synch.java?rev=1453246&view=auto
==============================================================================
---
tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/Synch.java
(added)
+++
tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/Synch.java
Wed Mar 6 09:55:25 2013
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.maven.plugin;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+public class Synch extends AbstractSynchronizable {
+ private File source;
+ private File target;
+
+ public File getSource() {
+ return source;
+ }
+
+ public void setSource(File source) {
+ this.source = source;
+ }
+
+ public File getTarget() {
+ return target;
+ }
+
+ public void setTarget(File target) {
+ this.target = target;
+ }
+
+ @Override
+ public Map<File, File> updates() {
+ if (updates == null) {
+ updates = new HashMap<File, File>();
+ if (source != null && target != null) {
+ updates.put(source, target);
+ }
+ }
+ return updates;
+ }
+}
Modified:
tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/Synchronization.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/Synchronization.java?rev=1453246&r1=1453245&r2=1453246&view=diff
==============================================================================
---
tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/Synchronization.java
(original)
+++
tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/Synchronization.java
Wed Mar 6 09:55:25 2013
@@ -18,17 +18,15 @@ package org.apache.openejb.maven.plugin;
import java.io.File;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
-public class Synchronization {
+public class Synchronization extends AbstractSynchronizable {
private File resourcesDir;
private File binariesDir;
private File targetBinariesDir;
private File targetResourcesDir;
- private int updateInterval;
- private List<String> extensions;
- private List<String> updateOnlyExtensions;
- private String regex;
public File getResourcesDir() {
return resourcesDir;
@@ -62,41 +60,17 @@ public class Synchronization {
this.targetResourcesDir = targetResourcesDir;
}
- public int getUpdateInterval() {
- return updateInterval;
- }
-
- public void setUpdateInterval(int updateInterval) {
- this.updateInterval = updateInterval;
- }
-
- public List<String> getExtensions() {
- if (extensions == null) {
- extensions = new ArrayList<String>();
+ @Override
+ public Map<File, File> updates() {
+ if (updates == null) {
+ updates = new HashMap<File, File>();
+ if (resourcesDir != null && targetResourcesDir != null) {
+ updates.put(resourcesDir, targetResourcesDir);
+ }
+ if (binariesDir != null && targetBinariesDir != null) {
+ updates.put(binariesDir, targetBinariesDir);
+ }
}
- return extensions;
- }
-
- public void setExtensions(List<String> extensions) {
- this.extensions = extensions;
- }
-
- public String getRegex() {
- return regex;
- }
-
- public void setRegex(String regex) {
- this.regex = regex;
- }
-
- public List<String> getUpdateOnlyExtenions() {
- if (updateOnlyExtensions == null) {
- updateOnlyExtensions = new ArrayList<String>();
- }
- return updateOnlyExtensions;
- }
-
- public void setUpdateOnlyExtensions(List<String> updateOnlyExtensions) {
- this.updateOnlyExtensions = updateOnlyExtensions;
+ return updates;
}
}
Modified:
tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/UpdatableTomEEMojo.java
URL:
http://svn.apache.org/viewvc/tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/UpdatableTomEEMojo.java?rev=1453246&r1=1453245&r2=1453246&view=diff
==============================================================================
---
tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/UpdatableTomEEMojo.java
(original)
+++
tomee/tomee/trunk/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/UpdatableTomEEMojo.java
Wed Mar 6 09:55:25 2013
@@ -35,6 +35,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
import java.util.Timer;
import java.util.TimerTask;
@@ -50,7 +51,7 @@ public abstract class UpdatableTomEEMojo
private Synchronization synchronization;
@Parameter
- private List<Synchronization> synchronizations;
+ private List<Synch> synchronizations;
@Parameter(property = "tomee-plugin.buildDir", defaultValue =
"${project.build.directory}", readonly = true)
private File buildDir;
@@ -70,8 +71,12 @@ public abstract class UpdatableTomEEMojo
initSynchronization(synchronization);
}
if (synchronizations != null) {
- for (Synchronization s :synchronizations) {
- initSynchronization(s);
+ for (final Synch s : synchronizations) {
+ if (s.getSource() == null || s.getTarget() == null) {
+ getLog().warn("Source or Target directory missing to a
<synch> block, skipping");
+ continue;
+ }
+ initSynch(s);
}
}
@@ -79,10 +84,22 @@ public abstract class UpdatableTomEEMojo
forceReloadable = true;
}
+ if (removeTomeeWebapp) {
+ getLog().warn("TomEE webapp is asked to be removed
(<removeTomeeWebapp>true</removeTomeeWebapp>) so you can use reload feature");
+ }
+
super.run();
}
+ private void initSynch(final AbstractSynchronizable s) {
+ s.getExtensions().addAll(s.getUpdateOnlyExtenions());
+ if (reloadOnUpdate) {
+ deployOpenEjbApplication = true;
+ }
+ }
+
private void initSynchronization(final Synchronization synchronization) {
+ // defaults values for main synchronization block
final String destination = destinationName().replaceAll("\\.[jew]ar",
"");
if (synchronization.getBinariesDir() == null) {
synchronization.setBinariesDir(new File(buildDir, "classes"));
@@ -106,12 +123,7 @@ public abstract class UpdatableTomEEMojo
synchronization.setUpdateOnlyExtensions(Collections.<String>emptyList());
}
- // merge update only and normal extensions to browse more easily
extensions in the timer task
-
synchronization.getExtensions().addAll(synchronization.getUpdateOnlyExtenions());
-
- if (reloadOnUpdate) {
- deployOpenEjbApplication = true;
- }
+ initSynch(synchronization);
}
@Override
@@ -140,7 +152,7 @@ public abstract class UpdatableTomEEMojo
interval =
TimeUnit.SECONDS.toMillis(synchronization.getUpdateInterval());
}
if (synchronizations != null) {
- for (Synchronization s : synchronizations) {
+ for (final AbstractSynchronizable s : synchronizations) {
synchronizers.add(new Synchronizer(s));
if (interval < s.getUpdateInterval()) {
interval =
TimeUnit.SECONDS.toMillis(s.getUpdateInterval());
@@ -224,10 +236,10 @@ public abstract class UpdatableTomEEMojo
private class Synchronizer implements Callable<Integer> {
private final FileFilter fileFilter;
private final FileFilter updateOnlyFilter;
- private final Synchronization synchronization;
+ private final AbstractSynchronizable synchronization;
private long lastUpdate = System.currentTimeMillis();
- public Synchronizer(final Synchronization synch) {
+ public Synchronizer(final AbstractSynchronizable synch) {
synchronization = synch;
updateOnlyFilter = new
SuffixesFileFilter(synchronization.getUpdateOnlyExtenions());
if (synchronization.getRegex() != null) {
@@ -240,8 +252,10 @@ public abstract class UpdatableTomEEMojo
@Override
public Integer call() throws Exception {
final long ts = System.currentTimeMillis();
- int updated = updateFiles(synchronization.getResourcesDir(),
synchronization.getTargetResourcesDir(), ts)
- + updateFiles(synchronization.getBinariesDir(),
synchronization.getTargetBinariesDir(), ts);
+ int updated = 0;
+ for (final Map.Entry<File, File> pair :
synchronization.updates().entrySet()) {
+ updated += updateFiles(pair.getKey(), pair.getValue(), ts);
+ }
lastUpdate = ts;
return updated;
}
@@ -301,7 +315,9 @@ public abstract class UpdatableTomEEMojo
FileUtils.forceMkdir(output.getParentFile());
}
FileUtils.copyFile(file, output);
- output.setLastModified(ts);
+ if (!output.setLastModified(ts)) {
+ getLog().debug("Can't update last modified date of " +
file);
+ }
} catch (IOException e) {
getLog().error(e);
}