All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.redhat.ceylon.maven.AbstractCeylonCompileMojo Maven / Gradle / Ivy

There is a newer version: 1.3.3
Show newest version
package com.redhat.ceylon.maven;

import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.shared.model.fileset.FileSet;
import org.apache.maven.shared.model.fileset.util.FileSetManager;

import com.redhat.ceylon.common.Backend;
import com.redhat.ceylon.common.tools.ModuleWildcardsHelper;

/**
 * @author Julien Viet
 */
public abstract class AbstractCeylonCompileMojo extends AbstractCeylonMojo {

  @Parameter(defaultValue = "${project.build.directory}/modules")
  protected String out;

  @Parameter()
  protected List sources;

  @Parameter()
  protected List resources;

  @Parameter
  protected String[] userRepos;

  public void execute() throws MojoExecutionException, MojoFailureException {
	  ArrayList files = new ArrayList<>();
	  ArrayList sourcePaths = new ArrayList<>();
	  ArrayList resourcePaths = new ArrayList<>();
	  List modules = new ArrayList<>();
	  if (this.sources != null) {
		  FileSetManager fileSetManager = new FileSetManager();
		  for (FileSet source : this.sources) {
			  File sourcePath = new File(source.getDirectory());
			  Set excluded = new HashSet<>();
			  for (String excludedFile : fileSetManager.getExcludedFiles(source)) {
				  excluded.add(new File(sourcePath, excludedFile));
			  }
			  for (String includedFile : fileSetManager.getIncludedFiles(source)) {
				  File included = new File(sourcePath, includedFile);
				  if (!excluded.contains(included)) {
					  files.add(included);
				  }
			  }
			  sourcePaths.add(new File(source.getDirectory()));
		  }
	  } else {
		  File sourcePath = new File(cwd, "src/"+getPhase()+"/ceylon");
		  if (sourcePath.exists() && sourcePath.isDirectory()) {
			  sourcePaths.add(sourcePath);
		  }
		  ModuleWildcardsHelper.expandWildcard(modules, sourcePaths, "*", getBackend());
	  }
	  if (this.resources != null) {
		  FileSetManager fileSetManager = new FileSetManager();
		  for (FileSet resource : this.resources) {
			  File resourcePath = new File(resource.getDirectory());
			  Set excluded = new HashSet<>();
			  for (String excludedFile : fileSetManager.getExcludedFiles(resource)) {
				  excluded.add(new File(resourcePath, excludedFile));
			  }
			  for (String includedFile : fileSetManager.getIncludedFiles(resource)) {
				  File included = new File(resourcePath, includedFile);
				  if (!excluded.contains(included)) {
					  files.add(included);
				  }
			  }
			  resourcePaths.add(new File(resource.getDirectory()));
		  }
	  } else {
		  File resourcePath = new File(cwd, "src/"+getPhase()+"/resources");
		  if (resourcePath.exists() && resourcePath.isDirectory()) {
			  resourcePaths.add(resourcePath);
		  }
	  }
	  if (sourcePaths.size() > 0 && (files.size() > 0 || modules.size() > 0)) {
		  compile(sourcePaths, resourcePaths, files, modules);
	  }
  }

  protected abstract Backend getBackend();

  protected String getPhase() {
	return "main";
  }

  protected abstract void compile(List sourcePath, List resourcePath, List files, List modules) 
		  throws MojoExecutionException, MojoFailureException;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy