Search in sources :

Example 1 with ExmlConfiguration

use of net.jangaroo.exml.config.ExmlConfiguration in project jangaroo-tools by CoreMedia.

the class MxmlLibraryManifestGeneratorTest method testCreateManifestFile.

@Test
public void testCreateManifestFile() throws Exception {
    ExmlConfiguration exmlConfiguration = mock(ExmlConfiguration.class);
    when(exmlConfiguration.getSourcePath()).thenReturn(Collections.singletonList(temporaryFolder.newFolder("out")));
    ConfigClass configClass1 = mock(ConfigClass.class);
    when(configClass1.getFullName()).thenReturn("foo");
    when(configClass1.getType()).thenReturn(ConfigClassType.CLASS);
    when(configClass1.getComponentClassName()).thenReturn("Foo");
    ConfigClass configClass2 = mock(ConfigClass.class);
    when(configClass2.getFullName()).thenReturn("bar");
    when(configClass2.getType()).thenReturn(ConfigClassType.CLASS);
    when(configClass2.getComponentClassName()).thenReturn("Bar");
    ConfigClass configClass3 = mock(ConfigClass.class);
    when(configClass3.getFullName()).thenReturn("comp");
    when(configClass3.getType()).thenReturn(ConfigClassType.COMPONENT);
    when(configClass3.getComponentClassName()).thenReturn("Comp");
    ConfigClassRegistry configClassRegistry = mock(ConfigClassRegistry.class);
    when(configClassRegistry.getConfig()).thenReturn(exmlConfiguration);
    when(configClassRegistry.getSourceConfigClasses()).thenReturn(asList(configClass1, configClass2, configClass3));
    File manifest = new MxmlLibraryManifestGenerator(configClassRegistry).createManifestFile();
    assertEquals(IOUtils.toString(getClass().getResourceAsStream("/expected/manifest.xml")), readFileToString(manifest));
}
Also used : ConfigClass(net.jangaroo.exml.model.ConfigClass) ConfigClassRegistry(net.jangaroo.exml.model.ConfigClassRegistry) ExmlConfiguration(net.jangaroo.exml.config.ExmlConfiguration) File(java.io.File) Test(org.junit.Test)

Example 2 with ExmlConfiguration

use of net.jangaroo.exml.config.ExmlConfiguration in project jangaroo-tools by CoreMedia.

the class AbstractExmlTest method setUp.

protected void setUp(String configClassPackage, String sourcePathFileName, String classPathFileName) throws Exception {
    File sourcePathFile = new File(getClass().getResource(sourcePathFileName).toURI());
    File classPathFile = new File(getClass().getResource(classPathFileName).toURI());
    ExmlConfiguration config = new ExmlConfiguration();
    config.setSourcePath(Arrays.asList(sourcePathFile));
    config.setClassPath(Arrays.asList(classPathFile));
    config.setOutputDirectory(outputFolder.getRoot());
    config.setConfigClassPackage(configClassPackage);
    exmlc = new Exmlc(config);
}
Also used : Exmlc(net.jangaroo.exml.compiler.Exmlc) ExmlConfiguration(net.jangaroo.exml.config.ExmlConfiguration) File(java.io.File)

Example 3 with ExmlConfiguration

use of net.jangaroo.exml.config.ExmlConfiguration in project jangaroo-tools by CoreMedia.

the class Exmlc method run.

public static int run(String[] argv) {
    ExmlcCommandLineParser parser = new ExmlcCommandLineParser();
    ExmlConfiguration exmlConfiguration;
    try {
        exmlConfiguration = parser.parse(argv);
    } catch (CommandLineParseException e) {
        // NOSONAR this is a commandline tool
        System.err.println(e.getMessage());
        return e.getExitCode();
    }
    if (exmlConfiguration != null) {
        Exmlc exmlc = new Exmlc(exmlConfiguration);
        if (exmlConfiguration.isConvertToMxml()) {
            exmlc.convertAllExmlToMxml();
        } else {
            exmlc.generateAllConfigClasses();
            exmlc.generateAllComponentClasses();
            exmlc.generateXsd();
        }
    }
    return 0;
}
Also used : ExmlcCommandLineParser(net.jangaroo.exml.cli.ExmlcCommandLineParser) CommandLineParseException(net.jangaroo.jooc.cli.CommandLineParseException) ExmlConfiguration(net.jangaroo.exml.config.ExmlConfiguration)

Example 4 with ExmlConfiguration

use of net.jangaroo.exml.config.ExmlConfiguration in project jangaroo-tools by CoreMedia.

the class ExmlValidatorTest method testValidateExmlFile.

