private void compileProtos() throws MojoExecutionException { List<String> args = Lists.newArrayList(); args.add("--proto_path=" + protoSourceDirectory); args.add("--java_out=" + generatedSourceDirectory); if (noOptions) { args.add("--no_options"); } if (enumOptions != null && enumOptions.length > 0) { args.add("--enum_options=" + Joiner.on(',').join(enumOptions)); } if (registryClass != null) { args.add("--registry_class=" + registryClass); } if (roots != null && roots.length > 0) { args.add("--roots=" + Joiner.on(',').join(roots)); } Collections.addAll(args, protoFiles); getLog().info("Invoking wire compiler with arguments:"); getLog().info(Joiner.on('\n').join(args)); try { // TODO(shawn) we don't have a great programatic interface to the compiler. // Not all exceptions should result in MojoFailureExceptions (i.e. bugs in this plugin that // invoke the compiler incorrectly). WireCompiler.main(args.toArray(new String[args.size()])); // Add the directory into which generated sources are placed as a compiled source root. project.addCompileSourceRoot(generatedSourceDirectory); } catch (Exception e) { throw new MojoExecutionException("Wire Plugin: Failure compiling proto sources.", e); } }
@Override public void execute() throws MojoExecutionException, MojoFailureException { final JsonReaderFactory readerFactory = Json.createReaderFactory(Collections.<String, Object>emptyMap()); if (source.isFile()) { generateFile(readerFactory, source); } else { final File[] children = source.listFiles( new FilenameFilter() { @Override public boolean accept(final File dir, final String name) { return name.endsWith(".json"); } }); if (children == null || children.length == 0) { throw new MojoExecutionException("No json file found in " + source); } for (final File child : children) { generateFile(readerFactory, child); } } if (attach && project != null) { project.addCompileSourceRoot(target.getAbsolutePath()); } }
@Override public void execute() throws MojoExecutionException, MojoFailureException { project.addCompileSourceRoot(generatedSourceDirectory); // TODO(shawn) only compile when things have changed. compileProtos(); }
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); }
@Override public void execute() throws MojoExecutionException { try { JavaProjectBuilder builder = new JavaProjectBuilder(); builder.addSourceTree(new File(srcDirectory, "src/main/java")); ObjectNode root = initializeRoot(); ArrayNode tags = mapper.createArrayNode(); ObjectNode paths = mapper.createObjectNode(); root.set("tags", tags); root.set("paths", paths); builder.getClasses().forEach(jc -> processClass(jc, paths, tags)); if (paths.size() > 0) { getLog().info("Generating ONOS REST API documentation..."); genCatalog(root); if (!isNullOrEmpty(apiPackage)) { genRegistrator(); } } project.addCompileSourceRoot(new File(dstDirectory, GEN_SRC).getPath()); } catch (Exception e) { getLog().warn("Unable to generate ONOS REST API documentation", e); throw e; } }
/** * Generate java parsers from lexer definition files. * * <p>This methods is checks parameters, sets options and calls JFlex.Main.generate() */ public void execute() throws MojoExecutionException, MojoFailureException { this.outputDirectory = getAbsolutePath(this.outputDirectory); // compiling the generated source in target/generated-sources/ is // the whole point of this plugin compared to running the ant plugin project.addCompileSourceRoot(outputDirectory.getPath()); List<File> filesIt; if (lexDefinitions == null) { // use default lexfiles if none provided getLog().debug("Use lexer files found in (default) " + SRC_MAIN_JFLEX); filesIt = new ArrayList<File>(); File defaultDir = getAbsolutePath(new File(SRC_MAIN_JFLEX)); if (defaultDir.isDirectory()) { filesIt.add(defaultDir); } } else { // use arguments provided in the plugin configuration filesIt = Arrays.asList(lexDefinitions); getLog() .debug( "Parsing " + lexDefinitions.length + " jflex files or directories given in configuration"); } // process all lexDefinitions for (File lexDefinition : filesIt) { lexDefinition = getAbsolutePath(lexDefinition); parseLexDefinition(lexDefinition); } }
public void execute() { try { generate(); project.addCompileSourceRoot(outputDirectory.getAbsolutePath()); } catch (Exception e) { getLog().error("General error", e); } }
@Override public void execute() throws MojoExecutionException { try { Configuration configuration = new Configuration(); configuration.setJdbc(jdbc); configuration.setGenerator(generator); StringWriter writer = new StringWriter(); JAXB.marshal(configuration, writer); getLog().info("Using this configuration:\n" + writer.toString()); GenerationTool.main(configuration); } catch (Exception ex) { throw new MojoExecutionException("Error running jOOQ code generation tool", ex); } project.addCompileSourceRoot(generator.getTarget().getDirectory()); }
public void execute() throws MojoExecutionException, MojoFailureException { String pkg = project.getPackaging(); if (pkg != null && pkg.equals("pom")) return; // skip POM modules Generator g = new Generator( outputDirectory, new Reporter() { public void debug(String msg) { getLog().debug(msg); } }); for (Resource res : (List<Resource>) project.getResources()) { File baseDir = new File(res.getDirectory()); if (!baseDir.exists()) continue; // this happens for example when POM inherits the default resource folder but no // such folder exists. FileSet fs = new FileSet(); fs.setDir(baseDir); for (String name : (List<String>) res.getIncludes()) fs.createInclude().setName(name); for (String name : (List<String>) res.getExcludes()) fs.createExclude().setName(name); for (String relPath : fs.getDirectoryScanner(new Project()).getIncludedFiles()) { File f = new File(baseDir, relPath); if (!f.getName().endsWith(".properties") || f.getName().contains("_")) continue; if (fileMask != null && !f.getName().equals(fileMask)) continue; try { g.generate(f, relPath); } catch (IOException e) { throw new MojoExecutionException("Failed to generate a class from " + f, e); } } } try { g.build(); } catch (IOException e) { throw new MojoExecutionException("Failed to generate source files", e); } project.addCompileSourceRoot(outputDirectory.getAbsolutePath()); }
@Override public void execute() throws MojoExecutionException { try { project.addCompileSourceRoot(outputDir.getAbsolutePath()); File output = new File(outputDir, outputName); if (output.exists() && project.getFile().lastModified() < output.lastModified()) { getLog().info("No changes detected, skipping: " + output); return; } if (Strings.isNullOrEmpty(javadoc)) getLog().warn("Javadocs not attached for paranamer."); else paranamer = new CachingParanamer(new JavadocParanamer(getFile(javadoc))); File jar = getFile(input); JarMethodScanner scanner = new JarMethodScanner(jar); List<Method> methods = Lists.newArrayList( Iterables.filter( scanner.getStaticMethods(scan), new Predicate<Method>() { @Override public boolean apply(Method input) { return exclude == null || !input.getName().matches(exclude); } })); String generated = generate(methods); output.getParentFile().mkdirs(); getLog().info("Generating " + output.getAbsoluteFile()); Files.write(generated, output, Charsets.UTF_8); } catch (Exception e) { throw new MojoExecutionException("java generation", e); } }
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); } } } }
@Override public void execute() throws MojoExecutionException, MojoFailureException { if (StringUtils.isBlank(packageName)) { throw new MojoFailureException("Package not specified"); } if (packageName.contains("..") || packageName.endsWith(".")) { throw new MojoFailureException("Invalid package specified"); } ourLog.info("Beginning HAPI-FHIR Tinder Code Generation..."); ourLog.info(" * Output Package: " + packageName); File resDirectoryBase = new File(new File(targetResourceDirectory), packageName.replace('.', File.separatorChar)); resDirectoryBase.mkdirs(); ourLog.info(" * Output Resource Directory: " + resDirectoryBase.getAbsolutePath()); File directoryBase = new File(new File(targetDirectory), packageName.replace('.', File.separatorChar)); directoryBase.mkdirs(); ourLog.info(" * Output Source Directory: " + directoryBase.getAbsolutePath()); ValueSetGenerator vsp = new ValueSetGenerator(version); vsp.setResourceValueSetFiles(resourceValueSetFiles); try { vsp.parse(); } catch (Exception e) { throw new MojoFailureException("Failed to load valuesets", e); } /* * A few enums are not found by default because none of the generated classes * refer to them, but we still want them. */ vsp.getClassForValueSetIdAndMarkAsNeeded("NarrativeStatus"); ourLog.info("Loading Datatypes..."); Map<String, String> datatypeLocalImports = new HashMap<String, String>(); DatatypeGeneratorUsingSpreadsheet dtp = new DatatypeGeneratorUsingSpreadsheet(version, baseDir); if (buildDatatypes) { try { dtp.parse(); dtp.markResourcesForImports(); } catch (Exception e) { throw new MojoFailureException("Failed to load datatypes", e); } dtp.bindValueSets(vsp); datatypeLocalImports = dtp.getLocalImports(); } ResourceGeneratorUsingSpreadsheet rp = new ResourceGeneratorUsingSpreadsheet(version, baseDir); if (baseResourceNames != null && baseResourceNames.size() > 0) { ourLog.info("Loading Resources..."); try { rp.setBaseResourceNames(baseResourceNames); rp.parse(); rp.markResourcesForImports(); } catch (Exception e) { throw new MojoFailureException("Failed to load resources", e); } rp.bindValueSets(vsp); rp.getLocalImports().putAll(datatypeLocalImports); datatypeLocalImports.putAll(rp.getLocalImports()); File resSubDirectoryBase = new File(directoryBase, "resource"); ourLog.info("Writing Resources to directory: {}", resSubDirectoryBase.getAbsolutePath()); rp.combineContentMaps(dtp); rp.writeAll(resSubDirectoryBase, resDirectoryBase, packageName); } ProfileParser pp = new ProfileParser(version, baseDir); if (resourceProfileFiles != null) { ourLog.info("Loading profiles..."); for (ProfileFileDefinition next : resourceProfileFiles) { ourLog.info("Parsing file: {}", next.profileFile); pp.parseSingleProfile(new File(next.profileFile), next.profileSourceUrl); } pp.bindValueSets(vsp); pp.markResourcesForImports(); pp.getLocalImports().putAll(datatypeLocalImports); datatypeLocalImports.putAll(pp.getLocalImports()); pp.combineContentMaps(rp); pp.combineContentMaps(dtp); pp.writeAll(new File(directoryBase, "resource"), resDirectoryBase, packageName); } if (dtp != null) { ourLog.info("Writing Composite Datatypes..."); dtp.combineContentMaps(pp); dtp.combineContentMaps(rp); dtp.writeAll(new File(directoryBase, "composite"), resDirectoryBase, packageName); } ourLog.info("Writing ValueSet Enums..."); vsp.writeMarkedValueSets(new File(directoryBase, "valueset"), packageName); myProject.addCompileSourceRoot(targetDirectory); }