public void execute()

in ruta-maven-plugin/src/main/java/org/apache/uima/ruta/maven/RutaGenerateDescriptorMojo.java [223:362]


  public void execute() throws MojoExecutionException, MojoFailureException {

    if (!typeSystemOutputDirectory.exists()) {
      typeSystemOutputDirectory.mkdirs();
      buildContext.refresh(typeSystemOutputDirectory);
    }

    if (!analysisEngineOutputDirectory.exists()) {
      analysisEngineOutputDirectory.mkdirs();
      buildContext.refresh(analysisEngineOutputDirectory);
    }

    project.addCompileSourceRoot(typeSystemOutputDirectory.getPath());
    project.addCompileSourceRoot(analysisEngineOutputDirectory.getPath());

    String[] files = null;
    if (scriptFiles != null) {
      try {
        files = Utils.getFilePathArray(scriptFiles, buildContext);
      } catch (Exception e) {
        getLog().warn("Error accessing script files.", e);
      }
    } else {
      files = FileUtils.getFilesFromExtension(project.getBuild().getOutputDirectory(),
              new String[] { "ruta" });
    }

    if (addRutaNature) {
      addRutaNature();
      addRutaBuildPath();
    }

    if (files == null) {
      getLog().info("UIMA Ruta Building: Skipped, since no script files were selected.");
      return;
    }

    List<File> filesToBuild = new ArrayList<>();
    for (String each : files) {
      File file = new File(each);

      // TODO should check the correct package!
      List<File> possibleDescriptors = getPossibleDescriptors(file);
      if (possibleDescriptors == null) {
        filesToBuild.add(file);
        continue;
      }

      long scriptModified = file.lastModified();
      for (File eachDescriptor : possibleDescriptors) {
        long descModified = eachDescriptor.lastModified();
        if (scriptModified > descModified) {
          filesToBuild.add(file);
          break;
        }
      }
    }

    if (filesToBuild.isEmpty()) {
      getLog().info("UIMA Ruta Building: Skipped, since no changes were detected.");
      return;
    }

    RutaDescriptorFactory factory = new RutaDescriptorFactory();
    if (typeSystemTemplate != null) {
      try {
        factory.setDefaultTypeSystem(typeSystemTemplate.toURI().toURL());
      } catch (MalformedURLException e) {
        handleError("Failed to get URL of " + analysisEngineTemplate, e);
      }
    }
    if (analysisEngineTemplate != null) {
      try {
        factory.setDefaultEngine(analysisEngineTemplate.toURI().toURL());
      } catch (MalformedURLException e) {
        handleError("Failed to get URL of " + analysisEngineTemplate, e);
      }
    }

    URLClassLoader classloader = getClassloader(project, getLog(), includeScope);

    RutaBuildOptions options = new RutaBuildOptions();
    options.setTypeSystemSuffix(typeSystemSuffix);
    options.setAnalysisEngineSuffix(analysisEngineSuffix);
    options.setEncoding(encoding);
    options.setResolveImports(resolveImports);
    options.setImportByName(importByName);
    options.setClassLoader(classloader);

    List<String> extensions = getExtensionsFromClasspath(classloader);
    options.setLanguageExtensions(extensions);

    if (maxBuildRetries == -1) {
      maxBuildRetries = filesToBuild.size() * 3;
    }

    Queue<RutaDescriptorInformation> toBuild = new LinkedList<>();

    for (File file : filesToBuild) {
      try {
        RutaDescriptorInformation descriptorInformation = factory.parseDescriptorInformation(file,
                options);
        toBuild.add(descriptorInformation);
      } catch (RecognitionException re) {
        handleError("Failed to parse UIMA Ruta script file: " + file.getAbsolutePath(), re);
      } catch (IOException ioe) {
        handleError("Failed to load UIMA Ruta script file: " + file.getAbsolutePath(), ioe);
      }
    }

    int count = 0;
    while (!toBuild.isEmpty() && count <= maxBuildRetries) {
      RutaDescriptorInformation descriptorInformation = toBuild.poll();
      String scriptName = descriptorInformation.getScriptName();
      try {
        createDescriptors(factory, options, descriptorInformation);
      } catch (RecognitionException re) {
        getLog().warn("Failed to parse UIMA Ruta script: " + scriptName, re);
      } catch (IOException ioe) {
        toBuild.add(descriptorInformation);
        getLog().warn("Tried to build " + scriptName
                + ", but failed (dependency probably not yet build): " + ioe.getMessage());
        count++;
      } catch (SAXException saxe) {
        getLog().warn("Failed to write descriptor: " + scriptName, saxe);
      } catch (URISyntaxException urise) {
        getLog().warn("Failed to get uri: " + scriptName, urise);
      } catch (ResourceInitializationException rie) {
        getLog().warn("Failed initialize resource: " + scriptName, rie);
      } catch (InvalidXMLException ixmle) {
        getLog().warn("Invalid XML while building descriptor: " + scriptName, ixmle);
      }
    }

    for (RutaDescriptorInformation eachFailed : toBuild) {
      String scriptName = eachFailed.getScriptName();
      handleError("Failed to build UIMA Ruta script: " + scriptName);
    }

  }