@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Test
public void testValidateExmlFile() throws Exception {
    setUp("testNamespace.config");
    ExmlConfiguration exmlConfiguration = getExmlc().getConfig();
    File testExmlFile = getFile("/exmlparser/TestValidation.exml");
    exmlConfiguration.setSourceFiles(Collections.singletonList(testExmlFile));
    exmlConfiguration.setResourceOutputDirectory(getFile("/"));
    exmlConfiguration.setValidationMode(ValidationMode.ERROR);
    final Map<FilePosition, String> validationErrors = new LinkedHashMap<FilePosition, String>();
    exmlConfiguration.setLog(new CompileLog() {

        @Override
        public void error(FilePosition position, String msg) {
            System.out.printf("%s(%d): %s%n", position.getFileName(), position.getLine(), msg);
            validationErrors.put(position, msg);
        }

        @Override
        public void error(String msg) {
            Assert.fail("should never be called");
        }

        @Override
        public void warning(FilePosition position, String msg) {
            Assert.fail("should never be called");
        }

        @Override
        public void warning(String msg) {
            Assert.fail("should never be called");
        }

        @Override
        public boolean hasErrors() {
            return !validationErrors.isEmpty();
        }
    });
    new ExmlValidator(exmlConfiguration).validateExmlFile(testExmlFile);
    String testExmlFilename = testExmlFile.getAbsolutePath();
    Assert.assertEquals(4, validationErrors.size());
    Iterator<Map.Entry<FilePosition, String>> validationErrorIterator = validationErrors.entrySet().iterator();
    // "cvc-datatype-valid.1.2.3: 'wrongType' is not a valid value of union type 'Number'."
    assertValidationErrorEquals(testExmlFilename, 4, new String[] { "cvc-datatype-valid.1.2.3:", "wrongType", "Number" }, validationErrorIterator.next());
    // "cvc-attribute.3: The value 'wrongType' of attribute 'x' on element 'panel' is not valid with respect to its type, 'Number'."
    assertValidationErrorEquals(testExmlFilename, 4, new String[] { "cvc-attribute.3:", "wrongType", "x", "panel", "Number" }, validationErrorIterator.next());
    // "cvc-complex-type.3.2.2: Attribute 'wrongAttribute' is not allowed to appear in element 'panel'."
    assertValidationErrorEquals(testExmlFilename, 4, new String[] { "cvc-complex-type.3.2.2:", "wrongAttribute", "panel" }, validationErrorIterator.next());
    // "cvc-complex-type.3.2.2: Attribute 'anotherWrongAttribute' is not allowed to appear in element 'baseAction'."
    assertValidationErrorEquals(testExmlFilename, 5, new String[] { "cvc-complex-type.3.2.2:", "anotherWrongAttribute", "baseAction" }, validationErrorIterator.next());
}
Also used : ExmlConfiguration(net.jangaroo.exml.config.ExmlConfiguration) FilePosition(net.jangaroo.jooc.api.FilePosition) File(java.io.File) CompileLog(net.jangaroo.jooc.api.CompileLog) ExmlValidator(net.jangaroo.exml.parser.ExmlValidator) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 5 with ExmlConfiguration

use of net.jangaroo.exml.config.ExmlConfiguration in project jangaroo-tools by CoreMedia.

the class AbstractExmlCompileMojo method execute.

public void execute() throws MojoExecutionException, MojoFailureException {
    File gSourcesDirectory = getGeneratedSourcesDirectory();
    if (!gSourcesDirectory.exists()) {
        getLog().info("generating sources into: " + gSourcesDirectory.getPath());
        getLog().debug("created " + gSourcesDirectory.mkdirs());
    }
    if (!generatedResourcesDirectory.exists()) {
        getLog().info("generating resources into: " + generatedResourcesDirectory.getPath());
        getLog().debug("created " + generatedResourcesDirectory.mkdirs());
    }
    List<File> sourcePath = getSourcePath();
    ExmlConfiguration exmlConfiguration = createExmlConfiguration(getActionScriptClassPath(), sourcePath, gSourcesDirectory);
    exmlConfiguration.setResourceOutputDirectory(generatedResourcesDirectory);
    exmlConfiguration.setSourceFiles(getMavenPluginHelper().computeStaleSources(sourcePath, includes, excludes, gSourcesDirectory, Exmlc.EXML_SUFFIX, Jooc.AS_SUFFIX, staleMillis));
    if (StringUtils.isNotEmpty(validationMode)) {
        try {
            exmlConfiguration.setValidationMode(ValidationMode.valueOf(validationMode.toUpperCase()));
        } catch (IllegalArgumentException e) {
            throw new MojoFailureException("The specified EXML validation mode '" + validationMode + "' is unsupported. " + "Legal values are 'error', 'warn', and 'off'.");
        }
    }
    CompileLog compileLog = new MavenCompileLog();
    exmlConfiguration.setLog(compileLog);
    Exmlc exmlc;
    try {
        getLog().debug("Exmlc configuration: " + exmlConfiguration);
        exmlc = new Exmlc(exmlConfiguration);
        executeExmlc(exmlc);
    } catch (ExmlcException e) {
        throw new MojoFailureException(e.toString(), e);
    }
    if (compileLog.hasErrors()) {
        throw new MojoFailureException("There were EXML compiler errors, see log for details.");
    }
    getProject().addCompileSourceRoot(gSourcesDirectory.getPath());
}
Also used : Exmlc(net.jangaroo.exml.compiler.Exmlc) ExmlcException(net.jangaroo.exml.api.ExmlcException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ExmlConfiguration(net.jangaroo.exml.config.ExmlConfiguration) File(java.io.File) CompileLog(net.jangaroo.jooc.api.CompileLog)

Aggregations

ExmlConfiguration (net.jangaroo.exml.config.ExmlConfiguration)8 File (java.io.File)4 Exmlc (net.jangaroo.exml.compiler.Exmlc)3 IOException (java.io.IOException)2 CompileLog (net.jangaroo.jooc.api.CompileLog)2 CommandLineParseException (net.jangaroo.jooc.cli.CommandLineParseException)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 Test (org.junit.Test)2 LinkedHashMap (java.util.LinkedHashMap)1 ExmlcException (net.jangaroo.exml.api.ExmlcException)1 ExmlcCommandLineParser (net.jangaroo.exml.cli.ExmlcCommandLineParser)1 ConfigClass (net.jangaroo.exml.model.ConfigClass)1 ConfigClassRegistry (net.jangaroo.exml.model.ConfigClassRegistry)1 ExmlValidator (net.jangaroo.exml.parser.ExmlValidator)1 FilePosition (net.jangaroo.jooc.api.FilePosition)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 CmdLineException (org.kohsuke.args4j.CmdLineException)1 CmdLineParser (org.kohsuke.args4j.CmdLineParser)1