Пример #1
0
  public static void main(String[] args) throws Exception {
    Furnace furnace = startFurnace();
    try {
      AddonRegistry addonRegistry = furnace.getAddonRegistry();
      ProjectFactory projectFactory = addonRegistry.getServices(ProjectFactory.class).get();
      ResourceFactory resourceFactory = addonRegistry.getServices(ResourceFactory.class).get();

      // Create a temporary directory as an example
      File underlyingResource = OperatingSystemUtils.getTempDirectory();

      Resource<File> projectDir = resourceFactory.create(underlyingResource);

      // This could return more than one provider, but since the maven addon is the only one
      // deployed, this is ok
      ProjectProvider projectProvider = addonRegistry.getServices(ProjectProvider.class).get();

      // Creating WAR project
      JavaWebProjectType javaWebProjectType =
          addonRegistry.getServices(JavaWebProjectType.class).get();
      Project project =
          projectFactory.createProject(
              projectDir, projectProvider, javaWebProjectType.getRequiredFacets());

      // Changing metadata
      MetadataFacet facet = project.getFacet(MetadataFacet.class);
      facet.setProjectName("my-demo-project");
      facet.setProjectVersion("1.0.0-SNAPSHOT");
      facet.setTopLevelPackage("com.mycompany.project");

      System.out.println("### Project Created in: " + project);
    } finally {
      furnace.stop();
    }
  }
Пример #2
0
  @Override
  public Result execute(UIExecutionContext context) throws Exception {
    Result result = Results.success("Project named '" + named.getValue() + "' has been created.");
    DirectoryResource directory = targetLocation.getValue();
    DirectoryResource targetDir = directory.getChildDirectory(named.getValue());

    if (targetDir.mkdirs() || overwrite.getValue()) {
      ProjectType value = type.getValue();

      Project project = null;
      if (value != null) {
        project =
            projectFactory.createProject(
                targetDir, buildSystem.getValue(), value.getRequiredFacets());
      } else {
        project = projectFactory.createProject(targetDir, buildSystem.getValue());
      }

      if (project != null) {
        UIContext uiContext = context.getUIContext();
        MetadataFacet metadataFacet = project.getFacet(MetadataFacet.class);
        metadataFacet.setProjectName(named.getValue());
        metadataFacet.setProjectVersion(version.getValue());
        metadataFacet.setTopLevelPackage(topLevelPackage.getValue());

        if (finalName.hasValue()) {
          PackagingFacet packagingFacet = project.getFacet(PackagingFacet.class);
          packagingFacet.setFinalName(finalName.getValue());
        }

        uiContext.setSelection(project.getRoot());
        uiContext.getAttributeMap().put(Project.class, project);
      } else result = Results.fail("Could not create project of type: [" + value + "]");
    } else result = Results.fail("Could not create target location: " + targetDir);

    return result;
  }