<commit_before>/*
 * Copyright 2003-2007 The eFaps Team
 *
 * 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
 *
 *     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.
 *
 * Revision:        $Rev$
 * Last Changed:    $Date$
 * Last Changed By: $Author$
 */

package org.efaps.maven.plugin.install;

import java.util.List;

import org.apache.maven.plugin.MojoExecutionException;
import org.jfrog.maven.annomojo.annotations.MojoGoal;
import org.jfrog.maven.annomojo.annotations.MojoParameter;
import org.jfrog.maven.annomojo.annotations.MojoRequiresDependencyResolution;

import org.efaps.maven.plugin.goal.efaps.install.Application;

/**
 *
 * @author tmo
 * @version $Id$
 * @todo description
 */
@MojoGoal("install")
@MojoRequiresDependencyResolution("compile")
public final class InstallMojo extends AbstractEFapsInstallMojo  {
  
  /////////////////////////////////////////////////////////////////////////////
  // instance variables

  /**
   * 
   */
  @MojoParameter()
  private List<String> applications = null;

  /////////////////////////////////////////////////////////////////////////////
  // instance methods

  /**
   * Executes the kernel install goal.
   *
   * @todo description
   */
  public void execute() throws MojoExecutionException  {
    init();
    try  {
      final ClassLoader cl = getClass().getClassLoader();

      // get kernel install application (read from version xml file)
      Application appl = Application.getApplication(cl.getResource("META-INF/efaps/install.xml"),
                                                    getClasspathElements());
      appl.install(getUserName(), getPassWord());

      startTransaction();
      appl.importData();
      commitTransaction();
    } catch (Exception e)  {
      throw new MojoExecutionException(
            "Could not execute Kernal Installation script", e);
    }
  }
}<commit_msg>- the application to install could now be defined<commit_after>/*
 * Copyright 2003-2007 The eFaps Team
 *
 * 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
 *
 *     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.
 *
 * Revision:        $Rev$
 * Last Changed:    $Date$
 * Last Changed By: $Author$
 */

package org.efaps.maven.plugin.install;

import java.net.URL;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

import org.apache.maven.plugin.MojoExecutionException;
import org.jfrog.maven.annomojo.annotations.MojoGoal;
import org.jfrog.maven.annomojo.annotations.MojoParameter;
import org.jfrog.maven.annomojo.annotations.MojoRequiresDependencyResolution;

import org.efaps.maven.plugin.goal.efaps.install.Application;

/**
 *
 * @author tmo
 * @version $Id$
 * @todo description
 */
@MojoGoal("install")
@MojoRequiresDependencyResolution("compile")
public final class InstallMojo extends AbstractEFapsInstallMojo  {
  
  /////////////////////////////////////////////////////////////////////////////
  // instance variables

  /**
   * Comma separated list of applications to install. The default value is the
   * kernel application.
   */
  @MojoParameter(defaultValue = "efaps")
  private String applications;

  /////////////////////////////////////////////////////////////////////////////
  // instance methods

  /**
   * Executes the kernel install goal.
   *
   * @throws MojoExecutionException if a defined application could not be found
   *                                or the installation scripts could not be
   *                                executed
   * @todo description
   */
  public void execute() throws MojoExecutionException  {
    init();
    try  {
      final ClassLoader cl = getClass().getClassLoader();

      // get install application (read from all install xml files)
      final Map<String, Application> appls = new HashMap<String, Application>();
      Enumeration<URL> urlEnum = cl.getResources("META-INF/efaps/install.xml");
      while (urlEnum.hasMoreElements())  {
        final Application appl = Application.getApplication(urlEnum.nextElement(),
                                                            getClasspathElements());
        appls.put(appl.getApplication(), appl);
      }

      // test if all defined applications could be found
      final String[] applicationNames = this.applications.split(",");
      for (final String applName : applicationNames)  {
        if (appls.get(applName) == null)  {
          throw new MojoExecutionException("Could not found defined "
              + "application '" + applName + "'. Installation not possible!");
        }
      }

      // install applications
      for (final String applName : applicationNames)  {
        final Application appl = appls.get(applName);
        appl.install(getUserName(), getPassWord());
        startTransaction();
        appl.importData();
        commitTransaction();
      }
    } catch (MojoExecutionException e)  {
      throw e;
    } catch (Exception e)  {
      throw new MojoExecutionException(
            "Could not execute Installation script", e);
    }
  }
}
{'fraction_non_alphanumeric': 0.14377646062658764, 'fraction_numerical': 0.004064352243861135, 'mean_word_length': 2.417824074074074, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6649572', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1508, 'n_words': 465}