Search in sources :

Example 1 with PomConverter

use of net.jangaroo.exml.mojo.pom.PomConverter in project jangaroo-tools by CoreMedia.

the class ExmlToMxmlMojo method execute.

@Override
public void execute() throws MojoExecutionException {
    boolean useNewPackagingType = extAsVersion != null && new DefaultArtifactVersion(extAsVersion).compareTo(EXT_AS_FIRST_SWC_ARTIFACT_VERSION) >= 0;
    if (!renameOnly && (hasExmlConfiguration() || "jangaroo".equals(getProject().getPackaging()))) {
        getLog().info("reading POM from " + getProject().getBasedir().getPath());
        PomConverter pomConverter = new PomConverter(getProject().getBasedir());
        getLog().info("removing exml-maven-plugin from POM");
        pomConverter.removeExmlPlugin();
        String newPackaging = useNewPackagingType ? "swc" : "jangaroo-pkg";
        getLog().info("changing packaging from 'jangaroo' to '" + newPackaging + "'");
        pomConverter.changePackaging(newPackaging);
        if (useNewPackagingType) {
            getLog().info("adding dependency type 'swc' to all compile dependencies");
            pomConverter.addDependencyType(newPackaging);
        }
        getLog().info("updating POM at " + getProject().getBasedir().getPath());
        pomConverter.writePom();
    }
    if (!isExmlProject()) {
        getLog().info("not an EXML project, skipping MXML conversion");
        return;
    }
    if (renameOnly) {
        getLog().info("Renaming EXML files to MXML files");
        try {
            renameFiles(getSourceDirectory(), "exml", "mxml");
            renameFiles(getTestSourceDirectory(), "exml", "mxml");
        } catch (IOException e) {
            throw new MojoExecutionException("error while renaming EXML files", e);
        }
        return;
    }
    if (alreadyRenamed) {
        getLog().info("Renaming MXML files back to EXML files before running the conversion");
        try {
            renameFiles(getSourceDirectory(), "mxml", "exml");
            renameFiles(getTestSourceDirectory(), "mxml", "exml");
        } catch (IOException e) {
            throw new MojoExecutionException("error while renaming files", e);
        }
    }
    if (extAsVersion == null) {
        throw new MojoExecutionException("exml-to-mxml needs an extAsVersion.");
    }
    Artifact extAsArtifact = resolveExtAsArtifact(extAsVersion, useNewPackagingType ? "swc" : "jar");
    File extAsJar = extAsArtifact.getFile();
    // Convert main EXML sources to MXML:
    ExmlConfiguration config = createExmlConfiguration(getActionScriptClassPath(), Collections.singletonList(getSourceDirectory()), getGeneratedSourcesDirectory());
    config.setExtAsJar(extAsJar);
    new Exmlc(config).convertAllExmlToMxml();
    // Also convert test EXML sources to MXML:
    if (getTestSourceDirectory() != null && getTestSourceDirectory().exists()) {
        ExmlConfiguration testConfig = createExmlConfiguration(getActionScriptTestClassPath(), Collections.singletonList(getTestSourceDirectory()), getGeneratedTestSourcesDirectory());
        testConfig.setExtAsJar(extAsJar);
        new Exmlc(testConfig).convertAllExmlToMxml();
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Exmlc(net.jangaroo.exml.compiler.Exmlc) DefaultArtifactVersion(org.apache.maven.artifact.versioning.DefaultArtifactVersion) IOException(java.io.IOException) ExmlConfiguration(net.jangaroo.exml.config.ExmlConfiguration) FileUtils.moveFile(org.apache.commons.io.FileUtils.moveFile) File(java.io.File) PomConverter(net.jangaroo.exml.mojo.pom.PomConverter) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 Exmlc (net.jangaroo.exml.compiler.Exmlc)1 ExmlConfiguration (net.jangaroo.exml.config.ExmlConfiguration)1 PomConverter (net.jangaroo.exml.mojo.pom.PomConverter)1 FileUtils.moveFile (org.apache.commons.io.FileUtils.moveFile)1 Artifact (org.apache.maven.artifact.Artifact)1 DefaultArtifactVersion (org.apache.maven.artifact.versioning.DefaultArtifactVersion)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1