Author: rmannibucau
Date: Sun Jan 20 17:21:38 2019
New Revision: 1851710
URL: http://svn.apache.org/viewvc?rev=1851710&view=rev
Log:
MEECROWAVE-175 ensure src/main/webapp - or the configured folder - is bundled
in meecrowave:bundle
Added:
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveBundleMojoTest.java
- copied, changed from r1851708,
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveRunMojoTest.java
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveBundleMojoTest/
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveBundleMojoTest/pom.xml
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveBundleMojoTest/src/
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveBundleMojoTest/src/main/
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveBundleMojoTest/src/main/webapp/
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveBundleMojoTest/src/main/webapp/sub/
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveBundleMojoTest/src/main/webapp/sub/index.html
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveRunMojoTest/src/
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveRunMojoTest/src/main/
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveRunMojoTest/src/main/webapp/
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveRunMojoTest/src/main/webapp/sub/
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveRunMojoTest/src/main/webapp/sub/index.html
Modified:
openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/Cli.java
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveBundleMojo.java
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveRunMojoTest.java
Modified:
openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/Cli.java
URL:
http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/Cli.java?rev=1851710&r1=1851709&r2=1851710&view=diff
==============================================================================
---
openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/Cli.java
(original)
+++
openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/runner/Cli.java
Sun Jan 20 17:21:38 2019
@@ -36,6 +36,7 @@ import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
import java.util.ServiceLoader;
@@ -79,7 +80,17 @@ public class Cli implements Runnable, Au
final String war = line.getOptionValue("webapp");
meecrowave.start();
if (war == null) {
- meecrowave.deployClasspath(new Meecrowave.DeploymentMeta(ctx,
ofNullable(line.getOptionValue("docbase")).map(File::new).orElse(null), null));
+ meecrowave.deployClasspath(new Meecrowave.DeploymentMeta(
+ ctx,
+
ofNullable(line.getOptionValue("docbase")).map(File::new).orElseGet(() ->
+ Stream.of("base", "home")
+ .map(it ->
System.getProperty("meecrowave." + it))
+ .filter(Objects::nonNull)
+ .map(it -> new File(it, "docBase"))
+ .filter(File::isDirectory)
+ .findFirst()
+ .orElse(null)),
+ null));
} else {
meecrowave.deployWebapp(fixedCtx, new File(war));
}
Modified:
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveBundleMojo.java
URL:
http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveBundleMojo.java?rev=1851710&r1=1851709&r2=1851710&view=diff
==============================================================================
---
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveBundleMojo.java
(original)
+++
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/main/java/org/apache/meecrowave/maven/MeecrowaveBundleMojo.java
Sun Jan 20 17:21:38 2019
@@ -142,6 +142,9 @@ public class MeecrowaveBundleMojo extend
@Parameter(property = "meecrowave.enforce-meecrowave", defaultValue =
"true")
private boolean enforceMeecrowave; // set to false if you package
meecrowave runner
+ @Parameter(property = "meecrowave.webapp", defaultValue =
"${project.basedir}/src/main/webapp")
+ private File webapp;
+
@Component
private MavenProjectHelper projectHelper;
@@ -202,6 +205,23 @@ public class MeecrowaveBundleMojo extend
if (app.exists()) {
addLib(distroFolder, app);
}
+ if (webapp != null && webapp.isDirectory()) {
+ try {
+ final Path rootSrc = webapp.toPath().toAbsolutePath();
+ final Path rootTarget =
distroFolder.toPath().toAbsolutePath().resolve("docBase");
+ Files.walkFileTree(rootSrc, new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile(final Path file, final
BasicFileAttributes attrs) throws IOException {
+ final Path target =
rootTarget.resolve(rootSrc.relativize(file));
+ target.toFile().getParentFile().mkdirs();
+ Files.copy(file, target,
StandardCopyOption.REPLACE_EXISTING);
+ return super.visitFile(file, attrs);
+ }
+ });
+ } catch (final IOException e) {
+ throw new MojoExecutionException(e.getMessage(), e);
+ }
+ }
if (enforceCommonsCli && !includedArtifacts.contains("commons-cli")) {
addLib(distroFolder, resolve("commons-cli", "commons-cli", "1.4",
""));
}
@@ -307,7 +327,7 @@ public class MeecrowaveBundleMojo extend
/**
- * Copy over all files from src/meecrowave/*
+ * Copy over all files from src/main/meecrowave/*
* TODO!
* The following files get added with default content if not found there:
* <ul>
@@ -316,27 +336,27 @@ public class MeecrowaveBundleMojo extend
* </ul>
* @param distroFolder
*/
- private void copyProvidedFiles(File distroFolder) throws
MojoExecutionException
+ private void copyProvidedFiles(final File distroFolder) throws
MojoExecutionException
{
boolean customLog4jConfig = false;
boolean customMwProperties = false;
- Log log = getLog();
+ final Log log = getLog();
- File srcConf = new File(project.getBasedir(), conf);
- if (srcConf.exists() && srcConf.isDirectory()) {
- File targetConf = new File(distroFolder, "conf");
+ File srcConf = new File(conf);
+ if (!srcConf.isAbsolute()) {
+ srcConf = new File(project.getBasedir(), conf);
+ }
+ if (srcConf.isDirectory()) {
+ final File targetConf = new File(distroFolder, "conf");
targetConf.mkdirs();
- for (File file : srcConf.listFiles()) {
- String fileName = file.getName();
+ for (final File file : srcConf.listFiles()) {
+ final String fileName = file.getName();
if ("log4j2.xml".equals(fileName)) {
customLog4jConfig = true;
- }
- if ("meecrowave.properties".equals(fileName)) {
+ } else if ("meecrowave.properties".equals(fileName)) {
customMwProperties = true;
- }
-
- if (fileName.startsWith(".")) {
+ } else if (fileName.startsWith(".")) {
// hidden file -> ignore
continue;
}
@@ -346,8 +366,7 @@ public class MeecrowaveBundleMojo extend
log.debug("Copying file from " + file + " to " +
targetConf);
}
Files.copy(file.toPath(), new File(targetConf,
fileName).toPath());
- }
- catch (IOException e) {
+ } catch (final IOException e) {
throw new MojoExecutionException("Could not copy file " +
file.getAbsolutePath(), e);
}
}
Copied:
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveBundleMojoTest.java
(from r1851708,
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveRunMojoTest.java)
URL:
http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveBundleMojoTest.java?p2=openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveBundleMojoTest.java&p1=openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveRunMojoTest.java&r1=1851708&r2=1851710&rev=1851710&view=diff
==============================================================================
---
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveRunMojoTest.java
(original)
+++
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveBundleMojoTest.java
Sun Jan 20 17:21:38 2019
@@ -18,10 +18,25 @@
*/
package org.apache.meecrowave.maven;
+import static org.apache.ziplock.JarLocation.jarLocation;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.ServerSocket;
+import java.net.URL;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.zip.ZipFile;
+
import org.apache.commons.io.IOUtils;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Build;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.testing.MojoRule;
import org.apache.maven.project.MavenProject;
@@ -34,26 +49,13 @@ import org.eclipse.aether.repository.Loc
import org.junit.Rule;
import org.junit.Test;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.ServerSocket;
-import java.net.URL;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import static org.apache.ziplock.JarLocation.jarLocation;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-public class MeecrowaveRunMojoTest {
+public class MeecrowaveBundleMojoTest {
@Rule
public final MojoRule mojo = new MojoRule();
@Test
- public void run() throws Exception {
- final File moduleBase =
jarLocation(MeecrowaveRunMojoTest.class).getParentFile().getParentFile();
+ public void bundle() throws Exception {
+ final File moduleBase =
jarLocation(MeecrowaveBundleMojoTest.class).getParentFile().getParentFile();
final File basedir = new File(moduleBase, "src/test/resources/" +
getClass().getSimpleName());
final File pom = new File(basedir, "pom.xml");
final MavenExecutionRequest request = new
DefaultMavenExecutionRequest();
@@ -64,63 +66,28 @@ public class MeecrowaveRunMojoTest {
.newInstance(repositorySession, new LocalRepository(new
File(moduleBase, "target/fake"), "")));
configuration.setRepositorySession(repositorySession);
final MavenProject project =
mojo.lookup(ProjectBuilder.class).build(pom, configuration).getProject();
+ final Build build = new Build();
+ final File buildDir = new File("target/" + getClass().getName() +
"/build");
+ build.setDirectory(buildDir.getAbsolutePath());
+ project.setBuild(build);
final MavenSession session = mojo.newMavenSession(project);
- final int port;
- try (final ServerSocket serverSocket = new ServerSocket(0)) {
- port = serverSocket.getLocalPort();
- }
- final MojoExecution execution = mojo.newMojoExecution("run");
- execution.getConfiguration().addChild(new Xpp3Dom("httpPort") {{
- setValue(Integer.toString(port));
+ final MojoExecution execution = mojo.newMojoExecution("bundle");
+ execution.getConfiguration().addChild(new Xpp3Dom("enforceMeecrowave")
{{
+ setValue(Boolean.FALSE.toString());
}});
- final InputStream in = System.in;
- final CountDownLatch latch = new CountDownLatch(1);
- System.setIn(new InputStream() {
- private int val = 2; // just to not return nothing
-
- @Override
- public int read() throws IOException {
- try {
- latch.await();
- } catch (final InterruptedException e) {
- Thread.interrupted();
- fail(e.getMessage());
- }
- return val--;
- }
- });
- final Thread runner = new Thread() {
- @Override
- public void run() {
- try {
- mojo.executeMojo(session, project, execution);
- } catch (final Exception e) {
- fail(e.getMessage());
- }
- }
- };
- try {
- runner.start();
- for (int i = 0; i < 120; i++) {
- try {
- assertEquals("simple", IOUtils.toString(new
URL("http://localhost:" + port + "/api/test")));
- assertTrue(IOUtils.toString(new URL("http://localhost:" +
port + "/api/test/model")).contains("first_name"));
- assertTrue(IOUtils.toString(new URL("http://localhost:" +
port + "/api/test/model")).contains("last_name"));
- assertTrue(IOUtils.toString(new URL("http://localhost:" +
port + "/api/test/model")).contains("firstname"));
- assertTrue(IOUtils.toString(new URL("http://localhost:" +
port + "/api/test/model")).contains("null"));
- latch.countDown();
- break;
- } catch (final Exception | AssertionError e) {
- Thread.sleep(500);
- }
- }
- } finally {
- runner.join(TimeUnit.MINUTES.toMillis(1));
- System.setIn(in);
- if (runner.isAlive()) {
- runner.interrupt();
- fail("Runner didn't terminate properly");
- }
+ execution.getConfiguration().addChild(new Xpp3Dom("enforceCommonsCli")
{{
+ setValue(Boolean.FALSE.toString());
+ }});
+ execution.getConfiguration().addChild(new Xpp3Dom("conf") {{
+ setValue("src/main/meecrowave/conf");
+ }});
+ execution.getConfiguration().addChild(new Xpp3Dom("webapp") {{
+ setValue("src/main/webapp");
+ }});
+ mojo.executeMojo(session, project, execution);
+ assertTrue(buildDir.exists());
+ try (final ZipFile zip = new ZipFile(new File(buildDir,
"test-meecrowave-distribution.zip"))) {
+
assertTrue(zip.getEntry("test-distribution/docBase/sub/index.html") != null);
}
}
}
Modified:
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveRunMojoTest.java
URL:
http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveRunMojoTest.java?rev=1851710&r1=1851709&r2=1851710&view=diff
==============================================================================
---
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveRunMojoTest.java
(original)
+++
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/java/org/apache/meecrowave/maven/MeecrowaveRunMojoTest.java
Sun Jan 20 17:21:38 2019
@@ -83,7 +83,7 @@ public class MeecrowaveRunMojoTest {
try {
latch.await();
} catch (final InterruptedException e) {
- Thread.interrupted();
+ Thread.currentThread().interrupt();
fail(e.getMessage());
}
return val--;
@@ -108,6 +108,7 @@ public class MeecrowaveRunMojoTest {
assertTrue(IOUtils.toString(new URL("http://localhost:" +
port + "/api/test/model")).contains("last_name"));
assertTrue(IOUtils.toString(new URL("http://localhost:" +
port + "/api/test/model")).contains("firstname"));
assertTrue(IOUtils.toString(new URL("http://localhost:" +
port + "/api/test/model")).contains("null"));
+ assertTrue(IOUtils.toString(new URL("http://localhost:" +
port + "/sub/index.html")).contains("<h1>yes</h1>"));
latch.countDown();
break;
} catch (final Exception | AssertionError e) {
Added:
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveBundleMojoTest/pom.xml
URL:
http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveBundleMojoTest/pom.xml?rev=1851710&view=auto
==============================================================================
---
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveBundleMojoTest/pom.xml
(added)
+++
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveBundleMojoTest/pom.xml
Sun Jan 20 17:21:38 2019
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://maven.apache.org/POM/4.0.0
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.meecrowave.test</groupId>
+ <artifactId>test</artifactId>
+ <version>0.1-SNAPSHOT</version>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.meecrowave</groupId>
+ <artifactId>meecrowave-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Added:
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveBundleMojoTest/src/main/webapp/sub/index.html
URL:
http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveBundleMojoTest/src/main/webapp/sub/index.html?rev=1851710&view=auto
==============================================================================
---
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveBundleMojoTest/src/main/webapp/sub/index.html
(added)
+++
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveBundleMojoTest/src/main/webapp/sub/index.html
Sun Jan 20 17:21:38 2019
@@ -0,0 +1,23 @@
+<!--
+ 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.
+-->
+<html>
+ <body>
+ <h1>Bundled</h1>
+ </body>
+</html>
Added:
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveRunMojoTest/src/main/webapp/sub/index.html
URL:
http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveRunMojoTest/src/main/webapp/sub/index.html?rev=1851710&view=auto
==============================================================================
---
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveRunMojoTest/src/main/webapp/sub/index.html
(added)
+++
openwebbeans/meecrowave/trunk/meecrowave-maven-plugin/src/test/resources/MeecrowaveRunMojoTest/src/main/webapp/sub/index.html
Sun Jan 20 17:21:38 2019
@@ -0,0 +1,23 @@
+<!--
+ 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.
+-->
+<html>
+ <body>
+ <h1>yes</h1>
+ </body>
+</html>