OrmGenerationMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { try { fileSystemManager = VFS.getManager(); } catch (FileSystemException e) { throw new MojoExecutionException("Issue initializing VFS system to fetch ontologies!", e); } final List<ReferenceOntology> referenceOntologies = gatherReferenceOntologies(); for (final Ontology generate : generates) { try { final FileObject fileObject = fileSystemManager.resolveFile(generate.getOntologyFile()); if (fileObject.isFile()) { try { final Model ontology = readOntology(fileObject, generate.getOntologyFile()); FileUtils.deleteQuietly(new File(outputLocation + (outputLocation.endsWith(File.separator) ? "" : File.separator) + generate.getOutputPackage().replace('.', File.separatorChar))); SourceGenerator.toSource(ontology, generate.getOutputPackage(), generate.getOntologyName(), outputLocation, referenceOntologies); } catch (Exception e) { throw new MojoFailureException(String.format("Issue generating source from ontology specified: {%s} {%s} {%s}", generate.getOntologyFile(), generate.getOutputPackage(), outputLocation), e); } } else { String msg = "Issue generating source from ontology specified. No ontology found at specified location: " + generate.getOntologyFile(); throw new MojoExecutionException(msg); } } catch (IOException e) { throw new MojoExecutionException("Issue fetching configured ontology", e); } } }  @Override void execute();  }
@Test public void simpleTest() throws Exception { OrmGenerationMojo mojo = new OrmGenerationMojo(); Ontology ont = new Ontology(); File loc = new File("src/test/resources/foaf.rdf"); set("ontologyFile", loc.getAbsolutePath(), ont); set("outputPackage", "org.foaf", ont); set("outputLocation", "target/generated-test-sources", mojo); set("generates", Collections.singletonList(ont), mojo); mojo.execute(); }
@Test public void vfsSpecTest() throws Exception { OrmGenerationMojo mojo = new OrmGenerationMojo(); Ontology ont = new Ontology(); File loc = new File("src/test/resources/foaf.rdf"); set("ontologyFile", "file: set("outputPackage", "org.foaf", ont); set("outputLocation", "target/generated-test-sources", mojo); set("generates", Collections.singletonList(ont), mojo); mojo.execute(); }
@Test public void testFetchVfs() throws Exception { final String URL = "http: try { URL val = new URL(URL); System.out.println(IOUtils.toString(val.openStream())); OrmGenerationMojo mojo = new OrmGenerationMojo(); Ontology ont = new Ontology(); set("ontologyFile", val.toString(), ont); set("outputPackage", "org.foaf", ont); set("outputLocation", "target/generated-test-sources", mojo); set("generates", Collections.singletonList(ont), mojo); mojo.execute(); mojo.execute(); } catch (IOException e) { System.err.println("Can't seem to find rdf syntax ontology..."); } }