protected void setUp() throws Exception { // prepare plexus environment super.setUp(); ajcMojo.project = project; String temp = new File(".").getAbsolutePath(); basedir = temp.substring(0, temp.length() - 2) + "/src/test/projects/" + getProjectName() + "/"; project.getBuild().setDirectory(basedir + "/target"); project.getBuild().setOutputDirectory(basedir + "/target/classes"); project.getBuild().setTestOutputDirectory(basedir + "/target/test-classes"); project.getBuild().setSourceDirectory(basedir + "/src/main/java"); project.getBuild().setTestSourceDirectory(basedir + "/src/test/java"); project.addCompileSourceRoot(project.getBuild().getSourceDirectory()); project.addTestCompileSourceRoot(project.getBuild().getTestSourceDirectory()); ajcMojo.basedir = new File(basedir); setVariableValueToObject( ajcMojo, "outputDirectory", new File(project.getBuild().getOutputDirectory())); ArtifactHandler artifactHandler = new MockArtifactHandler(); Artifact artifact = new MockArtifact("dill", "dall"); artifact.setArtifactHandler(artifactHandler); project.setArtifact(artifact); project.setDependencyArtifacts(Collections.EMPTY_SET); }
public void execute() throws MojoExecutionException { if (executeAll(velocitySources, outputDirectory)) { // File jf = new File(outputDirectory, "java"); // if (jf.exists()) // outputDirectory = jf; project.addCompileSourceRoot(outputDirectory.toString()); } if (executeAll(velocityTestSources, testOutputDirectory)) { // File jf = new File(testOutputDirectory, "java"); // if (jf.exists()) // testOutputDirectory = jf; project.addTestCompileSourceRoot(testOutputDirectory.toString()); } /*if (templates == null) getLog().error("Did not find <templates> !"); else { getLog().info("Found " + templates.size() + " templates"); for (Template conf : templates) conf.execute(this); }*/ }
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (this.skip) { getLog().info("Skip flag is on, will skip goal."); return; } if (this.templateDirectory == null) { throw new MojoExecutionException("Property templateDirectory cannot be null/empty"); } if (this.outputDirectory == null) { throw new MojoExecutionException("Property outputDirectory cannot be null/empty"); } if (this.classDirectory == null) { throw new MojoExecutionException("Property classDirectory cannot be null/empty"); } /** * if (this.compileDirectory == null) { throw new MojoExecutionException("Property * compileDirectory cannot be null/empty"); } */ if (javaVersion == null || javaVersion.length() == 0) { // set to current jdk version javaVersion = System.getProperty("java.version").substring(0, 3); getLog() .info("Property rocker.javaVersion not set. Using your JDK version " + this.javaVersion); } else { getLog().info("Targeting java version " + this.javaVersion); } try { JavaGeneratorMain jgm = new JavaGeneratorMain(); jgm.getParser().getConfiguration().setTemplateDirectory(templateDirectory); jgm.getGenerator().getConfiguration().setOutputDirectory(outputDirectory); jgm.getGenerator().getConfiguration().setClassDirectory(classDirectory); // jgm.getGenerator().getConfiguration().setCompileDirectory(compileDirectory); jgm.setFailOnError(failOnError); // passthru other config if (suffixRegex != null) { jgm.setSuffixRegex(suffixRegex); } if (javaVersion != null) { jgm.getParser().getConfiguration().getOptions().setJavaVersion(javaVersion); } if (extendsClass != null) { jgm.getParser().getConfiguration().getOptions().setExtendsClass(extendsClass); } if (extendsModelClass != null) { jgm.getParser().getConfiguration().getOptions().setExtendsModelClass(extendsModelClass); } if (discardLogicWhitespace != null) { jgm.getParser() .getConfiguration() .getOptions() .setDiscardLogicWhitespace(discardLogicWhitespace); } if (targetCharset != null) { jgm.getParser().getConfiguration().getOptions().setTargetCharset(targetCharset); } if (optimize != null) { jgm.getParser().getConfiguration().getOptions().setOptimize(optimize); } jgm.run(); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } // after generating templates THEN its safe to add a new source root // directory since it may not have existed before and the adding of it // would have silently failed if (addAsTestSources) { getLog().info("Added test sources with " + this.outputDirectory); project.addTestCompileSourceRoot(this.outputDirectory.getAbsolutePath()); } else if (addAsSources) { getLog().info("Added sources with " + this.outputDirectory); project.addCompileSourceRoot(this.outputDirectory.getAbsolutePath()); } if (!skipTouch) { if (touchFile != null && touchFile.length() > 0) { File f = new File(touchFile); getLog().info("Touching file " + f); try { if (!f.exists()) { new FileOutputStream(f).close(); } f.setLastModified(System.currentTimeMillis()); } catch (IOException e) { getLog().debug("Unable to touch file", e); } } } }