Exemple #1
0
 @Override
 public boolean install() {
   if (!this.isInstalled()) {
     for (DirectoryResource folder : this.getSourceDirectories()) {
       folder.mkdirs();
     }
   }
   return isInstalled();
 }
Exemple #2
0
 @Override
 public DirectoryResource getTestSourceDirectory() {
   MavenFacet mavenFacet = getFaceted().getFacet(MavenFacet.class);
   Build build = mavenFacet.getModel().getBuild();
   String srcFolderName;
   if (build != null && build.getTestSourceDirectory() != null) {
     srcFolderName = mavenFacet.resolveProperties(build.getTestSourceDirectory());
   } else {
     srcFolderName = "src" + File.separator + "test" + File.separator + "java";
   }
   DirectoryResource projectRoot = getFaceted().getRootDirectory();
   return projectRoot.getChildDirectory(srcFolderName);
 }
Exemple #3
0
  @Override
  public String calculatePackage(final JavaResource resource) {
    List<DirectoryResource> folders = getSourceDirectories();
    String pkg = null;
    for (DirectoryResource folder : folders) {
      String sourcePrefix = folder.getFullyQualifiedName();
      pkg = resource.getParent().getFullyQualifiedName();
      if (pkg.startsWith(sourcePrefix)) {
        pkg = pkg.substring(sourcePrefix.length() + 1);
        break;
      }
    }
    pkg = Packages.fromFileSyntax(pkg);

    return pkg;
  }
Exemple #4
0
  private JavaResource getJavaResource(final DirectoryResource sourceDir, final String relativePath)
      throws FileNotFoundException {
    if (Strings.isNullOrEmpty(relativePath)) {
      throw new FileNotFoundException("Empty relative path");
    }
    String path =
        relativePath.trim().endsWith(".java")
            ? relativePath.substring(0, relativePath.lastIndexOf(".java"))
            : relativePath;

    path = Packages.toFileSyntax(path) + ".java";
    JavaResource target = sourceDir.getChildOfType(JavaResource.class, path);
    return target;
  }
  @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;
  }