Пример #1
0
 /**
  * List the dependencies needed for compilation, those dependencies are used to get the include
  * paths needed for compilation and to get the libraries paths and names needed for linking.
  */
 @Override
 protected List<Artifact> getArtifacts() {
   try {
     final List<String> scopes = new ArrayList<String>();
     scopes.add(Artifact.SCOPE_COMPILE);
     scopes.add(Artifact.SCOPE_PROVIDED);
     // scopes.add(Artifact.SCOPE_RUNTIME);
     scopes.add(Artifact.SCOPE_SYSTEM);
     // scopes.add(Artifact.SCOPE_TEST);
     return getNarManager().getDependencies(scopes);
   } catch (final MojoExecutionException e) {
     e.printStackTrace();
   } catch (final MojoFailureException e) {
     e.printStackTrace();
   }
   return Collections.EMPTY_LIST;
 }
  public boolean mojo(List<String> args, MOJO_VARIANTS variant) {
    boolean success = false;
    try {
      File pom = new File(folder.getPath() + File.separator + "pom.xml");
      if (!pom.exists()) {
        success = streamMockPOM(pom, model.getName());
      }

      MavenProject mp = new MavenProject();

      final Hyperjaxb3Mojo mojo = new Hyperjaxb3Mojo();
      mojo.setVerbose(true);

      mojo.setBindingDirectory(getMetaInfDir());
      mojo.setSchemaDirectory(getMetaInfDir());

      int j = 0;
      String[] excludedSchemas = new String[preexistingSchemas.size()];
      for (File f : preexistingSchemas) {
        excludedSchemas[j++] = f.getName();
      }
      mojo.setSchemaExcludes(excludedSchemas);

      int k = 0;
      String[] excludedBindings = new String[preesistingBindings.size()];
      for (File f : preesistingBindings) {
        excludedBindings[k++] = f.getName();
      }
      mojo.setBindingExcludes(excludedBindings);

      mojo.setGenerateDirectory(getXjcDir());
      mojo.setExtension(true);
      mojo.variant = variant.getLabel();

      File perx =
          new File(
              getBinDir().getPath()
                  + File.separator
                  + "META-INF"
                  + File.separator
                  + "persistence.xml");
      if (perx.exists()) {
        mojo.persistenceXml = perx;
        try {
          Document dox = parseXML(perx);

          XPath xpath = XPathFactory.newInstance().newXPath();
          XPathExpression expr = xpath.compile("//persistence-unit/@name");

          mojo.persistenceUnitName = (String) expr.evaluate(dox, XPathConstants.STRING);

        } catch (Exception e) {
          mojo.persistenceXml =
              new File(getMetaInfDir() + File.separator + "persistence-template-hibernate.xml");
          mojo.persistenceUnitName = model.getName();
        }
      } else {
        mojo.persistenceXml =
            new File(getMetaInfDir() + File.separator + "persistence-template-hibernate.xml");
        mojo.persistenceUnitName = model.getName();
      }

      mojo.generateEquals = false;
      mojo.generateHashCode = false;
      mojo.setProject(mp);

      mojo.setArgs(args);

      mojo.setForceRegenerate(true);
      mojo.execute();
      success = true;
    } catch (MojoExecutionException e) {
      e.printStackTrace();
    }
    return success;
  }