Skip to content

Commit

Permalink
Fix #21 : add <m2e.wro4j.wtp.integration> Maven property to disable m…
Browse files Browse the repository at this point in the history
…2e-wtp integration

Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Jun 25, 2014
1 parent 45b408a commit 70d8275
Show file tree
Hide file tree
Showing 19 changed files with 121 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.Scanner;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomUtils;
Expand All @@ -30,6 +32,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.IMaven;
Expand All @@ -47,6 +50,8 @@
*/
public class Wro4jBuildParticipant extends MojoExecutionBuildParticipant {

private static final String M2E_WRO4J_WTP_INTEGRATION_KEY = "m2e.wro4j.wtp.integration";

private static final String CONTEXT_FOLDER = "contextFolder";

private static final String TOKEN_SEPARATOR = ",\\s*";
Expand Down Expand Up @@ -225,7 +230,7 @@ private void refreshResource(MojoExecution mojoExecution,

private Xpp3Dom customize(Xpp3Dom originalConfiguration, Collection<File> contextFolders,
File originalDestinationFolder, File originalJsDestinationFolder,
File originalCssDestinationFolder, File originalGroupNameMappingFile) throws IOException {
File originalCssDestinationFolder, File originalGroupNameMappingFile) throws IOException, CoreException {
IMavenProjectFacade facade = getMavenProjectFacade();
if (!"war".equals(facade.getPackaging())) {
// Not a war project, we don't know how to customize that
Expand All @@ -244,7 +249,7 @@ private Xpp3Dom customize(Xpp3Dom originalConfiguration, Collection<File> contex

IFolder m2eWtpFolder = project.getFolder(relativeTargetPath.append("m2e-wtp"));

if (!m2eWtpFolder.exists()) {
if (!m2eWtpFolder.exists() || isWtpIntegrationDisabled(facade.getMavenProject(new NullProgressMonitor()))) {
// Not a m2e-wtp project, we don't know how to customize either
// TODO Try to support Sonatype's webby instead?
return customConfiguration;
Expand All @@ -271,6 +276,12 @@ private Xpp3Dom customize(Xpp3Dom originalConfiguration, Collection<File> contex
return customConfiguration;
}

private boolean isWtpIntegrationDisabled(MavenProject mavenProject) {
Properties properties = mavenProject.getProperties();
String isWtpIntegrationProperty = properties.getProperty(M2E_WRO4J_WTP_INTEGRATION_KEY, Boolean.TRUE.toString());
return !Boolean.parseBoolean(isWtpIntegrationProperty);
}

private void customizeLocation(File originalDestinationFolder,
IFolder webResourcesFolder, IPath defaultOutputPathPrefix,
Xpp3Dom configuration, String parameterName) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
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>foo.bar</groupId>
<artifactId>p4-171</artifactId>
<artifactId>p4-176</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
Expand All @@ -13,7 +13,7 @@
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>1.7.3</version>
<version>1.7.6</version>
<executions>
<execution>
<phase>compile</phase>
Expand Down
41 changes: 41 additions & 0 deletions org.jboss.tools.m2e.wro4j.tests/projects/p7/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<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>foo.bar</groupId>
<artifactId>disable-wtp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<m2e.wro4j.wtp.integration>false</m2e.wro4j.wtp.integration>
</properties>
<build>
<plugins>
<plugin>
<groupId>ro.isdc.wro4j</groupId>
<artifactId>wro4j-maven-plugin</artifactId>
<version>1.7.6</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<configuration>
<destinationFolder>${project.build.directory}/${project.build.finalName}/resources</destinationFolder>
<targetGroups>testCase</targetGroups>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<target>1.6</target>
<source>1.6</source>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>p1</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
preProcessors=cssImport,semicolonAppender,lessCss
postProcessors=cssMinJawr,jsMin
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<groups xmlns="http://www.isdc.ro/wro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.isdc.ro/wro wro.xsd">
<group name="testCase">
<css>/*.css</css>
<js>/*.js</js>
</group>
</groups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function hi(name) {
alert("Hi "+ name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function hello(name) {
alert("Hello "+ name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background-color:#656565;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.yeaahbaby {
display:hidden;
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public void testContextFolder171() throws Exception {
basicTest(p);
}

public void testContextFolder173() throws Exception {
IProject p = importProject("projects/p4-173/pom.xml");
public void testContextFolder176() throws Exception {
IProject p = importProject("projects/p4-176/pom.xml");
waitForJobsToComplete();
basicTest(p);
}
Expand All @@ -102,6 +102,31 @@ public void testMultipleRelativeContextFolders() throws Exception {
basicTest(projects[1]);
}

public void testDisableM2eWtpIntegration() throws Exception {
IProject p = importProject("projects/p7/pom.xml");
waitForJobsToComplete();

p.build(IncrementalProjectBuilder.AUTO_BUILD, monitor);
waitForJobsToComplete();

IFile js = p
.getFile("target/m2e-wtp/web-resources/resources/testCase.js");
assertFalse(js + " should be missing", js.exists());

js = p
.getFile("target/disable-wtp-0.0.1-SNAPSHOT/resources/testCase.js");
assertTrue(js + " is missing", js.exists());


IFile css = p
.getFile("target/m2e-wtp/web-resources/resources/testCase.css");
assertFalse("target/m2e-wtp/web-resources/resources/testCase.css should be missing", css.exists());

css = p
.getFile("target/disable-wtp-0.0.1-SNAPSHOT/resources/testCase.css");
assertTrue(css + " is missing", css.exists());
}

private void assertMinifiedFiles(IProject p) throws Exception {
IFile js = p.getFile("target/m2e-wtp/web-resources/resources/testCase.js");
assertTrue("testCase.js is missing after a clean build", js.exists());
Expand Down
13 changes: 10 additions & 3 deletions org.jboss.tools.m2e.wro4j.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<pattern> &lt;plugin&gt;
&lt;groupId&gt;ro.isdc.wro4j&lt;/groupId&gt;
&lt;artifactId&gt;wro4j-maven-plugin&lt;/artifactId&gt;
&lt;version&gt;1.7.3&lt;/version&gt;
&lt;version&gt;1.7.6&lt;/version&gt;
&lt;executions&gt;
&lt;execution&gt;
&lt;phase&gt;compile&lt;/phase&gt;
Expand All @@ -19,10 +19,17 @@
&lt;/execution&gt;
&lt;/executions&gt;
&lt;configuration&gt;
&lt;jsDestinationFolder&gt;$${project.build.directory}/$${project.build.finalName}/${cursor}resources/js&lt;/jsDestinationFolder&gt;
&lt;cssDestinationFolder&gt;$${project.build.directory}/$${project.build.finalName}/resources/styles&lt;/cssDestinationFolder&gt;
&lt;jsDestinationFolder&gt;$${project.build.directory}/$${project.build.finalName}/${cursor}${resources}/js&lt;/jsDestinationFolder&gt;
&lt;cssDestinationFolder&gt;$${project.build.directory}/$${project.build.finalName}/${resources}/styles&lt;/cssDestinationFolder&gt;
&lt;/configuration&gt;
&lt;/plugin&gt;</pattern>
</template>
<template id="org.jboss.tools.m2e.wro4j.templates.wtpIntegrationProperty"
contextTypeId="org.eclipse.m2e.editor.xml.templates.contextType.properties"
name="m2e-wro4j integration with m2e-wtp"
description="Enable or disable m2e-wro4j integration with m2e-wtp">
<pattern>&lt;m2e.wro4j.wtp.integration&gt;${cursor}${false}&lt;/m2e.wro4j.wtp.integration&gt;</pattern>
</template>

</extension>
</plugin>

0 comments on commit 70d8275

Please sign in to comment.