You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2015/04/06 19:03:55 UTC
svn commit: r1671589 - in
/uima/ruta/trunk/ruta-maven-plugin/src/main/java/org/apache/uima/ruta/maven:
RutaGenerateMTWLMojo.java RutaGenerateTWLMojo.java Utils.java
Author: pkluegl
Date: Mon Apr 6 17:03:55 2015
New Revision: 1671589
URL: http://svn.apache.org/r1671589
Log:
UIMA-4320
- added mojos for twl and mtwl files
Added:
uima/ruta/trunk/ruta-maven-plugin/src/main/java/org/apache/uima/ruta/maven/RutaGenerateMTWLMojo.java
uima/ruta/trunk/ruta-maven-plugin/src/main/java/org/apache/uima/ruta/maven/RutaGenerateTWLMojo.java
uima/ruta/trunk/ruta-maven-plugin/src/main/java/org/apache/uima/ruta/maven/Utils.java
Added: uima/ruta/trunk/ruta-maven-plugin/src/main/java/org/apache/uima/ruta/maven/RutaGenerateMTWLMojo.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-maven-plugin/src/main/java/org/apache/uima/ruta/maven/RutaGenerateMTWLMojo.java?rev=1671589&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-maven-plugin/src/main/java/org/apache/uima/ruta/maven/RutaGenerateMTWLMojo.java (added)
+++ uima/ruta/trunk/ruta-maven-plugin/src/main/java/org/apache/uima/ruta/maven/RutaGenerateMTWLMojo.java Mon Apr 6 17:03:55 2015
@@ -0,0 +1,103 @@
+/*
+ * 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.uima.ruta.maven;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.maven.model.FileSet;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.project.MavenProject;
+import org.apache.uima.ruta.resource.MultiTreeWordList;
+import org.sonatype.plexus.build.incremental.BuildContext;
+
+/**
+ * Generate descriptors from UIMA Ruta script files.
+ *
+ */
+@Mojo(name = "mtwl", defaultPhase = LifecyclePhase.PROCESS_RESOURCES, requiresDependencyResolution = ResolutionScope.COMPILE)
+public class RutaGenerateMTWLMojo extends AbstractMojo {
+ @Component
+ private MavenProject project;
+
+ @Component
+ private BuildContext buildContext;
+
+ /**
+ * The file where the generated multi tree word list will be written.
+ */
+ @Parameter(defaultValue = "${project.build.directory}/generated-sources/ruta/resources/generated.mtwl", required = true)
+ private File outputFile;
+
+ /**
+ * The source files for the multi tree word list.
+ */
+ @Parameter(required = true)
+ private FileSet inputFiles;
+
+ /**
+ * Source file encoding.
+ */
+ @Parameter(defaultValue = "${project.build.sourceEncoding}", required = true)
+ private String encoding;
+
+ /**
+ * Compress resulting multi tree word list.
+ */
+ @Parameter(defaultValue = "true", required = true)
+ private boolean compress;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ File parentFile = outputFile.getParentFile();
+ if (!parentFile.exists()) {
+ parentFile.mkdirs();
+ buildContext.refresh(parentFile);
+ }
+ List<File> files = null;
+ try {
+ files = Utils.getFiles(inputFiles);
+ } catch (IOException e) {
+ getLog().warn("Error accessing input files.", e);
+ }
+
+ MultiTreeWordList trie = null;
+ try {
+ trie = new MultiTreeWordList(files);
+ } catch (IOException e) {
+ getLog().warn("Error creating MTWL file.", e);
+ }
+
+ if (trie != null) {
+ try {
+ trie.createMTWLFile(outputFile.getAbsolutePath(), compress, encoding);
+ } catch (IOException e) {
+ getLog().warn("Error writing MTWL file.", e);
+ }
+ }
+
+ }
+}
Added: uima/ruta/trunk/ruta-maven-plugin/src/main/java/org/apache/uima/ruta/maven/RutaGenerateTWLMojo.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-maven-plugin/src/main/java/org/apache/uima/ruta/maven/RutaGenerateTWLMojo.java?rev=1671589&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-maven-plugin/src/main/java/org/apache/uima/ruta/maven/RutaGenerateTWLMojo.java (added)
+++ uima/ruta/trunk/ruta-maven-plugin/src/main/java/org/apache/uima/ruta/maven/RutaGenerateTWLMojo.java Mon Apr 6 17:03:55 2015
@@ -0,0 +1,106 @@
+/*
+ * 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.uima.ruta.maven;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.maven.model.FileSet;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+import org.apache.maven.project.MavenProject;
+import org.apache.uima.ruta.resource.TreeWordList;
+import org.sonatype.plexus.build.incremental.BuildContext;
+
+/**
+ * Generate descriptors from UIMA Ruta script files.
+ *
+ */
+@Mojo(name = "twl", defaultPhase = LifecyclePhase.PROCESS_RESOURCES, requiresDependencyResolution = ResolutionScope.COMPILE)
+public class RutaGenerateTWLMojo extends AbstractMojo {
+ @Component
+ private MavenProject project;
+
+ @Component
+ private BuildContext buildContext;
+
+ /**
+ * The directory where the generated tree word lists will be written.
+ */
+ @Parameter(defaultValue = "${project.build.directory}/generated-sources/ruta/resources/", required = true)
+ private File outputDirectory;
+
+ /**
+ * The source files for the tree word list.
+ */
+ @Parameter(required = true)
+ private FileSet inputFiles;
+
+ /**
+ * Source file encoding.
+ */
+ @Parameter(defaultValue = "${project.build.sourceEncoding}", required = true)
+ private String encoding;
+
+ /**
+ * Compress resulting tree word list.
+ */
+ @Parameter(defaultValue = "true", required = true)
+ private boolean compress;
+
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (!outputDirectory.exists()) {
+ outputDirectory.mkdirs();
+ buildContext.refresh(outputDirectory);
+ }
+
+ List<File> files = null;
+ try {
+ files = Utils.getFiles(inputFiles);
+ } catch (IOException e) {
+ getLog().warn("Error accessing input files.", e);
+ }
+
+ for (File file : files) {
+ TreeWordList list = null;
+ try {
+ list = new TreeWordList(file.getAbsolutePath(), false);
+ } catch (IOException e) {
+ getLog().warn("Error generating twl.", e);
+ }
+ if (list != null) {
+ String outputName = file.getName().substring(0, file.getName().length() - 3) + "twl";
+ File outputFile = new File(outputDirectory, outputName);
+ try {
+ list.createTWLFile(outputFile.getAbsolutePath(), compress, "UTF-8");
+ } catch (IOException e) {
+ getLog().warn("Error writing twl file.", e);
+ }
+ }
+ }
+
+ }
+}
Added: uima/ruta/trunk/ruta-maven-plugin/src/main/java/org/apache/uima/ruta/maven/Utils.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-maven-plugin/src/main/java/org/apache/uima/ruta/maven/Utils.java?rev=1671589&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-maven-plugin/src/main/java/org/apache/uima/ruta/maven/Utils.java (added)
+++ uima/ruta/trunk/ruta-maven-plugin/src/main/java/org/apache/uima/ruta/maven/Utils.java Mon Apr 6 17:03:55 2015
@@ -0,0 +1,50 @@
+/*
+ * 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.uima.ruta.maven;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.maven.model.FileSet;
+import org.codehaus.plexus.util.FileUtils;
+
+public class Utils {
+
+ @SuppressWarnings("unchecked")
+ public static List<File> getFiles(FileSet fileSet) throws IOException {
+ File directory = new File(fileSet.getDirectory());
+ String includes = toString(fileSet.getIncludes());
+ String excludes = toString(fileSet.getExcludes());
+ return (List<File>) FileUtils.getFiles(directory, includes, excludes);
+ }
+
+ private static String toString(List<String> strings) {
+ StringBuilder sb = new StringBuilder();
+ for (String string : strings) {
+ if (sb.length() > 0) {
+ sb.append(", ");
+ }
+ sb.append(string);
+ }
+ return sb.toString();
+ }
+
+}