org.jboss.forge.addon.projects.facets.MetadataFacet Java Examples
The following examples show how to use
org.jboss.forge.addon.projects.facets.MetadataFacet.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FunktionProjectType.java From fabric8-forge with Apache License 2.0 | 5 votes |
@Override public Iterable<Class<? extends ProjectFacet>> getRequiredFacets() { List<Class<? extends ProjectFacet>> result = new ArrayList<Class<? extends ProjectFacet>>(7); result.add(MetadataFacet.class); result.add(PackagingFacet.class); result.add(DependencyFacet.class); result.add(ResourcesFacet.class); result.add(WebResourcesFacet.class); result.add(JavaSourceFacet.class); result.add(JavaCompilerFacet.class); return result; }
Example #2
Source File: FunktionArchetypeSelectionWizardStep.java From fabric8-forge with Apache License 2.0 | 5 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { UIContext uiContext = context.getUIContext(); Project project = (Project) uiContext.getAttributeMap().get(Project.class); Archetype chosenArchetype = archetype.getValue(); String coordinate = chosenArchetype.getGroupId() + ":" + chosenArchetype.getArtifactId() + ":" + chosenArchetype.getVersion(); DependencyQueryBuilder depQuery = DependencyQueryBuilder.create(coordinate); String repository = chosenArchetype.getRepository(); if (!Strings.isNullOrEmpty(repository)) { if (repository.endsWith(".xml")) { int lastRepositoryPath = repository.lastIndexOf('/'); if (lastRepositoryPath > -1) repository = repository.substring(0, lastRepositoryPath); } if (!repository.isEmpty()) { depQuery.setRepositories(new DependencyRepository("archetype", repository)); } } Dependency resolvedArtifact = dependencyResolver.resolveArtifact(depQuery); FileResource<?> artifact = resolvedArtifact.getArtifact(); MetadataFacet metadataFacet = project.getFacet(MetadataFacet.class); File fileRoot = project.getRoot().reify(DirectoryResource.class).getUnderlyingResourceObject(); ArchetypeHelper archetypeHelper = new ArchetypeHelper(artifact.getResourceInputStream(), fileRoot, metadataFacet.getProjectGroupName(), metadataFacet.getProjectName(), metadataFacet.getProjectVersion()); JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class); archetypeHelper.setPackageName(facet.getBasePackage()); archetypeHelper.execute(); return Results.success(); }
Example #3
Source File: SpringBootProjectType.java From fabric8-forge with Apache License 2.0 | 5 votes |
@Override public Iterable<Class<? extends ProjectFacet>> getRequiredFacets() { List<Class<? extends ProjectFacet>> result = new ArrayList<Class<? extends ProjectFacet>>(7); result.add(MetadataFacet.class); result.add(PackagingFacet.class); result.add(DependencyFacet.class); result.add(ResourcesFacet.class); result.add(WebResourcesFacet.class); result.add(JavaSourceFacet.class); result.add(JavaCompilerFacet.class); return result; }
Example #4
Source File: ThorntailProjectType.java From thorntail-addon with Eclipse Public License 1.0 | 5 votes |
/** * Same as JavaWebProjectType */ @Override public Iterable<Class<? extends ProjectFacet>> getRequiredFacets() { List<Class<? extends ProjectFacet>> result = new ArrayList<Class<? extends ProjectFacet>>(7); result.add(MetadataFacet.class); result.add(PackagingFacet.class); result.add(DependencyFacet.class); result.add(ResourcesFacet.class); result.add(WebResourcesFacet.class); result.add(JavaSourceFacet.class); result.add(JavaCompilerFacet.class); return result; }
Example #5
Source File: SpringBootNewProjectCommand.java From fabric8-forge with Apache License 2.0 | 4 votes |
@Override public Result execute(UIExecutionContext context) throws Exception { UIContext uiContext = context.getUIContext(); Project project = (Project) uiContext.getAttributeMap().get(Project.class); if (project == null) { project = getSelectedProject(context.getUIContext()); } MetadataFacet metadataFacet = project.getFacet(MetadataFacet.class); String projectName = metadataFacet.getProjectName(); String groupId = metadataFacet.getProjectGroupName(); String version = metadataFacet.getProjectVersion(); File folder = project.getRoot().reify(DirectoryResource.class).getUnderlyingResourceObject(); Map<String, SpringBootDependencyDTO> selectedDTOs = new HashMap<>(); int[] selected = dependencies.getSelectedIndexes(); CollectionStringBuffer csbSpringBoot = new CollectionStringBuffer(","); CollectionStringBuffer csbFabric8 = new CollectionStringBuffer(","); for (int val : selected) { SpringBootDependencyDTO dto = choices.get(val); if (isFabric8Dependency(dto.getId())) { csbFabric8.append(dto.getId()); } else { csbSpringBoot.append(dto.getId()); } selectedDTOs.put(dto.getId(), dto); } String springBootDeps = csbSpringBoot.toString(); String fabric8Deps = csbFabric8.toString(); // boot version need the RELEASE suffix String bootVersion = springBootVersion.getValue() + ".RELEASE"; String url = String.format("%s?bootVersion=%s&groupId=%s&artifactId=%s&version=%s&packageName=%s&dependencies=%s", STARTER_URL, bootVersion, groupId, projectName, version, groupId, springBootDeps); LOG.info("About to query url: " + url); // use http client to call start.spring.io that creates the project OkHttpClient client = createOkHttpClient(); Request request = new Request.Builder().url(url).build(); Response response = client.newCall(request).execute(); InputStream is = response.body().byteStream(); // some archetypes might not use maven or use the maven source layout so lets remove // the pom.xml and src folder if its already been pre-created // as these will be created if necessary via the archetype jar's contents File pom = new File(folder, "pom.xml"); if (pom.isFile() && pom.exists()) { pom.delete(); } File src = new File(folder, "src"); if (src.isDirectory() && src.exists()) { recursiveDelete(src); } File name = new File(folder, projectName + ".zip"); if (name.exists()) { name.delete(); } FileOutputStream fos = new FileOutputStream(name, false); copyAndCloseInput(is, fos); close(fos); // unzip the download from spring starter unzip(name, folder); LOG.info("Unzipped file to folder: {}", folder.getAbsolutePath()); // and delete the zip file name.delete(); if (!Strings.isEmpty(fabric8Deps)) { addFabric8DependenciesToPom(project, fabric8Deps, selectedDTOs); } // are there any fabric8 dependencies to add afterwards? return Results.success("Created new Spring Boot project in directory: " + folder.getName()); }
Example #6
Source File: AngularScaffoldProvider.java From angularjs-addon with Eclipse Public License 1.0 | 4 votes |
@Override public List<Resource<?>> generateFrom(ScaffoldGenerationContext generationContext) { setProject(generationContext.getProject()); String targetDir = generationContext.getTargetDirectory(); targetDir = (targetDir == null) ? "" : targetDir; List<Resource<?>> result = new ArrayList<>(); Collection<Resource<?>> resources = generationContext.getResources(); for (Resource<?> resource : resources) { JavaSource<?> javaSource = null; if (resource instanceof JavaResource) { JavaResource javaResource = (JavaResource) resource; try { javaSource = javaResource.getJavaType(); } catch (FileNotFoundException fileEx) { throw new IllegalStateException(fileEx); } } else { continue; } JavaClassSource entity = (JavaClassSource) javaSource; String resourceRootPath = getRootResourcePath(project); // Fetch the REST resource path from the existing JAX-RS resource if found. String entityResourcePath = parseResourcePath(entity); // If the path is not available, construct a default one from the JPA entity name // We'll let the user resolve the incorrect path later, // if needed through regeneration of the JAX-RS resources. String entityName = entity.getName(); if (entityResourcePath == null || entityResourcePath.isEmpty()) { entityResourcePath = inflector.pluralize(entityName.toLowerCase()); } entityResourcePath = trimSlashes(entityResourcePath); // Inspect the JPA entity and obtain a list of inspection results. Every inspected property is represented as a // Map<String,String> and all such inspection results are collated into a list. MetawidgetInspectorFacade metawidgetInspectorFacade = new MetawidgetInspectorFacade(project); InspectionResultProcessor angularResultEnhancer = new InspectionResultProcessor(project, metawidgetInspectorFacade); List<Map<String, String>> inspectionResults = metawidgetInspectorFacade.inspect(entity); String entityId = angularResultEnhancer.fetchEntityId(entity, inspectionResults); inspectionResults = angularResultEnhancer.enhanceResults(entity, inspectionResults); MetadataFacet metadata = project.getFacet(MetadataFacet.class); // TODO: Provide a 'utility' class for allowing transliteration across language naming schemes // We need this to use contextual naming schemes instead of performing toLowerCase etc. in FTLs. // Prepare the Freemarker data model Map<String, Object> dataModel = new HashMap<>(); dataModel.put("entityName", entityName); dataModel.put("pluralizedEntityName", inflector.pluralize(entityName)); dataModel.put("entityId", entityId); dataModel.put("properties", inspectionResults); dataModel.put("projectId", StringUtils.camelCase(metadata.getProjectName())); dataModel.put("projectTitle", StringUtils.uncamelCase(metadata.getProjectName())); dataModel.put("resourceRootPath", resourceRootPath); dataModel.put("resourcePath", entityResourcePath); dataModel.put("parentDirectories", getParentDirectories(targetDir)); // Process the Freemarker templates with the Freemarker data model and retrieve the generated resources from // the registry. WebResourcesFacet web = project.getFacet(WebResourcesFacet.class); ProcessingStrategy strategy = new ProcessTemplateStrategy(web, resourceFactory, project, templateFactory, dataModel); List<ScaffoldResource> scaffoldResources = getEntityTemplates(targetDir, entityName, strategy); scaffoldResources.add(new ScaffoldResource("/views/detail.html.ftl", targetDir + "/views/" + entityName + "/detail.html", new DetailTemplateStrategy(web, resourceFactory, project, templateFactory, dataModel))); scaffoldResources.add(new ScaffoldResource("/views/search.html.ftl", targetDir + "/views/" + entityName + "/search.html", new SearchTemplateStrategy(web, resourceFactory, project, templateFactory, dataModel))); for (ScaffoldResource scaffoldResource : scaffoldResources) { result.add(scaffoldResource.generate()); } } List<Resource<?>> indexResources = generateIndex(targetDir); result.addAll(indexResources); return result; }