use of io.atlasmap.java.inspect.ClassInspectionService in project atlasmap by atlasmap.
the class GenerateInspectionsMojo method generateInspection.
private void generateInspection(List<String> artifacts, Collection<String> classNames) throws MojoFailureException, MojoExecutionException {
List<URL> urls = artifacts == null ? Collections.emptyList() : resolveClasspath(artifacts);
ClassLoader origTccl = Thread.currentThread().getContextClassLoader();
for (String className : classNames) {
Class<?> clazz = null;
JavaClass c = null;
// Not even this plugin will be available on this new URLClassLoader
try (URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), origTccl)) {
clazz = loader.loadClass(className);
ClassInspectionService classInspectionService = new ClassInspectionService();
classInspectionService.setConversionService(DefaultAtlasConversionService.getInstance());
c = classInspectionService.inspectClass(loader, clazz);
} catch (ClassNotFoundException | IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
try {
ObjectMapper objectMapper = Json.mapper();
File target = outputFile;
if (target == null) {
target = new File(outputDir, "atlasmap-inpection-" + className + ".json");
}
objectMapper.writeValue(target, c);
getLog().info("Created: " + target);
} catch (JsonProcessingException e) {
throw new MojoExecutionException(e.getMessage(), e);
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
}
use of io.atlasmap.java.inspect.ClassInspectionService in project atlasmap by atlasmap.
the class JavaModuleTest method testGetSetJavaInspectionService.
@Test
public void testGetSetJavaInspectionService() {
ClassInspectionService cis = new ClassInspectionService();
assertNotNull(module);
assertNull(module.getJavaInspectionService());
module.setJavaInspectionService(cis);
assertNotNull(module.getJavaInspectionService());
assertSame(cis, module.getJavaInspectionService());
}
use of io.atlasmap.java.inspect.ClassInspectionService in project atlasmap by atlasmap.
the class JavaService method getClass.
// example from:
// https://www.mkyong.com/webservices/jax-rs/json-example-with-jersey-jackson/
@GET
@Path("/class")
@Produces(MediaType.APPLICATION_JSON)
public Response getClass(@QueryParam("className") String className) {
ClassInspectionService classInspectionService = new ClassInspectionService();
classInspectionService.setConversionService(DefaultAtlasConversionService.getInstance());
JavaClass c = classInspectionService.inspectClass(className);
classInspectionService = null;
return Response.ok().entity(toJson(c)).build();
}
use of io.atlasmap.java.inspect.ClassInspectionService in project syndesis by syndesisio.
the class GenerateConnectorInspectionsMojo method generateInspections.
// ****************************************
// Inspections
// ****************************************
@SuppressWarnings("PMD.CyclomaticComplexity")
private Optional<DataShape> generateInspections(Connector connector, Optional<DataShape> shape) throws IOException, DependencyResolutionRequiredException, ClassNotFoundException {
if (!shape.isPresent() || !connector.getId().isPresent()) {
return Optional.empty();
}
final DataShape given = shape.get();
DataShape ret = given;
if (DataShapeKinds.JAVA == given.getKind() && StringUtils.isNotEmpty(given.getType())) {
final String type = given.getType();
File outputFile = new File(inspectionsOutputDir, String.format("%s/%s/%s.json", inspectionsResourceDir, connector.getId().get(), type));
if (!outputFile.getParentFile().exists() && outputFile.getParentFile().mkdirs()) {
getLog().debug("Directory created:" + outputFile.getParentFile());
}
getLog().info("Generating for connector: " + connector.getId().get() + ", and type: " + type);
final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
final List<String> elements = project.getCompileClasspathElements();
final URL[] classpath = new URL[elements.size()];
for (int i = 0; i < elements.size(); i++) {
classpath[i] = new File(elements.get(i)).toURI().toURL();
getLog().debug("Add element to classpath: " + classpath[i]);
}
try (URLClassLoader loader = new URLClassLoader(classpath, tccl)) {
ClassInspectionService classInspectionService = new ClassInspectionService();
classInspectionService.setConversionService(DefaultAtlasConversionService.getInstance());
final Class<?> clazz = loader.loadClass(type);
final JavaClass c = classInspectionService.inspectClass(loader, clazz);
final ObjectMapper mapper = io.atlasmap.v2.Json.mapper();
if (inspectionMode == InspectionMode.SPECIFICATION || inspectionMode == InspectionMode.RESOURCE_AND_SPECIFICATION) {
getLog().info("Specification for type: " + type + " created");
ret = new DataShape.Builder().createFrom(given).specification(mapper.writeValueAsString(c)).build();
}
if (inspectionMode == InspectionMode.RESOURCE || inspectionMode == InspectionMode.RESOURCE_AND_SPECIFICATION) {
mapper.writeValue(outputFile, c);
getLog().info("Created: " + outputFile);
}
}
}
return Optional.of(ret);
}
use of io.atlasmap.java.inspect.ClassInspectionService in project atlasmap by atlasmap.
the class GenerateInspectionsMojo method generateJavaInspection.
private void generateJavaInspection(List<String> artifacts, Collection<String> classNames, CollectionType collectionType, String collectionClassName) throws MojoFailureException, MojoExecutionException {
List<URL> urls = artifacts == null ? Collections.emptyList() : resolveClasspath(artifacts);
ClassLoader origTccl = Thread.currentThread().getContextClassLoader();
for (String className : classNames) {
Class<?> clazz = null;
JavaClass c = null;
// Not even this plugin will be available on this new URLClassLoader
try (URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()]), origTccl)) {
clazz = loader.loadClass(className);
ClassInspectionService classInspectionService = new ClassInspectionService();
classInspectionService.setConversionService(DefaultAtlasConversionService.getInstance());
c = classInspectionService.inspectClass(loader, clazz, collectionType, collectionClassName);
} catch (ClassNotFoundException | IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
writeToJsonFile(DEFAULT_OUTPUT_FILE_PREFIX + "-" + className, c);
}
}
Aggregations