+ * TODO find out where this is probably done elsewhere * * @param pluginPomDom * @param element diff --git a/src/test/java/org/mybatis/maven/testing/ConfigurationException.java b/src/test/java/org/mybatis/maven/testing/ConfigurationException.java new file mode 100644 index 00000000..d19eaf8a --- /dev/null +++ b/src/test/java/org/mybatis/maven/testing/ConfigurationException.java @@ -0,0 +1,76 @@ +/* + * Copyright 2010-2024 the original author or authors. + * + * Licensed 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 + * + * https://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. + */ +/* + * 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.mybatis.maven.testing; + +/** + * Mybatis: Borrowed from 'https://github.com/apache/maven-plugin-testing/blob/master/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ConfiguationException.java' + * Reason: Removed from release 4.0.0-beta-1 and we need to have junit 5 support. Maven dropped maven 3 support here! + * Git: From release 4.0.0-alpha-2 + */ + +/** + * ConfigurationException + * + * @author jesse + */ +public class ConfigurationException extends Exception { + /** serialVersionUID */ + static final long serialVersionUID = -6180939638742159065L; + + /** + * @param message + * The detailed message. + */ + public ConfigurationException(String message) { + super(message); + } + + /** + * @param cause + * The detailed cause. + */ + public ConfigurationException(Throwable cause) { + super(cause); + } + + /** + * @param message + * The detailed message. + * @param cause + * The detailed cause. + */ + public ConfigurationException(String message, Throwable cause) { + super(message, cause); + } +} \ No newline at end of file diff --git a/src/test/java/org/mybatis/maven/testing/ResolverExpressionEvaluatorStub.java b/src/test/java/org/mybatis/maven/testing/ResolverExpressionEvaluatorStub.java new file mode 100644 index 00000000..6d3a3303 --- /dev/null +++ b/src/test/java/org/mybatis/maven/testing/ResolverExpressionEvaluatorStub.java @@ -0,0 +1,131 @@ +/* + * Copyright 2010-2024 the original author or authors. + * + * Licensed 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 + * + * https://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. + */ +/* + * 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.mybatis.maven.testing; + +import java.io.File; + +import org.apache.maven.artifact.repository.MavenArtifactRepository; +import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; +import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; + +/** + * Mybatis: Borrowed from 'https://github.com/apache/maven-plugin-testing/blob/master/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ConfiguationException.java' + * Reason: Removed from release 4.0.0-beta-1 and we need to have junit 5 support. Maven dropped maven 3 support here! + * Git: From release 4.0.0-alpha-2 + */ + +/** + * Stub for {@link ExpressionEvaluator} + * + * @author jesse + */ +public class ResolverExpressionEvaluatorStub implements ExpressionEvaluator { + /** {@inheritDoc} */ + @Override + public Object evaluate(String expr) throws ExpressionEvaluationException { + + Object value = null; + + if (expr == null) { + return null; + } + + String expression = stripTokens(expr); + + if (expression.equals(expr)) { + int index = expr.indexOf("${"); + if (index >= 0) { + int lastIndex = expr.indexOf("}", index); + if (lastIndex >= 0) { + String retVal = expr.substring(0, index); + + if (index > 0 && expr.charAt(index - 1) == '$') { + retVal += expr.substring(index + 1, lastIndex + 1); + } else { + retVal += evaluate(expr.substring(index, lastIndex + 1)); + } + + retVal += evaluate(expr.substring(lastIndex + 1)); + return retVal; + } + } + + // Was not an expression + if (expression.indexOf("$$") > -1) { + return expression.replaceAll("\\$\\$", "\\$"); + } + } + + if ("basedir".equals(expression) || "project.basedir".equals(expression)) { + return PlexusTestCase.getBasedir(); + } else if (expression.startsWith("basedir") || expression.startsWith("project.basedir")) { + int pathSeparator = expression.indexOf("/"); + + if (pathSeparator > 0) { + value = PlexusTestCase.getBasedir() + expression.substring(pathSeparator); + } else { + System.out.println("Got expression '" + expression + "' that was not recognised"); + } + return value; + } else if ("localRepository".equals(expression)) { + File localRepo = new File(PlexusTestCase.getBasedir(), "target/local-repo"); + return new MavenArtifactRepository("localRepository", "file://" + localRepo.getAbsolutePath(), + new DefaultRepositoryLayout(), null, null); + } else { + return expr; + } + } + + private String stripTokens(String expr) { + if (expr.startsWith("${") && expr.indexOf("}") == expr.length() - 1) { + expr = expr.substring(2, expr.length() - 1); + } + + return expr; + } + + /** {@inheritDoc} */ + @Override + public File alignToBaseDirectory(File file) { + if (file.getAbsolutePath().startsWith(PlexusTestCase.getBasedir())) { + return file; + } else if (file.isAbsolute()) { + return file; + } else { + return new File(PlexusTestCase.getBasedir(), file.getPath()); + } + } +} diff --git a/src/test/java/org/mybatis/maven/testing/package-info.java b/src/test/java/org/mybatis/maven/testing/package-info.java new file mode 100644 index 00000000..475937a7 --- /dev/null +++ b/src/test/java/org/mybatis/maven/testing/package-info.java @@ -0,0 +1,20 @@ +/* + * Copyright 2010-2024 the original author or authors. + * + * Licensed 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 + * + * https://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. + */ +/** + * Code borrowed from Maven Plugin Testing from 4.0.0-alpha-2 in order to support maven 3 with junit 5. Maven has since + * deleted all maven 3 support leaving no real option here. + */ +package org.mybatis.maven.testing;