You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sl...@apache.org on 2020/09/19 09:57:56 UTC
[maven-file-management] 01/01: [MSHARED-958] added missing regexp
mapper
This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch MSHARED-958
in repository https://gitbox.apache.org/repos/asf/maven-file-management.git
commit 476138eaedd883cd740c61e645b9d3563389911f
Author: Brian Long <br...@alfresco.com>
AuthorDate: Thu Mar 26 10:31:14 2020 -0400
[MSHARED-958] added missing regexp mapper
Closes #2
---
.../model/fileset/mappers/RegexpPatternMapper.java | 62 ++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/src/main/java/org/apache/maven/shared/model/fileset/mappers/RegexpPatternMapper.java b/src/main/java/org/apache/maven/shared/model/fileset/mappers/RegexpPatternMapper.java
new file mode 100644
index 0000000..92b3bf5
--- /dev/null
+++ b/src/main/java/org/apache/maven/shared/model/fileset/mappers/RegexpPatternMapper.java
@@ -0,0 +1,62 @@
+package org.apache.maven.shared.model.fileset.mappers;
+
+/*
+ * 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 java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Implementation of RegexpPatternMapper that returns either the source file
+ * name or it processed by a matching Regular Expression and its replacement.
+ *
+ * <p>This is a RegexpPatternMapper for the copy and move tasks.</p>
+ *
+ * @version $Id$
+ */
+public class RegexpPatternMapper
+ implements FileNameMapper
+{
+ private Pattern fromPattern;
+ private String toReplaceExpression;
+
+ /** {@inheritDoc} */
+ public void setFrom( String from )
+ {
+ this.fromPattern = Pattern.compile( from );
+ }
+
+ /** {@inheritDoc} */
+ public void setTo( String to )
+ {
+ this.toReplaceExpression = to;
+ }
+
+ /** {@inheritDoc} */
+ public String mapFileName( String sourceFileName )
+ {
+ Matcher matcher = this.fromPattern.matcher( sourceFileName );
+ if ( !matcher.find( ) )
+ {
+ return sourceFileName;
+ }
+
+ return matcher.replaceFirst( this.toReplaceExpression );
+ }
+}