This is an automated email from the ASF dual-hosted git repository. elharo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-scripting-plugin.git
The following commit(s) were added to refs/heads/master by this push: new 4985493 update parent POM to 39 (#9) 4985493 is described below commit 4985493f1d9fce6eb2816dc9640294e6d203befb Author: Elliotte Rusty Harold <elh...@users.noreply.github.com> AuthorDate: Wed Apr 12 10:38:28 2023 +0000 update parent POM to 39 (#9) --- pom.xml | 334 ++++++++++----------- src/it/mrm/repository/_mscripting-8.jar | Bin 867 -> 862 bytes .../plugins/scripting/AbstractScriptEvaluator.java | 132 ++++---- .../apache/maven/plugins/scripting/EvalMojo.java | 232 +++++++------- .../plugins/scripting/FileScriptEvaluator.java | 222 +++++++------- .../plugins/scripting/ResourceScriptEvaluator.java | 157 +++++----- .../plugins/scripting/StringScriptEvaluator.java | 172 +++++------ .../UnsupportedScriptEngineException.java | 13 +- 8 files changed, 600 insertions(+), 662 deletions(-) diff --git a/pom.xml b/pom.xml index 1d270ea..2ea294a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,168 +1,166 @@ -<?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> - - <parent> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-plugins</artifactId> - <version>34</version> - <relativePath>../../pom/maven/maven-plugins/pom.xml</relativePath> - </parent> - - <artifactId>maven-scripting-plugin</artifactId> - <version>3.0.1-SNAPSHOT</version> - <packaging>maven-plugin</packaging> - - <name>Apache Maven Scripting Plugin</name> - <description> - The Maven Scripting Plugin is a plugin that wrapped the Scripting API according to JSR223. - Add the scripting engines as dependencies of this plugin on its use. - </description> - <inceptionYear>2016</inceptionYear> - - <prerequisites> - <maven>${mavenVersion}</maven> - </prerequisites> - - <scm> - <connection>scm:git:https://gitbox.apache.org/repos/asf/maven-scripting-plugin.git</connection> - <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-scripting-plugin.git</developerConnection> - <url>https://github.com/apache/maven-scripting-plugin/tree/${project.scm.tag}</url> - <tag>HEAD</tag> - </scm> - <issueManagement> - <system>JIRA</system> - <url>https://issues.apache.org/jira/browse/MSCRIPTING</url> - </issueManagement> - <ciManagement> - <system>Jenkins</system> - <url>https://ci-builds.apache.org/job/Maven/job/maven-box/job/maven-scripting-plugin/</url> - </ciManagement> - <distributionManagement> - <site> - <id>apache.website</id> - <url>scm:svn:https://svn.apache.org/repos/asf/maven/website/components/${maven.site.path}</url> - </site> - </distributionManagement> - - <properties> - <mavenVersion>3.0</mavenVersion> - <maven.compiler.source>1.8</maven.compiler.source> - <maven.compiler.target>1.8</maven.compiler.target> - <project.build.outputTimestamp>2021-02-24T19:52:25Z</project.build.outputTimestamp> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-plugin-api</artifactId> - <version>${mavenVersion}</version> - </dependency> - <dependency> - <groupId>org.apache.maven.shared</groupId> - <artifactId>maven-shared-utils</artifactId> - <version>3.3.3</version> - </dependency> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-core</artifactId> - <version>${mavenVersion}</version> - </dependency> - - <!-- dependencies to annotations --> - <dependency> - <groupId>org.apache.maven.plugin-tools</groupId> - <artifactId>maven-plugin-annotations</artifactId> - <scope>provided</scope> - </dependency> - - <!-- Test --> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.12</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.maven.plugin-testing</groupId> - <artifactId>maven-plugin-testing-harness</artifactId> - <version>2.1</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.maven</groupId> - <artifactId>maven-compat</artifactId> - <version>${mavenVersion}</version> - <scope>test</scope> - </dependency> - </dependencies> - - <profiles> - <profile> - <id>run-its</id> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-invoker-plugin</artifactId> - <configuration> - <projectsDirectory>src/it/projects</projectsDirectory> - <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> - <preBuildHookScript>setup</preBuildHookScript> - <postBuildHookScript>verify</postBuildHookScript> - <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath> - <settingsFile>src/it/mrm/settings.xml</settingsFile> - <filterProperties> - <mrm.repository.url>${mrm.repository.url}</mrm.repository.url> - </filterProperties> - <goals> - <goal>scripting:eval</goal> - </goals> - </configuration> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>mrm-maven-plugin</artifactId> - <version>1.3.0</version> - <executions> - <execution> - <goals> - <goal>start</goal> - <goal>stop</goal> - </goals> - </execution> - </executions> - <configuration> - <repositories> - <mockRepo> - <source>src/it/mrm/repository</source> - </mockRepo> - <proxyRepo/> - </repositories> - </configuration> - </plugin> - </plugins> - </build> - </profile> - </profiles> -</project> +<?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> + + <parent> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-plugins</artifactId> + <version>39</version> + <relativePath>../../pom/maven/maven-plugins/pom.xml</relativePath> + </parent> + + <artifactId>maven-scripting-plugin</artifactId> + <version>3.0.1-SNAPSHOT</version> + <packaging>maven-plugin</packaging> + + <name>Apache Maven Scripting Plugin</name> + <description>The Maven Scripting Plugin is a plugin that wrapped the Scripting API according to JSR223. + Add the scripting engines as dependencies of this plugin on its use.</description> + <inceptionYear>2016</inceptionYear> + + <prerequisites> + <maven>${mavenVersion}</maven> + </prerequisites> + + <scm> + <connection>scm:git:https://gitbox.apache.org/repos/asf/maven-scripting-plugin.git</connection> + <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-scripting-plugin.git</developerConnection> + <tag>HEAD</tag> + <url>https://github.com/apache/maven-scripting-plugin/tree/${project.scm.tag}</url> + </scm> + <issueManagement> + <system>JIRA</system> + <url>https://issues.apache.org/jira/browse/MSCRIPTING</url> + </issueManagement> + <ciManagement> + <system>Jenkins</system> + <url>https://ci-builds.apache.org/job/Maven/job/maven-box/job/maven-scripting-plugin/</url> + </ciManagement> + <distributionManagement> + <site> + <id>apache.website</id> + <url>scm:svn:https://svn.apache.org/repos/asf/maven/website/components/${maven.site.path}</url> + </site> + </distributionManagement> + + <properties> + <mavenVersion>3.0</mavenVersion> + <maven.compiler.source>1.8</maven.compiler.source> + <maven.compiler.target>1.8</maven.compiler.target> + <project.build.outputTimestamp>2021-02-24T19:52:25Z</project.build.outputTimestamp> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>${mavenVersion}</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-shared-utils</artifactId> + <version>3.3.3</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>${mavenVersion}</version> + <scope>provided</scope> + </dependency> + + <!-- dependencies to annotations --> + <dependency> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-annotations</artifactId> + <scope>provided</scope> + </dependency> + + <!-- Test --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.maven.plugin-testing</groupId> + <artifactId>maven-plugin-testing-harness</artifactId> + <version>2.1</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-compat</artifactId> + <version>${mavenVersion}</version> + <scope>test</scope> + </dependency> + </dependencies> + + <profiles> + <profile> + <id>run-its</id> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-invoker-plugin</artifactId> + <configuration> + <projectsDirectory>src/it/projects</projectsDirectory> + <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo> + <preBuildHookScript>setup</preBuildHookScript> + <postBuildHookScript>verify</postBuildHookScript> + <localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath> + <settingsFile>src/it/mrm/settings.xml</settingsFile> + <filterProperties> + <mrm.repository.url>${mrm.repository.url}</mrm.repository.url> + </filterProperties> + <goals> + <goal>scripting:eval</goal> + </goals> + </configuration> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>mrm-maven-plugin</artifactId> + <version>1.3.0</version> + <configuration> + <repositories> + <mockRepo> + <source>src/it/mrm/repository</source> + </mockRepo> + <proxyRepo /> + </repositories> + </configuration> + <executions> + <execution> + <goals> + <goal>start</goal> + <goal>stop</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> diff --git a/src/it/mrm/repository/_mscripting-8.jar b/src/it/mrm/repository/_mscripting-8.jar index 4bc8711..5a8829a 100644 Binary files a/src/it/mrm/repository/_mscripting-8.jar and b/src/it/mrm/repository/_mscripting-8.jar differ diff --git a/src/main/java/org/apache/maven/plugins/scripting/AbstractScriptEvaluator.java b/src/main/java/org/apache/maven/plugins/scripting/AbstractScriptEvaluator.java index 7605680..a8cdb9b 100644 --- a/src/main/java/org/apache/maven/plugins/scripting/AbstractScriptEvaluator.java +++ b/src/main/java/org/apache/maven/plugins/scripting/AbstractScriptEvaluator.java @@ -1,68 +1,64 @@ -package org.apache.maven.plugins.scripting; - -/* - * 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 javax.script.Bindings; -import javax.script.ScriptContext; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; - -/** - * Evaluates a script in the appropriate context and return its possibly null result - * @author Rusi Popov - */ -abstract class AbstractScriptEvaluator -{ - - /** - * @param bindings not null bindings to provide to the script to execute - * @return the possibly null result the script produced - * @throws UnsupportedScriptEngineException when the engine is not configured correctly - * @throws ScriptException if an error occurs in script. - */ - public final Object eval( Bindings bindings ) throws ScriptException, UnsupportedScriptEngineException - { - ScriptEngineManager manager = new ScriptEngineManager(); - ScriptEngine engine = getEngine( manager ); - ScriptContext context = engine.getContext(); - - context.setBindings( bindings, ScriptContext.GLOBAL_SCOPE ); - - return eval( engine, context ); - } - - /** - * AbstractScriptEvaluator the script - * @param engine not null - * @param context not null, initialized - * @return possibly null result of the script - * @throws ScriptException if an error occurs in script. - */ - protected abstract Object eval( ScriptEngine engine, ScriptContext context ) throws ScriptException; - - /** - * @param manager not null - * @return non-null engine to execute the script - * @throws UnsupportedScriptEngineException when no engine could be identified - */ - protected abstract ScriptEngine getEngine( ScriptEngineManager manager ) - throws UnsupportedScriptEngineException; -} +/* + * 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.apache.maven.plugins.scripting; + +import javax.script.Bindings; +import javax.script.ScriptContext; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; + +/** + * Evaluates a script in the appropriate context and return its possibly null result + * @author Rusi Popov + */ +abstract class AbstractScriptEvaluator { + + /** + * @param bindings not null bindings to provide to the script to execute + * @return the possibly null result the script produced + * @throws UnsupportedScriptEngineException when the engine is not configured correctly + * @throws ScriptException if an error occurs in script. + */ + public final Object eval(Bindings bindings) throws ScriptException, UnsupportedScriptEngineException { + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine engine = getEngine(manager); + ScriptContext context = engine.getContext(); + + context.setBindings(bindings, ScriptContext.GLOBAL_SCOPE); + + return eval(engine, context); + } + + /** + * AbstractScriptEvaluator the script + * @param engine not null + * @param context not null, initialized + * @return possibly null result of the script + * @throws ScriptException if an error occurs in script. + */ + protected abstract Object eval(ScriptEngine engine, ScriptContext context) throws ScriptException; + + /** + * @param manager not null + * @return non-null engine to execute the script + * @throws UnsupportedScriptEngineException when no engine could be identified + */ + protected abstract ScriptEngine getEngine(ScriptEngineManager manager) throws UnsupportedScriptEngineException; +} diff --git a/src/main/java/org/apache/maven/plugins/scripting/EvalMojo.java b/src/main/java/org/apache/maven/plugins/scripting/EvalMojo.java index 3976f13..739a7a0 100644 --- a/src/main/java/org/apache/maven/plugins/scripting/EvalMojo.java +++ b/src/main/java/org/apache/maven/plugins/scripting/EvalMojo.java @@ -1,124 +1,108 @@ -package org.apache.maven.plugins.scripting; - -/* - * 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.io.File; - -import javax.script.Bindings; -import javax.script.ScriptException; -import javax.script.SimpleBindings; - -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Mojo; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; - -/** - * Evaluate the specified script or scriptFile - * - * @author Robert Scholte - * @since 3.0.0 - */ -@Mojo( name = "eval" ) -public class EvalMojo - extends AbstractMojo -{ - @Parameter - private String engineName; - - /** - * When used, also specify the engineName - */ - @Parameter - private String script; - - /** - * Provide the script as an external file as an alternative to <script>. - * When scriptFile provided the script is ignored. - * The file name extension identifies the script language to use, as of javax.script.ScriptEngineManager - * and {@linkplain "https://jcp.org/aboutJava/communityprocess/final/jsr223/index.html"} - */ - @Parameter - private File scriptFile; - - @Parameter String scriptResource; - - // script variables - @Parameter( defaultValue = "${project}", readonly = true ) - private MavenProject project; - - @Override - public void execute() - throws MojoExecutionException, MojoFailureException - { - try - { - AbstractScriptEvaluator execute = constructExecute(); - - Bindings bindings = new SimpleBindings(); - bindings.put( "project", project ); - bindings.put( "log", getLog() ); - - Object result = execute.eval( bindings ); - - getLog().info( "Result:" ); - if ( result != null ) - { - getLog().info( result.toString() ); - } - } - catch ( ScriptException e ) // configuring the plugin failed - { - throw new MojoExecutionException( e.getMessage(), e ); - } - catch ( UnsupportedScriptEngineException e ) // execution failure - { - throw new MojoFailureException( e.getMessage(), e ); - } - } - - private AbstractScriptEvaluator constructExecute() throws IllegalArgumentException - { - AbstractScriptEvaluator execute; - - if ( scriptFile != null ) - { - execute = new FileScriptEvaluator( engineName, scriptFile ); - - } - else if ( scriptResource != null ) - { - execute = new ResourceScriptEvaluator( engineName, scriptResource ); - - } - else if ( script != null ) - { - execute = new StringScriptEvaluator( engineName, script ); - - } - else - { - throw new IllegalArgumentException( "Missing script or scriptFile provided" ); - } - return execute; - } -} \ No newline at end of file +/* + * 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.apache.maven.plugins.scripting; + +import javax.script.Bindings; +import javax.script.ScriptException; +import javax.script.SimpleBindings; + +import java.io.File; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; + +/** + * Evaluate the specified script or scriptFile + * + * @author Robert Scholte + * @since 3.0.0 + */ +@Mojo(name = "eval") +public class EvalMojo extends AbstractMojo { + @Parameter + private String engineName; + + /** + * When used, also specify the engineName + */ + @Parameter + private String script; + + /** + * Provide the script as an external file as an alternative to <script>. + * When scriptFile provided the script is ignored. + * The file name extension identifies the script language to use, as of javax.script.ScriptEngineManager + * and {@linkplain "https://jcp.org/aboutJava/communityprocess/final/jsr223/index.html"} + */ + @Parameter + private File scriptFile; + + @Parameter + String scriptResource; + + // script variables + @Parameter(defaultValue = "${project}", readonly = true) + private MavenProject project; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + try { + AbstractScriptEvaluator execute = constructExecute(); + + Bindings bindings = new SimpleBindings(); + bindings.put("project", project); + bindings.put("log", getLog()); + + Object result = execute.eval(bindings); + + getLog().info("Result:"); + if (result != null) { + getLog().info(result.toString()); + } + } catch (ScriptException e) // configuring the plugin failed + { + throw new MojoExecutionException(e.getMessage(), e); + } catch (UnsupportedScriptEngineException e) // execution failure + { + throw new MojoFailureException(e.getMessage(), e); + } + } + + private AbstractScriptEvaluator constructExecute() throws IllegalArgumentException { + AbstractScriptEvaluator execute; + + if (scriptFile != null) { + execute = new FileScriptEvaluator(engineName, scriptFile); + + } else if (scriptResource != null) { + execute = new ResourceScriptEvaluator(engineName, scriptResource); + + } else if (script != null) { + execute = new StringScriptEvaluator(engineName, script); + + } else { + throw new IllegalArgumentException("Missing script or scriptFile provided"); + } + return execute; + } +} diff --git a/src/main/java/org/apache/maven/plugins/scripting/FileScriptEvaluator.java b/src/main/java/org/apache/maven/plugins/scripting/FileScriptEvaluator.java index 9f7abd7..0b1dff9 100644 --- a/src/main/java/org/apache/maven/plugins/scripting/FileScriptEvaluator.java +++ b/src/main/java/org/apache/maven/plugins/scripting/FileScriptEvaluator.java @@ -1,118 +1,104 @@ -package org.apache.maven.plugins.scripting; - -/* - * 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.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.UncheckedIOException; - -import javax.script.ScriptContext; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; - -/** - * Evaluates a script held in a file. Use the engine name to override the engine if the file name does not refer/decode - * to a valid engine name or not define any at all. - * @author Rusi Popov - */ -public class FileScriptEvaluator extends AbstractScriptEvaluator -{ - - /** - * Not null, existing readable file with the script - */ - private final File scriptFile; - - /** - * Possibly null engine name - */ - private final String engineName; - - /** - * @param engineName optional engine name, used to override the engine selection from the file extension - * @param scriptFile not null - */ - public FileScriptEvaluator( String engineName, File scriptFile ) - { - this.scriptFile = scriptFile; - - this.engineName = engineName; - } - - /** - * @param engine the script engine. - * @param context the script context. - * @return the result of the scriptFile. - * @throws ScriptException if an error occurs in script. - * @see org.apache.maven.plugins.scripting.AbstractScriptEvaluator#eval(javax.script.ScriptEngine, javax.script.ScriptContext) - */ - protected Object eval( ScriptEngine engine, ScriptContext context ) throws ScriptException - { - try ( FileReader reader = new FileReader( scriptFile ) ) - { - return engine.eval( reader, context ); - } - catch ( IOException ex ) - { - throw new UncheckedIOException( scriptFile + " caused:", ex ); - } - } - - /** - * Gets the script engine by engineName, otherwise by extension of the sciptFile - * - * @param manager the script engine manager - * @throws UnsupportedScriptEngineException if specified engine is not available - * @see org.apache.maven.plugins.scripting.AbstractScriptEvaluator#getEngine(javax.script.ScriptEngineManager) - */ - protected ScriptEngine getEngine( ScriptEngineManager manager ) throws UnsupportedScriptEngineException - { - ScriptEngine result; - - if ( engineName != null && !engineName.isEmpty() ) - { - result = manager.getEngineByName( engineName ); - - if ( result == null ) - { - throw new UnsupportedScriptEngineException( "No engine found by name \"" + engineName + "\n" ); - } - } - else - { - String extension = scriptFile.getName(); - int position = extension.indexOf( "." ); - - if ( position >= 0 ) - { - extension = extension.substring( position + 1 ); - } - result = manager.getEngineByExtension( extension ); - - if ( result == null ) - { - throw new UnsupportedScriptEngineException( "No engine found by extension \"" + extension + "\n" ); - } - } - return result; - } -} +/* + * 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.apache.maven.plugins.scripting; + +import javax.script.ScriptContext; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.UncheckedIOException; + +/** + * Evaluates a script held in a file. Use the engine name to override the engine if the file name does not refer/decode + * to a valid engine name or not define any at all. + * @author Rusi Popov + */ +public class FileScriptEvaluator extends AbstractScriptEvaluator { + + /** + * Not null, existing readable file with the script + */ + private final File scriptFile; + + /** + * Possibly null engine name + */ + private final String engineName; + + /** + * @param engineName optional engine name, used to override the engine selection from the file extension + * @param scriptFile not null + */ + public FileScriptEvaluator(String engineName, File scriptFile) { + this.scriptFile = scriptFile; + + this.engineName = engineName; + } + + /** + * @param engine the script engine. + * @param context the script context. + * @return the result of the scriptFile. + * @throws ScriptException if an error occurs in script. + * @see org.apache.maven.plugins.scripting.AbstractScriptEvaluator#eval(javax.script.ScriptEngine, javax.script.ScriptContext) + */ + protected Object eval(ScriptEngine engine, ScriptContext context) throws ScriptException { + try (FileReader reader = new FileReader(scriptFile)) { + return engine.eval(reader, context); + } catch (IOException ex) { + throw new UncheckedIOException(scriptFile + " caused:", ex); + } + } + + /** + * Gets the script engine by engineName, otherwise by extension of the sciptFile + * + * @param manager the script engine manager + * @throws UnsupportedScriptEngineException if specified engine is not available + * @see org.apache.maven.plugins.scripting.AbstractScriptEvaluator#getEngine(javax.script.ScriptEngineManager) + */ + protected ScriptEngine getEngine(ScriptEngineManager manager) throws UnsupportedScriptEngineException { + ScriptEngine result; + + if (engineName != null && !engineName.isEmpty()) { + result = manager.getEngineByName(engineName); + + if (result == null) { + throw new UnsupportedScriptEngineException("No engine found by name \"" + engineName + "\n"); + } + } else { + String extension = scriptFile.getName(); + int position = extension.indexOf("."); + + if (position >= 0) { + extension = extension.substring(position + 1); + } + result = manager.getEngineByExtension(extension); + + if (result == null) { + throw new UnsupportedScriptEngineException("No engine found by extension \"" + extension + "\n"); + } + } + return result; + } +} diff --git a/src/main/java/org/apache/maven/plugins/scripting/ResourceScriptEvaluator.java b/src/main/java/org/apache/maven/plugins/scripting/ResourceScriptEvaluator.java index 5321226..f0adb4d 100644 --- a/src/main/java/org/apache/maven/plugins/scripting/ResourceScriptEvaluator.java +++ b/src/main/java/org/apache/maven/plugins/scripting/ResourceScriptEvaluator.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.scripting; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,6 +16,12 @@ package org.apache.maven.plugins.scripting; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.scripting; + +import javax.script.ScriptContext; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; import java.io.IOException; import java.io.InputStream; @@ -25,104 +29,85 @@ import java.io.InputStreamReader; import java.io.Reader; import java.io.UncheckedIOException; -import javax.script.ScriptContext; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; - /** * Evaluates a script held in a resource. Use the engine name to override the engine if the resource name does not * refer/decode to a valid engine name or not define any at all. - * + * * @author Robert Scholte */ -public class ResourceScriptEvaluator extends AbstractScriptEvaluator -{ - - /** - * Not null, existing readable file with the script - */ - private final String resourceName; +public class ResourceScriptEvaluator extends AbstractScriptEvaluator { - /** - * Possibly null engine name - */ - private final String engineName; + /** + * Not null, existing readable file with the script + */ + private final String resourceName; - /** - * @param engineName optional engine name, used to override the engine selection from the file extension - * @param resourceName not null - */ - public ResourceScriptEvaluator( String engineName, String resourceName ) - { - this.resourceName = resourceName; + /** + * Possibly null engine name + */ + private final String engineName; - this.engineName = engineName; - } + /** + * @param engineName optional engine name, used to override the engine selection from the file extension + * @param resourceName not null + */ + public ResourceScriptEvaluator(String engineName, String resourceName) { + this.resourceName = resourceName; - /** - * @param engine the script engine. - * @param context the script context. - * @return the result of the scriptFile. - * @throws ScriptException if an error occurs in script. - * @see org.apache.maven.plugins.scripting.AbstractScriptEvaluator#eval(javax.script.ScriptEngine, javax.script.ScriptContext) - */ - protected Object eval( ScriptEngine engine, ScriptContext context ) throws ScriptException - { - - try ( InputStream is = this.getClass().getClassLoader().getResourceAsStream( resourceName ); - Reader reader = new InputStreamReader( is ) ) - { - return engine.eval( reader, context ); + this.engineName = engineName; } - catch ( IOException ex ) - { - throw new UncheckedIOException( resourceName + " caused:", ex ); + + /** + * @param engine the script engine. + * @param context the script context. + * @return the result of the scriptFile. + * @throws ScriptException if an error occurs in script. + * @see org.apache.maven.plugins.scripting.AbstractScriptEvaluator#eval(javax.script.ScriptEngine, javax.script.ScriptContext) + */ + protected Object eval(ScriptEngine engine, ScriptContext context) throws ScriptException { + + try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(resourceName); + Reader reader = new InputStreamReader(is)) { + return engine.eval(reader, context); + } catch (IOException ex) { + throw new UncheckedIOException(resourceName + " caused:", ex); + } } - } - /** - * Gets the script engine by engineName, otherwise by extension of the sciptFile - * - * @param manager the script engine manager - * @throws UnsupportedScriptEngineException if specified engine is not available - * @see org.apache.maven.plugins.scripting.AbstractScriptEvaluator#getEngine(javax.script.ScriptEngineManager) - */ - protected ScriptEngine getEngine( ScriptEngineManager manager ) throws UnsupportedScriptEngineException - { - ScriptEngine result; + /** + * Gets the script engine by engineName, otherwise by extension of the sciptFile + * + * @param manager the script engine manager + * @throws UnsupportedScriptEngineException if specified engine is not available + * @see org.apache.maven.plugins.scripting.AbstractScriptEvaluator#getEngine(javax.script.ScriptEngineManager) + */ + protected ScriptEngine getEngine(ScriptEngineManager manager) throws UnsupportedScriptEngineException { + ScriptEngine result; - if ( engineName != null && !engineName.isEmpty() ) - { - result = manager.getEngineByName( engineName ); + if (engineName != null && !engineName.isEmpty()) { + result = manager.getEngineByName(engineName); - if ( result == null ) - { - throw new UnsupportedScriptEngineException( "No engine found by name \"" + engineName + "\n" ); - } - } - else - { - String name = resourceName; - int fileSepIndex = name.lastIndexOf( '/' ); - if ( fileSepIndex >= 0 ) - { - name = name.substring( fileSepIndex + 1 ); - } - - String extension = name; - int position = name.indexOf( "." ); - if ( position >= 0 ) - { - extension = name.substring( position + 1 ); - } - result = manager.getEngineByExtension( extension ); + if (result == null) { + throw new UnsupportedScriptEngineException("No engine found by name \"" + engineName + "\n"); + } + } else { + String name = resourceName; + int fileSepIndex = name.lastIndexOf('/'); + if (fileSepIndex >= 0) { + name = name.substring(fileSepIndex + 1); + } + + String extension = name; + int position = name.indexOf("."); + if (position >= 0) { + extension = name.substring(position + 1); + } + result = manager.getEngineByExtension(extension); - if ( result == null ) - { - throw new UnsupportedScriptEngineException( "No engine found by extension \"" + extension + "\n" ); - } + if (result == null) { + throw new UnsupportedScriptEngineException("No engine found by extension \"" + extension + "\n"); + } + } + return result; } - return result; - } } diff --git a/src/main/java/org/apache/maven/plugins/scripting/StringScriptEvaluator.java b/src/main/java/org/apache/maven/plugins/scripting/StringScriptEvaluator.java index 5a31c85..8408888 100644 --- a/src/main/java/org/apache/maven/plugins/scripting/StringScriptEvaluator.java +++ b/src/main/java/org/apache/maven/plugins/scripting/StringScriptEvaluator.java @@ -1,90 +1,82 @@ -package org.apache.maven.plugins.scripting; - -/* - * 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 javax.script.ScriptContext; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; - -/** - * Evaluates a script held in a string - * @author Rusi Popov - */ -public class StringScriptEvaluator extends AbstractScriptEvaluator -{ - - /** - * Not null name of the engine to execute the script - */ - private final String engineName; - - /** - * The non-null script itself - */ - private final String script; - - /** - * @param engineName the engine name - * @param script the script - * @throws IllegalArgumentException if either engineName or script is null - */ - public StringScriptEvaluator( String engineName, String script ) - { - if ( engineName == null || engineName.isEmpty() ) - { - throw new IllegalArgumentException( "Expected a non-empty engine name provided" ); - } - this.engineName = engineName; - - if ( script == null || script.trim().isEmpty() ) - { - throw new IllegalArgumentException( "Expected a non-empty script provided" ); - } - this.script = script; - } - - /** - * @param manager the script engine manager. - * @throws UnsupportedScriptEngineException if the engineName is not supported - * @see org.apache.maven.plugins.scripting.AbstractScriptEvaluator#getEngine(javax.script.ScriptEngineManager) - */ - protected ScriptEngine getEngine( ScriptEngineManager manager ) throws UnsupportedScriptEngineException - { - ScriptEngine result = manager.getEngineByName( engineName ); - - if ( result == null ) - { - throw new UnsupportedScriptEngineException( "Unknown engine specified with name \"" + engineName + "\"" ); - } - return result; - } - - /** - * @param engine the script engine. - * @param context the script context. - * @throws ScriptException if an error occurs in script. - * @see org.apache.maven.plugins.scripting.AbstractScriptEvaluator#eval(javax.script.ScriptEngine, javax.script.ScriptContext) - */ - protected Object eval( ScriptEngine engine, ScriptContext context ) throws ScriptException - { - return engine.eval( script, context ); - } -} \ No newline at end of file +/* + * 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.apache.maven.plugins.scripting; + +import javax.script.ScriptContext; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; + +/** + * Evaluates a script held in a string + * @author Rusi Popov + */ +public class StringScriptEvaluator extends AbstractScriptEvaluator { + + /** + * Not null name of the engine to execute the script + */ + private final String engineName; + + /** + * The non-null script itself + */ + private final String script; + + /** + * @param engineName the engine name + * @param script the script + * @throws IllegalArgumentException if either engineName or script is null + */ + public StringScriptEvaluator(String engineName, String script) { + if (engineName == null || engineName.isEmpty()) { + throw new IllegalArgumentException("Expected a non-empty engine name provided"); + } + this.engineName = engineName; + + if (script == null || script.trim().isEmpty()) { + throw new IllegalArgumentException("Expected a non-empty script provided"); + } + this.script = script; + } + + /** + * @param manager the script engine manager. + * @throws UnsupportedScriptEngineException if the engineName is not supported + * @see org.apache.maven.plugins.scripting.AbstractScriptEvaluator#getEngine(javax.script.ScriptEngineManager) + */ + protected ScriptEngine getEngine(ScriptEngineManager manager) throws UnsupportedScriptEngineException { + ScriptEngine result = manager.getEngineByName(engineName); + + if (result == null) { + throw new UnsupportedScriptEngineException("Unknown engine specified with name \"" + engineName + "\""); + } + return result; + } + + /** + * @param engine the script engine. + * @param context the script context. + * @throws ScriptException if an error occurs in script. + * @see org.apache.maven.plugins.scripting.AbstractScriptEvaluator#eval(javax.script.ScriptEngine, javax.script.ScriptContext) + */ + protected Object eval(ScriptEngine engine, ScriptContext context) throws ScriptException { + return engine.eval(script, context); + } +} diff --git a/src/main/java/org/apache/maven/plugins/scripting/UnsupportedScriptEngineException.java b/src/main/java/org/apache/maven/plugins/scripting/UnsupportedScriptEngineException.java index 6f9975d..52a9118 100644 --- a/src/main/java/org/apache/maven/plugins/scripting/UnsupportedScriptEngineException.java +++ b/src/main/java/org/apache/maven/plugins/scripting/UnsupportedScriptEngineException.java @@ -1,5 +1,3 @@ -package org.apache.maven.plugins.scripting; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -18,17 +16,16 @@ package org.apache.maven.plugins.scripting; * specific language governing permissions and limitations * under the License. */ +package org.apache.maven.plugins.scripting; /** * Exception - * + * * @author Robert Scholte * */ -public class UnsupportedScriptEngineException extends Exception -{ - public UnsupportedScriptEngineException( String message ) - { - super( message ); +public class UnsupportedScriptEngineException extends Exception { + public UnsupportedScriptEngineException(String message) { + super(message); } }