You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Matthias Gradl (JIRA)" <ji...@apache.org> on 2015/07/06 18:14:04 UTC
[jira] [Commented] (SUREFIRE-1166) Include/Exclude regex pattern
for a path is incorrectly replaced on Windows
[ https://issues.apache.org/jira/browse/SUREFIRE-1166?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14615255#comment-14615255 ]
Matthias Gradl commented on SUREFIRE-1166:
------------------------------------------
I have a patch, that should demonstrate the issue:
{noformat}
diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/FailsafeIncludesRegexPath.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/FailsafeIncludesRegexPath.java
new file mode 100644
index 0000000..463a639
--- /dev/null
+++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/FailsafeIncludesRegexPath.java
@@ -0,0 +1,32 @@
+package org.apache.maven.surefire.its.jiras;
+
+import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
+import org.junit.Test;
+
+/*
+ * 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.
+ */
+
+
+public class FailsafeIncludesRegexPath extends SurefireJUnit4IntegrationTestCase {
+
+ @Test
+ public void testFailsafeIncludesRegexPath() throws Exception {
+ unpack("failsafe-includesRegexPath").executeVerify();
+ }
+}
diff --git a/surefire-integration-tests/src/test/resources/failsafe-includesRegexPath/pom.xml b/surefire-integration-tests/src/test/resources/failsafe-includesRegexPath/pom.xml
new file mode 100644
index 0000000..c84eea3
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/failsafe-includesRegexPath/pom.xml
@@ -0,0 +1,62 @@
+<?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>localhost</groupId>
+ <artifactId>failsafe-includesRegexPath</artifactId>
+ <version>1.0</version>
+ <name>failsafe-includesRegexPath</name>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>${surefire.version}</version>
+ <executions>
+ <execution>
+ <configuration>
+ <excludes>
+ <exclude>%regex[.*/exclude/.*]</exclude>
+ </excludes>
+ <includes>
+ <include>%regex[.*/include/.*]</include>
+ </includes>
+ </configuration>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/surefire-integration-tests/src/test/resources/failsafe-includesRegexPath/src/test/java/exclude/ExcludeMe.java b/surefire-integration-tests/src/test/resources/failsafe-includesRegexPath/src/test/java/exclude/ExcludeMe.java
new file mode 100644
index 0000000..f876f13
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/failsafe-includesRegexPath/src/test/java/exclude/ExcludeMe.java
@@ -0,0 +1,26 @@
+package exclude;
+/*
+ * 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.
+ */
+import junit.framework.TestCase;
+
+public class ExcludeMe extends TestCase {
+ public void testSomething() {
+ assertTrue(false);
+ }
+}
diff --git a/surefire-integration-tests/src/test/resources/failsafe-includesRegexPath/src/test/java/include/IncludeMe.java b/surefire-integration-tests/src/test/resources/failsafe-includesRegexPath/src/test/java/include/IncludeMe.java
new file mode 100644
index 0000000..415a3dc
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/failsafe-includesRegexPath/src/test/java/include/IncludeMe.java
@@ -0,0 +1,28 @@
+package include;
+
+/*
+ * 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.
+ */
+
+import junit.framework.TestCase;
+
+public class IncludeMe extends TestCase {
+ public void testSomething() {
+ assertTrue(true);
+ }
+}
{noformat}
I also fixed the issue in ScannerUtil to validate the test, but I'm not 100% sure it is the right place. Feel free to handle it your way...
{noformat}
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/ScannerUtil.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/ScannerUtil.java
index 8452a7a..6503c2d 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/ScannerUtil.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/ScannerUtil.java
@@ -42,6 +42,17 @@
@SuppressWarnings( "checkstyle:modifierorder" )
public static @Nonnull String convertSlashToSystemFileSeparator( @Nonnull String path )
{
- return ( IS_NON_UNIX_FS ? path.replace( "/", FS ) : path );
- }
+ String result = path;
+ if ( IS_NON_UNIX_FS )
+ {
+ if ( path.startsWith( "%regex" ) && "\\".equals( FS ) )
+ {
+ result = path.replace( "/", "\\" + FS );
+ }
+ else
+ {
+ result = path.replace( "/", FS );
+ }
+ }
+ return result; }
}
{noformat}
> Include/Exclude regex pattern for a path is incorrectly replaced on Windows
> ---------------------------------------------------------------------------
>
> Key: SUREFIRE-1166
> URL: https://issues.apache.org/jira/browse/SUREFIRE-1166
> Project: Maven Surefire
> Issue Type: Bug
> Components: Maven Failsafe Plugin
> Affects Versions: 2.18.1
> Environment: Windows
> Reporter: Matthias Gradl
>
> On non-unix systems, the file scanner converts slashes ("/") into the file-system appropriate separator (eg. "\" on Windows) thus colliding with the standard escape character in regex Strings.
> For regex pattern matching a path (segment) to a test package (like: "%regex[.*/smoketest/.*Test\.java]" this leads to unusable patterns: "%regex[.*\smoketest\.*Test\.java]"
> There needs to be a more sophisticated replacement happening when the include string is actually a regex pattern.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)