本文整理汇总了Java中org.jboss.forge.addon.projects.Project.getFacet方法的典型用法代码示例。如果您正苦于以下问题:Java Project.getFacet方法的具体用法?Java Project.getFacet怎么用?Java Project.getFacet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.forge.addon.projects.Project
的用法示例。
在下文中一共展示了Project.getFacet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCRUDRepository
import org.jboss.forge.addon.projects.Project; //导入方法依赖的package包/类
private void createCRUDRepository(JavaClassSource entitySource, Project project) {
// build interface declaration
final String name = entitySource.getName();
final String idFieldType = entitySource.getFields().stream()
.filter(field -> field.hasAnnotation(Id.class))
.findFirst()
.orElseThrow(IllegalArgumentException::new)
.getType()
.getSimpleName();
final String repoInterfaceDeclaration = "public interface " + name
+ "Repository extends PagingAndSortingRepository<"
+ name + "," + idFieldType + "> {}";
JavaInterfaceSource repoSource = Roaster.parse(JavaInterfaceSource.class, repoInterfaceDeclaration)
.setPackage(entitySource.getPackage());
repoSource.addImport("org.springframework.data.repository.PagingAndSortingRepository");
Roaster.format(repoSource.toString());
// Create Java Classes Greeting and GreetingProperties
JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
facet.saveJavaSource(repoSource);
}
示例2: modifyJavaClass
import org.jboss.forge.addon.projects.Project; //导入方法依赖的package包/类
public static void modifyJavaClass(Project project, String className, Optional<String> packageName,
JavaClassSourceDecorator decorator) {
final String packageLocation = packageName.orElseGet(() -> project.getFacet(MetadataFacet.class).getProjectGroupName());
final JavaSourceFacet sourceFacet = project.getFacet(JavaSourceFacet.class);
final DirectoryResource targetPackage = sourceFacet.getPackage(packageLocation);
final JavaResource sbAppResource = targetPackage.getChild(className).as(JavaResource.class);
if (sbAppResource.exists()) {
JavaClassSource sbApp = Roaster.parse(JavaClassSource.class, sbAppResource.getResourceInputStream());
decorator.modify(sbApp);
sourceFacet.saveJavaSource(sbApp);
}
}
示例3: asRelativeFile
import org.jboss.forge.addon.projects.Project; //导入方法依赖的package包/类
protected String asRelativeFile(UIContext context, String currentFile) {
Project project = getSelectedProject(context);
JavaSourceFacet javaSourceFacet = null;
ResourcesFacet resourcesFacet = null;
WebResourcesFacet webResourcesFacet = null;
if (project.hasFacet(JavaSourceFacet.class)) {
javaSourceFacet = project.getFacet(JavaSourceFacet.class);
}
if (project.hasFacet(ResourcesFacet.class)) {
resourcesFacet = project.getFacet(ResourcesFacet.class);
}
if (project.hasFacet(WebResourcesFacet.class)) {
webResourcesFacet = project.getFacet(WebResourcesFacet.class);
}
return asRelativeFile(currentFile, javaSourceFacet, resourcesFacet, webResourcesFacet);
}
示例4: setupFabricMavenPlugin
import org.jboss.forge.addon.projects.Project; //导入方法依赖的package包/类
public static MavenPluginBuilder setupFabricMavenPlugin(Project project) {
MavenPluginBuilder pluginBuilder;
MavenPlugin plugin = MavenHelpers.findPlugin(project, "io.fabric8", "fabric8-maven-plugin");
if (plugin != null) {
// if there is an existing then leave it as-is
LOG.info("Found existing fabric8-maven-plugin");
pluginBuilder = null;
} else {
LOG.info("Adding fabric8-maven-plugin");
// add fabric8 plugin
pluginBuilder = MavenPluginBuilder.create()
.setCoordinate(MavenHelpers.createCoordinate("io.fabric8", "fabric8-maven-plugin", VersionHelper.fabric8MavenPluginVersion()))
.addExecution(ExecutionBuilder.create().setId("fmp").addGoal("resource").addGoal("helm").addGoal("build"));
}
if (pluginBuilder != null) {
MavenPluginFacet pluginFacet = project.getFacet(MavenPluginFacet.class);
pluginFacet.addPlugin(pluginBuilder);
}
return pluginBuilder;
}
示例5: isFunktionParentPom
import org.jboss.forge.addon.projects.Project; //导入方法依赖的package包/类
@Deprecated
public static boolean isFunktionParentPom(Project project) {
MavenFacet mavenFacet = project.getFacet(MavenFacet.class);
if (mavenFacet != null) {
Model model = mavenFacet.getModel();
if (model != null) {
Parent parent = model.getParent();
if (parent != null) {
String groupId = parent.getGroupId();
if (groupId != null && groupId.startsWith("io.fabric8.funktion")) {
return true;
}
}
}
}
return false;
}
示例6: createCurrentLineCompleter
import org.jboss.forge.addon.projects.Project; //导入方法依赖的package包/类
protected CurrentLineCompleter createCurrentLineCompleter(int lineNumber, String file, UIContext context) throws Exception {
Project project = getSelectedProject(context);
JavaSourceFacet sourceFacet = null;
ResourcesFacet resourcesFacet = null;
WebResourcesFacet webResourcesFacet = null;
if (project.hasFacet(JavaSourceFacet.class)) {
sourceFacet = project.getFacet(JavaSourceFacet.class);
}
if (project.hasFacet(ResourcesFacet.class)) {
resourcesFacet = project.getFacet(ResourcesFacet.class);
}
if (project.hasFacet(WebResourcesFacet.class)) {
webResourcesFacet = project.getFacet(WebResourcesFacet.class);
}
String relativeFile = asRelativeFile(context, file);
return new CurrentLineCompleter(lineNumber, relativeFile, sourceFacet, resourcesFacet, webResourcesFacet);
}
示例7: getXmlResourceFile
import org.jboss.forge.addon.projects.Project; //导入方法依赖的package包/类
protected FileResource getXmlResourceFile(Project project, String xmlResourceName) {
if (xmlResourceName == null) {
return null;
}
ResourcesFacet facet = null;
WebResourcesFacet webResourcesFacet = null;
if (project.hasFacet(ResourcesFacet.class)) {
facet = project.getFacet(ResourcesFacet.class);
}
if (project.hasFacet(WebResourcesFacet.class)) {
webResourcesFacet = project.getFacet(WebResourcesFacet.class);
}
FileResource file = facet != null ? facet.getResource(xmlResourceName) : null;
if (file == null || !file.exists()) {
file = webResourcesFacet != null ? webResourcesFacet.getWebResource(xmlResourceName) : null;
}
return file;
}
示例8: initializeUI
import org.jboss.forge.addon.projects.Project; //导入方法依赖的package包/类
@Override
public void initializeUI(UIBuilder builder) throws Exception {
Project project = getSelectedProject(builder.getUIContext());
JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
targetPackage.setCompleter(new PackageNameCompleter(facet));
targetPackage.addValidator(new PackageNameValidator());
targetPackage.getFacet(HintsFacet.class).setInputType(InputType.JAVA_PACKAGE_PICKER);
// if there is only one package then use that as default
Set<String> packages = new RouteBuilderCompleter(facet).getPackages();
if (packages.size() == 1) {
targetPackage.setDefaultValue(first(packages));
}
name.addValidator(new ClassNameValidator(false));
name.getFacet(HintsFacet.class).setInputType(InputType.JAVA_CLASS_PICKER);
builder.add(targetPackage).add(name);
}
示例9: execute
import org.jboss.forge.addon.projects.Project; //导入方法依赖的package包/类
@Override
public Result execute(UIExecutionContext context) throws Exception
{
final Result result = original.execute(context);
final Project project = helper.getProject(context.getUIContext());
final DependencyFacet facet = project.getFacet(DependencyFacet.class);
// add dependencies
facet.addDirectDependency(SpringBootFacet.SPRING_BOOT_STARTER_WEB);
facet.addDirectDependency(SpringBootFacet.CXF_SPRING_BOOT);
facet.addDirectDependency(SpringBootFacet.JACKSON_JAXRS_PROVIDER);
// remove EE dependencies
facet.removeDependency(SpringBootFacet.JBOSS_EJB_SPEC);
facet.removeDependency(SpringBootFacet.JBOSS_JAXRS_SPEC);
facet.removeDependency(SpringBootFacet.JBOSS_SERVLET_SPEC);
facet.removeManagedDependency(SpringBootFacet.JBOSS_EE_SPEC);
// add CXF properties to application.properties
final Properties cxfProps = new Properties();
cxfProps.put("cxf.jaxrs.component-scan", "true");
cxfProps.put("cxf.path", "/rest");
SpringBootHelper.writeToApplicationProperties(project, cxfProps);
SpringBootHelper.modifySpringBootApplication(project, sbApp -> {
sbApp.addImport("com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider");
final MethodSource<JavaClassSource> method = sbApp.addMethod("public JacksonJsonProvider config() {\n" +
"\t\treturn new JacksonJsonProvider();\n" +
"\t}");
method.addAnnotation("org.springframework.context.annotation.Bean");
return sbApp;
});
return result;
}
示例10: addDependency
import org.jboss.forge.addon.projects.Project; //导入方法依赖的package包/类
public static DependencyBuilder addDependency(Project project, Dependency dependency) {
final DependencyFacet dependencyFacet = project.getFacet(DependencyFacet.class);
final DependencyBuilder builder = dependency instanceof DependencyBuilder
? (DependencyBuilder) dependency : DependencyBuilder.create(dependency);
dependencyFacet.addDirectDependency(builder);
return builder;
}
示例11: testOnProjectThatHasAlreadyACoreDependency
import org.jboss.forge.addon.projects.Project; //导入方法依赖的package包/类
@Test
public void testOnProjectThatHasAlreadyACoreDependency() throws Exception {
File root = prepareRoot("target/tests/project-with-core-dependency");
Project project = projectFactory.createProject(resourceFactory.create(root), projectProvider);
DependencyFacet dependencies = project.getFacet(DependencyFacet.class);
dependencies.addDirectDependency(DependencyBuilder.create("io.vertx:vertx-core:3.1.0"));
checkDependency(dependencies, "io.vertx", "vertx-core", "3.1.0", null);
facetFactory.install(project, VertxMavenFacet.class);
MavenPluginFacet plugins = project.getFacet(MavenPluginFacet.class);
MavenFacet maven = project.getFacet(MavenFacet.class);
// Check vertx.version
assertThat(maven.getProperties()).contains(entry(VertxMavenFacet.VERTX_VERSION_PROPERTY, config().getVersion()));
// Check managed dependency
checkVertxBom(dependencies);
assertThat(dependencies.getManagedDependencies()).hasSize(1);
// Check dependencies
checkDependency(dependencies, "io.vertx", "vertx-core", "3.1.0", null);
checkDependency(dependencies, "io.vertx", "vertx-unit", null, "test");
checkDependency(dependencies, "junit", "junit", "4.12", "test");
assertThat(dependencies.getDependencies()).hasSize(3);
// Check maven compiler
hasPlugin(plugins, "maven-compiler-plugin");
hasPlugin(plugins, "vertx-maven-plugin");
}
示例12: getBasePackageName
import org.jboss.forge.addon.projects.Project; //导入方法依赖的package包/类
protected String getBasePackageName(Project project) {
if (project != null && project.hasFacet(JavaSourceFacet.class)) {
JavaSourceFacet java = project.getFacet(JavaSourceFacet.class);
String base = java.getBasePackage();
return base;
}
return null;
}
示例13: getMavenFacet
import org.jboss.forge.addon.projects.Project; //导入方法依赖的package包/类
public MavenFacet getMavenFacet(UIContextProvider builder) {
final Project project = getSelectedProject(builder);
if (project != null) {
MavenFacet maven = project.getFacet(MavenFacet.class);
return maven;
}
return null;
}
示例14: getOrAddDependency
import org.jboss.forge.addon.projects.Project; //导入方法依赖的package包/类
public static Dependency getOrAddDependency(Project project, String groupId, String artifactId,
String version, String classifier, String scope) {
DependencyFacet dependencies = project.getFacet(DependencyFacet.class);
Optional<Dependency> found = dependencies.getEffectiveDependencies().stream().filter(dep ->
dep.getCoordinate().getGroupId().equalsIgnoreCase(groupId)
&& dep.getCoordinate().getArtifactId().equalsIgnoreCase(artifactId)
&& (version == null || version.equalsIgnoreCase(dep.getCoordinate().getVersion()))
&& Strings.isNullOrEmpty(dep.getCoordinate().getClassifier())
&& (Strings.isNullOrEmpty(dep.getCoordinate().getPackaging()) || dep.getCoordinate().getPackaging()
.equalsIgnoreCase("jar"))
).findAny();
if (found.isPresent()) {
return found.get();
}
DependencyBuilder dependency = DependencyBuilder.create().setGroupId(groupId).setArtifactId(artifactId);
if (version != null) {
dependency.setVersion(version);
}
if (scope != null) {
dependency.setScopeType(scope);
}
if (classifier != null && ! classifier.isEmpty()) {
dependency.setClassifier(classifier);
}
dependencies.addDirectDependency(dependency);
return dependency;
}
示例15: getProjectClassLoader
import org.jboss.forge.addon.projects.Project; //导入方法依赖的package包/类
public static URLClassLoader getProjectClassLoader(Project project) {
if (project != null) {
ClassLoaderFacet classLoaderFacet = project.getFacet(ClassLoaderFacet.class);
if (classLoaderFacet != null) {
return classLoaderFacet.getClassLoader();
}
}
return null;
}